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/scalar-collector.h>
48 #include <ns3/singleton.h>
49 #include <ns3/string.h>
50 #include <ns3/traffic-time-tag.h>
51 #include <ns3/unit-conversion-collector.h>
55 NS_LOG_COMPONENT_DEFINE(
"SatStatsPltHelper");
60 NS_OBJECT_ENSURE_REGISTERED(SatStatsPltHelper);
64 m_averagingMode(false)
66 NS_LOG_FUNCTION(
this << satHelper);
71 NS_LOG_FUNCTION(
this);
78 TypeId(
"ns3::SatStatsPltHelper")
80 .AddAttribute(
"AveragingMode",
81 "If true, all samples will be averaged before passed to aggregator. "
82 "Only affects histogram, PDF, and CDF output types.",
86 MakeBooleanChecker());
93 NS_LOG_FUNCTION(
this << averagingMode);
106 NS_LOG_FUNCTION(
this);
112 <<
" is not a valid output type for this statistics.");
122 "EnableContextPrinting",
130 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
133 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
137 &MultiFileAggregator::Write1d);
152 EnumValue(UnitConversionCollector::TRANSPARENT));
156 &MultiFileAggregator::Write2d);
171 "EnableContextPrinting",
175 Ptr<MultiFileAggregator> fileAggregator =
177 NS_ASSERT(fileAggregator !=
nullptr);
181 DistributionCollector::OutputType_t outputType =
182 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
185 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
189 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
196 MakeCallback(&MultiFileAggregator::Write2d, fileAggregator));
200 MakeCallback(&MultiFileAggregator::AddContextHeading, fileAggregator));
204 MakeCallback(&MultiFileAggregator::EnableContextWarning, fileAggregator));
209 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
212 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
214 Callback<void, double> callback =
220 it->second->TraceConnectWithoutContext(
"Output", callback);
234 DistributionCollector::OutputType_t outputType =
235 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
238 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
242 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
248 &MultiFileAggregator::Write2d);
251 &MultiFileAggregator::AddContextHeading);
254 &MultiFileAggregator::EnableContextWarning);
263 <<
" is not a valid output type for this statistics.");
273 Ptr<MagisterGnuplotAggregator> plotAggregator =
275 NS_ASSERT(plotAggregator !=
nullptr);
277 plotAggregator->SetLegend(
"Time (in seconds)",
"Object PLT (in seconds)");
278 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
283 EnumValue(UnitConversionCollector::TRANSPARENT));
289 const std::string context = it->second->GetName();
290 plotAggregator->Add2dDataset(context, context);
294 &MagisterGnuplotAggregator::Write2d);
309 Ptr<MagisterGnuplotAggregator> plotAggregator =
311 NS_ASSERT(plotAggregator !=
nullptr);
313 plotAggregator->SetLegend(
"Object PLT (in seconds)",
"Frequency");
314 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
320 DistributionCollector::OutputType_t outputType =
321 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
324 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
328 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
335 MakeCallback(&MagisterGnuplotAggregator::Write2d, plotAggregator));
341 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
344 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
346 Callback<void, double> callback =
352 it->second->TraceConnectWithoutContext(
"Output", callback);
363 Ptr<MagisterGnuplotAggregator> plotAggregator =
365 NS_ASSERT(plotAggregator !=
nullptr);
367 plotAggregator->SetLegend(
"Object PLT (in seconds)",
"Frequency");
368 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
372 DistributionCollector::OutputType_t outputType =
373 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
376 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
380 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
388 const std::string context = it->second->GetName();
389 plotAggregator->Add2dDataset(context, context);
393 &MagisterGnuplotAggregator::Write2d);
400 NS_FATAL_ERROR(
"SatStatsPltHelper - Invalid output type");
421 if (from.IsInvalid())
423 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
424 <<
" from statistics collection because of"
425 <<
" invalid sender address");
430 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(from);
438 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
439 <<
" from statistics collection because of"
440 <<
" unknown sender address " << from);
448 NS_LOG_FUNCTION(
this << utNode->GetId());
450 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
453 if (addr.IsInvalid())
455 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" is not a valid UT");
461 NS_LOG_INFO(
this <<
" associated address " << addr <<
" with identifier " << identifier);
468 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
478 &ScalarCollector::TraceSinkDouble);
486 &UnitConversionCollector::TraceSinkDouble);
500 &ScalarCollector::TraceSinkDouble);
507 &DistributionCollector::TraceSinkDouble);
513 <<
" is not a valid output type for this statistics.");
519 NS_LOG_INFO(
this <<
" created probe " << probe->GetName() <<
", connected to collector "
524 NS_LOG_WARN(
this <<
" unable to connect probe " << probe->GetName() <<
" to collector "
537 NS_ASSERT_MSG(collector !=
nullptr,
"Unable to find collector with identifier " << identifier);
543 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
544 NS_ASSERT(c !=
nullptr);
545 c->TraceSinkDouble(0.0, plt.GetSeconds());
551 Ptr<UnitConversionCollector> c = collector->GetObject<UnitConversionCollector>();
552 NS_ASSERT(c !=
nullptr);
553 c->TraceSinkDouble(0.0, plt.GetSeconds());
565 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
566 NS_ASSERT(c !=
nullptr);
567 c->TraceSinkDouble(0.0, plt.GetSeconds());
571 Ptr<DistributionCollector> c = collector->GetObject<DistributionCollector>();
572 NS_ASSERT(c !=
nullptr);
573 c->TraceSinkDouble(0.0, plt.GetSeconds());
579 <<
" is not a valid output type for this statistics.");
593 NS_LOG_FUNCTION(
this << satHelper);
598 NS_LOG_FUNCTION(
this);
604 static TypeId tid = TypeId(
"ns3::SatStatsFwdAppPltHelper").SetParent<
SatStatsPltHelper>();
611 NS_LOG_FUNCTION(
this);
614 for (NodeContainer::Iterator it = utUsers.Begin(); it != utUsers.End(); ++it)
617 NS_ASSERT_MSG(utUserId > 0,
"Node " << (*it)->GetId() <<
" is not a valid UT user");
620 for (uint32_t i = 0; i < (*it)->GetNApplications(); i++)
622 Ptr<Application> app = (*it)->GetApplication(i);
623 bool isConnected =
false;
625 if (app->GetInstanceTypeId().LookupTraceSourceByName(
"RxPlt") !=
nullptr)
627 NS_LOG_INFO(
this <<
" attempt to connect using RxPlt");
630 std::ostringstream probeName;
631 probeName << utUserId <<
"-" << i;
632 Ptr<ApplicationDelayProbe> probe = CreateObject<ApplicationDelayProbe>();
633 probe->SetName(probeName.str());
636 if (probe->ConnectByObject(
"RxPlt", app))
639 m_probes.push_back(probe->GetObject<Probe>());
645 NS_LOG_INFO(
this <<
" successfully connected"
646 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
655 NS_LOG_WARN(
this <<
" unable to connect"
656 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
672 NS_LOG_FUNCTION(
this << satHelper);
677 NS_LOG_FUNCTION(
this);
683 static TypeId tid = TypeId(
"ns3::SatStatsRtnAppPltHelper").SetParent<
SatStatsPltHelper>();
690 NS_LOG_FUNCTION(
this);
694 Callback<void, const Time&, const Address&> rxPltCallback =
697 for (NodeContainer::Iterator it = gwUsers.Begin(); it != gwUsers.End(); ++it)
699 for (uint32_t i = 0; i < (*it)->GetNApplications(); i++)
701 Ptr<Application> app = (*it)->GetApplication(i);
702 bool isConnected =
false;
704 if (app->GetInstanceTypeId().LookupTraceSourceByName(
"RxPlt") !=
nullptr)
706 isConnected = app->TraceConnectWithoutContext(
"RxPlt", rxPltCallback);
711 NS_LOG_INFO(
this <<
" successfully connected"
712 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
721 NS_LOG_WARN(
this <<
" unable to connect"
722 <<
" with node ID " << (*it)->GetId() <<
" application #" << i);
736 if (InetSocketAddress::IsMatchingType(from))
739 const Address ipv4Addr = InetSocketAddress::ConvertFrom(from).GetIpv4();
740 std::map<const Address, uint32_t>::const_iterator it1 =
m_identifierMap.find(ipv4Addr);
744 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
745 <<
" from statistics collection because of"
746 <<
" unknown sender IPV4 address " << ipv4Addr);
755 NS_LOG_WARN(
this <<
" discarding a object PLT of " << plt.GetSeconds()
756 <<
" from statistics collection"
757 <<
" because it comes from sender " << from
758 <<
" without valid InetSocketAddress");
765 NS_LOG_FUNCTION(
this << utUserNode->GetId());
767 Ptr<Ipv4> ipv4 = utUserNode->GetObject<Ipv4>();
771 NS_LOG_INFO(
this <<
" Node " << utUserNode->GetId() <<
" does not support IPv4 protocol");
773 else if (ipv4->GetNInterfaces() >= 2)
781 for (uint32_t i = 0; i < ipv4->GetNAddresses(1); i++)
783 const Address addr = ipv4->GetAddress(1, i).GetLocal();
785 NS_LOG_INFO(
this <<
" associated address " << addr <<
" with identifier "
791 NS_LOG_WARN(
this <<
" Node " << utUserNode->GetId() <<
" is not a valid UT user");
Address GetUtMacWithNode(Ptr< Node > utNode) const
virtual ~SatStatsFwdAppPltHelper()
Destructor for SatStatsFwdAppPltHelper.
SatStatsFwdAppPltHelper(Ptr< const SatHelper > satHelper)
std::list< Ptr< Probe > > m_probes
Maintains a list of probes created by this helper.
static TypeId GetTypeId()
inherited from ObjectBase base class
Parent abstract class of all satellite statistics helpers.
Ptr< const SatHelper > GetSatHelper() const
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
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)
virtual ~SatStatsPltHelper()
/ Destructor.
void SaveAddressAndIdentifier(Ptr< Node > utNode)
Save the address and the proper identifier from the given UT node.
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
std::map< const Address, uint32_t > m_identifierMap
Map of address and the identifier associated with it (for return link).
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.