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