Loading...
Searching...
No Matches
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-handover-module.h"
36#include "ns3/satellite-helper.h"
37#include "ns3/satellite-orbiter-net-device.h"
38#include "ns3/satellite-topology.h"
39#include "ns3/scalar-collector.h"
40#include "ns3/singleton.h"
41#include "ns3/string.h"
42#include "ns3/unit-conversion-collector.h"
43
44#include <sstream>
45#include <string>
46#include <vector>
47
48NS_LOG_COMPONENT_DEFINE("SatStatsPacketDropRateHelper");
49
50namespace ns3
51{
52
53NS_OBJECT_ENSURE_REGISTERED(SatStatsPacketDropRateHelper);
54
56 : SatStatsHelper(satHelper)
57{
58 NS_LOG_FUNCTION(this << satHelper);
59}
60
65
66TypeId
68{
69 static TypeId tid = TypeId("ns3::SatStatsPacketDropRateHelper").SetParent<SatStatsHelper>();
70 return tid;
71}
72
73void
75 Ptr<Node> satSrc,
76 Ptr<Node> satDst,
77 bool isError)
78{
79 NS_LOG_FUNCTION(this << nPackets << satSrc << satDst << isError);
80
81 uint32_t identifier = GetIdentifierForIsl(satSrc, satDst);
82
83 // Find the first-level collector with the right identifier.
84 Ptr<DataCollectionObject> collector = m_terminalCollectors.Get(identifier);
85 NS_ASSERT_MSG(collector != nullptr, "Unable to find collector with identifier " << identifier);
86
87 switch (GetOutputType())
88 {
91 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
92 NS_ASSERT(c != nullptr);
93 c->TraceSinkBoolean(false, isError);
94 break;
95 }
96
99 Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
100 NS_ASSERT(c != nullptr);
101 c->TraceSinkBoolean(false, isError);
102 break;
103 }
104
105 default:
106 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
107 << " is not a valid output type for this statistics.");
108 break;
109
110 } // end of `switch (GetOutputType ())`
111}
112
113void
115{
116 NS_LOG_FUNCTION(this);
117
118 switch (GetOutputType())
119 {
121 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
122 << " is not a valid output type for this statistics.");
123 break;
124
126 // Setup aggregator.
127 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
128 "OutputFileName",
129 StringValue(GetOutputFileName()),
130 "MultiFileMode",
131 BooleanValue(false),
132 "EnableContextPrinting",
133 BooleanValue(true),
134 "GeneralHeading",
135 StringValue(GetIdentifierHeading("packet_drop_rate")));
136
137 // Setup collectors.
138 m_terminalCollectors.SetType("ns3::ScalarCollector");
139 m_terminalCollectors.SetAttribute("InputDataType",
140 EnumValue(ScalarCollector::INPUT_DATA_TYPE_BOOLEAN));
141 m_terminalCollectors.SetAttribute(
142 "OutputType",
143 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
145 m_terminalCollectors.ConnectToAggregator("Output",
147 &MultiFileAggregator::Write1d);
148 break;
149 }
150
152 // Setup aggregator.
153 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
154 "OutputFileName",
155 StringValue(GetOutputFileName()),
156 "GeneralHeading",
157 StringValue(GetTimeHeading("packet_drop_rate")));
158
159 // Setup collectors.
160 m_terminalCollectors.SetType("ns3::IntervalRateCollector");
161 m_terminalCollectors.SetAttribute(
162 "InputDataType",
163 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
164 m_terminalCollectors.SetAttribute(
165 "OutputType",
166 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
168 m_terminalCollectors.ConnectToAggregator("OutputWithTime",
170 &MultiFileAggregator::Write2d);
171 m_terminalCollectors.ConnectToAggregator("OutputString",
173 &MultiFileAggregator::AddContextHeading);
174 break;
175 }
176
180 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
181 << " is not a valid output type for this statistics.");
182 break;
183
186 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
187 << " is not a valid output type for this statistics.");
188 break;
189
191 // Setup aggregator.
192 m_aggregator = CreateAggregator("ns3::MagisterGnuplotAggregator",
193 "OutputPath",
194 StringValue(GetOutputPath()),
195 "OutputFileName",
196 StringValue(GetName()));
197 Ptr<MagisterGnuplotAggregator> plotAggregator =
198 m_aggregator->GetObject<MagisterGnuplotAggregator>();
199 NS_ASSERT(plotAggregator != nullptr);
200 // plot->SetTitle ("");
201 plotAggregator->SetLegend("Time (in seconds)", "Packet drop rate");
202 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
203
204 // Setup collectors.
205 m_terminalCollectors.SetType("ns3::IntervalRateCollector");
206 m_terminalCollectors.SetAttribute(
207 "InputDataType",
208 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
209 m_terminalCollectors.SetAttribute(
210 "OutputType",
211 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
213 for (CollectorMap::Iterator it = m_terminalCollectors.Begin();
214 it != m_terminalCollectors.End();
215 ++it)
216 {
217 const std::string context = it->second->GetName();
218 plotAggregator->Add2dDataset(context, context);
219 }
220 m_terminalCollectors.ConnectToAggregator("OutputWithTime",
222 &MagisterGnuplotAggregator::Write2d);
223 break;
224 }
225
229 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
230 << " is not a valid output type for this statistics.");
231 break;
232
233 default:
234 NS_FATAL_ERROR("SatStatsPacketErrorHelper - Invalid output type");
235 break;
236 }
237
239}
240
241void
243{
244 NS_LOG_FUNCTION(this);
245
246 Callback<void, uint32_t, Ptr<Node>, Ptr<Node>, bool> callback =
248
249 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
250 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
251 {
252 Ptr<SatOrbiterNetDevice> satOrbiterNetDevice =
253 DynamicCast<SatOrbiterNetDevice>(GetSatSatOrbiterNetDevice(*it));
254 std::vector<Ptr<PointToPointIslNetDevice>> islNetDevices =
255 satOrbiterNetDevice->GetIslsNetDevices();
256 for (std::vector<Ptr<PointToPointIslNetDevice>>::iterator itIsl = islNetDevices.begin();
257 itIsl != islNetDevices.end();
258 itIsl++)
259 {
260 std::ostringstream oss;
261 oss << GetIdentifierForIsl(*it, (*itIsl)->GetDestinationNode());
262
263 if ((*itIsl)->TraceConnectWithoutContext("PacketDropRateTrace", callback))
264 {
265 NS_LOG_INFO(this << " successfully connected with ISL " << oss.str());
266 }
267 else
268 {
269 NS_LOG_WARN(this << " unable to connect to ISL " << oss.str());
270 }
271 }
272 }
273}
274
275} // namespace ns3
static Ptr< NetDevice > GetSatSatOrbiterNetDevice(Ptr< Node > satNode)
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 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
Base class for antenna gain statistics helpers.
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.