36#include "ns3/address.h"
37#include "ns3/boolean.h"
39#include "ns3/mac48-address.h"
40#include "ns3/packet.h"
41#include "ns3/pointer.h"
42#include "ns3/simulator.h"
43#include "ns3/singleton.h"
44#include "ns3/uinteger.h"
50NS_LOG_COMPONENT_DEFINE(
"SatGwMac");
55NS_OBJECT_ENSURE_REGISTERED(
SatGwMac);
61 TypeId(
"ns3::SatGwMac")
63 .AddConstructor<SatGwMac>()
64 .AddAttribute(
"Scheduler",
65 "Forward link scheduler used by this Sat GW MAC.",
68 MakePointerChecker<SatFwdLinkScheduler>())
69 .AddAttribute(
"GuardTime",
70 "Guard time in forward link",
71 TimeValue(MicroSeconds(1)),
74 .AddAttribute(
"NcrBroadcastPeriod",
75 "Interval between two broadcast of NCR dates",
76 TimeValue(MilliSeconds(100)),
79 .AddAttribute(
"UseCmt",
80 "Use CMT control messages to correct time on the UTs",
84 .AddAttribute(
"CmtPeriodMin",
85 "Minimum interval between two CMT control messages for a same UT",
86 TimeValue(MilliSeconds(550)),
89 .AddAttribute(
"SendNcrBroadcast",
90 "Broadcast NCR messages to all UTs",
94 .AddAttribute(
"DisableSchedulingIfNoDeviceConnected",
95 "If true, the periodic calls of StartTransmission are not called when no "
96 "devices are connected to this MAC",
100 .AddTraceSource(
"BBFrameTxTrace",
101 "Trace for transmitted BB Frames.",
103 "ns3::SatBbFrame::BbFrameCallback");
119 NS_LOG_FUNCTION(
this);
121 NS_FATAL_ERROR(
"SatUtMac::SatGwMac - Constructor not in use");
127 uint32_t feederSatId,
128 uint32_t feederBeamId)
143 NS_LOG_FUNCTION(
this);
148 NS_LOG_FUNCTION(
this);
154 NS_LOG_FUNCTION(
this);
168 NS_LOG_FUNCTION(
this);
172 NS_LOG_INFO(
"Do not start beam " <<
m_beamId <<
" because no device is connected");
178 NS_LOG_INFO(
"Beam " <<
m_beamId <<
" already enabled");
186 NS_FATAL_ERROR(
"Scheduler not set for GW MAC!!!");
210 NS_LOG_FUNCTION(
this);
227 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
231 bool mSuccess = (*i)->PeekPacketTag(macTag);
234 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
237 mSuccess = (*i)->PeekPacketTag(addressE2ETag);
240 NS_FATAL_ERROR(
"Address E2E tag was not found from the packet!");
245 NS_LOG_INFO(
"Receiver " <<
m_nodeInfo->GetMacAddress());
251 if (destAddress ==
m_nodeInfo->GetMacAddress() || destAddress.IsBroadcast())
255 bool cSuccess = (*i)->PeekPacketTag(ctrlTag);
269 beamId = rxParams->m_beamId;
270 satId = rxParams->m_satId;
276 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
278 NS_FATAL_ERROR(
"SatUplinkInfoTag not found!");
281 satId = satUplinkInfoTag.
GetSatId();
285 NS_FATAL_ERROR(
"Unknown regeneration mode");
291 NS_FATAL_ERROR(
"A control message received with not valid msg type!");
305 "Packet intended for others received by MAC: " <<
m_nodeInfo->GetMacAddress());
314 if (rxParams->m_txInfo.waveformId == 2)
317 rxParams->m_duration,
326 if (rxParams->m_txInfo.waveformId == 2)
328 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end();
332 if ((*i)->PeekPacketTag(ctrlTag))
338 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
340 NS_FATAL_ERROR(
"SatUplinkInfoTag not found !");
343 uint32_t beamId = satUplinkInfoTag.
GetBeamId();
344 uint32_t satId = satUplinkInfoTag.
GetSatId();
346 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
354 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
357 if (!(*i)->PeekPacketTag(satUplinkInfoTag))
359 NS_FATAL_ERROR(
"SatUplinkInfoTag not found !");
362 uint32_t beamId = satUplinkInfoTag.
GetBeamId();
363 uint32_t satId = satUplinkInfoTag.
GetSatId();
364 bool isControl = satUplinkInfoTag.
IsControl();
368 SendCmtMessage(utId, Seconds(0), satelliteReceptionTime, satId, beamId);
375 NS_FATAL_ERROR(
"Unknown regeneration mode, or received");
383 NS_LOG_FUNCTION(
this << carrierId);
389 NS_LOG_INFO(
"GW handover, old satellite is " <<
m_feederSatId <<
", old beam is "
392 Ptr<SatBeamScheduler> srcScheduler =
398 NS_LOG_INFO(
"GW handover, new satellite is " <<
m_feederSatId <<
", new beam is "
401 Ptr<SatBeamScheduler> dstScheduler =
403 srcScheduler->DisconnectGw(
m_nodeInfo->GetMacAddress());
404 dstScheduler->ConnectGw(
m_nodeInfo->GetMacAddress());
408 Ptr<SatOrbiterNetDevice> orbiterNetDevice = DynamicCast<SatOrbiterNetDevice>(
409 Singleton<SatTopology>::Get()->GetOrbiterNode(
m_feederSatId)->GetDevice(0));
410 Mac48Address satFeederAddress = orbiterNetDevice->GetSatelliteFeederAddress(
m_beamId);
413 Ptr<SatGwLlc> gwLlc =
415 gwLlc->SetSatelliteAddress(satFeederAddress);
417 Singleton<SatTopology>::Get()->UpdateGwSatAndBeam(
m_node,
430 uint8_t lastSOFSize =
m_ncrV2 ? 3 : 1;
441 std::pair<Ptr<SatBbFrame>,
const Time> bbFrameInfo =
m_fwdScheduler->GetNextFrame();
442 Ptr<SatBbFrame> bbFrame = bbFrameInfo.first;
443 txDuration = bbFrameInfo.second;
449 if (bbFrame !=
nullptr)
463 txInfo.
modCod = bbFrame->GetModcod();
464 txInfo.
sliceId = bbFrame->GetSliceId();
465 txInfo.
frameType = bbFrame->GetFrameType();
481 NS_LOG_INFO(
"TX is disabled, thus nothing is transmitted!");
501 NS_LOG_FUNCTION(
this << tbtp);
503 uint32_t superframeCounter = tbtp->GetSuperframeCounter();
507 m_tbtps[superframeCounter] = std::vector<Ptr<SatTbtpMessage>>();
509 m_tbtps[superframeCounter].push_back(tbtp);
517 NS_LOG_FUNCTION(
this);
525 NS_LOG_FUNCTION(
this);
533 m_tbtps.erase(superframeCounter);
539 NS_LOG_FUNCTION(
this);
552 NS_LOG_FUNCTION(
this << packet << beamId);
556 packet->PeekPacketTag(macTag);
559 packet->PeekPacketTag(addressE2ETag);
563 bool cSuccess = packet->PeekPacketTag(ctrlTag);
567 NS_FATAL_ERROR(
"SatControlMsgTag not found in the packet!");
573 uint32_t msgId = ctrlTag.
GetMsgId();
576 if (crMsg !=
nullptr)
578 Mac48Address sourceAddress;
591 NS_FATAL_ERROR(
"Unknown regeneration mode");
593 m_fwdScheduler->CnoInfoUpdated(sourceAddress, crMsg->GetCnoEstimate());
607 std::stringstream msg;
608 msg <<
"Control message " << ctrlTag.
GetMsgType()
609 <<
" is not found from the RTN link control msg container!";
610 msg <<
" at: " << Now().GetSeconds() <<
"s";
614 packet->RemovePacketTag(macTag);
615 packet->RemovePacketTag(addressE2ETag);
616 packet->RemovePacketTag(ctrlTag);
621 uint32_t msgId = ctrlTag.
GetMsgId();
622 Ptr<SatCnoReportMessage> cnoReport =
625 if (cnoReport !=
nullptr)
628 cnoReport->GetCnoEstimate());
637 std::stringstream msg;
638 msg <<
"Control message " << ctrlTag.
GetMsgType()
639 <<
" is not found from the RTN link control msg container!";
640 msg <<
" at: " << Now().GetSeconds() <<
"s";
644 packet->RemovePacketTag(macTag);
645 packet->RemovePacketTag(addressE2ETag);
646 packet->RemovePacketTag(ctrlTag);
656 uint32_t msgId = ctrlTag.
GetMsgId();
657 Ptr<SatHandoverRecommendationMessage> handoverRecommendation =
660 if (handoverRecommendation !=
nullptr)
662 uint32_t newSatId = handoverRecommendation->GetRecommendedSatId();
663 uint32_t newBeamId = handoverRecommendation->GetRecommendedBeamId();
677 std::stringstream msg;
678 msg <<
"Control message " << ctrlTag.
GetMsgType()
679 <<
" is not found from the RTN link control msg container!";
680 msg <<
" at: " << Now().GetSeconds() <<
"s";
687 uint32_t msgId = ctrlTag.
GetMsgId();
688 Ptr<SatLogonMessage> logonMessage = DynamicCast<SatLogonMessage>(
m_readCtrlCallback(msgId));
690 if (logonMessage !=
nullptr)
693 Callback<void, uint32_t> raChannelCallback =
704 std::stringstream msg;
705 msg <<
"Control message " << ctrlTag.
GetMsgType()
706 <<
" is not found from the RTN link control msg container!";
707 msg <<
" at: " << Now().GetSeconds() <<
"s";
717 NS_FATAL_ERROR(
"SatGwMac received a non-supported control packet!");
726 NS_LOG_FUNCTION(
this);
728 Ptr<SatNcrMessage> ncrMessage = CreateObject<SatNcrMessage>();
729 m_fwdScheduler->SendControlMsg(ncrMessage, Mac48Address::GetBroadcast());
736 Time satelliteReceptionTime,
740 NS_LOG_FUNCTION(
this << utId);
742 Time lastCmtSent = Seconds(0);
748 Time timeReceived = satelliteReceptionTime;
749 if (satelliteReceptionTime == Seconds(0))
751 timeReceived = Simulator::Now();
759 uint32_t indexClosest = 0;
760 uint32_t tbtpIndexClosest = 0;
761 uint32_t timeSlotIndexClosest = 0;
762 Time differenceClosest = Seconds(1000000);
763 std::vector<Ptr<SatTbtpMessage>> tbtpsForCurrentSF;
764 Ptr<SatTbtpMessage> tbtp;
765 for (uint32_t i = 0; i <
m_tbtps.size(); i++)
767 tbtpsForCurrentSF =
m_tbtps[i];
768 for (uint32_t tbtpIndex = 0; tbtpIndex < tbtpsForCurrentSF.size(); tbtpIndex++)
770 tbtp = tbtpsForCurrentSF[tbtpIndex];
771 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots =
772 tbtp->GetDaTimeslots(utId);
773 for (uint32_t j = 0; j < timeslots.second.size(); j++)
775 Ptr<SatTimeSlotConf> tsConf = timeslots.second[j];
778 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
782 Time slotStartTime = tsConf->GetStartTime();
783 Time difference = timeReceived - frameStartTime - slotStartTime - burstDuration;
784 if (Abs(difference) < differenceClosest)
786 differenceClosest = Abs(difference);
788 timeSlotIndexClosest = j;
789 tbtpIndexClosest = tbtpIndex;
796 if (indexClosest == 0)
801 tbtp =
m_tbtps[indexClosest][tbtpIndexClosest];
802 std::pair<uint8_t, std::vector<Ptr<SatTimeSlotConf>>> timeslots = tbtp->GetDaTimeslots(utId);
804 if (timeslots.second[timeSlotIndexClosest]->GetSlotType() == 0)
806 Time frameStartTime = Singleton<SatRtnLinkTime>::Get()->GetSuperFrameTxTime(
810 Time slotStartTime = timeslots.second[timeSlotIndexClosest]->GetStartTime();
812 Time difference = frameStartTime + slotStartTime + burstDuration - timeReceived;
813 int32_t differenceNcr = difference.GetMicroSeconds() * 27;
815 if (differenceNcr > 16256 || differenceNcr < -16256)
817 NS_LOG_INFO(
"Burst Time Correction outside bounds, should be at least -16256 and at "
818 "most 16256, but got "
819 << differenceNcr <<
". Forcing logoff of UT " << utId);
820 Ptr<SatLogoffMessage> logoffMsg = CreateObject<SatLogoffMessage>();
826 Ptr<SatCmtMessage> cmt = CreateObject<SatCmtMessage>();
827 cmt->SetBurstTimeCorrection(differenceNcr);
839 NS_LOG_FUNCTION(
this << utId << raChannel);
840 Ptr<SatLogonResponseMessage> logonResponse = CreateObject<SatLogonResponseMessage>();
841 logonResponse->SetRaChannel(raChannel);
854 NS_LOG_FUNCTION(
this << &cb);
861 NS_LOG_FUNCTION(
this << &cb);
868 NS_LOG_FUNCTION(
this << &cb);
875 NS_LOG_FUNCTION(
this << &cb);
882 NS_LOG_FUNCTION(
this << &cb);
889 NS_LOG_FUNCTION(
this << &cb);
896 NS_LOG_FUNCTION(
this << &cb);
914 NS_LOG_FUNCTION(
this << satId << beamId);
920 NS_LOG_FUNCTION(
this << utAddress);
926 NS_LOG_INFO(
"Start beam " <<
m_beamId);
939 NS_LOG_FUNCTION(
this << utAddress);
947 NS_LOG_INFO(
"Stop beam " <<
m_beamId);
955 NS_LOG_FUNCTION(
this);
963 NS_LOG_FUNCTION(
this);
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
GW specific Mac class for Sat Net Devices.
void SetLogonCallback(SatGwMac::LogonCallback cb)
Method to set logon callback.
bool m_disableSchedulingIfNoDeviceConnected
If true, the periodic calls of StartTransmission are not called when no devices are connected to this...
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.
Callback< void > ClearQueuesCallback
Callback to clear LLC queues.
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.
SatGwMac::PhyBeamCallback m_beamCallback
Callback to change phy-layer beam ID.
SatGwMac::CrReceiveCallback m_crReceiveCallback
Capacity request receive callback.
bool m_broadcastNcr
Broadcast NCR messages to all UTs.
void ChangeBeam(uint32_t satId, uint32_t beamId)
Method handling beam handover.
static void SendLogonResponseHelper(SatGwMac *self, Address utId, uint32_t raChannel)
void SetHandoverCallback(SatGwMac::HandoverCallback cb)
Method to set handover callback.
void ConnectUt(Mac48Address utAddress)
Connect a UT to this satellite.
bool HasPeer()
Indicates if at least one device is connected in this beam.
SatGwMac::ClearQueuesCallback m_clearQueuesCallback
Callback to clear LLC queues.
void SetCrReceiveCallback(SatGwMac::CrReceiveCallback cb)
Method to set read control message callback.
uint32_t m_feederBeamId
ID of beam linked to this GW.
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.
uint32_t GetFeederBeamId()
Get ID of beam linked to this GW.
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.
Callback< void, Address, uint32_t, uint32_t, uint32_t, uint32_t > HandoverCallback
Callback to query/apply handover on the terrestrial network.
bool m_useCmt
Use CMT control messages to correct time on the UTs.
uint32_t GetFeederSatId()
Get ID of satellite linked to this GW.
void RemoveTbtp(uint32_t superframeCounter)
Function used to clear old TBTP.
bool m_periodicTransmissionEnabled
Indicated if periodic transmission is enabled.
Callback< void, uint32_t, uint32_t > PhyBeamCallback
Callback to change phy-layer beam ID.
void StartPeriodicTransmissions()
Starts periodical transmissions.
void SetBeamCallback(SatGwMac::PhyBeamCallback cb)
Method to set phy-layer beam handover callback.
virtual void StopPeriodicTransmissions()
Stop periodic transmission, until a pacquet in enqued.
std::set< Mac48Address > m_peers
List of UT MAC connected to this MAC.
void DisconnectUt(Mac48Address utAddress)
Disconnect a UT to this satellite.
Ptr< Node > m_node
Node containing this MAC.
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.
uint32_t m_feederSatId
ID of satellite linked to this GW.
Time m_guardTime
Guard time for BB frames.
void SetClearQueuesCallback(SatGwMac::ClearQueuesCallback cb)
Method to set callback for LLC queues clearing.
@ LOG_WARNING
LOG_WARNING.
void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
uint32_t m_beamId
The ID of the beam where mac belongs.
virtual void SetSatelliteAddress(Address satelliteAddress)
Set the satellite MAC address on the other side of this link (if regenerative satellite).
SatMac::BeamSchedulerCallback m_beamSchedulerCallback
Callback to get the SatBeamScheduler linked to a beam ID.
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.
Ptr< SatHandoverModule > m_handoverModule
Module used to perform handovers.
bool m_txEnabled
Flag indicating whether the MAC is enabled, i.e.
SatMac::ReadCtrlMsgCallback m_readCtrlCallback
The read control message callback.
SatMac()
Construct a SatMac.
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.
uint32_t m_satId
The ID of the sat where mac belongs.
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.
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