satellite-frame-allocator.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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
21 #ifndef SAT_FRAME_ALLOCATOR_H
22 #define SAT_FRAME_ALLOCATOR_H
23 
25 #include "satellite-frame-conf.h"
26 
27 #include <ns3/address.h>
28 #include <ns3/simple-ref-count.h>
29 #include <ns3/traced-callback.h>
30 
31 #include <list>
32 #include <map>
33 #include <stdint.h>
34 #include <utility>
35 #include <vector>
36 
37 namespace ns3
38 {
39 
62 class SatFrameAllocator : public SimpleRefCount<SatFrameAllocator>
63 {
64  public:
68  typedef std::vector<Ptr<SatTbtpMessage>> TbtpMsgContainer_t;
69 
77  typedef std::pair<std::vector<uint32_t>, bool> UtAllocInfoItem_t;
78 
85  typedef std::map<Address, UtAllocInfoItem_t> UtAllocInfoContainer_t;
86 
91  {
92  public:
93  uint32_t m_craBytes;
94  uint32_t m_minRbdcBytes;
95  uint32_t m_rbdcBytes;
96  uint32_t m_vbdcBytes;
97 
99  : m_craBytes(0),
100  m_minRbdcBytes(0),
101  m_rbdcBytes(0),
102  m_vbdcBytes(0)
103  {
104  }
105  };
106 
110  typedef std::vector<SatFrameAllocReqItem> SatFrameAllocReqItemContainer_t;
111 
117  {
118  public:
120  double m_cno;
121  Address m_address;
123 
125  : m_generateCtrlSlot(false),
126  m_cno(NAN)
127  {
128  }
129 
136  : m_generateCtrlSlot(false),
137  m_cno(NAN),
138  m_reqPerRc(req)
139  {
140  }
141  };
142 
146  typedef std::vector<SatFrameAllocReq*> SatFrameAllocContainer_t;
147 
151  typedef enum
152  {
157  } CcLevel_t;
158 
163  {
164  bool operator()(const Ptr<SatFrameAllocator>& a, const Ptr<SatFrameAllocator>& b) const;
165  };
166 
171 
180  SatFrameAllocator(Ptr<SatFrameConf> frameConf,
181  uint8_t frameId,
183  Ptr<SatFrameAllocator> parent);
184 
190  inline uint32_t GetCarrierMinPayloadInBytes() const
191  {
192  return m_frameConf->GetCarrierMinPayloadInBytes();
193  }
194 
200  inline Ptr<SatWaveform> GetMostRobustWaveform() const
201  {
202  return m_mostRobustWaveform;
203  }
204 
210  inline uint16_t GetCarrierCount() const
211  {
212  return m_maxCarrierCount;
213  }
214 
222  void SelectCarriers(uint16_t& amount, uint16_t offset);
223 
224  inline double GetCarrierBandwidthHz(bool checkParent = false) const
225  {
226  if (checkParent && m_frameConf->IsSubdivided())
227  return 0.0;
228  return m_frameConf->GetCarrierBandwidthHz(SatEnums::EFFECTIVE_BANDWIDTH);
229  }
230 
231  inline double GetVolumeBytes() const
232  {
233  return m_maxSymbolsPerCarrier;
234  }
235 
236  inline Ptr<SatFrameAllocator> GetParent() const
237  {
238  return m_parent;
239  }
240 
244  void Reset();
245 
254  bool GetBestWaveform(double cno, uint32_t& waveFormId, double& cnoThreshold) const;
255 
261  double GetCcLoad(CcLevel_t ccLevel);
262 
271  bool Allocate(CcLevel_t ccLevel, SatFrameAllocReq* allocReq, uint32_t waveformId);
272 
278  void PreAllocateSymbols(double targetLoad, bool fcaEnabled);
279 
291  uint32_t maxSizeInBytes,
292  UtAllocInfoContainer_t& utAllocContainer,
293  bool rcBasedAllocationEnabled,
294  TracedCallback<uint32_t> waveformTrace,
295  TracedCallback<uint32_t, uint32_t> utLoadTrace,
296  TracedCallback<uint32_t, double> loadTrace);
297 
298  private:
304  {
305  public:
306  double m_craSymbols;
310 
315  : m_craSymbols(0.0),
316  m_minRbdcSymbols(0.0),
317  m_rbdcSymbols(0.0),
318  m_vbdcSymbols(0.0)
319  {
320  }
321 
328  {
330  }
331  };
332 
336  typedef std::vector<SatFrameAllocInfoItem> SatFrameAllocInfoItemContainer_t;
337 
344  {
345  public:
347  double m_craSymbols;
351 
356 
361 
365  SatFrameAllocInfo(uint8_t countOfRcs);
366 
375  Ptr<SatWaveform> trcWaveForm,
376  bool ctrlSlotPresent,
377  double ctrlSlotLength);
378 
385 
390  double GetTotalSymbols();
391  };
392 
396  typedef struct
397  {
398  double m_cno;
401  } UtAllocItem_t;
402 
408  typedef std::pair<Address, uint8_t> RcAllocItem_t;
409 
413  typedef std::map<Address, UtAllocItem_t> UtAllocContainer_t;
414 
418  typedef std::list<RcAllocItem_t> RcAllocContainer_t;
419 
424  {
425  public:
429  typedef enum
430  {
434  } CcReqType_t;
435 
442  CcReqCompare(const UtAllocContainer_t& utAllocContainer,
443  CcReqCompare::CcReqType_t ccReqType);
444 
452  bool operator()(RcAllocItem_t rcAlloc1, RcAllocItem_t rcAlloc2);
453 
454  private:
459 
464  };
465 
467 
468  // total symbols in frame.
470 
471  // available (left) symbols in frame.
473 
474  // pre-allocated CRA symbols in frame
476 
477  // pre-allocated minimum RBDC symbols in frame
479 
480  // pre-allocated RBDC symbols in frame
482 
483  // pre-allocated minimum VBDC symbols in frame
485 
486  // maximum symbols available in frame
488 
489  // maximum carriers available in frame
491 
492  // skipped carriers at the beginning of the frame
494 
495  // configuration type of the frame
497 
498  // Id of the frame
499  uint8_t m_frameId;
500 
501  // Burst lengths in use.
503 
504  // Waveform configuration
505  Ptr<SatWaveformConf> m_waveformConf;
506 
507  // Frame configuration
508  Ptr<SatFrameConf> m_frameConf;
509 
510  // Parent allocator in case of carrier subdivision
511  Ptr<SatFrameAllocator> m_parent;
512 
513  // UT allocation container
515 
516  // RC allocation container
518 
519  // The most robust waveform
520  Ptr<SatWaveform> m_mostRobustWaveform;
521 
522  // Guard time in symbols to apply
524 
530  void ShareSymbols(bool fcaEnabled);
531 
541  uint32_t GetOptimalBurtsLengthInSymbols(int64_t symbolsToUse,
542  int64_t symbolsLeft,
543  double cno,
544  uint32_t& waveformId);
545 
558  Ptr<SatTimeSlotConf> CreateTimeSlot(uint16_t carrierId,
559  int64_t& utSymbolsToUse,
560  int64_t& carrierSymbolsToUse,
561  int64_t& utSymbolsLeft,
562  int64_t& rcSymbolsLeft,
563  double cno,
564  bool rcBasedAllocationEnabled);
565 
577  Ptr<SatTimeSlotConf> CreateCtrlTimeSlot(uint16_t carrierId,
578  int64_t& utSymbolsToUse,
579  int64_t& carrierSymbolsToUse,
580  int64_t& utSymbolsLeft,
581  int64_t& rcSymbolsLeft,
582  bool rcBasedAllocationEnabled);
583 
590  void UpdateAndStoreAllocReq(Address address, double cno, SatFrameAllocInfo& req);
591 
597  void AcceptRequests(CcLevel_t ccLevel);
598 
604  std::vector<Address> SortUts();
605 
611  std::vector<uint16_t> SortCarriers();
612 
619  std::vector<uint32_t> SortUtRcs(Address ut);
620 
629  SatFrameAllocator::UtAllocInfoContainer_t::iterator GetUtAllocItem(
630  UtAllocInfoContainer_t& allocContainer,
631  Address ut);
632 
640  Ptr<SatTbtpMessage> CreateNewTbtp(TbtpMsgContainer_t& tbtpContainer);
641 };
642 
643 } // namespace ns3
644 
645 #endif /* SAT_FRAME_ALLOCATOR_H */
CcReqCompare class for CC type comparisons.
CcReqType_t
Definition for different comparison types.
CcReqCompare(const UtAllocContainer_t &utAllocContainer, CcReqCompare::CcReqType_t ccReqType)
Construct CcReqCompare.
bool operator()(RcAllocItem_t rcAlloc1, RcAllocItem_t rcAlloc2)
Comparison operator to compare two RC allocations.
CcReqType_t m_ccReqType
Type used for comparisons.
const UtAllocContainer_t & m_utAllocContainer
Reference to UT allocation container.
SatFrameAllocInfo is used to hold a frame's allocation info in symbols.
SatFrameAllocInfoItemContainer_t m_allocInfoPerRc
Information for the RCs.
SatFrameAllocInfo()
Construct empty SatFrameAllocInfo.
double GetTotalSymbols()
Get total symbols of the item.
SatFrameAllocInfoItem UpdateTotalCounts()
Update total count of SatFrameAllocInfo from RCs.
Allocation information item for requests and allocations [symbols] used internally by SatFrameAllocat...
SatFrameAllocInfoItem()
Construct SatFrameAllocInfoItem.
double GetTotalSymbols()
Get symbols allocated/requested by this item.
SatFrameAllocReq is used to define frame allocation parameters when requesting allocation from SatFra...
SatFrameAllocReq(SatFrameAllocReqItemContainer_t req)
Construct SatFrameAllocReq.
Allocation information item for the UT/RC requests [bytes].
helper class for Satellite Superframe Allocator.
std::list< RcAllocItem_t > RcAllocContainer_t
Container for RC allocation items.
void ShareSymbols(bool fcaEnabled)
Share symbols between all UTs and RCs allocated to the frame.
std::vector< uint16_t > SortCarriers()
Sort carriers belonging to this frame.
Ptr< SatWaveform > m_mostRobustWaveform
Ptr< SatFrameAllocator > GetParent() const
double GetCcLoad(CcLevel_t ccLevel)
Get frame load by requested CC.
std::vector< SatFrameAllocReq * > SatFrameAllocContainer_t
Container to store SatFrameAllocReq item pointers.
SatSuperframeConf::ConfigType_t m_configType
void SelectCarriers(uint16_t &amount, uint16_t offset)
Set the amount of carriers used in this frame.
std::map< Address, UtAllocItem_t > UtAllocContainer_t
Map container for UT allocation items.
SatFrameAllocator::UtAllocInfoContainer_t::iterator GetUtAllocItem(UtAllocInfoContainer_t &allocContainer, Address ut)
Get UT allocation item from given container.
bool Allocate(CcLevel_t ccLevel, SatFrameAllocReq *allocReq, uint32_t waveformId)
Allocate symbols to this frame, if criteria are fulfilled.
bool GetBestWaveform(double cno, uint32_t &waveFormId, double &cnoThreshold) const
Get the best waveform supported by this allocator based on given C/N0.
Ptr< SatWaveform > GetMostRobustWaveform() const
Get the most robust waveform used by this frame allocator.
SatWaveformConf::BurstLengthContainer_t m_burstLenghts
Ptr< SatWaveformConf > m_waveformConf
void Reset()
Reset frame allocator.
SatFrameAllocator()
Default constructor (not in used)
std::vector< Address > SortUts()
Sort UTs allocated to this frame.
std::pair< std::vector< uint32_t >, bool > UtAllocInfoItem_t
Pair used to store UT allocation information.
Ptr< SatTimeSlotConf > CreateTimeSlot(uint16_t carrierId, int64_t &utSymbolsToUse, int64_t &carrierSymbolsToUse, int64_t &utSymbolsLeft, int64_t &rcSymbolsLeft, double cno, bool rcBasedAllocationEnabled)
Create time slot according to configuration type.
void UpdateAndStoreAllocReq(Address address, double cno, SatFrameAllocInfo &req)
Update RC/CC requested according to carrier limit.
void AcceptRequests(CcLevel_t ccLevel)
Accept UT/RC requests of the frame according to given CC level.
std::vector< SatFrameAllocInfoItem > SatFrameAllocInfoItemContainer_t
Container to store SatFrameAllocInfoItem items.
std::vector< Ptr< SatTbtpMessage > > TbtpMsgContainer_t
Container to store generated TBTP messages.
uint32_t GetOptimalBurtsLengthInSymbols(int64_t symbolsToUse, int64_t symbolsLeft, double cno, uint32_t &waveformId)
Get optimal burst length in symbols.
uint32_t GetCarrierMinPayloadInBytes() const
Get minimum payload of a carrier in bytes.
Ptr< SatFrameAllocator > m_parent
Ptr< SatTimeSlotConf > CreateCtrlTimeSlot(uint16_t carrierId, int64_t &utSymbolsToUse, int64_t &carrierSymbolsToUse, int64_t &utSymbolsLeft, int64_t &rcSymbolsLeft, bool rcBasedAllocationEnabled)
Create control time slot.
Ptr< SatTbtpMessage > CreateNewTbtp(TbtpMsgContainer_t &tbtpContainer)
Creates new TBTP to given container with information of the last TBTP in container.
void GenerateTimeSlots(SatFrameAllocator::TbtpMsgContainer_t &tbtpContainer, uint32_t maxSizeInBytes, UtAllocInfoContainer_t &utAllocContainer, bool rcBasedAllocationEnabled, TracedCallback< uint32_t > waveformTrace, TracedCallback< uint32_t, uint32_t > utLoadTrace, TracedCallback< uint32_t, double > loadTrace)
Generate time slots for UT/RCs i.e.
@ CC_LEVEL_CRA_RBDC
CC level CRA + RBDC.
@ CC_LEVEL_CRA_RBDC_VBDC
CC level CRA + RBDC + VBDC.
@ CC_LEVEL_CRA_MIN_RBDC
CC level CRA + Minimum RBDC.
std::map< Address, UtAllocInfoItem_t > UtAllocInfoContainer_t
Map container to store UT allocation information.
std::pair< Address, uint8_t > RcAllocItem_t
Pair used as RC allocation item.
uint16_t GetCarrierCount() const
Get the amount of carriers used in this frame.
void PreAllocateSymbols(double targetLoad, bool fcaEnabled)
Preallocate symbols for all UTs with RCs allocated to the frame.
double GetCarrierBandwidthHz(bool checkParent=false) const
std::vector< SatFrameAllocReqItem > SatFrameAllocReqItemContainer_t
Container to store SatFrameAllocReqItem items.
std::vector< uint32_t > SortUtRcs(Address ut)
Sort RCs in given UT.
ConfigType_t
Enum for configuration types.
std::vector< uint32_t > BurstLengthContainer_t
Define BurstLengthContainer.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
BandwidthComparator is a custom functor meant as comparison function for std::map.
bool operator()(const Ptr< SatFrameAllocator > &a, const Ptr< SatFrameAllocator > &b) const