24 #include <ns3/boolean.h>
25 #include <ns3/callback.h>
26 #include <ns3/data-collection-object.h>
27 #include <ns3/distribution-collector.h>
29 #include <ns3/fatal-error.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/scalar-collector.h>
39 #include <ns3/string.h>
45 NS_LOG_COMPONENT_DEFINE(
"SatStatsFrameTypeUsageHelper");
50 NS_OBJECT_ENSURE_REGISTERED(SatStatsFrameTypeUsageHelper);
60 m_usePercentage(false)
62 NS_LOG_FUNCTION(
this << satHelper);
67 NS_LOG_FUNCTION(
this);
74 TypeId(
"ns3::SatStatsFrameTypeUsageHelper")
76 .AddAttribute(
"Percentage",
77 "Use percentage of each frame type instead of sum per identifier.",
80 MakeBooleanChecker());
87 NS_LOG_FUNCTION(
this);
92 <<
" is not a valid output type for this statistics.");
99 <<
" is not a valid identifier type for this statistics.");
103 std::string dataLabel;
105 dataLabel =
"usage_percentage";
107 dataLabel =
"usage_count";
114 "EnableContextPrinting",
122 uint32_t frameTypeId = it.second;
124 NS_LOG_INFO(
this <<
" Creating new collectors for frame type ID " << frameTypeId);
126 CollectorMap collectorMap;
127 ScalarCollector::OutputType_t opType;
129 opType = ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE;
131 opType = ScalarCollector::OUTPUT_TYPE_SUM;
133 collectorMap.SetType(
"ns3::ScalarCollector");
134 collectorMap.SetAttribute(
"OutputType", EnumValue(opType));
135 collectorMap.SetAttribute(
"InputDataType",
136 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
147 std::ostringstream name;
148 name <<
"0 " << frameTypeId;
149 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
150 collectorMap.Create(0);
156 NodeContainer gws =
GetSatHelper()->GetBeamHelper()->GetGwNodes();
157 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
159 const uint32_t gwId =
GetGwId(*it);
160 std::ostringstream name;
161 name << gwId <<
" " << frameTypeId;
162 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
163 collectorMap.Create(gwId);
170 std::list<std::pair<uint32_t, uint32_t>> beams =
172 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
176 const uint32_t satId = (it->first);
177 const uint32_t beamId = (it->second);
178 std::ostringstream name;
179 name << satId <<
"-" << beamId <<
" " << frameTypeId;
180 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
189 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
193 collectorMap.ConnectToAggregator(
"Output",
m_aggregator, &MultiFileAggregator::Write1d);
195 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)"
196 <<
" of " << collectorMap.GetType().GetName() <<
" for "
199 std::pair<std::map<uint32_t, CollectorMap>::iterator,
bool> ret;
200 ret =
m_collectors.insert(std::make_pair(frameTypeId, collectorMap));
201 NS_ASSERT(ret.second);
205 Callback<void, std::string, Ptr<SatBbFrame>> frameTypeUsageCallback =
209 NodeContainer gwNodes =
GetSatHelper()->GetBeamHelper()->GetGwNodes();
210 for (
auto node = gwNodes.Begin(); node != gwNodes.End(); node++)
212 for (uint32_t i = 0; i < (*node)->GetNDevices(); i++)
214 Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>((*node)->GetDevice(i));
217 Ptr<SatGwMac> mac = DynamicCast<SatGwMac>(dev->GetMac());
222 uint32_t beamId = mac->GetBeamId();
223 uint32_t satId = mac->GetSatId();
224 std::ostringstream context;
227 mac->TraceConnect(
"BBFrameTxTrace", context.str(), frameTypeUsageCallback);
228 NS_ASSERT_MSG(ret,
"Error connecting to BBFrameTxTrace of beam " << beamId);
229 NS_LOG_INFO(
this <<
" successfully connected"
230 <<
" with beam " << beamId);
242 return "% global frame_type " + dataLabel;
245 return "% gw_id frame_type " + dataLabel;
248 return "% beam_id frame_type " + dataLabel;
251 NS_FATAL_ERROR(
"SatStatsFrameTypeUsageHelper - Invalid identifier type");
274 std::stringstream ss(context);
276 if (!(ss >> identifier))
278 NS_FATAL_ERROR(
"Cannot convert '" << context <<
"' to number");
282 std::map<uint32_t, CollectorMap>::iterator it =
m_collectors.find(frameTypeId);
288 Ptr<DataCollectionObject> collector = it->second.Get(identifier);
289 NS_ASSERT_MSG(collector !=
nullptr,
290 "Unable to find collector with identifier " << identifier);
292 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
293 NS_ASSERT(c !=
nullptr);
296 c->TraceSinkUinteger32(0, 1);
304 Ptr<DataCollectionObject> collector = it.second.Get(identifier);
305 NS_ASSERT_MSG(collector !=
nullptr,
306 "Unable to find collector with identifier " << identifier);
307 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
308 NS_ASSERT(c !=
nullptr);
309 if (it.first == frameTypeId)
310 c->TraceSinkUinteger32(0, 1);
312 c->TraceSinkUinteger32(0, 0);
SatBbFrameType_t
BB frame type used in DVB-S2 FWD link.
static std::string GetFrameTypeName(SatBbFrameType_t frameType)
virtual ~SatStatsFrameTypeUsageHelper()
/ Destructor.
SatStatsFrameTypeUsageHelper(Ptr< const SatHelper > satHelper)
Constructor.
std::string GetIdentifierHeading(std::string dataLabel) const
Get identifier header for file.
void FrameTypeUsageCallback(std::string context, Ptr< SatBbFrame > bbFrame)
static const std::map< SatEnums::SatBbFrameType_t, uint32_t > frameTypeIdMap
Mapping for frame type IDs to integers, in case that SatBbFrameType_t enums are assigned.
std::map< uint32_t, CollectorMap > m_collectors
Two-dimensional map of collectors, indexed first by the the frame type identifier and second by the g...
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
static uint32_t GetFrameTypeId(SatEnums::SatBbFrameType_t frameType)
Get frame type ID.
bool m_usePercentage
Flag for using percentage of the frame types in beam/in gw/globally instead of sum by type.
static TypeId GetTypeId()
inherited from ObjectBase base class
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
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.