Loading...
Searching...
No Matches
satellite-stats-resources-granted-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/bytes-probe.h"
26#include "ns3/data-collection-object.h"
27#include "ns3/distribution-collector.h"
28#include "ns3/enum.h"
29#include "ns3/fatal-error.h"
30#include "ns3/log.h"
31#include "ns3/magister-gnuplot-aggregator.h"
32#include "ns3/multi-file-aggregator.h"
33#include "ns3/node-container.h"
34#include "ns3/probe.h"
35#include "ns3/satellite-helper.h"
36#include "ns3/satellite-net-device.h"
37#include "ns3/satellite-topology.h"
38#include "ns3/satellite-ut-mac.h"
39#include "ns3/scalar-collector.h"
40#include "ns3/simulator.h"
41#include "ns3/singleton.h"
42#include "ns3/string.h"
43#include "ns3/unit-conversion-collector.h"
44
45#include <map>
46#include <sstream>
47#include <string>
48#include <utility>
49
50NS_LOG_COMPONENT_DEFINE("SatStatsResourcesGrantedHelper");
51
52namespace ns3
53{
54
55NS_OBJECT_ENSURE_REGISTERED(SatStatsResourcesGrantedHelper);
56
58 : SatStatsHelper(satHelper)
59{
60 NS_LOG_FUNCTION(this << satHelper);
61}
62
67
68TypeId // static
70{
71 static TypeId tid = TypeId("ns3::SatStatsResourcesGrantedHelper").SetParent<SatStatsHelper>();
72 return tid;
73}
74
75void
77{
78 NS_LOG_FUNCTION(this);
79
80 switch (GetOutputType())
81 {
83 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
84 << " is not a valid output type for this statistics.");
85 break;
86
88 // Setup aggregator.
89 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
90 "OutputFileName",
91 StringValue(GetOutputFileName()),
92 "MultiFileMode",
93 BooleanValue(false),
94 "EnableContextPrinting",
95 BooleanValue(true),
96 "GeneralHeading",
97 StringValue(GetIdentifierHeading("resources_bytes")));
98
99 // Setup collectors.
100 m_terminalCollectors.SetType("ns3::ScalarCollector");
101 m_terminalCollectors.SetAttribute("InputDataType",
102 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
103 m_terminalCollectors.SetAttribute(
104 "OutputType",
105 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
107 m_terminalCollectors.ConnectToAggregator("Output",
109 &MultiFileAggregator::Write1d);
110
111 // Setup a probe in each UT MAC.
112 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
113 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
114 {
115 InstallProbe(*it, &ScalarCollector::TraceSinkUinteger32);
116 }
117
118 break;
119 }
120
122 // Setup aggregator.
123 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
124 "OutputFileName",
125 StringValue(GetOutputFileName()),
126 "GeneralHeading",
127 StringValue(GetTimeHeading("resources_bytes")));
128
129 // Setup collectors.
130 m_terminalCollectors.SetType("ns3::UnitConversionCollector");
131 m_terminalCollectors.SetAttribute("ConversionType",
132 EnumValue(UnitConversionCollector::TRANSPARENT));
134 m_terminalCollectors.ConnectToAggregator("OutputTimeValue",
136 &MultiFileAggregator::Write2d);
137
138 // Setup a probe in each UT MAC.
139 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
140 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
141 {
142 InstallProbe(*it, &UnitConversionCollector::TraceSinkUinteger32);
143 }
144
145 break;
146 }
147
151 // Setup aggregator.
152 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
153 "OutputFileName",
154 StringValue(GetOutputFileName()),
155 "GeneralHeading",
156 StringValue(GetDistributionHeading("resources_bytes")));
157
158 // Setup collectors.
159 m_terminalCollectors.SetType("ns3::DistributionCollector");
160 DistributionCollector::OutputType_t outputType =
161 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
163 {
164 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
165 }
167 {
168 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
169 }
170 m_terminalCollectors.SetAttribute("OutputType", EnumValue(outputType));
172 m_terminalCollectors.ConnectToAggregator("Output",
174 &MultiFileAggregator::Write2d);
175 m_terminalCollectors.ConnectToAggregator("OutputString",
177 &MultiFileAggregator::AddContextHeading);
178 m_terminalCollectors.ConnectToAggregator("Warning",
180 &MultiFileAggregator::EnableContextWarning);
181
182 // Setup a probe in each UT MAC.
183 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
184 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
185 {
186 InstallProbe(*it, &DistributionCollector::TraceSinkUinteger32);
187 }
188
189 break;
190 }
191
194 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
195 << " is not a valid output type for this statistics.");
196 break;
197
199 // Setup aggregator.
200 m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
201 "OutputPath",
202 StringValue(GetOutputPath()),
203 "OutputFileName",
204 StringValue(GetName()));
205 Ptr<MagisterGnuplotAggregator> plotAggregator =
206 m_aggregator->GetObject<MagisterGnuplotAggregator>();
207 NS_ASSERT(plotAggregator != nullptr);
208 // plot->SetTitle ("");
209 plotAggregator->SetLegend("Time (in seconds)", "Resources granted (in bytes)");
210 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES_POINTS);
211
212 // Setup collectors.
213 m_terminalCollectors.SetType("ns3::UnitConversionCollector");
214 m_terminalCollectors.SetAttribute("ConversionType",
215 EnumValue(UnitConversionCollector::TRANSPARENT));
217 for (CollectorMap::Iterator it = m_terminalCollectors.Begin();
218 it != m_terminalCollectors.End();
219 ++it)
220 {
221 const std::string context = it->second->GetName();
222 plotAggregator->Add2dDataset(context, context);
223 }
224 m_terminalCollectors.ConnectToAggregator("OutputTimeValue",
226 &MagisterGnuplotAggregator::Write2d);
227
228 // Setup a probe in each UT MAC.
229 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
230 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
231 {
232 InstallProbe(*it, &UnitConversionCollector::TraceSinkUinteger32);
233 }
234
235 break;
236 }
237
241 // Setup aggregator.
242 m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
243 "OutputPath",
244 StringValue(GetOutputPath()),
245 "OutputFileName",
246 StringValue(GetName()));
247 Ptr<MagisterGnuplotAggregator> plotAggregator =
248 m_aggregator->GetObject<MagisterGnuplotAggregator>();
249 NS_ASSERT(plotAggregator != nullptr);
250 // plot->SetTitle ("");
251 plotAggregator->SetLegend("Resources granted (in bytes)", "Frequency");
252 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
253
254 // Setup collectors.
255 m_terminalCollectors.SetType("ns3::DistributionCollector");
256 DistributionCollector::OutputType_t outputType =
257 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
259 {
260 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
261 }
263 {
264 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
265 }
266 m_terminalCollectors.SetAttribute("OutputType", EnumValue(outputType));
268 for (CollectorMap::Iterator it = m_terminalCollectors.Begin();
269 it != m_terminalCollectors.End();
270 ++it)
271 {
272 const std::string context = it->second->GetName();
273 plotAggregator->Add2dDataset(context, context);
274 }
275 m_terminalCollectors.ConnectToAggregator("Output",
277 &MagisterGnuplotAggregator::Write2d);
278
279 // Setup a probe in each UT MAC.
280 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
281 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
282 {
283 InstallProbe(*it, &DistributionCollector::TraceSinkUinteger32);
284 }
285
286 break;
287 }
288
289 default:
290 NS_FATAL_ERROR("SatStatsResourcesGrantedHelper - Invalid output type");
291 break;
292 }
293
294} // end of `void DoInstall ();`
295
296template <typename R, typename C, typename P>
297void
298SatStatsResourcesGrantedHelper::InstallProbe(Ptr<Node> utNode, R (C::*collectorTraceSink)(P, P))
299{
300 NS_LOG_FUNCTION(this << utNode);
301
302 const int32_t utId = GetUtId(utNode);
303 NS_ASSERT_MSG(utId > 0, "Node " << utNode->GetId() << " is not a valid UT");
304 const uint32_t identifier = GetIdentifierForUt(utNode);
305
306 // Create the probe.
307 std::ostringstream probeName;
308 probeName << utId;
309 Ptr<BytesProbe> probe = CreateObject<BytesProbe>();
310 probe->SetName(probeName.str());
311
312 Ptr<NetDevice> dev = GetUtSatNetDevice(utNode);
313 Ptr<SatNetDevice> satDev = dev->GetObject<SatNetDevice>();
314 NS_ASSERT(satDev != nullptr);
315 Ptr<SatMac> satMac = satDev->GetMac();
316 NS_ASSERT(satMac != nullptr);
317 Ptr<SatUtMac> satUtMac = satMac->GetObject<SatUtMac>();
318 NS_ASSERT(satUtMac != nullptr);
319
320 // Connect the object to the probe.
321 if (probe->ConnectByObject("DaResourcesTrace", satUtMac))
322 {
323 // Connect the probe to the right collector.
324 if (m_terminalCollectors.ConnectWithProbe(probe->GetObject<Probe>(),
325 "Output",
326 identifier,
327 collectorTraceSink))
328 {
329 NS_LOG_INFO(this << " created probe " << probeName.str() << ", connected to collector "
330 << identifier);
331 m_probes.insert(
332 std::make_pair(probe->GetObject<Probe>(), std::make_pair(utNode, identifier)));
333 }
334 else
335 {
336 NS_LOG_WARN(this << " unable to connect probe " << probeName.str() << " to collector "
337 << identifier);
338 }
339 }
340 else
341 {
342 NS_FATAL_ERROR("Error connecting to DaResourcesTrace trace source of SatUtMac"
343 << " at node ID " << utNode->GetId() << " device #" << satDev->GetIfIndex());
344 }
345
346} // end of `void InstallProbe (Ptr<Node>, R (C::*) (P, P));`
347
348// template <typename R, typename C, typename P>
349void
351{
352 NS_LOG_FUNCTION(this);
353
354 std::map<Ptr<Probe>, std::pair<Ptr<Node>, uint32_t>>::iterator it;
355
356 for (it = m_probes.begin(); it != m_probes.end(); it++)
357 {
358 Ptr<Probe> probe = it->first;
359 Ptr<Node> node = it->second.first;
360 uint32_t identifier = it->second.second;
361
362 switch (GetOutputType())
363 {
365 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
366 << " is not a valid output type for this statistics.");
367 break;
368
370 if (!m_terminalCollectors.DisconnectWithProbe(probe->GetObject<Probe>(),
371 "Output",
372 identifier,
373 &ScalarCollector::TraceSinkUinteger32))
374 {
375 NS_FATAL_ERROR("Error disconnecting trace file on handover");
376 }
377
378 identifier = GetIdentifierForUtUser(node);
379
380 if (!m_terminalCollectors.ConnectWithProbe(probe->GetObject<Probe>(),
381 "Output",
382 identifier,
383 &ScalarCollector::TraceSinkUinteger32))
384 {
385 NS_FATAL_ERROR("Error connecting trace file on handover");
386 }
387
388 it->second.second = identifier;
389 break;
390 }
391
393 if (!m_terminalCollectors.DisconnectWithProbe(
394 probe->GetObject<Probe>(),
395 "Output",
396 identifier,
397 &UnitConversionCollector::TraceSinkUinteger32))
398 {
399 NS_FATAL_ERROR("Error disconnecting trace file on handover");
400 }
401
402 identifier = GetIdentifierForUtUser(node);
403
404 if (!m_terminalCollectors.ConnectWithProbe(
405 probe->GetObject<Probe>(),
406 "Output",
407 identifier,
408 &UnitConversionCollector::TraceSinkUinteger32))
409 {
410 NS_FATAL_ERROR("Error connecting trace file on handover");
411 }
412
413 it->second.second = identifier;
414 break;
415 }
416
420 if (!m_terminalCollectors.DisconnectWithProbe(
421 probe->GetObject<Probe>(),
422 "Output",
423 identifier,
424 &DistributionCollector::TraceSinkUinteger32))
425 {
426 NS_FATAL_ERROR("Error disconnecting trace file on handover");
427 }
428
429 identifier = GetIdentifierForUtUser(node);
430
431 if (!m_terminalCollectors.ConnectWithProbe(probe->GetObject<Probe>(),
432 "Output",
433 identifier,
434 &DistributionCollector::TraceSinkUinteger32))
435 {
436 NS_FATAL_ERROR("Error connecting trace file on handover");
437 }
438
439 it->second.second = identifier;
440 break;
441 }
442
444 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
445 << " is not a valid output type for this statistics.");
446 break;
447
449 if (!m_terminalCollectors.DisconnectWithProbe(
450 probe->GetObject<Probe>(),
451 "Output",
452 identifier,
453 &UnitConversionCollector::TraceSinkUinteger32))
454 {
455 NS_FATAL_ERROR("Error disconnecting trace file on handover");
456 }
457
458 identifier = GetIdentifierForUtUser(node);
459
460 if (!m_terminalCollectors.ConnectWithProbe(
461 probe->GetObject<Probe>(),
462 "Output",
463 identifier,
464 &UnitConversionCollector::TraceSinkUinteger32))
465 {
466 NS_FATAL_ERROR("Error connecting trace file on handover");
467 }
468
469 it->second.second = identifier;
470 break;
471 }
472
476 if (!m_terminalCollectors.DisconnectWithProbe(
477 probe->GetObject<Probe>(),
478 "Output",
479 identifier,
480 &DistributionCollector::TraceSinkUinteger32))
481 {
482 NS_FATAL_ERROR("Error disconnecting trace file on handover");
483 }
484
485 identifier = GetIdentifierForUtUser(node);
486
487 if (!m_terminalCollectors.ConnectWithProbe(probe->GetObject<Probe>(),
488 "Output",
489 identifier,
490 &DistributionCollector::TraceSinkUinteger32))
491 {
492 NS_FATAL_ERROR("Error connecting trace file on handover");
493 }
494
495 it->second.second = identifier;
496 break;
497 }
498
499 default:
500 NS_FATAL_ERROR("SatStatsResourcesGrantedHelper - Invalid output type");
501 break;
502 }
503 }
504} // end of `void UpdateIdentifierOnProbes ();`
505
506} // end of namespace ns3
SatNetDevice to be utilized in the UT and GW nodes.
uint32_t GetIdentifierForUtUser(Ptr< Node > utUserNode) const
static std::string GetOutputTypeName(OutputType_t outputType)
SatStatsHelper(Ptr< const SatHelper > satHelper)
Creates a new helper instance.
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 GetUtId(Ptr< Node > utNode) const
uint32_t CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
static Ptr< NetDevice > GetUtSatNetDevice(Ptr< Node > utNode)
OutputType_t GetOutputType() const
uint32_t GetIdentifierForUt(Ptr< Node > utNode) const
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
virtual std::string GetDistributionHeading(std::string dataLabel) const
std::map< Ptr< Probe >, std::pair< Ptr< Node >, uint32_t > > m_probes
Maintains a list of probes created by this helper.
void InstallProbe(Ptr< Node > utNode, R(C::*collectorTraceSink)(P, P))
void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
static TypeId GetTypeId()
inherited from ObjectBase base class
CollectorMap m_terminalCollectors
Maintains a list of collectors created by this helper.
UT specific Mac class for Sat Net Devices.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.