satellite-beam-scheduler.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 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.com>
21  */
22 
23 #ifndef SAT_BEAM_SCHEDULER_H
24 #define SAT_BEAM_SCHEDULER_H
25 
27 #include "satellite-enums.h"
29 #include "satellite-gw-mac.h"
30 #include "satellite-net-device.h"
32 
33 #include <ns3/callback.h>
34 #include <ns3/nstime.h>
35 #include <ns3/object.h>
36 #include <ns3/ptr.h>
37 #include <ns3/simple-ref-count.h>
38 #include <ns3/traced-callback.h>
39 
40 #include <cmath>
41 #include <list>
42 #include <map>
43 #include <stdint.h>
44 #include <string>
45 #include <utility>
46 #include <vector>
47 
48 namespace ns3
49 {
50 
51 class Address;
52 class Ipv4Address;
53 class SatControlMessage;
54 class SatCrMessage;
55 class SatTbtpMessage;
56 class SatTimuMessage;
57 class SatSuperframeSeq;
58 class SatSuperframeAllocator;
59 class SatLowerLayerServiceConf;
60 class SatDamaEntry;
61 
80 class SatBeamScheduler : public Object
81 {
82  public:
87  typedef enum
88  {
92 
97  static TypeId GetTypeId(void);
98 
106 
113 
119  typedef Callback<bool, Ptr<SatControlMessage>, const Address&> SendCtrlMsgCallback;
120 
124  typedef Callback<void, Ptr<SatTbtpMessage>> SendTbtpCallback;
125 
130  typedef Callback<void, uint32_t, Ptr<SatTbtpMessage>> TbtpAddCallback;
131 
144  void Initialize(uint32_t satId,
145  uint32_t beamId,
146  Ptr<SatNetDevice> gwNetDevice,
147  Ptr<SatOrbiterNetDevice> orbiterNetDevice,
149  Ptr<SatSuperframeSeq> seq,
150  uint32_t maxFrameSizeInBytes,
151  Address satAddress,
152  Address gwAddress);
153 
161  uint32_t AddUt(Address utId, Ptr<SatLowerLayerServiceConf> llsConf);
162 
169  bool HasUt(Address utId);
170 
176  bool HasUt();
177 
184  void UpdateUtCno(Address utId, double cno);
185 
192  void UpdateSatelliteCno(Address satelliteMac, double cno);
193 
200  void UtCrReceived(Address utId, Ptr<SatCrMessage> crMsg);
201 
208  bool Send(Ptr<SatControlMessage> message);
209 
217  bool SendTo(Ptr<SatControlMessage> message, Address utId);
218 
226  bool SendToSatellite(Ptr<SatControlMessage> msg, Address satelliteMac);
227 
232 
243  typedef void (*BacklogRequestsTraceCallback)(std::string trace);
244 
250  typedef void (*WaveformTraceCallback)(uint32_t waveformId);
251 
257  typedef void (*UsableCapacityTraceCallback)(uint32_t usableCapacity);
258 
265  typedef void (*UnmetCapacityTraceCallback)(uint32_t unmetCapacity);
266 
273  typedef void (*ExceedingCapacityTraceCallback)(uint32_t exceedingCapacity);
274 
279  Ptr<SatTimuMessage> CreateTimu() const;
280 
286  void TransferUtToBeam(Address utId, Ptr<SatBeamScheduler> destination);
287 
293  void ConnectUt(Mac48Address address);
294 
300  void DisconnectUt(Mac48Address address);
301 
307  void ConnectGw(Mac48Address address);
308 
314  void DisconnectGw(Mac48Address address);
315 
320  void RemoveUt(Address utId);
321 
322  void ReserveLogonChannel(uint32_t logonChannelId);
323 
327  inline Address GetSatAddress(void) const
328  {
329  return m_satAddress;
330  }
331 
335  inline Address GetGwAddress(void) const
336  {
337  return m_gwAddress;
338  }
339 
344  void SetUseLora(bool useLora);
345 
346  private:
352  class SatUtInfo : public SimpleRefCount<SatUtInfo>
353  {
354  public:
364  SatUtInfo(Ptr<SatDamaEntry> damaEntry,
365  Ptr<SatCnoEstimator> cnoEstimator,
366  Time controlSlotOffset,
367  bool controlSlotsEnabled);
368 
374  Ptr<SatDamaEntry> GetDamaEntry();
375 
379  void UpdateDamaEntryFromCrs();
380 
386  void AddCnoSample(double sample);
387 
393  double GetCnoEstimation();
394 
401  void AddCrMsg(Ptr<SatCrMessage> crMsg);
402 
407  void ClearCrMsgs();
408 
414  bool IsControlSlotGenerationTime() const;
415 
421  void SetControlSlotGenerationTime(Time offset);
422 
423  private:
427  typedef std::vector<Ptr<SatCrMessage>> CrMsgContainer_t;
428 
432  Ptr<SatDamaEntry> m_damaEntry;
433 
437  Ptr<SatCnoEstimator> m_cnoEstimator;
438 
443 
448 
453  };
454 
458  typedef std::pair<Address, SatFrameAllocator::SatFrameAllocReq> UtReqInfoItem_t;
459 
463  typedef std::map<Address, Ptr<SatUtInfo>> UtInfoMap_t;
464 
468  typedef std::list<UtReqInfoItem_t> UtReqInfoContainer_t;
469 
474  {
475  public:
481  CnoCompare(const UtInfoMap_t& utInfoMap)
482  : m_utInfoMap(utInfoMap)
483  {
484  }
485 
493  bool operator()(UtReqInfoItem_t utReqInfo1, UtReqInfoItem_t utReqInfo2)
494  {
495  double result = false;
496 
497  double cnoFirst = m_utInfoMap.at(utReqInfo1.first)->GetCnoEstimation();
498  double cnoSecond = m_utInfoMap.at(utReqInfo2.first)->GetCnoEstimation();
499 
500  if (!std::isnan(cnoFirst))
501  {
502  if (std::isnan(cnoSecond))
503  {
504  result = false;
505  }
506  else
507  {
508  result = (cnoFirst < cnoSecond);
509  }
510  }
511 
512  return result;
513  }
514 
515  private:
520  };
521 
525  uint32_t m_satId;
526 
530  uint32_t m_beamId;
531 
535  Ptr<SatGwMac> m_gwMac;
536 
540  Ptr<SatOrbiterNetDevice> m_orbiterNetDevice;
541 
545  Ptr<SatSuperframeSeq> m_superframeSeq;
546 
551 
556 
561 
566 
571 
575  Ptr<RandomVariableStream> m_raChRandomIndex;
576 
581 
586 
591 
595  Ptr<SatSuperframeAllocator> m_superframeAllocator;
596 
603 
610 
615 
620 
625 
629  TracedCallback<std::string> m_backlogRequestsTrace;
630 
634  TracedCallback<uint32_t> m_waveformTrace;
635 
639  TracedCallback<uint32_t, uint32_t> m_frameUtLoadTrace;
640 
644  TracedCallback<uint32_t, double> m_frameLoadTrace;
645 
649  TracedCallback<uint32_t> m_usableCapacityTrace;
650 
654  TracedCallback<uint32_t> m_unmetCapacityTrace;
655 
659  TracedCallback<uint32_t> m_exceedingCapacityTrace;
660 
664  void DoDispose(void);
665 
669  void Schedule();
670 
674  uint32_t UpdateDamaEntriesWithReqs();
675 
683 
688 
693  void AddRaChannels(std::vector<Ptr<SatTbtpMessage>>& tbtpContainer);
694 
695  void AddUtInfo(Address utId, Ptr<SatUtInfo> utInfo);
696  void RemoveUtInfo(UtInfoMap_t::iterator iterator);
697 
702  Ptr<SatCnoEstimator> CreateCnoEstimator();
703 
707  void SendCnoToSatellite();
708 
709  Address m_satAddress;
710 
711  Address m_gwAddress;
712 
714 
719 
723  Ptr<SatCnoEstimator> m_satelliteCnoEstimator;
724 
728  Address m_satelliteMac;
729 
734 
738  bool m_useLora;
739 };
740 
741 } // namespace ns3
742 
743 #endif /* SAT_BEAM_SCHEDULER_H */
CnoCompare class to sort UT request according to C/N0 information.
bool operator()(UtReqInfoItem_t utReqInfo1, UtReqInfoItem_t utReqInfo2)
Compare operator to compare request information of the two UTs.
CnoCompare(const UtInfoMap_t &utInfoMap)
Construct CnoCompare object.
const UtInfoMap_t & m_utInfoMap
Reference to map container for the UT information.
UT information helper class for SatBeamScheduler.
void ClearCrMsgs()
Remove all CR messages from UT info to reset capacity requests in case of handover.
void UpdateDamaEntryFromCrs()
Update DamaEntry with information of the received CR messages.
void AddCrMsg(Ptr< SatCrMessage > crMsg)
Add CR message to UT info to be used when capacity request is calculated next time (method UpdateDama...
double GetCnoEstimation()
Get estimated C/N0 value based on added samples.
Ptr< SatDamaEntry > GetDamaEntry()
Get damaEntry of the UT info.
bool IsControlSlotGenerationTime() const
Check if time is expired to send control slot.
Ptr< SatDamaEntry > m_damaEntry
DamaEntry of this UT info.
SatUtInfo(Ptr< SatDamaEntry > damaEntry, Ptr< SatCnoEstimator > cnoEstimator, Time controlSlotOffset, bool controlSlotsEnabled)
Construct SatUtInfo.
Ptr< SatCnoEstimator > m_cnoEstimator
Estimator for the C/N0.
void SetControlSlotGenerationTime(Time offset)
Set time for next time slot generation for this UT.
CrMsgContainer_t m_crContainer
Received CRs since last update round (call of the method UpdateDamaEntryFromCrs).
Time m_controlSlotGenerationTime
Time to send next control time slot.
bool m_controlSlotsEnabled
Flag to indicated if control time slots generation is enabled.
std::vector< Ptr< SatCrMessage > > CrMsgContainer_t
Container to store received CR messages.
void AddCnoSample(double sample)
Add C/N0 sample to UT info's estimator.
class for module Beam Scheduler.
bool SendToSatellite(Ptr< SatControlMessage > msg, Address satelliteMac)
Send control message to the satellite.
void DisconnectGw(Mac48Address address)
Disconnect a new GW address from this scheduler.
HandoverInformationForward_t m_handoverStrategy
void UtCrReceived(Address utId, Ptr< SatCrMessage > crMsg)
Receive capacity requests from UTs.
uint32_t UpdateDamaEntriesWithAllocs(SatFrameAllocator::UtAllocInfoContainer_t &utAllocContainer)
Update dama entries with given allocations at end of the scheduling.
uint32_t m_maxBbFrameSize
Maximum size of the BB frame.
Callback< void, uint32_t, Ptr< SatTbtpMessage > > TbtpAddCallback
Ptr< SatCnoEstimator > m_satelliteCnoEstimator
Estimator for the C/N0 from satellite.
void DisconnectUt(Mac48Address address)
Disconnect a new UT address from this scheduler.
Time m_cnoEstimationWindow
Time window for C/N0 estimation.
bool m_receivedSatelliteCnoSample
Indicates if Cno sample have been received since last C/N0 control message sent.
Callback< bool, Ptr< SatControlMessage >, const Address & > SendCtrlMsgCallback
SatBeamScheduler::SendTbtpCallback m_txTbtpCallback
The TBTP send callback to inform GW Mac.
void AddRaChannels(std::vector< Ptr< SatTbtpMessage >> &tbtpContainer)
Add RA channel information to TBTP(s).
void DoPreResourceAllocation()
Do pre-allocation of the symbols per UT/RC, before time slot generation.
Time m_maxTwoWayPropagationDelay
Maximum two-way propagation delay estimate between GW-SAT-UT-SAT-GW.
void RemoveUtInfo(UtInfoMap_t::iterator iterator)
TracedCallback< uint32_t > m_exceedingCapacityTrace
Trace exceeding capacity.
Callback< void, Ptr< SatTbtpMessage > > SendTbtpCallback
void(* UnmetCapacityTraceCallback)(uint32_t unmetCapacity)
Callback signature for the UnmetCapacityTrace trace source.
void AddUtInfo(Address utId, Ptr< SatUtInfo > utInfo)
TracedCallback< uint32_t > m_usableCapacityTrace
Trace usable capacity.
TracedCallback< uint32_t, double > m_frameLoadTrace
Trace frame load ratio.
void DoDispose(void)
Dispose actions for SatBeamScheduler.
Address GetGwAddress(void) const
Return the address of the gateway responsible of this beam.
SatBeamScheduler::SendCtrlMsgCallback m_txCallback
The control message send callback.
uint32_t m_logonChannelIndex
Logon channel ID to exclude it from the RA channel selection.
SatEnums::SuperframeAllocatorType_t m_superframeAllocatorType
Type of SatSuperframeAllocator class to use.
void ConnectUt(Mac48Address address)
Connect a new UT address to this scheduler.
HandoverInformationForward_t
Strategies to exchange informations between beams.
void ConnectGw(Mac48Address address)
Connect a new GW address to this scheduler.
void SetSendTbtpCallback(SendTbtpCallback cb)
Set the callback to inform NCC a TBTP has been sent.
Time m_controlSlotInterval
Interval to generate control time slots.
bool Send(Ptr< SatControlMessage > message)
Send control messages to the beam.
bool SendTo(Ptr< SatControlMessage > message, Address utId)
Send control message to an UT into the beam.
std::map< Address, Ptr< SatUtInfo > > UtInfoMap_t
Map container to store UT information.
Ptr< SatSuperframeSeq > m_superframeSeq
Pointer to super frame sequence.
Ptr< SatCnoEstimator > CreateCnoEstimator()
Create estimator for the UT according to set attributes.
Ptr< SatSuperframeAllocator > m_superframeAllocator
Superframe allocator to maintain load information of the frames and their configurations.
TracedCallback< std::string > m_backlogRequestsTrace
Trace for backlog requests done to beam scheduler.
void Initialize(uint32_t satId, uint32_t beamId, Ptr< SatNetDevice > gwNetDevice, Ptr< SatOrbiterNetDevice > orbiterNetDevice, SatBeamScheduler::SendCtrlMsgCallback cb, Ptr< SatSuperframeSeq > seq, uint32_t maxFrameSizeInBytes, Address satAddress, Address gwAddress)
TracedCallback< uint32_t, uint32_t > m_frameUtLoadTrace
Trace count of UTs scheduled per Frame.
bool HasUt()
Check whether an UT is handled by this scheduler.
Ptr< SatOrbiterNetDevice > m_orbiterNetDevice
OrbiterNetDevice on satellite linked to this beam.
TracedCallback< uint32_t > m_waveformTrace
Trace first wave form scheduled for the UT.
Ptr< RandomVariableStream > m_raChRandomIndex
Random variable stream to select RA channel for a UT.
void(* ExceedingCapacityTraceCallback)(uint32_t exceedingCapacity)
Callback signature for the ExceedingCapacityTrace trace source.
void(* BacklogRequestsTraceCallback)(std::string trace)
Callback signature for BacklogRequestsTrace trace source.
static TypeId GetTypeId(void)
Get the type ID.
Time m_maxTbtpTxAndProcessingDelay
Maximum TBTP tx and processing delay estimate at the GW (scheduler).
uint32_t m_satId
ID of the satellite using this beam.
void SendCnoToSatellite()
Send an estimation of cno to satellite, if samples have been received.
void TransferUtToBeam(Address utId, Ptr< SatBeamScheduler > destination)
Transfer ownership of a terminal to the given SatBeamScheduler.
void ReserveLogonChannel(uint32_t logonChannelId)
std::list< UtReqInfoItem_t > UtReqInfoContainer_t
Container to store capacity request information for the UTs.
~SatBeamScheduler()
Destroy a SatBeamScheduler.
uint32_t m_superFrameCounter
Counter for super frame sequence.
Ptr< SatTimuMessage > CreateTimu() const
Create a TIM unicast message containing enough data for a terminal to connect to the beam handled by ...
void RemoveUt(Address utId)
Remove a UT from its SatBeamScheduler.
UtReqInfoContainer_t m_utRequestInfos
Container including every UT's allocation requests.
Address m_satelliteMac
MAC address of the satellite (used when regenerative)
SatCnoEstimator::EstimationMode_t m_cnoEstimatorMode
Mode used for C/N0 estimator.
std::pair< Address, SatFrameAllocator::SatFrameAllocReq > UtReqInfoItem_t
Pair to store capacity request information for the UT.
void Schedule()
Schedule UTs added (registered) to scheduler.
void SetUseLora(bool useLora)
Set if SNS-3 is used with Lora standard.
bool m_controlSlotsEnabled
Flag to indicated if control time slots generation is enabled.
void(* UsableCapacityTraceCallback)(uint32_t usableCapacity)
Callback signature for the UsableCapacityTrace trace source.
uint32_t m_beamId
ID of the beam.
Address GetSatAddress(void) const
Return the address of the satellite responsible of this beam.
uint32_t UpdateDamaEntriesWithReqs()
Update dama entries with received requests at beginning of the scheduling.
void UpdateUtCno(Address utId, double cno)
Update UT C/N0 info with the latest value.
void(* WaveformTraceCallback)(uint32_t waveformId)
Callback signature for WaveformTrace trace source.
bool m_useLora
Flag indicating if lora standard is used.
SatBeamScheduler()
Construct a SatBeamScheduler.
uint32_t AddUt(Address utId, Ptr< SatLowerLayerServiceConf > llsConf)
Add UT to scheduler.
UtInfoMap_t m_utInfos
Map to store UT information in beam for updating purposes.
Ptr< SatGwMac > m_gwMac
GW MAC linked to this beam.
void UpdateSatelliteCno(Address satelliteMac, double cno)
Update satellite C/N0 info with the latest value.
TracedCallback< uint32_t > m_unmetCapacityTrace
Trace unmet capacity.
EstimationMode_t
Definition of modes for estimator.
std::map< Address, UtAllocInfoItem_t > UtAllocInfoContainer_t
Map container to store UT allocation information.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.