Loading...
Searching...
No Matches
satellite-stats-beam-service-time-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: Lauri Sormunen <lauri.sormunen@magister.fi>
19 *
20 */
21
23
24#include "ns3/boolean.h"
25#include "ns3/callback.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/multi-file-aggregator.h"
32#include "ns3/node-container.h"
33#include "ns3/satellite-beam-helper.h"
34#include "ns3/satellite-beam-scheduler.h"
35#include "ns3/satellite-gw-mac.h"
36#include "ns3/satellite-helper.h"
37#include "ns3/satellite-ncc.h"
38#include "ns3/satellite-topology.h"
39#include "ns3/scalar-collector.h"
40#include "ns3/singleton.h"
41#include "ns3/string.h"
42
43#include <list>
44#include <sstream>
45#include <string>
46#include <utility>
47
48NS_LOG_COMPONENT_DEFINE("SatStatsBeamServiceTimeHelper");
49
50namespace ns3
51{
52
53NS_OBJECT_ENSURE_REGISTERED(SatStatsBeamServiceTimeHelper);
54
56 : SatStatsHelper(satHelper)
57{
58 NS_LOG_FUNCTION(this << satHelper);
59}
60
65
66TypeId // static
68{
69 static TypeId tid = TypeId("ns3::SatStatsBeamServiceTimeHelper").SetParent<SatStatsHelper>();
70 return tid;
71}
72
73void
75{
76 NS_LOG_FUNCTION(this);
77
79 {
80 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
81 << " is not a valid output type for this statistics.");
82 }
83
85 {
87 << " is not a valid identifier type for this statistics.");
88 }
89
90 // Setup aggregator.
91 std::string dataLabel = "service_time";
92
93 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
94 "OutputFileName",
95 StringValue(GetOutputFileName()),
96 "MultiFileMode",
97 BooleanValue(false),
98 "EnableContextPrinting",
99 BooleanValue(true),
100 "GeneralHeading",
101 StringValue("% beam_id service_time"));
102
103 // Prepare collector map
104 NS_LOG_INFO(this << " Creating new collectors for beams");
105
106 m_collectorMap.SetType("ns3::ScalarCollector");
107 m_collectorMap.SetAttribute("OutputType", EnumValue(ScalarCollector::OUTPUT_TYPE_SUM));
108 m_collectorMap.SetAttribute("InputDataType",
109 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
110
111 // Create the callback for trace source
112 Callback<void, std::string, Time> beamServiceCallback =
114
115 // Connect SatGwMac of each beam by identifier (global, gw, beam) to callback
116 NodeContainer gwNodes = Singleton<SatTopology>::Get()->GetGwNodes();
117 for (auto node = gwNodes.Begin(); node != gwNodes.End(); node++)
118 {
119 for (uint32_t i = 0; i < (*node)->GetNDevices(); i++)
120 {
121 Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>((*node)->GetDevice(i));
122 if (dev == nullptr)
123 {
124 continue;
125 }
126 Ptr<SatMac> mac = dev->GetMac();
127 if (mac == nullptr)
128 {
129 continue;
130 }
131
132 // Connect the trace source
133 uint32_t beamId = mac->GetBeamId();
134 std::ostringstream context;
135 context << beamId;
136 const bool ret =
137 mac->TraceConnect("BeamServiceTime", context.str(), beamServiceCallback);
138 NS_ASSERT_MSG(ret, "Error connecting to BeamServiceTime of beam " << beamId);
139 NS_LOG_INFO(this << " successfully connected" << " with beam " << beamId);
140 }
141 }
142
143} // end of `void DoInstall ();`
144
145void
147{
148 NS_LOG_FUNCTION(this << context << time.GetSeconds());
149
150 // convert context to number
151 std::stringstream ss(context);
152 uint32_t beamId;
153 if (!(ss >> beamId))
154 {
155 NS_FATAL_ERROR("Cannot convert '" << context << "' to number");
156 }
157
158 Ptr<DataCollectionObject> o = m_collectorMap.Get(beamId);
159 if (o == nullptr)
160 {
161 std::ostringstream name;
162 name << beamId;
163 m_collectorMap.SetAttribute("Name", StringValue(name.str()));
164 m_collectorMap.Create(beamId);
165 o = m_collectorMap.Get(beamId);
166
167 bool success =
168 o->TraceConnect("Output",
169 context,
170 MakeCallback(&MultiFileAggregator::Write1d,
171 DynamicCast<MultiFileAggregator>(m_aggregator)));
172 NS_ASSERT(success);
173 }
174
175 Ptr<ScalarCollector> s = o->GetObject<ScalarCollector>();
176 NS_ASSERT(s != nullptr);
177
178 // Pass the sample to the collector.
179 s->TraceSinkDouble(0, time.GetSeconds());
180
181} // end of `void BeamServiceCallback (std::string, uint32_t)`
182
183} // end of namespace ns3
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
static TypeId GetTypeId()
inherited from ObjectBase base class
CollectorMap m_collectorMap
Two-dimensional map of collectors, indexed first by the the frame type identifier and second by the g...
SatStatsBeamServiceTimeHelper(Ptr< const SatHelper > satHelper)
Constructor.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
IdentifierType_t GetIdentifierType() const
static std::string GetOutputTypeName(OutputType_t outputType)
SatStatsHelper(Ptr< const SatHelper > satHelper)
Creates a new helper instance.
static std::string GetIdentifierTypeName(IdentifierType_t identifierType)
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
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.