satellite-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
21 #include "satellite-helper.h"
22 
23 #include <ns3/arp-cache.h>
24 #include <ns3/csma-helper.h>
25 #include <ns3/double.h>
26 #include <ns3/internet-stack-helper.h>
27 #include <ns3/ipv4-interface.h>
28 #include <ns3/ipv4-routing-table-entry.h>
29 #include <ns3/ipv4-static-routing-helper.h>
30 #include <ns3/log.h>
31 #include <ns3/lora-device-address-generator.h>
32 #include <ns3/lora-forwarder-helper.h>
33 #include <ns3/lora-network-server-helper.h>
34 #include <ns3/mobility-helper.h>
35 #include <ns3/names.h>
36 #include <ns3/queue.h>
37 #include <ns3/satellite-env-variables.h>
38 #include <ns3/satellite-id-mapper.h>
39 #include <ns3/satellite-log.h>
40 #include <ns3/satellite-lora-conf.h>
41 #include <ns3/satellite-point-to-point-isl-net-device.h>
42 #include <ns3/satellite-position-allocator.h>
43 #include <ns3/satellite-rtn-link-time.h>
44 #include <ns3/satellite-sgp4-mobility-model.h>
45 #include <ns3/satellite-traced-mobility-model.h>
46 #include <ns3/satellite-typedefs.h>
47 #include <ns3/satellite-ut-handover-module.h>
48 #include <ns3/singleton.h>
49 #include <ns3/string.h>
50 #include <ns3/system-path.h>
51 #include <ns3/type-id.h>
52 
53 #include <sys/stat.h>
54 
55 NS_LOG_COMPONENT_DEFINE("SatHelper");
56 
57 namespace ns3
58 {
59 
60 NS_OBJECT_ENSURE_REGISTERED(SatHelper);
61 
62 TypeId
64 {
65  static TypeId tid =
66  TypeId("ns3::SatHelper")
67  .SetParent<Object>()
68  .AddConstructor<SatHelper>()
69  .AddAttribute("Standard",
70  "The global standard used. Can be either DVB or Lora",
71  EnumValue(SatEnums::DVB),
72  MakeEnumAccessor(&SatHelper::m_standard),
73  MakeEnumChecker(SatEnums::DVB, "DVB", SatEnums::LORA, "LORA"))
74  .AddAttribute("SatRtnConfFileName",
75  "Name of the satellite network RTN link configuration file.",
76  StringValue("Scenario72RtnConf.txt"),
77  MakeStringAccessor(&SatHelper::m_rtnConfFileName),
78  MakeStringChecker())
79  .AddAttribute("SatFwdConfFileName",
80  "Name of the satellite network FWD link configuration file.",
81  StringValue("Scenario72FwdConf.txt"),
82  MakeStringAccessor(&SatHelper::m_fwdConfFileName),
83  MakeStringChecker())
84  .AddAttribute("GwPosFileName",
85  "Name of the GW positions configuration file.",
86  StringValue("Scenario72GwPos.txt"),
87  MakeStringAccessor(&SatHelper::m_gwPosFileName),
88  MakeStringChecker())
89  .AddAttribute("SatMobilitySGP4Enabled",
90  "The satellite moves following a SGP4 model.",
91  BooleanValue(false),
92  MakeBooleanAccessor(&SatHelper::m_satMobilitySGP4Enabled),
93  MakeBooleanChecker())
94  .AddAttribute("SatMobilitySGP4TleFileName",
95  "TLE input filename used for SGP4 mobility.",
96  StringValue("tle_iss_zarya.txt"),
97  MakeStringAccessor(&SatHelper::m_satMobilitySGP4TleFileName),
98  MakeStringChecker())
99  .AddAttribute("SatConstellationEnabled",
100  "Use a constellation of satellites.",
101  BooleanValue(false),
102  MakeBooleanAccessor(&SatHelper::m_satConstellationEnabled),
103  MakeBooleanChecker())
104  .AddAttribute("SatConstellationFolder",
105  "Folder where are stored satellite constellation data.",
106  StringValue("eutelsat-geo-2-sats"),
107  MakeStringAccessor(&SatHelper::m_satConstellationFolder),
108  MakeStringChecker())
109  .AddAttribute("GeoSatPosFileName",
110  "Name of the geostationary satellite position configuration file.",
111  StringValue("Scenario72GeoPos.txt"),
112  MakeStringAccessor(&SatHelper::m_geoPosFileName),
113  MakeStringChecker())
114  .AddAttribute("RtnLinkWaveformConfFileName",
115  "Name of the RTN link waveform configuration file.",
116  StringValue("dvbRcs2Waveforms.txt"),
117  MakeStringAccessor(&SatHelper::m_waveformConfFileName),
118  MakeStringChecker())
119  .AddAttribute("UtCount",
120  "The count of created UTs in beam (full or user-defined scenario)",
121  UintegerValue(3),
122  MakeUintegerAccessor(&SatHelper::m_utsInBeam),
123  MakeUintegerChecker<uint32_t>(1))
124  .AddAttribute("GwUsers",
125  "The number of created GW users (full or user-defined scenario)",
126  UintegerValue(5),
127  MakeUintegerAccessor(&SatHelper::m_gwUsers),
128  MakeUintegerChecker<uint32_t>(1))
129  .AddAttribute("UtUsers",
130  "The number of created UT users per UT (full or user-defined scenario)",
131  UintegerValue(3),
132  MakeUintegerAccessor(&SatHelper::m_utUsers),
133  MakeUintegerChecker<uint32_t>(1))
134  .AddAttribute(
135  "BeamNetworkAddress",
136  "Initial network number to use "
137  "during allocation of satellite devices "
138  "(mask set by attribute 'BeamNetworkMask' will be used as the network mask)",
139  Ipv4AddressValue("40.1.0.0"),
140  MakeIpv4AddressAccessor(&SatHelper::m_beamNetworkAddress),
141  MakeIpv4AddressChecker())
142  .AddAttribute("BeamNetworkMask",
143  "Network mask to use during allocation of satellite devices.",
144  Ipv4MaskValue("255.255.0.0"),
145  MakeIpv4MaskAccessor(&SatHelper::m_beamNetworkMask),
146  MakeIpv4MaskChecker())
147  .AddAttribute(
148  "GwNetworkAddress",
149  "Initial network number to use "
150  "during allocation of GW, router, and GW users "
151  "(mask set by attribute 'GwNetworkMask' will be used as the network mask)",
152  Ipv4AddressValue("90.1.0.0"),
153  MakeIpv4AddressAccessor(&SatHelper::m_gwNetworkAddress),
154  MakeIpv4AddressChecker())
155  .AddAttribute("GwNetworkMask",
156  "Network mask to use during allocation of GW, router, and GW users.",
157  Ipv4MaskValue("255.255.0.0"),
158  MakeIpv4MaskAccessor(&SatHelper::m_gwNetworkMask),
159  MakeIpv4MaskChecker())
160  .AddAttribute(
161  "UtNetworkAddress",
162  "Initial network number to use "
163  "during allocation of UT and UT users "
164  "(mask set by attribute 'UtNetworkMask' will be used as the network mask)",
165  Ipv4AddressValue("10.1.0.0"),
166  MakeIpv4AddressAccessor(&SatHelper::m_utNetworkAddress),
167  MakeIpv4AddressChecker())
168  .AddAttribute("UtNetworkMask",
169  "Network mask to use during allocation of UT and UT users.",
170  Ipv4MaskValue("255.255.0.0"),
171  MakeIpv4MaskAccessor(&SatHelper::m_utNetworkMask),
172  MakeIpv4MaskChecker())
173  .AddAttribute("PacketTraceEnabled",
174  "Packet tracing enable status.",
175  BooleanValue(false),
176  MakeBooleanAccessor(&SatHelper::m_packetTraces),
177  MakeBooleanChecker())
178  .AddAttribute("ScenarioCreationTraceEnabled",
179  "Scenario creation trace output enable status.",
180  BooleanValue(false),
181  MakeBooleanAccessor(&SatHelper::m_creationTraces),
182  MakeBooleanChecker())
183  .AddAttribute("DetailedScenarioCreationTraceEnabled",
184  "Detailed scenario creation trace output enable status.",
185  BooleanValue(false),
186  MakeBooleanAccessor(&SatHelper::m_detailedCreationTraces),
187  MakeBooleanChecker())
188  .AddAttribute("ScenarioCreationTraceFileName",
189  "File name for the scenario creation trace output",
190  StringValue("CreationTraceScenario"),
191  MakeStringAccessor(&SatHelper::m_scenarioCreationFileName),
192  MakeStringChecker())
193  .AddAttribute("UtCreationTraceFileName",
194  "File name for the UT creation trace output",
195  StringValue("CreationTraceUt"),
196  MakeStringAccessor(&SatHelper::m_utCreationFileName),
197  MakeStringChecker())
198  .AddTraceSource("Creation",
199  "Creation traces",
200  MakeTraceSourceAccessor(&SatHelper::m_creationDetailsTrace),
201  "ns3::SatTypedefs::CreationCallback")
202  .AddTraceSource("CreationSummary",
203  "Creation summary traces",
204  MakeTraceSourceAccessor(&SatHelper::m_creationSummaryTrace),
205  "ns3::SatTypedefs::CreationCallback")
206 
207  ;
208  return tid;
209 }
210 
211 TypeId
213 {
214  NS_LOG_FUNCTION(this);
215 
216  return GetTypeId();
217 }
218 
220  : m_rtnConfFileName("Scenario72RtnConf.txt"),
221  m_fwdConfFileName("Scenario72FwdConf.txt"),
222  m_gwPosFileName("Scenario72GwPos.txt"),
223  m_geoPosFileName("Scenario72GeoPos.txt"),
224  m_waveformConfFileName("dvbRcs2Waveforms.txt"),
225  m_scenarioCreated(false),
226  m_creationTraces(false),
227  m_detailedCreationTraces(false),
228  m_packetTraces(false),
229  m_utsInBeam(0),
230  m_gwUsers(0),
231  m_utUsers(0),
232  m_utPositionsByBeam(),
233  m_mobileUtsByBeam(),
234  m_mobileUtsUsersByBeam()
235 {
236  NS_LOG_FUNCTION(this);
237 
238  // uncomment next line, if attributes are needed already in construction phase
239  ObjectBase::ConstructSelf(AttributeConstructionList());
240 
241  Singleton<SatEnvVariables>::Get()->Initialize();
242  Singleton<SatIdMapper>::Get()->Reset();
243 
244  m_satConf = CreateObject<SatConf>();
245 
246  if (m_standard == SatEnums::LORA)
247  {
248  SatLoraConf satLoraConf;
249  satLoraConf.setSatConfAttributes(m_satConf);
250  }
251 
252  NodeContainer geoNodes;
253  std::vector<std::pair<uint32_t, uint32_t>> isls;
254 
256  {
257  if (m_satConf->GetForwardLinkRegenerationMode() != SatEnums::REGENERATION_NETWORK)
258  {
259  NS_FATAL_ERROR("Forward regeneration must be network when using constellations");
260  }
261  if (m_satConf->GetReturnLinkRegenerationMode() != SatEnums::REGENERATION_NETWORK)
262  {
263  NS_FATAL_ERROR("Return regeneration must be network when using constellations");
264  }
265 
266  std::vector<std::string> tles;
267 
269 
270  m_antennaGainPatterns = CreateObject<SatAntennaGainPatternContainer>(tles.size());
271 
272  for (uint32_t i = 0; i < tles.size(); i++)
273  {
274  // create Geo Satellite node, set mobility to it
275  Ptr<Node> geoSatNode = CreateObject<Node>();
276 
277  SetSatMobility(geoSatNode, tles[i]);
278 
279  Ptr<SatMobilityModel> mobility = geoSatNode->GetObject<SatMobilityModel>();
280  m_antennaGainPatterns->ConfigureBeamsMobility(i, mobility);
281 
282  geoNodes.Add(geoSatNode);
283  }
284  }
285  else
286  {
287  m_antennaGainPatterns = CreateObject<SatAntennaGainPatternContainer>();
288 
289  // In case of constellations, all satellites have the same features, read in same
290  // configuration file
291  m_satConf->Initialize(m_rtnConfFileName,
297 
298  // create Geo Satellite node, set mobility to it
299  Ptr<Node> geoSatNode = CreateObject<Node>();
300 
301  if (m_satMobilitySGP4Enabled == true)
302  {
303  SetSatMobility(geoSatNode);
304  }
305  else
306  {
307  SetGeoSatMobility(geoSatNode);
308  }
309 
310  Ptr<SatMobilityModel> mobility = geoSatNode->GetObject<SatMobilityModel>();
311  m_antennaGainPatterns->ConfigureBeamsMobility(0, mobility);
312 
313  geoNodes.Add(geoSatNode);
314  }
315 
316  m_beamHelper =
317  CreateObject<SatBeamHelper>(geoNodes,
318  isls,
320  m_satConf->GetRtnLinkCarrierCount(),
321  m_satConf->GetFwdLinkCarrierCount(),
322  m_satConf->GetSuperframeSeq(),
323  m_satConf->GetForwardLinkRegenerationMode(),
324  m_satConf->GetReturnLinkRegenerationMode());
325 
326  m_beamHelper->SetAntennaGainPatterns(m_antennaGainPatterns);
327 
328  if (m_satMobilitySGP4Enabled == true &&
329  m_beamHelper->GetPropagationDelayModelEnum() != SatEnums::PD_CONSTANT_SPEED)
330  {
331  NS_FATAL_ERROR(
332  "Must use constant speed propagation delay model if satellite mobility is enabled");
333  }
334 
335  m_beamHelper->SetStandard(m_standard);
336 
337  Ptr<SatRtnLinkTime> rtnTime = Singleton<SatRtnLinkTime>::Get();
338  rtnTime->Initialize(m_satConf->GetSuperframeSeq());
339 
342  m_beamHelper->SetAttribute("CarrierFrequencyConverter", CallbackValue(converterCb));
343 
344  m_userHelper = CreateObject<SatUserHelper>();
347  m_userHelper->SetAttribute("PropagationDelayGetter", CallbackValue(delayModelCb));
348 }
349 
350 void
352 {
353  NS_LOG_FUNCTION(this);
354 
355  switch (scenario)
356  {
357  case SIMPLE:
359  break;
360 
361  case LARGER:
363  break;
364 
365  case FULL:
367  break;
368 
369  default:
370  NS_FATAL_ERROR("Not supported predefined scenario.");
371  break;
372  }
373 }
374 
375 void
377 {
378  NS_LOG_FUNCTION(this);
379 
380  AsciiTraceHelper asciiTraceHelper;
381 
382  std::stringstream outputPathCreation;
383  std::stringstream outputPathUt;
384  outputPathCreation << Singleton<SatEnvVariables>::Get()->GetOutputPath() << "/"
385  << m_scenarioCreationFileName << ".log";
386  outputPathUt << Singleton<SatEnvVariables>::Get()->GetOutputPath() << "/"
387  << m_utCreationFileName << ".log";
388 
389  m_creationTraceStream = asciiTraceHelper.CreateFileStream(outputPathCreation.str());
390  m_utTraceStream = asciiTraceHelper.CreateFileStream(outputPathUt.str());
391 
392  TraceConnectWithoutContext("CreationSummary",
393  MakeCallback(&SatHelper::CreationSummarySink, this));
394 
396  {
398  }
399 }
400 
401 void
403 {
404  m_beamHelper->EnablePacketTrace();
405 }
406 
407 void
409  std::vector<std::string>& tles,
410  std::vector<std::pair<uint32_t, uint32_t>>& isls)
411 {
412  NS_LOG_FUNCTION(this << path);
413 
414  std::string dataPath =
415  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/constellations/" + path;
416 
417  if (!(Singleton<SatEnvVariables>::Get()->IsValidDirectory(dataPath)))
418  {
419  NS_FATAL_ERROR("Directory '" << dataPath
420  << "' does not exist, no constellation can be created.");
421  }
422 
423  m_satConf->SetUtPositionInputFileName("constellations/" + path + "/ut_positions.txt");
424 
425  m_satConf->Initialize(m_rtnConfFileName,
427  "constellations/" + path + "/gw_positions.txt",
431  true);
432 
433  tles = m_satConf->LoadTles(dataPath + "/tles.txt");
434  isls = m_satConf->LoadIsls(dataPath + "/isls.txt");
435 }
436 
437 void
439 {
440  NS_LOG_FUNCTION(this);
441 
442  CallbackBase creationCb =
444  TraceConnect("Creation", "SatHelper", creationCb);
445 
446  m_userHelper->EnableCreationTraces(m_creationTraceStream, creationCb);
447  m_beamHelper->EnableCreationTraces(m_creationTraceStream, creationCb);
448 }
449 
450 uint32_t
452 {
453  NS_LOG_FUNCTION(this);
454 
455  return m_beamHelper->GetClosestSat(position);
456 }
457 
458 Ipv4Address
460 {
461  NS_LOG_FUNCTION(this);
462 
463  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>(); // Get Ipv4 instance of the node
464  return ipv4->GetAddress(1, 0)
465  .GetLocal(); // Get Ipv4InterfaceAddress of interface csma interface.
466 }
467 
468 NodeContainer
470 {
471  NS_LOG_FUNCTION(this);
472 
473  return m_userHelper->GetUtUsers();
474 }
475 
476 NodeContainer
477 SatHelper::GetUtUsers(Ptr<Node> utNode) const
478 {
479  return m_userHelper->GetUtUsers(utNode);
480 }
481 
482 NodeContainer
483 SatHelper::GetUtUsers(NodeContainer utNodes) const
484 {
485  NodeContainer total;
486  for (NodeContainer::Iterator i = utNodes.Begin(); i != utNodes.End(); i++)
487  {
488  total.Add(GetUtUsers(*i));
489  }
490  return total;
491 }
492 
493 NodeContainer
495 {
496  NS_LOG_FUNCTION(this);
497 
498  return m_userHelper->GetGwUsers();
499 }
500 
501 Ptr<SatBeamHelper>
503 {
504  NS_LOG_FUNCTION(this);
505  return m_beamHelper;
506 }
507 
508 Ptr<SatGroupHelper>
510 {
511  NS_LOG_FUNCTION(this);
512  return m_groupHelper;
513 }
514 
515 void
516 SatHelper::SetGroupHelper(Ptr<SatGroupHelper> groupHelper)
517 {
518  NS_LOG_FUNCTION(this << groupHelper);
519  m_groupHelper = groupHelper;
520 }
521 
522 void
523 SatHelper::SetAntennaGainPatterns(Ptr<SatAntennaGainPatternContainer> antennaGainPatterns)
524 {
525  NS_LOG_FUNCTION(this);
526  m_antennaGainPatterns = antennaGainPatterns;
527 }
528 
529 Ptr<SatAntennaGainPatternContainer>
531 {
532  return m_antennaGainPatterns;
533 }
534 
535 Ptr<SatUserHelper>
537 {
538  NS_LOG_FUNCTION(this);
539  return m_userHelper;
540 }
541 
542 uint32_t
544 {
545  NS_LOG_FUNCTION(this);
546 
547  return m_satConf->GetBeamCount();
548 }
549 
550 void
552 {
553  NS_LOG_FUNCTION(this);
554 
555  SatBeamUserInfo beamInfo = SatBeamUserInfo(1, 1);
556  BeamUserInfoMap_t beamUserInfos;
557  beamUserInfos[std::make_pair(0, 8)] = beamInfo;
558 
559  DoCreateScenario(beamUserInfos, 1);
560 
561  m_creationSummaryTrace("*** Simple Scenario Creation Summary ***");
562 }
563 
564 void
566 {
567  NS_LOG_FUNCTION(this);
568 
569  // install one user for UTs in beams 12 and 22
570  SatBeamUserInfo beamInfo = SatBeamUserInfo(1, 1);
571  BeamUserInfoMap_t beamUserInfos;
572 
573  beamUserInfos[std::make_pair(0, 12)] = beamInfo;
574  beamUserInfos[std::make_pair(0, 22)] = beamInfo;
575 
576  // install two users for UT1 and one for UT2 in beam 3
577  beamInfo.SetUtUserCount(0, 2);
578  beamInfo.AppendUt(1);
579 
580  beamUserInfos[std::make_pair(0, 3)] = beamInfo;
581 
582  DoCreateScenario(beamUserInfos, 1);
583 
584  m_creationSummaryTrace("*** Larger Scenario Creation Summary ***");
585 }
586 
587 void
589 {
590  NS_LOG_FUNCTION(this);
591 
592  uint32_t beamCount = m_satConf->GetBeamCount();
593  BeamUserInfoMap_t beamUserInfos;
594 
595  for (uint32_t i = 1; i < (beamCount + 1); i++)
596  {
597  BeamUserInfoMap_t::iterator beamInfo = m_beamUserInfos.find(std::make_pair(0, i));
598  SatBeamUserInfo info;
599 
600  if (beamInfo != m_beamUserInfos.end())
601  {
602  info = beamInfo->second;
603  }
604  else
605  {
606  info = SatBeamUserInfo(m_utsInBeam, this->m_utUsers);
607  }
608 
609  beamUserInfos[std::make_pair(0, i)] = info;
610  }
611 
612  DoCreateScenario(beamUserInfos, m_gwUsers);
613 
614  m_creationSummaryTrace("*** Full Scenario Creation Summary ***");
615 }
616 
617 void
619 {
620  NS_LOG_FUNCTION(this);
621 
622  // create as user wants
623  DoCreateScenario(infos, m_gwUsers);
624 
625  m_creationSummaryTrace("*** User Defined Scenario Creation Summary ***");
626 }
627 
628 void
629 SatHelper::SetCustomUtPositionAllocator(Ptr<SatListPositionAllocator> posAllocator)
630 {
631  NS_LOG_FUNCTION(this);
632  m_utPositions = posAllocator;
633 }
634 
635 void
637  Ptr<SatListPositionAllocator> posAllocator)
638 {
639  NS_LOG_FUNCTION(this << beamId);
640  m_utPositionsByBeam[beamId] = posAllocator;
641 }
642 
643 void
645  BeamUserInfoMap_t& infos,
646  bool checkBeam)
647 {
648  NS_LOG_FUNCTION(this);
649 
650  uint32_t positionIndex = 1;
651 
652  // construct list position allocator and fill it with position
653  // configured through SatConf
654 
655  m_utPositions = CreateObject<SatListPositionAllocator>();
656 
657  for (BeamUserInfoMap_t::iterator it = infos.begin(); it != infos.end(); it++)
658  {
659  for (uint32_t i = 0; i < it->second.GetUtCount(); i++)
660  {
661  if (positionIndex > m_satConf->GetUtCount())
662  {
663  NS_FATAL_ERROR("Not enough positions available in SatConf for UTs!!!");
664  }
665 
666  GeoCoordinate position = m_satConf->GetUtPosition(positionIndex);
667  m_utPositions->Add(position);
668  positionIndex++;
669 
670  // if requested, check that the given beam is the best in the configured position
671  if (checkBeam)
672  {
673  uint32_t bestBeamId = m_antennaGainPatterns->GetBestBeamId(satId, position, false);
674 
675  if (bestBeamId != it->first.second)
676  {
677  NS_FATAL_ERROR("The beam: " << it->first << " is not the best beam ("
678  << bestBeamId
679  << ") for the position: " << position);
680  }
681  }
682  }
683  }
684 
685  // create as user wants
686  DoCreateScenario(infos, m_gwUsers);
687 
688  m_creationSummaryTrace("*** User Defined Scenario with List Positions Creation Summary ***");
689 }
690 
691 void
693  GetNextUtUserCountCallback getNextUtUserCountCallback)
694 {
695  NS_LOG_FUNCTION(this);
696 
697  NS_ASSERT_MSG(info.size() > 0, "There must be at least one satellite");
698 
699  m_antennaGainPatterns->SetEnabledBeams(info);
700 
701  for (uint32_t i = 0; i < m_satConf->GetUtCount(); i++)
702  {
703  GeoCoordinate position = m_satConf->GetUtPosition(i + 1);
704 
705  uint32_t satId = m_beamHelper->GetClosestSat(position);
706 
707  uint32_t bestBeamId = m_antennaGainPatterns->GetBestBeamId(satId, position, false);
708 
709  std::vector<std::pair<GeoCoordinate, uint32_t>> positions =
710  info.at(std::pair(satId, bestBeamId)).GetPositions();
711  positions.push_back(std::make_pair(position, 0));
712  info.at(std::pair(satId, bestBeamId)).SetPositions(positions);
713  uint32_t nbUsers = getNextUtUserCountCallback();
714  info.at(std::pair(satId, bestBeamId)).AppendUt(nbUsers);
715  }
716 
717  for (uint32_t i = 0; i < m_satConf->GetGwCount(); i++)
718  {
719  GeoCoordinate position = m_satConf->GetGwPosition(i + 1);
720  uint32_t satId = m_beamHelper->GetClosestSat(position);
721 
722  m_gwSats[i] = satId;
723  }
724 
725  m_groupHelper->SetSatConstellationEnabled();
726 
728 }
729 
730 void
731 SatHelper::DoCreateScenario(BeamUserInfoMap_t& beamInfos, uint32_t gwUsers)
732 {
733  NS_LOG_FUNCTION(this);
734 
735  if (m_scenarioCreated)
736  {
737  Singleton<SatLog>::Get()->AddToLog(
739  "",
740  "Scenario tried to re-create with SatHelper. Creation can be done only once.");
741  }
742  else
743  {
744  SetNetworkAddresses(beamInfos, gwUsers);
745 
746  if (m_creationTraces)
747  {
749  }
750 
751  m_beamHelper->SetNccRoutingCallback(
753 
754  InternetStackHelper internet;
755 
756  // create all possible GW nodes, set mobility to them and install to Internet
757  NodeContainer gwNodes;
758  gwNodes.Create(m_satConf->GetGwCount());
759  internet.Install(gwNodes);
760 
761  // Create beams explicitly required for this scenario
762  for (BeamUserInfoMap_t::iterator info = beamInfos.begin(); info != beamInfos.end(); info++)
763  {
764  uint32_t satId = info->first.first;
765  uint32_t beamId = info->first.second;
766 
767  // create UTs of the beam, set mobility to them
768  std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId =
769  info->second.GetPositions();
770  NodeContainer uts;
771  uts.Create(info->second.GetUtCount() - positionsAndGroupId.size());
772  SetUtMobility(uts, satId, beamId);
773 
774  NodeContainer utsFromPosition;
775  utsFromPosition.Create(positionsAndGroupId.size());
776  SetUtMobilityFromPosition(utsFromPosition, satId, beamId, positionsAndGroupId);
777  uts.Add(utsFromPosition);
778 
779  // Add mobile UTs starting at this beam
780  std::map<uint32_t, NodeContainer>::iterator mobileUts = m_mobileUtsByBeam.find(beamId);
781  if (mobileUts != m_mobileUtsByBeam.end())
782  {
783  uts.Add(mobileUts->second);
784  m_mobileUtsByBeam.erase(mobileUts);
785  }
786 
787  // install the whole fleet to Internet
788  internet.Install(uts);
789 
790  for (uint32_t i = 0; i < info->second.GetUtCount(); ++i)
791  {
792  // create and install needed users
793  m_userHelper->InstallUt(uts.Get(i), info->second.GetUtUserCount(i));
794  }
795 
796  std::pair<std::multimap<uint32_t, uint32_t>::iterator,
797  std::multimap<uint32_t, uint32_t>::iterator>
798  mobileUsers;
799  mobileUsers = m_mobileUtsUsersByBeam.equal_range(beamId);
800  std::multimap<uint32_t, uint32_t>::iterator it = mobileUsers.first;
801  for (uint32_t i = info->second.GetUtCount(); i < uts.GetN() && it != mobileUsers.second;
802  ++i, ++it)
803  {
804  // create and install needed mobile users
805  m_userHelper->InstallUt(uts.Get(i), it->second);
806  }
807 
808  std::vector<uint32_t> rtnConf =
809  m_satConf->GetBeamConfiguration(beamId, SatEnums::LD_RETURN);
810  std::vector<uint32_t> fwdConf =
811  m_satConf->GetBeamConfiguration(beamId, SatEnums::LD_FORWARD);
812 
817  NS_ASSERT(rtnConf[SatConf::GW_ID_INDEX] == fwdConf[SatConf::GW_ID_INDEX]);
818  NS_ASSERT(rtnConf[SatConf::BEAM_ID_INDEX] == fwdConf[SatConf::BEAM_ID_INDEX]);
819 
820  // gw index starts from 1 and we have stored them starting from 0
821  Ptr<Node> gwNode = gwNodes.Get(rtnConf[SatConf::GW_ID_INDEX] - 1);
822 
823  SetGwMobility(satId, gwNode, rtnConf[SatConf::GW_ID_INDEX]);
824 
825  std::pair<Ptr<NetDevice>, NetDeviceContainer> netDevices =
826  m_beamHelper->Install(uts,
827  gwNode,
828  rtnConf[SatConf::GW_ID_INDEX],
829  satId,
830  rtnConf[SatConf::BEAM_ID_INDEX],
831  rtnConf[SatConf::U_FREQ_ID_INDEX],
832  rtnConf[SatConf::F_FREQ_ID_INDEX],
833  fwdConf[SatConf::U_FREQ_ID_INDEX],
834  fwdConf[SatConf::F_FREQ_ID_INDEX],
836 
837  for (uint32_t utId = 0; utId < uts.GetN(); utId++)
838  {
839  m_gwDistribution[uts.Get(utId)] = gwNode;
840  }
841 
842  m_utsDistribution.insert(netDevices);
843 
845  {
846  uint32_t gwId = rtnConf[SatConf::GW_ID_INDEX] - 1;
847  uint32_t gwSatId = m_gwSats[gwId];
848  if (satId == gwSatId)
849  {
850  DynamicCast<SatGeoNetDevice>(
851  m_beamHelper->GetGeoSatNodes().Get(gwSatId)->GetDevice(0))
852  ->ConnectGw(Mac48Address::ConvertFrom(netDevices.first->GetAddress()));
853  }
854  }
855  else
856  {
857  DynamicCast<SatGeoNetDevice>(m_beamHelper->GetGeoSatNodes().Get(0)->GetDevice(0))
858  ->ConnectGw(Mac48Address::ConvertFrom(netDevices.first->GetAddress()));
859  m_userHelper->PopulateBeamRoutings(uts,
860  netDevices.second,
861  gwNode,
862  netDevices.first);
863  }
864 
865  for (uint32_t utIndex = 0; utIndex < uts.GetN(); utIndex++)
866  {
867  DynamicCast<SatGeoNetDevice>(
868  m_beamHelper->GetGeoSatNodes().Get(satId)->GetDevice(0))
869  ->ConnectUt(
870  Mac48Address::ConvertFrom(netDevices.second.Get(utIndex)->GetAddress()));
871  }
872  }
873 
875  .clear(); // Release unused resources (mobile UTs starting in non-existent beams)
876 
878  {
880  }
881 
882  m_userHelper->InstallGw(m_beamHelper->GetGwNodes(), gwUsers);
883 
885  {
886  m_beamHelper->InstallIsls();
887  m_beamHelper->SetIslRoutes();
888 
890  }
891 
892  if (m_standard == SatEnums::LORA)
893  {
894  // Create the LoraDeviceAddress of the end devices
895  uint8_t nwkId = 54;
896  uint32_t nwkAddr = 1864;
897  Ptr<LoraDeviceAddressGenerator> addrGen =
898  CreateObject<LoraDeviceAddressGenerator>(nwkId, nwkAddr);
899 
900  Ptr<Node> utNode;
901  for (uint32_t indexUt = 0; indexUt < UtNodes().GetN(); indexUt++)
902  {
903  utNode = UtNodes().Get(indexUt);
904  Ptr<SatLorawanNetDevice> dev =
905  utNode->GetDevice(2)->GetObject<SatLorawanNetDevice>();
906  dev->GetMac()->GetObject<LorawanMacEndDeviceClassA>()->SetDeviceAddress(
907  addrGen->NextAddress());
908  ;
909  }
910 
911  Ptr<LoraNetworkServerHelper> loraNetworkServerHelper =
912  CreateObject<LoraNetworkServerHelper>();
913  Ptr<LoraForwarderHelper> forHelper = CreateObject<LoraForwarderHelper>();
914 
915  loraNetworkServerHelper->SetGateways(GwNodes());
916  loraNetworkServerHelper->SetEndDevices(UtNodes());
917 
918  NodeContainer networkServer;
919  networkServer.Create(1);
920 
921  loraNetworkServerHelper->Install(networkServer);
922 
923  forHelper->Install(GwNodes());
924  }
925 
926  if (m_packetTraces)
927  {
929  }
930 
931  m_scenarioCreated = true;
932  }
933 
934  m_beamHelper->Init();
935 }
936 
937 void
939 {
940  NS_LOG_FUNCTION(this);
941 
942  // Loop on each UT
943  for (uint32_t utId = 0; utId < m_beamHelper->GetUtNodes().GetN(); utId++)
944  {
945  // Get UT, GW attached to this UT, satellite linked to this GW and beam ID used by the
946  // satellite connected to the UT
947  Ptr<Node> ut = m_beamHelper->GetUtNodes().Get(utId);
948  Ptr<SatUtMac> satUtMac;
949  Ptr<Node> gw = m_gwDistribution[ut];
950  uint32_t gwSatId =
951  GetClosestSat(GeoCoordinate(gw->GetObject<SatMobilityModel>()->GetPosition()));
952  uint32_t utBeamId = 0;
953  uint32_t utSatNetDeviceCount = 0;
954  for (uint32_t ndId = 0; ndId < m_beamHelper->GetUtNodes().Get(utId)->GetNDevices(); ndId++)
955  {
956  Ptr<SatNetDevice> utNd =
957  DynamicCast<SatNetDevice>(m_beamHelper->GetUtNodes().Get(utId)->GetDevice(ndId));
958  if (utNd)
959  {
960  utSatNetDeviceCount++;
961  utBeamId = utNd->GetMac()->GetBeamId();
962  satUtMac = DynamicCast<SatUtMac>(utNd->GetMac());
963  }
964  }
965  NS_ASSERT_MSG(utSatNetDeviceCount == 1, "UT must have exactly on SatNetDevice");
966  NS_ASSERT_MSG(satUtMac != nullptr, "UT must have a SatUtMac for beam");
967 
968  // Get feeder MAC used on sat on GW side, and corresponding beam ID used for downlink (can
969  // be different than UT beam ID)
970  uint32_t usedBeamId = 0;
971  uint32_t gwSatGeoNetDeviceCount = 0;
972  for (uint32_t ndId = 0; ndId < m_beamHelper->GetGeoSatNodes().Get(gwSatId)->GetNDevices();
973  ndId++)
974  {
975  Ptr<SatGeoNetDevice> gwNd = DynamicCast<SatGeoNetDevice>(
976  m_beamHelper->GetGeoSatNodes().Get(gwSatId)->GetDevice(ndId));
977  if (gwNd)
978  {
979  gwSatGeoNetDeviceCount++;
980  usedBeamId = gwNd->GetFeederMac(utBeamId)->GetBeamId();
981  }
982  }
983  NS_ASSERT_MSG(gwSatGeoNetDeviceCount == 1, "SAT must have exactly on SatGeoNetDevice");
984  NS_ASSERT_MSG(usedBeamId != 0, "Incorrect beam ID");
985 
986  // Get GW MAC for usedBeamId, and corresponding MAC address
987  Mac48Address gwAddress;
988  uint32_t gwSatNetDeviceCount = 0;
989  for (uint32_t ndId = 0; ndId < gw->GetNDevices(); ndId++)
990  {
991  Ptr<SatNetDevice> gwNd = DynamicCast<SatNetDevice>(gw->GetDevice(ndId));
992  if (gwNd && gwNd->GetMac()->GetBeamId() == usedBeamId &&
993  gwNd->GetMac()->GetSatId() == gwSatId)
994  {
995  gwSatNetDeviceCount++;
996  gwAddress = Mac48Address::ConvertFrom(gwNd->GetAddress());
997  }
998  }
999  NS_ASSERT_MSG(gwSatNetDeviceCount == 1,
1000  "GW must have exactly on SatNetDevice for beam "
1001  << usedBeamId << " and satellite " << gwSatId);
1002 
1003  satUtMac->SetGwAddress(gwAddress);
1004  }
1005 }
1006 
1007 void
1009 {
1010  NS_LOG_FUNCTION(this);
1011 
1012  for (uint32_t gwId = 0; gwId < GwNodes().GetN(); gwId++)
1013  {
1014  Ptr<Node> gw = GwNodes().Get(gwId);
1015  for (uint32_t ndId = 0; ndId < gw->GetNDevices(); ndId++)
1016  {
1017  if (DynamicCast<SatNetDevice>(gw->GetDevice(ndId)))
1018  {
1019  Ptr<SatNetDevice> gwNd = DynamicCast<SatNetDevice>(gw->GetDevice(ndId));
1020 
1021  NetDeviceContainer utNd = m_utsDistribution[gwNd];
1022  NodeContainer ut;
1023  for (uint32_t i = 0; i < utNd.GetN(); i++)
1024  {
1025  ut.Add(utNd.Get(i)->GetNode());
1026  }
1027  m_userHelper->PopulateBeamRoutings(ut, utNd, gw, gwNd);
1028  }
1029  }
1030  }
1031 }
1032 
1033 void
1035  const std::string& folderName,
1036  Ptr<RandomVariableStream> utUsers)
1037 {
1038  if (!(Singleton<SatEnvVariables>::Get()->IsValidDirectory(folderName)))
1039  {
1040  NS_LOG_INFO("Directory '" << folderName
1041  << "' does not exist, no mobile UTs will be created.");
1042  return;
1043  }
1044 
1045  for (std::string& filename : SystemPath::ReadFiles(folderName))
1046  {
1047  std::string filepath = folderName + "/" + filename;
1048  if (Singleton<SatEnvVariables>::Get()->IsValidDirectory(filepath))
1049  {
1050  NS_LOG_INFO("Skipping directory '" << filename << "'");
1051  continue;
1052  }
1053 
1054  Ptr<Node> utNode = LoadMobileUtFromFile(satId, filepath);
1055  uint32_t bestBeamId = utNode->GetObject<SatTracedMobilityModel>()->GetBestBeamId();
1056 
1057  // Store Node in the container for the starting beam
1058  std::map<uint32_t, NodeContainer>::iterator it = m_mobileUtsByBeam.find(bestBeamId);
1059  if (it == m_mobileUtsByBeam.end())
1060  {
1061  std::pair<std::map<uint32_t, NodeContainer>::iterator, bool> inserted =
1062  m_mobileUtsByBeam.insert(std::make_pair(bestBeamId, NodeContainer(utNode)));
1063  NS_ASSERT_MSG(inserted.second,
1064  "Failed to create a new beam when reading UT mobility files");
1065  }
1066  else
1067  {
1068  it->second.Add(utNode);
1069  }
1070 
1071  // Store amount of users for this UT
1072  m_mobileUtsUsersByBeam.insert(std::make_pair(bestBeamId, utUsers->GetInteger()));
1073  }
1074 
1075  for (auto& mobileUtsForBeam : m_mobileUtsByBeam)
1076  {
1077  NS_LOG_INFO("Installing Mobility Observers for mobile UTs starting in beam "
1078  << mobileUtsForBeam.first);
1079  InstallMobilityObserver(satId, mobileUtsForBeam.second);
1080  }
1081 }
1082 
1083 Ptr<Node>
1084 SatHelper::LoadMobileUtFromFile(uint32_t satId, const std::string& filename)
1085 {
1086  // Create Node, Mobility and aggregate them
1087  Ptr<SatTracedMobilityModel> mobility =
1088  CreateObject<SatTracedMobilityModel>(satId, filename, m_antennaGainPatterns);
1089  Ptr<Node> utNode = CreateObject<Node>();
1090  utNode->AggregateObject(mobility);
1091  utNode->AggregateObject(CreateObject<SatUtHandoverModule>(m_antennaGainPatterns));
1092  return utNode;
1093 }
1094 
1095 void
1096 SatHelper::SetGwMobility(uint32_t satId, Ptr<Node> gw, uint32_t gwIndex)
1097 {
1098  NS_LOG_FUNCTION(this);
1099 
1100  NodeContainer gwNodes = NodeContainer(gw);
1101  MobilityHelper mobility;
1102  Ptr<SatListPositionAllocator> gwPosAllocator = CreateObject<SatListPositionAllocator>();
1103 
1104  gwPosAllocator->Add(m_satConf->GetGwPosition(gwIndex));
1105 
1106  mobility.SetPositionAllocator(gwPosAllocator);
1107  mobility.SetMobilityModel("ns3::SatConstantPositionMobilityModel");
1108  mobility.Install(gwNodes);
1109 
1110  InstallMobilityObserver(satId, gwNodes);
1111 }
1112 
1113 void
1114 SatHelper::SetUtMobility(NodeContainer uts, uint32_t satId, uint32_t beamId)
1115 {
1116  NS_LOG_FUNCTION(this);
1117 
1118  MobilityHelper mobility;
1119 
1120  Ptr<SatPositionAllocator> allocator;
1121 
1122  // if position allocator (list) for UTs is created by helper already use it,
1123  // in other case use the spot beam position allocator
1124  if (m_utPositionsByBeam.find(beamId) != m_utPositionsByBeam.end())
1125  {
1126  allocator = m_utPositionsByBeam[beamId];
1127  }
1128  else if (m_utPositions != NULL)
1129  {
1130  allocator = m_utPositions;
1131  }
1132  else
1133  {
1134  // Create new position allocator
1135  allocator = GetBeamAllocator(beamId);
1136  }
1137 
1138  mobility.SetPositionAllocator(allocator);
1139  mobility.SetMobilityModel("ns3::SatConstantPositionMobilityModel");
1140  mobility.Install(uts);
1141 
1142  InstallMobilityObserver(satId, uts);
1143 
1144  for (uint32_t i = 0; i < uts.GetN(); ++i)
1145  {
1146  GeoCoordinate position = uts.Get(i)->GetObject<SatMobilityModel>()->GetGeoPosition();
1147  NS_LOG_INFO(
1148  "Installing mobility observer on Ut Node at "
1149  << position << " with antenna gain of "
1150  << m_antennaGainPatterns->GetAntennaGainPattern(beamId)->GetAntennaGain_lin(
1151  position,
1152  m_beamHelper->GetGeoSatNodes().Get(satId)->GetObject<SatMobilityModel>()));
1153  }
1154 }
1155 
1156 void
1158  NodeContainer uts,
1159  uint32_t satId,
1160  uint32_t beamId,
1161  std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId)
1162 {
1163  NS_LOG_FUNCTION(this << beamId);
1164 
1165  MobilityHelper mobility;
1166 
1167  Ptr<SatListPositionAllocator> allocator = CreateObject<SatListPositionAllocator>();
1168 
1169  NS_ASSERT_MSG(uts.GetN() == positionsAndGroupId.size(),
1170  "Inconsistent number of nodes and positions");
1171 
1172  for (uint32_t i = 0; i < positionsAndGroupId.size(); i++)
1173  {
1174  allocator->Add(positionsAndGroupId[i].first);
1175  m_groupHelper->AddNodeToGroupAfterScenarioCreation(positionsAndGroupId[i].second,
1176  uts.Get(i));
1177  }
1178 
1179  mobility.SetPositionAllocator(allocator);
1180  mobility.SetMobilityModel("ns3::SatConstantPositionMobilityModel");
1181  mobility.Install(uts);
1182 
1183  InstallMobilityObserver(satId, uts);
1184 
1185  for (uint32_t i = 0; i < uts.GetN(); ++i)
1186  {
1187  GeoCoordinate position = uts.Get(i)->GetObject<SatMobilityModel>()->GetGeoPosition();
1188  NS_LOG_INFO(
1189  "Installing mobility observer on Ut Node at "
1190  << position << " with antenna gain of "
1191  << m_antennaGainPatterns->GetAntennaGainPattern(beamId)->GetAntennaGain_lin(
1192  position,
1193  m_beamHelper->GetGeoSatNodes().Get(satId)->GetObject<SatMobilityModel>()));
1194  }
1195 }
1196 
1197 Ptr<SatSpotBeamPositionAllocator>
1199 {
1200  GeoCoordinate satPosition = m_satConf->GetGeoSatPosition();
1202  {
1203  satPosition =
1204  m_beamHelper->GetGeoSatNodes().Get(0)->GetObject<SatMobilityModel>()->GetPosition();
1205  }
1206  Ptr<SatSpotBeamPositionAllocator> beamAllocator =
1207  CreateObject<SatSpotBeamPositionAllocator>(beamId, m_antennaGainPatterns, satPosition);
1208 
1209  Ptr<UniformRandomVariable> altRnd = CreateObject<UniformRandomVariable>();
1210  altRnd->SetAttribute("Min", DoubleValue(0.0));
1211  altRnd->SetAttribute("Max", DoubleValue(500.0));
1212  beamAllocator->SetAltitude(altRnd);
1213  return beamAllocator;
1214 }
1215 
1216 void
1218 {
1219  NS_LOG_FUNCTION(this);
1220 
1221  MobilityHelper mobility;
1222 
1223  Ptr<SatListPositionAllocator> geoSatPosAllocator = CreateObject<SatListPositionAllocator>();
1224  geoSatPosAllocator->Add(m_satConf->GetGeoSatPosition());
1225 
1226  mobility.SetPositionAllocator(geoSatPosAllocator);
1227  mobility.SetMobilityModel("ns3::SatConstantPositionMobilityModel");
1228  mobility.Install(node);
1229 }
1230 
1231 void
1232 SatHelper::SetSatMobility(Ptr<Node> node, std::string tle)
1233 {
1234  NS_LOG_FUNCTION(this);
1235 
1236  Ptr<Object> object = node;
1237  Ptr<SatSGP4MobilityModel> model = object->GetObject<SatSGP4MobilityModel>();
1238  if (model == nullptr)
1239  {
1240  ObjectFactory mobilityFactory;
1241  mobilityFactory.SetTypeId("ns3::SatSGP4MobilityModel");
1242  model = mobilityFactory.Create()->GetObject<SatSGP4MobilityModel>();
1243  if (model == nullptr)
1244  {
1245  NS_FATAL_ERROR("The requested mobility model is not a mobility model: \""
1246  << mobilityFactory.GetTypeId().GetName() << "\"");
1247  }
1248  object->AggregateObject(model);
1249  }
1250 
1251  if (tle.empty())
1252  {
1253  model->SetTleInfo(m_satConf->GetSatTle());
1254  }
1255  else
1256  {
1257  model->SetTleInfo(tle);
1258  }
1259 }
1260 
1261 void
1262 SatHelper::InstallMobilityObserver(uint32_t satId, NodeContainer nodes) const
1263 {
1264  NS_LOG_FUNCTION(this);
1265 
1266  for (NodeContainer::Iterator i = nodes.Begin(); i != nodes.End(); i++)
1267  {
1268  Ptr<SatMobilityObserver> observer = (*i)->GetObject<SatMobilityObserver>();
1269 
1270  if (observer == nullptr)
1271  {
1272  Ptr<SatMobilityModel> ownMobility = (*i)->GetObject<SatMobilityModel>();
1273  Ptr<SatMobilityModel> satMobility =
1274  m_beamHelper->GetGeoSatNodes().Get(satId)->GetObject<SatMobilityModel>();
1275 
1276  NS_ASSERT(ownMobility != NULL);
1277  NS_ASSERT(satMobility != NULL);
1278 
1279  observer = CreateObject<SatMobilityObserver>(
1280  ownMobility,
1281  satMobility,
1282  m_beamHelper->GetReturnLinkRegenerationMode() != SatEnums::TRANSPARENT);
1283 
1284  (*i)->AggregateObject(observer);
1285  }
1286  }
1287 }
1288 
1289 void
1291  NodeContainer receivers,
1292  Ipv4Address sourceAddress,
1293  Ipv4Address groupAddress)
1294 {
1295  NS_LOG_FUNCTION(this);
1296 
1297  MulticastBeamInfo_t beamInfo;
1298  Ptr<NetDevice> routerUserOutputDev;
1299  Ptr<Node> sourceUtNode = m_userHelper->GetUtNode(source);
1300 
1301  // Construct multicast info from source UT node and receivers. In case that sourceUtNode is
1302  // NULL, source is some GW user. As a result is given flag indicating if traffic shall be
1303  // forwarded to source's own network
1304 
1305  if (ConstructMulticastInfo(sourceUtNode, receivers, beamInfo, routerUserOutputDev))
1306  {
1307  // Some multicast receiver belongs to same group with source
1308 
1309  // select destination node
1310  Ptr<Node> destNode = m_userHelper->GetRouter();
1311 
1312  if (sourceUtNode)
1313  {
1314  destNode = sourceUtNode;
1315  }
1316 
1317  // add default route for multicast group to source's network
1318  SetMulticastRouteToSourceNetwork(source, destNode);
1319  }
1320 
1321  // set routes outside source's network only when there are receivers
1322  if (!beamInfo.empty() || (sourceUtNode && routerUserOutputDev))
1323  {
1324  Ptr<Node> routerNode = m_userHelper->GetRouter();
1325 
1326  Ptr<NetDevice> routerInputDev = NULL;
1327  Ptr<NetDevice> gwOutputDev = NULL;
1328 
1329  // set multicast routes to satellite network utilizing beam helper
1330  NetDeviceContainer gwInputDevices =
1331  m_beamHelper->AddMulticastGroupRoutes(beamInfo,
1332  sourceUtNode,
1333  sourceAddress,
1334  groupAddress,
1335  (bool)routerUserOutputDev,
1336  gwOutputDev);
1337 
1338  Ipv4StaticRoutingHelper multicast;
1339 
1340  // select input device in IP router
1341  if (gwOutputDev)
1342  {
1343  // traffic coming from some GW to router (satellite network and source is UT)
1344  // find matching input device using GW output device
1345  routerInputDev = FindMatchingDevice(gwOutputDev, routerNode);
1346  }
1347  else if (!sourceUtNode)
1348  {
1349  // traffic is coming form user network (some GW user)
1350 
1351  // find matching device using source node
1352  std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1353 
1354  if (FindMatchingDevices(source, routerNode, devices))
1355  {
1356  routerInputDev = devices.second;
1357  }
1358  }
1359 
1360  NetDeviceContainer routerOutputDevices;
1361 
1362  if (routerUserOutputDev)
1363  {
1364  routerOutputDevices.Add(routerUserOutputDev);
1365  }
1366 
1367  for (NetDeviceContainer::Iterator it = gwInputDevices.Begin(); it != gwInputDevices.End();
1368  it++)
1369  {
1370  Ptr<NetDevice> matchingDevice = FindMatchingDevice(*it, routerNode);
1371 
1372  if (matchingDevice)
1373  {
1374  routerOutputDevices.Add(matchingDevice);
1375  }
1376  }
1377 
1378  // Add multicast route over IP router
1379  // Input device is getting traffic from user network (GW users) or from some GW
1380  // Output devices are forwarding traffic to user network (GW users) and/or GWs
1381  if (routerInputDev && (routerOutputDevices.GetN() > 0))
1382  {
1383  multicast.AddMulticastRoute(routerNode,
1384  sourceAddress,
1385  groupAddress,
1386  routerInputDev,
1387  routerOutputDevices);
1388  }
1389  }
1390 }
1391 
1392 void
1393 SatHelper::CreationDetailsSink(Ptr<OutputStreamWrapper> stream,
1394  std::string context,
1395  std::string info)
1396 {
1397  *stream->GetStream() << context << ", " << info << std::endl;
1398 }
1399 
1400 void
1402 {
1403  NS_LOG_FUNCTION(this);
1404 
1405  *m_creationTraceStream->GetStream() << CreateCreationSummary(title);
1406  *m_utTraceStream->GetStream() << m_beamHelper->GetUtInfo();
1407 }
1408 
1409 std::string
1411 {
1412  NS_LOG_FUNCTION(this);
1413 
1414  std::ostringstream oss;
1415 
1416  oss << std::endl << std::endl << title << std::endl << std::endl;
1417  oss << "--- User Info ---" << std::endl << std::endl;
1418  oss << "Created GW users: " << m_userHelper->GetGwUserCount() << ", ";
1419  oss << "Created UT users: " << m_userHelper->GetUtUserCount() << std::endl << std::endl;
1420  oss << m_userHelper->GetRouterInfo() << std::endl << std::endl;
1421  oss << m_beamHelper->GetBeamInfo() << std::endl;
1422 
1423  return oss.str();
1424 }
1425 
1426 void
1428 {
1429  NS_LOG_FUNCTION(this);
1430 
1431  m_userHelper = NULL;
1432  m_beamHelper->DoDispose();
1433  m_beamHelper = NULL;
1434  m_antennaGainPatterns = NULL;
1435  m_utPositionsByBeam.clear();
1436  m_mobileUtsByBeam.clear();
1437  m_mobileUtsUsersByBeam.clear();
1438 }
1439 
1440 void
1441 SatHelper::PrintTopology(std::ostream& os) const
1442 {
1443  NS_LOG_FUNCTION(this);
1444 
1445  os << "Satellite topology" << std::endl;
1446  os << "==================" << std::endl;
1447 
1448  os << "Satellites" << std::endl;
1449  NodeContainer satNodes = m_beamHelper->GetGeoSatNodes();
1450  for (uint32_t i = 0; i < satNodes.GetN(); i++)
1451  {
1452  Ptr<Node> node = satNodes.Get(i);
1453  os << " SAT: ID = " << satNodes.Get(i)->GetId();
1454  os << ", at " << GeoCoordinate(node->GetObject<SatMobilityModel>()->GetPosition())
1455  << std::endl;
1456  os << " Devices to ground stations " << std::endl;
1457  for (uint32_t j = 0; j < node->GetNDevices(); j++)
1458  {
1459  Ptr<SatGeoNetDevice> geoNetDevice = DynamicCast<SatGeoNetDevice>(node->GetDevice(j));
1460  if (geoNetDevice)
1461  {
1462  os << " " << geoNetDevice->GetAddress() << std::endl;
1463  std::map<uint32_t, Ptr<SatMac>> feederMac = geoNetDevice->GetAllFeederMac();
1464  for (std::map<uint32_t, Ptr<SatMac>>::iterator it = feederMac.begin();
1465  it != feederMac.end();
1466  it++)
1467  {
1468  os << " Feeder at " << it->second->GetAddress() << ", beam " << it->first
1469  << std::endl;
1470  }
1471  std::map<uint32_t, Ptr<SatMac>> userMac = geoNetDevice->GetUserMac();
1472  for (std::map<uint32_t, Ptr<SatMac>>::iterator it = userMac.begin();
1473  it != userMac.end();
1474  it++)
1475  {
1476  os << " User at " << it->second->GetAddress() << ", beam " << it->first
1477  << std::endl;
1478  }
1479  std::set<Mac48Address> gwConnected = geoNetDevice->GetGwConnected();
1480  os << " Feeder connected to" << std::endl;
1481  for (std::set<Mac48Address>::iterator it = gwConnected.begin();
1482  it != gwConnected.end();
1483  it++)
1484  {
1485  os << " " << *it << std::endl;
1486  }
1487  }
1488  }
1489  os << " ISLs " << std::endl;
1490  for (uint32_t j = 0; j < node->GetNDevices(); j++)
1491  {
1492  Ptr<PointToPointIslNetDevice> islNetDevice =
1493  DynamicCast<PointToPointIslNetDevice>(node->GetDevice(j));
1494  if (islNetDevice)
1495  {
1496  os << " " << islNetDevice->GetAddress() << " to SAT "
1497  << islNetDevice->GetDestinationNode()->GetId() << std::endl;
1498  }
1499  }
1500  }
1501 
1502  os << "GWs" << std::endl;
1503  NodeContainer gwNodes = m_beamHelper->GetGwNodes();
1504  for (uint32_t i = 0; i < gwNodes.GetN(); i++)
1505  {
1506  Ptr<Node> node = gwNodes.Get(i);
1507  os << " GW: ID = " << gwNodes.Get(i)->GetId();
1508  os << ", at " << GeoCoordinate(node->GetObject<SatMobilityModel>()->GetPosition())
1509  << std::endl;
1510  os << " Devices " << std::endl;
1511  for (uint32_t j = 0; j < node->GetNDevices(); j++)
1512  {
1513  Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(node->GetDevice(j));
1514  if (netDevice)
1515  {
1516  Ptr<SatMac> mac = netDevice->GetMac();
1517  os << " " << mac->GetAddress() << ", sat: " << mac->GetSatId()
1518  << ", beam: " << mac->GetBeamId() << std::endl;
1519  }
1520  }
1521  }
1522 
1523  os << "UTs" << std::endl;
1524  NodeContainer utNodes = m_beamHelper->GetUtNodes();
1525  for (uint32_t i = 0; i < utNodes.GetN(); i++)
1526  {
1527  Ptr<Node> node = utNodes.Get(i);
1528  os << " UT: ID = " << utNodes.Get(i)->GetId();
1529  os << ", at " << GeoCoordinate(node->GetObject<SatMobilityModel>()->GetPosition())
1530  << std::endl;
1531  os << " Devices " << std::endl;
1532  for (uint32_t j = 0; j < node->GetNDevices(); j++)
1533  {
1534  Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(node->GetDevice(j));
1535  if (netDevice)
1536  {
1537  Ptr<SatUtMac> mac = DynamicCast<SatUtMac>(netDevice->GetMac());
1538  os << " " << mac->GetAddress() << ", sat: " << mac->GetSatId()
1539  << ", beam: " << mac->GetBeamId();
1540  os << ". Linked to GW " << mac->GetGwAddress() << std::endl;
1541  }
1542  }
1543  }
1544 
1545  os << "GW users" << std::endl;
1546  NodeContainer gwUserNodes = m_userHelper->GetGwUsers();
1547  for (uint32_t i = 0; i < gwUserNodes.GetN(); i++)
1548  {
1549  Ptr<Node> node = gwUserNodes.Get(i);
1550  os << " GW user: ID = " << gwUserNodes.Get(i)->GetId() << std::endl;
1551  }
1552 
1553  os << "UT users" << std::endl;
1554  NodeContainer utUserNodes = m_userHelper->GetUtUsers();
1555  for (uint32_t i = 0; i < utUserNodes.GetN(); i++)
1556  {
1557  Ptr<Node> node = utUserNodes.Get(i);
1558  os << " UT user: ID = " << utUserNodes.Get(i)->GetId() << std::endl;
1559  }
1560 
1561  os << "==================" << std::endl;
1562  os << std::endl;
1563 }
1564 
1565 bool
1567  Ptr<Node> nodeB,
1568  std::pair<Ptr<NetDevice>, Ptr<NetDevice>>& matchingDevices)
1569 {
1570  bool found = false;
1571 
1572  for (uint32_t i = 1; ((i < nodeA->GetNDevices()) && !found); i++)
1573  {
1574  Ptr<NetDevice> devA = nodeA->GetDevice(i);
1575  Ptr<NetDevice> devB = FindMatchingDevice(devA, nodeB);
1576 
1577  if (devB)
1578  {
1579  matchingDevices = std::make_pair(devA, devB);
1580  found = true;
1581  }
1582  }
1583 
1584  return found;
1585 }
1586 
1587 Ptr<NetDevice>
1588 SatHelper::FindMatchingDevice(Ptr<NetDevice> devA, Ptr<Node> nodeB)
1589 {
1590  Ptr<NetDevice> matchingDevice = NULL;
1591 
1592  Ipv4Address addressA =
1593  devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetLocal();
1594  Ipv4Mask maskA =
1595  devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetMask();
1596 
1597  Ipv4Address netAddressA = addressA.CombineMask(maskA);
1598 
1599  for (uint32_t j = 1; j < nodeB->GetNDevices(); j++)
1600  {
1601  Ipv4Address addressB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetLocal();
1602  Ipv4Mask maskB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetMask();
1603 
1604  Ipv4Address netAddressB = addressB.CombineMask(maskB);
1605 
1606  if (netAddressA == netAddressB)
1607  {
1608  matchingDevice = nodeB->GetDevice(j);
1609  }
1610  }
1611 
1612  return matchingDevice;
1613 }
1614 
1615 void
1616 SatHelper::SetMulticastRouteToSourceNetwork(Ptr<Node> source, Ptr<Node> dest)
1617 {
1618  NS_LOG_FUNCTION(this);
1619 
1620  std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1621 
1622  if (FindMatchingDevices(source, dest, devices))
1623  {
1624  Ipv4StaticRoutingHelper multicast;
1625  Ptr<Ipv4StaticRouting> staticRouting =
1626  multicast.GetStaticRouting(source->GetObject<ns3::Ipv4>());
1627 
1628  // check if default multicast route already exists
1629  bool defaultMulticastRouteExists = false;
1630  Ipv4Address defMulticastNetwork = Ipv4Address("224.0.0.0");
1631  Ipv4Mask defMulticastNetworkMask = Ipv4Mask("240.0.0.0");
1632 
1633  for (uint32_t i = 0; i < staticRouting->GetNRoutes(); i++)
1634  {
1635  if (staticRouting->GetRoute(i).GetDestNetwork() == defMulticastNetwork &&
1636  staticRouting->GetRoute(i).GetDestNetworkMask() == defMulticastNetworkMask)
1637  {
1638  defaultMulticastRouteExists = true;
1639  }
1640  }
1641 
1642  // add default multicast route only if it does not exist already
1643  if (!defaultMulticastRouteExists)
1644  {
1645  multicast.SetDefaultMulticastRoute(source, devices.first);
1646  }
1647  }
1648 }
1649 
1650 bool
1651 SatHelper::ConstructMulticastInfo(Ptr<Node> sourceUtNode,
1652  NodeContainer receivers,
1653  MulticastBeamInfo_t& beamInfo,
1654  Ptr<NetDevice>& routerUserOutputDev)
1655 {
1656  NS_LOG_FUNCTION(this);
1657 
1658  bool routeToSourceNertwork = false;
1659 
1660  routerUserOutputDev = NULL;
1661 
1662  // go through all receivers
1663  for (uint32_t i = 0; i < receivers.GetN(); i++)
1664  {
1665  Ptr<Node> receiverNode = receivers.Get(i);
1666  Ptr<Node> utNode = m_userHelper->GetUtNode(receiverNode);
1667 
1668  // check if user is connected to UT or GW
1669 
1670  if (utNode) // connected to UT
1671  {
1672  uint32_t beamId = m_beamHelper->GetUtBeamId(utNode);
1673 
1674  if (beamId != 0) // beam ID is found
1675  {
1676  if (sourceUtNode == utNode)
1677  {
1678  // Source UT node is same than current UT node. Set flag to indicate that
1679  // multicast group traffic shall be routed to source own network.
1680  routeToSourceNertwork = true;
1681  }
1682  else
1683  {
1684  // store other UT nodes beam ID and pointer to multicast group info for later
1685  // routing
1686  MulticastBeamInfo_t::iterator it = beamInfo.find(beamId);
1687 
1688  // find or create first storage for the beam
1689  if (it == beamInfo.end())
1690  {
1691  std::pair<MulticastBeamInfo_t::iterator, bool> result =
1692  beamInfo.insert(std::make_pair(beamId, MulticastBeamInfoItem_t()));
1693 
1694  if (result.second)
1695  {
1696  it = result.first;
1697  }
1698  else
1699  {
1700  NS_FATAL_ERROR("Cannot insert beam to map container");
1701  }
1702  }
1703 
1704  // Add to UT node to beam storage (map)
1705  it->second.insert(utNode);
1706  }
1707  }
1708  else
1709  {
1710  NS_FATAL_ERROR("UT node's beam ID is invalid!!");
1711  }
1712  }
1713  else if (m_userHelper->IsGwUser(receiverNode)) // connected to GW
1714  {
1715  if (!routerUserOutputDev)
1716  {
1717  if (sourceUtNode)
1718  {
1719  std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1720 
1721  if (FindMatchingDevices(receiverNode, m_userHelper->GetRouter(), devices))
1722  {
1723  routerUserOutputDev = devices.second;
1724  }
1725  }
1726  else
1727  {
1728  routeToSourceNertwork = true;
1729  }
1730  }
1731  }
1732  else
1733  {
1734  NS_FATAL_ERROR("Multicast receiver node is expected to be connected UT or GW node!!!");
1735  }
1736  }
1737 
1738  return routeToSourceNertwork;
1739 }
1740 
1741 void
1743 {
1744  NS_LOG_FUNCTION(this);
1745 
1746  std::set<uint32_t> networkAddresses;
1747  std::pair<std::set<uint32_t>::const_iterator, bool> addressInsertionResult;
1748 
1749  // test first that configured initial addresses per configured address space
1750  // are not same by inserting them to set container
1751  networkAddresses.insert(m_beamNetworkAddress.Get());
1752  addressInsertionResult = networkAddresses.insert(m_gwNetworkAddress.Get());
1753 
1754  if (!addressInsertionResult.second)
1755  {
1756  NS_FATAL_ERROR("GW network address is invalid (same as Beam network address)");
1757  }
1758 
1759  addressInsertionResult = networkAddresses.insert(m_utNetworkAddress.Get());
1760 
1761  if (!addressInsertionResult.second)
1762  {
1763  NS_FATAL_ERROR("UT network address is invalid (same as Beam or GW network address)");
1764  }
1765 
1766  // calculate values to check needed network and host address counts
1767  uint32_t utNetworkAddressCount = 0; // network addresses needed in UT network
1768  uint32_t utHostAddressCount = 0; // host addresses needed in UT network
1769  uint32_t beamHostAddressCount = 0; // host addresses needed in Beam network
1770  uint32_t gwNetworkAddressCount = 1; // network addresses needed in GW network. Initially one
1771  // network needed between GW users and Router needed
1772  std::set<uint32_t> gwIds; // to find out the additional network addresses needed in GW network
1773 
1774  for (BeamUserInfoMap_t::const_iterator it = info.begin(); it != info.end(); it++)
1775  {
1776  uint32_t beamUtCount = it->second.GetUtCount();
1777  utNetworkAddressCount += beamUtCount;
1778 
1779  if (beamUtCount > beamHostAddressCount)
1780  {
1781  beamHostAddressCount = beamUtCount;
1782  }
1783 
1784  for (uint32_t i = 0; i < beamUtCount; i++)
1785  {
1786  if (it->second.GetUtUserCount(i) > utHostAddressCount)
1787  {
1788  utHostAddressCount = it->second.GetUtUserCount(i);
1789  }
1790  }
1791 
1792  // try to add GW id to container, if not existing already in the container
1793  // increment GW network address count
1794  if (gwIds.insert(m_beamHelper->GetGwId(it->first.first, it->first.second)).second)
1795  {
1796  gwNetworkAddressCount++; // one network more needed between a GW and Router
1797  }
1798  }
1799 
1800  // do final checking of the configured address spaces
1801  CheckNetwork("Beam",
1804  networkAddresses,
1805  info.size(),
1806  beamHostAddressCount);
1807  CheckNetwork("GW",
1810  networkAddresses,
1811  gwNetworkAddressCount,
1812  gwUsers);
1813  CheckNetwork("UT",
1816  networkAddresses,
1817  utNetworkAddressCount,
1818  utHostAddressCount);
1819 
1820  // set base addresses of the sub-helpers
1821  m_userHelper->SetBeamBaseAddress(m_beamNetworkAddress, m_beamNetworkMask);
1822  m_userHelper->SetGwBaseAddress(m_gwNetworkAddress, m_gwNetworkMask);
1823  m_userHelper->SetUtBaseAddress(m_utNetworkAddress, m_utNetworkMask);
1824 }
1825 
1826 void
1827 SatHelper::CheckNetwork(std::string networkName,
1828  const Ipv4Address& firstNetwork,
1829  const Ipv4Mask& mask,
1830  const std::set<uint32_t>& networkAddresses,
1831  uint32_t networkCount,
1832  uint32_t hostCount) const
1833 {
1834  NS_LOG_FUNCTION(this);
1835 
1836  uint16_t addressPrefixLength = mask.GetPrefixLength();
1837 
1838  // test that configured mask is valid (address prefix length is in valid range)
1839  if ((addressPrefixLength < MIN_ADDRESS_PREFIX_LENGTH) ||
1840  (addressPrefixLength > MAX_ADDRESS_PREFIX_LENGTH))
1841  {
1842  NS_FATAL_ERROR(networkName
1843  << " network mask value out of range (0xFFFFFF70 to 0x10000000).");
1844  }
1845 
1846  // test that configured initial network number (prefix) is valid, consistent with mask
1847  if ((firstNetwork.Get() & mask.GetInverse()) != 0)
1848  {
1849  NS_FATAL_ERROR(networkName << " network address and mask inconsistent.");
1850  }
1851 
1852  std::set<uint32_t>::const_iterator currentAddressIt = networkAddresses.find(firstNetwork.Get());
1853 
1854  // test that network we are checking is in given container
1855  if (currentAddressIt != networkAddresses.end())
1856  {
1857  // calculate network and host count based on configured initial network address and
1858  // mask for the network space
1859  uint32_t hostAddressCount = std::pow(2, (32 - addressPrefixLength)) - 2;
1860  uint32_t firstAddressValue = firstNetwork.Get();
1861  uint32_t networkAddressCount =
1862  mask.Get() - firstAddressValue +
1863  1; // increase subtraction result by one, to include also first address
1864 
1865  currentAddressIt++;
1866 
1867  // test in the case that checked address space is not last ('highest') in the
1868  // given address container that the address space doesn't overlap with other configured
1869  // address spaces
1870  if ((currentAddressIt != networkAddresses.end()) &&
1871  (firstAddressValue + (networkCount << (32 - addressPrefixLength))) >= *currentAddressIt)
1872  {
1873  NS_FATAL_ERROR(networkName << " network's addresses overlaps with some other network)");
1874  }
1875 
1876  // test that enough network addresses are available in address space
1877  if (networkCount > networkAddressCount)
1878  {
1879  NS_FATAL_ERROR("Not enough network addresses for '" << networkName << "' network");
1880  }
1881 
1882  // test that enough host addresses are available in address space
1883  if (hostCount > hostAddressCount)
1884  {
1885  NS_FATAL_ERROR("Not enough host addresses for '" << networkName << "' network");
1886  }
1887  }
1888  else
1889  {
1890  NS_FATAL_ERROR(networkName
1891  << "network's initial address number not among of the given addresses");
1892  }
1893 }
1894 
1895 } // namespace ns3
GeoCoordinate class is used to store and operate with geodetic coordinates.
Class representing the MAC layer of a Class A LoRaWAN device.
SatChannel::CarrierFreqConverter CarrierFreqConverter
Define type CarrierFreqConverter.
Ptr< PropagationDelayModel > GetPropagationDelayModel(uint32_t satId, uint32_t beamId, SatEnums::ChannelType_t channelType)
Class that holds information for each beam regarding UTs and their users camped in each beam.
void AppendUt(uint32_t userCount)
Appends new UT to end of the list with given user count for the appended UT.
void SetUtUserCount(uint32_t utIndex, uint32_t userCount)
Sets user count for the UT with given uIndex.
double GetCarrierBandwidthHz(SatEnums::ChannelType_t chType, uint32_t carrierId, SatEnums::CarrierBandwidthType_t bandwidthType)
Convert carrier id and sequence id to to bandwidth value.
static const uint32_t GW_ID_INDEX
Definition for GW ID index (column) in m_conf.
static const uint32_t BEAM_ID_INDEX
Definition for beam ID index (column) in m_conf.
double GetCarrierFrequencyHz(SatEnums::ChannelType_t chType, uint32_t freqId, uint32_t carrierId)
Convert carrier id, sequency id and frequency id to real frequency value.
static const uint32_t U_FREQ_ID_INDEX
Definition for user frequency ID index (column) in m_conf.
static const uint32_t F_FREQ_ID_INDEX
Definition for feeder frequency ID index (column) in m_conf.
void PrintTopology(std::ostream &os) const
Print all the satellite topology.
void CreateConstellationScenario(BeamUserInfoMap_t &info, GetNextUtUserCountCallback getNextUtUserCountCallback)
Creates satellite objects according to constellation parameters.
void LoadMobileUTsFromFolder(uint32_t satId, const std::string &folderName, Ptr< RandomVariableStream > utUsers)
Load UTs with a SatTracedMobilityModel associated to them from the files found in the given folder.
void LoadConstellationTopology(std::string path, std::vector< std::string > &tles, std::vector< std::pair< uint32_t, uint32_t >> &isls)
Load a constellation topology.
Ptr< SatUserHelper > GetUserHelper() const
void CreatePredefinedScenario(PreDefinedScenario_t scenario)
Create a pre-defined SatHelper to make life easier when creating Satellite topologies.
Ptr< Node > LoadMobileUtFromFile(uint32_t satId, const std::string &filename)
Load an UT with a SatTracedMobilityModel associated to them from the given file.
Ipv4Mask m_beamNetworkMask
Network mask number of satellite devices.
std::string m_utCreationFileName
File name for UT creation trace output.
SatHelper()
Create a base SatHelper for creating customized Satellite topologies.
static void CreationDetailsSink(Ptr< OutputStreamWrapper > stream, std::string context, std::string info)
Sink for creation details traces.
SatEnums::Standard_t m_standard
std::multimap< uint32_t, uint32_t > m_mobileUtsUsersByBeam
List of users by mobile UT by beam ID.
void SetUtMobilityFromPosition(NodeContainer uts, uint32_t satId, uint32_t beamId, std::vector< std::pair< GeoCoordinate, uint32_t >> positionsAndGroupId)
Sets mobility to created UT nodes when position is known.
Ptr< SatSpotBeamPositionAllocator > GetBeamAllocator(uint32_t beamId)
Create a SatSpotBeamPositionAllocator able to generate random position within the given beam.
Ipv4Address m_beamNetworkAddress
Initial network number of satellite devices, e.g., 10.1.1.0.
void CreateLargerScenario()
Creates satellite objects according to larger scenario.
Ipv4Address m_gwNetworkAddress
Initial network number of GW, router, and GW users, e.g., 10.2.1.0.
Callback< uint32_t > GetNextUtUserCountCallback
Get number of Users for a UT.
void CheckNetwork(std::string networkName, const Ipv4Address &firstNetwork, const Ipv4Mask &mask, const std::set< uint32_t > &networkAddresses, uint32_t networkCount, uint32_t hostCount) const
Check validity of the configured network space.
Ipv4Mask m_utNetworkMask
Network mask number of UT and UT users.
void InstallMobilityObserver(uint32_t satId, NodeContainer nodes) const
Install Satellite Mobility Observer to nodes, if observer doesn't exist already in a node.
static TypeId GetTypeId(void)
Get the type ID.
std::string m_scenarioCreationFileName
File name for scenario creation trace output.
BeamUserInfoMap_t m_beamUserInfos
Info for beam creation in user defined scenario.
void DoCreateScenario(BeamUserInfoMap_t &info, uint32_t gwUsers)
Creates satellite objects according to given beam info.
uint32_t m_utsInBeam
Number of UTs created per Beam in full or user-defined scenario.
bool m_satMobilitySGP4Enabled
The satellite moves following a SGP4 model.
std::string m_gwPosFileName
Ipv4Address GetUserAddress(Ptr< Node > node)
void SetCustomUtPositionAllocator(Ptr< SatListPositionAllocator > posAllocator)
Set custom position allocator.
void SetGroupHelper(Ptr< SatGroupHelper > groupHelper)
set the group helper.
std::string m_fwdConfFileName
NodeContainer GwNodes()
bool m_creationTraces
flag to indicate if creation trace should be enabled for scenario creation.
void SetBeamRoutingConstellations()
Populate the routes, when using constellations.
SatBeamHelper::MulticastBeamInfo_t MulticastBeamInfo_t
std::map< Ptr< Node >, Ptr< Node > > m_gwDistribution
Map indicating the GW node associated to each UT node.
static const uint16_t MAX_ADDRESS_PREFIX_LENGTH
TypeId GetInstanceTypeId(void) const
Get the type ID of object instance.
Ptr< SatConf > m_satConf
Configuration for satellite network.
void SetAntennaGainPatterns(Ptr< SatAntennaGainPatternContainer > antennaGainPattern)
Set the antenna gain patterns.
Ptr< OutputStreamWrapper > m_creationTraceStream
Stream wrapper used for creation traces.
bool ConstructMulticastInfo(Ptr< Node > sourceUtNode, NodeContainer receivers, MulticastBeamInfo_t &beamInfo, Ptr< NetDevice > &routerUserOutputDev)
Construct multicast information from source UT node and group receivers.
std::string m_rtnConfFileName
Configuration file names as attributes of this class.
bool m_packetTraces
flag to indicate if packet trace should be enabled after scenario creation.
PreDefinedScenario_t
Values for pre-defined scenarios to be used by helper when building satellite network topology base.
@ LARGER
LARGER Larger scenario used as base.
@ FULL
FULL Full scenario used as base.
@ SIMPLE
SIMPLE Simple scenario used as base.
Ptr< SatAntennaGainPatternContainer > GetAntennaGainPatterns()
TracedCallback< std::string > m_creationSummaryTrace
Trace callback for creation traces (summary)
void SetUtMobility(NodeContainer uts, uint32_t satId, uint32_t beamId)
Sets mobility to created UT nodes.
void EnableCreationTraces()
Enables creation traces to be written in given file.
bool m_detailedCreationTraces
flag to indicate if detailed creation trace should be enabled for scenario creation.
void CreationSummarySink(std::string title)
Sink for creation summary traces.
std::string CreateCreationSummary(std::string title)
Creates trace summary starting with give title.
Ptr< OutputStreamWrapper > m_utTraceStream
Stream wrapper used for UT position traces.
void SetGwMobility(uint32_t satId, Ptr< Node > gw, uint32_t gwIndex)
Sets mobilities to created GW nodes.
Ptr< SatUserHelper > m_userHelper
User helper.
NodeContainer GetGwUsers() const
std::string m_geoPosFileName
NodeContainer UtNodes()
void SetUtPositionAllocatorForBeam(uint32_t beamId, Ptr< SatListPositionAllocator > posAllocator)
Set custom position allocator for specific beam.
void EnablePacketTrace()
Enable packet traces.
void SetGeoSatMobility(Ptr< Node > node)
Sets mobility to created Sat Geo node.
uint32_t GetBeamCount() const
Get count of the beams (configurations).
SatBeamHelper::MulticastBeamInfoItem_t MulticastBeamInfoItem_t
void CreateUserDefinedScenarioFromListPositions(uint32_t satId, BeamUserInfoMap_t &info, bool checkBeam)
Creates satellite objects according to user defined scenario.
void SetSatMobility(Ptr< Node > node, std::string tle="")
Sets SGP4 mobility to created Sat node.
Ptr< SatAntennaGainPatternContainer > m_antennaGainPatterns
Antenna gain patterns for all spot-beams.
void CreateFullScenario()
Creates satellite objects according to full scenario.
std::map< uint32_t, NodeContainer > m_mobileUtsByBeam
List of mobile UTs by beam ID.
Ptr< SatGroupHelper > GetGroupHelper() const
void CreateSimpleScenario()
Creates satellite objects according to simple scenario.
bool m_scenarioCreated
flag to check if scenario is already created.
Ptr< SatGroupHelper > m_groupHelper
Group helper.
void SetNetworkAddresses(BeamUserInfoMap_t &info, uint32_t gwUsers) const
Set configured network addresses to user and beam helpers.
void SetMulticastRouteToSourceNetwork(Ptr< Node > source, Ptr< Node > destination)
Set multicast traffic to source's nwtwork by finding source network utilizing given destination node.
Ipv4Address m_utNetworkAddress
Initial network number of UT and UT users, e.g., 10.3.1.0.
uint32_t GetClosestSat(GeoCoordinate position)
Get closest satellite to a ground station.
uint32_t m_utUsers
Number of users created in end user network (behind every UT) in full or user-defined scenario.
Ptr< NetDevice > FindMatchingDevice(Ptr< NetDevice > devA, Ptr< Node > nodeB)
Find given device's counterpart (device belonging to same network) device from given node.
void SetGwAddressInUt()
Set the value of GW address for each UT.
TracedCallback< std::string > m_creationDetailsTrace
Trace callback for creation traces (details)
std::map< std::pair< uint32_t, uint32_t >, SatBeamUserInfo > BeamUserInfoMap_t
definition for beam map key is pair sat ID / beam ID and value is UT/user info.
NodeContainer GetUtUsers() const
static const uint16_t MIN_ADDRESS_PREFIX_LENGTH
std::map< uint32_t, Ptr< SatListPositionAllocator > > m_utPositionsByBeam
User defined UT positions by beam ID.
Ipv4Mask m_gwNetworkMask
Network mask number of GW, router, and GW users.
std::string m_waveformConfFileName
bool FindMatchingDevices(Ptr< Node > nodeA, Ptr< Node > nodeB, std::pair< Ptr< NetDevice >, Ptr< NetDevice >> &matchingDevices)
Find counterpart (device belonging to same network) devices from given nodes.
Ptr< SatBeamHelper > m_beamHelper
Beam helper.
void CreateUserDefinedScenario(BeamUserInfoMap_t &info)
Creates satellite objects according to user defined scenario.
std::string m_satMobilitySGP4TleFileName
TLE input filename used for SGP4 mobility.
void DoDispose()
Dispose of this class instance.
std::map< Ptr< NetDevice >, NetDeviceContainer > m_utsDistribution
Map indicating all UT NetDevices associated to each GW NetDevice.
std::map< uint32_t, uint32_t > m_gwSats
Map of closest satellite for each GW.
void SetMulticastGroupRoutes(Ptr< Node > source, NodeContainer receivers, Ipv4Address sourceAddress, Ipv4Address groupAddress)
Set multicast group to satellite network and IP router.
uint32_t m_gwUsers
Number of users created in public network (behind GWs) in full or user-defined scenario.
Ptr< SatBeamHelper > GetBeamHelper() const
bool m_satConstellationEnabled
Use a constellation of satellites.
std::string m_satConstellationFolder
Folder where are stored satellite constellation data.
void EnableDetailedCreationTraces()
Enables creation traces in sub-helpers.
Ptr< SatListPositionAllocator > m_utPositions
User defined UT positions from SatConf (or manually set)
@ LOG_WARNING
LOG_WARNING.
Definition: satellite-log.h:64
A configuration class for the GEO satellite reference system.
void setSatConfAttributes(Ptr< SatConf > satConf)
SatLorawanNetDevice to be utilized in the UT and GW nodes for IoT configuration.
Keep track of the current position and velocity of an object in satellite network.
Observes given mobilities and keeps track of certain wanted properties.
Ptr< SatMac > GetMac(void) const
Get a Mac pointer.
Keep track of the current position and velocity of satellite using SGP4 model.
Satellite mobility model for which the current position change based on values read from a file.
Callback< Ptr< PropagationDelayModel >, uint32_t, uint32_t, SatEnums::ChannelType_t > PropagationDelayCallback
void UpdateGwRoutes(Address ut, Address oldGateway, Address newGateway)
Update ARP cache and default route on the terrestrial network so packets are properly routed to the U...
void UpdateUtRoutes(Address ut, Address newGateway)
Update ARP cache and default route on an UT so packets are properly routed to the new GW as their nex...
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Ptr< SatMobilityModel > satMobility