26 #include <ns3/boolean.h>
27 #include <ns3/callback.h>
28 #include <ns3/data-collection-object.h>
29 #include <ns3/distribution-collector.h>
32 #include <ns3/mac48-address.h>
33 #include <ns3/magister-gnuplot-aggregator.h>
34 #include <ns3/multi-file-aggregator.h>
35 #include <ns3/node-container.h>
36 #include <ns3/object-vector.h>
37 #include <ns3/probe.h>
38 #include <ns3/satellite-helper.h>
39 #include <ns3/satellite-id-mapper.h>
40 #include <ns3/satellite-net-device.h>
41 #include <ns3/satellite-phy-rx-carrier.h>
42 #include <ns3/satellite-phy-rx.h>
43 #include <ns3/satellite-phy.h>
44 #include <ns3/satellite-topology.h>
45 #include <ns3/scalar-collector.h>
46 #include <ns3/singleton.h>
47 #include <ns3/string.h>
48 #include <ns3/unit-conversion-collector.h>
55 NS_LOG_COMPONENT_DEFINE(
"SatStatsCompositeSinrHelper");
60 NS_OBJECT_ENSURE_REGISTERED(SatStatsCompositeSinrHelper);
65 NS_LOG_FUNCTION(
this << satHelper);
70 NS_LOG_FUNCTION(
this);
76 static TypeId tid = TypeId(
"ns3::SatStatsCompositeSinrHelper").SetParent<
SatStatsHelper>();
83 NS_LOG_FUNCTION(
this);
89 <<
" is not a valid output type for this statistics.");
99 "EnableContextPrinting",
107 EnumValue(ScalarCollector::INPUT_DATA_TYPE_DOUBLE));
110 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
114 &MultiFileAggregator::Write1d);
129 EnumValue(UnitConversionCollector::TRANSPARENT));
133 &MultiFileAggregator::Write2d);
149 DistributionCollector::OutputType_t outputType =
150 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
153 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
157 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
163 &MultiFileAggregator::Write2d);
166 &MultiFileAggregator::AddContextHeading);
169 &MultiFileAggregator::EnableContextWarning);
176 <<
" is not a valid output type for this statistics.");
186 Ptr<MagisterGnuplotAggregator> plotAggregator =
188 NS_ASSERT(plotAggregator !=
nullptr);
190 plotAggregator->SetLegend(
"Time (in seconds)",
"SINR (in dB)");
191 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
196 EnumValue(UnitConversionCollector::TRANSPARENT));
202 const std::string context = it->second->GetName();
203 plotAggregator->Add2dDataset(context, context);
207 &MagisterGnuplotAggregator::Write2d);
220 Ptr<MagisterGnuplotAggregator> plotAggregator =
222 NS_ASSERT(plotAggregator !=
nullptr);
224 plotAggregator->SetLegend(
"SINR (in dB)",
"Frequency");
225 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
229 DistributionCollector::OutputType_t outputType =
230 DistributionCollector::OUTPUT_TYPE_HISTOGRAM;
233 outputType = DistributionCollector::OUTPUT_TYPE_PROBABILITY;
237 outputType = DistributionCollector::OUTPUT_TYPE_CUMULATIVE;
245 const std::string context = it->second->GetName();
246 plotAggregator->Add2dDataset(context, context);
250 &MagisterGnuplotAggregator::Write2d);
255 NS_FATAL_ERROR(
"SatStatsCompositeSinrHelper - Invalid output type");
274 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
285 &ScalarCollector::TraceSinkDouble);
293 &UnitConversionCollector::TraceSinkDouble);
305 &DistributionCollector::TraceSinkDouble);
310 <<
" is not a valid output type for this statistics.");
317 NS_LOG_INFO(
this <<
" created probe " << probe->GetName() <<
", connected to collector "
322 NS_LOG_WARN(
this <<
" unable to connect probe " << probe->GetName() <<
" to collector "
332 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
343 &ScalarCollector::TraceSinkDouble);
351 &UnitConversionCollector::TraceSinkDouble);
363 &DistributionCollector::TraceSinkDouble);
368 <<
" is not a valid output type for this statistics.");
375 NS_LOG_INFO(
this <<
" probe " << probe->GetName() <<
", disconnected from collector "
380 NS_LOG_WARN(
this <<
" unable to disconnect probe " << probe->GetName() <<
" from collector "
394 NS_LOG_FUNCTION(
this << satHelper);
399 NS_LOG_FUNCTION(
this);
413 NS_LOG_FUNCTION(
this);
414 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
416 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
418 const int32_t utId =
GetUtId(*it);
419 NS_ASSERT_MSG(utId > 0,
"Node " << (*it)->GetId() <<
" is not a valid UT");
423 std::ostringstream probeName;
425 Ptr<SatSinrProbe> probe = CreateObject<SatSinrProbe>();
426 probe->SetName(probeName.str());
429 Ptr<SatNetDevice> satDev = dev->GetObject<
SatNetDevice>();
430 NS_ASSERT(satDev !=
nullptr);
431 Ptr<SatPhy> satPhy = satDev->GetPhy();
432 NS_ASSERT(satPhy !=
nullptr);
433 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
434 NS_ASSERT(satPhyRx !=
nullptr);
435 ObjectVectorValue carriers;
436 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
437 NS_LOG_DEBUG(
this <<
" Node ID " << (*it)->GetId() <<
" device #" << dev->GetIfIndex()
438 <<
" has " << carriers.GetN() <<
" RX carriers");
440 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin(); itCarrier != carriers.End();
444 if (probe->ConnectByObject(
"Sinr", itCarrier->second) &&
448 std::make_pair(probe->GetObject<Probe>(), std::make_pair(*it, identifier)));
452 NS_FATAL_ERROR(
"Error connecting to Sinr trace source"
453 <<
" of SatPhyRxCarrier"
454 <<
" at node ID " << (*it)->GetId() <<
" device #"
455 << dev->GetIfIndex() <<
" RX carrier #" << itCarrier->first);
467 NS_LOG_FUNCTION(
this);
469 std::map<Ptr<Probe>, std::pair<Ptr<Node>, uint32_t>>::iterator it;
473 Ptr<Probe> probe = it->first;
474 Ptr<Node> node = it->second.first;
475 uint32_t identifier = it->second.second;
479 NS_FATAL_ERROR(
"Error disconnecting trace file on handover");
486 NS_FATAL_ERROR(
"Error connecting trace file on handover");
489 it->second.second = identifier;
500 NS_LOG_FUNCTION(
this << satHelper);
505 NS_LOG_FUNCTION(
this);
519 NS_LOG_FUNCTION(
this);
521 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
522 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
530 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
531 Callback<void, double, const Address&> callback =
534 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
538 for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
540 Ptr<SatNetDevice> satDev = (*itDev)->GetObject<
SatNetDevice>();
541 NS_ASSERT(satDev !=
nullptr);
542 Ptr<SatPhy> satPhy = satDev->GetPhy();
543 NS_ASSERT(satPhy !=
nullptr);
544 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
545 NS_ASSERT(satPhyRx !=
nullptr);
546 ObjectVectorValue carriers;
547 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
548 NS_LOG_DEBUG(
this <<
" Node ID " << (*it)->GetId() <<
" device #"
549 << (*itDev)->GetIfIndex() <<
" has " << carriers.GetN()
552 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin();
553 itCarrier != carriers.End();
556 if (itCarrier->second->TraceConnectWithoutContext(
"Sinr", callback))
558 NS_LOG_INFO(
this <<
" successfully connected with node ID " << (*it)->GetId()
559 <<
" device #" << (*itDev)->GetIfIndex() <<
" RX carrier #"
560 << itCarrier->first);
564 NS_FATAL_ERROR(
"Error connecting to Sinr trace source"
565 <<
" of SatPhyRxCarrier"
566 <<
" at node ID " << (*it)->GetId() <<
" device #"
567 << (*itDev)->GetIfIndex() <<
" RX carrier #"
568 << itCarrier->first);
584 if (from.IsInvalid())
586 NS_LOG_WARN(
this <<
" discarding a SINR trace of " << sinrDb <<
" dB"
587 <<
" from statistics collection because of"
588 <<
" invalid sender address");
593 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(from);
597 NS_LOG_WARN(
this <<
" discarding a SINR trace of " << sinrDb <<
" dB"
598 <<
" from statistics collection because of"
599 <<
" unknown sender address " << from);
605 NS_ASSERT_MSG(collector !=
nullptr,
606 "Unable to find collector with identifier " << it->second);
612 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
613 NS_ASSERT(c !=
nullptr);
614 c->TraceSinkDouble(0.0, sinrDb);
620 Ptr<UnitConversionCollector> c = collector->GetObject<UnitConversionCollector>();
621 NS_ASSERT(c !=
nullptr);
622 c->TraceSinkDouble(0.0, sinrDb);
632 Ptr<DistributionCollector> c = collector->GetObject<DistributionCollector>();
633 NS_ASSERT(c !=
nullptr);
634 c->TraceSinkDouble(0.0, sinrDb);
640 <<
" is not a valid output type for this statistics.");
SatNetDevice to be utilized in the UT and GW nodes.
Abstract class inherited by SatStatsFwdCompositeSinrHelper and SatStatsRtnCompositeSinrHelper.
static TypeId GetTypeId()
inherited from ObjectBase base class
bool ConnectProbeToCollector(Ptr< Probe > probe, uint32_t identifier)
Connect the probe to the right collector.
void InstallProbes()
Set up several probes or other means of listeners and connect them to the collectors.
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.
bool DisconnectProbeFromCollector(Ptr< Probe > probe, uint32_t identifier)
Disconnect the probe from the right collector.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
virtual void DoInstallProbes()=0
virtual ~SatStatsCompositeSinrHelper()
/ Destructor.
SatStatsCompositeSinrHelper(Ptr< const SatHelper > satHelper)
Produce forward link composite SINR statistics from a satellite module simulation.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsFwdCompositeSinrHelper()
/ Destructor.
SatStatsFwdCompositeSinrHelper(Ptr< const SatHelper > satHelper)
virtual void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
std::map< Ptr< Probe >, std::pair< Ptr< Node >, uint32_t > > m_probes
Maintains a list of probes created by this helper.
Parent abstract class of all satellite statistics helpers.
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)
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
virtual std::string GetDistributionHeading(std::string dataLabel) const
Produce return link composite SINR statistics from a satellite module simulation.
SatStatsRtnCompositeSinrHelper(Ptr< const SatHelper > satHelper)
void SinrCallback(double sinrDb, const Address &from)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsRtnCompositeSinrHelper()
/ Destructor.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.