35 #include <ns3/address.h>
37 #include <ns3/mac48-address.h>
38 #include <ns3/packet.h>
39 #include <ns3/pointer.h>
40 #include <ns3/simulator.h>
45 NS_LOG_COMPONENT_DEFINE(
"SatUtLlc");
50 NS_OBJECT_ENSURE_REGISTERED(SatLlc);
55 static TypeId tid = TypeId(
"ns3::SatUtLlc")
57 .AddConstructor<SatUtLlc>()
58 .AddAttribute(
"SatRequestManager",
59 "The request manager of this UT.",
63 MakePointerChecker<SatRequestManager>());
71 NS_LOG_FUNCTION(
this);
76 NS_LOG_FUNCTION(
this);
82 NS_LOG_FUNCTION(
this);
98 NS_LOG_FUNCTION(
this << packet << dest << (uint32_t)flowId);
99 NS_LOG_INFO(
"p=" << packet);
100 NS_LOG_INFO(
"dest=" << dest);
101 NS_LOG_INFO(
"UID is " << packet->GetUid());
103 Mac48Address destMacAddress;
106 destMacAddress = Mac48Address::ConvertFrom(
m_gwAddress);
110 destMacAddress = Mac48Address::ConvertFrom(dest);
117 packet->AddPacketTag(groundStationAddressTag);
123 if (destMacAddress.IsGroup())
131 key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
139 key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
146 EncapContainer_t::iterator it =
m_encaps.find(key);
163 packet->AddPacketTag(addressE2ETag);
165 it->second->EnquePdu(packet, destMacAddress);
185 uint32_t& nextMinTxO)
187 NS_LOG_FUNCTION(
this << utAddr << bytes << (uint32_t)rcIndex);
197 key = Create<EncapKey>(utAddr,
m_gwAddress, rcIndex);
200 EncapContainer_t::iterator it =
m_encaps.find(key);
204 packet = it->second->NotifyTxOpportunity(bytes, bytesLeft, nextMinTxO);
234 NS_LOG_FUNCTION(
this);
238 Ptr<SatRequestManager>
241 NS_LOG_FUNCTION(
this);
249 NS_LOG_FUNCTION(
this);
253 for (EncapContainer_t::iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
264 NS_LOG_FUNCTION(
this << maxPacketSizeBytes);
267 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
269 packets += it->second->GetQueue()->GetNumSmallerPackets(maxPacketSizeBytes);
277 NS_LOG_FUNCTION(
this);
292 NS_LOG_FUNCTION(
this << key->m_encapAddress << key->m_decapAddress
293 << (uint32_t)(key->m_flowId));
295 Ptr<SatBaseEncapsulator> utEncap;
300 utEncap = CreateObject<SatBaseEncapsulator>(key->m_encapAddress,
302 key->m_sourceE2EAddress,
303 key->m_destE2EAddress,
308 utEncap = CreateObject<SatReturnLinkEncapsulatorArq>(key->m_encapAddress,
310 key->m_sourceE2EAddress,
311 key->m_destE2EAddress,
317 utEncap = CreateObject<SatReturnLinkEncapsulator>(key->m_encapAddress,
319 key->m_sourceE2EAddress,
320 key->m_destE2EAddress,
325 Ptr<SatQueue> queue = providedQueue;
328 queue = CreateObject<SatQueue>(key->m_flowId);
330 queue->AddQueueEventCallback(
339 utEncap->SetQueue(queue);
341 NS_LOG_INFO(
"Create encapsulator with key (" << key->m_encapAddress <<
", "
342 << key->m_decapAddress <<
", "
343 << (uint32_t)key->m_flowId <<
")");
346 std::pair<EncapContainer_t::iterator, bool> result =
347 m_encaps.insert(std::make_pair(key, utEncap));
348 if (result.second ==
false)
350 NS_FATAL_ERROR(
"Insert to map with key (" << key->m_encapAddress <<
", "
351 << key->m_decapAddress <<
", "
352 << (uint32_t)key->m_flowId <<
") failed!");
359 NS_LOG_FUNCTION(
this << key->m_encapAddress << key->m_decapAddress
360 << (uint32_t)(key->m_flowId));
362 Ptr<SatBaseEncapsulator> utDecap;
366 utDecap = CreateObject<SatGenericStreamEncapsulatorArq>(key->m_encapAddress,
368 key->m_sourceE2EAddress,
369 key->m_destE2EAddress,
375 utDecap = CreateObject<SatGenericStreamEncapsulator>(key->m_encapAddress,
377 key->m_sourceE2EAddress,
378 key->m_destE2EAddress,
386 NS_LOG_INFO(
"Create decapsulator with key (" << key->m_encapAddress <<
", "
387 << key->m_decapAddress <<
", "
388 << (uint32_t)key->m_flowId <<
")");
391 std::pair<EncapContainer_t::iterator, bool> result =
392 m_decaps.insert(std::make_pair(key, utDecap));
393 if (result.second ==
false)
395 NS_FATAL_ERROR(
"Insert to map with key (" << key->m_encapAddress <<
", "
396 << key->m_decapAddress <<
", "
397 << (uint32_t)key->m_flowId <<
") failed!");
404 NS_LOG_FUNCTION(
this << utAddress);
408 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
410 if (it->first->m_encapAddress == utAddress)
412 NS_ASSERT(it->second !=
nullptr);
413 Ptr<SatQueue> queue = it->second->GetQueue();
414 NS_ASSERT(queue !=
nullptr);
415 sum += queue->GetNBytes();
425 NS_LOG_FUNCTION(
this << utAddress);
429 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
431 if (it->first->m_encapAddress == utAddress)
433 NS_ASSERT(it->second !=
nullptr);
434 Ptr<SatQueue> queue = it->second->GetQueue();
435 NS_ASSERT(queue !=
nullptr);
436 sum += queue->GetNPackets();
446 NS_LOG_FUNCTION(
this);
469 NS_LOG_FUNCTION(
this << &cb);
477 NS_LOG_FUNCTION(
this << address);
482 for (uint8_t rcIndex = 0;; ++rcIndex)
486 EncapContainer_t::iterator it =
m_encaps.find(peek);
490 Ptr<EncapKey> key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(), address, rcIndex);
493 NS_LOG_INFO(
"Queue from key "
494 << peek->m_encapAddress <<
", " << peek->m_decapAddress <<
", "
495 << (uint32_t)(peek->m_flowId) <<
" moved to key " << key->m_encapAddress
496 <<
", " << key->m_decapAddress <<
", " << (uint32_t)(key->m_flowId));
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.
SatLinkDir_t
Link direction used for packet tracing.
Tag to store ground station destination address.
SatLlc base class holds the UT specific SatBaseEncapsulator instances, which are responsible of fragm...
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.
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.
uint32_t m_additionalHeaderSize
Additional header size to add to encapsulation/decapsulation.
bool m_fwdLinkArqEnabled
Is FWD link ARQ enabled.
SatBaseEncapsulator::SendCtrlCallback m_sendCtrlCallback
Callback to send control messages.
SatEnums::RegenerationMode_t m_returnLinkRegenerationMode
Regeneration mode on return link.
EncapContainer_t m_decaps
Map of decapsulator base pointers.
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:
Mac48Address m_gwAddress
GW address.
virtual void DoDispose()
Dispose of this class instance.
EncapContainer_t m_encaps
Map of encapsulator base pointers.
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.
Mac48Address m_satelliteAddress
SAT address, used in case of network regeneration.
bool m_rtnLinkArqEnabled
Is RTN link ARQ enabled.
Callback< void, SatQueue::QueueEvent_t, uint8_t > QueueEventCallback
Callback to indicate queue related event.
QueueStats_t GetQueueStatistics(bool reset)
GetQueueStatistics returns a struct of KPIs.
void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event.
Callback< SatQueue::QueueStats_t, bool > QueueCallback
Callback to fetch queue statistics.
void SetQueueStatisticsCallbacks()
Set queue statistics callbacks for each UT packet queue.
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
void SetMacQueueEventCallback(SatQueue::QueueEventCallback cb)
SatQueue::QueueEventCallback m_macQueueEventCb
Callback to send queue events to e.g.
Ptr< SatRequestManager > m_requestManager
Request manager handling the capacity requests.
void SetRequestManager(Ptr< SatRequestManager > rm)
Set a request manager for UT's LLC instance.
virtual void CreateDecap(Ptr< EncapKey > key)
Virtual method to create a new decapsulator 'on-a-need-basis' dynamically.
virtual ~SatUtLlc()
Destroy a SatUtLlc.
virtual uint32_t GetNumSmallerPackets(uint32_t maxPacketSizeBytes) const
Method checks how many packets are smaller or equal in size than the maximum packets size threshold s...
SatUtLlc()
Construct a SatUtLlc.
void SetGwAddress(Mac48Address address)
Set the GW address.
virtual void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
virtual void CreateEncap(Ptr< EncapKey > key)
Virtual method to create a new encapsulator 'on-a-need-basis' dynamically.
Ptr< SatRequestManager > GetRequestManager() const
Getter for the request manager.
void DoDispose()
Dispose of SatUtLLc.
static TypeId GetTypeId(void)
Derived form Object.
virtual bool Enque(Ptr< Packet > packet, Address dest, uint8_t flowId)
Called from higher layer (SatNetDevice) to enque packet to LLC.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
virtual Ptr< Packet > NotifyTxOpportunity(uint32_t bytes, Mac48Address utAddr, uint8_t rcIndex, uint32_t &bytesLeft, uint32_t &nextMinTxO)
Called from lower layer (MAC) to inform a Tx opportunity of certain amount of bytes.
virtual void GetSchedulingContexts(std::vector< Ptr< SatSchedulingObject >> &output) const
Create and fill the scheduling objects based on LLC layer information.
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.