27#include "ns3/boolean.h"
28#include "ns3/callback.h"
29#include "ns3/data-collection-object.h"
31#include "ns3/fatal-error.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"
50NS_LOG_COMPONENT_DEFINE(
"SatStatsFrameLoadHelper");
63 return "UNIT_SYMBOLS";
67 NS_FATAL_ERROR(
"SatStatsFrameLoadHelper - Invalid unit type");
71 NS_FATAL_ERROR(
"SatStatsFrameLoadHelper - Invalid unit type");
83 NS_LOG_FUNCTION(
this << satHelper);
88 NS_LOG_FUNCTION(
this);
94 static TypeId tid = TypeId(
"ns3::SatStatsFrameLoadHelper").SetParent<
SatStatsHelper>();
108 m_longLabel =
"Number of allocated symbols over total number of symbols";
121 NS_FATAL_ERROR(
"SatStatsFrameLoadHelper - Invalid unit type");
134 NS_LOG_FUNCTION(
this);
139 <<
" is not a valid output type for this statistics.");
146 <<
" is not a valid identifier type for this statistics.");
155 "EnableContextPrinting",
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();
168 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
175 ncc->GetBeamScheduler(it->first, it->second),
190 NS_LOG_INFO(
this <<
" successfully connected" <<
" with beam " << it->second);
194 NS_LOG_WARN(
this <<
" unable to connect to beam " << it->second);
207 return "% global frame_number " + dataLabel;
210 return "% gw_id frame_number " + dataLabel;
213 return "% beam_id frame_number " + dataLabel;
216 NS_FATAL_ERROR(
"SatStatsFrameLoadHelper - Invalid identifier type");
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 "
236 collector->TraceSinkDouble(0, loadRatio);
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);
253 collector->TraceSinkUinteger32(0, utCount);
262 std::stringstream ss(identifier);
263 uint32_t identifierNum;
264 if (!(ss >> identifierNum))
266 NS_FATAL_ERROR(
"Cannot convert '" << identifier <<
"' to number");
269 std::map<uint32_t, CollectorMap>::iterator it =
m_collectors.find(frameId);
274 CollectorMap collectorMap;
275 collectorMap.SetType(
"ns3::ScalarCollector");
278 collectorMap.SetAttribute(
"InputDataType",
279 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
280 collectorMap.SetAttribute(
"OutputType",
281 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
286 collectorMap.SetAttribute(
"InputDataType",
287 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
288 collectorMap.SetAttribute(
"OutputType", EnumValue(ScalarCollector::OUTPUT_TYPE_SUM));
300 std::ostringstream name;
301 name <<
"0 " << frameId;
302 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
303 collectorMap.Create(0);
309 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
310 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
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);
323 std::list<std::pair<uint32_t, uint32_t>> beams =
325 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
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()));
342 NS_FATAL_ERROR(
"SatStatsFrameLoadHelper - Invalid identifier type");
346 collectorMap.ConnectToAggregator(
"Output",
m_aggregator, &MultiFileAggregator::Write1d);
347 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)" <<
" of "
348 << collectorMap.GetType().GetName() <<
" for "
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);
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>();
375 NS_LOG_FUNCTION(
this << satHelper);
381 NS_LOG_FUNCTION(
this);
399 NS_LOG_FUNCTION(
this << satHelper);
405 NS_LOG_FUNCTION(
this);
Helper for frame load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
std::string m_objectTraceSourceName
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)
UnitType_t GetUnitType() const
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))
void SetUnitType(UnitType_t unitType)
virtual ~SatStatsFrameLoadHelper()
/ Destructor.
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)
std::string m_probeTraceSourceName
Helper for frame symbol load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFrameSymbolLoadHelper(Ptr< const SatHelper > satHelper)
virtual ~SatStatsFrameSymbolLoadHelper()
/ Destructor.
Helper for frame user load statistics.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsFrameUserLoadHelper()
/ Destructor.
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.