24 #include <ns3/boolean.h>
25 #include <ns3/callback.h>
26 #include <ns3/data-collection-object.h>
28 #include <ns3/fatal-error.h>
30 #include <ns3/multi-file-aggregator.h>
31 #include <ns3/node-container.h>
32 #include <ns3/satellite-beam-helper.h>
33 #include <ns3/satellite-beam-scheduler.h>
34 #include <ns3/satellite-helper.h>
35 #include <ns3/satellite-ncc.h>
36 #include <ns3/satellite-topology.h>
37 #include <ns3/scalar-collector.h>
38 #include <ns3/singleton.h>
39 #include <ns3/string.h>
47 NS_LOG_COMPONENT_DEFINE(
"SatStatsWaveformUsageHelper");
52 NS_OBJECT_ENSURE_REGISTERED(SatStatsWaveformUsageHelper);
57 NS_LOG_FUNCTION(
this << satHelper);
62 NS_LOG_FUNCTION(
this);
68 static TypeId tid = TypeId(
"ns3::SatStatsWaveformUsageHelper").SetParent<
SatStatsHelper>();
75 NS_LOG_FUNCTION(
this);
80 <<
" is not a valid output type for this statistics.");
87 <<
" is not a valid identifier type for this statistics.");
96 "EnableContextPrinting",
101 Callback<void, std::string, uint32_t> waveformUsageCallback =
105 Ptr<SatBeamHelper> beamHelper =
GetSatHelper()->GetBeamHelper();
106 NS_ASSERT(beamHelper !=
nullptr);
107 Ptr<SatNcc> ncc = beamHelper->GetNcc();
108 NS_ASSERT(ncc !=
nullptr);
109 std::list<std::pair<uint32_t, uint32_t>> beams = beamHelper->GetBeams();
111 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
115 std::ostringstream context;
118 Ptr<SatBeamScheduler> s = ncc->GetBeamScheduler(it->first, it->second);
119 NS_ASSERT_MSG(s !=
nullptr,
"Error finding beam " << it->second);
120 const bool ret = s->TraceConnect(
"WaveformTrace", context.str(), waveformUsageCallback);
121 NS_ASSERT_MSG(ret,
"Error connecting to WaveformTrace of beam " << it->second);
122 NS_LOG_INFO(
this <<
" successfully connected"
123 <<
" with beam " << it->second);
134 return "% global waveform_id " + dataLabel;
137 return "% gw_id waveform_id " + dataLabel;
140 return "% beam_id waveform_id " + dataLabel;
143 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
152 NS_LOG_FUNCTION(
this << context << waveformId);
155 std::stringstream ss(context);
157 if (!(ss >> identifier))
159 NS_FATAL_ERROR(
"Cannot convert '" << context <<
"' to number");
162 std::map<uint32_t, CollectorMap>::iterator it =
m_collectors.find(waveformId);
166 NS_LOG_INFO(
this <<
" Creating new collectors for waveform ID " << waveformId);
167 CollectorMap collectorMap;
168 collectorMap.SetType(
"ns3::ScalarCollector");
169 collectorMap.SetAttribute(
"InputDataType",
170 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
171 collectorMap.SetAttribute(
"OutputType", EnumValue(ScalarCollector::OUTPUT_TYPE_SUM));
183 std::ostringstream name;
184 name <<
"0 " << waveformId;
185 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
186 collectorMap.Create(0);
192 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
193 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
195 const uint32_t gwId =
GetGwId(*it);
196 std::ostringstream name;
197 name << gwId <<
" " << waveformId;
198 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
199 collectorMap.Create(gwId);
206 std::list<std::pair<uint32_t, uint32_t>> beams =
208 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
212 const uint32_t satId = (it->first);
213 const uint32_t beamId = (it->second);
214 std::ostringstream name;
215 name << satId <<
"-" << beamId <<
" " << waveformId;
216 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
225 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
229 collectorMap.ConnectToAggregator(
"Output",
m_aggregator, &MultiFileAggregator::Write1d);
230 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)"
231 <<
" of " << collectorMap.GetType().GetName() <<
" for "
234 std::pair<std::map<uint32_t, CollectorMap>::iterator,
bool> ret;
235 ret =
m_collectors.insert(std::make_pair(waveformId, collectorMap));
236 NS_ASSERT(ret.second);
244 Ptr<DataCollectionObject> collector = it->second.Get(identifier);
245 NS_ASSERT_MSG(collector !=
nullptr,
"Unable to find collector with identifier " << identifier);
246 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
247 NS_ASSERT(c !=
nullptr);
250 c->TraceSinkUinteger32(0, 1);
Parent abstract class of all satellite statistics helpers.
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)
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.