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 
26 #include "satellite-enums.h"
27 #include "satellite-mac.h"
28 #include "satellite-phy.h"
29 #include "satellite-queue.h"
32 #include "satellite-ut-mac-state.h"
33 #include "satellite-ut-scheduler.h"
34 
35 #include <ns3/callback.h>
36 #include <ns3/nstime.h>
37 #include <ns3/ptr.h>
38 #include <ns3/traced-callback.h>
39 #include <ns3/traced-value.h>
40 
41 #include <map>
42 #include <queue>
43 #include <set>
44 #include <stdint.h>
45 #include <utility>
46 
47 namespace ns3
48 {
49 
50 class Packet;
51 class Mac48Address;
52 class SatSuperframeSeq;
53 class SatNodeInfo;
54 class SatFrameConf;
55 class SatTbtpMessage;
56 class SatWaveform;
57 class SatTimeSlotConf;
58 class SatTbtpContainer;
59 class UniformRandomVariable;
60 
74 class SatUtMac : public SatMac
75 {
76  public:
80  static TypeId GetTypeId(void);
84  virtual TypeId GetInstanceTypeId(void) const;
85 
89  SatUtMac();
90 
102  SatUtMac(Ptr<Node> node,
103  uint32_t satId,
104  uint32_t beamId,
105  Ptr<SatSuperframeSeq> seq,
106  bool crdsaOnlyForControl);
107 
113  ~SatUtMac();
114 
119  inline uint32_t GetSatId() const
120  {
121  return m_satId;
122  }
123 
128  inline uint32_t GetBeamId() const
129  {
130  return m_beamId;
131  }
132 
138  virtual void Receive(SatPhy::PacketContainer_t packets, Ptr<SatSignalParameters> /*rxParams*/);
139 
143  typedef Callback<Time> TimingAdvanceCallback;
144 
150 
157  typedef Callback<void, uint8_t, uint32_t> AssignedDaResourcesCallback;
158 
164 
168  typedef Callback<bool> TxCheckCallback;
169 
175 
179  typedef Callback<void, uint8_t> SliceSubscriptionCallback;
180 
186 
190  typedef Callback<void> SendLogonCallback;
191 
197 
201  typedef Callback<void, Mac48Address> UpdateGwAddressCallback;
202 
208 
214  Time GetNextSuperFrameTxTime(uint8_t superFrameSeqId) const;
215 
223  virtual void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex);
224 
232  virtual void ReceiveQueueEventEssa(SatQueue::QueueEvent_t event, uint8_t rcIndex);
233 
238  void SendLogon(Ptr<Packet> packet);
239 
243  virtual void SetSatelliteAddress(Address satelliteAddress);
244 
250  Mac48Address GetGwAddress();
251 
257  void SetGwAddress(Mac48Address gwAddress);
258 
263  virtual void SetNodeInfo(Ptr<SatNodeInfo> nodeInfo);
264 
270  void SetRaChannel(uint32_t raChannel);
271 
277  uint32_t GetRaChannel() const;
278 
283  void SetRandomAccess(Ptr<SatRandomAccess> randomAccess);
284 
292  bool ControlMsgTransmissionPossible() const;
293 
299  bool LogonMsgTransmissionPossible() const;
300 
306  typedef void (*TbtpResourcesTraceCallback)(uint32_t size);
307 
312  typedef Callback<void, uint32_t, uint32_t> HandoverCallback;
313 
319 
324  typedef Callback<void, Mac48Address> GatewayUpdateCallback;
325 
331 
335  typedef Callback<void, Ptr<Node>> UpdateAddressAndIdentifierCallback;
336 
342 
343  void LogOff();
344 
345  void SetLogonChannel(uint32_t channelId);
346 
348 
349  protected:
353  void DoDispose(void);
354 
355  private:
361  Time GetCurrentSuperFrameStartTime(uint8_t superFrameSeqId) const;
362 
363  uint32_t GetCurrentSuperFrameId(uint8_t superFrameSeqId) const;
364 
369  void DoRandomAccess(SatEnums::RandomAccessTriggerType_t randomAccessTriggerType);
370 
376 
381  void ScheduleSlottedAlohaTransmission(uint32_t allocationChannel);
382 
387  void ScheduleEssaTransmission(uint32_t allocationChannel);
388 
394  void ScheduleCrdsaTransmission(uint32_t allocationChannel,
396 
400  void CreateCrdsaPacketInstances(uint32_t allocationChannel, std::set<uint32_t> slots);
401 
406  void RemovePastRandomAccessSlots(uint32_t superFrameId);
407 
415  bool UpdateUsedRandomAccessSlots(uint32_t superFrameId,
416  uint32_t allocationChannel,
417  uint32_t slot);
418 
428  std::pair<bool, uint32_t> FindNextAvailableRandomAccessSlot(Time opportunityOffset,
429  Ptr<SatFrameConf> frameConf,
430  uint32_t timeSlotCount,
431  uint32_t superFrameId,
432  uint32_t allocationChannel);
433 
443  std::pair<bool, uint32_t> SearchFrameForAvailableSlot(Time superframeStartTime,
444  Ptr<SatFrameConf> frameConf,
445  uint32_t timeSlotCount,
446  uint32_t superFrameId,
447  uint32_t allocationChannel);
448 
456  bool IsRandomAccessSlotAvailable(uint32_t superFrameId,
457  uint32_t allocationChannelId,
458  uint32_t slotId);
459 
464 
470  void ScheduleTimeSlots(Ptr<SatTbtpMessage> tbtp);
471 
480  void ScheduleDaTxOpportunity(Time transmitDelay,
481  Time duration,
482  Ptr<SatWaveform> wf,
483  Ptr<SatTimeSlotConf> tsConf,
484  uint32_t carrierId);
485 
496  void DoTransmit(Time duration,
497  uint32_t carrierId,
498  Ptr<SatWaveform> wf,
499  Ptr<SatTimeSlotConf> tsConf,
501 
512  Time duration,
513  Ptr<SatWaveform> waveform,
514  uint32_t carrierId,
515  uint8_t rcIndex,
517 
527  void DoEssaTransmit(Time duration,
528  Ptr<SatWaveform> waveform,
529  uint32_t carrierId,
530  uint8_t rcIndex,
532 
541  SatPhy::PacketContainer_t FetchPackets(uint32_t payloadBytes,
543  uint8_t rcIndex,
545 
556  uint32_t payloadBytes,
558  uint8_t rcIndex,
560  bool randomAccessChannel);
561 
570  Time duration,
571  uint32_t carrierId,
573 
579  void ReceiveSignalingPacket(Ptr<Packet> packet);
580 
584  void DoFrameStart();
585 
591  Time GetRealSendingTime(Time t);
592 
595 
599  Ptr<Node> m_node;
600 
604  uint32_t m_satId;
605 
609  uint32_t m_beamId;
610 
614  Ptr<SatSuperframeSeq> m_superframeSeq;
615 
620 
625 
629  Ptr<SatRandomAccess> m_randomAccess;
630 
636 
640  Ptr<SatTbtpContainer> m_tbtpContainer;
641 
645  Ptr<UniformRandomVariable> m_uniformRandomVariable;
646 
650  std::map<std::pair<uint32_t, uint32_t>, std::set<uint32_t>> m_usedRandomAccessSlots;
651 
655  uint32_t m_raChannel;
656 
660  uint32_t m_logonChannel;
661 
666 
671 
676 
681 
689  Ptr<UniformRandomVariable> m_waitingTimeLogonRng;
690 
695 
699  Ptr<SatUtScheduler> m_utScheduler;
700 
704  TracedCallback<uint32_t> m_tbtpResourcesTrace;
705 
710 
717 
722 
728 
729  class SatTimuInfo : public SimpleRefCount<SatTimuInfo>
730  {
731  public:
732  SatTimuInfo(uint32_t beamId, uint32_t satId, Address satAddress, Address gwAddress);
733 
734  uint32_t GetBeamId() const;
735 
736  uint32_t GetSatId() const;
737 
738  Address GetSatAddress() const;
739 
740  Address GetGwAddress() const;
741 
742  private:
743  uint32_t m_beamId;
744  uint32_t m_satId;
745  Address m_satAddress;
746  Address m_gwAddress;
747  };
748 
749  Ptr<SatTimuInfo> m_timuInfo;
750 
751  Mac48Address m_gwAddress;
752 
754 
759 
763  uint64_t m_ncr;
764 
768  int64_t m_deltaNcr;
769 
773  int32_t m_clockDrift;
774 
778  std::queue<Time> m_receptionDates;
779 
780  typedef enum
781  {
785  } HandoverState_t;
786 
788 
791 
793 
798 
803 
808 
813 
818 
823 
828 };
829 
830 } // namespace ns3
831 
832 #endif /* SATELLITE_UT_MAC_H */
RandomAccessTriggerType_t
The defined random access trigger types.
Base MAC class for SatNetDevices.
Definition: satellite-mac.h:57
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
Definition: satellite-phy.h:79
SatTimeSlotType_t
Types for time slot.
SatTimuInfo(uint32_t beamId, uint32_t satId, Address satAddress, Address gwAddress)
UT specific Mac class for Sat Net Devices.
void SetRandomAccess(Ptr< SatRandomAccess > randomAccess)
Set the random access module.
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)
Callback< void, uint32_t, uint32_t > HandoverCallback
Callback to reconfigure physical layer during handover.
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.
SatUtMac::UpdateAddressAndIdentifierCallback m_updateAddressAndIdentifierCallback
Callback to update addresses in statistics helpers.
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.
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.
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.
Ptr< Node > m_node
Node containing this MAC.
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)
Ptr< SatRandomAccess > m_randomAccess
RA main module.
bool m_isRandomAccessScheduled
Flag that indicates if a method DoRandomAccess is scheduled for asynchronous access.
TimingAdvanceCallback m_timingAdvanceCb
Callback for getting the timing advance information.
uint32_t m_satId
ID of sat for UT.
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 SetUpdateAddressAndIdentifierCallback(SatUtMac::UpdateAddressAndIdentifierCallback cb)
Set the callback to update addresses in statistics helpers.
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.
Callback< void, Ptr< Node > > UpdateAddressAndIdentifierCallback
Callback to update addresses in statistics helpers.
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.