Loading...
Searching...
No Matches
satellite-net-device.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Magister Solutions Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Jani Puttonen <jani.puttonen@magister.fi>
19 */
20
22
25#include "satellite-llc.h"
26#include "satellite-mac.h"
27#include "satellite-node-info.h"
28#include "satellite-phy.h"
29#include "satellite-time-tag.h"
30#include "satellite-typedefs.h"
31#include "satellite-utils.h"
32
33#include "ns3/boolean.h"
34#include "ns3/channel.h"
35#include "ns3/error-model.h"
36#include "ns3/ipv4-l3-protocol.h"
37#include "ns3/log.h"
38#include "ns3/node.h"
39#include "ns3/packet.h"
40#include "ns3/pointer.h"
41#include "ns3/trace-source-accessor.h"
42
43NS_LOG_COMPONENT_DEFINE("SatNetDevice");
44
45namespace ns3
46{
47
48NS_OBJECT_ENSURE_REGISTERED(SatNetDevice);
49
50TypeId
52{
53 static TypeId tid =
54 TypeId("ns3::SatNetDevice")
55 .SetParent<NetDevice>()
56 .AddConstructor<SatNetDevice>()
57 .AddAttribute("ReceiveErrorModel",
58 "The receiver error model used to simulate packet loss",
59 PointerValue(),
60 MakePointerAccessor(&SatNetDevice::m_receiveErrorModel),
61 MakePointerChecker<ErrorModel>())
62 .AddAttribute("SatMac",
63 "The Satellite MAC layer attached to this device.",
64 PointerValue(),
65 MakePointerAccessor(&SatNetDevice::GetMac, &SatNetDevice::SetMac),
66 MakePointerChecker<SatMac>())
67 .AddAttribute("SatPhy",
68 "The Satellite Phy layer attached to this device.",
69 PointerValue(),
70 MakePointerAccessor(&SatNetDevice::GetPhy, &SatNetDevice::SetPhy),
71 MakePointerChecker<SatPhy>())
72 .AddAttribute("SatLlc",
73 "The Satellite Llc layer attached to this device.",
74 PointerValue(),
75 MakePointerAccessor(&SatNetDevice::GetLlc, &SatNetDevice::SetLlc),
76 MakePointerChecker<SatLlc>())
77 .AddAttribute("MaximumTransmissionUnit",
78 "Maximum transmission unit in Bytes",
79 UintegerValue(0xffff),
80 MakeUintegerAccessor(&SatNetDevice::m_mtu),
81 MakeUintegerChecker<uint16_t>())
82 .AddAttribute("EnableStatisticsTags",
83 "If true, some tags will be added to each transmitted packet to assist "
84 "with statistics computation",
85 BooleanValue(false),
86 MakeBooleanAccessor(&SatNetDevice::m_isStatisticsTagsEnabled),
87 MakeBooleanChecker())
88 .AddTraceSource("PacketTrace",
89 "Packet event trace",
90 MakeTraceSourceAccessor(&SatNetDevice::m_packetTrace),
91 "ns3::SatTypedefs::PacketTraceCallback")
92 .AddTraceSource("Tx",
93 "A packet to be sent",
94 MakeTraceSourceAccessor(&SatNetDevice::m_txTrace),
95 "ns3::Packet::TracedCallback")
96 .AddTraceSource("SignallingTx",
97 "A signalling packet to be sent",
98 MakeTraceSourceAccessor(&SatNetDevice::m_signallingTxTrace),
99 "ns3::SatTypedefs::PacketDestinationAddressCallback")
100 .AddTraceSource("Rx",
101 "A packet received",
102 MakeTraceSourceAccessor(&SatNetDevice::m_rxTrace),
103 "ns3::SatTypedefs::PacketSourceAddressCallback")
104 .AddTraceSource("RxDelay",
105 "A packet is received with delay information",
106 MakeTraceSourceAccessor(&SatNetDevice::m_rxDelayTrace),
107 "ns3::SatTypedefs::PacketDelayAddressCallback")
108 .AddTraceSource("RxJitter",
109 "A packet is received with jitter information",
110 MakeTraceSourceAccessor(&SatNetDevice::m_rxJitterTrace),
111 "ns3::SatTypedefs::PacketJitterAddressCallback")
112 .AddTraceSource("RxLinkDelay",
113 "A packet is received with link delay information",
114 MakeTraceSourceAccessor(&SatNetDevice::m_rxLinkDelayTrace),
115 "ns3::SatTypedefs::PacketDelayAddressCallback")
116 .AddTraceSource("RxLinkJitter",
117 "A packet is received with link jitter information",
118 MakeTraceSourceAccessor(&SatNetDevice::m_rxLinkJitterTrace),
119 "ns3::SatTypedefs::PacketJitterAddressCallback");
120 return tid;
121}
122
124 : m_phy(0),
125 m_mac(0),
126 m_llc(0),
128 m_node(0),
129 m_mtu(0xffff),
130 m_ifIndex(0),
131 m_lastDelay(0),
133{
134 NS_LOG_FUNCTION(this);
135}
136
137void
138SatNetDevice::Receive(Ptr<const Packet> packet)
139{
140 NS_LOG_FUNCTION(this << packet);
141 NS_LOG_INFO("Receiving a packet: " << packet->GetUid());
142
143 // Add packet trace entry:
146
147 m_packetTrace(Simulator::Now(),
149 m_nodeInfo->GetNodeType(),
150 m_nodeInfo->GetNodeId(),
151 m_nodeInfo->GetMacAddress(),
153 ld,
155
156 /*
157 * Invoke the `Rx` and `RxDelay` trace sources. We look at the packet's tags
158 * for information, but cannot remove the tags because the packet is a const.
159 */
161 {
162 Address addr; // invalid address.
163 bool isTaggedWithAddress = false;
164 ByteTagIterator it = packet->GetByteTagIterator();
165
166 while (!isTaggedWithAddress && it.HasNext())
167 {
168 ByteTagIterator::Item item = it.Next();
169
170 if (item.GetTypeId() == SatAddressTag::GetTypeId())
171 {
172 NS_LOG_DEBUG(this << " contains a SatAddressTag tag:" << " start="
173 << item.GetStart() << " end=" << item.GetEnd());
174 SatAddressTag addrTag;
175 item.GetTag(addrTag);
176 addr = addrTag.GetSourceAddress();
177 isTaggedWithAddress = true; // this will exit the while loop.
178 }
179 }
180
181 m_rxTrace(packet, addr);
182
183 SatDevTimeTag timeTag;
184 if (packet->PeekPacketTag(timeTag))
185 {
186 NS_LOG_DEBUG(this << " contains a SatDevTimeTag tag");
187 Time delay = Simulator::Now() - timeTag.GetSenderTimestamp();
188 m_rxDelayTrace(delay, addr);
189 if (m_lastDelay.IsZero() == false)
190 {
191 Time jitter = Abs(delay - m_lastDelay);
192 m_rxJitterTrace(jitter, addr);
193 }
194 m_lastDelay = delay;
195 }
196
197 SatDevLinkTimeTag linkTimeTag;
198 if (packet->PeekPacketTag(linkTimeTag))
199 {
200 NS_LOG_DEBUG(this << " contains a SatDevLinkTimeTag tag");
201 Time delay = Simulator::Now() - linkTimeTag.GetSenderTimestamp();
202 m_rxLinkDelayTrace(delay, addr);
203 if (m_lastLinkDelay.IsZero() == false)
204 {
205 Time jitter = Abs(delay - m_lastLinkDelay);
206 m_rxLinkJitterTrace(jitter, addr);
207 }
208 m_lastLinkDelay = delay;
209 }
210 }
211
212 // Pass the packet to the upper layer.
213 m_rxCallback(this, packet, Ipv4L3Protocol::PROT_NUMBER, Address());
214}
215
216void
217SatNetDevice::SetPhy(Ptr<SatPhy> phy)
218{
219 NS_LOG_FUNCTION(this << phy);
220 m_phy = phy;
221}
222
223void
224SatNetDevice::SetMac(Ptr<SatMac> mac)
225{
226 NS_LOG_FUNCTION(this << mac);
227 m_mac = mac;
228}
229
230void
231SatNetDevice::SetLlc(Ptr<SatLlc> llc)
232{
233 NS_LOG_FUNCTION(this << llc);
234 m_llc = llc;
235}
236
237void
238SatNetDevice::SetNodeInfo(Ptr<SatNodeInfo> nodeInfo)
239{
240 NS_LOG_FUNCTION(this << nodeInfo);
241 m_nodeInfo = nodeInfo;
242}
243
244void
246{
247 NS_LOG_FUNCTION(this << enabled);
248
249 if (enabled)
250 {
251 m_mac->Enable();
252 }
253 else
254 {
255 m_mac->Disable();
256 }
257}
258
259void
261{
262 NS_LOG_FUNCTION(this << em);
264}
265
266void
267SatNetDevice::SetIfIndex(const uint32_t index)
268{
269 NS_LOG_FUNCTION(this << index);
270 m_ifIndex = index;
271}
272
273uint32_t
275{
276 NS_LOG_FUNCTION(this);
277 return m_ifIndex;
278}
279
280Ptr<SatPhy>
282{
283 NS_LOG_FUNCTION(this);
284 return m_phy;
285}
286
287Ptr<SatMac>
289{
290 NS_LOG_FUNCTION(this);
291 return m_mac;
292}
293
294Ptr<SatLlc>
296{
297 NS_LOG_FUNCTION(this);
298 return m_llc;
299}
300
301void
302SatNetDevice::SetPacketClassifier(Ptr<SatPacketClassifier> classifier)
303{
304 NS_LOG_FUNCTION(this);
305 m_classifier = classifier;
306}
307
308Ptr<SatPacketClassifier>
310{
311 NS_LOG_FUNCTION(this);
312 return m_classifier;
313}
314
315void
317{
318 NS_LOG_FUNCTION(this << address);
319 m_address = Mac48Address::ConvertFrom(address);
320}
321
322Address
324{
325 //
326 // Implicit conversion from Mac48Address to Address
327 //
328 NS_LOG_FUNCTION(this);
329 return m_address;
330}
331
332bool
333SatNetDevice::SetMtu(const uint16_t mtu)
334{
335 NS_LOG_FUNCTION(this << mtu);
336 m_mtu = mtu;
337 return true;
338}
339
340uint16_t
342{
343 NS_LOG_FUNCTION(this);
344 return m_mtu;
345}
346
347bool
349{
350 NS_LOG_FUNCTION(this);
351 return true;
352}
353
354void
356{
357 NS_LOG_FUNCTION(this << &callback);
358}
359
360bool
362{
363 NS_LOG_FUNCTION(this);
364 return true;
365}
366
367Address
369{
370 NS_LOG_FUNCTION(this);
371 return Mac48Address("ff:ff:ff:ff:ff:ff");
372}
373
374bool
376{
377 NS_LOG_FUNCTION(this);
378 return true;
379}
380
381Address
382SatNetDevice::GetMulticast(Ipv4Address multicastGroup) const
383{
384 NS_LOG_FUNCTION(this << multicastGroup);
385 return Mac48Address::GetMulticast(multicastGroup);
386}
387
388Address
389SatNetDevice::GetMulticast(Ipv6Address addr) const
390{
391 NS_LOG_FUNCTION(this << addr);
392 return Mac48Address::GetMulticast(addr);
393}
394
395bool
397{
398 NS_LOG_FUNCTION(this);
399 return false;
400}
401
402bool
404{
405 NS_LOG_FUNCTION(this);
406 return false;
407}
408
409bool
410SatNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
411{
412 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
413
415 {
416 // Add a SatAddressTag tag with this device's address as the source address.
417 packet->AddByteTag(SatAddressTag(m_nodeInfo->GetMacAddress()));
418
419 // Add a SatDevTimeTag tag for packet delay computation at the receiver end.
420 packet->AddPacketTag(SatDevTimeTag(Simulator::Now()));
421
422 // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
423 packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
424 }
425
426 // Add packet trace entry:
429
430 m_packetTrace(Simulator::Now(),
432 m_nodeInfo->GetNodeType(),
433 m_nodeInfo->GetNodeId(),
434 m_nodeInfo->GetMacAddress(),
436 ld,
438
439 m_txTrace(packet);
440
441 uint8_t flowId = m_classifier->Classify(packet, dest, protocolNumber);
442 m_llc->Enque(packet, dest, flowId);
443
444 return true;
445}
446
447bool
448SatNetDevice::SendFrom(Ptr<Packet> packet,
449 const Address& source,
450 const Address& dest,
451 uint16_t protocolNumber)
452{
453 NS_LOG_FUNCTION(this << packet << source << dest << protocolNumber);
454
456 {
457 // Add a SatAddressTag tag with this device's address as the source address.
458 packet->AddByteTag(SatAddressTag(m_nodeInfo->GetMacAddress()));
459
460 // Add a SatDevTimeTag tag for packet delay computation at the receiver end.
461 packet->AddPacketTag(SatDevTimeTag(Simulator::Now()));
462
463 // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
464 packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
465 }
466
467 // Add packet trace entry:
470
471 m_packetTrace(Simulator::Now(),
473 m_nodeInfo->GetNodeType(),
474 m_nodeInfo->GetNodeId(),
475 m_nodeInfo->GetMacAddress(),
477 ld,
479
480 m_txTrace(packet);
481
482 uint8_t flowId = m_classifier->Classify(packet, dest, protocolNumber);
483 m_llc->Enque(packet, dest, flowId);
484
485 return true;
486}
487
488bool
489SatNetDevice::SendControlMsg(Ptr<SatControlMessage> msg, const Address& dest)
490{
491 NS_LOG_FUNCTION(this << msg << dest);
492
493 Ptr<Packet> packet = Create<Packet>(msg->GetSizeInBytes());
494
496 {
497 // Add a SatAddressTag tag with this device's address as the source address.
498 packet->AddByteTag(SatAddressTag(m_nodeInfo->GetMacAddress()));
499
500 // Add a SatDevTimeTag tag for packet delay computation at the receiver end.
501 packet->AddPacketTag(SatDevTimeTag(Simulator::Now()));
502
503 // Add a SatDevLinkTimeTag tag for packet link delay computation at the receiver end.
504 packet->AddPacketTag(SatDevLinkTimeTag(Simulator::Now()));
505 }
506
507 // Add packet trace entry:
510
511 m_packetTrace(Simulator::Now(),
513 m_nodeInfo->GetNodeType(),
514 m_nodeInfo->GetNodeId(),
515 m_nodeInfo->GetMacAddress(),
517 ld,
519
520 // Add control tag to message and write msg to container in MAC
522 uint32_t id = m_mac->ReserveIdAndStoreCtrlMsgToContainer(msg);
523 tag.SetMsgId(id);
524 tag.SetMsgType(msg->GetMsgType());
525 packet->AddPacketTag(tag);
526
527 uint8_t flowId = m_classifier->Classify(msg->GetMsgType(), dest);
528
529 m_signallingTxTrace(packet, dest);
530
531 m_llc->Enque(packet, dest, flowId);
532
533 return true;
534}
535
536Ptr<Node>
538{
539 NS_LOG_FUNCTION(this);
540 return m_node;
541}
542
543void
545{
546 NS_LOG_FUNCTION(this << node);
547 m_node = node;
548}
549
550bool
552{
553 NS_LOG_FUNCTION(this);
554 return true;
555}
556
557void
558SatNetDevice::SetReceiveCallback(NetDevice::ReceiveCallback cb)
559{
560 NS_LOG_FUNCTION(this << &cb);
561 m_rxCallback = cb;
562}
563
564void
566{
567 NS_LOG_FUNCTION(this);
568 m_rxCallback.Nullify();
569 m_promiscCallback.Nullify();
570 m_phy = 0;
571 m_mac->Dispose();
572 m_mac = 0;
573 m_node = 0;
575 if (m_llc != nullptr)
576 {
577 m_llc->Dispose();
578 }
579 m_llc = 0;
580 m_classifier = 0;
581
582 NetDevice::DoDispose();
583}
584
585void
587{
588 NS_LOG_FUNCTION(this << &cb);
590}
591
592bool
594{
595 NS_LOG_FUNCTION(this);
596 return true;
597}
598
599Ptr<Channel>
601{
602 NS_LOG_FUNCTION(this);
603
608 return 0;
609}
610
611} // namespace ns3
This class implements a tag that carries the MAC address of the sender of the packet.
static TypeId GetTypeId()
Inherited from ObjectBase base class.
Address GetSourceAddress() const
Get the source address.
This class implements a tag that is used to identify control messages (packages).
void SetMsgType(SatControlMsgType_t type)
Set type of the control message.
virtual void SetMsgId(uint32_t msgId)
Set message type specific identifier.
Time tag used to identify the time when packet is enqueued at device level.
Time GetSenderTimestamp(void) const
Get sender time stamp of this tag.
SatLinkDir_t
Link direction used for packet tracing.
SatNetDevice to be utilized in the UT and GW nodes.
Time m_lastLinkDelay
Last link delay measurement.
TracedCallback< const Time &, const Address & > m_rxDelayTrace
Traced callback for all received packets, including delay information and the address of the senders.
virtual bool SetMtu(const uint16_t mtu)
virtual bool IsLinkUp(void) const
virtual Ptr< Channel > GetChannel(void) const
void ToggleState(bool enabled)
Toggle the state of the device.
void SetLlc(Ptr< SatLlc > llc)
Attach the SatLlc llc layer to this netdevice.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Ptr< SatMac > GetMac(void) const
Get a Mac pointer.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
SatNetDevice()
Default constructor.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced callback for all packets received to be transmitted.
Ptr< SatPacketClassifier > m_classifier
Ptr< ErrorModel > m_receiveErrorModel
Time m_lastDelay
Last delay measurement.
virtual uint16_t GetMtu(void) const
virtual bool SupportsSendFrom(void) const
virtual bool NeedsArp(void) const
virtual Address GetAddress(void) const
virtual void DoDispose(void)
Dispose of this class instance.
TracedCallback< const Time &, const Address & > m_rxLinkDelayTrace
Traced callback for all received packets, including link delay information and the address of the sen...
void SetPhy(Ptr< SatPhy > phy)
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced callback for all received packets, including the address of the senders.
virtual bool IsBroadcast(void) const
Ptr< SatLlc > GetLlc(void) const
Get Llc pointer.
Ptr< SatNodeInfo > m_nodeInfo
virtual Address GetMulticast(Ipv4Address multicastGroup) const
virtual void Receive(Ptr< const Packet > packet)
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
static TypeId GetTypeId(void)
Get the type ID.
Ptr< SatPhy > GetPhy(void) const
Get a Phy pointer.
virtual Address GetBroadcast(void) const
virtual uint32_t GetIfIndex(void) const
void SetMac(Ptr< SatMac > mac)
virtual void SetIfIndex(const uint32_t index)
virtual void SetAddress(Address address)
Ptr< SatPacketClassifier > GetPacketClassifier() const
Get a pointer to packet classifier class.
bool SendControlMsg(Ptr< SatControlMessage > msg, const Address &dest)
NetDevice::PromiscReceiveCallback m_promiscCallback
virtual Ptr< Node > GetNode(void) const
virtual void AddLinkChangeCallback(Callback< void > callback)
TracedCallback< const Time &, const Address & > m_rxJitterTrace
Traced callback for all received packets, including jitter information and the address of the senders...
void SetPacketClassifier(Ptr< SatPacketClassifier > classifier)
Set the packet classifier class.
NetDevice::ReceiveCallback m_rxCallback
void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
TracedCallback< const Time &, const Address & > m_rxLinkJitterTrace
Traced callback for all received packets, including link jitter information and the address of the se...
virtual bool IsPointToPoint(void) const
virtual bool IsMulticast(void) const
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SatNetDevice.
virtual bool IsBridge(void) const
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
TracedCallback< Ptr< const Packet >, const Address & > m_signallingTxTrace
Traced callback for all signalling (control message) packets sent, including the destination address.
virtual void SetNode(Ptr< Node > node)
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.