Loading...
Searching...
No Matches
satellite-stats-frame-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
26
27#include "ns3/boolean.h"
28#include "ns3/callback.h"
29#include "ns3/data-collection-object.h"
30#include "ns3/enum.h"
31#include "ns3/fatal-error.h"
32#include "ns3/log.h"
33#include "ns3/multi-file-aggregator.h"
34#include "ns3/node-container.h"
35#include "ns3/satellite-beam-helper.h"
36#include "ns3/satellite-beam-scheduler.h"
37#include "ns3/satellite-helper.h"
38#include "ns3/satellite-ncc.h"
39#include "ns3/satellite-topology.h"
40#include "ns3/scalar-collector.h"
41#include "ns3/singleton.h"
42#include "ns3/string.h"
43
44#include <list>
45#include <map>
46#include <sstream>
47#include <string>
48#include <utility>
49
50NS_LOG_COMPONENT_DEFINE("SatStatsFrameLoadHelper");
51
52namespace ns3
53{
54
55NS_OBJECT_ENSURE_REGISTERED(SatStatsFrameLoadHelper);
56
57std::string // static
59{
60 switch (unitType)
61 {
63 return "UNIT_SYMBOLS";
65 return "UNIT_USERS";
66 default:
67 NS_FATAL_ERROR("SatStatsFrameLoadHelper - Invalid unit type");
68 break;
69 }
70
71 NS_FATAL_ERROR("SatStatsFrameLoadHelper - Invalid unit type");
72 return "";
73}
74
76 : SatStatsHelper(satHelper),
78 m_shortLabel(""),
79 m_longLabel(""),
82{
83 NS_LOG_FUNCTION(this << satHelper);
84}
85
87{
88 NS_LOG_FUNCTION(this);
89}
90
91TypeId // static
93{
94 static TypeId tid = TypeId("ns3::SatStatsFrameLoadHelper").SetParent<SatStatsHelper>();
95 return tid;
96}
97
98void
100{
101 NS_LOG_FUNCTION(this << GetUnitTypeName(unitType));
102 m_unitType = unitType;
103
104 // Update unit-specific attributes.
106 {
107 m_shortLabel = "allocated_symbol_ratio";
108 m_longLabel = "Number of allocated symbols over total number of symbols";
109 m_objectTraceSourceName = "FrameLoadTrace";
110 m_probeTraceSourceName = "Output";
111 }
112 else if (unitType == SatStatsFrameLoadHelper::UNIT_USERS)
113 {
114 m_shortLabel = "allocated_users";
115 m_longLabel = "Number of scheduled users";
116 m_objectTraceSourceName = "FrameUtLoadTrace";
117 m_probeTraceSourceName = "Output";
118 }
119 else
120 {
121 NS_FATAL_ERROR("SatStatsFrameLoadHelper - Invalid unit type");
122 }
123}
124
130
131void
133{
134 NS_LOG_FUNCTION(this);
135
137 {
138 NS_FATAL_ERROR(GetOutputTypeName(GetOutputType())
139 << " is not a valid output type for this statistics.");
140 }
141
144 {
146 << " is not a valid identifier type for this statistics.");
147 }
148
149 // Setup aggregator.
150 m_aggregator = CreateAggregator("ns3::MultiFileAggregator",
151 "OutputFileName",
152 StringValue(GetOutputFileName()),
153 "MultiFileMode",
154 BooleanValue(false),
155 "EnableContextPrinting",
156 BooleanValue(true),
157 "GeneralHeading",
158 StringValue(GetIdentifierHeading(m_shortLabel)));
159
160 // Setup probes.
161 Ptr<SatBeamHelper> beamHelper = GetSatHelper()->GetBeamHelper();
162 NS_ASSERT(beamHelper != nullptr);
163 Ptr<SatNcc> ncc = beamHelper->GetNcc();
164 NS_ASSERT(ncc != nullptr);
165 std::list<std::pair<uint32_t, uint32_t>> beams = beamHelper->GetBeams();
166 bool ret = false;
167
168 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
169 it != beams.end();
170 ++it)
171 {
173 {
175 ncc->GetBeamScheduler(it->first, it->second),
176 GetIdentifierForBeam(it->first, it->second),
178 }
179 else
180 {
181 NS_ASSERT_MSG(m_unitType == SatStatsFrameLoadHelper::UNIT_USERS, "Invalid unit type");
182 ret =
183 SetupProbe<SatFrameUserLoadProbe>(ncc->GetBeamScheduler(it->first, it->second),
184 GetIdentifierForBeam(it->first, it->second),
186 }
187
188 if (ret)
189 {
190 NS_LOG_INFO(this << " successfully connected" << " with beam " << it->second);
191 }
192 else
193 {
194 NS_LOG_WARN(this << " unable to connect to beam " << it->second);
195 }
196
197 } // end of `for (it: beams)`
198
199} // end of `void DoInstall ();`
200
201std::string
203{
204 switch (GetIdentifierType())
205 {
207 return "% global frame_number " + dataLabel;
208
210 return "% gw_id frame_number " + dataLabel;
211
213 return "% beam_id frame_number " + dataLabel;
214
215 default:
216 NS_FATAL_ERROR("SatStatsFrameLoadHelper - Invalid identifier type");
217 break;
218 }
219 return "";
220}
221
222void
224 uint32_t frameId,
225 double loadRatio)
226{
227 // NS_LOG_FUNCTION (this << context << frameId << loadRatio);
228
229 // Get the right collector for this frame ID and identifier.
230 Ptr<ScalarCollector> collector = GetCollector(frameId, context);
231 NS_ASSERT_MSG(collector != nullptr,
232 "Unable to get/create collector" << " for frame ID " << frameId << " and beam "
233 << context);
234
235 // Pass the sample to the collector.
236 collector->TraceSinkDouble(0, loadRatio);
237}
238
239void
241 uint32_t frameId,
242 uint32_t utCount)
243{
244 // NS_LOG_FUNCTION (this << context << frameId << utCount);
245
246 // Get the right collector for this frame ID and identifier.
247 Ptr<ScalarCollector> collector = GetCollector(frameId, context);
248 NS_ASSERT_MSG(collector != nullptr,
249 "Unable to get/create collector" << " for frame ID " << frameId
250 << " and identifier " << context);
251
252 // Pass the sample to the collector.
253 collector->TraceSinkUinteger32(0, utCount);
254}
255
256Ptr<ScalarCollector>
257SatStatsFrameLoadHelper::GetCollector(uint32_t frameId, std::string identifier)
258{
259 // NS_LOG_FUNCTION (this << frameId);
260
261 // convert context to number
262 std::stringstream ss(identifier);
263 uint32_t identifierNum;
264 if (!(ss >> identifierNum))
265 {
266 NS_FATAL_ERROR("Cannot convert '" << identifier << "' to number");
267 }
268
269 std::map<uint32_t, CollectorMap>::iterator it = m_collectors.find(frameId);
270 if (it == m_collectors.end())
271 {
272 // Newly discovered frame ID
273 uint32_t n = 0;
274 CollectorMap collectorMap;
275 collectorMap.SetType("ns3::ScalarCollector");
277 {
278 collectorMap.SetAttribute("InputDataType",
279 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
280 collectorMap.SetAttribute("OutputType",
281 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
282 }
283 else
284 {
285 NS_ASSERT_MSG(m_unitType == SatStatsFrameLoadHelper::UNIT_USERS, "Invalid unit type");
286 collectorMap.SetAttribute("InputDataType",
287 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
288 collectorMap.SetAttribute("OutputType", EnumValue(ScalarCollector::OUTPUT_TYPE_SUM));
289 }
290
291 /*
292 * Create a new set of collectors. Its name consists of two integers:
293 * - the first is the identifier ID (beam ID, GW ID, or simply zero for
294 * global);
295 * - the second is the frame ID.
296 */
297 switch (GetIdentifierType())
298 {
300 std::ostringstream name;
301 name << "0 " << frameId;
302 collectorMap.SetAttribute("Name", StringValue(name.str()));
303 collectorMap.Create(0);
304 n++;
305 break;
306 }
307
309 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
310 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
311 {
312 const uint32_t gwId = GetGwId(*it);
313 std::ostringstream name;
314 name << gwId << " " << frameId;
315 collectorMap.SetAttribute("Name", StringValue(name.str()));
316 collectorMap.Create(gwId);
317 n++;
318 }
319 break;
320 }
321
323 std::list<std::pair<uint32_t, uint32_t>> beams =
324 GetSatHelper()->GetBeamHelper()->GetBeams();
325 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
326 it != beams.end();
327 ++it)
328 {
329 const uint32_t satId = (it->first);
330 const uint32_t beamId = (it->second);
331 std::ostringstream name;
332 name << satId << "-" << beamId << " " << frameId;
333 collectorMap.SetAttribute("Name", StringValue(name.str()));
334 collectorMap.Create(SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) +
335 beamId);
336 n++;
337 }
338 break;
339 }
340
341 default:
342 NS_FATAL_ERROR("SatStatsFrameLoadHelper - Invalid identifier type");
343 break;
344 }
345
346 collectorMap.ConnectToAggregator("Output", m_aggregator, &MultiFileAggregator::Write1d);
347 NS_LOG_INFO(this << " created " << n << " instance(s)" << " of "
348 << collectorMap.GetType().GetName() << " for "
350
351 std::pair<std::map<uint32_t, CollectorMap>::iterator, bool> ret;
352 ret = m_collectors.insert(std::make_pair(frameId, collectorMap));
353 NS_ASSERT(ret.second);
354 it = ret.first;
355
356 } // end of `if (it == m_collectors.end ())`
357
358 NS_ASSERT(it != m_collectors.end());
359
360 // Find the collector with the right identifier.
361 Ptr<DataCollectionObject> collector = it->second.Get(identifierNum);
362 NS_ASSERT_MSG(collector != nullptr, "Unable to find collector with identifier " << identifier);
363 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
364 return c;
365
366} // `Ptr<ScalarCollector> GetCollector (uint32_t, std::string)`
367
368// IN SYMBOL UNIT /////////////////////////////////////////////////////////////
369
370NS_OBJECT_ENSURE_REGISTERED(SatStatsFrameSymbolLoadHelper);
371
373 : SatStatsFrameLoadHelper(satHelper)
374{
375 NS_LOG_FUNCTION(this << satHelper);
377}
378
383
384TypeId // static
386{
387 static TypeId tid =
388 TypeId("ns3::SatStatsFrameSymbolLoadHelper").SetParent<SatStatsFrameLoadHelper>();
389 return tid;
390}
391
392// IN USER UNIT ///////////////////////////////////////////////////////////////
393
394NS_OBJECT_ENSURE_REGISTERED(SatStatsFrameUserLoadHelper);
395
397 : SatStatsFrameLoadHelper(satHelper)
398{
399 NS_LOG_FUNCTION(this << satHelper);
401}
402
407
408TypeId // static
410{
411 static TypeId tid =
412 TypeId("ns3::SatStatsFrameUserLoadHelper").SetParent<SatStatsFrameLoadHelper>();
413 return tid;
414}
415
416} // end of namespace ns3
Helper for frame load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
std::map< uint32_t, CollectorMap > m_collectors
Two-dimensional map of collectors, indexed by the frame ID and then by the identifier.
Ptr< ScalarCollector > GetCollector(uint32_t frameId, std::string identifier)
static std::string GetUnitTypeName(UnitType_t unitType)
void FrameSymbolLoadCallback(std::string context, uint32_t frameId, double loadRatio)
bool SetupProbe(Ptr< Object > object, uint32_t identifier, void(SatStatsFrameLoadHelper::*traceSink)(std::string, uint32_t, V))
std::string GetIdentifierHeading(std::string dataLabel) const
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
void FrameUserLoadCallback(std::string context, uint32_t frameId, uint32_t utCount)
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
@ UNIT_USERS
Number of scheduled users (i.e., UT).
@ UNIT_SYMBOLS
Number of allocated symbols over total number of symbols in the frame.
SatStatsFrameLoadHelper(Ptr< const SatHelper > satHelper)
Helper for frame symbol load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFrameSymbolLoadHelper(Ptr< const SatHelper > satHelper)
Helper for frame user load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFrameUserLoadHelper(Ptr< const SatHelper > satHelper)
uint32_t GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
Ptr< const SatHelper > GetSatHelper() const
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
uint32_t GetGwId(Ptr< Node > gwNode) const
constexpr uint32_t MAX_BEAMS_PER_SATELLITE
Maximum number of beams per satellite.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.