26#include "ns3/boolean.h"
27#include "ns3/callback.h"
28#include "ns3/data-collection-object.h"
30#include "ns3/interval-rate-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/satellite-helper.h"
38#include "ns3/satellite-id-mapper.h"
39#include "ns3/satellite-net-device.h"
40#include "ns3/satellite-orbiter-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"
54NS_LOG_COMPONENT_DEFINE(
"SatStatsPacketErrorHelper");
68 NS_LOG_FUNCTION(
this << satHelper);
73 NS_LOG_FUNCTION(
this);
79 static TypeId tid = TypeId(
"ns3::SatStatsPacketErrorHelper").SetParent<
SatStatsHelper>();
86 NS_LOG_FUNCTION(
this << traceSourceName);
112 NS_LOG_FUNCTION(
this);
118 <<
" is not a valid output type for this statistics.");
128 "EnableContextPrinting",
136 EnumValue(ScalarCollector::INPUT_DATA_TYPE_BOOLEAN));
139 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
143 &MultiFileAggregator::Write1d);
159 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
162 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
166 &MultiFileAggregator::Write2d);
169 &MultiFileAggregator::AddContextHeading);
177 <<
" is not a valid output type for this statistics.");
183 <<
" is not a valid output type for this statistics.");
193 Ptr<MagisterGnuplotAggregator> plotAggregator =
195 NS_ASSERT(plotAggregator !=
nullptr);
197 plotAggregator->SetLegend(
"Time (in seconds)",
"Packet error rate");
198 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
204 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
207 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
213 const std::string context = it->second->GetName();
214 plotAggregator->Add2dDataset(context, context);
218 &MagisterGnuplotAggregator::Write2d);
226 <<
" is not a valid output type for this statistics.");
230 NS_FATAL_ERROR(
"SatStatsPacketErrorHelper - Invalid output type");
238 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
239 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
249 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
250 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
256 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
257 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
267 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
268 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
274 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
275 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
285 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
286 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
292 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
293 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
302 NS_FATAL_ERROR(
"SatStatsPacketErrorHelper - Invalid link");
311 NS_LOG_FUNCTION(
this << nPackets << fromOrTo << isError);
313 if (fromOrTo.IsInvalid())
315 NS_LOG_WARN(
this <<
" discarding " << nPackets <<
" packets"
316 <<
" from statistics collection because of"
317 <<
" invalid sender/destination address");
319 else if (Mac48Address::ConvertFrom(fromOrTo).IsBroadcast())
325 NS_ASSERT_MSG(collector !=
nullptr,
326 "Unable to find collector with identifier " << item.second);
332 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
333 NS_ASSERT(c !=
nullptr);
334 c->TraceSinkBoolean(
false, isError);
340 Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
341 NS_ASSERT(c !=
nullptr);
342 c->TraceSinkBoolean(
false, isError);
348 <<
" is not a valid output type for this statistics.");
357 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(fromOrTo);
361 NS_LOG_WARN(
this <<
" discarding " << nPackets <<
" packets"
362 <<
" from statistics collection because of"
363 <<
" unknown sender/destination address " << fromOrTo);
369 NS_ASSERT_MSG(collector !=
nullptr,
370 "Unable to find collector with identifier " << it->second);
376 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
377 NS_ASSERT(c !=
nullptr);
378 c->TraceSinkBoolean(
false, isError);
384 Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
385 NS_ASSERT(c !=
nullptr);
386 c->TraceSinkBoolean(
false, isError);
392 <<
" is not a valid output type for this statistics.");
406 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
417 &ScalarCollector::TraceSinkBoolean);
425 &IntervalRateCollector::TraceSinkBoolean);
430 <<
" is not a valid output type for this statistics.");
437 NS_LOG_INFO(
this <<
" created probe " << probe->GetName() <<
", connected to collector "
442 NS_LOG_WARN(
this <<
" unable to connect probe " << probe->GetName() <<
" to collector "
452 NS_LOG_FUNCTION(
this << probe << probe->GetName() << identifier);
463 &ScalarCollector::TraceSinkBoolean);
471 &IntervalRateCollector::TraceSinkBoolean);
476 <<
" is not a valid output type for this statistics.");
483 NS_LOG_INFO(
this <<
" probe " << probe->GetName() <<
", disconnected from collector "
488 NS_LOG_WARN(
this <<
" unable to disconnect probe " << probe->GetName() <<
" from collector "
498 NS_LOG_FUNCTION(
this);
500 std::map<Ptr<Probe>, std::pair<Ptr<Node>, uint32_t>>::iterator it;
504 Ptr<Probe> probe = it->first;
505 Ptr<Node> node = it->second.first;
506 uint32_t identifier = it->second.second;
510 NS_FATAL_ERROR(
"Error disconnecting trace file on handover");
517 NS_FATAL_ERROR(
"Error connecting trace file on handover");
520 it->second.second = identifier;
527 NS_LOG_FUNCTION(
this << gwNode->GetId());
530 Callback<void, uint32_t, const Address&, bool> callback =
533 for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
535 Ptr<SatNetDevice> satDev = (*itDev)->GetObject<
SatNetDevice>();
536 NS_ASSERT(satDev !=
nullptr);
537 Ptr<SatPhy> satPhy = satDev->GetPhy();
538 NS_ASSERT(satPhy !=
nullptr);
539 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
540 NS_ASSERT(satPhyRx !=
nullptr);
541 ObjectVectorValue carriers;
542 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
543 NS_LOG_DEBUG(
this <<
" Node ID " << gwNode->GetId() <<
" device #" << (*itDev)->GetIfIndex()
544 <<
" has " << carriers.GetN() <<
" RX carriers");
546 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin(); itCarrier != carriers.End();
549 if (DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType() !=
558 NS_LOG_INFO(
this <<
" successfully connected with node ID " << gwNode->GetId()
559 <<
" device #" << (*itDev)->GetIfIndex() <<
" RX carrier #"
560 << itCarrier->first);
564 NS_FATAL_ERROR(
"Error connecting to "
566 <<
" at node ID " << gwNode->GetId() <<
" device #"
567 << (*itDev)->GetIfIndex() <<
" RX carrier #" << itCarrier->first);
579 NS_LOG_FUNCTION(
this << satNode->GetId());
582 Callback<void, uint32_t, const Address&, bool> callback =
587 NS_ASSERT(satOrbiterDev !=
nullptr);
588 std::map<uint32_t, Ptr<SatPhy>> satOrbiterFeederPhys = satOrbiterDev->GetFeederPhy();
589 for (std::map<uint32_t, Ptr<SatPhy>>::iterator itPhy = satOrbiterFeederPhys.begin();
590 itPhy != satOrbiterFeederPhys.end();
593 satPhy = itPhy->second;
594 NS_ASSERT(satPhy !=
nullptr);
595 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
596 NS_ASSERT(satPhyRx !=
nullptr);
598 ObjectVectorValue carriers;
599 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
600 NS_LOG_DEBUG(
this <<
" Node ID " << satNode->GetId() <<
" device #" << dev->GetIfIndex()
601 <<
" has " << carriers.GetN() <<
" RX carriers");
603 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin(); itCarrier != carriers.End();
606 if (DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType() !=
615 NS_LOG_INFO(
this <<
" successfully connected with node ID " << satNode->GetId()
616 <<
" device #" << dev->GetIfIndex() <<
" RX carrier #"
617 << itCarrier->first);
621 NS_FATAL_ERROR(
"Error connecting to "
623 <<
" at node ID " << satNode->GetId() <<
" device #"
624 << dev->GetIfIndex() <<
" RX carrier #" << itCarrier->first);
636 NS_LOG_FUNCTION(
this << satNode->GetId());
639 Callback<void, uint32_t, const Address&, bool> callback =
644 NS_ASSERT(satOrbiterDev !=
nullptr);
645 std::map<uint32_t, Ptr<SatPhy>> satOrbiterUserPhys = satOrbiterDev->GetUserPhy();
646 for (std::map<uint32_t, Ptr<SatPhy>>::iterator itPhy = satOrbiterUserPhys.begin();
647 itPhy != satOrbiterUserPhys.end();
650 satPhy = itPhy->second;
651 NS_ASSERT(satPhy !=
nullptr);
652 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
653 NS_ASSERT(satPhyRx !=
nullptr);
655 ObjectVectorValue carriers;
656 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
657 NS_LOG_DEBUG(
this <<
" Node ID " << satNode->GetId() <<
" device #" << dev->GetIfIndex()
658 <<
" has " << carriers.GetN() <<
" RX carriers");
660 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin(); itCarrier != carriers.End();
663 if (DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType() !=
672 NS_LOG_INFO(
this <<
" successfully connected with node ID " << satNode->GetId()
673 <<
" device #" << dev->GetIfIndex() <<
" RX carrier #"
674 << itCarrier->first);
678 NS_FATAL_ERROR(
"Error connecting to "
680 <<
" at node ID " << satNode->GetId() <<
" device #"
681 << dev->GetIfIndex() <<
" RX carrier #" << itCarrier->first);
693 NS_LOG_FUNCTION(
this << utNode->GetId());
695 const int32_t utId =
GetUtId(utNode);
696 NS_ASSERT_MSG(utId > 0,
"Node " << utNode->GetId() <<
" is not a valid UT");
700 std::ostringstream probeName;
702 Ptr<SatPhyRxCarrierPacketProbe> probe = CreateObject<SatPhyRxCarrierPacketProbe>();
703 probe->SetName(probeName.str());
706 Ptr<SatNetDevice> satDev = dev->GetObject<
SatNetDevice>();
707 NS_ASSERT(satDev !=
nullptr);
708 Ptr<SatPhy> satPhy = satDev->GetPhy();
709 NS_ASSERT(satPhy !=
nullptr);
710 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
711 NS_ASSERT(satPhyRx !=
nullptr);
712 ObjectVectorValue carriers;
713 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
714 NS_LOG_DEBUG(
this <<
" Node ID " << utNode->GetId() <<
" device #" << dev->GetIfIndex()
715 <<
" has " << carriers.GetN() <<
" RX carriers");
717 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin(); itCarrier != carriers.End();
720 if (DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType() !=
730 std::make_pair(probe->GetObject<Probe>(), std::make_pair(utNode, identifier)));
735 NS_FATAL_ERROR(
"Error connecting to "
737 <<
" at node ID " << utNode->GetId() <<
" device #" << dev->GetIfIndex()
738 <<
" RX carrier #" << itCarrier->first);
750 Ptr<const SatHelper> satHelper)
753 NS_LOG_FUNCTION(
this << satHelper);
761 NS_LOG_FUNCTION(
this);
777 Ptr<const SatHelper> satHelper)
780 NS_LOG_FUNCTION(
this << satHelper);
788 NS_LOG_FUNCTION(
this);
804 Ptr<const SatHelper> satHelper)
807 NS_LOG_FUNCTION(
this << satHelper);
815 NS_LOG_FUNCTION(
this);
831 Ptr<const SatHelper> satHelper)
834 NS_LOG_FUNCTION(
this << satHelper);
842 NS_LOG_FUNCTION(
this);
858 Ptr<const SatHelper> satHelper)
861 NS_LOG_FUNCTION(
this << satHelper);
869 NS_LOG_FUNCTION(
this);
875 static TypeId tid = TypeId(
"ns3::SatStatsFeederSlottedAlohaPacketErrorHelper")
885 Ptr<const SatHelper> satHelper)
888 NS_LOG_FUNCTION(
this << satHelper);
896 NS_LOG_FUNCTION(
this);
902 static TypeId tid = TypeId(
"ns3::SatStatsUserSlottedAlohaPacketErrorHelper")
912 Ptr<const SatHelper> satHelper)
915 NS_LOG_FUNCTION(
this << satHelper);
923 NS_LOG_FUNCTION(
this);
939 Ptr<const SatHelper> satHelper)
942 NS_LOG_FUNCTION(
this << satHelper);
950 NS_LOG_FUNCTION(
this);
966 Ptr<const SatHelper> satHelper)
969 NS_LOG_FUNCTION(
this << satHelper);
977 NS_LOG_FUNCTION(
this);
995 NS_LOG_FUNCTION(
this << satHelper);
1003 NS_LOG_FUNCTION(
this);
SatEnums class is for simplifying the use of enumerators in the satellite module.
ChannelType_t
Types of channel.
static std::string GetChannelTypeName(ChannelType_t channelType)
SatNetDevice to be utilized in the UT and GW nodes.
SatOrbiterNetDevice to be utilized in geostationary satellite.
Produce packet error statistics of Random Access CRDSA on feeder link from a satellite module simulat...
virtual ~SatStatsFeederCrdsaPacketErrorHelper()
/ Destructor.
SatStatsFeederCrdsaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
Produce packet error statistics of Random Access E-SSA on feeder link from a satellite module simulat...
virtual ~SatStatsFeederEssaPacketErrorHelper()
/ Destructor.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFeederEssaPacketErrorHelper(Ptr< const SatHelper > satHelper)
Produce packet error statistics of Random Access Slotted ALOHA on feeder link from a satellite module...
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFeederSlottedAlohaPacketErrorHelper(Ptr< const SatHelper > satHelper)
virtual ~SatStatsFeederSlottedAlohaPacketErrorHelper()
/ Destructor.
Produce packet error statistics of Dedicated Access in forward feeder link from a satellite module si...
SatStatsFwdFeederDaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsFwdFeederDaPacketErrorHelper()
/ Destructor.
Produce packet error statistics of Dedicated Access in forward user link from a satellite module simu...
SatStatsFwdUserDaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsFwdUserDaPacketErrorHelper()
/ Destructor.
static Ptr< NetDevice > GetSatSatOrbiterNetDevice(Ptr< Node > satNode)
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
Base class for packet error statistics helpers.
static TypeId GetTypeId()
inherited from ObjectBase base class
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
std::string m_traceSourceName
Name of trace source of PHY RX carrier to listen to.
std::string GetTraceSourceName() const
SatEnums::ChannelType_t GetChannelType() const
virtual void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
void InstallProbeOnGw(Ptr< Node > gwNode)
Set up several listeners on a GW node and connect them to the collectors.
std::map< Ptr< Probe >, std::pair< Ptr< Node >, uint32_t > > m_probes
Maintains a list of probes created by this helper (for forward link).
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
SatPhyRxCarrier::CarrierType GetValidCarrierType() const
Get the valid carrier type.
bool DisconnectProbeFromCollector(Ptr< Probe > probe, uint32_t identifier)
Disconnect the probe from the right collector.
SatStatsPacketErrorHelper(Ptr< const SatHelper > satHelper)
CollectorMap m_terminalCollectors
Maintains a list of collectors created by this helper.
void InstallProbeOnUt(Ptr< Node > utNode)
Set up several probes on a UT node and connect them to the collectors.
SatEnums::ChannelType_t m_channelType
Link where statistics are gathered from.
void InstallProbeOnSatUser(Ptr< Node > satNode)
Set up several listeners on a SAT user node and connect them to the collectors.
void SetChannelType(SatEnums::ChannelType_t channelType)
bool ConnectProbeToCollector(Ptr< Probe > probe, uint32_t identifier)
Connect the probe to the right collector.
void SetValidCarrierType(SatPhyRxCarrier::CarrierType carrierType)
Set valid carrier type for this statistics helper type.
void SetTraceSourceName(std::string traceSourceName)
void ErrorRxCallback(uint32_t nPackets, const Address &fromOrTo, bool isError)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
virtual ~SatStatsPacketErrorHelper()
/ Destructor.
void InstallProbeOnSatFeeder(Ptr< Node > satNode)
Set up several listeners on a SAT feeder node and connect them to the collectors.
Produce packet error statistics of Dedicated Access in return feeder link from a satellite module sim...
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsRtnFeederDaPacketErrorHelper()
/ Destructor.
SatStatsRtnFeederDaPacketErrorHelper(Ptr< const SatHelper > satHelper)
Produce packet error statistics of Dedicated Access in return user link from a satellite module simul...
SatStatsRtnUserDaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsRtnUserDaPacketErrorHelper()
/ Destructor.
Produce packet error statistics of Random Access CRDSA on user link from a satellite module simulatio...
SatStatsUserCrdsaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsUserCrdsaPacketErrorHelper()
/ Destructor.
Produce packet error statistics of Random Access E-SSA on user link from a satellite module simulatio...
virtual ~SatStatsUserEssaPacketErrorHelper()
/ Destructor.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsUserEssaPacketErrorHelper(Ptr< const SatHelper > satHelper)
Produce packet error statistics of Random Access Slotted ALOHA on user link from a satellite module s...
virtual ~SatStatsUserSlottedAlohaPacketErrorHelper()
/ Destructor.
SatStatsUserSlottedAlohaPacketErrorHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.