satellite-stats-fwd-link-scheduler-symbol-rate-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 CNES
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  */
21 
23 
24 #include <ns3/boolean.h>
25 #include <ns3/data-collection-object.h>
26 #include <ns3/distribution-collector.h>
27 #include <ns3/enum.h>
28 #include <ns3/interval-rate-collector.h>
29 #include <ns3/log.h>
30 #include <ns3/magister-gnuplot-aggregator.h>
31 #include <ns3/multi-file-aggregator.h>
32 #include <ns3/node-container.h>
33 #include <ns3/object-map.h>
34 #include <ns3/object-vector.h>
35 #include <ns3/pointer.h>
36 #include <ns3/satellite-fwd-link-scheduler.h>
37 #include <ns3/satellite-gw-mac.h>
38 #include <ns3/satellite-helper.h>
39 #include <ns3/satellite-mac.h>
40 #include <ns3/satellite-net-device.h>
41 #include <ns3/scalar-collector.h>
42 #include <ns3/string.h>
43 #include <ns3/unit-conversion-collector.h>
44 
45 #include <sstream>
46 
47 NS_LOG_COMPONENT_DEFINE("SatStatsFwdLinkSchedulerSymbolRateHelper");
48 
49 namespace ns3
50 {
51 
52 NS_OBJECT_ENSURE_REGISTERED(SatStatsFwdLinkSchedulerSymbolRateHelper);
53 
55  Ptr<const SatHelper> satHelper)
56  : SatStatsHelper(satHelper),
57  m_traceSinkCallback(
58  MakeCallback(&SatStatsFwdLinkSchedulerSymbolRateHelper::SymbolRateCallback, this))
59 {
60  NS_LOG_FUNCTION(this << satHelper);
61 }
62 
64 {
65  NS_LOG_FUNCTION(this);
66 }
67 
68 TypeId // static
70 {
71  static TypeId tid =
72  TypeId("ns3::SatStatsFwdLinkSchedulerSymbolRateHelper").SetParent<SatStatsHelper>();
73  return tid;
74 }
75 
76 void
78 {
79  NS_LOG_FUNCTION(this << sliceId << " " << symbolRate);
80 
81  Ptr<DataCollectionObject> collector = NULL;
82 
83  switch (GetIdentifierType())
84  {
86  collector = m_collectors.Get(0);
87  NS_ASSERT_MSG(collector != nullptr, "Unable to find collector with identifier 0");
88  break;
89  }
91  collector = m_collectors.Get(static_cast<uint32_t>(sliceId));
92  NS_ASSERT_MSG(collector != nullptr, "Unable to find collector with identifier " << sliceId);
93  break;
94  }
95  default:
96  NS_FATAL_ERROR("SatStatsFwdLinkSchedulerSymbolRateHelper - Invalid identifier type");
97  break;
98  }
99 
100  switch (GetOutputType())
101  {
104  Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
105  NS_ASSERT(c != nullptr);
106  c->TraceSinkDouble(0.0, symbolRate);
107  break;
108  }
109 
112  Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
113  NS_ASSERT(c != nullptr);
114  c->TraceSinkDouble(0.0, symbolRate);
115  break;
116  }
117 
124  Ptr<DistributionCollector> c = collector->GetObject<DistributionCollector>();
125  NS_ASSERT(c != nullptr);
126  c->TraceSinkDouble(0.0, symbolRate);
127  break;
128  }
129 
130  default:
131  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
132  << " is not a valid output type for this statistics.");
133  break;
134 
135  } // end of `switch (GetOutputType ())`
136 
137 } // end of `void RxPowerCallback (double);`
138 
139 Callback<void, uint8_t, double>
141 {
142  return m_traceSinkCallback;
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION(this);
149 
150  switch (GetOutputType())
151  {
153  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
154  << " is not a valid output type for this statistics.");
155  break;
156 
158  // Setup aggregator.
159  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
160  "OutputFileName",
161  StringValue(GetOutputFileName()),
162  "MultiFileMode",
163  BooleanValue(false),
164  "EnableContextPrinting",
165  BooleanValue(true),
166  "GeneralHeading",
167  StringValue(GetIdentifierHeading("symbol_rate_baud")));
168  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
169 
170  // Setup collectors.
171  m_collectors.SetType("ns3::ScalarCollector");
172  m_collectors.SetAttribute("InputDataType",
173  EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
174  m_collectors.SetAttribute("OutputType",
175  EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SECOND));
177  m_collectors.ConnectToAggregator("Output", m_aggregator, &MultiFileAggregator::Write1d);
178 
179  break;
180  }
181 
183  // Setup aggregator.
184  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
185  "OutputFileName",
186  StringValue(GetOutputFileName()),
187  "GeneralHeading",
188  StringValue(GetTimeHeading("symbol_rate_baud")));
189  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
190 
191  // Setup collectors
192  m_collectors.SetType("ns3::IntervalRateCollector");
193  m_collectors.SetAttribute("InputDataType",
194  EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_DOUBLE));
196  m_collectors.ConnectToAggregator("OutputWithTime",
197  m_aggregator,
198  &MultiFileAggregator::Write2d);
199  m_collectors.ConnectToAggregator("OutputString",
200  m_aggregator,
201  &MultiFileAggregator::AddContextHeading);
202 
203  break;
204  }
205 
209  // Setup aggregator.
210  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
211  "OutputFileName",
212  StringValue(GetOutputFileName()),
213  "GeneralHeading",
214  StringValue(GetDistributionHeading("symbol_rate_baud")));
215  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
216 
217  // Setup collectors.
218  m_collectors.SetType("ns3::DistributionCollector");
219  DistributionCollector::OutputType_t outputType =
220  DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
222  {
223  outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
224  }
226  {
227  outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
228  }
229  m_collectors.SetAttribute("OutputType", EnumValue(outputType));
231  m_collectors.ConnectToAggregator("Output", m_aggregator, &MultiFileAggregator::Write2d);
232  m_collectors.ConnectToAggregator("OutputString",
233  m_aggregator,
234  &MultiFileAggregator::AddContextHeading);
235  m_collectors.ConnectToAggregator("Warning",
236  m_aggregator,
237  &MultiFileAggregator::EnableContextWarning);
238 
239  break;
240  }
241 
244  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
245  << " is not a valid output type for this statistics.");
246  break;
247 
249  // Setup aggregator.
250  m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
251  "OutputPath",
252  StringValue(GetOutputPath()),
253  "OutputFileName",
254  StringValue(GetName()));
255  Ptr<MagisterGnuplotAggregator> plotAggregator =
256  m_aggregator->GetObject<MagisterGnuplotAggregator>();
257  NS_ASSERT(plotAggregator != nullptr);
258  // plot->SetTitle ("");
259  plotAggregator->SetLegend("Time (in seconds)", "Latency (in seconds)");
260  plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
261 
262  // Setup collectors.
263  m_collectors.SetType("ns3::IntervalRateCollector");
264  m_collectors.SetAttribute("InputDataType",
265  EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_DOUBLE));
267  for (CollectorMap::Iterator it = m_collectors.Begin(); it != m_collectors.End(); ++it)
268  {
269  const std::string context = it->second->GetName();
270  plotAggregator->Add2dDataset(context, context);
271  }
272  m_collectors.ConnectToAggregator("OutputWithTime",
273  m_aggregator,
274  &MagisterGnuplotAggregator::Write2d);
275 
276  break;
277  }
278 
282  // Setup aggregator.
283  m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
284  "OutputPath",
285  StringValue(GetOutputPath()),
286  "OutputFileName",
287  StringValue(GetName()));
288  Ptr<MagisterGnuplotAggregator> plotAggregator =
289  m_aggregator->GetObject<MagisterGnuplotAggregator>();
290  NS_ASSERT(plotAggregator != nullptr);
291  // plot->SetTitle ("");
292  plotAggregator->SetLegend("Latency (in seconds)", "Frequency");
293  plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
294 
295  // Setup collectors.
296  m_collectors.SetType("ns3::DistributionCollector");
297  DistributionCollector::OutputType_t outputType =
298  DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
300  {
301  outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
302  }
304  {
305  outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
306  }
307  m_collectors.SetAttribute("OutputType", EnumValue(outputType));
309  for (CollectorMap::Iterator it = m_collectors.Begin(); it != m_collectors.End(); ++it)
310  {
311  const std::string context = it->second->GetName();
312  plotAggregator->Add2dDataset(context, context);
313  }
314  m_collectors.ConnectToAggregator("Output",
315  m_aggregator,
316  &MagisterGnuplotAggregator::Write2d);
317 
318  break;
319  }
320 
321  default:
322  NS_FATAL_ERROR("SatStatsFwdLinkSchedulerSymbolRateHelper - Invalid output type");
323  break;
324  }
325 
326  // Setup probes and connect them to the collectors.
327  InstallProbes();
328 
329 } // end of `void DoInstall ();`
330 
331 void
333 {
334  NS_LOG_FUNCTION(this);
335 
336  // Connect to trace sources at GW nodes.
337  NodeContainer gws = GetSatHelper()->GetBeamHelper()->GetGwNodes();
338 
339  for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
340  {
341  NetDeviceContainer devs = GetGwSatNetDevice(*it);
342 
343  for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
344  {
345  Ptr<SatNetDevice> satDev = (*itDev)->GetObject<SatNetDevice>();
346  NS_ASSERT(satDev != nullptr);
347  Ptr<SatMac> satMac = satDev->GetMac();
348  NS_ASSERT(satMac != nullptr);
349  Ptr<SatGwMac> satGwMac = satMac->GetObject<SatGwMac>();
350  NS_ASSERT(satGwMac != nullptr);
351  PointerValue scheduler;
352  satGwMac->GetAttribute("Scheduler", scheduler);
353  Ptr<SatFwdLinkScheduler> fwdLinkScheduler = scheduler.Get<SatFwdLinkScheduler>();
354  NS_ASSERT(fwdLinkScheduler != nullptr);
355 
356  if (!fwdLinkScheduler->TraceConnectWithoutContext("SymbolRate", GetTraceSinkCallback()))
357  {
358  NS_FATAL_ERROR("Error connecting to Symbol Rate trace source"
359  << " of SatFwdLinkScheduler"
360  << " at node ID " << (*it)->GetId() << " device #"
361  << (*itDev)->GetIfIndex());
362  }
363 
364  } // end of `for (NetDeviceCOntainer::Iterator itDev = devs)`
365 
366  } // end of `for (it = gws.Begin (); it != gws.End (); ++it)`
367 }
368 
369 } // end of namespace ns3
GW specific Mac class for Sat Net Devices.
SatNetDevice to be utilized in the UT and GW nodes.
Parent abstract class of all satellite statistics helpers.
Ptr< const SatHelper > GetSatHelper() const
static NetDeviceContainer GetGwSatNetDevice(Ptr< Node > gwNode)
IdentifierType_t GetIdentifierType() const
static std::string GetOutputTypeName(OutputType_t outputType)
virtual std::string GetIdentifierHeading(std::string dataLabel) const
virtual std::string GetOutputPath() const
Ptr< DataCollectionObject > CreateAggregator(std::string aggregatorTypeId, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue())
Create the aggregator according to the output type.
virtual std::string GetOutputFileName() const
Compute the path and file name where statistics output should be written to.
uint32_t CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
OutputType_t GetOutputType() const
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
virtual std::string GetDistributionHeading(std::string dataLabel) const
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.