satellite-scpc-scheduler.cc
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  *
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: Bastien Tauran <bastien.tauran@viveris.fr>
19  */
20 
22 
23 #include <ns3/log.h>
24 
25 #include <utility>
26 #include <vector>
27 
28 NS_LOG_COMPONENT_DEFINE("SatScpcScheduler");
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatScpcScheduler);
34 
35 TypeId
37 {
38  static TypeId tid =
39  TypeId("ns3::SatScpcScheduler")
40  .SetParent<SatFwdLinkScheduler>()
41  .AddConstructor<SatScpcScheduler>()
42  .AddAttribute("SchedulingStartThresholdTime",
43  "Threshold time of total transmissions in BB Frame container to trigger "
44  "a scheduling round.",
45  TimeValue(MilliSeconds(5)),
47  MakeTimeChecker())
48  .AddAttribute("SchedulingStopThresholdTime",
49  "Threshold time of total transmissions in BB Frame container to stop a "
50  "scheduling round.",
51  TimeValue(MilliSeconds(15)),
53  MakeTimeChecker())
54  .AddAttribute("BBFrameContainer",
55  "BB frame container of this scheduler.",
56  PointerValue(),
57  MakePointerAccessor(&SatScpcScheduler::m_bbFrameContainer),
58  MakePointerChecker<SatBbFrameContainer>());
59  return tid;
60 }
61 
62 TypeId
64 {
65  NS_LOG_FUNCTION(this);
66 
67  return GetTypeId();
68 }
69 
72 {
73  NS_LOG_FUNCTION(this);
74  NS_FATAL_ERROR("Default constructor for SatScpcScheduler not supported");
75 }
76 
77 SatScpcScheduler::SatScpcScheduler(Ptr<SatBbFrameConf> conf,
78  Mac48Address address,
79  double carrierBandwidthInHz)
80  : SatFwdLinkScheduler(conf, address, carrierBandwidthInHz),
81  m_symbolsSent(0)
82 {
83  NS_LOG_FUNCTION(this);
84 
85  ObjectBase::ConstructSelf(AttributeConstructionList());
86 
87  std::vector<SatEnums::SatModcod_t> modCods = conf->GetModCodsUsed();
88 
89  m_bbFrameContainer = CreateObject<SatBbFrameContainer>(modCods, m_bbFrameConf);
90 
92 }
93 
95 {
96  NS_LOG_FUNCTION(this);
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION(this);
104  m_bbFrameContainer = nullptr;
105 }
106 
107 std::pair<Ptr<SatBbFrame>, const Time>
109 {
110  NS_LOG_FUNCTION(this);
111 
112  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStartThresholdTime)
113  {
115  }
116 
117  Ptr<SatBbFrame> frame = m_bbFrameContainer->GetNextFrame();
118  Time frameDuration;
119 
120  if (frame != nullptr)
121  {
122  m_symbolsSent += ceil(frame->GetDuration().GetSeconds() * m_carrierBandwidthInHz);
123  }
124 
125  // create dummy frame
126  if (m_dummyFrameSendingEnabled && frame == nullptr)
127  {
128  frame = Create<SatBbFrame>(m_bbFrameConf->GetDefaultModCod(),
130  m_bbFrameConf);
131 
132  // create dummy packet
133  Ptr<Packet> dummyPacket = Create<Packet>(1);
134 
135  // Add MAC tag
136  SatMacTag mTag;
137  mTag.SetDestAddress(Mac48Address::GetBroadcast());
139  dummyPacket->AddPacketTag(mTag);
140 
141  // Add E2E address tag
142  SatAddressE2ETag addressE2ETag;
143  addressE2ETag.SetE2EDestAddress(Mac48Address::GetBroadcast());
144  addressE2ETag.SetE2ESourceAddress(m_macAddress);
145  dummyPacket->AddPacketTag(addressE2ETag);
146 
147  // Add dummy packet to dummy frame
148  frame->AddPayload(dummyPacket);
149 
150  frameDuration = frame->GetDuration();
151  }
152  // If no bb frame available and dummy frames disabled
153  else if (frame == nullptr)
154  {
155  frameDuration = m_bbFrameConf->GetDummyBbFrameDuration();
156  }
157 
158  if (frame != nullptr)
159  {
160  frameDuration = frame->GetDuration();
161  frame->SetSliceId(0);
162  }
163 
164  return std::make_pair(frame, frameDuration);
165 }
166 
167 void
169 {
170  NS_LOG_FUNCTION(this);
171 
174 
175  Simulator::Schedule(m_periodicInterval, &SatScpcScheduler::PeriodicTimerExpired, this);
176 }
177 
178 void
180 {
181  NS_LOG_FUNCTION(this);
182 
183  m_schedulingSymbolRateTrace(0, m_symbolsSent / Seconds(1).GetSeconds());
184 
185  m_symbolsSent = 0;
186 }
187 
188 void
190 {
191  NS_LOG_FUNCTION(this);
192 
193  // Get scheduling objects from LLC
194  std::vector<Ptr<SatSchedulingObject>> so;
196 
197  for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin();
198  (it != so.end()) &&
199  (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime);
200  it++)
201  {
202  uint32_t currentObBytes = (*it)->GetBufferedBytes();
203  uint32_t currentObMinReqBytes = (*it)->GetMinTxOpportunityInBytes();
204  uint8_t flowId = (*it)->GetFlowId();
205  SatEnums::SatModcod_t modcod =
206  m_bbFrameContainer->GetModcod(flowId, GetSchedulingObjectCno(*it));
207 
208  uint32_t frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
209 
210  while (((m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)) &&
211  (currentObBytes > 0))
212  {
213  if (frameBytes < currentObMinReqBytes)
214  {
215  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) -
216  m_bbFrameConf->GetBbFrameHeaderSizeInBytes();
217 
218  // if frame bytes still too small, we must have too long control message, so let's
219  // crash
220  if (frameBytes < currentObMinReqBytes)
221  {
222  NS_FATAL_ERROR("Control package probably too long!!!");
223  }
224  }
225 
226  Ptr<Packet> p = m_txOpportunityCallback(frameBytes,
227  (*it)->GetMacAddress(),
228  flowId,
229  currentObBytes,
230  currentObMinReqBytes);
231 
232  if (p)
233  {
234  m_bbFrameContainer->AddData(flowId, modcod, p);
235  frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
236  }
237  else if (m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) !=
238  m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod))
239  {
240  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod);
241  }
242  else
243  {
244  NS_FATAL_ERROR("Packet does not fit in empty BB Frame. Control package too long or "
245  "fragmentation problem in user package!!!");
246  }
247  }
248 
250  }
251 }
252 
253 void
254 SatScpcScheduler::GetSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& output)
255 {
256  NS_LOG_FUNCTION(this);
257 
258  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)
259  {
260  // Get scheduling objects from LLC
261  m_schedContextCallback(output);
262 
263  SortSchedulingObjects(output);
264  }
265 }
266 
267 } // namespace ns3
This class implements a tag that carries the satellite MAC of GW and UT.
void SetE2ESourceAddress(Mac48Address e2eSourceAddress)
Set E2E source MAC address.
void SetE2EDestAddress(Mac48Address e2eDestAddress)
Set E2E destination MAC address.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
void SendAndClearSymbolsSentStat()
Send stats and reset all the symbols sent count for each slice to zero.
Ptr< SatBbFrameContainer > m_bbFrameContainer
The container for BB Frames.
~SatScpcScheduler()
Destroy a SatFwdLinkScheduler.
void DoDispose(void)
Do dispose actions.
uint32_t m_symbolsSent
The number of symbols sent for each slice during an allocation cycle.
Time m_schedulingStartThresholdTime
Threshold time of total transmissions in BB Frame container to trigger a scheduling round.
virtual std::pair< Ptr< SatBbFrame >, const Time > GetNextFrame()
Get next frame to be transmitted.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
static TypeId GetTypeId(void)
Get the type ID.
SatScpcScheduler()
Construct a SatFwdLinkScheduler.
void ScheduleBbFrames()
Schedule BB Frames.
void PeriodicTimerExpired()
Handles periodic timer timeouts.
Time m_schedulingStopThresholdTime
Threshold time of total transmissions in BB Frame container to stop a scheduling round.
void GetSchedulingObjects(std::vector< Ptr< SatSchedulingObject >> &output)
Gets scheduling object in sorted order according to configured sorting criteria.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.