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/satellite-topology.h>
39 #include <ns3/scalar-collector.h>
40 #include <ns3/singleton.h>
41 #include <ns3/string.h>
49 NS_LOG_COMPONENT_DEFINE(
"SatStatsFrameTypeUsageHelper");
54 NS_OBJECT_ENSURE_REGISTERED(SatStatsFrameTypeUsageHelper);
64 m_usePercentage(false)
66 NS_LOG_FUNCTION(
this << satHelper);
71 NS_LOG_FUNCTION(
this);
78 TypeId(
"ns3::SatStatsFrameTypeUsageHelper")
80 .AddAttribute(
"Percentage",
81 "Use percentage of each frame type instead of sum per identifier.",
84 MakeBooleanChecker());
91 NS_LOG_FUNCTION(
this);
96 <<
" is not a valid output type for this statistics.");
103 <<
" is not a valid identifier type for this statistics.");
107 std::string dataLabel;
109 dataLabel =
"usage_percentage";
111 dataLabel =
"usage_count";
118 "EnableContextPrinting",
126 uint32_t frameTypeId = it.second;
128 NS_LOG_INFO(
this <<
" Creating new collectors for frame type ID " << frameTypeId);
130 CollectorMap collectorMap;
131 ScalarCollector::OutputType_t opType;
133 opType = ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE;
135 opType = ScalarCollector::OUTPUT_TYPE_SUM;
137 collectorMap.SetType(
"ns3::ScalarCollector");
138 collectorMap.SetAttribute(
"OutputType", EnumValue(opType));
139 collectorMap.SetAttribute(
"InputDataType",
140 EnumValue(ScalarCollector::INPUT_DATA_TYPE_UINTEGER));
151 std::ostringstream name;
152 name <<
"0 " << frameTypeId;
153 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
154 collectorMap.Create(0);
160 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
161 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
163 const uint32_t gwId =
GetGwId(*it);
164 std::ostringstream name;
165 name << gwId <<
" " << frameTypeId;
166 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
167 collectorMap.Create(gwId);
174 std::list<std::pair<uint32_t, uint32_t>> beams =
176 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
180 const uint32_t satId = (it->first);
181 const uint32_t beamId = (it->second);
182 std::ostringstream name;
183 name << satId <<
"-" << beamId <<
" " << frameTypeId;
184 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
193 NS_FATAL_ERROR(
"SatStatsWaveformUsageHelper - Invalid identifier type");
197 collectorMap.ConnectToAggregator(
"Output",
m_aggregator, &MultiFileAggregator::Write1d);
199 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)"
200 <<
" of " << collectorMap.GetType().GetName() <<
" for "
203 std::pair<std::map<uint32_t, CollectorMap>::iterator,
bool> ret;
204 ret =
m_collectors.insert(std::make_pair(frameTypeId, collectorMap));
205 NS_ASSERT(ret.second);
209 Callback<void, std::string, Ptr<SatBbFrame>> frameTypeUsageCallback =
213 NodeContainer gwNodes = Singleton<SatTopology>::Get()->GetGwNodes();
214 for (
auto node = gwNodes.Begin(); node != gwNodes.End(); node++)
216 for (uint32_t i = 0; i < (*node)->GetNDevices(); i++)
218 Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>((*node)->GetDevice(i));
221 Ptr<SatGwMac> mac = DynamicCast<SatGwMac>(dev->GetMac());
226 uint32_t beamId = mac->GetBeamId();
227 uint32_t satId = mac->GetSatId();
228 std::ostringstream context;
231 mac->TraceConnect(
"BBFrameTxTrace", context.str(), frameTypeUsageCallback);
232 NS_ASSERT_MSG(ret,
"Error connecting to BBFrameTxTrace of beam " << beamId);
233 NS_LOG_INFO(
this <<
" successfully connected"
234 <<
" with beam " << beamId);
246 return "% global frame_type " + dataLabel;
249 return "% gw_id frame_type " + dataLabel;
252 return "% beam_id frame_type " + dataLabel;
255 NS_FATAL_ERROR(
"SatStatsFrameTypeUsageHelper - Invalid identifier type");
278 std::stringstream ss(context);
280 if (!(ss >> identifier))
282 NS_FATAL_ERROR(
"Cannot convert '" << context <<
"' to number");
286 std::map<uint32_t, CollectorMap>::iterator it =
m_collectors.find(frameTypeId);
292 Ptr<DataCollectionObject> collector = it->second.Get(identifier);
293 NS_ASSERT_MSG(collector !=
nullptr,
294 "Unable to find collector with identifier " << identifier);
296 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
297 NS_ASSERT(c !=
nullptr);
300 c->TraceSinkUinteger32(0, 1);
308 Ptr<DataCollectionObject> collector = it.second.Get(identifier);
309 NS_ASSERT_MSG(collector !=
nullptr,
310 "Unable to find collector with identifier " << identifier);
311 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
312 NS_ASSERT(c !=
nullptr);
313 if (it.first == frameTypeId)
314 c->TraceSinkUinteger32(0, 1);
316 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.