33 #include <ns3/nstime.h>
34 #include <ns3/simulator.h>
36 NS_LOG_COMPONENT_DEFINE(
"SatLlc");
41 NS_OBJECT_ENSURE_REGISTERED(SatLlc);
46 static TypeId tid = TypeId(
"ns3::SatLlc")
48 .AddAttribute(
"FwdLinkArqEnabled",
49 "Enable ARQ in forward link.",
53 .AddAttribute(
"RtnLinkArqEnabled",
54 "Enable ARQ in return link.",
58 .AddTraceSource(
"PacketTrace",
61 "ns3::PacketTraceCallback");
69 m_fwdLinkArqEnabled(false),
70 m_rtnLinkArqEnabled(false),
73 m_additionalHeaderSize(0),
74 m_forwardLinkRegenerationMode(
SatEnums::TRANSPARENT),
75 m_returnLinkRegenerationMode(
SatEnums::TRANSPARENT)
77 NS_LOG_FUNCTION(
this);
86 m_fwdLinkArqEnabled(false),
87 m_rtnLinkArqEnabled(false),
90 m_additionalHeaderSize(0),
91 m_forwardLinkRegenerationMode(forwardLinkRegenerationMode),
92 m_returnLinkRegenerationMode(returnLinkRegenerationMode)
94 NS_LOG_FUNCTION(
this);
99 NS_LOG_FUNCTION(
this);
105 NS_LOG_FUNCTION(
this);
108 EncapContainer_t::iterator it;
112 it->second->DoDispose();
119 it->second->DoDispose();
130 NS_LOG_FUNCTION(
this << packet << dest << (uint32_t)flowId);
131 NS_LOG_INFO(
"p=" << packet);
132 NS_LOG_INFO(
"dest=" << dest);
133 NS_LOG_INFO(
"UID is " << packet->GetUid());
135 Ptr<EncapKey> key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
136 Mac48Address::ConvertFrom(dest),
139 Mac48Address::ConvertFrom(dest));
141 EncapContainer_t::iterator it =
m_encaps.find(key);
156 packet->AddPacketTag(timeTag);
162 packet->AddPacketTag(addressE2ETag);
164 it->second->EnquePdu(packet, Mac48Address::ConvertFrom(dest));
184 NS_LOG_FUNCTION(
this << source << dest << packet);
201 bool mSuccess = packet->PeekPacketTag(flowIdTag);
205 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
206 EncapContainer_t::iterator it =
m_decaps.find(key);
211 NS_FATAL_ERROR(
"Control messages should not be received by SatLlc::Receive () method!");
225 it->second->ReceivePdu(packet);
232 NS_LOG_FUNCTION(
this << source << dest);
240 uint32_t flowId = ack->GetFlowId();
242 Ptr<EncapKey> key = Create<EncapKey>(dest, source, flowId);
243 EncapContainer_t::iterator it =
m_encaps.find(key);
247 it->second->ReceiveAck(ack);
251 NS_FATAL_ERROR(
"Encapsulator not found for key (" << source <<
", " << dest <<
", "
252 << (uint32_t)flowId <<
")");
271 NS_LOG_FUNCTION(
this << packet << source << dest);
275 packet->RemovePacketTag(timeTag);
279 bool cSuccess = packet->RemovePacketTag(ctrlTag);
285 NS_FATAL_ERROR(
"A control message other than ARQ ACK received at the LLC!");
289 uint32_t ackId = ctrlTag.
GetMsgId();
296 "ARQ ACK not found, check that control msg storage time is set long enough!");
308 packet->RemovePacketTag(addressE2ETag);
318 Ptr<SatBaseEncapsulator> enc)
320 NS_LOG_FUNCTION(
this << source << dest << (uint32_t)flowId);
322 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
323 EncapContainer_t::iterator it =
m_encaps.find(key);
327 NS_LOG_INFO(
"Add encapsulator with key (" << source <<
", " << dest <<
", "
328 << (uint32_t)flowId <<
")");
330 std::pair<EncapContainer_t::iterator, bool> result =
331 m_encaps.insert(std::make_pair(key, enc));
332 if (result.second ==
false)
334 NS_FATAL_ERROR(
"Insert to map with key (" << source <<
", " << dest <<
", "
335 << (uint32_t)flowId <<
") failed!");
340 NS_FATAL_ERROR(
"Encapsulator container already holds key ("
341 << source <<
", " << dest <<
", " << (uint32_t)flowId <<
") key!");
349 Ptr<SatBaseEncapsulator> dec)
351 NS_LOG_FUNCTION(
this << source << dest << (uint32_t)flowId);
353 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
354 EncapContainer_t::iterator it =
m_decaps.find(key);
358 NS_LOG_INFO(
"Add Decapsulator with key (" << source <<
", " << dest <<
", "
359 << (uint32_t)flowId <<
")");
361 std::pair<EncapContainer_t::iterator, bool> result =
362 m_decaps.insert(std::make_pair(key, dec));
363 if (result.second ==
false)
365 NS_FATAL_ERROR(
"Insert to map with key (" << source <<
", " << dest <<
", "
366 << (uint32_t)flowId <<
") failed!");
371 NS_FATAL_ERROR(
"Decapsulator container already holds (" << source <<
", " << dest <<
", "
372 << (uint32_t)flowId <<
") key!");
379 NS_LOG_FUNCTION(
this << nodeInfo);
386 NS_LOG_FUNCTION(
this << &cb);
393 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
395 if (it->second->GetTxBufferSizeInBytes() > 0)
406 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
410 if (it->second->GetTxBufferSizeInBytes() > 0)
422 NS_LOG_FUNCTION(
this);
426 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
428 NS_ASSERT(it->second !=
nullptr);
429 Ptr<SatQueue> queue = it->second->GetQueue();
430 NS_ASSERT(queue !=
nullptr);
431 sum += queue->GetNBytes();
440 NS_LOG_FUNCTION(
this);
444 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
446 NS_ASSERT(it->second !=
nullptr);
447 Ptr<SatQueue> queue = it->second->GetQueue();
448 NS_ASSERT(queue !=
nullptr);
449 sum += queue->GetNPackets();
458 NS_LOG_FUNCTION(
this << &cb);
465 NS_LOG_FUNCTION(
this << &cb);
473 NS_LOG_FUNCTION(
this << address);
480 NS_LOG_FUNCTION(
this << address);
487 NS_LOG_FUNCTION(
this << additionalHeaderSize);
This class implements a tag that carries the satellite MAC of GW and UT.
void SetE2ESourceAddress(Mac48Address e2eSourceAddress)
Set E2E source MAC address.
void SetE2EDestAddress(Mac48Address e2eDestAddress)
Set E2E destination MAC address.
Callback< bool, Ptr< SatControlMessage >, const Address & > SendCtrlCallback
Control msg sending callback.
This class implements a tag that is used to identify control messages (packages).
@ SAT_ARQ_ACK
SAT_ARQ_ACK.
virtual uint32_t GetMsgId() const
Get message type specific identifier.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
SatEnums class is for simplifying the use of enumerators in the satellite module.
SatLinkDir_t
Link direction used for packet tracing.
RegenerationMode_t
The regeneration mode used in satellites.
SatFlowIdTag implements a tag which carries the flow identifier of a packet.
uint8_t GetFlowId() const
Get flow identifier.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
virtual bool BuffersEmpty() const
Are buffers empty?
static TypeId GetTypeId(void)
Derived from Object.
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
virtual void SetGwAddress(Mac48Address address)
Set the GW address.
SatLlc::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
Callback< Ptr< SatControlMessage >, uint32_t > ReadCtrlMsgCallback
Callback to read control messages from container storing control messages.
virtual uint32_t GetNBytesInQueue() const
Get the total number of (new) bytes in all encapsulators.
virtual void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
void SetReadCtrlCallback(SatLlc::ReadCtrlMsgCallback cb)
Method to set read control message callback.
uint32_t m_additionalHeaderSize
Additional header size to add to encapsulation/decapsulation.
void SetReceiveCallback(SatLlc::ReceiveCallback cb)
Set Receive callback to forward packet to upper layer.
bool m_fwdLinkArqEnabled
Is FWD link ARQ enabled.
SatBaseEncapsulator::SendCtrlCallback m_sendCtrlCallback
Callback to send control messages.
EncapContainer_t m_decaps
Map of decapsulator base pointers.
virtual void CreateEncap(Ptr< EncapKey > key)=0
Virtual method to create a new encapsulator 'on-a-need-basis' dynamically.
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
Trace callback used for packet tracing:
virtual void CreateDecap(Ptr< EncapKey > key)=0
Virtual method to create a new decapsulator 'on-a-need-basis' dynamically.
Mac48Address m_gwAddress
GW address.
virtual void DoDispose()
Dispose of this class instance.
void AddEncap(Mac48Address source, Mac48Address dest, uint8_t flowId, Ptr< SatBaseEncapsulator > enc)
Add an encapsulator entry for the LLC.
virtual void ReceiveAck(Ptr< SatArqAckMessage > ack, Mac48Address source, Mac48Address dest)
Receive a control msg (ARQ ACK) from lower layer.
void SetCtrlMsgCallback(SatBaseEncapsulator::SendCtrlCallback cb)
EncapContainer_t m_encaps
Map of encapsulator base pointers.
virtual ~SatLlc()
Destroy a SatLlc.
void SetAdditionalHeaderSize(uint32_t additionalHeaderSize)
Set the additional header size.
virtual bool ControlBuffersEmpty() const
Are buffers empty?
SatLlc()
Construct a SatLlc, should not be used.
virtual void SetSatelliteAddress(Mac48Address address)
Set the SAT address.
virtual uint32_t GetNPacketsInQueue() const
Get the total number of (new) packets in all encapsulators.
virtual void ReceiveHigherLayerPdu(Ptr< Packet > packet, Mac48Address source, Mac48Address dest)
Receive HL PDU from encapsulator/decapsulator entity.
Callback< void, Ptr< const Packet > > ReceiveCallback
Receive callback used for sending packet to netdevice layer.
virtual bool Enque(Ptr< Packet > packet, Address dest, uint8_t flowId)
Called from higher layer (SatNetDevice) to enque packet to LLC.
Mac48Address m_satelliteAddress
SAT address, used in case of network regeneration.
void AddDecap(Mac48Address source, Mac48Address dest, uint8_t flowId, Ptr< SatBaseEncapsulator > dec)
Add an decapsulator entry for the LLC.
bool m_rtnLinkArqEnabled
Is RTN link ARQ enabled.
virtual void Receive(Ptr< Packet > packet, Mac48Address source, Mac48Address dest)
Receive user data packet from lower layer.
ReceiveCallback m_rxCallback
The upper layer package receive callback.
Time tag used to identify the time when packet is enqueued at LLC level.
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.