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