Loading...
Searching...
No Matches
satellite-fwd-link-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: Sami Rantanen <sami.rantanen@magister.fi>
19 */
20
22
23#include "satellite-enums.h"
24#include "satellite-mac-tag.h"
26
27#include "ns3/boolean.h"
28#include "ns3/double.h"
29#include "ns3/enum.h"
30#include "ns3/log.h"
31#include "ns3/mac48-address.h"
32#include "ns3/nstime.h"
33#include "ns3/pointer.h"
34#include "ns3/simulator.h"
35#include "ns3/trace-source-accessor.h"
36#include "ns3/uinteger.h"
37
38#include <algorithm>
39#include <iostream>
40#include <stdint.h>
41#include <string>
42#include <utility>
43#include <vector>
44
45NS_LOG_COMPONENT_DEFINE("SatFwdLinkScheduler");
46
47namespace ns3
48{
49
50NS_OBJECT_ENSURE_REGISTERED(SatFwdLinkScheduler);
51
52// #define SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
53
54#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
55static void
56PrintSoContent(std::string context, std::vector<Ptr<SatSchedulingObject>>& so)
57{
58 std::cout << context << std::endl;
59
60 for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin(); it != so.end();
61 it++)
62 {
63 std::cout << "So-Content (ptr, priority, load, hol): " << (*it) << ", "
64 << (*it)->GetPriority() << ", " << (*it)->GetBufferedBytes() << ", "
65 << (*it)->GetHolDelay() << std::endl;
66 }
67
68 std::cout << std::endl;
69}
70#endif
71
72bool
73SatFwdLinkScheduler::CompareSoFlowId(Ptr<SatSchedulingObject> obj1, Ptr<SatSchedulingObject> obj2)
74{
75 return (bool)(obj1->GetFlowId() < obj2->GetFlowId());
76}
77
78bool
79SatFwdLinkScheduler::CompareSoPriorityLoad(Ptr<SatSchedulingObject> obj1,
80 Ptr<SatSchedulingObject> obj2)
81{
82 bool result = CompareSoFlowId(obj1, obj2);
83
84 if (obj1->GetFlowId() == obj2->GetFlowId())
85 {
86 result = (bool)(obj1->GetBufferedBytes() > obj2->GetBufferedBytes());
87 }
88
89 return result;
90}
91
92bool
93SatFwdLinkScheduler::CompareSoPriorityHol(Ptr<SatSchedulingObject> obj1,
94 Ptr<SatSchedulingObject> obj2)
95{
96 bool result = CompareSoFlowId(obj1, obj2);
97
98 if (obj1->GetFlowId() == obj2->GetFlowId())
99 {
100 result = (bool)(obj1->GetHolDelay() > obj2->GetHolDelay());
101 }
102
103 return result;
104}
105
106TypeId
108{
109 static TypeId tid =
110 TypeId("ns3::SatFwdLinkScheduler")
111 .SetParent<Object>()
112 .AddAttribute("Interval",
113 "The time for periodic scheduling",
114 TimeValue(MilliSeconds(20)),
116 MakeTimeChecker())
117 .AddAttribute("BBFrameConf",
118 "BB Frame configuration for this scheduler.",
119 PointerValue(),
120 MakePointerAccessor(&SatFwdLinkScheduler::m_bbFrameConf),
121 MakePointerChecker<SatBbFrameConf>())
122 .AddAttribute("DummyFrameSendingEnabled",
123 "Flag to tell, if dummy frames are sent or not.",
124 BooleanValue(false),
126 MakeBooleanChecker())
127 .AddAttribute("AdditionalSortCriteria",
128 "Sorting criteria after priority for scheduling objects from LLC.",
130 MakeEnumAccessor<SatFwdLinkScheduler::ScheduleSortingCriteria_t>(
132 MakeEnumChecker(SatFwdLinkScheduler::NO_SORT,
133 "NoSorting",
135 "DelaySort",
137 "LoadSort"))
138 .AddAttribute("CnoEstimationMode",
139 "Mode of the C/N0 estimator",
140 EnumValue(SatCnoEstimator::LAST),
141 MakeEnumAccessor<SatCnoEstimator::EstimationMode_t>(
143 MakeEnumChecker(SatCnoEstimator::LAST,
144 "LastValueInWindow",
146 "MinValueInWindow",
148 "AverageValueInWindow"))
149 .AddAttribute("CnoEstimationWindow",
150 "Time window for C/N0 estimation.",
151 TimeValue(Seconds(5000)),
153 MakeTimeChecker())
154 .AddTraceSource(
155 "SymbolRate",
156 "Scheduler symbol rate for a given packet",
157 MakeTraceSourceAccessor(&SatFwdLinkScheduler::m_schedulingSymbolRateTrace),
158 "ns3::SatTypedefs::FwdLinkSchedulerSymbolRateCallback")
159
160 ;
161 return tid;
162}
163
168{
169 NS_LOG_FUNCTION(this);
170 NS_FATAL_ERROR("Default constructor for SatFwdLinkScheduler not supported");
171}
172
174 Mac48Address address,
175 double carrierBandwidthInHz)
176 : m_macAddress(address),
177 m_bbFrameConf(conf),
180 m_carrierBandwidthInHz(carrierBandwidthInHz)
181{
182 NS_LOG_FUNCTION(this << conf << address << carrierBandwidthInHz);
183
184 // Random variable used in scheduling
185 m_random = CreateObject<UniformRandomVariable>();
186}
187
188void
190{
191 NS_LOG_FUNCTION(this);
192
193 Object::NotifyConstructionCompleted();
194
196}
197
199{
200 NS_LOG_FUNCTION(this);
201}
202
203void
205{
206 NS_LOG_FUNCTION(this);
207 m_schedContextCallback.Nullify();
208 m_txOpportunityCallback.Nullify();
209 m_sendControlMsgCallback.Nullify();
211}
212
213void
219
220void
226
227void
233
234bool
235SatFwdLinkScheduler::SendControlMsg(Ptr<SatControlMessage> message, const Address& dest) const
236{
237 NS_LOG_FUNCTION(this << message << dest);
238 return m_sendControlMsgCallback(message, dest);
239}
240
241std::pair<Ptr<SatBbFrame>, const Time>
243{
244 NS_FATAL_ERROR("SatFwdLinkScheduler::GetNextFrame: should not be here");
245
246 Ptr<SatBbFrame> f = nullptr;
247
248 return std::make_pair(f, m_bbFrameConf->GetDummyBbFrameDuration());
249}
250
251void
252SatFwdLinkScheduler::CnoInfoUpdated(Mac48Address utAddress, double cnoEstimate)
253{
254 NS_LOG_FUNCTION(this << utAddress << cnoEstimate);
255
256 CnoEstimatorMap_t::const_iterator it = m_cnoEstimatorContainer.find(utAddress);
257
258 if (it == m_cnoEstimatorContainer.end())
259 {
260 Ptr<SatCnoEstimator> estimator = CreateCnoEstimator();
261
262 std::pair<CnoEstimatorMap_t::const_iterator, bool> result =
263 m_cnoEstimatorContainer.insert(std::make_pair(utAddress, estimator));
264 it = result.first;
265
266 if (result.second == false)
267 {
268 NS_FATAL_ERROR("Estimator cannot be added to container!!!");
269 }
270 }
271
272 it->second->AddSample(cnoEstimate);
273}
274
275Time
277{
278 NS_LOG_FUNCTION(this);
279
280 return m_bbFrameConf->GetBbFrameDuration(m_bbFrameConf->GetDefaultModCod(),
282}
283
284void
286{
287 m_dummyFrameSendingEnabled = dummyFrameSendingEnabled;
288}
289
290void
292{
293 NS_LOG_FUNCTION(this);
294
295 NS_FATAL_ERROR("Must use subclasses");
296}
297
298void
300{
301 NS_LOG_FUNCTION(this);
302
305
307}
308
309void
310SatFwdLinkScheduler::GetSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& output)
311{
312 NS_FATAL_ERROR("SatFwdLinkScheduler::GetSchedulingObjects: should not be here");
313}
314
315void
316SatFwdLinkScheduler::SortSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& so)
317{
318 NS_LOG_FUNCTION(this);
319
320 // sort only if there is need to sort
321 if ((so.empty() == false) && (so.size() > 1))
322 {
323#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
324 PrintSoContent("Before sort", so);
325#endif
326
328 {
330 std::sort(so.begin(), so.end(), CompareSoFlowId);
331 break;
332
334 std::sort(so.begin(), so.end(), CompareSoPriorityHol);
335 break;
336
338 std::sort(so.begin(), so.end(), CompareSoPriorityLoad);
339 break;
340
341 default:
342 NS_FATAL_ERROR("Not supported sorting criteria!!!");
343 break;
344 }
345
346#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
347 PrintSoContent("After sort", so);
348#endif
349 }
350}
351
352bool
353SatFwdLinkScheduler::CnoMatchWithFrame(double cno, Ptr<SatBbFrame> frame) const
354{
355 NS_LOG_FUNCTION(this << cno << frame);
356
357 bool match = false;
358
359 SatEnums::SatModcod_t modCod = m_bbFrameConf->GetBestModcod(cno, frame->GetFrameType());
360
361 if (modCod >= frame->GetModcod())
362 {
363 match = true;
364 }
365
366 return match;
367}
368
369double
371{
372 NS_LOG_FUNCTION(this << ob);
373
374 double cno = NAN;
375
376 CnoEstimatorMap_t::const_iterator it = m_cnoEstimatorContainer.find(ob->GetMacAddress());
377
378 if (it != m_cnoEstimatorContainer.end())
379 {
380 cno = it->second->GetCnoEstimation();
381 }
382
383 return cno;
384}
385
386Ptr<SatCnoEstimator>
388{
389 NS_LOG_FUNCTION(this);
390
391 Ptr<SatCnoEstimator> estimator = nullptr;
392
393 switch (m_cnoEstimatorMode)
394 {
398 estimator = Create<SatBasicCnoEstimator>(m_cnoEstimatorMode, m_cnoEstimationWindow);
399 break;
400
401 default:
402 NS_FATAL_ERROR("Not supported C/N0 estimation mode!!!");
403 break;
404 }
405
406 return estimator;
407}
408
409} // namespace ns3
SatCnoEstimator class defines interface for C/N0 estimators.
@ MINIMUM
Minimum value in the given window returned.
@ LAST
Last value in the given window returned.
@ AVERAGE
Average value in the given window returned.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.