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>
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>
67 NS_LOG_COMPONENT_DEFINE(
"SatHelper");
72 NS_OBJECT_ENSURE_REGISTERED(SatHelper);
78 TypeId(
"ns3::SatHelper")
80 .AddConstructor<SatHelper>()
81 .AddAttribute(
"UtCount",
82 "The count of created UTs in beam (full or user-defined GEO scenario)",
85 MakeUintegerChecker<uint32_t>(1))
86 .AddAttribute(
"GwUsers",
87 "The number of created GW users (full or user-defined scenario)",
90 MakeUintegerChecker<uint32_t>(1))
91 .AddAttribute(
"UtUsers",
92 "The number of created UT users per UT (full or user-defined scenario)",
95 MakeUintegerChecker<uint32_t>(1))
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"),
103 MakeIpv4AddressChecker())
104 .AddAttribute(
"BeamNetworkMask",
105 "Network mask to use during allocation of satellite devices.",
106 Ipv4MaskValue(
"255.255.0.0"),
108 MakeIpv4MaskChecker())
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"),
116 MakeIpv4AddressChecker())
117 .AddAttribute(
"GwNetworkMask",
118 "Network mask to use during allocation of GW, router, and GW users.",
119 Ipv4MaskValue(
"255.255.0.0"),
121 MakeIpv4MaskChecker())
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"),
129 MakeIpv4AddressChecker())
130 .AddAttribute(
"UtNetworkMask",
131 "Network mask to use during allocation of UT and UT users.",
132 Ipv4MaskValue(
"255.255.0.0"),
134 MakeIpv4MaskChecker())
135 .AddAttribute(
"HandoversEnabled",
136 "Enable handovers for all UTs and GWs. If false, only moving UTs can "
137 "perform handovers.",
140 MakeBooleanChecker())
141 .AddAttribute(
"PacketTraceEnabled",
142 "Packet tracing enable status.",
145 MakeBooleanChecker())
146 .AddAttribute(
"ScenarioCreationTraceEnabled",
147 "Scenario creation trace output enable status.",
150 MakeBooleanChecker())
151 .AddAttribute(
"DetailedScenarioCreationTraceEnabled",
152 "Detailed scenario creation trace output enable status.",
155 MakeBooleanChecker())
156 .AddAttribute(
"ScenarioCreationTraceFileName",
157 "File name for the scenario creation trace output",
158 StringValue(
"CreationTraceScenario"),
161 .AddAttribute(
"UtCreationTraceFileName",
162 "File name for the UT creation trace output",
163 StringValue(
"CreationTraceUt"),
166 .AddTraceSource(
"Creation",
169 "ns3::SatTypedefs::CreationCallback")
170 .AddTraceSource(
"CreationSummary",
171 "Creation summary traces",
173 "ns3::SatTypedefs::CreationCallback");
180 NS_LOG_FUNCTION(
this);
187 NS_LOG_FUNCTION(
this);
189 NS_FATAL_ERROR(
"Constructor not in use");
193 : m_satConstellationEnabled(false),
194 m_handoversEnabled(false),
195 m_scenarioCreated(false),
196 m_creationTraces(false),
197 m_detailedCreationTraces(false),
198 m_packetTraces(false),
202 m_utPositionsByBeam(),
204 m_mobileUtsUsersByBeam()
206 NS_LOG_FUNCTION(
this << scenarioPath);
221 if (Singleton<SatEnvVariables>::Get()->IsValidFile(
m_scenarioPath +
"/positions/tles.txt"))
223 NS_ASSERT_MSG(!Singleton<SatEnvVariables>::Get()->IsValidFile(
225 "position subfolder of scenario cannot have both contain tles.txt and "
226 "sat_positions.txt");
229 else if (!Singleton<SatEnvVariables>::Get()->IsValidFile(
m_scenarioPath +
230 "/positions/sat_positions.txt"))
232 NS_FATAL_ERROR(
"position subfolder of scenario must contain tles.txt or sat_positions.txt");
236 ObjectBase::ConstructSelf(AttributeConstructionList());
238 Singleton<SatEnvVariables>::Get()->Initialize();
239 Singleton<SatIdMapper>::Get()->Reset();
240 Singleton<SatTopology>::Get()->Reset();
250 std::vector<std::pair<uint32_t, uint32_t>> isls;
254 std::vector<std::string> tles;
258 if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() !=
261 NS_FATAL_ERROR(
"Forward regeneration must be network when using constellations");
263 if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() !=
266 NS_FATAL_ERROR(
"Return regeneration must be network when using constellations");
270 CreateObject<SatAntennaGainPatternContainer>(tles.size(),
273 for (uint32_t i = 0; i < tles.size(); i++)
276 Ptr<Node> satNode = CreateObject<Node>();
283 Singleton<SatTopology>::Get()->AddOrbiterNode(satNode);
289 CreateObject<SatAntennaGainPatternContainer>(1,
m_scenarioPath +
"/antennapatterns");
301 Ptr<Node> satNode = CreateObject<Node>();
308 Singleton<SatTopology>::Get()->AddOrbiterNode(satNode);
312 CreateObject<SatBeamHelper>(isls,
320 Ptr<SatRtnLinkTime> rtnTime = Singleton<SatRtnLinkTime>::Get();
321 rtnTime->Initialize(
m_satConf->GetSuperframeSeq());
325 m_beamHelper->SetAttribute(
"CarrierFrequencyConverter", CallbackValue(converterCb));
330 m_userHelper->SetAttribute(
"PropagationDelayGetter", CallbackValue(delayModelCb));
336 NS_LOG_FUNCTION(
this);
353 NS_FATAL_ERROR(
"Not supported predefined scenario.");
361 NS_LOG_FUNCTION(
this);
363 AsciiTraceHelper asciiTraceHelper;
365 std::stringstream outputPathCreation;
366 std::stringstream outputPathUt;
367 outputPathCreation << Singleton<SatEnvVariables>::Get()->GetOutputPath() <<
"/"
369 outputPathUt << Singleton<SatEnvVariables>::Get()->GetOutputPath() <<
"/"
373 m_utTraceStream = asciiTraceHelper.CreateFileStream(outputPathUt.str());
375 TraceConnectWithoutContext(
"CreationSummary",
392 std::vector<std::pair<uint32_t, uint32_t>>& isls)
394 NS_LOG_FUNCTION(
this);
409 if (Singleton<SatEnvVariables>::Get()->IsValidFile(
m_scenarioPath +
"/positions/isls.txt"))
418 NS_LOG_FUNCTION(
this);
420 CallbackBase creationCb =
422 TraceConnect(
"Creation",
"SatHelper", creationCb);
431 NS_LOG_FUNCTION(
this);
433 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
435 return ipv4->GetAddress(1, 0)
442 NS_LOG_FUNCTION(
this);
449 NS_LOG_FUNCTION(
this);
456 NS_LOG_FUNCTION(
this << groupHelper);
463 NS_LOG_FUNCTION(
this);
467 Ptr<SatAntennaGainPatternContainer>
476 NS_LOG_FUNCTION(
this);
483 NS_LOG_FUNCTION(
this);
491 NS_LOG_FUNCTION(
this);
495 beamUserInfos[std::make_pair(0, 8)] = beamInfo;
505 NS_LOG_FUNCTION(
this);
511 beamUserInfos[std::make_pair(0, 12)] = beamInfo;
512 beamUserInfos[std::make_pair(0, 22)] = beamInfo;
518 beamUserInfos[std::make_pair(0, 3)] = beamInfo;
528 NS_LOG_FUNCTION(
this);
530 uint32_t beamCount =
m_satConf->GetBeamCount();
533 for (uint32_t i = 1; i < (beamCount + 1); i++)
535 BeamUserInfoMap_t::iterator beamInfo =
m_beamUserInfos.find(std::make_pair(0, i));
540 info = beamInfo->second;
547 beamUserInfos[std::make_pair(0, i)] = info;
558 NS_LOG_FUNCTION(
this);
569 NS_LOG_FUNCTION(
this);
575 Ptr<SatListPositionAllocator> posAllocator)
577 NS_LOG_FUNCTION(
this << beamId);
584 std::string inputFileUtListPositions,
587 NS_LOG_FUNCTION(
this);
589 uint32_t positionIndex = 1;
600 for (BeamUserInfoMap_t::iterator it = infos.begin(); it != infos.end(); it++)
602 for (uint32_t i = 0; i < it->second.GetUtCount(); i++)
604 if (positionIndex >
m_satConf->GetUtCount())
606 NS_FATAL_ERROR(
"Not enough positions available in SatConf for UTs!!!");
618 if (bestBeamId != it->first.second)
620 NS_FATAL_ERROR(
"The beam: " << it->first <<
" is not the best beam ("
622 <<
") for the position: " << position);
638 NS_LOG_FUNCTION(
this);
640 NS_ASSERT_MSG(info.size() > 0,
"There must be at least one beam satellite");
644 for (uint32_t i = 0; i <
m_satConf->GetUtCount(); i++)
648 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(position);
654 NS_LOG_WARN(
"UT at " << position <<
" is too far away from any beam");
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);
666 for (uint32_t i = 0; i <
m_satConf->GetGwCount(); i++)
669 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(position);
680 NS_LOG_FUNCTION(
this);
684 Singleton<SatLog>::Get()->AddToLog(
687 "Scenario tried to re-create with SatHelper. Creation can be done only once.");
701 InternetStackHelper internet;
704 NodeContainer gwNodes;
706 internet.Install(gwNodes);
710 std::set<uint32_t> beams;
713 for (BeamUserInfoMap_t::iterator info = beamInfos.begin(); info != beamInfos.end(); info++)
715 uint32_t satId = info->first.first;
716 uint32_t beamId = info->first.second;
718 beams.insert(beamId);
721 std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId =
722 info->second.GetPositions();
724 uts.Create(info->second.GetUtCount() - positionsAndGroupId.size());
727 NodeContainer utsFromPosition;
728 utsFromPosition.Create(positionsAndGroupId.size());
730 uts.Add(utsFromPosition);
733 std::map<uint32_t, NodeContainer>::iterator mobileUts =
m_mobileUtsByBeam.find(beamId);
736 uts.Add(mobileUts->second);
740 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
742 Singleton<SatTopology>::Get()->AddUtNode(*it);
746 internet.Install(uts);
748 for (uint32_t i = 0; i < info->second.GetUtCount(); ++i)
751 m_userHelper->InstallUt(uts.Get(i), info->second.GetUtUserCount(i));
754 std::pair<std::multimap<uint32_t, uint32_t>::iterator,
755 std::multimap<uint32_t, uint32_t>::iterator>
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;
766 std::vector<uint32_t> rtnConf =
768 std::vector<uint32_t> fwdConf =
781 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
783 Singleton<SatTopology>::Get()->ConnectGwToUt(*it, gwNode);
788 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
790 (*it)->AggregateObject(CreateObject<SatHandoverModule>(
792 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
797 std::pair<Ptr<NetDevice>, NetDeviceContainer> netDevices =
810 Ptr<NetDevice> gwNetDevice = netDevices.first;
811 NetDeviceContainer utNetDevices = netDevices.second;
813 Ptr<SatGwMac> gwMac =
814 DynamicCast<SatGwMac>(DynamicCast<SatNetDevice>(gwNetDevice)->GetMac());
815 uint32_t feederSatId;
816 uint32_t feederBeamId;
817 if (gwMac !=
nullptr)
819 feederSatId = gwMac->GetFeederSatId();
820 feederBeamId = gwMac->GetFeederBeamId();
828 NetDeviceContainer::Iterator itNd;
829 for (itNd = utNetDevices.Begin(); itNd != utNetDevices.End(); itNd++)
831 Ptr<SatMac> mac = DynamicCast<SatMac>(DynamicCast<SatNetDevice>(*itNd)->GetMac());
832 if (mac !=
nullptr && gwMac !=
nullptr)
834 gwMac->ConnectUt(Mac48Address::ConvertFrom((*itNd)->GetAddress()));
838 DynamicCast<SatOrbiterNetDevice>(
839 Singleton<SatTopology>::Get()->GetOrbiterNode(feederSatId)->GetDevice(0))
840 ->ConnectGw(Mac48Address::ConvertFrom(netDevices.first->GetAddress()),
851 for (uint32_t utIndex = 0; utIndex < uts.GetN(); utIndex++)
853 DynamicCast<SatOrbiterNetDevice>(
854 Singleton<SatTopology>::Get()->GetOrbiterNode(satId)->GetDevice(0))
856 Mac48Address::ConvertFrom(netDevices.second.Get(utIndex)->GetAddress()),
872 for (uint32_t beamId : beams)
874 std::vector<uint32_t> fwdConf =
876 Ptr<Node> gwNode = gwNodes.Get(
879 Singleton<SatTopology>::Get()->ConnectGwToBeam(beamId, gwNode);
889 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
891 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
895 for (uint32_t j = 0; j < ut->GetNDevices(); j++)
897 Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(ut->GetDevice(j));
900 Ptr<SatMac> mac = netDevice->GetMac();
904 Ptr<SatUtMac> utMac = DynamicCast<SatUtMac>(mac);
905 utMac->SetUpdateIslCallback(
910 Ptr<LorawanMacEndDevice> endDeviceMac =
911 DynamicCast<LorawanMacEndDevice>(mac);
912 endDeviceMac->SetUpdateIslCallback(
917 NS_FATAL_ERROR(
"Unknown standard");
924 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
928 for (uint32_t j = 0; j < gw->GetNDevices(); j++)
930 Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(gw->GetDevice(j));
933 Ptr<SatGwMac> mac = DynamicCast<SatGwMac>(netDevice->GetMac());
934 mac->SetUpdateIslCallback(
945 uint32_t nwkAddr = 1864;
946 Ptr<LoraDeviceAddressGenerator> addrGen =
947 CreateObject<LoraDeviceAddressGenerator>(nwkId, nwkAddr);
949 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
951 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
956 addrGen->NextAddress());
959 Ptr<LoraNetworkServerHelper> loraNetworkServerHelper =
960 CreateObject<LoraNetworkServerHelper>();
961 Ptr<LoraForwarderHelper> forHelper = CreateObject<LoraForwarderHelper>();
963 NodeContainer networkServer;
964 networkServer.Create(1);
966 loraNetworkServerHelper->Install(networkServer);
968 forHelper->Install(Singleton<SatTopology>::Get()->GetGwNodes());
985 NS_LOG_FUNCTION(
this);
988 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
990 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
993 Mac48Address gwAddress = Singleton<SatTopology>::Get()->GetGwAddressInUt(ut->GetId());
998 Singleton<SatTopology>::Get()->GetDvbUtMac(ut)->SetGwAddress(gwAddress);
1002 Singleton<SatTopology>::Get()->GetLoraUtMac(ut)->SetGwAddress(gwAddress);
1006 NS_FATAL_ERROR(
"Unknown standard");
1015 NS_LOG_FUNCTION(
this);
1017 NodeContainer gwNodes = Singleton<SatTopology>::Get()->GetGwNodes();
1018 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
1021 for (uint32_t ndId = 0; ndId < gw->GetNDevices(); ndId++)
1023 if (DynamicCast<SatNetDevice>(gw->GetDevice(ndId)))
1025 Ptr<SatNetDevice> gwNd = DynamicCast<SatNetDevice>(gw->GetDevice(ndId));
1029 for (uint32_t i = 0; i < utNd.GetN(); i++)
1031 ut.Add(utNd.Get(i)->GetNode());
1033 m_userHelper->PopulateBeamRoutings(ut, utNd, gw, gwNd);
1042 NS_LOG_FUNCTION(
this << folderName << utUsers);
1044 if (!(Singleton<SatEnvVariables>::Get()->IsValidDirectory(folderName)))
1046 NS_LOG_INFO(
"Directory '" << folderName
1047 <<
"' does not exist, no mobile UTs will be created.");
1051 for (std::string& filename : SystemPath::ReadFiles(folderName))
1053 std::string filepath = folderName +
"/" + filename;
1054 if (Singleton<SatEnvVariables>::Get()->IsValidDirectory(filepath))
1056 NS_LOG_INFO(
"Skipping directory '" << filename <<
"'");
1064 std::map<uint32_t, NodeContainer>::iterator it =
m_mobileUtsByBeam.find(bestBeamId);
1067 std::pair<std::map<uint32_t, NodeContainer>::iterator,
bool> inserted =
1069 NS_ASSERT_MSG(inserted.second,
1070 "Failed to create a new beam when reading UT mobility files");
1074 it->second.Add(utNode);
1083 NS_LOG_INFO(
"Installing Mobility Observers for mobile UTs starting in beam "
1084 << mobileUtsForBeam.first);
1092 NS_LOG_FUNCTION(
this << filename);
1094 if (Singleton<SatEnvVariables>::Get()->IsValidFile(
1095 Singleton<SatEnvVariables>::Get()->LocateDataDirectory() +
"/" + filename))
1097 NS_FATAL_ERROR(filename <<
" is not a valid file name");
1101 Singleton<SatPositionInputTraceContainer>::Get()->GetPosition(filename,
1103 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(initialPosition);
1106 Ptr<SatTracedMobilityModel> mobility =
1109 Ptr<Node> utNode = CreateObject<Node>();
1110 utNode->AggregateObject(mobility);
1113 utNode->AggregateObject(
1114 CreateObject<SatHandoverModule>(utNode,
1115 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
1124 NS_LOG_FUNCTION(
this << satId << filename);
1126 if (Singleton<SatEnvVariables>::Get()->IsValidFile(
1127 Singleton<SatEnvVariables>::Get()->LocateDataDirectory() +
"/" + filename))
1129 NS_FATAL_ERROR(filename <<
" is not a valid file name");
1133 Ptr<SatTracedMobilityModel> mobility =
1136 Ptr<Node> utNode = CreateObject<Node>();
1137 utNode->AggregateObject(mobility);
1140 utNode->AggregateObject(
1141 CreateObject<SatHandoverModule>(utNode,
1142 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
1151 NS_LOG_FUNCTION(
this);
1153 MobilityHelper mobility;
1155 Ptr<SatListPositionAllocator> gwPosAllocator = CreateObject<SatListPositionAllocator>();
1157 for (uint32_t i = 0; i < gwNodes.GetN(); i++)
1160 gwPosAllocator->Add(
m_satConf->GetGwPosition(i + 1));
1163 mobility.SetPositionAllocator(gwPosAllocator);
1164 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1165 mobility.Install(gwNodes);
1167 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
1169 Ptr<Node> gwNode = *it;
1173 uint32_t gwSatId = Singleton<SatTopology>::Get()->GetClosestSat(
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);
1198 NS_LOG_FUNCTION(
this);
1200 MobilityHelper mobility;
1202 Ptr<SatPositionAllocator> allocator;
1220 mobility.SetPositionAllocator(allocator);
1221 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1222 mobility.Install(uts);
1226 for (uint32_t i = 0; i < uts.GetN(); ++i)
1229 NS_LOG_INFO(
"Installing mobility observer on Ut Node at "
1230 << position <<
" with antenna gain of "
1233 Singleton<SatTopology>::Get()
1234 ->GetOrbiterNode(satId)
1244 std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId)
1246 NS_LOG_FUNCTION(
this << beamId);
1248 MobilityHelper mobility;
1250 Ptr<SatListPositionAllocator> allocator = CreateObject<SatListPositionAllocator>();
1252 NS_ASSERT_MSG(uts.GetN() == positionsAndGroupId.size(),
1253 "Inconsistent number of nodes and positions");
1255 for (uint32_t i = 0; i < positionsAndGroupId.size(); i++)
1257 allocator->Add(positionsAndGroupId[i].first);
1258 m_groupHelper->AddNodeToGroupAfterScenarioCreation(positionsAndGroupId[i].second,
1262 mobility.SetPositionAllocator(allocator);
1263 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1264 mobility.Install(uts);
1268 for (uint32_t i = 0; i < uts.GetN(); ++i)
1271 NS_LOG_INFO(
"Installing mobility observer on Ut Node at "
1272 << position <<
" with antenna gain of "
1275 Singleton<SatTopology>::Get()
1276 ->GetOrbiterNode(satId)
1281 Ptr<SatSpotBeamPositionAllocator>
1284 NS_LOG_FUNCTION(
this << beamId);
1289 satPosition = Singleton<SatTopology>::Get()
1296 satPosition =
m_satConf->GetSatPosition();
1298 Ptr<SatSpotBeamPositionAllocator> beamAllocator =
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;
1311 NS_LOG_FUNCTION(
this << node);
1312 MobilityHelper mobility;
1314 Ptr<SatListPositionAllocator> satPosAllocator = CreateObject<SatListPositionAllocator>();
1315 satPosAllocator->Add(
m_satConf->GetSatPosition());
1317 mobility.SetPositionAllocator(satPosAllocator);
1318 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1319 mobility.Install(node);
1325 NS_LOG_FUNCTION(
this);
1327 Ptr<Object>
object = node;
1329 if (model ==
nullptr)
1331 ObjectFactory mobilityFactory;
1332 mobilityFactory.SetTypeId(
"ns3::SatSGP4MobilityModel");
1334 if (model ==
nullptr)
1336 NS_FATAL_ERROR(
"The requested mobility model is not a mobility model: \""
1337 << mobilityFactory.GetTypeId().GetName() <<
"\"");
1339 model->SetStartDate(
m_satConf->GetStartTimeStr());
1340 object->AggregateObject(model);
1343 model->SetTleInfo(tle);
1349 NS_LOG_FUNCTION(
this);
1351 for (NodeContainer::Iterator i = nodes.Begin(); i != nodes.End(); i++)
1355 if (observer ==
nullptr)
1359 Singleton<SatTopology>::Get()->GetOrbiterNode(satId)->GetObject<
SatMobilityModel>();
1361 NS_ASSERT(ownMobility !=
nullptr);
1364 observer = CreateObject<SatMobilityObserver>(
1367 Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() !=
1370 (*i)->AggregateObject(observer);
1377 NodeContainer receivers,
1378 Ipv4Address sourceAddress,
1379 Ipv4Address groupAddress)
1381 NS_LOG_FUNCTION(
this);
1384 Ptr<NetDevice> routerUserOutputDev;
1385 Ptr<Node> sourceUtNode = Singleton<SatTopology>::Get()->GetUtNode(source);
1400 destNode = sourceUtNode;
1408 if (!beamInfo.empty() || (sourceUtNode && routerUserOutputDev))
1412 Ptr<NetDevice> routerInputDev =
nullptr;
1413 Ptr<NetDevice> gwOutputDev =
nullptr;
1416 NetDeviceContainer gwInputDevices =
1421 (
bool)routerUserOutputDev,
1424 Ipv4StaticRoutingHelper multicast;
1433 else if (!sourceUtNode)
1438 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1442 routerInputDev = devices.second;
1446 NetDeviceContainer routerOutputDevices;
1448 if (routerUserOutputDev)
1450 routerOutputDevices.Add(routerUserOutputDev);
1453 for (NetDeviceContainer::Iterator it = gwInputDevices.Begin(); it != gwInputDevices.End();
1460 routerOutputDevices.Add(matchingDevice);
1467 if (routerInputDev && (routerOutputDevices.GetN() > 0))
1469 multicast.AddMulticastRoute(routerNode,
1473 routerOutputDevices);
1480 std::string context,
1483 *stream->GetStream() << context <<
", " << info << std::endl;
1489 NS_LOG_FUNCTION(
this);
1498 NS_LOG_FUNCTION(
this);
1500 std::ostringstream oss;
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;
1515 NS_LOG_FUNCTION(
this);
1529 std::pair<Ptr<NetDevice>, Ptr<NetDevice>>& matchingDevices)
1533 for (uint32_t i = 1; ((i < nodeA->GetNDevices()) && !found); i++)
1535 Ptr<NetDevice> devA = nodeA->GetDevice(i);
1540 matchingDevices = std::make_pair(devA, devB);
1551 Ptr<NetDevice> matchingDevice =
nullptr;
1553 Ipv4Address addressA =
1554 devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetLocal();
1556 devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetMask();
1558 Ipv4Address netAddressA = addressA.CombineMask(maskA);
1560 for (uint32_t j = 1; j < nodeB->GetNDevices(); j++)
1562 Ipv4Address addressB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetLocal();
1563 Ipv4Mask maskB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetMask();
1565 Ipv4Address netAddressB = addressB.CombineMask(maskB);
1567 if (netAddressA == netAddressB)
1569 matchingDevice = nodeB->GetDevice(j);
1573 return matchingDevice;
1579 NS_LOG_FUNCTION(
this);
1581 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1585 Ipv4StaticRoutingHelper multicast;
1586 Ptr<Ipv4StaticRouting> staticRouting =
1587 multicast.GetStaticRouting(source->GetObject<ns3::Ipv4>());
1590 bool defaultMulticastRouteExists =
false;
1591 Ipv4Address defMulticastNetwork = Ipv4Address(
"224.0.0.0");
1592 Ipv4Mask defMulticastNetworkMask = Ipv4Mask(
"240.0.0.0");
1594 for (uint32_t i = 0; i < staticRouting->GetNRoutes(); i++)
1596 if (staticRouting->GetRoute(i).GetDestNetwork() == defMulticastNetwork &&
1597 staticRouting->GetRoute(i).GetDestNetworkMask() == defMulticastNetworkMask)
1599 defaultMulticastRouteExists =
true;
1604 if (!defaultMulticastRouteExists)
1606 multicast.SetDefaultMulticastRoute(source, devices.first);
1613 NodeContainer receivers,
1615 Ptr<NetDevice>& routerUserOutputDev)
1617 NS_LOG_FUNCTION(
this);
1619 bool routeToSourceNertwork =
false;
1621 routerUserOutputDev =
nullptr;
1624 for (uint32_t i = 0; i < receivers.GetN(); i++)
1626 Ptr<Node> receiverNode = receivers.Get(i);
1627 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(receiverNode);
1637 if (sourceUtNode == utNode)
1641 routeToSourceNertwork =
true;
1647 MulticastBeamInfo_t::iterator it = beamInfo.find(beamId);
1650 if (it == beamInfo.end())
1652 std::pair<MulticastBeamInfo_t::iterator, bool> result =
1661 NS_FATAL_ERROR(
"Cannot insert beam to map container");
1666 it->second.insert(utNode);
1671 NS_FATAL_ERROR(
"UT node's beam ID is invalid!!");
1676 if (!routerUserOutputDev)
1680 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1684 routerUserOutputDev = devices.second;
1689 routeToSourceNertwork =
true;
1695 NS_FATAL_ERROR(
"Multicast receiver node is expected to be connected UT or GW node!!!");
1699 return routeToSourceNertwork;
1705 NS_LOG_FUNCTION(
this);
1707 std::set<uint32_t> networkAddresses;
1708 std::pair<std::set<uint32_t>::const_iterator,
bool> addressInsertionResult;
1715 if (!addressInsertionResult.second)
1717 NS_FATAL_ERROR(
"GW network address is invalid (same as Beam network address)");
1722 if (!addressInsertionResult.second)
1724 NS_FATAL_ERROR(
"UT network address is invalid (same as Beam or GW network address)");
1728 uint32_t utNetworkAddressCount = 0;
1729 uint32_t utHostAddressCount = 0;
1730 uint32_t beamHostAddressCount = 0;
1731 uint32_t gwNetworkAddressCount = 1;
1733 std::set<uint32_t> gwIds;
1735 for (BeamUserInfoMap_t::const_iterator it = info.begin(); it != info.end(); it++)
1737 uint32_t beamUtCount = it->second.GetUtCount();
1738 utNetworkAddressCount += beamUtCount;
1740 if (beamUtCount > beamHostAddressCount)
1742 beamHostAddressCount = beamUtCount;
1745 for (uint32_t i = 0; i < beamUtCount; i++)
1747 if (it->second.GetUtUserCount(i) > utHostAddressCount)
1749 utHostAddressCount = it->second.GetUtUserCount(i);
1755 if (gwIds.insert(
m_beamHelper->GetGwId(it->first.first, it->first.second)).second)
1757 gwNetworkAddressCount++;
1767 beamHostAddressCount);
1772 gwNetworkAddressCount,
1778 utNetworkAddressCount,
1779 utHostAddressCount);
1789 const Ipv4Address& firstNetwork,
1790 const Ipv4Mask& mask,
1791 const std::set<uint32_t>& networkAddresses,
1792 uint32_t networkCount,
1793 uint32_t hostCount)
const
1795 NS_LOG_FUNCTION(
this);
1797 uint16_t addressPrefixLength = mask.GetPrefixLength();
1803 NS_FATAL_ERROR(networkName
1804 <<
" network mask value out of range (0xFFFFFF70 to 0x10000000).");
1808 if ((firstNetwork.Get() & mask.GetInverse()) != 0)
1810 NS_FATAL_ERROR(networkName <<
" network address and mask inconsistent.");
1813 std::set<uint32_t>::const_iterator currentAddressIt = networkAddresses.find(firstNetwork.Get());
1816 if (currentAddressIt != networkAddresses.end())
1820 uint32_t hostAddressCount = std::pow(2, (32 - addressPrefixLength)) - 2;
1821 uint32_t firstAddressValue = firstNetwork.Get();
1822 uint32_t networkAddressCount =
1823 mask.Get() - firstAddressValue +
1831 if ((currentAddressIt != networkAddresses.end()) &&
1832 (firstAddressValue + (networkCount << (32 - addressPrefixLength))) >= *currentAddressIt)
1834 NS_FATAL_ERROR(networkName <<
" network's addresses overlaps with some other network)");
1838 if (networkCount > networkAddressCount)
1840 NS_FATAL_ERROR(
"Not enough network addresses for '" << networkName <<
"' network");
1844 if (hostCount > hostAddressCount)
1846 NS_FATAL_ERROR(
"Not enough host addresses for '" << networkName <<
"' network");
1851 NS_FATAL_ERROR(networkName
1852 <<
"network's initial address number not among of the given addresses");
1859 NS_LOG_FUNCTION(
this << pathName);
1862 std::ifstream* ifs =
new std::ifstream(pathName.c_str(), std::ifstream::in);
1864 if (!ifs->is_open())
1868 pathName =
"../../" + pathName;
1869 ifs =
new std::ifstream(pathName.c_str(), std::ifstream::in);
1871 if (!ifs->is_open())
1873 NS_FATAL_ERROR(
"The file " << pathName <<
" is not found.");
1877 std::string standardString;
1878 *ifs >> standardString;
1883 if (standardString ==
"DVB")
1887 else if (standardString ==
"LORA")
1893 NS_FATAL_ERROR(
"Unknown standard: " << standardString <<
". Must be DVB or LORA");
1896 Singleton<SatTopology>::Get()->SetStandard(
m_standard);
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.
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