34 #include <ns3/nstime.h>
35 #include <ns3/simulator.h>
36 #include <ns3/singleton.h>
40 NS_LOG_COMPONENT_DEFINE(
"SatLlc");
45 NS_OBJECT_ENSURE_REGISTERED(SatLlc);
50 static TypeId tid = TypeId(
"ns3::SatLlc")
52 .AddAttribute(
"FwdLinkArqEnabled",
53 "Enable ARQ in forward link.",
57 .AddAttribute(
"RtnLinkArqEnabled",
58 "Enable ARQ in return link.",
62 .AddTraceSource(
"PacketTrace",
65 "ns3::PacketTraceCallback");
73 m_fwdLinkArqEnabled(false),
74 m_rtnLinkArqEnabled(false),
77 m_additionalHeaderSize(0),
78 m_forwardLinkRegenerationMode(
79 Singleton<
SatTopology>::Get()->GetForwardLinkRegenerationMode()),
80 m_returnLinkRegenerationMode(Singleton<
SatTopology>::Get()->GetReturnLinkRegenerationMode())
82 NS_LOG_FUNCTION(
this);
87 NS_LOG_FUNCTION(
this);
93 NS_LOG_FUNCTION(
this);
96 EncapContainer_t::iterator it;
100 it->second->DoDispose();
107 it->second->DoDispose();
118 NS_LOG_FUNCTION(
this << packet << dest << (uint32_t)flowId);
119 NS_LOG_INFO(
"p=" << packet);
120 NS_LOG_INFO(
"dest=" << dest);
121 NS_LOG_INFO(
"UID is " << packet->GetUid());
123 Ptr<EncapKey> key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
124 Mac48Address::ConvertFrom(dest),
127 Mac48Address::ConvertFrom(dest));
129 EncapContainer_t::iterator it =
m_encaps.find(key);
144 packet->AddPacketTag(timeTag);
150 packet->AddPacketTag(addressE2ETag);
152 it->second->EnquePdu(packet, Mac48Address::ConvertFrom(dest));
172 NS_LOG_FUNCTION(
this << source << dest << packet);
189 bool mSuccess = packet->PeekPacketTag(flowIdTag);
193 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
194 EncapContainer_t::iterator it =
m_decaps.find(key);
199 NS_FATAL_ERROR(
"Control messages should not be received by SatLlc::Receive () method!");
213 it->second->ReceivePdu(packet);
220 NS_LOG_FUNCTION(
this << source << dest);
228 uint32_t flowId = ack->GetFlowId();
230 Ptr<EncapKey> key = Create<EncapKey>(dest, source, flowId);
231 EncapContainer_t::iterator it =
m_encaps.find(key);
235 it->second->ReceiveAck(ack);
239 NS_FATAL_ERROR(
"Encapsulator not found for key (" << source <<
", " << dest <<
", "
240 << (uint32_t)flowId <<
")");
259 NS_LOG_FUNCTION(
this << packet << source << dest);
263 packet->RemovePacketTag(timeTag);
267 bool cSuccess = packet->RemovePacketTag(ctrlTag);
273 NS_FATAL_ERROR(
"A control message other than ARQ ACK received at the LLC!");
277 uint32_t ackId = ctrlTag.
GetMsgId();
284 "ARQ ACK not found, check that control msg storage time is set long enough!");
296 packet->RemovePacketTag(addressE2ETag);
306 Ptr<SatBaseEncapsulator> enc)
308 NS_LOG_FUNCTION(
this << source << dest << (uint32_t)flowId);
310 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
311 EncapContainer_t::iterator it =
m_encaps.find(key);
315 NS_LOG_INFO(
"Add encapsulator with key (" << source <<
", " << dest <<
", "
316 << (uint32_t)flowId <<
")");
318 std::pair<EncapContainer_t::iterator, bool> result =
319 m_encaps.insert(std::make_pair(key, enc));
320 if (result.second ==
false)
322 NS_FATAL_ERROR(
"Insert to map with key (" << source <<
", " << dest <<
", "
323 << (uint32_t)flowId <<
") failed!");
328 NS_FATAL_ERROR(
"Encapsulator container already holds key ("
329 << source <<
", " << dest <<
", " << (uint32_t)flowId <<
") key!");
337 Ptr<SatBaseEncapsulator> dec)
339 NS_LOG_FUNCTION(
this << source << dest << (uint32_t)flowId);
341 Ptr<EncapKey> key = Create<EncapKey>(source, dest, flowId);
342 EncapContainer_t::iterator it =
m_decaps.find(key);
346 NS_LOG_INFO(
"Add Decapsulator with key (" << source <<
", " << dest <<
", "
347 << (uint32_t)flowId <<
")");
349 std::pair<EncapContainer_t::iterator, bool> result =
350 m_decaps.insert(std::make_pair(key, dec));
351 if (result.second ==
false)
353 NS_FATAL_ERROR(
"Insert to map with key (" << source <<
", " << dest <<
", "
354 << (uint32_t)flowId <<
") failed!");
359 NS_FATAL_ERROR(
"Decapsulator container already holds (" << source <<
", " << dest <<
", "
360 << (uint32_t)flowId <<
") key!");
367 NS_LOG_FUNCTION(
this << nodeInfo);
374 NS_LOG_FUNCTION(
this << &cb);
381 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
383 if (it->second->GetTxBufferSizeInBytes() > 0)
394 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
398 if (it->second->GetTxBufferSizeInBytes() > 0)
410 NS_LOG_FUNCTION(
this);
414 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
416 NS_ASSERT(it->second !=
nullptr);
417 Ptr<SatQueue> queue = it->second->GetQueue();
418 NS_ASSERT(queue !=
nullptr);
419 sum += queue->GetNBytes();
428 NS_LOG_FUNCTION(
this);
432 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
434 NS_ASSERT(it->second !=
nullptr);
435 Ptr<SatQueue> queue = it->second->GetQueue();
436 NS_ASSERT(queue !=
nullptr);
437 sum += queue->GetNPackets();
446 NS_LOG_FUNCTION(
this << &cb);
453 NS_LOG_FUNCTION(
this << &cb);
461 NS_LOG_FUNCTION(
this << address);
468 NS_LOG_FUNCTION(
this << address);
475 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.
SatLinkDir_t
Link direction used for packet tracing.
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.
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.
Class to store topology of the whole system.
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.