satellite-ut-mac.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
4  * Copyright (c) 2018 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Sami Rantanen <sami.rantanen@magister.fi>
20  * Author: Mathias Ettinger <mettinger@toulouse.viveris.fr>
21  */
22 
23 #ifndef SATELLITE_UT_MAC_H
24 #define SATELLITE_UT_MAC_H
25 
27 #include "satellite-enums.h"
28 #include "satellite-mac.h"
29 #include "satellite-phy.h"
30 #include "satellite-queue.h"
33 #include "satellite-ut-mac-state.h"
34 #include "satellite-ut-scheduler.h"
35 
36 #include <ns3/callback.h>
37 #include <ns3/nstime.h>
38 #include <ns3/ptr.h>
39 #include <ns3/traced-callback.h>
40 #include <ns3/traced-value.h>
41 
42 #include <utility>
43 
44 namespace ns3
45 {
46 
47 class Packet;
48 class Mac48Address;
49 class SatSuperframeSeq;
50 class SatNodeInfo;
51 class SatFrameConf;
52 class SatTbtpMessage;
53 class SatWaveform;
54 class SatTimeSlotConf;
55 class SatTbtpContainer;
56 class UniformRandomVariable;
57 
71 class SatUtMac : public SatMac
72 {
73  public:
77  static TypeId GetTypeId(void);
81  virtual TypeId GetInstanceTypeId(void) const;
82 
86  SatUtMac();
87 
100  SatUtMac(uint32_t satId,
101  uint32_t beamId,
102  Ptr<SatSuperframeSeq> seq,
103  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
104  SatEnums::RegenerationMode_t returnLinkRegenerationMode,
105  bool crdsaOnlyForControl);
106 
112  ~SatUtMac();
113 
118  inline uint32_t GetSatId() const
119  {
120  return m_satId;
121  }
122 
127  inline uint32_t GetBeamId() const
128  {
129  return m_beamId;
130  }
131 
137  virtual void Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> /*rxParams*/);
138 
142  typedef Callback<Time> TimingAdvanceCallback;
143 
149 
156  typedef Callback<void, uint8_t, uint32_t> AssignedDaResourcesCallback;
157 
163 
167  typedef Callback<bool> TxCheckCallback;
168 
174 
178  typedef Callback<void, uint8_t> SliceSubscriptionCallback;
179 
185 
189  typedef Callback<void> SendLogonCallback;
190 
196 
200  typedef Callback<void, Mac48Address> UpdateGwAddressCallback;
201 
207 
211  typedef Callback<Ptr<SatBeamScheduler>, uint32_t, uint32_t> BeamScheculerCallback;
212 
218 
224  Time GetNextSuperFrameTxTime(uint8_t superFrameSeqId) const;
225 
233  virtual void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex);
234 
242  virtual void ReceiveQueueEventEssa(SatQueue::QueueEvent_t event, uint8_t rcIndex);
243 
248  void SendLogon(Ptr<Packet> packet);
249 
253  virtual void SetSatelliteAddress(Address satelliteAddress);
254 
260  Mac48Address GetGwAddress();
261 
267  void SetGwAddress(Mac48Address gwAddress);
268 
273  virtual void SetNodeInfo(Ptr<SatNodeInfo> nodeInfo);
274 
280  void SetRaChannel(uint32_t raChannel);
281 
287  uint32_t GetRaChannel() const;
288 
293  void SetRandomAccess(Ptr<SatRandomAccess> randomAccess);
294 
302  bool ControlMsgTransmissionPossible() const;
303 
309  bool LogonMsgTransmissionPossible() const;
310 
316  typedef void (*TbtpResourcesTraceCallback)(uint32_t size);
317 
322  typedef Callback<void, uint32_t> HandoverCallback;
323 
329 
334  typedef Callback<void, Mac48Address> GatewayUpdateCallback;
335 
341 
348  typedef Callback<bool, uint32_t, uint32_t> BeamCheckerCallback;
349 
354  typedef Callback<uint32_t> AskedBeamCallback;
355 
361 
367 
368  void LogOff();
369 
370  void SetLogonChannel(uint32_t channelId);
371 
373 
374  protected:
378  void DoDispose(void);
379 
380  private:
386  Time GetCurrentSuperFrameStartTime(uint8_t superFrameSeqId) const;
387 
388  uint32_t GetCurrentSuperFrameId(uint8_t superFrameSeqId) const;
389 
394  void DoRandomAccess(SatEnums::RandomAccessTriggerType_t randomAccessTriggerType);
395 
401 
406  void ScheduleSlottedAlohaTransmission(uint32_t allocationChannel);
407 
412  void ScheduleEssaTransmission(uint32_t allocationChannel);
413 
419  void ScheduleCrdsaTransmission(uint32_t allocationChannel,
421 
425  void CreateCrdsaPacketInstances(uint32_t allocationChannel, std::set<uint32_t> slots);
426 
431  void RemovePastRandomAccessSlots(uint32_t superFrameId);
432 
440  bool UpdateUsedRandomAccessSlots(uint32_t superFrameId,
441  uint32_t allocationChannel,
442  uint32_t slot);
443 
453  std::pair<bool, uint32_t> FindNextAvailableRandomAccessSlot(Time opportunityOffset,
454  Ptr<SatFrameConf> frameConf,
455  uint32_t timeSlotCount,
456  uint32_t superFrameId,
457  uint32_t allocationChannel);
458 
468  std::pair<bool, uint32_t> SearchFrameForAvailableSlot(Time superframeStartTime,
469  Ptr<SatFrameConf> frameConf,
470  uint32_t timeSlotCount,
471  uint32_t superFrameId,
472  uint32_t allocationChannel);
473 
481  bool IsRandomAccessSlotAvailable(uint32_t superFrameId,
482  uint32_t allocationChannelId,
483  uint32_t slotId);
484 
489 
495  void ScheduleTimeSlots(Ptr<SatTbtpMessage> tbtp);
496 
505  void ScheduleDaTxOpportunity(Time transmitDelay,
506  Time duration,
507  Ptr<SatWaveform> wf,
508  Ptr<SatTimeSlotConf> tsConf,
509  uint32_t carrierId);
510 
521  void DoTransmit(Time duration,
522  uint32_t carrierId,
523  Ptr<SatWaveform> wf,
524  Ptr<SatTimeSlotConf> tsConf,
526 
537  Time duration,
538  Ptr<SatWaveform> waveform,
539  uint32_t carrierId,
540  uint8_t rcIndex,
542 
552  void DoEssaTransmit(Time duration,
553  Ptr<SatWaveform> waveform,
554  uint32_t carrierId,
555  uint8_t rcIndex,
557 
566  SatPhy::PacketContainer_t FetchPackets(uint32_t payloadBytes,
568  uint8_t rcIndex,
570 
581  uint32_t payloadBytes,
583  uint8_t rcIndex,
585  bool randomAccessChannel);
586 
595  Time duration,
596  uint32_t carrierId,
598 
604  void ReceiveSignalingPacket(Ptr<Packet> packet);
605 
609  void DoFrameStart();
610 
616  Time GetRealSendingTime(Time t);
617 
620 
624  uint32_t m_satId;
625 
629  uint32_t m_beamId;
630 
634  Ptr<SatSuperframeSeq> m_superframeSeq;
635 
640 
645 
649  Ptr<SatRandomAccess> m_randomAccess;
650 
656 
660  Ptr<SatTbtpContainer> m_tbtpContainer;
661 
665  Ptr<UniformRandomVariable> m_uniformRandomVariable;
666 
670  std::map<std::pair<uint32_t, uint32_t>, std::set<uint32_t>> m_usedRandomAccessSlots;
671 
675  uint32_t m_raChannel;
676 
680  uint32_t m_logonChannel;
681 
686 
691 
696 
701 
709  Ptr<UniformRandomVariable> m_waitingTimeLogonRng;
710 
715 
719  Ptr<SatUtScheduler> m_utScheduler;
720 
724  TracedCallback<uint32_t> m_tbtpResourcesTrace;
725 
730 
737 
742 
748 
749  class SatTimuInfo : public SimpleRefCount<SatTimuInfo>
750  {
751  public:
752  SatTimuInfo(uint32_t beamId, Address address);
753 
754  uint32_t GetBeamId() const;
755 
756  Address GetGwAddress() const;
757 
758  private:
759  uint32_t m_beamId;
760  Address m_gwAddress;
761  };
762 
763  Ptr<SatTimuInfo> m_timuInfo;
764 
765  Mac48Address m_gwAddress;
766 
768 
773 
777  uint64_t m_ncr;
778 
782  int64_t m_deltaNcr;
783 
787  int32_t m_clockDrift;
788 
792  std::queue<Time> m_receptionDates;
793 
794  typedef enum
795  {
799  } HandoverState_t;
800 
802 
805 
807 
812 
817 
822 
827 
832 
837 
842 
847 
852 };
853 
854 } // namespace ns3
855 
856 #endif /* SATELLITE_UT_MAC_H */
RegenerationMode_t
The regeneration mode used in satellites.
RandomAccessTriggerType_t
The defined random access trigger types.
Base MAC class for SatNetDevices.
Definition: satellite-mac.h:52
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Definition: satellite-phy.h:78
SatTimeSlotType_t
Types for time slot.
SatTimuInfo(uint32_t beamId, Address address)
UT specific Mac class for Sat Net Devices.
void SetRandomAccess(Ptr< SatRandomAccess > randomAccess)
Set the random access module.
void SetBeamScheculerCallback(SatUtMac::BeamScheculerCallback cb)
Set the beam scheduler callback.
void SetAskedBeamCallback(SatUtMac::AskedBeamCallback cb)
Method to get the best beam when performing handover.
Callback< void, uint32_t > HandoverCallback
Callback to reconfigure physical layer during handover.
Ptr< SatSuperframeSeq > m_superframeSeq
Used superframe sequence for the return link.
Callback< bool > TxCheckCallback
Callback to check if TX is operational.
virtual void ReceiveQueueEventEssa(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event:
Ptr< SatTbtpContainer > m_tbtpContainer
Container for storing all the TBTP information related to this UT.
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive packet from lower layer.
Time m_guardTime
Guard time for time slots.
void DoEssaTransmit(Time duration, Ptr< SatWaveform > waveform, uint32_t carrierId, uint8_t rcIndex, SatUtScheduler::SatCompliancePolicy_t policy=SatUtScheduler::LOOSE)
Notify the upper layer about the ESSA Tx opportunity.
static TypeId GetTypeId(void)
Derived from Object.
int64_t m_deltaNcr
Correction to apply to NCR dates.
void PrintUsedRandomAccessSlots()
uint32_t m_beamId
ID of beam for UT.
uint32_t m_handoverMessagesCount
Time m_maxWaitingTimeLogonResponse
Timeout for waiting for a response for a logon message.
std::pair< bool, uint32_t > SearchFrameForAvailableSlot(Time superframeStartTime, Ptr< SatFrameConf > frameConf, uint32_t timeSlotCount, uint32_t superFrameId, uint32_t allocationChannel)
void SetAssignedDaResourcesCallback(SatUtMac::AssignedDaResourcesCallback cb)
Set the assigned DA resources callback.
Mac48Address m_gwAddress
SatUtMac::HandoverCallback m_handoverCallback
The physical layer handover callback.
SatUtMacState::RcstState_t GetRcstState() const
uint64_t m_ncr
NCR value of last NCR control message.
void SendLogon(Ptr< Packet > packet)
Receive a logon message to transmit /param packet The logon packet to send.
virtual void SetSatelliteAddress(Address satelliteAddress)
Set the satellite MAC address on the other side of this link (if regenerative satellite).
void ScheduleTimeSlots(Ptr< SatTbtpMessage > tbtp)
Schedules time slots according to received TBTP message.
void SetHandoverCallback(SatUtMac::HandoverCallback cb)
Method to set handover callback.
virtual void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event:
Callback< void, Mac48Address > UpdateGwAddressCallback
Callback to update GW address to SatRequestManager.
Callback< void > SendLogonCallback
Callback to send a logon message to the gateway.
SatUtMac::SliceSubscriptionCallback m_sliceSubscriptionCallback
Tx checking callback.
Time GetRealSendingTime(Time t)
Compute real sending time of UT based on last NCR reception date and clock drift.
void ScheduleEssaTransmission(uint32_t allocationChannel)
Function for scheduling the ESSA transmissions.
virtual TypeId GetInstanceTypeId(void) const
Derived from Object.
void SetTxCheckCallback(SatUtMac::TxCheckCallback cb)
Set the TX check callback.
bool IsRandomAccessSlotAvailable(uint32_t superFrameId, uint32_t allocationChannelId, uint32_t slotId)
Ptr< SatTimuInfo > m_timuInfo
void RemovePastRandomAccessSlots(uint32_t superFrameId)
Function for removing the past used RA slots.
void ScheduleCrdsaTransmission(uint32_t allocationChannel, SatRandomAccess::RandomAccessTxOpportunities_s txOpportunities)
Function for scheduling the CRDSA transmissions.
Callback< Time > TimingAdvanceCallback
uint32_t GetBeamId() const
Get beam ID of the object.
uint32_t m_maxHandoverMessagesSent
void SetUpdateGwAddressCallback(SatUtMac::UpdateGwAddressCallback cb)
Set the gw update callback.
SatUtMac::UpdateGwAddressCallback m_updateGwAddressCallback
Callback for sending a logon message.
uint32_t m_firstTransmittableSuperframeId
std::map< std::pair< uint32_t, uint32_t >, std::set< uint32_t > > m_usedRandomAccessSlots
A container for storing the used RA slots in each frame and allocation channel.
void SetSliceSubscriptionCallback(SatUtMac::SliceSubscriptionCallback cb)
Get sliec subscription info from MAC layer.
void DoSlottedAlohaTransmit(Time duration, Ptr< SatWaveform > waveform, uint32_t carrierId, uint8_t rcIndex, SatUtScheduler::SatCompliancePolicy_t policy=SatUtScheduler::LOOSE)
Notify the upper layer about the Slotted ALOHA Tx opportunity.
uint32_t m_crdsaUniquePacketId
CRDSA packet ID (per frame)
Time m_lastNcrDateReceived
Reception date of last NCR control message.
void SetSendLogonCallback(SatUtMac::SendLogonCallback cb)
Set the logon callback.
~SatUtMac()
Destroy a SatUtMac.
Time m_windowInitLogon
The initial max time to wait when sending a logon message.
Time GetNextSuperFrameTxTime(uint8_t superFrameSeqId) const
Get Tx time for the next possible superframe.
SatUtMac::GatewayUpdateCallback m_gatewayUpdateCallback
Gateway address update callback.
void ScheduleSlottedAlohaTransmission(uint32_t allocationChannel)
Function for scheduling the Slotted ALOHA transmissions.
SatUtMac::BeamScheculerCallback m_beamScheculerCallback
Callback to get the SatBeamScheduler linked to a beam ID.
HandoverState_t m_handoverState
void(* TbtpResourcesTraceCallback)(uint32_t size)
Callback signature for DaResourcesTrace trace source.
uint32_t GetCurrentSuperFrameId(uint8_t superFrameSeqId) const
void SetRaChannel(uint32_t raChannel)
Set RA channel assigned for this UT.
Mac48Address GetGwAddress()
Get address of the GW (or its MAC) serving this UT.
std::queue< Time > m_receptionDates
Store last 3 packets reception date, to be associated to NCR dates.
void ExtractPacketsToSchedule(SatPhy::PacketContainer_t &packets, uint32_t payloadBytes, SatTimeSlotConf::SatTimeSlotType_t type, uint8_t rcIndex, SatUtScheduler::SatCompliancePolicy_t policy, bool randomAccessChannel)
Extract packets from the underlying queue and put them in the provided container.
SatUtMacState m_rcstState
Time m_nextPacketTime
Next time when a next ESSA packet can be safely sent.
uint32_t m_logonChannel
RA channel dedicated to logon messages.
void ReceiveSignalingPacket(Ptr< Packet > packet)
Signaling packet receiver, which handles all the signaling packet receptions.
Callback< uint32_t > AskedBeamCallback
Callback to ask for the best beam ID during handover.
void SetTimingAdvanceCallback(SatUtMac::TimingAdvanceCallback cb)
Set the timing advance callback.
SatPhy::PacketContainer_t FetchPackets(uint32_t payloadBytes, SatTimeSlotConf::SatTimeSlotType_t type, uint8_t rcIndex, SatUtScheduler::SatCompliancePolicy_t policy)
Callback< void, uint8_t, uint32_t > AssignedDaResourcesCallback
Callback for informing the amount of dedicated access bytes received from TBTP.
TracedCallback< uint32_t > m_tbtpResourcesTrace
Assigned TBTP resources in superframe for this UT (in bytes).
std::pair< bool, uint32_t > FindNextAvailableRandomAccessSlot(Time opportunityOffset, Ptr< SatFrameConf > frameConf, uint32_t timeSlotCount, uint32_t superFrameId, uint32_t allocationChannel)
bool m_crdsaOnlyForControl
Planned CRDSA usage:
SatUtMac(const SatUtMac &)
void DoDispose(void)
Dispose of SatUtMac.
uint32_t GetNextRandomAccessAllocationChannel()
Function for selecting the allocation channel for the current RA evaluation.
void SetLogonChannel(uint32_t channelId)
void ScheduleDaTxOpportunity(Time transmitDelay, Time duration, Ptr< SatWaveform > wf, Ptr< SatTimeSlotConf > tsConf, uint32_t carrierId)
Schdules one Tx opportunity, i.e.
SatUtMac()
Default constructor, which is not used.
SatUtMac::BeamCheckerCallback m_beamCheckerCallback
Beam checker and handover recommendation sending callback.
Callback< bool, uint32_t, uint32_t > BeamCheckerCallback
Callback to check whether the current beam is still the best one to use for sending data; and sending...
Ptr< SatUtScheduler > m_utScheduler
UT scheduler.
bool UpdateUsedRandomAccessSlots(uint32_t superFrameId, uint32_t allocationChannel, uint32_t slot)
Function for updating the used RA slots.
void TransmitPackets(SatPhy::PacketContainer_t packets, Time duration, uint32_t carrierId, SatSignalParameters::txInfo_s txInfo)
void CreateCrdsaPacketInstances(uint32_t allocationChannel, std::set< uint32_t > slots)
void SetBeamCheckerCallback(SatUtMac::BeamCheckerCallback cb)
Method to set the beam checker callback.
Ptr< SatRandomAccess > m_randomAccess
RA main module.
bool m_isRandomAccessScheduled
Flag that indicates if a method DoRandomAccess is scheduled for asynchronous access.
Callback< Ptr< SatBeamScheduler >, uint32_t, uint32_t > BeamScheculerCallback
Callback to get the SatBeamScheduler from the beam ID for handover.
TimingAdvanceCallback m_timingAdvanceCb
Callback for getting the timing advance information.
uint32_t m_satId
ID of sat for UT.
SatUtMac::AskedBeamCallback m_askedBeamCallback
Beam checker and handover recommendation sending callback.
uint32_t GetSatId() const
Get sat ID of the object.
bool ControlMsgTransmissionPossible() const
Method to check whether a transmission of a control msg is somewhat possible.
int32_t m_clockDrift
Clock drift (number of ticks per second)
void DoTransmit(Time duration, uint32_t carrierId, Ptr< SatWaveform > wf, Ptr< SatTimeSlotConf > tsConf, SatUtScheduler::SatCompliancePolicy_t policy=SatUtScheduler::LOOSE)
Notify the upper layer about the Tx opportunity.
void DoFrameStart()
Function which is executed at every frame start.
Callback< void, Mac48Address > GatewayUpdateCallback
Callback to update gateway address after handover.
Time m_nextLogonTransmissionPossible
Instant when a logon message can be transmitted.
Ptr< UniformRandomVariable > m_waitingTimeLogonRng
The random generator for waiting transmission time.
void SetGwAddress(Mac48Address gwAddress)
Set address of the GW (or its MAC) serving this UT.
SatUtMac & operator=(const SatUtMac &)
bool LogonMsgTransmissionPossible() const
Method to check whether a transmission of a logon msg is somewhat possible.
Time GetCurrentSuperFrameStartTime(uint8_t superFrameSeqId) const
Get start time for the current superframe.
void SetGatewayUpdateCallback(SatUtMac::GatewayUpdateCallback cb)
Method to set the gateway address update callback.
bool m_useLogon
Should logon be simulated?
virtual void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
uint32_t m_sendLogonTries
Number of times a logon message has been sent without response.
uint32_t m_raChannel
RA channel assigned to the UT.
uint32_t GetRaChannel() const
Get RA channel assigned for this UT.
void DoRandomAccess(SatEnums::RandomAccessTriggerType_t randomAccessTriggerType)
Do random access evaluation for Tx opportunities.
Callback< void, uint8_t > SliceSubscriptionCallback
Callback to check if TX is operational.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Uniform random variable distribution generator.
AssignedDaResourcesCallback m_assignedDaResourcesCallback
Callback for informing the assigned TBTP resources.
SatUtMac::SendLogonCallback m_sendLogonCallback
Callback for sending a logon message.
bool m_loggedOn
UT is logged on.
SatUtMac::TxCheckCallback m_txCheckCallback
Tx checking callback.
Class handling UT Mac states and transitions.
SatCompliancePolicy_t
Enum describing the wanted scheduler policy.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the packet specific Tx information.