24#include "ns3/application-packet-probe.h"
25#include "ns3/boolean.h"
26#include "ns3/callback.h"
27#include "ns3/data-collection-object.h"
29#include "ns3/interval-rate-collector.h"
31#include "ns3/mac48-address.h"
32#include "ns3/magister-gnuplot-aggregator.h"
33#include "ns3/multi-file-aggregator.h"
34#include "ns3/node-container.h"
35#include "ns3/packet.h"
37#include "ns3/satellite-helper.h"
38#include "ns3/satellite-id-mapper.h"
39#include "ns3/satellite-net-device.h"
40#include "ns3/satellite-topology.h"
41#include "ns3/scalar-collector.h"
42#include "ns3/singleton.h"
43#include "ns3/string.h"
44#include "ns3/unit-conversion-collector.h"
51NS_LOG_COMPONENT_DEFINE(
"SatStatsSignallingLoadHelper");
61 NS_LOG_FUNCTION(
this << satHelper);
66 NS_LOG_FUNCTION(
this);
72 static TypeId tid = TypeId(
"ns3::SatStatsSignallingLoadHelper").SetParent<
SatStatsHelper>();
79 NS_LOG_FUNCTION(
this);
85 <<
" is not a valid output type for this statistics.");
95 "EnableContextPrinting",
103 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
106 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SECOND));
110 &MultiFileAggregator::Write1d);
115 EnumValue(UnitConversionCollector::FROM_BYTES_TO_KBIT));
119 &ScalarCollector::TraceSinkDouble);
134 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_DOUBLE));
138 &MultiFileAggregator::Write2d);
141 &MultiFileAggregator::AddContextHeading);
146 EnumValue(UnitConversionCollector::FROM_BYTES_TO_KBIT));
150 &IntervalRateCollector::TraceSinkDouble);
158 <<
" is not a valid output type for this statistics.");
164 <<
" is not a valid output type for this statistics.");
174 Ptr<MagisterGnuplotAggregator> plotAggregator =
176 NS_ASSERT(plotAggregator !=
nullptr);
178 plotAggregator->SetLegend(
"Time (in seconds)",
"Signalling load (in kilobits per second)");
179 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
184 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_DOUBLE));
190 const std::string context = it->second->GetName();
191 plotAggregator->Add2dDataset(context, context);
195 &MagisterGnuplotAggregator::Write2d);
200 EnumValue(UnitConversionCollector::FROM_BYTES_TO_KBIT));
204 &IntervalRateCollector::TraceSinkDouble);
212 <<
" is not a valid output type for this statistics.");
216 NS_FATAL_ERROR(
"SatStatsSignallingLoadHelper - Invalid output type");
228 NS_LOG_FUNCTION(
this);
241 NS_LOG_WARN(
this <<
" discarding packet " << packet <<
" (" << packet->GetSize()
242 <<
" bytes)" <<
" from statistics collection because of"
243 <<
" invalid sender address");
247 const Mac48Address addr = Mac48Address::ConvertFrom(to);
249 if (addr.IsBroadcast())
251 NS_LOG_INFO(
this <<
" broadcast control message packet");
258 Ptr<UnitConversionCollector> c = it->second->GetObject<UnitConversionCollector>();
259 NS_ASSERT(c !=
nullptr);
260 c->TraceSinkUinteger32(0, packet->GetSize());
266 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(addr);
270 NS_LOG_WARN(
this <<
" discarding packet " << packet <<
" (" << packet->GetSize()
271 <<
" bytes)" <<
" from statistics collection because of"
272 <<
" unknown sender address " << addr);
278 NS_ASSERT_MSG(collector !=
nullptr,
279 "Unable to find collector with identifier " << it->second);
280 Ptr<UnitConversionCollector> c = collector->GetObject<UnitConversionCollector>();
281 NS_ASSERT(c !=
nullptr);
284 c->TraceSinkUinteger32(0, packet->GetSize());
298 NS_LOG_FUNCTION(
this << satHelper);
303 NS_LOG_FUNCTION(
this);
317 NS_LOG_FUNCTION(
this);
320 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
321 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
328 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
329 Callback<void, Ptr<const Packet>,
const Address&> callback =
332 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
336 for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
338 NS_ASSERT((*itDev)->GetObject<
SatNetDevice>() !=
nullptr);
340 if ((*itDev)->TraceConnectWithoutContext(
"SignallingTx", callback))
342 NS_LOG_INFO(
this <<
" successfully connected with node ID " << (*it)->GetId()
343 <<
" device #" << (*itDev)->GetIfIndex());
347 NS_FATAL_ERROR(
"Error connecting to SignallingTx trace source"
348 <<
" of SatNetDevice" <<
" at node ID " << (*it)->GetId()
349 <<
" device #" << (*itDev)->GetIfIndex());
365 NS_LOG_FUNCTION(
this << satHelper);
370 NS_LOG_FUNCTION(
this);
384 NS_LOG_FUNCTION(
this);
385 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
387 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
389 const int32_t utId =
GetUtId(*it);
390 NS_ASSERT_MSG(utId > 0,
"Node " << (*it)->GetId() <<
" is not a valid UT");
394 std::ostringstream probeName;
396 Ptr<ApplicationPacketProbe> probe = CreateObject<ApplicationPacketProbe>();
397 probe->SetName(probeName.str());
402 if (probe->ConnectByObject(
"SignallingTx", dev))
406 probe->GetObject<Probe>(),
409 &UnitConversionCollector::TraceSinkUinteger32))
411 NS_LOG_INFO(
this <<
" created probe " << probeName.str()
412 <<
", connected to collector " << identifier);
414 std::make_pair(probe->GetObject<Probe>(), std::make_pair(*it, identifier)));
418 NS_LOG_WARN(
this <<
" unable to connect probe " << probeName.str()
419 <<
" to collector " << identifier);
425 NS_FATAL_ERROR(
"Error connecting to SignallingTx trace source of SatNetDevice"
426 <<
" at node ID " << (*it)->GetId() <<
" device #2");
436 NS_LOG_FUNCTION(
this);
438 std::map<Ptr<Probe>, std::pair<Ptr<Node>, uint32_t>>::iterator it;
442 Ptr<Probe> probe = it->first;
443 Ptr<Node> node = it->second.first;
444 uint32_t identifier = it->second.second;
447 probe->GetObject<Probe>(),
450 &UnitConversionCollector::TraceSinkUinteger32))
452 NS_FATAL_ERROR(
"Error disconnecting trace file on handover");
460 &UnitConversionCollector::TraceSinkUinteger32))
462 NS_FATAL_ERROR(
"Error connecting trace file on handover");
465 it->second.second = identifier;
SatNetDevice to be utilized in the UT and GW nodes.
Produce forward link signalling load statistics from a satellite module simulation.
SatStatsFwdSignallingLoadHelper(Ptr< const SatHelper > satHelper)
virtual ~SatStatsFwdSignallingLoadHelper()
/ Destructor.
static TypeId GetTypeId()
inherited from ObjectBase base class
uint32_t GetIdentifierForUtUser(Ptr< Node > utUserNode) const
static NetDeviceContainer GetGwSatNetDevice(Ptr< Node > gwNode)
virtual void SaveAddressAndIdentifier(Ptr< Node > utNode)
Save the address and the proper identifier from the given UT node.
static std::string GetOutputTypeName(OutputType_t outputType)
SatStatsHelper(Ptr< const SatHelper > satHelper)
Creates a new helper instance.
virtual std::string GetIdentifierHeading(std::string dataLabel) const
virtual std::string GetOutputPath() const
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.
uint32_t GetUtId(Ptr< Node > utNode) const
uint32_t CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
static Ptr< NetDevice > GetUtSatNetDevice(Ptr< Node > utNode)
OutputType_t GetOutputType() const
uint32_t GetIdentifierForUt(Ptr< Node > utNode) const
std::map< const Address, uint32_t > m_identifierMap
Map of address and the identifier associated with it.
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
Produce return link signalling load statistics from a satellite module simulation.
SatStatsRtnSignallingLoadHelper(Ptr< const SatHelper > satHelper)
std::map< Ptr< Probe >, std::pair< Ptr< Node >, uint32_t > > m_probes
Maintains a list of probes created by this helper.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
virtual ~SatStatsRtnSignallingLoadHelper()
/ Destructor.
Abstract class inherited by SatStatsFwdSignallingLoadHelper and SatStatsRtnSignallingLoadHelper.
virtual void DoInstallProbes()=0
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
virtual ~SatStatsSignallingLoadHelper()
/ Destructor.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
void InstallProbes()
Set up several probes or other means of listeners and connect them to the first-level collectors.
CollectorMap m_terminalCollectors
Maintains a list of second-level collectors created by this helper.
void SignallingTxCallback(Ptr< const Packet > packet, const Address &to)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsSignallingLoadHelper(Ptr< const SatHelper > satHelper)
CollectorMap m_conversionCollectors
Maintains a list of first-level collectors created by this helper.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.