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 NS_LOG_COMPONENT_DEFINE("SatScpcScheduler");
26 
27 namespace ns3
28 {
29 
30 NS_OBJECT_ENSURE_REGISTERED(SatScpcScheduler);
31 
32 TypeId
34 {
35  static TypeId tid =
36  TypeId("ns3::SatScpcScheduler")
37  .SetParent<SatFwdLinkScheduler>()
38  .AddConstructor<SatScpcScheduler>()
39  .AddAttribute("SchedulingStartThresholdTime",
40  "Threshold time of total transmissions in BB Frame container to trigger "
41  "a scheduling round.",
42  TimeValue(MilliSeconds(5)),
44  MakeTimeChecker())
45  .AddAttribute("SchedulingStopThresholdTime",
46  "Threshold time of total transmissions in BB Frame container to stop a "
47  "scheduling round.",
48  TimeValue(MilliSeconds(15)),
50  MakeTimeChecker())
51  .AddAttribute("BBFrameContainer",
52  "BB frame container of this scheduler.",
53  PointerValue(),
54  MakePointerAccessor(&SatScpcScheduler::m_bbFrameContainer),
55  MakePointerChecker<SatBbFrameContainer>());
56  return tid;
57 }
58 
59 TypeId
61 {
62  NS_LOG_FUNCTION(this);
63 
64  return GetTypeId();
65 }
66 
69 {
70  NS_LOG_FUNCTION(this);
71  NS_FATAL_ERROR("Default constructor for SatScpcScheduler not supported");
72 }
73 
74 SatScpcScheduler::SatScpcScheduler(Ptr<SatBbFrameConf> conf,
75  Mac48Address address,
76  double carrierBandwidthInHz)
77  : SatFwdLinkScheduler(conf, address, carrierBandwidthInHz),
78  m_symbolsSent(0)
79 {
80  NS_LOG_FUNCTION(this);
81 
82  ObjectBase::ConstructSelf(AttributeConstructionList());
83 
84  std::vector<SatEnums::SatModcod_t> modCods = conf->GetModCodsUsed();
85 
86  m_bbFrameContainer = CreateObject<SatBbFrameContainer>(modCods, m_bbFrameConf);
87 
89 }
90 
92 {
93  NS_LOG_FUNCTION(this);
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION(this);
101  m_bbFrameContainer = NULL;
102 }
103 
104 std::pair<Ptr<SatBbFrame>, const Time>
106 {
107  NS_LOG_FUNCTION(this);
108 
109  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStartThresholdTime)
110  {
112  }
113 
114  Ptr<SatBbFrame> frame = m_bbFrameContainer->GetNextFrame();
115  Time frameDuration;
116 
117  if (frame != NULL)
118  {
119  m_symbolsSent += ceil(frame->GetDuration().GetSeconds() * m_carrierBandwidthInHz);
120  }
121 
122  // create dummy frame
123  if (m_dummyFrameSendingEnabled && frame == NULL)
124  {
125  frame = Create<SatBbFrame>(m_bbFrameConf->GetDefaultModCod(),
127  m_bbFrameConf);
128 
129  // create dummy packet
130  Ptr<Packet> dummyPacket = Create<Packet>(1);
131 
132  // Add MAC tag
133  SatMacTag mTag;
134  mTag.SetDestAddress(Mac48Address::GetBroadcast());
136  dummyPacket->AddPacketTag(mTag);
137 
138  // Add E2E address tag
139  SatAddressE2ETag addressE2ETag;
140  addressE2ETag.SetE2EDestAddress(Mac48Address::GetBroadcast());
141  addressE2ETag.SetE2ESourceAddress(m_macAddress);
142  dummyPacket->AddPacketTag(addressE2ETag);
143 
144  // Add dummy packet to dummy frame
145  frame->AddPayload(dummyPacket);
146 
147  frameDuration = frame->GetDuration();
148  }
149  // If no bb frame available and dummy frames disabled
150  else if (frame == NULL)
151  {
152  frameDuration = m_bbFrameConf->GetDummyBbFrameDuration();
153  }
154 
155  if (frame != NULL)
156  {
157  frameDuration = frame->GetDuration();
158  frame->SetSliceId(0);
159  }
160 
161  return std::make_pair(frame, frameDuration);
162 }
163 
164 void
166 {
167  NS_LOG_FUNCTION(this);
168 
171 
172  Simulator::Schedule(m_periodicInterval, &SatScpcScheduler::PeriodicTimerExpired, this);
173 }
174 
175 void
177 {
178  NS_LOG_FUNCTION(this);
179 
180  m_schedulingSymbolRateTrace(0, m_symbolsSent / Seconds(1).GetSeconds());
181 
182  m_symbolsSent = 0;
183 }
184 
185 void
187 {
188  NS_LOG_FUNCTION(this);
189 
190  // Get scheduling objects from LLC
191  std::vector<Ptr<SatSchedulingObject>> so;
193 
194  for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin();
195  (it != so.end()) &&
196  (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime);
197  it++)
198  {
199  uint32_t currentObBytes = (*it)->GetBufferedBytes();
200  uint32_t currentObMinReqBytes = (*it)->GetMinTxOpportunityInBytes();
201  uint8_t flowId = (*it)->GetFlowId();
202  SatEnums::SatModcod_t modcod =
203  m_bbFrameContainer->GetModcod(flowId, GetSchedulingObjectCno(*it));
204 
205  uint32_t frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
206 
207  while (((m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)) &&
208  (currentObBytes > 0))
209  {
210  if (frameBytes < currentObMinReqBytes)
211  {
212  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) -
213  m_bbFrameConf->GetBbFrameHeaderSizeInBytes();
214 
215  // if frame bytes still too small, we must have too long control message, so let's
216  // crash
217  if (frameBytes < currentObMinReqBytes)
218  {
219  NS_FATAL_ERROR("Control package probably too long!!!");
220  }
221  }
222 
223  Ptr<Packet> p = m_txOpportunityCallback(frameBytes,
224  (*it)->GetMacAddress(),
225  flowId,
226  currentObBytes,
227  currentObMinReqBytes);
228 
229  if (p)
230  {
231  m_bbFrameContainer->AddData(flowId, modcod, p);
232  frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
233  }
234  else if (m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) !=
235  m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod))
236  {
237  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod);
238  }
239  else
240  {
241  NS_FATAL_ERROR("Packet does not fit in empty BB Frame. Control package too long or "
242  "fragmentation problem in user package!!!");
243  }
244  }
245 
247  }
248 }
249 
250 void
251 SatScpcScheduler::GetSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& output)
252 {
253  NS_LOG_FUNCTION(this);
254 
255  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)
256  {
257  // Get scheduling objects from LLC
258  m_schedContextCallback(output);
259 
260  SortSchedulingObjects(output);
261  }
262 }
263 
264 } // 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.