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-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 
50 NS_LOG_COMPONENT_DEFINE("SatStatsHelper");
51 
52 namespace ns3
53 {
54 
55 NS_OBJECT_ENSURE_REGISTERED(SatStatsHelper);
56 
57 std::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 
89 std::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 
125 SatStatsHelper::SatStatsHelper(Ptr<const SatHelper> satHelper)
126  : m_name("stat"),
127  m_identifierType(SatStatsHelper::IDENTIFIER_GLOBAL),
128  m_outputType(SatStatsHelper::OUTPUT_SCATTER_FILE),
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 
140 TypeId // 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"),
149  MakeStringAccessor(&SatStatsHelper::SetName, &SatStatsHelper::GetName),
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 
204 void
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 
221 void
222 SatStatsHelper::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 
236 std::string
238 {
239  return m_name;
240 }
241 
242 void
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"
250  << " (" << GetIdentifierTypeName(m_identifierType) << ")"
251  << " because this instance have already been installed");
252  }
253  else
254  {
255  m_identifierType = identifierType;
256  }
257 }
258 
261 {
262  return m_identifierType;
263 }
264 
265 void
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"
273  << " (" << GetIdentifierTypeName(m_identifierType) << ")"
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 
288 bool
290 {
291  return m_isInstalled;
292 }
293 
294 Ptr<const SatHelper>
296 {
297  return m_satHelper;
298 }
299 
300 Ptr<DataCollectionObject>
301 SatStatsHelper::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 
326 uint32_t
327 SatStatsHelper::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)"
474  << " of " << collectorMap.GetType().GetName() << " for "
476 
477  return n;
478 
479 } // end of `uint32_t CreateCollectorPerIdentifier (CollectorMap &);`
480 
481 std::string
483 {
484  return Singleton<SatEnvVariables>::Get()->GetOutputPath();
485 }
486 
487 std::string
489 {
490  return GetOutputPath() + "/" + GetName();
491 }
492 
493 std::string
494 SatStatsHelper::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 
532 std::string
533 SatStatsHelper::GetTimeHeading(std::string dataLabel) const
534 {
535  return "% time_sec " + dataLabel;
536 }
537 
538 std::string
539 SatStatsHelper::GetDistributionHeading(std::string dataLabel) const
540 {
541  return "% " + dataLabel + " freq";
542 }
543 
544 // IDENTIFIER RELATED METHODS /////////////////////////////////////////////////
545 
546 uint32_t
547 SatStatsHelper::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 
576 uint32_t
577 SatStatsHelper::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 
605 uint32_t
606 SatStatsHelper::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 
634 uint32_t
635 SatStatsHelper::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 
664 uint32_t
665 SatStatsHelper::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 
809 uint32_t
810 SatStatsHelper::GetIdentifierForUt(Ptr<Node> utNode) const
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."
893  << " Assigning identifier 0 to this UT.");
894  break;
895  }
896 
897  return ret;
898 }
899 
900 uint32_t
901 SatStatsHelper::GetIdentifierForBeam(uint32_t satId, uint32_t beamId) const
902 {
903  uint32_t ret = 0;
904 
905  switch (m_identifierType)
906  {
908  ret = 0;
909  break;
910 
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");
914  ret = gwId;
915  break;
916  }
917 
919  ret = satId;
920 
921  break;
922  }
923 
925  ret = SatConstVariables::MAX_BEAMS_PER_SATELLITE * (satId + 1) + beamId;
926  break;
927 
928  default:
929  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
930  << " is not valid for a beam."
931  << " Assigning identifier 0 to this beam.");
932  break;
933  }
934 
935  return ret;
936 }
937 
938 uint32_t
940 {
941  uint32_t ret = 0;
942 
943  switch (m_identifierType)
944  {
946  ret = 0;
947  break;
948 
950  ret = groupId;
951  break;
952 
953  default:
954  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
955  << " is not valid for a group."
956  << " Assigning identifier 0 to this group.");
957  break;
958  }
959 
960  return ret;
961 }
962 
963 uint32_t
964 SatStatsHelper::GetIdentifierForGw(Ptr<Node> gwNode) const
965 {
967  {
968  return GetGwId(gwNode);
969  }
971  {
972  return 0;
973  }
974  else
975  {
976  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
977  << " is not valid for a GW."
978  << " Assigning identifier 0 to this GW.");
979  return 0;
980  }
981 }
982 
983 uint32_t
984 SatStatsHelper::GetIdentifierForSat(Ptr<Node> satNode) const
985 {
987  {
988  return GetSatId(satNode);
989  }
991  {
992  return 0;
993  }
994  else
995  {
996  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
997  << " is not valid for a SAT."
998  << " Assigning identifier 0 to this SAT.");
999  return 0;
1000  }
1001 }
1002 
1003 uint32_t
1004 SatStatsHelper::GetIdentifierForIsl(Ptr<Node> satNodeSrc, Ptr<Node> satNodeDst) const
1005 {
1007  {
1008  return SatConstVariables::MAX_SATELLITES * GetSatId(satNodeSrc) + GetSatId(satNodeDst);
1009  }
1010  else if (m_identifierType == IDENTIFIER_GLOBAL)
1011  {
1012  return 0;
1013  }
1014  else
1015  {
1016  NS_LOG_WARN(this << " Identifier type " << GetIdentifierTypeName(m_identifierType)
1017  << " is not valid for a ISL."
1018  << " Assigning identifier 0 to this ISL.");
1019  return 0;
1020  }
1021 }
1022 
1023 NetDeviceContainer // static
1025 {
1026  NetDeviceContainer ret;
1027 
1028  NS_LOG_DEBUG("Node ID " << gwNode->GetId() << " has " << gwNode->GetNDevices() << " devices");
1029  /*
1030  * Assuming that device #0 is for loopback device, device #(N-1) is for
1031  * backbone network device, and devices #1 until #(N-2) are for satellite
1032  * beam device. ==> This is true for DVB, but not for Lora: now we keep all
1033  * devices that can be casted to SatNetDevice.
1034  */
1035  for (uint32_t i = 0; i < gwNode->GetNDevices(); i++)
1036  {
1037  Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>(gwNode->GetDevice(i));
1038 
1039  if (dev != nullptr)
1040  {
1041  ret.Add(dev);
1042  }
1043  }
1044 
1045  return ret;
1046 }
1047 
1048 Ptr<NetDevice> // static
1050 {
1051  /*
1052  * Assuming that device #0 is for loopback device, device #1 is for
1053  * subscriber network device, and device #2 is for satellite beam device.
1054  */
1055  NS_ASSERT(utNode->GetNDevices() >= 3);
1056  Ptr<NetDevice> dev = utNode->GetDevice(2);
1057 
1058  if (dev->GetObject<SatNetDevice>() == nullptr)
1059  {
1060  NS_FATAL_ERROR("Node " << utNode->GetId() << " is not a valid UT");
1061  }
1062 
1063  return dev;
1064 }
1065 
1066 Ptr<NetDevice> // static
1068 {
1069  NS_ASSERT(satNode->GetNDevices() > 0);
1070  Ptr<NetDevice> dev = satNode->GetDevice(0);
1071 
1072  if (dev->GetObject<SatOrbiterNetDevice>() == nullptr)
1073  {
1074  NS_FATAL_ERROR("Node " << satNode->GetId() << " is not a valid SAT");
1075  }
1076 
1077  return dev;
1078 }
1079 
1080 void
1082 {
1083  NS_LOG_FUNCTION(this << utNode->GetId());
1084 
1085  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1086  const Address addr = satIdMapper->GetUtMacWithNode(utNode);
1087 
1088  if (addr.IsInvalid())
1089  {
1090  NS_LOG_WARN(this << " Node " << utNode->GetId() << " is not a valid UT");
1091  }
1092  else
1093  {
1094  const uint32_t identifier = GetIdentifierForUt(utNode);
1095  m_identifierMap[addr] = identifier;
1096  NS_LOG_INFO(this << " associated address " << addr << " with identifier " << identifier);
1097  }
1098 }
1099 
1100 void
1102 {
1103  NS_LOG_FUNCTION(this << utNode->GetId());
1104 
1105  const SatIdMapper* satIdMapper = Singleton<SatIdMapper>::Get();
1106  const Address addr = satIdMapper->GetUtMacWithNode(utNode);
1107 
1108  if (addr.IsInvalid())
1109  {
1110  NS_LOG_WARN(this << " Node " << utNode->GetId() << " is not a valid UT");
1111  }
1112  else
1113  {
1114  const uint32_t identifier = GetIdentifierForUt(utNode);
1115  m_identifierMap[addr] = identifier;
1116  NS_LOG_INFO(this << " update address " << addr << " to identifier " << identifier);
1117  }
1118 }
1119 
1120 void
1122 {
1123  NS_LOG_FUNCTION(this);
1124 }
1125 
1126 } // end of namespace ns3
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.