34 #include <ns3/address.h>
35 #include <ns3/boolean.h>
37 #include <ns3/mac48-address.h>
38 #include <ns3/packet.h>
39 #include <ns3/pointer.h>
40 #include <ns3/simulator.h>
41 #include <ns3/singleton.h>
42 #include <ns3/uinteger.h>
44 NS_LOG_COMPONENT_DEFINE(
"SatGwMac");
49 NS_OBJECT_ENSURE_REGISTERED(SatGwMac);
55 TypeId(
"ns3::SatGwMac")
57 .AddConstructor<SatGwMac>()
58 .AddAttribute(
"Scheduler",
59 "Forward link scheduler used by this Sat GW MAC.",
62 MakePointerChecker<SatFwdLinkScheduler>())
63 .AddAttribute(
"GuardTime",
64 "Guard time in forward link",
65 TimeValue(MicroSeconds(1)),
68 .AddAttribute(
"NcrBroadcastPeriod",
69 "Interval between two broadcast of NCR dates",
70 TimeValue(MilliSeconds(100)),
73 .AddAttribute(
"UseCmt",
74 "Use CMT control messages to correct time on the UTs",
78 .AddAttribute(
"CmtPeriodMin",
79 "Minimum interval between two CMT control messages for a same UT",
80 TimeValue(MilliSeconds(550)),
83 .AddAttribute(
"SendNcrBroadcast",
84 "Broadcast NCR messages to all UTs",
88 .AddTraceSource(
"BBFrameTxTrace",
89 "Trace for transmitted BB Frames.",
91 "ns3::SatBbFrame::BbFrameCallback");
98 NS_LOG_FUNCTION(
this);
106 m_guardTime(MicroSeconds(1)),
107 m_ncrInterval(MilliSeconds(100)),
110 m_cmtPeriodMin(MilliSeconds(550)),
113 NS_LOG_FUNCTION(
this);
115 NS_FATAL_ERROR(
"SatUtMac::SatGwMac - Constructor not in use");
122 :
SatMac(satId, beamId, forwardLinkRegenerationMode, returnLinkRegenerationMode),
124 m_guardTime(MicroSeconds(1)),
125 m_ncrInterval(MilliSeconds(100)),
128 m_cmtPeriodMin(MilliSeconds(550)),
131 NS_LOG_FUNCTION(
this);
136 NS_LOG_FUNCTION(
this);
142 NS_LOG_FUNCTION(
this);
156 NS_LOG_FUNCTION(
this);
160 NS_FATAL_ERROR(
"Scheduler not set for GW MAC!!!");
181 NS_LOG_FUNCTION(
this);
198 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
202 bool mSuccess = (*i)->PeekPacketTag(macTag);
205 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
208 mSuccess = (*i)->PeekPacketTag(addressE2ETag);
211 NS_FATAL_ERROR(
"Address E2E tag was not found from the packet!");
216 NS_LOG_INFO(
"Receiver " <<
m_nodeInfo->GetMacAddress());
222 if (destAddress ==
m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast())
226 bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
240 beamId = rxParams->m_beamId;
241 satId = rxParams->m_satId;
247 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
249 NS_FATAL_ERROR(
"SatUplinkInfoTag not found!");
252 satId = satUplinkInfoTag.
GetSatId();
256 NS_FATAL_ERROR(
"Unknown regeneration mode");
262 NS_FATAL_ERROR(
"A control message received with not valid msg type!");
276 "Packet intended for others received by MAC: " <<
m_nodeInfo->GetMacAddress());
285 if (rxParams->m_txInfo.waveformId == 2)
288 rxParams->m_duration,
297 if (rxParams->m_txInfo.waveformId == 2)
299 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end();
303 if ((*i)->PeekPacketTag(ctrlTag))
309 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
311 NS_FATAL_ERROR(
"SatUplinkInfoTag not found !");
314 uint32_t beamId = satUplinkInfoTag.
GetBeamId();
315 uint32_t satId = satUplinkInfoTag.
GetSatId();
317 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
325 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
328 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
330 NS_FATAL_ERROR(
"SatUplinkInfoTag not found !");
333 uint32_t beamId = satUplinkInfoTag.
GetBeamId();
334 uint32_t satId = satUplinkInfoTag.
GetSatId();
335 bool isControl = satUplinkInfoTag.
IsControl();
339 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
346 NS_FATAL_ERROR(
"Unknown regeneration mode, or received");
354 NS_LOG_FUNCTION(
this);
359 uint8_t lastSOFSize =
m_ncrV2 ? 3 : 1;
370 std::pair<Ptr<SatBbFrame>,
const Time> bbFrameInfo =
m_fwdScheduler->GetNextFrame();
371 Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
372 txDuration = bbFrameInfo.second;
392 txInfo.
modCod = bbFrame->GetModcod();
393 txInfo.
sliceId = bbFrame->GetSliceId();
394 txInfo.
frameType = bbFrame->GetFrameType();
410 NS_LOG_INFO(
"TX is disabled, thus nothing is transmitted!");
427 NS_LOG_FUNCTION(
this << tbtp);
429 uint32_t superframeCounter = tbtp->GetSuperframeCounter();
433 m_tbtps[superframeCounter] = std::vector<Ptr<SatTbtpMessage>>();
435 m_tbtps[superframeCounter].push_back(tbtp);
443 m_tbtps.erase(superframeCounter);
449 NS_LOG_FUNCTION(
this);
459 NS_LOG_FUNCTION(
this << packet << beamId);
463 packet->PeekPacketTag(macTag);
466 packet->PeekPacketTag(addressE2ETag);
470 bool cSuccess = packet->PeekPacketTag(ctrlTag);
474 NS_FATAL_ERROR(
"SatControlMsgTag not found in the packet!");
480 uint32_t msgId = ctrlTag.
GetMsgId();
485 Mac48Address sourceAddress;
498 NS_FATAL_ERROR(
"Unknown regeneration mode");
500 m_fwdScheduler->CnoInfoUpdated(sourceAddress, crMsg->GetCnoEstimate());
514 std::stringstream msg;
515 msg <<
"Control message " << ctrlTag.
GetMsgType()
516 <<
" is not found from the RTN link control msg container!";
517 msg <<
" at: " << Now().GetSeconds() <<
"s";
521 packet->RemovePacketTag(macTag);
522 packet->RemovePacketTag(addressE2ETag);
523 packet->RemovePacketTag(ctrlTag);
528 uint32_t msgId = ctrlTag.
GetMsgId();
529 Ptr<SatCnoReportMessage> cnoReport =
532 if (cnoReport != NULL)
535 cnoReport->GetCnoEstimate());
544 std::stringstream msg;
545 msg <<
"Control message " << ctrlTag.
GetMsgType()
546 <<
" is not found from the RTN link control msg container!";
547 msg <<
" at: " << Now().GetSeconds() <<
"s";
551 packet->RemovePacketTag(macTag);
552 packet->RemovePacketTag(addressE2ETag);
553 packet->RemovePacketTag(ctrlTag);
563 uint32_t msgId = ctrlTag.
GetMsgId();
564 Ptr<SatHandoverRecommendationMessage> handoverRecommendation =
567 if (handoverRecommendation != NULL)
569 uint32_t newBeamId = handoverRecommendation->GetRecommendedBeamId();
579 std::stringstream msg;
580 msg <<
"Control message " << ctrlTag.
GetMsgType()
581 <<
" is not found from the RTN link control msg container!";
582 msg <<
" at: " << Now().GetSeconds() <<
"s";
589 uint32_t msgId = ctrlTag.
GetMsgId();
590 Ptr<SatLogonMessage> logonMessage = DynamicCast<SatLogonMessage>(
m_readCtrlCallback(msgId));
592 if (logonMessage != NULL)
595 Callback<void, uint32_t> raChannelCallback =
606 std::stringstream msg;
607 msg <<
"Control message " << ctrlTag.
GetMsgType()
608 <<
" is not found from the RTN link control msg container!";
609 msg <<
" at: " << Now().GetSeconds() <<
"s";
619 NS_FATAL_ERROR(
"SatGwMac received a non-supported control packet!");
628 NS_LOG_FUNCTION(
this);
629 Ptr<SatNcrMessage> ncrMessage = CreateObject<SatNcrMessage>();
630 m_fwdScheduler->SendControlMsg(ncrMessage, Mac48Address::GetBroadcast());
637 Time satelliteReceptionTime,
641 NS_LOG_FUNCTION(
this << utId);
643 Time lastCmtSent = Seconds(0);
649 Time timeReceived = satelliteReceptionTime;
650 if (satelliteReceptionTime == Seconds(0))
652 timeReceived = Simulator::Now();
660 uint32_t indexClosest = 0;
661 uint32_t tbtpIndexClosest = 0;
662 uint32_t timeSlotIndexClosest = 0;
663 Time differenceClosest = Seconds(1000000);
664 std::vector<Ptr<SatTbtpMessage>> tbtpsForCurrentSF;
665 Ptr<SatTbtpMessage> tbtp;
666 for (uint32_t i = 0; i <
m_tbtps.size(); i++)
668 tbtpsForCurrentSF =
m_tbtps[i];
669 for (uint32_t tbtpIndex = 0; tbtpIndex < tbtpsForCurrentSF.size(); tbtpIndex++)
671 tbtp = tbtpsForCurrentSF[tbtpIndex];
672 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots =
673 tbtp->GetDaTimeslots(utId);
674 for (uint32_t j = 0; j < timeslots.second.size(); j++)
676 Ptr<SatTimeSlotConf> tsConf = timeslots.second[j];
679 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
683 Time slotStartTime = tsConf->GetStartTime();
684 Time difference = timeReceived - frameStartTime - slotStartTime - burstDuration;
685 if (Abs(difference) < differenceClosest)
687 differenceClosest = Abs(difference);
689 timeSlotIndexClosest = j;
690 tbtpIndexClosest = tbtpIndex;
697 if (indexClosest == 0)
702 tbtp =
m_tbtps[indexClosest][tbtpIndexClosest];
703 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots = tbtp->GetDaTimeslots(utId);
705 if (timeslots.second[timeSlotIndexClosest]->GetSlotType() == 0)
707 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
711 Time slotStartTime = timeslots.second[timeSlotIndexClosest]->GetStartTime();
713 Time difference = frameStartTime + slotStartTime + burstDuration - timeReceived;
714 int32_t differenceNcr = difference.GetMicroSeconds() * 27;
716 if (differenceNcr > 16256 || differenceNcr < -16256)
718 NS_LOG_INFO(
"Burst Time Correction outside bounds, should be at least -16256 and at "
719 "most 16256, but got "
720 << differenceNcr <<
". Forcing logoff of UT " << utId);
721 Ptr<SatLogoffMessage> logoffMsg = CreateObject<SatLogoffMessage>();
727 Ptr<SatCmtMessage> cmt = CreateObject<SatCmtMessage>();
728 cmt->SetBurstTimeCorrection(differenceNcr);
740 NS_LOG_FUNCTION(
this << utId << raChannel);
741 Ptr<SatLogonResponseMessage> logonResponse = CreateObject<SatLogonResponseMessage>();
742 logonResponse->SetRaChannel(raChannel);
749 self->SendLogonResponse(utId, raChannel);
755 NS_LOG_FUNCTION(
this << &cb);
762 NS_LOG_FUNCTION(
this << &cb);
769 NS_LOG_FUNCTION(
this << &cb);
776 NS_LOG_FUNCTION(
this << &cb);
783 NS_LOG_FUNCTION(
this << &cb);
This class implements a tag that carries the satellite MAC of GW and UT.
Mac48Address GetE2ESourceAddress(void) const
Get E2E source MAC address.
Mac48Address GetE2EDestAddress(void) const
Get E2E destination MAC address.
This class implements a tag that is used to identify control messages (packages).
SatControlMsgType_t
Definition for different types of control messages.
@ SAT_CR_CTRL_MSG
SAT_CR_CTRL_MSG.
@ SAT_ARQ_ACK
SAT_ARQ_ACK.
@ SAT_HR_CTRL_MSG
SAT_HR_CTRL_MSG.
@ SAT_CN0_REPORT
SAT_CN0_REPORT.
@ SAT_NON_CTRL_MSG
SAT_NON_CTRL_MSG.
@ SAT_LOGON_CTRL_MSG
SAT_LOGON_CTRL_MSG.
@ SAT_CMT_CTRL_MSG
SAT_CMT_CTRL_MSG.
virtual uint32_t GetMsgId() const
Get message type specific identifier.
SatControlMsgType_t GetMsgType(void) const
Get type of the control message.
@ PACKET_TYPE_DEDICATED_ACCESS
RegenerationMode_t
The regeneration mode used in satellites.
GW specific Mac class for Sat Net Devices.
void SetLogonCallback(SatGwMac::LogonCallback cb)
Method to set logon callback.
SatGwMac::HandoverCallback m_handoverCallback
Callback to query/apply handover on the terrestrial network.
Ptr< SatFwdLinkScheduler > m_fwdScheduler
Scheduler for the forward link.
void TbtpSent(Ptr< SatTbtpMessage > tbtp)
Function called when a TBTP has been sent by the SatBeamScheduler.
SatGwMac::TxOpportunityCallback m_txOpportunityCallback
Callback to notify the txOpportunity to upper layer Returns a packet Attributes: payload in bytes.
void SendLogonResponse(Address utId, uint32_t raChannel)
std::map< Address, Time > m_lastCmtSent
Time of last CMT sending for each UT.
void SetRemoveUtCallback(SatGwMac::RemoveUtCallback cb)
Method to set callback for UT removing.
Time m_cmtPeriodMin
Minimum interval between two CMT control messages for a same UT.
Callback< void, Address, uint32_t, uint32_t > RemoveUtCallback
Callback to indicate NCC a UT needs to be removed.
void SetFwdScheduler(Ptr< SatFwdLinkScheduler > fwdScheduler)
Method to set forward link scheduler.
static TypeId GetTypeId(void)
Get the type ID.
Callback< void, Address, uint32_t, uint32_t, uint32_t > HandoverCallback
Callback to query/apply handover on the terrestrial network.
SatGwMac::CrReceiveCallback m_crReceiveCallback
Capacity request receive callback.
bool m_broadcastNcr
Broadcast NCR messages to all UTs.
static void SendLogonResponseHelper(SatGwMac *self, Address utId, uint32_t raChannel)
void SetHandoverCallback(SatGwMac::HandoverCallback cb)
Method to set handover callback.
void SetCrReceiveCallback(SatGwMac::CrReceiveCallback cb)
Method to set read control message callback.
SatGwMac::LogonCallback m_logonCallback
Callback to log a terminal on.
Callback< void, Address, uint32_t, uint32_t, Callback< void, uint32_t > > LogonCallback
Callback to register UT logon.
void StartNcrTransmission()
Send a NCR packet to the UTs.
void ReceiveSignalingPacket(Ptr< Packet > packet, uint32_t satId, uint32_t beamId)
Signaling packet receiver, which handles all the signaling packet receptions.
~SatGwMac()
Destroy a SatGwMac.
SatGwMac()
Default constructor, which is not used.
TracedCallback< Ptr< SatBbFrame > > m_bbFrameTxTrace
Trace for transmitted BB frames.
void SendCmtMessage(Address utId, Time burstDuration, Time satelliteReceptionTime, uint32_t satId, uint32_t beamId)
void StartTransmission(uint32_t carrierId)
Start sending a Packet Down the Wire.
Callback< void, uint32_t, uint32_t, Address, Ptr< SatCrMessage > > CrReceiveCallback
Callback to receive capacity request (CR) messages.
SatGwMac::RemoveUtCallback m_removeUtCallback
Callback to indicate NCC a UT needs to be removed.
SatGwMac::ControlMessageReceivedCallback m_controlMessageReceivedCallback
Callback to indicate NCC a control burst has been received.
std::map< uint32_t, std::vector< Ptr< SatTbtpMessage > > > m_tbtps
List of TBTPs sent to UTs.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive packet from lower layer.
void SetControlMessageReceivedCallback(SatGwMac::ControlMessageReceivedCallback cb)
Method to set callback for control burst reception.
bool m_useCmt
Use CMT control messages to correct time on the UTs.
void RemoveTbtp(uint32_t superframeCounter)
Function used to clear old TBTP.
void StartPeriodicTransmissions()
Starts periodical transmissions.
Time m_ncrInterval
Interval between two broadcast of NCR dates.
Callback< void, Address, uint32_t, uint32_t > ControlMessageReceivedCallback
Callback to inform NCC a control burst has been received.
TypeId GetInstanceTypeId(void) const
Derived from Object.
Time m_guardTime
Guard time for BB frames.
@ LOG_WARNING
LOG_WARNING.
Base MAC class for SatNetDevices.
void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
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.
Address m_satelliteAddress
MAC address of satellite on other side of the link.
void DoDispose(void)
Dispose of SatMac.
SatMac::ReceiveCallback m_rxCallback
The upper layer package receive callback.
bool m_ncrV2
Use of version 2 of NCR dates.
bool m_txEnabled
Flag indicating whether the MAC is enabled, i.e.
SatMac::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
SatEnums::RegenerationMode_t m_forwardLinkRegenerationMode
Regeneration mode on forward link.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
SatEnums::RegenerationMode_t m_returnLinkRegenerationMode
Regeneration mode on return link.
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.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
Mac48Address GetSourceAddress(void) const
Get source MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
@ SLOT_TYPE_C
Control slot.
Tag to store uplink phy info that need to be forwarded to the downlink.
bool IsControl(void) const
Get if packet is a control packet.
uint32_t GetBeamId(void) const
Get the UT beam ID.
uint32_t GetSatId(void) const
Get the UT sat ID.
Time GetSatelliteReceptionTime(void) const
Get satellite reception time of packet.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the packet specific Tx information.
SatEnums::PacketType_t packetType
SatEnums::SatBbFrameType_t frameType
SatEnums::SatModcod_t modCod