Loading...
Searching...
No Matches
satellite-stats-helper.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 Magister Solutions
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Budiarto Herman <budiarto.herman@magister.fi>
19 *
20 */
21
23
24#include "ns3/address.h"
25#include "ns3/collector-map.h"
26#include "ns3/data-collection-object.h"
27#include "ns3/enum.h"
28#include "ns3/log.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"
43
44#include <list>
45#include <sstream>
46#include <string>
47#include <utility>
48#include <vector>
49
50NS_LOG_COMPONENT_DEFINE("SatStatsHelper");
51
52namespace ns3
53{
54
55NS_OBJECT_ENSURE_REGISTERED(SatStatsHelper);
56
57std::string // static
59{
60 switch (identifierType)
61 {
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";
80 default:
81 NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
82 break;
83 }
84
85 NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
86 return "";
87}
88
89std::string // static
91{
92 switch (outputType)
93 {
95 return "OUTPUT_NONE";
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";
116 default:
117 NS_FATAL_ERROR("SatStatsHelper - Invalid output type");
118 break;
119 }
120
121 NS_FATAL_ERROR("SatStatsHelper - Invalid output type");
122 return "";
123}
124
125SatStatsHelper::SatStatsHelper(Ptr<const SatHelper> satHelper)
126 : m_name("stat"),
129 m_isInstalled(false),
130 m_satHelper(satHelper)
131{
132 NS_LOG_FUNCTION(this << satHelper);
133}
134
136{
137 NS_LOG_FUNCTION(this);
138}
139
140TypeId // static
142{
143 static TypeId tid =
144 TypeId("ns3::SatStatsHelper")
145 .SetParent<Object>()
146 .AddAttribute("Name",
147 "String to be prepended on every output file name.",
148 StringValue("stat"),
150 MakeStringChecker())
151 .AddAttribute("IdentifierType",
152 "Determines how the statistics are categorized.",
154 MakeEnumAccessor<SatStatsHelper::IdentifierType_t>(
157 MakeEnumChecker(SatStatsHelper::IDENTIFIER_GLOBAL,
158 "GLOBAL",
160 "GW",
162 "BEAM",
164 "UT",
166 "UT_USER",
168 "SLICE",
170 "GROUP",
172 "SAT",
174 "ISL"))
175 .AddAttribute(
176 "OutputType",
177 "Determines the type and format of the output.",
179 MakeEnumAccessor<SatStatsHelper::OutputType_t>(&SatStatsHelper::SetOutputType,
181 MakeEnumChecker(SatStatsHelper::OUTPUT_NONE,
182 "NONE",
184 "SCALAR_FILE",
186 "SCATTER_FILE",
188 "HISTOGRAM_FILE",
190 "PDF_FILE",
192 "CDF_FILE",
194 "SCATTER_PLOT",
196 "HISTOGRAM_PLOT",
198 "PDF_PLOT",
200 "CDF_PLOT"));
201 return tid;
202}
203
204void
206{
207 NS_LOG_FUNCTION(this);
208
210 {
211 NS_LOG_WARN(this << " Skipping statistics installation"
212 << " because OUTPUT_NONE output type is selected.");
213 }
214 else
215 {
216 DoInstall(); // this method is supposed to be implemented by the child class
217 m_isInstalled = true;
218 }
219}
220
221void
222SatStatsHelper::SetName(std::string name)
223{
224 NS_LOG_FUNCTION(this << name);
225
226 // convert all spaces and slashes in the name to underscores
227 for (size_t pos = name.find_first_of(" /"); pos != std::string::npos;
228 pos = name.find_first_of(" /", pos + 1, 1))
229 {
230 name[pos] = '_';
231 }
232
233 m_name = name;
234}
235
236std::string
238{
239 return m_name;
240}
241
242void
244{
245 NS_LOG_FUNCTION(this << GetIdentifierTypeName(identifierType));
246
247 if (m_isInstalled && (m_identifierType != identifierType))
248 {
249 NS_LOG_WARN(this << " cannot modify the current identifier type" << " ("
251 << " because this instance have already been installed");
252 }
253 else
254 {
255 m_identifierType = identifierType;
256 }
257}
258
264
265void
267{
268 NS_LOG_FUNCTION(this << GetOutputTypeName(outputType));
269
270 if (m_isInstalled && (m_outputType != outputType))
271 {
272 NS_LOG_WARN(this << " cannot modify the current output type" << " ("
274 << " because this instance have already been installed");
275 }
276 else
277 {
278 m_outputType = outputType;
279 }
280}
281
284{
285 return m_outputType;
286}
287
288bool
290{
291 return m_isInstalled;
292}
293
294Ptr<const SatHelper>
296{
297 return m_satHelper;
298}
299
300Ptr<DataCollectionObject>
301SatStatsHelper::CreateAggregator(std::string aggregatorTypeId,
302 std::string n1,
303 const AttributeValue& v1,
304 std::string n2,
305 const AttributeValue& v2,
306 std::string n3,
307 const AttributeValue& v3,
308 std::string n4,
309 const AttributeValue& v4,
310 std::string n5,
311 const AttributeValue& v5)
312{
313 NS_LOG_FUNCTION(this << aggregatorTypeId);
314
315 TypeId tid = TypeId::LookupByName(aggregatorTypeId);
316 ObjectFactory factory;
317 factory.SetTypeId(tid);
318 factory.Set(n1, v1);
319 factory.Set(n2, v2);
320 factory.Set(n3, v3);
321 factory.Set(n4, v4);
322 factory.Set(n5, v5);
323 return factory.Create()->GetObject<DataCollectionObject>();
324}
325
326uint32_t
327SatStatsHelper::CreateCollectorPerIdentifier(CollectorMap& collectorMap) const
328{
329 NS_LOG_FUNCTION(this);
330 uint32_t n = 0;
331
332 switch (GetIdentifierType())
333 {
335 collectorMap.SetAttribute("Name", StringValue("0"));
336 collectorMap.Create(0);
337 n++;
338 break;
339 }
340
342 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
343 for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
344 {
345 const uint32_t gwId = GetGwId(*it);
346 std::ostringstream name;
347 name << gwId;
348 collectorMap.SetAttribute("Name", StringValue(name.str()));
349 collectorMap.Create(gwId);
350 n++;
351 }
352 break;
353 }
354
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();
358 it != beams.end();
359 ++it)
360 {
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()));
366 collectorMap.Create(SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) + beamId);
367 n++;
368 }
369 break;
370 }
371
373 std::list<uint32_t> groups = m_satHelper->GetGroupHelper()->GetGroups();
374 groups.push_back(0);
375 for (std::list<uint32_t>::const_iterator it = groups.begin(); it != groups.end(); ++it)
376 {
377 const uint32_t groupId = (*it);
378 std::ostringstream name;
379 name << groupId;
380 collectorMap.SetAttribute("Name", StringValue(name.str()));
381 collectorMap.Create(groupId);
382 n++;
383 }
384 break;
385 }
386
388 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
389 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
390 {
391 const uint32_t utId = GetUtId(*it);
392 std::ostringstream name;
393 name << utId;
394 collectorMap.SetAttribute("Name", StringValue(name.str()));
395 collectorMap.Create(utId);
396 n++;
397 }
398 break;
399 }
400
402 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
403 for (NodeContainer::Iterator it = utUsers.Begin(); it != utUsers.End(); ++it)
404 {
405 const uint32_t utUserId = GetUtUserId(*it);
406 std::ostringstream name;
407 name << utUserId;
408 collectorMap.SetAttribute("Name", StringValue(name.str()));
409 collectorMap.Create(utUserId);
410 n++;
411 }
412 break;
413 }
414
416 for (uint32_t sliceId = 0; sliceId < 256; sliceId++)
417 {
418 std::ostringstream name;
419 name << sliceId;
420 collectorMap.SetAttribute("Name", StringValue(name.str()));
421 collectorMap.Create(sliceId);
422 n++;
423 }
424 break;
425 }
426
428 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
429
430 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
431 {
432 const uint32_t satId = GetSatId(*it);
433 std::ostringstream name;
434 name << satId;
435 collectorMap.SetAttribute("Name", StringValue(name.str()));
436 collectorMap.Create(satId);
437 n++;
438 }
439 break;
440 }
441
443 NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
444
445 for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
446 {
447 Ptr<SatOrbiterNetDevice> satOrbiterNetDevice =
448 DynamicCast<SatOrbiterNetDevice>(GetSatSatOrbiterNetDevice(*it));
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();
454 itIsl++)
455 {
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()));
461 collectorMap.Create(SatConstVariables::MAX_SATELLITES * satSrcId + satDstId);
462 n++;
463 }
464 }
465 break;
466 }
467
468 default:
469 NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
470 break;
471 }
472
473 NS_LOG_INFO(this << " created " << n << " instance(s)" << " of "
474 << collectorMap.GetType().GetName() << " for "
476
477 return n;
478
479} // end of `uint32_t CreateCollectorPerIdentifier (CollectorMap &);`
480
481std::string
483{
484 return SatEnvVariables::GetInstance()->GetOutputPath();
485}
486
487std::string
489{
490 return GetOutputPath() + "/" + GetName();
491}
492
493std::string
494SatStatsHelper::GetIdentifierHeading(std::string dataLabel) const
495{
496 switch (GetIdentifierType())
497 {
499 return "% global " + dataLabel;
500
502 return "% gw_id " + dataLabel;
503
505 return "% beam_id " + dataLabel;
506
508 return "% group_id " + dataLabel;
509
511 return "% ut_id " + dataLabel;
512
514 return "% ut_user_id " + dataLabel;
515
517 return "% slice_id " + dataLabel;
518
520 return "% sat_id " + dataLabel;
521
523 return "% isl_id " + dataLabel;
524
525 default:
526 NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
527 break;
528 }
529 return "";
530}
531
532std::string
533SatStatsHelper::GetTimeHeading(std::string dataLabel) const
534{
535 return "% time_sec " + dataLabel;
536}
537
538std::string
539SatStatsHelper::GetDistributionHeading(std::string dataLabel) const
540{
541 return "% " + dataLabel + " freq";
542}
543
544// IDENTIFIER RELATED METHODS /////////////////////////////////////////////////
545
546uint32_t
547SatStatsHelper::GetUtUserId(Ptr<Node> utUserNode) const
548{
549 uint32_t ret = 0;
550 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
551 const Address addr = satIdMapper->GetUtUserMacWithNode(utUserNode);
552
553 if (addr.IsInvalid())
554 {
555 NS_LOG_WARN(this << " Node " << utUserNode->GetId()
556 << " does not have any valid Mac48Address");
557 }
558 else
559 {
560 const int32_t utUserId = satIdMapper->GetUtUserIdWithMac(addr);
561
562 if (utUserId < 0)
563 {
564 NS_LOG_WARN(this << " Node " << utUserNode->GetId()
565 << " is not found in the global list of UT users");
566 }
567 else
568 {
569 ret = utUserId;
570 }
571 }
572
573 return ret;
574}
575
576uint32_t
577SatStatsHelper::GetUtId(Ptr<Node> utNode) const
578{
579 uint32_t ret = 0;
580 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
581 const Address addr = satIdMapper->GetUtMacWithNode(utNode);
582
583 if (addr.IsInvalid())
584 {
585 NS_LOG_WARN(this << " Node " << utNode->GetId() << " does not have any valid Mac48Address");
586 }
587 else
588 {
589 const int32_t utId = satIdMapper->GetUtIdWithMac(addr);
590
591 if (utId < 0)
592 {
593 NS_LOG_WARN(this << " Node " << utNode->GetId()
594 << " is not found in the global list of UTs");
595 }
596 else
597 {
598 ret = utId;
599 }
600 }
601
602 return ret;
603}
604
605uint32_t
606SatStatsHelper::GetGwId(Ptr<Node> gwNode) const
607{
608 uint32_t ret = 0;
609 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
610 const Address addr = satIdMapper->GetGwMacWithNode(gwNode);
611
612 if (addr.IsInvalid())
613 {
614 NS_LOG_WARN(this << " Node " << gwNode->GetId() << " does not have any valid Mac48Address");
615 }
616 else
617 {
618 const int32_t gwId = satIdMapper->GetGwIdWithMac(addr);
619
620 if (gwId < 0)
621 {
622 NS_LOG_WARN(this << " Node " << gwNode->GetId()
623 << " is not found in the global list of GWs");
624 }
625 else
626 {
627 ret = gwId;
628 }
629 }
630
631 return ret;
632}
633
634uint32_t
635SatStatsHelper::GetSatId(Ptr<Node> satNode) const
636{
637 uint32_t ret = 0;
638 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
639 const Address addr = satIdMapper->GetSatMacWithNode(satNode);
640
641 if (addr.IsInvalid())
642 {
643 NS_LOG_WARN(this << " Node " << satNode->GetId()
644 << " does not have any valid Mac48Address");
645 }
646 else
647 {
648 const int32_t satId = satIdMapper->GetSatIdWithMac(addr);
649
650 if (satId < 0)
651 {
652 NS_LOG_WARN(this << " Node " << satNode->GetId()
653 << " is not found in the global list of SATs");
654 }
655 else
656 {
657 ret = satId;
658 }
659 }
660
661 return ret;
662}
663
664uint32_t
665SatStatsHelper::GetIdentifierForUtUser(Ptr<Node> utUserNode) const
666{
667 uint32_t ret = 0;
668
669 switch (m_identifierType)
670 {
672 ret = 0;
673 break;
674
676 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
677
678 if (utNode == nullptr)
679 {
680 NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
681 << " is not attached to any UT node");
682 }
683 else
684 {
685 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
686 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
687
688 if (!utMac.IsInvalid())
689 {
690 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
691 const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
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");
702 ret = gwId;
703 }
704 }
705
706 break;
707 }
708
710 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
711
712 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
713 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
714
715 if (!utMac.IsInvalid())
716 {
717 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
718 NS_ASSERT_MSG(satId != -1,
719 "UT node " << utNode->GetId() << " is not attached to any sat");
720 ret = satId;
721 }
722
723 break;
724 }
725
727 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
728
729 if (utNode == nullptr)
730 {
731 NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
732 << " is not attached to any UT node");
733 }
734 else
735 {
736 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
737 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
738
739 if (!utMac.IsInvalid())
740 {
741 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
742 const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
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");
749 ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * satId + beamId;
750 }
751 }
752
753 break;
754 }
755
757 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
758
759 if (utNode == nullptr)
760 {
761 NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
762 << " is not attached to any UT node");
763 }
764 else
765 {
766 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
767 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
768
769 if (!utMac.IsInvalid())
770 {
771 const int32_t groupId = satIdMapper->GetGroupIdWithMac(utMac);
772 ret = groupId;
773 }
774 }
775
776 break;
777 }
778
780 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(utUserNode);
781
782 if (utNode == nullptr)
783 {
784 NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
785 << " is not attached to any UT node");
786 }
787 else
788 {
789 ret = GetUtId(utNode);
790 }
791
792 break;
793 }
794
796 ret = GetUtUserId(utUserNode);
797 break;
798
799 default:
800 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
801 << " is not valid for a UT user."
802 << " Assigning identifier 0 to this UT user.");
803 break;
804 }
805
806 return ret;
807}
808
809uint32_t
811{
812 uint32_t ret = 0;
813
814 switch (m_identifierType)
815 {
817 ret = 0;
818 break;
819
821 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
822 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
823
824 if (!utMac.IsInvalid())
825 {
826 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
827 const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
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");
834 ret = gwId;
835 }
836
837 break;
838 }
839
841 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
842 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
843
844 if (!utMac.IsInvalid())
845 {
846 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
847 NS_ASSERT_MSG(satId != -1,
848 "UT node " << utNode->GetId() << " is not attached to any sat");
849 ret = satId;
850 }
851
852 break;
853 }
854
856 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
857 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
858
859 if (!utMac.IsInvalid())
860 {
861 const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
862 const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
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");
867 ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * satId + beamId;
868 }
869
870 break;
871 }
872
874 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
875 const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
876
877 if (!utMac.IsInvalid())
878 {
879 const int32_t groupId = satIdMapper->GetGroupIdWithMac(utMac);
880 ret = groupId;
881 }
882
883 break;
884 }
885
887 ret = GetUtId(utNode);
888 break;
889
890 default:
891 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
892 << " is not valid for a UT." << " Assigning identifier 0 to this UT.");
893 break;
894 }
895
896 return ret;
897}
898
899uint32_t
900SatStatsHelper::GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
901{
902 uint32_t ret = 0;
903
904 switch (m_identifierType)
905 {
907 ret = 0;
908 break;
909
911 const uint32_t gwId = m_satHelper->GetBeamHelper()->GetGwId(satId, beamId);
912 NS_ASSERT_MSG(gwId != 0, "Beam " << beamId << " is not attached to any GW");
913 ret = gwId;
914 break;
915 }
916
918 ret = satId;
919
920 break;
921 }
922
924 ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) + beamId;
925 break;
926
927 default:
928 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
929 << " is not valid for a beam." << " Assigning identifier 0 to this beam.");
930 break;
931 }
932
933 return ret;
934}
935
936uint32_t
938{
939 uint32_t ret = 0;
940
941 switch (m_identifierType)
942 {
944 ret = 0;
945 break;
946
948 ret = groupId;
949 break;
950
951 default:
952 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
953 << " is not valid for a group."
954 << " Assigning identifier 0 to this group.");
955 break;
956 }
957
958 return ret;
959}
960
961uint32_t
963{
965 {
966 return GetGwId(gwNode);
967 }
969 {
970 return 0;
971 }
972 else
973 {
974 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
975 << " is not valid for a GW." << " Assigning identifier 0 to this GW.");
976 return 0;
977 }
978}
979
980uint32_t
982{
984 {
985 return GetSatId(satNode);
986 }
988 {
989 return 0;
990 }
991 else
992 {
993 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
994 << " is not valid for a SAT." << " Assigning identifier 0 to this SAT.");
995 return 0;
996 }
997}
998
999uint32_t
1000SatStatsHelper::GetIdentifierForIsl(Ptr<Node> satNodeSrc, Ptr<Node> satNodeDst) const
1001{
1003 {
1004 return SatConstVariables::MAX_SATELLITES * GetSatId(satNodeSrc) + GetSatId(satNodeDst);
1005 }
1007 {
1008 return 0;
1009 }
1010 else
1011 {
1012 NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
1013 << " is not valid for a ISL." << " Assigning identifier 0 to this ISL.");
1014 return 0;
1015 }
1016}
1017
1018NetDeviceContainer // static
1020{
1021 NetDeviceContainer ret;
1022
1023 NS_LOG_DEBUG("Node ID " << gwNode->GetId() << " has " << gwNode->GetNDevices() << " devices");
1024 /*
1025 * Assuming that device #0 is for loopback device, device #(N-1) is for
1026 * backbone network device, and devices #1 until #(N-2) are for satellite
1027 * beam device. ==> This is true for DVB, but not for Lora: now we keep all
1028 * devices that can be casted to SatNetDevice.
1029 */
1030 for (uint32_t i = 0; i < gwNode->GetNDevices(); i++)
1031 {
1032 Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>(gwNode->GetDevice(i));
1033
1034 if (dev != nullptr)
1035 {
1036 ret.Add(dev);
1037 }
1038 }
1039
1040 return ret;
1041}
1042
1043Ptr<NetDevice> // static
1045{
1046 /*
1047 * Assuming that device #0 is for loopback device, device #1 is for
1048 * subscriber network device, and device #2 is for satellite beam device.
1049 */
1050 NS_ASSERT(utNode->GetNDevices() >= 3);
1051 Ptr<NetDevice> dev = utNode->GetDevice(2);
1052
1053 if (dev->GetObject<SatNetDevice>() == nullptr)
1054 {
1055 NS_FATAL_ERROR("Node " << utNode->GetId() << " is not a valid UT");
1056 }
1057
1058 return dev;
1059}
1060
1061Ptr<NetDevice> // static
1063{
1064 NS_ASSERT(satNode->GetNDevices() > 0);
1065 Ptr<NetDevice> dev = satNode->GetDevice(0);
1066
1067 if (dev->GetObject<SatOrbiterNetDevice>() == nullptr)
1068 {
1069 NS_FATAL_ERROR("Node " << satNode->GetId() << " is not a valid SAT");
1070 }
1071
1072 return dev;
1073}
1074
1075void
1077{
1078 NS_LOG_FUNCTION(this << utNode->GetId());
1079
1080 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1081 const Address addr = satIdMapper->GetUtMacWithNode(utNode);
1082
1083 if (addr.IsInvalid())
1084 {
1085 NS_LOG_WARN(this << " Node " << utNode->GetId() << " is not a valid UT");
1086 }
1087 else
1088 {
1089 const uint32_t identifier = GetIdentifierForUt(utNode);
1090 m_identifierMap[addr] = identifier;
1091 NS_LOG_INFO(this << " associated address " << addr << " with identifier " << identifier);
1092 }
1093}
1094
1095void
1097{
1098 NS_LOG_FUNCTION(this << utNode->GetId());
1099
1100 const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1101 const Address addr = satIdMapper->GetUtMacWithNode(utNode);
1102
1103 if (addr.IsInvalid())
1104 {
1105 NS_LOG_WARN(this << " Node " << utNode->GetId() << " is not a valid UT");
1106 }
1107 else
1108 {
1109 const uint32_t identifier = GetIdentifierForUt(utNode);
1110 m_identifierMap[addr] = identifier;
1111 NS_LOG_INFO(this << " update address " << addr << " to identifier " << identifier);
1112 }
1113}
1114
1115void
1117{
1118 NS_LOG_FUNCTION(this);
1119}
1120
1121} // end of namespace ns3
static Ptr< SatEnvVariables > GetInstance()
Class for ID-mapper.
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
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.