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/scalar-collector.h>
37 #include <ns3/string.h>
43 NS_LOG_COMPONENT_DEFINE(
"SatStatsWaveformUsageHelper");
48 NS_OBJECT_ENSURE_REGISTERED(SatStatsWaveformUsageHelper);
53 NS_LOG_FUNCTION(
this << satHelper);
58 NS_LOG_FUNCTION(
this);
64 static TypeId tid = TypeId(
"ns3::SatStatsWaveformUsageHelper").SetParent<
SatStatsHelper>();
71 NS_LOG_FUNCTION(
this);
76 <<
" is not a valid output type for this statistics.");
83 <<
" is not a valid identifier type for this statistics.");
92 "EnableContextPrinting",
97 Callback<void, std::string, uint32_t> waveformUsageCallback =
101 Ptr<SatBeamHelper> beamHelper =
GetSatHelper()->GetBeamHelper();
102 NS_ASSERT(beamHelper !=
nullptr);
103 Ptr<SatNcc> ncc = beamHelper->GetNcc();
104 NS_ASSERT(ncc !=
nullptr);
105 std::list<std::pair<uint32_t, uint32_t>> beams = beamHelper->GetBeams();
107 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
111 std::ostringstream context;
114 Ptr<SatBeamScheduler> s = ncc->GetBeamScheduler(it->first, it->second);
115 NS_ASSERT_MSG(s !=
nullptr,
"Error finding beam " << it->second);
116 const bool ret = s->TraceConnect(
"WaveformTrace", context.str(), waveformUsageCallback);
117 NS_ASSERT_MSG(ret,
"Error connecting to WaveformTrace of beam " << it->second);
118 NS_LOG_INFO(
this <<
" successfully connected"
119 <<
" with beam " << it->second);
130 return "% global waveform_id " + dataLabel;
133 return "% gw_id waveform_id " + dataLabel;
136 return "% beam_id waveform_id " + dataLabel;
139 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
148 NS_LOG_FUNCTION(
this << context << waveformId);
151 std::stringstream ss(context);
153 if (!(ss >> identifier))
155 NS_FATAL_ERROR(
"Cannot convert '" << context <<
"' to number");
158 std::map<uint32_t, CollectorMap>::iterator it =
m_collectors.find(waveformId);
162 NS_LOG_INFO(
this <<
" Creating new collectors for waveform ID " << waveformId);
163 CollectorMap collectorMap;
164 collectorMap.SetType(
"ns3::ScalarCollector");
165 collectorMap.SetAttribute(
"InputDataType",
166 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
167 collectorMap.SetAttribute(
"OutputType", EnumValue(ScalarCollector::OUTPUT_TYPE_SUM));
179 std::ostringstream name;
180 name <<
"0 " << waveformId;
181 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
182 collectorMap.Create(0);
188 NodeContainer gws =
GetSatHelper()->GetBeamHelper()->GetGwNodes();
189 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
191 const uint32_t gwId =
GetGwId(*it);
192 std::ostringstream name;
193 name << gwId <<
" " << waveformId;
194 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
195 collectorMap.Create(gwId);
202 std::list<std::pair<uint32_t, uint32_t>> beams =
204 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
208 const uint32_t satId = (it->first);
209 const uint32_t beamId = (it->second);
210 std::ostringstream name;
211 name << satId <<
"-" << beamId <<
" " << waveformId;
212 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
221 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
225 collectorMap.ConnectToAggregator(
"Output",
m_aggregator, &MultiFileAggregator::Write1d);
226 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)"
227 <<
" of " << collectorMap.GetType().GetName() <<
" for "
230 std::pair<std::map<uint32_t, CollectorMap>::iterator,
bool> ret;
231 ret =
m_collectors.insert(std::make_pair(waveformId, collectorMap));
232 NS_ASSERT(ret.second);
240 Ptr<DataCollectionObject> collector = it->second.Get(identifier);
241 NS_ASSERT_MSG(collector !=
nullptr,
"Unable to find collector with identifier " << identifier);
242 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
243 NS_ASSERT(c !=
nullptr);
246 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.