29 #include <ns3/boolean.h>
31 #include <ns3/nstime.h>
32 #include <ns3/packet.h>
33 #include <ns3/pointer.h>
34 #include <ns3/simulator.h>
35 #include <ns3/singleton.h>
36 #include <ns3/trace-source-accessor.h>
37 #include <ns3/uinteger.h>
39 NS_LOG_COMPONENT_DEFINE(
"SatMac");
44 NS_OBJECT_ENSURE_REGISTERED(SatMac);
52 .AddConstructor<SatMac>()
53 .AddAttribute(
"EnableStatisticsTags",
54 "If true, some tags will be added to each transmitted packet to assist "
55 "with statistics computation",
59 .AddAttribute(
"NcrVersion2",
60 "NCR version used (false for 1, true for 2)",
64 .AddTraceSource(
"PacketTrace",
67 "ns3::SatTypedefs::PacketTraceCallback")
71 "ns3::SatTypedefs::PacketSenderAddressCallback")
72 .AddTraceSource(
"RxDelay",
73 "A packet is received with delay information",
75 "ns3::SatTypedefs::PacketDelayAddressCallback")
76 .AddTraceSource(
"RxLinkDelay",
77 "A packet is received with link delay information",
79 "ns3::SatTypedefs::PacketDelayAddressCallback")
80 .AddTraceSource(
"RxJitter",
81 "A packet is received with jitter information",
83 "ns3::SatTypedefs::PacketJitterAddressCallback")
84 .AddTraceSource(
"RxLinkJitter",
85 "A packet is received with link jitter information",
87 "ns3::SatTypedefs::PacketJitterAddressCallback")
88 .AddTraceSource(
"BeamServiceTime",
89 "A beam was disabled. Transmits length of last beam service time.",
91 "ns3::SatTypedefs::ServiceTimeCallback");
96 : m_isStatisticsTagsEnabled(false),
98 m_routingUpdateCallback(),
100 m_handoverModule(nullptr),
102 m_beamEnabledTime(Seconds(0)),
104 m_forwardLinkRegenerationMode(
105 Singleton<
SatTopology>::Get()->GetForwardLinkRegenerationMode()),
106 m_returnLinkRegenerationMode(Singleton<
SatTopology>::Get()->GetReturnLinkRegenerationMode()),
107 m_isRegenerative(false),
108 m_satelliteAddress(),
111 NS_LOG_FUNCTION(
this);
116 : m_isStatisticsTagsEnabled(false),
118 m_routingUpdateCallback(),
122 m_handoverModule(nullptr),
124 m_beamEnabledTime(Seconds(0)),
126 m_forwardLinkRegenerationMode(
127 Singleton<
SatTopology>::Get()->GetForwardLinkRegenerationMode()),
128 m_returnLinkRegenerationMode(Singleton<
SatTopology>::Get()->GetReturnLinkRegenerationMode()),
129 m_isRegenerative(false),
130 m_satelliteAddress(),
133 NS_LOG_FUNCTION(
this);
138 NS_LOG_FUNCTION(
this);
144 NS_LOG_FUNCTION(
this);
164 NS_LOG_FUNCTION(
this << nodeInfo);
165 NS_LOG_INFO(
"Node (id)= " << nodeInfo->GetNodeId()
166 <<
" Node (type)= " << nodeInfo->GetNodeType()
167 <<
" Address= " << nodeInfo->GetMacAddress());
174 NS_LOG_FUNCTION(
this << msg);
184 NS_FATAL_ERROR(
"Reserve control message (m_reserveCtrlCallback) callback is NULL!");
192 NS_LOG_FUNCTION(
this << sendId);
201 NS_FATAL_ERROR(
"Write control message (m_writeCtrlCallback) callback is NULL!");
209 NS_LOG_FUNCTION(
this);
215 NS_LOG_FUNCTION(
this);
224 NS_LOG_FUNCTION(
this);
242 for (SatPhy::PacketContainer_t::const_iterator it = packets.begin(); it != packets.end();
246 if (!(*it)->PeekPacketTag(timeTag))
252 if (!(*it)->PeekPacketTag(linkTimeTag))
266 NS_LOG_FUNCTION(
this);
274 for (SatPhy::PacketContainer_t::const_iterator it = packets.begin(); it != packets.end();
278 bool success = (*it)->RemovePacketTag(mTag);
284 (*it)->AddPacketTag(mTag);
295 for (SatPhy::PacketContainer_t::const_iterator it = packets.begin(); it != packets.end(); ++it)
298 bool success = (*it)->RemovePacketTag(cTag);
310 (*it)->AddPacketTag(cTag);
316 uint8_t lastSOFSize =
m_ncrV2 ? 3 : 1;
317 ncrMsg->SetNcrDate(
m_lastSOF.size() == lastSOFSize
318 ?
m_lastSOF.front().GetNanoSeconds() * 0.027
331 NS_LOG_FUNCTION(
this);
335 for (SatPhy::PacketContainer_t::const_iterator it1 = packets.begin(); it1 != packets.end();
340 bool mSuccess = (*it1)->PeekPacketTag(macTag);
343 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
349 if (destAddress ==
m_nodeInfo->GetMacAddress())
353 bool isTaggedWithAddress =
false;
354 ByteTagIterator it2 = (*it1)->GetByteTagIterator();
356 while (!isTaggedWithAddress && it2.HasNext())
358 ByteTagIterator::Item item = it2.Next();
362 NS_LOG_DEBUG(
this <<
" contains a SatAddressTag tag:"
363 <<
" start=" << item.GetStart()
364 <<
" end=" << item.GetEnd());
366 item.GetTag(addrTag);
368 isTaggedWithAddress =
true;
375 if ((*it1)->RemovePacketTag(timeTag))
377 NS_LOG_DEBUG(
this <<
" contains a SatMacTimeTag tag");
388 if ((*it1)->RemovePacketTag(linkTimeTag))
390 NS_LOG_DEBUG(
this <<
" contains a SatMacLinkTimeTag tag");
409 NS_LOG_INFO(
this << handoverModule);
417 NS_LOG_FUNCTION(
this << &cb);
424 NS_LOG_FUNCTION(
this << &cb);
431 NS_LOG_FUNCTION(
this << &cb);
438 NS_LOG_FUNCTION(
this << &cb);
445 NS_LOG_FUNCTION(
this << &cb);
452 NS_LOG_FUNCTION(
this << &cb);
459 NS_LOG_FUNCTION(
this << &cb);
466 NS_LOG_FUNCTION(
this << &cb);
474 NS_LOG_FUNCTION(
this << &cb);
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).
@ SAT_NCR_CTRL_MSG
SAT_NCR_CTRL_MSG.
virtual uint32_t GetMsgId() const
Get message type specific identifier.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
virtual void SetMsgId(uint32_t msgId)
Set message type specific identifier.
Callback< void > UpdateIslCallback
Callback to update ISL routes when handovers are performed.
TracedCallback< const Time &, const Address & > m_rxJitterTrace
Traced callback for all received packets, including jitter information and the address of the senders...
SatMac::TransmitCallback m_txCallback
The lower layer packet transmit callback.
void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
void SetBeamSchedulerCallback(SatMac::BeamSchedulerCallback cb)
Set the beam scheduler callback.
uint32_t ReserveIdAndStoreCtrlMsgToContainer(Ptr< SatControlMessage > msg)
Reserve id and store the control message.
TracedCallback< Time > m_beamServiceTrace
Traced callback for beam being disabled and including service time.
static TypeId GetTypeId(void)
Derived from Object.
void SetReserveCtrlCallback(SatMac::ReserveCtrlMsgCallback cb)
Method to set reserve control message id callback.
virtual void SetSatelliteAddress(Address satelliteAddress)
Set the satellite MAC address on the other side of this link (if regenerative satellite).
Callback< void, SatPhy::PacketContainer_t, uint32_t, Time, SatSignalParameters::txInfo_s > TransmitCallback
Callback to send packet to lower layer.
SatMac::BeamSchedulerCallback m_beamSchedulerCallback
Callback to get the SatBeamScheduler linked to a beam ID.
Callback< Ptr< SatBeamScheduler >, uint32_t, uint32_t > BeamSchedulerCallback
Callback to get the SatBeamScheduler from the beam ID for handover.
void SetTransmitCallback(SatMac::TransmitCallback cb)
Method to set transmit callback.
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
Time m_beamEnabledTime
Time of the last beam enable event.
SatMac::RoutingUpdateCallback m_routingUpdateCallback
Callback to update routing and ARP tables after a beam handover.
std::queue< Ptr< SatNcrMessage > > m_ncrMessagesToSend
List of NCR control messages created but not sent yet.
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.
SatMac::SendCtrlMsgCallback m_sendCtrlCallback
The send control message callback.
void SetTimeTag(SatPhy::PacketContainer_t packets)
Set SatMacTimeTag of packets.
Callback< uint32_t, Ptr< SatControlMessage > > ReserveCtrlMsgCallback
Callback to reserve an id and initially store the control message.
Address m_satelliteAddress
MAC address of satellite on other side of the link.
virtual void Enable()
Enable the MAC layer, i.e.
SatMac::LoraReceiveCallback m_rxLoraCallback
The upper layer package receive callback.
void SetSendCtrlCallback(SatMac::SendCtrlMsgCallback cb)
Method to set send control message callback.
virtual void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
void DoDispose(void)
Dispose of SatMac.
virtual void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t flowIndex)
Receive a queue event:
TracedCallback< const Time &, const Address & > m_rxLinkJitterTrace
Traced callback for all received packets, including link jitter information and the address of the se...
TracedCallback< const Time &, const Address & > m_rxDelayTrace
Traced callback for all received packets, including delay information and the address of the senders.
Time m_lastDelay
Last delay measurement.
Callback< void, Ptr< const Packet > > LoraReceiveCallback
Callback to receive packet by upper layer.
~SatMac()
Destroy a SatMac.
void SetRoutingUpdateCallback(SatMac::RoutingUpdateCallback cb)
Method to set the routing update callback.
SatMac::ReceiveCallback m_rxCallback
The upper layer package receive callback.
bool m_ncrV2
Use of version 2 of NCR dates.
void SetUpdateIslCallback(SatMac::UpdateIslCallback cb)
Method to set update ISL callback.
bool m_isRegenerative
Indicate if satellite is regeneration (at least LINK level) for TX.
Callback< void, Address, Address > RoutingUpdateCallback
Callback to update routing and ARP tables after handover.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced callback for all received packets, including the address of the senders.
Callback< void, Ptr< Packet >, Mac48Address, Mac48Address > ReceiveCallback
Callback to receive packet by upper layer.
Ptr< SatHandoverModule > m_handoverModule
Module used to perform handovers.
void SetReadCtrlCallback(SatMac::ReadCtrlMsgCallback cb)
Method to set read control message callback.
void SetHandoverModule(Ptr< SatHandoverModule > handoverModule)
Set the handover module.
bool m_txEnabled
Flag indicating whether the MAC is enabled, i.e.
TracedCallback< const Time &, const Address & > m_rxLinkDelayTrace
Traced callback for all received packets, including link delay information and the address of the sen...
SatMac::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
Callback< uint32_t, uint32_t > SendCtrlMsgCallback
Callback to send a control message and allocate a recv ID for it.
SatMac()
Construct a SatMac.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
void SetLoraReceiveCallback(SatMac::LoraReceiveCallback cb)
Method to set receive callback.
uint32_t SendCtrlMsgFromContainer(uint32_t sendId)
Send the control message from the container.
Time m_lastLinkDelay
Last delay measurement for link.
Callback< Ptr< SatControlMessage >, uint32_t > ReadCtrlMsgCallback
Callback to read control messages from container storing control messages.
void SetReceiveCallback(SatMac::ReceiveCallback cb)
Method to set receive callback.
SatMac::ReserveCtrlMsgCallback m_reserveCtrlCallback
The reserve control message id callback.
virtual void Disable()
Disable the MAC layer, i.e.
virtual void SendPacket(SatPhy::PacketContainer_t packets, uint32_t carrierId, Time duration, SatSignalParameters::txInfo_s txInfo)
Send packets to lower layer by using a callback.
std::queue< Time > m_lastSOF
Store last 3 SOF date for Forward messages, to insert in NCR packets.
SatMac::UpdateIslCallback m_updateIslCallback
The update ISL routes callback.
Time tag used to identify the time when packet is enqueued at MAC on current link level.
Time GetSenderLinkTimestamp(void) const
Get sender time stamp of this tag.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
Time tag used to identify the time when packet is enqueued at MAC level.
Time GetSenderTimestamp(void) const
Get sender time stamp of this tag.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Class to store topology of the whole system.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the packet specific Tx information.