satellite-stats-packet-drop-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) 2018 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 
22 
23 #include <ns3/boolean.h>
24 #include <ns3/callback.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/nstime.h>
34 #include <ns3/probe.h>
35 #include <ns3/satellite-helper.h>
36 #include <ns3/satellite-ut-handover-module.h>
37 #include <ns3/scalar-collector.h>
38 #include <ns3/singleton.h>
39 #include <ns3/string.h>
40 #include <ns3/unit-conversion-collector.h>
41 
42 #include <sstream>
43 
44 NS_LOG_COMPONENT_DEFINE("SatStatsPacketDropRateHelper");
45 
46 namespace ns3
47 {
48 
49 NS_OBJECT_ENSURE_REGISTERED(SatStatsPacketDropRateHelper);
50 
52  : SatStatsHelper(satHelper)
53 {
54  NS_LOG_FUNCTION(this << satHelper);
55 }
56 
58 {
59  NS_LOG_FUNCTION(this);
60 }
61 
62 TypeId
64 {
65  static TypeId tid = TypeId("ns3::SatStatsPacketDropRateHelper").SetParent<SatStatsHelper>();
66  return tid;
67 }
68 
69 void
71  Ptr<Node> satSrc,
72  Ptr<Node> satDst,
73  bool isError)
74 {
75  NS_LOG_FUNCTION(this << nPackets << satSrc << satDst << isError);
76 
77  uint32_t identifier = GetIdentifierForIsl(satSrc, satDst);
78 
79  // Find the first-level collector with the right identifier.
80  Ptr<DataCollectionObject> collector = m_terminalCollectors.Get(identifier);
81  NS_ASSERT_MSG(collector != nullptr, "Unable to find collector with identifier " << identifier);
82 
83  switch (GetOutputType())
84  {
87  Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
88  NS_ASSERT(c != nullptr);
89  c->TraceSinkBoolean(false, isError);
90  break;
91  }
92 
95  Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
96  NS_ASSERT(c != nullptr);
97  c->TraceSinkBoolean(false, isError);
98  break;
99  }
100 
101  default:
102  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
103  << " is not a valid output type for this statistics.");
104  break;
105 
106  } // end of `switch (GetOutputType ())`
107 }
108 
109 void
111 {
112  NS_LOG_FUNCTION(this);
113 
114  switch (GetOutputType())
115  {
117  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
118  << " is not a valid output type for this statistics.");
119  break;
120 
122  // Setup aggregator.
123  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
124  "OutputFileName",
125  StringValue(GetOutputFileName()),
126  "MultiFileMode",
127  BooleanValue(false),
128  "EnableContextPrinting",
129  BooleanValue(true),
130  "GeneralHeading",
131  StringValue(GetIdentifierHeading("packet_drop_rate")));
132 
133  // Setup collectors.
134  m_terminalCollectors.SetType("ns3::ScalarCollector");
135  m_terminalCollectors.SetAttribute("InputDataType",
136  EnumValue(ScalarCollector::INPUT_DATA_TYPE_BOOLEAN));
137  m_terminalCollectors.SetAttribute(
138  "OutputType",
139  EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
141  m_terminalCollectors.ConnectToAggregator("Output",
142  m_aggregator,
143  &MultiFileAggregator::Write1d);
144  break;
145  }
146 
148  // Setup aggregator.
149  m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
150  "OutputFileName",
151  StringValue(GetOutputFileName()),
152  "GeneralHeading",
153  StringValue(GetTimeHeading("packet_drop_rate")));
154 
155  // Setup collectors.
156  m_terminalCollectors.SetType("ns3::IntervalRateCollector");
157  m_terminalCollectors.SetAttribute(
158  "InputDataType",
159  EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
160  m_terminalCollectors.SetAttribute(
161  "OutputType",
162  EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
164  m_terminalCollectors.ConnectToAggregator("OutputWithTime",
165  m_aggregator,
166  &MultiFileAggregator::Write2d);
167  m_terminalCollectors.ConnectToAggregator("OutputString",
168  m_aggregator,
169  &MultiFileAggregator::AddContextHeading);
170  break;
171  }
172 
176  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
177  << " is not a valid output type for this statistics.");
178  break;
179 
182  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
183  << " is not a valid output type for this statistics.");
184  break;
185 
187  // Setup aggregator.
188  m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
189  "OutputPath",
190  StringValue(GetOutputPath()),
191  "OutputFileName",
192  StringValue(GetName()));
193  Ptr<MagisterGnuplotAggregator> plotAggregator =
194  m_aggregator->GetObject<MagisterGnuplotAggregator>();
195  NS_ASSERT(plotAggregator != nullptr);
196  // plot->SetTitle ("");
197  plotAggregator->SetLegend("Time (in seconds)", "Packet drop rate");
198  plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
199 
200  // Setup collectors.
201  m_terminalCollectors.SetType("ns3::IntervalRateCollector");
202  m_terminalCollectors.SetAttribute(
203  "InputDataType",
204  EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
205  m_terminalCollectors.SetAttribute(
206  "OutputType",
207  EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
209  for (CollectorMap::Iterator it = m_terminalCollectors.Begin();
210  it != m_terminalCollectors.End();
211  ++it)
212  {
213  const std::string context = it->second->GetName();
214  plotAggregator->Add2dDataset(context, context);
215  }
216  m_terminalCollectors.ConnectToAggregator("OutputWithTime",
217  m_aggregator,
218  &MagisterGnuplotAggregator::Write2d);
219  break;
220  }
221 
225  NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
226  << " is not a valid output type for this statistics.");
227  break;
228 
229  default:
230  NS_FATAL_ERROR("SatStatsPacketErrorHelper - Invalid output type");
231  break;
232  }
233 
234  InstallProbes();
235 }
236 
237 void
239 {
240  NS_LOG_FUNCTION(this);
241 
242  Callback<void, uint32_t, Ptr<Node>, Ptr<Node>, bool> callback =
244 
245  NodeContainer sats = GetSatHelper()->GetBeamHelper()->GetGeoSatNodes();
246  for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
247  {
248  Ptr<SatGeoNetDevice> satGeoNetDevice =
249  DynamicCast<SatGeoNetDevice>(GetSatSatGeoNetDevice(*it));
250  std::vector<Ptr<PointToPointIslNetDevice>> islNetDevices =
251  satGeoNetDevice->GetIslsNetDevices();
252  for (std::vector<Ptr<PointToPointIslNetDevice>>::iterator itIsl = islNetDevices.begin();
253  itIsl != islNetDevices.end();
254  itIsl++)
255  {
256  std::ostringstream oss;
257  oss << GetIdentifierForIsl(*it, (*itIsl)->GetDestinationNode());
258 
259  if ((*itIsl)->TraceConnectWithoutContext("PacketDropRateTrace", callback))
260  {
261  NS_LOG_INFO(this << " successfully connected with ISL " << oss.str());
262  }
263  else
264  {
265  NS_LOG_WARN(this << " unable to connect to ISL " << oss.str());
266  }
267  }
268  }
269 }
270 
271 } // namespace ns3
Parent abstract class of all satellite statistics helpers.
Ptr< const SatHelper > GetSatHelper() const
static std::string GetOutputTypeName(OutputType_t outputType)
static Ptr< NetDevice > GetSatSatGeoNetDevice(Ptr< Node > satNode)
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.
uint32_t GetIdentifierForIsl(Ptr< Node > satNodeSrc, Ptr< Node > satNodeDst) const
OutputType_t GetOutputType() const
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
static TypeId GetTypeId()
inherited from ObjectBase base class
void PacketDropRateCallback(uint32_t nPackets, Ptr< Node > satSrc, Ptr< Node > satDst, bool isError)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
CollectorMap m_terminalCollectors
Maintains a list of collectors created by this helper.
void InstallProbes()
Set up several probes or other means of listeners and connect them to the collectors.
SatStatsPacketDropRateHelper(Ptr< const SatHelper > satHelper)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.