satellite-stats-window-load-helper.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions
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: Budiarto Herman <budiarto.herman@magister.fi>
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/log.h>
29 #include <ns3/magister-gnuplot-aggregator.h>
30 #include <ns3/multi-file-aggregator.h>
31 #include <ns3/node.h>
32 #include <ns3/object-map.h>
33 #include <ns3/object-vector.h>
34 #include <ns3/satellite-geo-net-device.h>
35 #include <ns3/satellite-helper.h>
36 #include <ns3/satellite-phy-rx-carrier.h>
37 #include <ns3/satellite-phy-rx.h>
38 #include <ns3/satellite-phy.h>
39 #include <ns3/scalar-collector.h>
40 #include <ns3/string.h>
41 #include <ns3/unit-conversion-collector.h>
42 
43 #include <sstream>
44 
45 NS_LOG_COMPONENT_DEFINE("SatStatsWindowLoadHelper");
46 
47 namespace ns3
48 {
49 
50 NS_OBJECT_ENSURE_REGISTERED(SatStatsWindowLoadHelper);
51 
53  : SatStatsHelper(satHelper),
54  m_traceSinkCallback(MakeCallback(&SatStatsWindowLoadHelper::WindowLoadCallback, this))
55 {
56  NS_LOG_FUNCTION(this << satHelper);
57 }
58 
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
64 TypeId // static
66 {
67  static TypeId tid = TypeId("ns3::SatStatsWindowLoadHelper").SetParent<SatStatsHelper>();
68  return tid;
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this << windowLoad);
75 
76  switch (GetOutputType())
77  {
80  Ptr<ScalarCollector> c = m_collector->GetObject<ScalarCollector>();
81  NS_ASSERT(c != nullptr);
82  c->TraceSinkDouble(0.0, windowLoad);
83  break;
84  }
85 
88  Ptr<UnitConversionCollector> c = m_collector->GetObject<UnitConversionCollector>();
89  NS_ASSERT(c != nullptr);
90  c->TraceSinkDouble(0.0, windowLoad);
91  break;
92  }
93 
100  Ptr<DistributionCollector> c = m_collector->GetObject<DistributionCollector>();
101  NS_ASSERT(c != nullptr);
102  c->TraceSinkDouble(0.0, windowLoad);
103  break;
104  }
105 
106  default:
107  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
108  << " is not a valid output type for this statistics.");
109  break;
110 
111  } // end of `switch (GetOutputType ())`
112 
113 } // end of `void RxPowerCallback (double);`
114 
115 Callback<void, double>
117 {
118  return m_traceSinkCallback;
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION(this);
125 
126  switch (GetOutputType())
127  {
129  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
130  << " is not a valid output type for this statistics.");
131  break;
132 
134  // Setup aggregator.
135  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
136  "OutputFileName",
137  StringValue(GetOutputFileName()),
138  "MultiFileMode",
139  BooleanValue(false),
140  "EnableContextPrinting",
141  BooleanValue(true),
142  "GeneralHeading",
143  StringValue(GetIdentifierHeading("window_load")));
144  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
145 
146  // Setup collector.
147  Ptr<ScalarCollector> collector = CreateObject<ScalarCollector>();
148  collector->SetName("0");
149  collector->SetInputDataType(ScalarCollector::INPUT_DATA_TYPE_DOUBLE);
150  collector->SetOutputType(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE);
151  collector->TraceConnect("Output",
152  "0",
153  MakeCallback(&MultiFileAggregator::Write1d, aggregator));
154  m_collector = collector->GetObject<DataCollectionObject>();
155 
156  break;
157  }
158 
160  // Setup aggregator.
161  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
162  "OutputFileName",
163  StringValue(GetOutputFileName()),
164  "GeneralHeading",
165  StringValue(GetTimeHeading("window_load")));
166  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
167 
168  // Setup collector.
169  Ptr<UnitConversionCollector> collector = CreateObject<UnitConversionCollector>();
170  collector->SetName("0");
171  collector->SetConversionType(UnitConversionCollector::TRANSPARENT);
172  collector->TraceConnect("OutputTimeValue",
173  "0",
174  MakeCallback(&MultiFileAggregator::Write2d, aggregator));
175  m_collector = collector->GetObject<DataCollectionObject>();
176 
177  break;
178  }
179 
183  // Setup aggregator.
184  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
185  "OutputFileName",
186  StringValue(GetOutputFileName()),
187  "GeneralHeading",
188  StringValue(GetDistributionHeading("window_load")));
189  Ptr<MultiFileAggregator> aggregator = m_aggregator->GetObject<MultiFileAggregator>();
190 
191  // Setup collector.
192  Ptr<DistributionCollector> collector = CreateObject<DistributionCollector>();
193  collector->SetName("0");
195  {
196  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_HISTOGRAM);
197  }
199  {
200  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_PROBABILITY);
201  }
203  {
204  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_CUMULATIVE);
205  }
206  collector->TraceConnect("Output",
207  "0",
208  MakeCallback(&MultiFileAggregator::Write2d, aggregator));
209  collector->TraceConnect("OutputString",
210  "0",
211  MakeCallback(&MultiFileAggregator::AddContextHeading, aggregator));
212  collector->TraceConnect(
213  "Warning",
214  "0",
215  MakeCallback(&MultiFileAggregator::EnableContextWarning, aggregator));
216  m_collector = collector->GetObject<DataCollectionObject>();
217 
218  break;
219  }
220 
223  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
224  << " is not a valid output type for this statistics.");
225  break;
226 
228  // Setup aggregator.
229  m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
230  "OutputPath",
231  StringValue(GetOutputPath()),
232  "OutputFileName",
233  StringValue(GetName()));
234  Ptr<MagisterGnuplotAggregator> plotAggregator =
235  m_aggregator->GetObject<MagisterGnuplotAggregator>();
236  NS_ASSERT(plotAggregator != nullptr);
237  // plot->SetTitle ("");
238  plotAggregator->SetLegend("Time (in seconds)", "Window normalized load (in bps/Hz)");
239  plotAggregator->Add2dDataset("0", "0");
240  plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
241 
242  // Setup collector.
243  Ptr<UnitConversionCollector> collector = CreateObject<UnitConversionCollector>();
244  collector->SetName("0");
245  collector->SetConversionType(UnitConversionCollector::TRANSPARENT);
246  collector->TraceConnect("OutputTimeValue",
247  "0",
248  MakeCallback(&MagisterGnuplotAggregator::Write2d, plotAggregator));
249  m_collector = collector->GetObject<DataCollectionObject>();
250 
251  break;
252  }
253 
257  // Setup aggregator.
258  m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
259  "OutputPath",
260  StringValue(GetOutputPath()),
261  "OutputFileName",
262  StringValue(GetName()));
263  Ptr<MagisterGnuplotAggregator> plotAggregator =
264  m_aggregator->GetObject<MagisterGnuplotAggregator>();
265  NS_ASSERT(plotAggregator != nullptr);
266  // plot->SetTitle ("");
267  plotAggregator->SetLegend("Window normalized load (in bps/Hz)", "Frequency");
268  plotAggregator->Add2dDataset("0", "0");
269  plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
270 
271  // Setup collector.
272  Ptr<DistributionCollector> collector = CreateObject<DistributionCollector>();
273  collector->SetName("0");
275  {
276  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_HISTOGRAM);
277  }
279  {
280  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_PROBABILITY);
281  }
283  {
284  collector->SetOutputType(DistributionCollector::OUTPUT_TYPE_CUMULATIVE);
285  }
286  collector->TraceConnect("Output",
287  "0",
288  MakeCallback(&MagisterGnuplotAggregator::Write2d, plotAggregator));
289  m_collector = collector->GetObject<DataCollectionObject>();
290 
291  break;
292  }
293 
294  default:
295  NS_FATAL_ERROR("SatStatsWindowLoadHelper - Invalid output type");
296  break;
297  }
298 
299  // Setup probes and connect them to the collectors.
300  InstallProbes();
301 
302 } // end of `void DoInstall ();`
303 
304 void
306 {
307  // The method below is supposed to be implemented by the child class.
308  DoInstallProbes();
309 }
310 
311 // RETURN FEEDER LINK ////////////////////////////////////////////////////////
312 
313 NS_OBJECT_ENSURE_REGISTERED(SatStatsRtnFeederWindowLoadHelper);
314 
316  : SatStatsWindowLoadHelper(satHelper)
317 {
318  NS_LOG_FUNCTION(this << satHelper);
319 }
320 
322 {
323  NS_LOG_FUNCTION(this);
324 }
325 
326 TypeId // static
328 {
329  static TypeId tid =
330  TypeId("ns3::SatStatsRtnFeederWindowLoadHelper").SetParent<SatStatsWindowLoadHelper>();
331  return tid;
332 }
333 
334 void
336 {
337  NS_LOG_FUNCTION(this);
338 
339  NodeContainer gws = GetSatHelper()->GetBeamHelper()->GetGwNodes();
340  for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
341  {
342  NetDeviceContainer devs = GetGwSatNetDevice(*it);
343 
344  for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
345  {
346  Ptr<SatNetDevice> satDev = (*itDev)->GetObject<SatNetDevice>();
347  NS_ASSERT(satDev != nullptr);
348  Ptr<SatPhy> satPhy = satDev->GetPhy();
349  NS_ASSERT(satPhy != nullptr);
350  Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
351  NS_ASSERT(satPhyRx != nullptr);
352  ObjectVectorValue carriers;
353  satPhyRx->GetAttribute("RxCarrierList", carriers);
354  NS_LOG_DEBUG(this << " Node ID " << (*it)->GetId() << " device #"
355  << (*itDev)->GetIfIndex() << " has " << carriers.GetN()
356  << " RX carriers");
357 
358  for (ObjectVectorValue::Iterator itCarrier = carriers.Begin();
359  itCarrier != carriers.End();
360  ++itCarrier)
361  {
362  if (DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType() !=
363  SatPhyRxCarrier::CarrierType::RA_ESSA)
364  {
365  continue;
366  }
367  // NS_ASSERT (itCarrier->second->m_channelType == SatEnums::RETURN_FEEDER_CH)
368  if (!itCarrier->second->TraceConnectWithoutContext("WindowLoad",
370  {
371  NS_FATAL_ERROR("Error connecting to WindowLoad trace source"
372  << " of SatPhyRxCarrier"
373  << " at node ID " << (*it)->GetId() << " device #"
374  << (*itDev)->GetIfIndex() << " RX carrier #"
375  << itCarrier->first);
376  }
377 
378  } // end of `for (ObjectVectorValue::Iterator itCarrier = carriers)`
379 
380  } // end of `for (it = gws.Begin(); it != gws.End (); ++it)`
381 
382  } // end of `for (itDev = devs.Begin (); itDev != devs.End (); ++itDev)`
383 
384 } // end of `void DoInstallProbes ();`
385 
386 } // end of namespace ns3
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)
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.
OutputType_t GetOutputType() const
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
virtual std::string GetDistributionHeading(std::string dataLabel) const
Produce return feeder window load statistics from a satellite module simulation.
SatStatsRtnFeederWindowLoadHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
Abstract class inherited by SatStatsRtnFeederWindowLoadHelper.
void WindowLoadCallback(double windowLoad)
Receive inputs from trace sources and forward them to the collector.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
void InstallProbes()
Set up several probes or other means of listeners and connect them to the collectors.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
Callback< void, double > GetTraceSinkCallback() const
virtual void DoInstallProbes()=0
SatStatsWindowLoadHelper(Ptr< const SatHelper > satHelper)
Ptr< DataCollectionObject > m_collector
The collector created by this helper.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.