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>
42 NS_LOG_COMPONENT_DEFINE(
"SatUtLlc");
47 NS_OBJECT_ENSURE_REGISTERED(SatLlc);
52 static TypeId tid = TypeId(
"ns3::SatUtLlc")
54 .AddConstructor<SatUtLlc>()
55 .AddAttribute(
"SatRequestManager",
56 "The request manager of this UT.",
60 MakePointerChecker<SatRequestManager>());
67 NS_LOG_FUNCTION(
this);
73 :
SatLlc(forwardLinkRegenerationMode, returnLinkRegenerationMode),
76 NS_LOG_FUNCTION(
this);
81 NS_LOG_FUNCTION(
this);
87 NS_LOG_FUNCTION(
this);
103 NS_LOG_FUNCTION(
this << packet << dest << (uint32_t)flowId);
104 NS_LOG_INFO(
"p=" << packet);
105 NS_LOG_INFO(
"dest=" << dest);
106 NS_LOG_INFO(
"UID is " << packet->GetUid());
108 Mac48Address destMacAddress;
111 destMacAddress = Mac48Address::ConvertFrom(
m_gwAddress);
115 destMacAddress = Mac48Address::ConvertFrom(dest);
122 packet->AddPacketTag(groundStationAddressTag);
128 if (destMacAddress.IsGroup())
136 key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
144 key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(),
151 EncapContainer_t::iterator it =
m_encaps.find(key);
168 packet->AddPacketTag(addressE2ETag);
170 it->second->EnquePdu(packet, destMacAddress);
190 uint32_t& nextMinTxO)
192 NS_LOG_FUNCTION(
this << utAddr << bytes << (uint32_t)rcIndex);
202 key = Create<EncapKey>(utAddr,
m_gwAddress, rcIndex);
205 EncapContainer_t::iterator it =
m_encaps.find(key);
209 packet = it->second->NotifyTxOpportunity(bytes, bytesLeft, nextMinTxO);
239 NS_LOG_FUNCTION(
this);
243 Ptr<SatRequestManager>
246 NS_LOG_FUNCTION(
this);
254 NS_LOG_FUNCTION(
this);
258 for (EncapContainer_t::iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
269 NS_LOG_FUNCTION(
this << maxPacketSizeBytes);
272 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
274 packets += it->second->GetQueue()->GetNumSmallerPackets(maxPacketSizeBytes);
282 NS_LOG_FUNCTION(
this);
297 NS_LOG_FUNCTION(
this << key->m_encapAddress << key->m_decapAddress
298 << (uint32_t)(key->m_flowId));
300 Ptr<SatBaseEncapsulator> utEncap;
305 utEncap = CreateObject<SatBaseEncapsulator>(key->m_encapAddress,
307 key->m_sourceE2EAddress,
308 key->m_destE2EAddress,
313 utEncap = CreateObject<SatReturnLinkEncapsulatorArq>(key->m_encapAddress,
315 key->m_sourceE2EAddress,
316 key->m_destE2EAddress,
322 utEncap = CreateObject<SatReturnLinkEncapsulator>(key->m_encapAddress,
324 key->m_sourceE2EAddress,
325 key->m_destE2EAddress,
330 Ptr<SatQueue> queue = providedQueue;
333 queue = CreateObject<SatQueue>(key->m_flowId);
335 queue->AddQueueEventCallback(
344 utEncap->SetQueue(queue);
346 NS_LOG_INFO(
"Create encapsulator with key (" << key->m_encapAddress <<
", "
347 << key->m_decapAddress <<
", "
348 << (uint32_t)key->m_flowId <<
")");
351 std::pair<EncapContainer_t::iterator, bool> result =
352 m_encaps.insert(std::make_pair(key, utEncap));
353 if (result.second ==
false)
355 NS_FATAL_ERROR(
"Insert to map with key (" << key->m_encapAddress <<
", "
356 << key->m_decapAddress <<
", "
357 << (uint32_t)key->m_flowId <<
") failed!");
364 NS_LOG_FUNCTION(
this << key->m_encapAddress << key->m_decapAddress
365 << (uint32_t)(key->m_flowId));
367 Ptr<SatBaseEncapsulator> utDecap;
371 utDecap = CreateObject<SatGenericStreamEncapsulatorArq>(key->m_encapAddress,
373 key->m_sourceE2EAddress,
374 key->m_destE2EAddress,
380 utDecap = CreateObject<SatGenericStreamEncapsulator>(key->m_encapAddress,
382 key->m_sourceE2EAddress,
383 key->m_destE2EAddress,
391 NS_LOG_INFO(
"Create decapsulator with key (" << key->m_encapAddress <<
", "
392 << key->m_decapAddress <<
", "
393 << (uint32_t)key->m_flowId <<
")");
396 std::pair<EncapContainer_t::iterator, bool> result =
397 m_decaps.insert(std::make_pair(key, utDecap));
398 if (result.second ==
false)
400 NS_FATAL_ERROR(
"Insert to map with key (" << key->m_encapAddress <<
", "
401 << key->m_decapAddress <<
", "
402 << (uint32_t)key->m_flowId <<
") failed!");
409 NS_LOG_FUNCTION(
this << utAddress);
413 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
415 if (it->first->m_encapAddress == utAddress)
417 NS_ASSERT(it->second !=
nullptr);
418 Ptr<SatQueue> queue = it->second->GetQueue();
419 NS_ASSERT(queue !=
nullptr);
420 sum += queue->GetNBytes();
430 NS_LOG_FUNCTION(
this << utAddress);
434 for (EncapContainer_t::const_iterator it =
m_encaps.begin(); it !=
m_encaps.end(); ++it)
436 if (it->first->m_encapAddress == utAddress)
438 NS_ASSERT(it->second !=
nullptr);
439 Ptr<SatQueue> queue = it->second->GetQueue();
440 NS_ASSERT(queue !=
nullptr);
441 sum += queue->GetNPackets();
451 NS_LOG_FUNCTION(
this);
474 NS_LOG_FUNCTION(
this << &cb);
482 NS_LOG_FUNCTION(
this << address);
487 for (uint8_t rcIndex = 0;; ++rcIndex)
491 EncapContainer_t::iterator it =
m_encaps.find(peek);
495 Ptr<EncapKey> key = Create<EncapKey>(
m_nodeInfo->GetMacAddress(), address, rcIndex);
498 NS_LOG_INFO(
"Queue from key "
499 << peek->m_encapAddress <<
", " << peek->m_decapAddress <<
", "
500 << (uint32_t)(peek->m_flowId) <<
" moved to key " << key->m_encapAddress
501 <<
", " << 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.
RegenerationMode_t
The regeneration mode used in satellites.
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, should not be used.
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.