24 #include <ns3/address.h>
25 #include <ns3/collector-map.h>
26 #include <ns3/data-collection-object.h>
29 #include <ns3/mac48-address.h>
30 #include <ns3/node-container.h>
31 #include <ns3/object-factory.h>
32 #include <ns3/satellite-beam-helper.h>
33 #include <ns3/satellite-const-variables.h>
34 #include <ns3/satellite-env-variables.h>
35 #include <ns3/satellite-helper.h>
36 #include <ns3/satellite-id-mapper.h>
37 #include <ns3/satellite-orbiter-net-device.h>
38 #include <ns3/satellite-topology.h>
39 #include <ns3/satellite-user-helper.h>
40 #include <ns3/singleton.h>
41 #include <ns3/string.h>
42 #include <ns3/type-id.h>
50 NS_LOG_COMPONENT_DEFINE(
"SatStatsHelper");
55 NS_OBJECT_ENSURE_REGISTERED(SatStatsHelper);
60 switch (identifierType)
63 return "IDENTIFIER_GLOBAL";
65 return "IDENTIFIER_GW";
67 return "IDENTIFIER_BEAM";
69 return "IDENTIFIER_UT";
71 return "IDENTIFIER_UT_USER";
73 return "IDENTIFIER_SLICE";
75 return "IDENTIFIER_GROUP";
77 return "IDENTIFIER_SAT";
79 return "IDENTIFIER_ISL";
81 NS_FATAL_ERROR(
"SatStatsHelper - Invalid identifier type");
85 NS_FATAL_ERROR(
"SatStatsHelper - Invalid identifier type");
97 return "OUTPUT_SCALAR_FILE";
99 return "OUTPUT_SCATTER_FILE";
101 return "OUTPUT_HISTOGRAM_FILE";
103 return "OUTPUT_PDF_FILE";
105 return "OUTPUT_CDF_FILE";
107 return "OUTPUT_SCALAR_PLOT";
109 return "OUTPUT_SCATTER_PLOT";
111 return "OUTPUT_HISTOGRAM_PLOT";
113 return "OUTPUT_PDF_PLOT";
115 return "OUTPUT_CDF_PLOT";
117 NS_FATAL_ERROR(
"SatStatsHelper - Invalid output type");
121 NS_FATAL_ERROR(
"SatStatsHelper - Invalid output type");
129 m_isInstalled(false),
130 m_satHelper(satHelper)
132 NS_LOG_FUNCTION(
this << satHelper);
137 NS_LOG_FUNCTION(
this);
144 TypeId(
"ns3::SatStatsHelper")
146 .AddAttribute(
"Name",
147 "String to be prepended on every output file name.",
151 .AddAttribute(
"IdentifierType",
152 "Determines how the statistics are categorized.",
154 MakeEnumAccessor<SatStatsHelper::IdentifierType_t>(
177 "Determines the type and format of the output.",
207 NS_LOG_FUNCTION(
this);
211 NS_LOG_WARN(
this <<
" Skipping statistics installation"
212 <<
" because OUTPUT_NONE output type is selected.");
224 NS_LOG_FUNCTION(
this << name);
227 for (
size_t pos = name.find_first_of(
" /"); pos != std::string::npos;
228 pos = name.find_first_of(
" /", pos + 1, 1))
249 NS_LOG_WARN(
this <<
" cannot modify the current identifier type"
251 <<
" because this instance have already been installed");
272 NS_LOG_WARN(
this <<
" cannot modify the current output type"
274 <<
" because this instance have already been installed");
300 Ptr<DataCollectionObject>
303 const AttributeValue& v1,
305 const AttributeValue& v2,
307 const AttributeValue& v3,
309 const AttributeValue& v4,
311 const AttributeValue& v5)
313 NS_LOG_FUNCTION(
this << aggregatorTypeId);
315 TypeId tid = TypeId::LookupByName(aggregatorTypeId);
316 ObjectFactory factory;
317 factory.SetTypeId(tid);
323 return factory.Create()->GetObject<DataCollectionObject>();
329 NS_LOG_FUNCTION(
this);
335 collectorMap.SetAttribute(
"Name", StringValue(
"0"));
336 collectorMap.Create(0);
342 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
343 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
345 const uint32_t gwId =
GetGwId(*it);
346 std::ostringstream name;
348 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
349 collectorMap.Create(gwId);
356 std::list<std::pair<uint32_t, uint32_t>> beams =
m_satHelper->GetBeamHelper()->GetBeams();
357 for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
361 const uint32_t satId = (it->first);
362 const uint32_t beamId = (it->second);
363 std::ostringstream name;
364 name << (satId + 1) <<
"-" << beamId;
365 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
373 std::list<uint32_t> groups =
m_satHelper->GetGroupHelper()->GetGroups();
375 for (std::list<uint32_t>::const_iterator it = groups.begin(); it != groups.end(); ++it)
377 const uint32_t groupId = (*it);
378 std::ostringstream name;
380 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
381 collectorMap.Create(groupId);
388 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
389 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
391 const uint32_t utId =
GetUtId(*it);
392 std::ostringstream name;
394 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
395 collectorMap.Create(utId);
402 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
403 for (NodeContainer::Iterator it = utUsers.Begin(); it != utUsers.End(); ++it)
406 std::ostringstream name;
408 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
409 collectorMap.Create(utUserId);
416 for (uint32_t sliceId = 0; sliceId < 256; sliceId++)
418 std::ostringstream name;
420 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
421 collectorMap.Create(sliceId);
428 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
430 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
432 const uint32_t satId =
GetSatId(*it);
433 std::ostringstream name;
435 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
436 collectorMap.Create(satId);
443 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
445 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
447 Ptr<SatOrbiterNetDevice> satOrbiterNetDevice =
449 const uint32_t satSrcId =
GetSatId(*it);
450 std::vector<Ptr<PointToPointIslNetDevice>> islNetDevices =
451 satOrbiterNetDevice->GetIslsNetDevices();
452 for (std::vector<Ptr<PointToPointIslNetDevice>>::iterator itIsl = islNetDevices.begin();
453 itIsl != islNetDevices.end();
456 Ptr<PointToPointIslNetDevice> islNetDevice = *itIsl;
457 const uint32_t satDstId =
GetSatId(islNetDevice->GetDestinationNode());
458 std::ostringstream name;
459 name << satSrcId <<
"-" << satDstId;
460 collectorMap.SetAttribute(
"Name", StringValue(name.str()));
469 NS_FATAL_ERROR(
"SatStatsHelper - Invalid identifier type");
473 NS_LOG_INFO(
this <<
" created " << n <<
" instance(s)"
474 <<
" of " << collectorMap.GetType().GetName() <<
" for "
484 return Singleton<SatEnvVariables>::Get()->GetOutputPath();
499 return "% global " + dataLabel;
502 return "% gw_id " + dataLabel;
505 return "% beam_id " + dataLabel;
508 return "% group_id " + dataLabel;
511 return "% ut_id " + dataLabel;
514 return "% ut_user_id " + dataLabel;
517 return "% slice_id " + dataLabel;
520 return "% sat_id " + dataLabel;
523 return "% isl_id " + dataLabel;
526 NS_FATAL_ERROR(
"SatStatsHelper - Invalid identifier type");
535 return "% time_sec " + dataLabel;
541 return "% " + dataLabel +
" freq";
550 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
553 if (addr.IsInvalid())
555 NS_LOG_WARN(
this <<
" Node " << utUserNode->GetId()
556 <<
" does not have any valid Mac48Address");
564 NS_LOG_WARN(
this <<
" Node " << utUserNode->GetId()
565 <<
" is not found in the global list of UT users");
580 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
583 if (addr.IsInvalid())
585 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" does not have any valid Mac48Address");
593 NS_LOG_WARN(
this <<
" Node " << utNode->GetId()
594 <<
" is not found in the global list of UTs");
609 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
612 if (addr.IsInvalid())
614 NS_LOG_WARN(
this <<
" Node " << gwNode->GetId() <<
" does not have any valid Mac48Address");
622 NS_LOG_WARN(
this <<
" Node " << gwNode->GetId()
623 <<
" is not found in the global list of GWs");
638 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
641 if (addr.IsInvalid())
643 NS_LOG_WARN(
this <<
" Node " << satNode->GetId()
644 <<
" does not have any valid Mac48Address");
652 NS_LOG_WARN(
this <<
" Node " << satNode->GetId()
653 <<
" is not found in the global list of SATs");
676 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
678 if (utNode ==
nullptr)
680 NS_LOG_WARN(
this <<
" UT user node " << utUserNode->GetId()
681 <<
" is not attached to any UT node");
685 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
688 if (!utMac.IsInvalid())
692 NS_ASSERT_MSG(satId != -1,
693 "UT user node " << utUserNode->GetId()
694 <<
" is not attached to any sat");
695 NS_ASSERT_MSG(beamId != -1,
696 "UT user node " << utUserNode->GetId()
697 <<
" is not attached to any beam");
698 const uint32_t gwId =
m_satHelper->GetBeamHelper()->GetGwId(satId - 1, beamId);
699 NS_ASSERT_MSG(gwId != 0,
700 "UT user node " << utUserNode->GetId()
701 <<
" is not attached to any GW");
710 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
712 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
715 if (!utMac.IsInvalid())
718 NS_ASSERT_MSG(satId != -1,
719 "UT node " << utNode->GetId() <<
" is not attached to any sat");
727 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
729 if (utNode ==
nullptr)
731 NS_LOG_WARN(
this <<
" UT user node " << utUserNode->GetId()
732 <<
" is not attached to any UT node");
736 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
739 if (!utMac.IsInvalid())
743 NS_ASSERT_MSG(satId != -1,
744 "UT user node " << utUserNode->GetId()
745 <<
" is not attached to any sat");
746 NS_ASSERT_MSG(beamId != -1,
747 "UT user node " << utUserNode->GetId()
748 <<
" is not attached to any beam");
757 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
759 if (utNode ==
nullptr)
761 NS_LOG_WARN(
this <<
" UT user node " << utUserNode->GetId()
762 <<
" is not attached to any UT node");
766 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
769 if (!utMac.IsInvalid())
780 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
782 if (utNode ==
nullptr)
784 NS_LOG_WARN(
this <<
" UT user node " << utUserNode->GetId()
785 <<
" is not attached to any UT node");
801 <<
" is not valid for a UT user."
802 <<
" Assigning identifier 0 to this UT user.");
821 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
824 if (!utMac.IsInvalid())
828 NS_ASSERT_MSG(satId != -1,
829 "UT user node " << utNode->GetId() <<
" is not attached to any sat");
830 NS_ASSERT_MSG(beamId != -1,
831 "UT node " << utNode->GetId() <<
" is not attached to any beam");
832 const uint32_t gwId =
m_satHelper->GetBeamHelper()->GetGwId(satId - 1, beamId);
833 NS_ASSERT_MSG(gwId != 0,
"UT node " << utNode->GetId() <<
" is not attached to any GW");
841 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
844 if (!utMac.IsInvalid())
847 NS_ASSERT_MSG(satId != -1,
848 "UT node " << utNode->GetId() <<
" is not attached to any sat");
856 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
859 if (!utMac.IsInvalid())
863 NS_ASSERT_MSG(satId != -1,
864 "UT node " << utNode->GetId() <<
" is not attached to any sat");
865 NS_ASSERT_MSG(beamId != -1,
866 "UT node " << utNode->GetId() <<
" is not attached to any beam");
874 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
877 if (!utMac.IsInvalid())
892 <<
" is not valid for a UT."
893 <<
" Assigning identifier 0 to this UT.");
912 const uint32_t gwId =
m_satHelper->GetBeamHelper()->GetGwId(satId, beamId);
913 NS_ASSERT_MSG(gwId != 0,
"Beam " << beamId <<
" is not attached to any GW");
930 <<
" is not valid for a beam."
931 <<
" Assigning identifier 0 to this beam.");
955 <<
" is not valid for a group."
956 <<
" Assigning identifier 0 to this group.");
977 <<
" is not valid for a GW."
978 <<
" Assigning identifier 0 to this GW.");
997 <<
" is not valid for a SAT."
998 <<
" Assigning identifier 0 to this SAT.");
1017 <<
" is not valid for a ISL."
1018 <<
" Assigning identifier 0 to this ISL.");
1026 NetDeviceContainer ret;
1028 NS_LOG_DEBUG(
"Node ID " << gwNode->GetId() <<
" has " << gwNode->GetNDevices() <<
" devices");
1035 for (uint32_t i = 0; i < gwNode->GetNDevices(); i++)
1037 Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>(gwNode->GetDevice(i));
1055 NS_ASSERT(utNode->GetNDevices() >= 3);
1056 Ptr<NetDevice> dev = utNode->GetDevice(2);
1060 NS_FATAL_ERROR(
"Node " << utNode->GetId() <<
" is not a valid UT");
1069 NS_ASSERT(satNode->GetNDevices() > 0);
1070 Ptr<NetDevice> dev = satNode->GetDevice(0);
1074 NS_FATAL_ERROR(
"Node " << satNode->GetId() <<
" is not a valid SAT");
1083 NS_LOG_FUNCTION(
this << utNode->GetId());
1085 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1088 if (addr.IsInvalid())
1090 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" is not a valid UT");
1096 NS_LOG_INFO(
this <<
" associated address " << addr <<
" with identifier " << identifier);
1103 NS_LOG_FUNCTION(
this << utNode->GetId());
1105 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1108 if (addr.IsInvalid())
1110 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" is not a valid UT");
1116 NS_LOG_INFO(
this <<
" update address " << addr <<
" to identifier " << identifier);
1123 NS_LOG_FUNCTION(
this);
int32_t GetBeamIdWithMac(Address mac) const
Function for getting the beam ID with MAC.
int32_t GetUtUserIdWithMac(Address mac) const
Function for getting the UT user ID with MAC.
int32_t GetSatIdWithMac(Address mac) const
Function for getting the SAT ID with MAC.
Address GetSatMacWithNode(Ptr< Node > satNode) const
int32_t GetGwIdWithMac(Address mac) const
Function for getting the GW ID with MAC.
int32_t GetUtIdWithMac(Address mac) const
Function for getting the UT ID with MAC.
Address GetGwMacWithNode(Ptr< Node > gwNode) const
Address GetUtMacWithNode(Ptr< Node > utNode) const
Address GetUtUserMacWithNode(Ptr< Node > utUserNode) const
int32_t GetGroupIdWithMac(Address mac) const
Function for getting the group ID with MAC.
SatNetDevice to be utilized in the UT and GW nodes.
SatOrbiterNetDevice to be utilized in geostationary satellite.
Parent abstract class of all satellite statistics helpers.
virtual void UpdateIdentifierOnProbes()
Change identifier used on probes, when handovers occur.
Ptr< const SatHelper > m_satHelper
uint32_t GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
uint32_t GetIdentifierForGw(Ptr< Node > gwNode) const
uint32_t GetSatId(Ptr< Node > satNode) const
static Ptr< NetDevice > GetSatSatOrbiterNetDevice(Ptr< Node > satNode)
Ptr< const SatHelper > GetSatHelper() const
uint32_t GetIdentifierForUtUser(Ptr< Node > utUserNode) const
static NetDeviceContainer GetGwSatNetDevice(Ptr< Node > gwNode)
IdentifierType_t m_identifierType
void SetIdentifierType(IdentifierType_t identifierType)
void SetName(std::string name)
virtual void SaveAddressAndIdentifier(Ptr< Node > utNode)
Save the address and the proper identifier from the given UT node.
IdentifierType_t GetIdentifierType() const
virtual ~SatStatsHelper()
/ Destructor.
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
OutputType_t m_outputType
static std::string GetIdentifierTypeName(IdentifierType_t identifierType)
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.
virtual void UpdateAddressAndIdentifier(Ptr< Node > utNode)
Update the address and the proper identifier from the given UT node.
static TypeId GetTypeId()
inherited from ObjectBase base class
uint32_t GetIdentifierForGroup(uint32_t groupId) const
uint32_t GetUtId(Ptr< Node > utNode) const
void SetOutputType(OutputType_t outputType)
uint32_t CreateCollectorPerIdentifier(CollectorMap &collectorMap) const
Create one collector instance for each identifier in the simulation.
virtual void DoInstall()=0
Install the probes, collectors, and aggregators necessary to produce the statistics output.
OutputType_t
Possible types and formats of statistics output.
uint32_t GetIdentifierForSat(Ptr< Node > satNode) const
static Ptr< NetDevice > GetUtSatNetDevice(Ptr< Node > utNode)
void Install()
Install the probes, collectors, and aggregators necessary to produce the statistics output.
uint32_t GetIdentifierForIsl(Ptr< Node > satNodeSrc, Ptr< Node > satNodeDst) const
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.
IdentifierType_t
Possible categorization of statistics output.
uint32_t GetUtUserId(Ptr< Node > utUserNode) const
std::string GetName() const
uint32_t GetGwId(Ptr< Node > gwNode) const
virtual std::string GetTimeHeading(std::string dataLabel) const
virtual std::string GetDistributionHeading(std::string dataLabel) const
constexpr uint32_t MAX_BEAMS_PER_SATELLITE
Maximum number of beams per satellite.
constexpr uint32_t MAX_SATELLITES
Maximum number of satellites in constellation.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.