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 
22 #include "satellite-stats-helper.h"
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-geo-net-device.h>
36 #include <ns3/satellite-helper.h>
37 #include <ns3/satellite-id-mapper.h>
38 #include <ns3/satellite-user-helper.h>
39 #include <ns3/singleton.h>
40 #include <ns3/string.h>
41 #include <ns3/type-id.h>
42 
43 #include <sstream>
44 
45 NS_LOG_COMPONENT_DEFINE("SatStatsHelper");
46 
47 namespace ns3
48 {
49 
50 NS_OBJECT_ENSURE_REGISTERED(SatStatsHelper);
51 
52 std::string // static
54 {
55  switch (identifierType)
56  {
58  return "IDENTIFIER_GLOBAL";
60  return "IDENTIFIER_GW";
62  return "IDENTIFIER_BEAM";
64  return "IDENTIFIER_UT";
66  return "IDENTIFIER_UT_USER";
68  return "IDENTIFIER_SLICE";
70  return "IDENTIFIER_GROUP";
72  return "IDENTIFIER_SAT";
74  return "IDENTIFIER_ISL";
75  default:
76  NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
77  break;
78  }
79 
80  NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
81  return "";
82 }
83 
84 std::string // static
86 {
87  switch (outputType)
88  {
90  return "OUTPUT_NONE";
92  return "OUTPUT_SCALAR_FILE";
94  return "OUTPUT_SCATTER_FILE";
96  return "OUTPUT_HISTOGRAM_FILE";
98  return "OUTPUT_PDF_FILE";
100  return "OUTPUT_CDF_FILE";
102  return "OUTPUT_SCALAR_PLOT";
104  return "OUTPUT_SCATTER_PLOT";
106  return "OUTPUT_HISTOGRAM_PLOT";
108  return "OUTPUT_PDF_PLOT";
110  return "OUTPUT_CDF_PLOT";
111  default:
112  NS_FATAL_ERROR("SatStatsHelper - Invalid output type");
113  break;
114  }
115 
116  NS_FATAL_ERROR("SatStatsHelper - Invalid output type");
117  return "";
118 }
119 
120 SatStatsHelper::SatStatsHelper(Ptr<const SatHelper> satHelper)
121  : m_name("stat"),
122  m_identifierType(SatStatsHelper::IDENTIFIER_GLOBAL),
123  m_outputType(SatStatsHelper::OUTPUT_SCATTER_FILE),
124  m_isInstalled(false),
125  m_satHelper(satHelper)
126 {
127  NS_LOG_FUNCTION(this << satHelper);
128 }
129 
131 {
132  NS_LOG_FUNCTION(this);
133 }
134 
135 TypeId // static
137 {
138  static TypeId tid =
139  TypeId("ns3::SatStatsHelper")
140  .SetParent<Object>()
141  .AddAttribute("Name",
142  "String to be prepended on every output file name.",
143  StringValue("stat"),
144  MakeStringAccessor(&SatStatsHelper::SetName, &SatStatsHelper::GetName),
145  MakeStringChecker())
146  .AddAttribute("IdentifierType",
147  "Determines how the statistics are categorized.",
149  MakeEnumAccessor(&SatStatsHelper::SetIdentifierType,
151  MakeEnumChecker(SatStatsHelper::IDENTIFIER_GLOBAL,
152  "GLOBAL",
154  "GW",
156  "BEAM",
158  "UT",
160  "UT_USER",
162  "SLICE",
164  "GROUP",
166  "SAT",
168  "ISL"))
169  .AddAttribute(
170  "OutputType",
171  "Determines the type and format of the output.",
174  MakeEnumChecker(SatStatsHelper::OUTPUT_NONE,
175  "NONE",
177  "SCALAR_FILE",
179  "SCATTER_FILE",
181  "HISTOGRAM_FILE",
183  "PDF_FILE",
185  "CDF_FILE",
187  "SCATTER_PLOT",
189  "HISTOGRAM_PLOT",
191  "PDF_PLOT",
193  "CDF_PLOT"));
194  return tid;
195 }
196 
197 void
199 {
200  NS_LOG_FUNCTION(this);
201 
203  {
204  NS_LOG_WARN(this << " Skipping statistics installation"
205  << " because OUTPUT_NONE output type is selected.");
206  }
207  else
208  {
209  DoInstall(); // this method is supposed to be implemented by the child class
210  m_isInstalled = true;
211  }
212 }
213 
214 void
215 SatStatsHelper::SetName(std::string name)
216 {
217  NS_LOG_FUNCTION(this << name);
218 
219  // convert all spaces and slashes in the name to underscores
220  for (size_t pos = name.find_first_of(" /"); pos != std::string::npos;
221  pos = name.find_first_of(" /", pos + 1, 1))
222  {
223  name[pos] = '_';
224  }
225 
226  m_name = name;
227 }
228 
229 std::string
231 {
232  return m_name;
233 }
234 
235 void
237 {
238  NS_LOG_FUNCTION(this << GetIdentifierTypeName(identifierType));
239 
240  if (m_isInstalled && (m_identifierType != identifierType))
241  {
242  NS_LOG_WARN(this << " cannot modify the current identifier type"
243  << " (" << GetIdentifierTypeName(m_identifierType) << ")"
244  << " because this instance have already been installed");
245  }
246  else
247  {
248  m_identifierType = identifierType;
249  }
250 }
251 
254 {
255  return m_identifierType;
256 }
257 
258 void
260 {
261  NS_LOG_FUNCTION(this << GetOutputTypeName(outputType));
262 
263  if (m_isInstalled && (m_outputType != outputType))
264  {
265  NS_LOG_WARN(this << " cannot modify the current output type"
266  << " (" << GetIdentifierTypeName(m_identifierType) << ")"
267  << " because this instance have already been installed");
268  }
269  else
270  {
271  m_outputType = outputType;
272  }
273 }
274 
277 {
278  return m_outputType;
279 }
280 
281 bool
283 {
284  return m_isInstalled;
285 }
286 
287 Ptr<const SatHelper>
289 {
290  return m_satHelper;
291 }
292 
293 Ptr<DataCollectionObject>
294 SatStatsHelper::CreateAggregator(std::string aggregatorTypeId,
295  std::string n1,
296  const AttributeValue& v1,
297  std::string n2,
298  const AttributeValue& v2,
299  std::string n3,
300  const AttributeValue& v3,
301  std::string n4,
302  const AttributeValue& v4,
303  std::string n5,
304  const AttributeValue& v5)
305 {
306  NS_LOG_FUNCTION(this << aggregatorTypeId);
307 
308  TypeId tid = TypeId::LookupByName(aggregatorTypeId);
309  ObjectFactory factory;
310  factory.SetTypeId(tid);
311  factory.Set(n1, v1);
312  factory.Set(n2, v2);
313  factory.Set(n3, v3);
314  factory.Set(n4, v4);
315  factory.Set(n5, v5);
316  return factory.Create()->GetObject<DataCollectionObject>();
317 }
318 
319 uint32_t
320 SatStatsHelper::CreateCollectorPerIdentifier(CollectorMap& collectorMap) const
321 {
322  NS_LOG_FUNCTION(this);
323  uint32_t n = 0;
324 
325  switch (GetIdentifierType())
326  {
328  collectorMap.SetAttribute("Name", StringValue("0"));
329  collectorMap.Create(0);
330  n++;
331  break;
332  }
333 
335  NodeContainer gws = m_satHelper->GetBeamHelper()->GetGwNodes();
336  for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); ++it)
337  {
338  const uint32_t gwId = GetGwId(*it);
339  std::ostringstream name;
340  name << gwId;
341  collectorMap.SetAttribute("Name", StringValue(name.str()));
342  collectorMap.Create(gwId);
343  n++;
344  }
345  break;
346  }
347 
349  std::list<std::pair<uint32_t, uint32_t>> beams = m_satHelper->GetBeamHelper()->GetBeams();
350  for (std::list<std::pair<uint32_t, uint32_t>>::const_iterator it = beams.begin();
351  it != beams.end();
352  ++it)
353  {
354  const uint32_t satId = (it->first);
355  const uint32_t beamId = (it->second);
356  std::ostringstream name;
357  name << (satId + 1) << "-" << beamId;
358  collectorMap.SetAttribute("Name", StringValue(name.str()));
359  collectorMap.Create(SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) + beamId);
360  n++;
361  }
362  break;
363  }
364 
366  std::list<uint32_t> groups = m_satHelper->GetGroupHelper()->GetGroups();
367  groups.push_back(0);
368  for (std::list<uint32_t>::const_iterator it = groups.begin(); it != groups.end(); ++it)
369  {
370  const uint32_t groupId = (*it);
371  std::ostringstream name;
372  name << groupId;
373  collectorMap.SetAttribute("Name", StringValue(name.str()));
374  collectorMap.Create(groupId);
375  n++;
376  }
377  break;
378  }
379 
381  NodeContainer uts = m_satHelper->GetBeamHelper()->GetUtNodes();
382  for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); ++it)
383  {
384  const uint32_t utId = GetUtId(*it);
385  std::ostringstream name;
386  name << utId;
387  collectorMap.SetAttribute("Name", StringValue(name.str()));
388  collectorMap.Create(utId);
389  n++;
390  }
391  break;
392  }
393 
395  NodeContainer utUsers = m_satHelper->GetUtUsers();
396  for (NodeContainer::Iterator it = utUsers.Begin(); it != utUsers.End(); ++it)
397  {
398  const uint32_t utUserId = GetUtUserId(*it);
399  std::ostringstream name;
400  name << utUserId;
401  collectorMap.SetAttribute("Name", StringValue(name.str()));
402  collectorMap.Create(utUserId);
403  n++;
404  }
405  break;
406  }
407 
409  for (uint32_t sliceId = 0; sliceId < 256; sliceId++)
410  {
411  std::ostringstream name;
412  name << sliceId;
413  collectorMap.SetAttribute("Name", StringValue(name.str()));
414  collectorMap.Create(sliceId);
415  n++;
416  }
417  break;
418  }
419 
421  NodeContainer sats = GetSatHelper()->GetBeamHelper()->GetGeoSatNodes();
422 
423  for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
424  {
425  const uint32_t satId = GetSatId(*it);
426  std::ostringstream name;
427  name << satId;
428  collectorMap.SetAttribute("Name", StringValue(name.str()));
429  collectorMap.Create(satId);
430  n++;
431  }
432  break;
433  }
434 
436  NodeContainer sats = GetSatHelper()->GetBeamHelper()->GetGeoSatNodes();
437 
438  for (NodeContainer::Iterator it = sats.Begin(); it != sats.End(); ++it)
439  {
440  Ptr<SatGeoNetDevice> satGeoNetDevice =
441  DynamicCast<SatGeoNetDevice>(GetSatSatGeoNetDevice(*it));
442  const uint32_t satSrcId = GetSatId(*it);
443  std::vector<Ptr<PointToPointIslNetDevice>> islNetDevices =
444  satGeoNetDevice->GetIslsNetDevices();
445  for (std::vector<Ptr<PointToPointIslNetDevice>>::iterator itIsl = islNetDevices.begin();
446  itIsl != islNetDevices.end();
447  itIsl++)
448  {
449  Ptr<PointToPointIslNetDevice> islNetDevice = *itIsl;
450  const uint32_t satDstId = GetSatId(islNetDevice->GetDestinationNode());
451  std::ostringstream name;
452  name << satSrcId << "-" << satDstId;
453  collectorMap.SetAttribute("Name", StringValue(name.str()));
454  collectorMap.Create(SatConstVariables::MAX_SATELLITES * satSrcId + satDstId);
455  n++;
456  }
457  }
458  break;
459  }
460 
461  default:
462  NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
463  break;
464  }
465 
466  NS_LOG_INFO(this << " created " << n << " instance(s)"
467  << " of " << collectorMap.GetType().GetName() << " for "
469 
470  return n;
471 
472 } // end of `uint32_t CreateCollectorPerIdentifier (CollectorMap &);`
473 
474 std::string
476 {
477  return Singleton<SatEnvVariables>::Get()->GetOutputPath();
478 }
479 
480 std::string
482 {
483  return GetOutputPath() + "/" + GetName();
484 }
485 
486 std::string
487 SatStatsHelper::GetIdentifierHeading(std::string dataLabel) const
488 {
489  switch (GetIdentifierType())
490  {
492  return "% global " + dataLabel;
493 
495  return "% gw_id " + dataLabel;
496 
498  return "% beam_id " + dataLabel;
499 
501  return "% group_id " + dataLabel;
502 
504  return "% ut_id " + dataLabel;
505 
507  return "% ut_user_id " + dataLabel;
508 
510  return "% slice_id " + dataLabel;
511 
513  return "% sat_id " + dataLabel;
514 
516  return "% isl_id " + dataLabel;
517 
518  default:
519  NS_FATAL_ERROR("SatStatsHelper - Invalid identifier type");
520  break;
521  }
522  return "";
523 }
524 
525 std::string
526 SatStatsHelper::GetTimeHeading(std::string dataLabel) const
527 {
528  return "% time_sec " + dataLabel;
529 }
530 
531 std::string
532 SatStatsHelper::GetDistributionHeading(std::string dataLabel) const
533 {
534  return "% " + dataLabel + " freq";
535 }
536 
537 // IDENTIFIER RELATED METHODS /////////////////////////////////////////////////
538 
539 uint32_t
540 SatStatsHelper::GetUtUserId(Ptr<Node> utUserNode) const
541 {
542  uint32_t ret = 0;
543  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
544  const Address addr = satIdMapper->GetUtUserMacWithNode(utUserNode);
545 
546  if (addr.IsInvalid())
547  {
548  NS_LOG_WARN(this << " Node " << utUserNode->GetId()
549  << " does not have any valid Mac48Address");
550  }
551  else
552  {
553  const int32_t utUserId = satIdMapper->GetUtUserIdWithMac(addr);
554 
555  if (utUserId < 0)
556  {
557  NS_LOG_WARN(this << " Node " << utUserNode->GetId()
558  << " is not found in the global list of UT users");
559  }
560  else
561  {
562  ret = utUserId;
563  }
564  }
565 
566  return ret;
567 }
568 
569 uint32_t
570 SatStatsHelper::GetUtId(Ptr<Node> utNode) const
571 {
572  uint32_t ret = 0;
573  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
574  const Address addr = satIdMapper->GetUtMacWithNode(utNode);
575 
576  if (addr.IsInvalid())
577  {
578  NS_LOG_WARN(this << " Node " << utNode->GetId() << " does not have any valid Mac48Address");
579  }
580  else
581  {
582  const int32_t utId = satIdMapper->GetUtIdWithMac(addr);
583 
584  if (utId < 0)
585  {
586  NS_LOG_WARN(this << " Node " << utNode->GetId()
587  << " is not found in the global list of UTs");
588  }
589  else
590  {
591  ret = utId;
592  }
593  }
594 
595  return ret;
596 }
597 
598 uint32_t
599 SatStatsHelper::GetGwId(Ptr<Node> gwNode) const
600 {
601  uint32_t ret = 0;
602  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
603  const Address addr = satIdMapper->GetGwMacWithNode(gwNode);
604 
605  if (addr.IsInvalid())
606  {
607  NS_LOG_WARN(this << " Node " << gwNode->GetId() << " does not have any valid Mac48Address");
608  }
609  else
610  {
611  const int32_t gwId = satIdMapper->GetGwIdWithMac(addr);
612 
613  if (gwId < 0)
614  {
615  NS_LOG_WARN(this << " Node " << gwNode->GetId()
616  << " is not found in the global list of GWs");
617  }
618  else
619  {
620  ret = gwId;
621  }
622  }
623 
624  return ret;
625 }
626 
627 uint32_t
628 SatStatsHelper::GetSatId(Ptr<Node> satNode) const
629 {
630  uint32_t ret = 0;
631  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
632  const Address addr = satIdMapper->GetSatMacWithNode(satNode);
633 
634  if (addr.IsInvalid())
635  {
636  NS_LOG_WARN(this << " Node " << satNode->GetId()
637  << " does not have any valid Mac48Address");
638  }
639  else
640  {
641  const int32_t satId = satIdMapper->GetSatIdWithMac(addr);
642 
643  if (satId < 0)
644  {
645  NS_LOG_WARN(this << " Node " << satNode->GetId()
646  << " is not found in the global list of SATs");
647  }
648  else
649  {
650  ret = satId;
651  }
652  }
653 
654  return ret;
655 }
656 
657 uint32_t
658 SatStatsHelper::GetIdentifierForUtUser(Ptr<Node> utUserNode) const
659 {
660  uint32_t ret = 0;
661 
662  switch (m_identifierType)
663  {
665  ret = 0;
666  break;
667 
669  Ptr<Node> utNode = m_satHelper->GetUserHelper()->GetUtNode(utUserNode);
670 
671  if (utNode == nullptr)
672  {
673  NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
674  << " is not attached to any UT node");
675  }
676  else
677  {
678  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
679  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
680 
681  if (!utMac.IsInvalid())
682  {
683  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
684  const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
685  NS_ASSERT_MSG(satId != -1,
686  "UT user node " << utUserNode->GetId()
687  << " is not attached to any sat");
688  NS_ASSERT_MSG(beamId != -1,
689  "UT user node " << utUserNode->GetId()
690  << " is not attached to any beam");
691  const uint32_t gwId = m_satHelper->GetBeamHelper()->GetGwId(satId - 1, beamId);
692  NS_ASSERT_MSG(gwId != 0,
693  "UT user node " << utUserNode->GetId()
694  << " is not attached to any GW");
695  ret = gwId;
696  }
697  }
698 
699  break;
700  }
701 
703  Ptr<Node> utNode = m_satHelper->GetUserHelper()->GetUtNode(utUserNode);
704 
705  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
706  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
707 
708  if (!utMac.IsInvalid())
709  {
710  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
711  NS_ASSERT_MSG(satId != -1,
712  "UT node " << utNode->GetId() << " is not attached to any sat");
713  ret = satId;
714  }
715 
716  break;
717  }
718 
720  Ptr<Node> utNode = m_satHelper->GetUserHelper()->GetUtNode(utUserNode);
721 
722  if (utNode == nullptr)
723  {
724  NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
725  << " is not attached to any UT node");
726  }
727  else
728  {
729  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
730  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
731 
732  if (!utMac.IsInvalid())
733  {
734  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
735  const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
736  NS_ASSERT_MSG(satId != -1,
737  "UT user node " << utUserNode->GetId()
738  << " is not attached to any sat");
739  NS_ASSERT_MSG(beamId != -1,
740  "UT user node " << utUserNode->GetId()
741  << " is not attached to any beam");
742  ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * satId + beamId;
743  }
744  }
745 
746  break;
747  }
748 
750  Ptr<Node> utNode = m_satHelper->GetUserHelper()->GetUtNode(utUserNode);
751 
752  if (utNode == nullptr)
753  {
754  NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
755  << " is not attached to any UT node");
756  }
757  else
758  {
759  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
760  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
761 
762  if (!utMac.IsInvalid())
763  {
764  const int32_t groupId = satIdMapper->GetGroupIdWithMac(utMac);
765  ret = groupId;
766  }
767  }
768 
769  break;
770  }
771 
773  Ptr<Node> utNode = m_satHelper->GetUserHelper()->GetUtNode(utUserNode);
774 
775  if (utNode == nullptr)
776  {
777  NS_LOG_WARN(this << " UT user node " << utUserNode->GetId()
778  << " is not attached to any UT node");
779  }
780  else
781  {
782  ret = GetUtId(utNode);
783  }
784 
785  break;
786  }
787 
789  ret = GetUtUserId(utUserNode);
790  break;
791 
792  default:
793  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
794  << " is not valid for a UT user."
795  << " Assigning identifier 0 to this UT user.");
796  break;
797  }
798 
799  return ret;
800 }
801 
802 uint32_t
803 SatStatsHelper::GetIdentifierForUt(Ptr<Node> utNode) const
804 {
805  uint32_t ret = 0;
806 
807  switch (m_identifierType)
808  {
810  ret = 0;
811  break;
812 
814  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
815  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
816 
817  if (!utMac.IsInvalid())
818  {
819  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
820  const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
821  NS_ASSERT_MSG(satId != -1,
822  "UT user node " << utNode->GetId() << " is not attached to any sat");
823  NS_ASSERT_MSG(beamId != -1,
824  "UT node " << utNode->GetId() << " is not attached to any beam");
825  const uint32_t gwId = m_satHelper->GetBeamHelper()->GetGwId(satId - 1, beamId);
826  NS_ASSERT_MSG(gwId != 0, "UT node " << utNode->GetId() << " is not attached to any GW");
827  ret = gwId;
828  }
829 
830  break;
831  }
832 
834  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
835  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
836 
837  if (!utMac.IsInvalid())
838  {
839  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
840  NS_ASSERT_MSG(satId != -1,
841  "UT node " << utNode->GetId() << " is not attached to any sat");
842  ret = satId;
843  }
844 
845  break;
846  }
847 
849  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
850  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
851 
852  if (!utMac.IsInvalid())
853  {
854  const int32_t satId = satIdMapper->GetSatIdWithMac(utMac);
855  const int32_t beamId = satIdMapper->GetBeamIdWithMac(utMac);
856  NS_ASSERT_MSG(satId != -1,
857  "UT node " << utNode->GetId() << " is not attached to any sat");
858  NS_ASSERT_MSG(beamId != -1,
859  "UT node " << utNode->GetId() << " is not attached to any beam");
860  ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * satId + beamId;
861  }
862 
863  break;
864  }
865 
867  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
868  const Address utMac = satIdMapper->GetUtMacWithNode(utNode);
869 
870  if (!utMac.IsInvalid())
871  {
872  const int32_t groupId = satIdMapper->GetGroupIdWithMac(utMac);
873  ret = groupId;
874  }
875 
876  break;
877  }
878 
880  ret = GetUtId(utNode);
881  break;
882 
883  default:
884  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
885  << " is not valid for a UT."
886  << " Assigning identifier 0 to this UT.");
887  break;
888  }
889 
890  return ret;
891 }
892 
893 uint32_t
894 SatStatsHelper::GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
895 {
896  uint32_t ret = 0;
897 
898  switch (m_identifierType)
899  {
901  ret = 0;
902  break;
903 
905  const uint32_t gwId = m_satHelper->GetBeamHelper()->GetGwId(satId, beamId);
906  NS_ASSERT_MSG(gwId != 0, "Beam " << beamId << " is not attached to any GW");
907  ret = gwId;
908  break;
909  }
910 
912  ret = satId;
913 
914  break;
915  }
916 
918  ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) + beamId;
919  break;
920 
921  default:
922  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
923  << " is not valid for a beam."
924  << " Assigning identifier 0 to this beam.");
925  break;
926  }
927 
928  return ret;
929 }
930 
931 uint32_t
933 {
934  uint32_t ret = 0;
935 
936  switch (m_identifierType)
937  {
939  ret = 0;
940  break;
941 
943  ret = groupId;
944  break;
945 
946  default:
947  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
948  << " is not valid for a group."
949  << " Assigning identifier 0 to this group.");
950  break;
951  }
952 
953  return ret;
954 }
955 
956 uint32_t
957 SatStatsHelper::GetIdentifierForGw(Ptr<Node> gwNode) const
958 {
960  {
961  return GetGwId(gwNode);
962  }
964  {
965  return 0;
966  }
967  else
968  {
969  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
970  << " is not valid for a GW."
971  << " Assigning identifier 0 to this GW.");
972  return 0;
973  }
974 }
975 
976 uint32_t
977 SatStatsHelper::GetIdentifierForSat(Ptr<Node> satNode) const
978 {
980  {
981  return GetSatId(satNode);
982  }
984  {
985  return 0;
986  }
987  else
988  {
989  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
990  << " is not valid for a SAT."
991  << " Assigning identifier 0 to this SAT.");
992  return 0;
993  }
994 }
995 
996 uint32_t
997 SatStatsHelper::GetIdentifierForIsl(Ptr<Node> satNodeSrc, Ptr<Node> satNodeDst) const
998 {
1000  {
1001  return SatConstVariables::MAX_SATELLITES * GetSatId(satNodeSrc) + GetSatId(satNodeDst);
1002  }
1003  else if (m_identifierType == IDENTIFIER_GLOBAL)
1004  {
1005  return 0;
1006  }
1007  else
1008  {
1009  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
1010  << " is not valid for a ISL."
1011  << " Assigning identifier 0 to this ISL.");
1012  return 0;
1013  }
1014 }
1015 
1016 NetDeviceContainer // static
1018 {
1019  NetDeviceContainer ret;
1020 
1021  NS_LOG_DEBUG("Node ID " << gwNode->GetId() << " has " << gwNode->GetNDevices() << " devices");
1022  /*
1023  * Assuming that device #0 is for loopback device, device #(N-1) is for
1024  * backbone network device, and devices #1 until #(N-2) are for satellite
1025  * beam device. ==> This is true for DVB, but not for Lora: now we keep all
1026  * devices that can be casted to SatNetDevice.
1027  */
1028  for (uint32_t i = 0; i < gwNode->GetNDevices(); i++)
1029  {
1030  Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>(gwNode->GetDevice(i));
1031 
1032  if (dev != nullptr)
1033  {
1034  ret.Add(dev);
1035  }
1036  }
1037 
1038  return ret;
1039 }
1040 
1041 Ptr<NetDevice> // static
1043 {
1044  /*
1045  * Assuming that device #0 is for loopback device, device #1 is for
1046  * subscriber network device, and device #2 is for satellite beam device.
1047  */
1048  NS_ASSERT(utNode->GetNDevices() >= 3);
1049  Ptr<NetDevice> dev = utNode->GetDevice(2);
1050 
1051  if (dev->GetObject<SatNetDevice>() == nullptr)
1052  {
1053  NS_FATAL_ERROR("Node " << utNode->GetId() << " is not a valid UT");
1054  }
1055 
1056  return dev;
1057 }
1058 
1059 Ptr<NetDevice> // static
1061 {
1062  NS_ASSERT(satNode->GetNDevices() > 0);
1063  Ptr<NetDevice> dev = satNode->GetDevice(0);
1064 
1065  if (dev->GetObject<SatGeoNetDevice>() == nullptr)
1066  {
1067  NS_FATAL_ERROR("Node " << satNode->GetId() << " is not a valid SAT");
1068  }
1069 
1070  return dev;
1071 }
1072 
1073 } // end of namespace ns3
SatGeoNetDevice to be utilized in geostationary satellite.
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.
Parent abstract class of all satellite statistics helpers.
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
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)
IdentifierType_t GetIdentifierType() const
virtual ~SatStatsHelper()
/ Destructor.
static std::string GetOutputTypeName(OutputType_t outputType)
SatStatsHelper(Ptr< const SatHelper > satHelper)
Creates a new helper instance.
static Ptr< NetDevice > GetSatSatGeoNetDevice(Ptr< Node > satNode)
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.
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
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.