24#include "ns3/boolean.h"
25#include "ns3/callback.h"
26#include "ns3/data-collection-object.h"
28#include "ns3/interval-rate-collector.h"
30#include "ns3/mac48-address.h"
31#include "ns3/magister-gnuplot-aggregator.h"
32#include "ns3/multi-file-aggregator.h"
33#include "ns3/node-container.h"
34#include "ns3/object-vector.h"
35#include "ns3/satellite-helper.h"
36#include "ns3/satellite-id-mapper.h"
37#include "ns3/satellite-net-device.h"
38#include "ns3/satellite-orbiter-net-device.h"
39#include "ns3/satellite-phy-rx-carrier.h"
40#include "ns3/satellite-phy-rx.h"
41#include "ns3/satellite-phy.h"
42#include "ns3/satellite-topology.h"
43#include "ns3/scalar-collector.h"
44#include "ns3/singleton.h"
45#include "ns3/string.h"
51NS_LOG_COMPONENT_DEFINE(
"SatStatsPacketCollisionHelper");
63 NS_LOG_FUNCTION(
this << satHelper);
68 NS_LOG_FUNCTION(
this);
74 static TypeId tid = TypeId(
"ns3::SatStatsPacketCollisionHelper").SetParent<
SatStatsHelper>();
81 NS_LOG_FUNCTION(
this << traceSourceName);
96 NS_LOG_FUNCTION(
this << nPackets << from << isCollided);
100 NS_LOG_WARN(
this <<
" discarding " << nPackets <<
" packets"
101 <<
" from statistics collection because of" <<
" invalid sender address");
106 std::map<const Address, uint32_t>::const_iterator it =
m_identifierMap.find(from);
110 NS_LOG_WARN(
this <<
" discarding " << nPackets <<
" packets"
111 <<
" from statistics collection because of"
112 <<
" unknown sender address " << from);
118 NS_ASSERT_MSG(collector !=
nullptr,
119 "Unable to find collector with identifier " << it->second);
125 Ptr<ScalarCollector> c = collector->GetObject<ScalarCollector>();
126 NS_ASSERT(c !=
nullptr);
127 c->TraceSinkBoolean(
false, isCollided);
133 Ptr<IntervalRateCollector> c = collector->GetObject<IntervalRateCollector>();
134 NS_ASSERT(c !=
nullptr);
135 c->TraceSinkBoolean(
false, isCollided);
141 <<
" is not a valid output type for this statistics.");
157 Ptr<const SatHelper> satHelper)
160 NS_LOG_FUNCTION(
this << satHelper);
165 NS_LOG_FUNCTION(
this);
171 static TypeId tid = TypeId(
"ns3::SatStatsFeederPacketCollisionHelper")
179 NS_LOG_FUNCTION(
this);
185 <<
" is not a valid output type for this statistics.");
195 "EnableContextPrinting",
203 EnumValue(ScalarCollector::INPUT_DATA_TYPE_BOOLEAN));
206 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
210 &MultiFileAggregator::Write1d);
226 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
229 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
233 &MultiFileAggregator::Write2d);
236 &MultiFileAggregator::AddContextHeading);
244 <<
" is not a valid output type for this statistics.");
250 <<
" is not a valid output type for this statistics.");
260 Ptr<MagisterGnuplotAggregator> plotAggregator =
262 NS_ASSERT(plotAggregator !=
nullptr);
264 plotAggregator->SetLegend(
"Time (in seconds)",
"Packet collision rate");
265 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
271 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
274 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
280 const std::string context = it->second->GetName();
281 plotAggregator->Add2dDataset(context, context);
285 &MagisterGnuplotAggregator::Write2d);
293 <<
" is not a valid output type for this statistics.");
297 NS_FATAL_ERROR(
"SatStatsUserPacketCollisionHelper - Invalid output type");
302 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
303 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
310 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
311 Callback<void, uint32_t, const Address&, bool> callback =
314 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
318 for (NetDeviceContainer::Iterator itDev = devs.Begin(); itDev != devs.End(); ++itDev)
320 Ptr<SatNetDevice> satDev = (*itDev)->GetObject<
SatNetDevice>();
321 NS_ASSERT(satDev !=
nullptr);
322 Ptr<SatPhy> satPhy = satDev->GetPhy();
323 NS_ASSERT(satPhy !=
nullptr);
324 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
325 NS_ASSERT(satPhyRx !=
nullptr);
326 ObjectVectorValue carriers;
327 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
328 NS_LOG_DEBUG(
this <<
" Node ID " << (*it)->GetId() <<
" device #"
329 << (*itDev)->GetIfIndex() <<
" has " << carriers.GetN()
332 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin();
333 itCarrier != carriers.End();
337 DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType();
347 NS_LOG_INFO(
this <<
" successfully connected with node ID " << (*it)->GetId()
348 <<
" device #" << (*itDev)->GetIfIndex() <<
" RX carrier #"
349 << itCarrier->first);
353 NS_FATAL_ERROR(
"Error connecting to "
355 <<
" of SatPhyRxCarrier" <<
" at node ID " << (*it)->GetId()
356 <<
" device #" << (*itDev)->GetIfIndex() <<
" RX carrier #"
357 << itCarrier->first);
375 NS_LOG_FUNCTION(
this << satHelper);
380 NS_LOG_FUNCTION(
this);
394 NS_LOG_FUNCTION(
this);
400 <<
" is not a valid output type for this statistics.");
410 "EnableContextPrinting",
418 EnumValue(ScalarCollector::INPUT_DATA_TYPE_BOOLEAN));
421 EnumValue(ScalarCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
425 &MultiFileAggregator::Write1d);
441 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
444 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
448 &MultiFileAggregator::Write2d);
451 &MultiFileAggregator::AddContextHeading);
459 <<
" is not a valid output type for this statistics.");
465 <<
" is not a valid output type for this statistics.");
475 Ptr<MagisterGnuplotAggregator> plotAggregator =
477 NS_ASSERT(plotAggregator !=
nullptr);
479 plotAggregator->SetLegend(
"Time (in seconds)",
"Packet collision rate");
480 plotAggregator->Set2dDatasetDefaultStyle(Gnuplot2dDataset::LINES);
486 EnumValue(IntervalRateCollector::INPUT_DATA_TYPE_BOOLEAN));
489 EnumValue(IntervalRateCollector::OUTPUT_TYPE_AVERAGE_PER_SAMPLE));
495 const std::string context = it->second->GetName();
496 plotAggregator->Add2dDataset(context, context);
500 &MagisterGnuplotAggregator::Write2d);
508 <<
" is not a valid output type for this statistics.");
512 NS_FATAL_ERROR(
"SatStatsFeederPacketCollisionHelper - Invalid output type");
517 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
518 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
525 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
526 Callback<void, uint32_t, const Address&, bool> callback =
529 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
535 NS_ASSERT(satOrbiterDev !=
nullptr);
536 std::map<uint32_t, Ptr<SatPhy>> satOrbiterUserPhys = satOrbiterDev->GetUserPhy();
537 for (std::map<uint32_t, Ptr<SatPhy>>::iterator itPhy = satOrbiterUserPhys.begin();
538 itPhy != satOrbiterUserPhys.end();
541 satPhy = itPhy->second;
542 NS_ASSERT(satPhy !=
nullptr);
543 Ptr<SatPhyRx> satPhyRx = satPhy->GetPhyRx();
544 NS_ASSERT(satPhyRx !=
nullptr);
546 ObjectVectorValue carriers;
547 satPhyRx->GetAttribute(
"RxCarrierList", carriers);
548 NS_LOG_DEBUG(
this <<
" Node ID " << (*it)->GetId() <<
" device #" << dev->GetIfIndex()
549 <<
" has " << carriers.GetN() <<
" RX carriers");
551 for (ObjectVectorValue::Iterator itCarrier = carriers.Begin();
552 itCarrier != carriers.End();
556 DynamicCast<SatPhyRxCarrier>(itCarrier->second)->GetCarrierType();
566 NS_LOG_INFO(
this <<
" successfully connected with node ID " << (*it)->GetId()
567 <<
" device #" << dev->GetIfIndex() <<
" RX carrier #"
568 << itCarrier->first);
573 <<
" of SatPhyRxCarrier" <<
" at node ID "
574 << (*it)->GetId() <<
" device #"
575 << dev->GetIfIndex() <<
" RX carrier #"
576 << itCarrier->first);
592 Ptr<const SatHelper> satHelper)
595 NS_LOG_FUNCTION(
this << satHelper);
602 NS_LOG_FUNCTION(
this);
608 static TypeId tid = TypeId(
"ns3::SatStatsFeederSlottedAlohaPacketCollisionHelper")
618 Ptr<const SatHelper> satHelper)
621 NS_LOG_FUNCTION(
this << satHelper);
628 NS_LOG_FUNCTION(
this);
634 static TypeId tid = TypeId(
"ns3::SatStatsFeederCrdsaPacketCollisionHelper")
644 Ptr<const SatHelper> satHelper)
647 NS_LOG_FUNCTION(
this << satHelper);
654 NS_LOG_FUNCTION(
this);
660 static TypeId tid = TypeId(
"ns3::SatStatsFeederEssaPacketCollisionHelper")
670 Ptr<const SatHelper> satHelper)
673 NS_LOG_FUNCTION(
this << satHelper);
680 NS_LOG_FUNCTION(
this);
686 static TypeId tid = TypeId(
"ns3::SatStatsUserSlottedAlohaPacketCollisionHelper")
696 Ptr<const SatHelper> satHelper)
699 NS_LOG_FUNCTION(
this << satHelper);
706 NS_LOG_FUNCTION(
this);
712 static TypeId tid = TypeId(
"ns3::SatStatsUserCrdsaPacketCollisionHelper")
722 Ptr<const SatHelper> satHelper)
725 NS_LOG_FUNCTION(
this << satHelper);
732 NS_LOG_FUNCTION(
this);
738 static TypeId tid = TypeId(
"ns3::SatStatsUserEssaPacketCollisionHelper")
SatNetDevice to be utilized in the UT and GW nodes.
SatOrbiterNetDevice to be utilized in geostationary satellite.
CarrierType
Possible carrier types.
Produce packet collision statistics of Random Access CRDSA from a satellite module simulation.
virtual ~SatStatsFeederCrdsaPacketCollisionHelper()
/ Destructor.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFeederCrdsaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
Produce packet collision statistics of Random Access E-SSA from a satellite module simulation.
static TypeId GetTypeId()
inherited from ObjectBase base class
SatStatsFeederEssaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
virtual ~SatStatsFeederEssaPacketCollisionHelper()
/ Destructor.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
virtual ~SatStatsFeederPacketCollisionHelper()
/ Destructor.
static TypeId GetTypeId()
inherited from ObjectBase base class
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
SatStatsFeederPacketCollisionHelper(Ptr< const SatHelper > satHelper)
Produce packet collision statistics of Random Access Slotted ALOHA from a satellite module simulation...
virtual ~SatStatsFeederSlottedAlohaPacketCollisionHelper()
/ Destructor.
SatStatsFeederSlottedAlohaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
static Ptr< NetDevice > GetSatSatOrbiterNetDevice(Ptr< Node > satNode)
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 CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
OutputType_t GetOutputType() 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
void CollisionRxCallback(uint32_t nPackets, const Address &from, bool isCollided)
Receive inputs from trace sources and determine the right collector to forward the inputs to.
void SetTraceSourceName(std::string traceSourceName)
void SetValidCarrierType(SatPhyRxCarrier::CarrierType carrierType)
Set valid carrier type for this statistics helper type.
virtual ~SatStatsPacketCollisionHelper()
/ Destructor.
SatStatsPacketCollisionHelper(Ptr< const SatHelper > satHelper)
std::string m_traceSourceName
SatPhyRxCarrier::CarrierType GetValidCarrierType() const
Get the valid carrier type.
CollectorMap m_terminalCollectors
Maintains a list of collectors created by this helper.
std::string GetTraceSourceName() const
static TypeId GetTypeId()
inherited from ObjectBase base class
Produce packet collision statistics of Random Access CRDSA from a satellite module simulation.
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsUserCrdsaPacketCollisionHelper()
/ Destructor.
SatStatsUserCrdsaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
Produce packet collision statistics of Random Access E-SSA from a satellite module simulation.
SatStatsUserEssaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsUserEssaPacketCollisionHelper()
/ Destructor.
SatStatsUserPacketCollisionHelper(Ptr< const SatHelper > satHelper)
void DoInstall()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
virtual ~SatStatsUserPacketCollisionHelper()
/ Destructor.
Ptr< DataCollectionObject > m_aggregator
The aggregator created by this helper.
static TypeId GetTypeId()
inherited from ObjectBase base class
Produce packet collision statistics of Random Access Slotted ALOHA from a satellite module simulation...
static TypeId GetTypeId()
inherited from ObjectBase base class
virtual ~SatStatsUserSlottedAlohaPacketCollisionHelper()
/ Destructor.
SatStatsUserSlottedAlohaPacketCollisionHelper(Ptr< const SatHelper > satHelper)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.