24 #include <ns3/application-delay-probe.h>
25 #include <ns3/application.h>
26 #include <ns3/boolean.h>
27 #include <ns3/callback.h>
28 #include <ns3/data-collection-object.h>
29 #include <ns3/distribution-collector.h>
31 #include <ns3/inet-socket-address.h>
34 #include <ns3/mac48-address.h>
35 #include <ns3/magister-gnuplot-aggregator.h>
36 #include <ns3/multi-file-aggregator.h>
37 #include <ns3/net-device.h>
38 #include <ns3/node-container.h>
39 #include <ns3/nstime.h>
40 #include <ns3/probe.h>
41 #include <ns3/satellite-helper.h>
42 #include <ns3/satellite-id-mapper.h>
43 #include <ns3/satellite-mac.h>
44 #include <ns3/satellite-net-device.h>
45 #include <ns3/satellite-phy.h>
46 #include <ns3/satellite-time-tag.h>
47 #include <ns3/satellite-topology.h>
48 #include <ns3/scalar-collector.h>
49 #include <ns3/singleton.h>
50 #include <ns3/string.h>
51 #include <ns3/traffic-time-tag.h>
52 #include <ns3/unit-conversion-collector.h>
59 NS_LOG_COMPONENT_DEFINE(
"SatStatsPltHelper");
64 NS_OBJECT_ENSURE_REGISTERED(SatStatsPltHelper);
68 m_averagingMode(false)
70 NS_LOG_FUNCTION(
this << satHelper);
75 NS_LOG_FUNCTION(
this);
82 TypeId(
"ns3::SatStatsPltHelper")
84 .AddAttribute(
"AveragingMode",
85 "If true, all samples will be averaged before passed to aggregator. "
86 "Only affects histogram, PDF, and CDF output types.",
90 MakeBooleanChecker());
97 NS_LOG_FUNCTION(
this << averagingMode);
110 NS_LOG_FUNCTION(
this);
116 <<
" is not a valid output type for this statistics.");
126 "EnableContextPrinting",
134 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
137 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
141 &MultiFileAggregator::Write1d);
156 EnumValue(UnitConversionCollector::TRANSPARENT));
160 &MultiFileAggregator::Write2d);
175 "EnableContextPrinting",
179 Ptr<MultiFileAggregator> fileAggregator =
181 NS_ASSERT(fileAggregator !=
nullptr);
185 DistributionCollector::OutputType_t outputType =
186 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
189 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
193 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
200 MakeCallback(&MultiFileAggregator::Write2d, fileAggregator));
204 MakeCallback(&MultiFileAggregator::AddContextHeading, fileAggregator));
208 MakeCallback(&MultiFileAggregator::EnableContextWarning, fileAggregator));
213 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
216 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
218 Callback<void, double> callback =
224 it->second->TraceConnectWithoutContext(
"Output", callback);
238 DistributionCollector::OutputType_t outputType =
239 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
242 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
246 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
252 &MultiFileAggregator::Write2d);
255 &MultiFileAggregator::AddContextHeading);
258 &MultiFileAggregator::EnableContextWarning);
267 <<
" is not a valid output type for this statistics.");
277 Ptr<MagisterGnuplotAggregator> plotAggregator =
279 NS_ASSERT(plotAggregator !=
nullptr);
281 plotAggregator->SetLegend(
"Time (in seconds)",
"Object PLT (in seconds)");
282 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
287 EnumValue(UnitConversionCollector::TRANSPARENT));
293 const std::string context = it->second->GetName();
294 plotAggregator->Add2dDataset(context, context);
298 &MagisterGnuplotAggregator::Write2d);
313 Ptr<MagisterGnuplotAggregator> plotAggregator =
315 NS_ASSERT(plotAggregator !=
nullptr);
317 plotAggregator->SetLegend(
"Object PLT (in seconds)",
"Frequency");
318 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
324 DistributionCollector::OutputType_t outputType =
325 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
328 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
332 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
339 MakeCallback(&MagisterGnuplotAggregator::Write2d, plotAggregator));
345 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
348 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
350 Callback<void, double> callback =
356 it->second->TraceConnectWithoutContext(
"Output", callback);
367 Ptr<MagisterGnuplotAggregator> plotAggregator =
369 NS_ASSERT(plotAggregator !=
nullptr);
371 plotAggregator->SetLegend(
"Object PLT (in seconds)",
"Frequency");
372 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
376 DistributionCollector::OutputType_t outputType =
377 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
380 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
384 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
392 const std::string context = it->second->GetName();
393 plotAggregator->Add2dDataset(context, context);
397 &MagisterGnuplotAggregator::Write2d);
404 NS_FATAL_ERROR(
"SatStatsPltHelper - Invalid output type");
425 if (from.IsInvalid())
427 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
428 <<
" from statistics collection because of"
429 <<
" invalid sender address");
434 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(from);
442 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
443 <<
" from statistics collection because of"
444 <<
" unknown sender address " << from);
452 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
462 &ScalarCollector::TraceSinkDouble);
470 &UnitConversionCollector::TraceSinkDouble);
484 &ScalarCollector::TraceSinkDouble);
491 &DistributionCollector::TraceSinkDouble);
497 <<
" is not a valid output type for this statistics.");
503 NS_LOG_INFO(
this <<
" created probe " << probe->GetName() <<
", connected to collector "
508 NS_LOG_WARN(
this <<
" unable to connect probe " << probe->GetName() <<
" to collector "
518 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
528 &ScalarCollector::TraceSinkDouble);
536 &UnitConversionCollector::TraceSinkDouble);
550 &ScalarCollector::TraceSinkDouble);
557 &DistributionCollector::TraceSinkDouble);
563 <<
" is not a valid output type for this statistics.");
569 NS_LOG_INFO(
this <<
" probe " << probe->GetName() <<
", disconnected from collector "
574 NS_LOG_WARN(
this <<
" unable to disconnect probe " << probe->GetName() <<
" from collector "
587 NS_ASSERT_MSG(collector !=
nullptr,
"Unable to find collector with identifier " << identifier);
593 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
594 NS_ASSERT(c !=
nullptr);
595 c->TraceSinkDouble(0.0, plt.GetSeconds());
601 Ptr<UnitConversionCollector> c = collector->GetObject<UnitConversionCollector>();
602 NS_ASSERT(c !=
nullptr);
603 c->TraceSinkDouble(0.0, plt.GetSeconds());
615 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
616 NS_ASSERT(c !=
nullptr);
617 c->TraceSinkDouble(0.0, plt.GetSeconds());
621 Ptr<DistributionCollector> c = collector->GetObject<DistributionCollector>();
622 NS_ASSERT(c !=
nullptr);
623 c->TraceSinkDouble(0.0, plt.GetSeconds());
629 <<
" is not a valid output type for this statistics.");
643 NS_LOG_FUNCTION(
this << satHelper);
648 NS_LOG_FUNCTION(
this);
654 static TypeId tid = TypeId(
"ns3::SatStatsFwdAppPltHelper").SetParent<
SatStatsPltHelper>();
661 NS_LOG_FUNCTION(
this);
662 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
664 for (NodeContainer::Iterator it = utUsers.Begin(); it != utUsers.End(); ++it)
667 NS_ASSERT_MSG(utUserId > 0,
"Node " << (*it)->GetId() <<
" is not a valid UT user");
670 for (uint32_t i = 0; i < (*it)->GetNApplications(); i++)
672 Ptr<Application> app = (*it)->GetApplication(i);
673 bool isConnected =
false;
675 if (app->GetInstanceTypeId().LookupTraceSourceByName(
"RxPlt") !=
nullptr)
677 NS_LOG_INFO(
this <<
" attempt to connect using RxPlt");
680 std::ostringstream probeName;
681 probeName << utUserId <<
"-" << i;
682 Ptr<ApplicationDelayProbe> probe = CreateObject<ApplicationDelayProbe>();
683 probe->SetName(probeName.str());
686 if (probe->ConnectByObject(
"RxPlt", app))
690 std::make_pair(probe->GetObject<Probe>(), std::make_pair(*it, identifier)));
696 NS_LOG_INFO(
this <<
" successfully connected"
697 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
706 NS_LOG_WARN(
this <<
" unable to connect"
707 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
719 NS_LOG_FUNCTION(
this);
721 std::map<Ptr<Probe>, std::pair<Ptr<Node>, uint32_t>>::iterator it;
725 Ptr<Probe> probe = it->first;
726 Ptr<Node> node = it->second.first;
727 uint32_t identifier = it->second.second;
731 NS_FATAL_ERROR(
"Error disconnecting trace file on handover");
738 NS_FATAL_ERROR(
"Error connecting trace file on handover");
741 it->second.second = identifier;
752 NS_LOG_FUNCTION(
this << satHelper);
757 NS_LOG_FUNCTION(
this);
763 static TypeId tid = TypeId(
"ns3::SatStatsRtnAppPltHelper").SetParent<
SatStatsPltHelper>();
770 NS_LOG_FUNCTION(
this);
773 NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
774 Callback<void, const Time&, const Address&> rxPltCallback =
777 for (NodeContainer::Iterator it = gwUsers.Begin(); it != gwUsers.End(); ++it)
779 for (uint32_t i = 0; i < (*it)->GetNApplications(); i++)
781 Ptr<Application> app = (*it)->GetApplication(i);
782 bool isConnected =
false;
784 if (app->GetInstanceTypeId().LookupTraceSourceByName(
"RxPlt") !=
nullptr)
786 isConnected = app->TraceConnectWithoutContext(
"RxPlt", rxPltCallback);
791 NS_LOG_INFO(
this <<
" successfully connected"
792 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
801 NS_LOG_WARN(
this <<
" unable to connect"
802 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
816 if (InetSocketAddress::IsMatchingType(from))
819 const Address ipv4Addr = InetSocketAddress::ConvertFrom(from).GetIpv4();
820 std::map<const Address, uint32_t>::const_iterator it1 =
m_identifierMap.find(ipv4Addr);
824 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
825 <<
" from statistics collection because of"
826 <<
" unknown sender IPV4 address " << ipv4Addr);
835 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
836 <<
" from statistics collection"
837 <<
" because it comes from sender " << from
838 <<
" without valid InetSocketAddress");
845 NS_LOG_FUNCTION(
this << utUserNode->GetId());
847 Ptr<Ipv4> ipv4 = utUserNode->GetObject<Ipv4>();
851 NS_LOG_INFO(
this <<
" Node " << utUserNode->GetId() <<
" does not support IPv4 protocol");
853 else if (ipv4->GetNInterfaces() >= 2)
861 for (uint32_t i = 0; i < ipv4->GetNAddresses(1); i++)
863 const Address addr = ipv4->GetAddress(1, i).GetLocal();
865 NS_LOG_INFO(
this <<
" associated address " << addr <<
" with identifier "
871 NS_LOG_WARN(
this <<
" Node " << utUserNode->GetId() <<
" is not a valid UT user");
virtual ~SatStatsFwdAppPltHelper()
Destructor for SatStatsFwdAppPltHelper.
SatStatsFwdAppPltHelper(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.
virtual void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
static TypeId GetTypeId()
inherited from ObjectBase base class
Parent abstract class of all satellite statistics helpers.
uint32_t GetIdentifierForUtUser(Ptr< Node > utUserNode) const
static std::string GetOutputTypeName(OutputType_t outputType)
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 CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
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.
uint32_t GetUtUserId(Ptr< Node > utUserNode) const
std::string GetName() const
virtual std::string GetTimeHeading(std::string dataLabel) const
virtual std::string GetDistributionHeading(std::string dataLabel) const
Base class for PLT statistics helpers.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual void DoInstallProbes()=0
void RxPltCallback(const Time &plt, const Address &from)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
CollectorMap m_terminalCollectors
Maintains a list of collectors created by this helper.
Ptr< DistributionCollector > m_averagingCollector
The final collector utilized in averaged output (histogram, PDF, and CDF).
bool ConnectProbeToCollector(Ptr< Probe > probe, uint32_t identifier)
Connect the probe to the right collector.
bool m_averagingMode
AveragingMode attribute.
void SetAveragingMode(bool averagingMode)
bool DisconnectProbeFromCollector(Ptr< Probe > probe, uint32_t identifier)
Disconnect the probe from the right collector.
virtual ~SatStatsPltHelper()
/ Destructor.
SatStatsPltHelper(Ptr< const SatHelper > satHelper)
void InstallProbes()
Set up several probes or other means of listeners and connect them to the collectors.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
void PassSampleToCollector(const Time &plt, uint32_t identifier)
Find a collector with the right identifier and pass a sample data to it.
bool GetAveragingMode() const
void Ipv4Callback(const Time &plt, const Address &from)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
virtual ~SatStatsRtnAppPltHelper()
/ Destructor.
void SaveIpv4AddressAndIdentifier(Ptr< Node > utUserNode)
Save the IPv4 address and the proper identifier from the given UT user node.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsRtnAppPltHelper(Ptr< const SatHelper > satHelper)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.