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"
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"
67NS_LOG_COMPONENT_DEFINE(
"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");
179 NS_LOG_FUNCTION(
this);
181 NS_FATAL_ERROR(
"Constructor not in use");
198 NS_LOG_FUNCTION(
this << scenarioPath);
216 "/positions/sat_positions.txt"),
217 "position subfolder of scenario cannot have both contain tles.txt and "
218 "sat_positions.txt");
222 "/positions/sat_positions.txt"))
224 NS_FATAL_ERROR(
"position subfolder of scenario must contain tles.txt or sat_positions.txt");
231 NS_LOG_FUNCTION(
this);
233 Object::NotifyConstructionCompleted();
236 Singleton<SatIdMapper>::Get()->Reset();
237 Singleton<SatTopology>::Get()->Reset();
243 Ptr<SatLoraConf> satLoraConf = CreateObject<SatLoraConf>();
244 satLoraConf->setSatConfAttributes(
m_satConf);
247 std::vector<std::pair<uint32_t, uint32_t>> isls;
251 std::vector<std::string> tles;
255 if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() !=
258 NS_FATAL_ERROR(
"Forward regeneration must be network when using constellations");
260 if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() !=
263 NS_FATAL_ERROR(
"Return regeneration must be network when using constellations");
267 CreateObject<SatAntennaGainPatternContainer>(tles.size(),
270 for (uint32_t i = 0; i < tles.size(); i++)
273 Ptr<Node> satNode = CreateObject<Node>();
280 Singleton<SatTopology>::Get()->AddOrbiterNode(satNode);
286 CreateObject<SatAntennaGainPatternContainer>(1,
m_scenarioPath +
"/antennapatterns");
298 Ptr<Node> satNode = CreateObject<Node>();
305 Singleton<SatTopology>::Get()->AddOrbiterNode(satNode);
309 CreateObject<SatBeamHelper>(isls,
317 Ptr<SatRtnLinkTime> rtnTime = Singleton<SatRtnLinkTime>::Get();
318 rtnTime->Initialize(
m_satConf->GetSuperframeSeq());
322 m_beamHelper->SetAttribute(
"CarrierFrequencyConverter", CallbackValue(converterCb));
327 m_userHelper->SetAttribute(
"PropagationDelayGetter", CallbackValue(delayModelCb));
333 NS_LOG_FUNCTION(
this);
350 NS_FATAL_ERROR(
"Not supported predefined scenario.");
358 NS_LOG_FUNCTION(
this);
360 AsciiTraceHelper asciiTraceHelper;
362 std::stringstream outputPathCreation;
363 std::stringstream outputPathUt;
370 m_utTraceStream = asciiTraceHelper.CreateFileStream(outputPathUt.str());
372 TraceConnectWithoutContext(
"CreationSummary",
389 std::vector<std::pair<uint32_t, uint32_t>>& isls)
391 NS_LOG_FUNCTION(
this);
413 NS_LOG_FUNCTION(
this);
415 CallbackBase creationCb =
417 TraceConnect(
"Creation",
"SatHelper", creationCb);
426 NS_LOG_FUNCTION(
this);
428 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
430 return ipv4->GetAddress(1, 0)
437 NS_LOG_FUNCTION(
this);
444 NS_LOG_FUNCTION(
this);
451 NS_LOG_FUNCTION(
this << groupHelper);
458 NS_LOG_FUNCTION(
this);
462Ptr<SatAntennaGainPatternContainer>
471 NS_LOG_FUNCTION(
this);
478 NS_LOG_FUNCTION(
this);
486 NS_LOG_FUNCTION(
this);
490 beamUserInfos[std::make_pair(0, 8)] = beamInfo;
500 NS_LOG_FUNCTION(
this);
506 beamUserInfos[std::make_pair(0, 12)] = beamInfo;
507 beamUserInfos[std::make_pair(0, 22)] = beamInfo;
513 beamUserInfos[std::make_pair(0, 3)] = beamInfo;
523 NS_LOG_FUNCTION(
this);
525 uint32_t beamCount =
m_satConf->GetBeamCount();
528 for (uint32_t i = 1; i < (beamCount + 1); i++)
530 BeamUserInfoMap_t::iterator beamInfo =
m_beamUserInfos.find(std::make_pair(0, i));
535 info = beamInfo->second;
542 beamUserInfos[std::make_pair(0, i)] = info;
553 NS_LOG_FUNCTION(
this);
564 NS_LOG_FUNCTION(
this);
570 Ptr<SatListPositionAllocator> posAllocator)
572 NS_LOG_FUNCTION(
this << beamId);
579 std::string inputFileUtListPositions,
582 NS_LOG_FUNCTION(
this);
584 uint32_t positionIndex = 1;
595 for (BeamUserInfoMap_t::iterator it = infos.begin(); it != infos.end(); it++)
597 for (uint32_t i = 0; i < it->second.GetUtCount(); i++)
599 if (positionIndex >
m_satConf->GetUtCount())
601 NS_FATAL_ERROR(
"Not enough positions available in SatConf for UTs!!!");
613 if (bestBeamId != it->first.second)
615 NS_FATAL_ERROR(
"The beam: " << it->first <<
" is not the best beam ("
617 <<
") for the position: " << position);
633 NS_LOG_FUNCTION(
this);
635 NS_ASSERT_MSG(info.size() > 0,
"There must be at least one beam satellite");
639 for (uint32_t i = 0; i <
m_satConf->GetUtCount(); i++)
643 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(position);
649 NS_LOG_WARN(
"UT at " << position <<
" is too far away from any beam");
653 std::vector<std::pair<GeoCoordinate, uint32_t>> positions =
654 info.at(std::pair(satId, bestBeamId)).GetPositions();
655 positions.push_back(std::make_pair(position, 0));
656 info.at(std::pair(satId, bestBeamId)).SetPositions(positions);
657 uint32_t nbUsers = getNextUtUserCountCallback();
658 info.at(std::pair(satId, bestBeamId)).AppendUt(nbUsers);
661 for (uint32_t i = 0; i <
m_satConf->GetGwCount(); i++)
664 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(position);
675 NS_LOG_FUNCTION(
this);
679 Singleton<SatLog>::Get()->AddToLog(
682 "Scenario tried to re-create with SatHelper. Creation can be done only once.");
696 InternetStackHelper internet;
699 NodeContainer gwNodes;
701 internet.Install(gwNodes);
705 std::set<uint32_t> beams;
708 for (BeamUserInfoMap_t::iterator info = beamInfos.begin(); info != beamInfos.end(); info++)
710 uint32_t satId = info->first.first;
711 uint32_t beamId = info->first.second;
713 beams.insert(beamId);
716 std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId =
717 info->second.GetPositions();
719 uts.Create(info->second.GetUtCount() - positionsAndGroupId.size());
722 NodeContainer utsFromPosition;
723 utsFromPosition.Create(positionsAndGroupId.size());
725 uts.Add(utsFromPosition);
728 std::map<uint32_t, NodeContainer>::iterator mobileUts =
m_mobileUtsByBeam.find(beamId);
731 uts.Add(mobileUts->second);
735 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
737 Singleton<SatTopology>::Get()->AddUtNode(*it);
741 internet.Install(uts);
743 for (uint32_t i = 0; i < info->second.GetUtCount(); ++i)
746 m_userHelper->InstallUt(uts.Get(i), info->second.GetUtUserCount(i));
749 std::pair<std::multimap<uint32_t, uint32_t>::iterator,
750 std::multimap<uint32_t, uint32_t>::iterator>
753 std::multimap<uint32_t, uint32_t>::iterator it = mobileUsers.first;
754 for (uint32_t i = info->second.GetUtCount(); i < uts.GetN() && it != mobileUsers.second;
761 std::vector<uint32_t> rtnConf =
763 std::vector<uint32_t> fwdConf =
776 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
778 Singleton<SatTopology>::Get()->ConnectGwToUt(*it, gwNode);
783 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
785 (*it)->AggregateObject(CreateObject<SatHandoverModule>(
787 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
792 std::pair<Ptr<NetDevice>, NetDeviceContainer> netDevices =
805 Ptr<NetDevice> gwNetDevice = netDevices.first;
806 NetDeviceContainer utNetDevices = netDevices.second;
808 Ptr<SatGwMac> gwMac =
809 DynamicCast<SatGwMac>(DynamicCast<SatNetDevice>(gwNetDevice)->GetMac());
810 uint32_t feederSatId;
811 uint32_t feederBeamId;
812 if (gwMac !=
nullptr)
814 feederSatId = gwMac->GetFeederSatId();
815 feederBeamId = gwMac->GetFeederBeamId();
823 NetDeviceContainer::Iterator itNd;
824 for (itNd = utNetDevices.Begin(); itNd != utNetDevices.End(); itNd++)
826 Ptr<SatMac> mac = DynamicCast<SatMac>(DynamicCast<SatNetDevice>(*itNd)->GetMac());
827 if (mac !=
nullptr && gwMac !=
nullptr)
829 gwMac->ConnectUt(Mac48Address::ConvertFrom((*itNd)->GetAddress()));
833 DynamicCast<SatOrbiterNetDevice>(
834 Singleton<SatTopology>::Get()->GetOrbiterNode(feederSatId)->GetDevice(0))
835 ->ConnectGw(Mac48Address::ConvertFrom(netDevices.first->GetAddress()),
846 for (uint32_t utIndex = 0; utIndex < uts.GetN(); utIndex++)
848 DynamicCast<SatOrbiterNetDevice>(
849 Singleton<SatTopology>::Get()->GetOrbiterNode(satId)->GetDevice(0))
851 Mac48Address::ConvertFrom(netDevices.second.Get(utIndex)->GetAddress()),
867 for (uint32_t beamId : beams)
869 std::vector<uint32_t> fwdConf =
871 Ptr<Node> gwNode = gwNodes.Get(
874 Singleton<SatTopology>::Get()->ConnectGwToBeam(beamId, gwNode);
884 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
886 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
890 for (uint32_t j = 0; j < ut->GetNDevices(); j++)
892 Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(ut->GetDevice(j));
895 Ptr<SatMac> mac = netDevice->GetMac();
899 Ptr<SatUtMac> utMac = DynamicCast<SatUtMac>(mac);
900 utMac->SetUpdateIslCallback(
905 Ptr<LorawanMacEndDevice> endDeviceMac =
906 DynamicCast<LorawanMacEndDevice>(mac);
907 endDeviceMac->SetUpdateIslCallback(
912 NS_FATAL_ERROR(
"Unknown standard");
919 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
923 for (uint32_t j = 0; j < gw->GetNDevices(); j++)
925 Ptr<SatNetDevice> netDevice = DynamicCast<SatNetDevice>(gw->GetDevice(j));
928 Ptr<SatGwMac> mac = DynamicCast<SatGwMac>(netDevice->GetMac());
929 mac->SetUpdateIslCallback(
940 uint32_t nwkAddr = 1864;
941 Ptr<LoraDeviceAddressGenerator> addrGen =
942 CreateObject<LoraDeviceAddressGenerator>(nwkId, nwkAddr);
944 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
946 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
951 addrGen->NextAddress());
954 Ptr<LoraNetworkServerHelper> loraNetworkServerHelper =
955 CreateObject<LoraNetworkServerHelper>();
956 Ptr<LoraForwarderHelper> forHelper = CreateObject<LoraForwarderHelper>();
958 NodeContainer networkServer;
959 networkServer.Create(1);
961 loraNetworkServerHelper->Install(networkServer);
963 forHelper->Install(Singleton<SatTopology>::Get()->GetGwNodes());
980 NS_LOG_FUNCTION(
this);
983 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
985 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
988 Mac48Address gwAddress = Singleton<SatTopology>::Get()->GetGwAddressInUt(ut->GetId());
993 Singleton<SatTopology>::Get()->GetDvbUtMac(ut)->SetGwAddress(gwAddress);
997 Singleton<SatTopology>::Get()->GetLoraUtMac(ut)->SetGwAddress(gwAddress);
1001 NS_FATAL_ERROR(
"Unknown standard");
1010 NS_LOG_FUNCTION(
this);
1012 NodeContainer gwNodes = Singleton<SatTopology>::Get()->GetGwNodes();
1013 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
1016 for (uint32_t ndId = 0; ndId < gw->GetNDevices(); ndId++)
1018 if (DynamicCast<SatNetDevice>(gw->GetDevice(ndId)))
1020 Ptr<SatNetDevice> gwNd = DynamicCast<SatNetDevice>(gw->GetDevice(ndId));
1024 for (uint32_t i = 0; i < utNd.GetN(); i++)
1026 ut.Add(utNd.Get(i)->GetNode());
1028 m_userHelper->PopulateBeamRoutings(ut, utNd, gw, gwNd);
1037 NS_LOG_FUNCTION(
this << folderName << utUsers);
1041 NS_LOG_INFO(
"Directory '" << folderName
1042 <<
"' does not exist, no mobile UTs will be created.");
1046 for (std::string& filename : SystemPath::ReadFiles(folderName))
1048 std::string filepath = folderName +
"/" + filename;
1051 NS_LOG_INFO(
"Skipping directory '" << filename <<
"'");
1059 std::map<uint32_t, NodeContainer>::iterator it =
m_mobileUtsByBeam.find(bestBeamId);
1062 std::pair<std::map<uint32_t, NodeContainer>::iterator,
bool> inserted =
1064 NS_ASSERT_MSG(inserted.second,
1065 "Failed to create a new beam when reading UT mobility files");
1069 it->second.Add(utNode);
1078 NS_LOG_INFO(
"Installing Mobility Observers for mobile UTs starting in beam "
1079 << mobileUtsForBeam.first);
1087 NS_LOG_FUNCTION(
this << filename);
1092 NS_FATAL_ERROR(filename <<
" is not a valid file name");
1096 Singleton<SatPositionInputTraceContainer>::Get()->GetPosition(filename,
1098 uint32_t satId = Singleton<SatTopology>::Get()->GetClosestSat(initialPosition);
1101 Ptr<SatTracedMobilityModel> mobility =
1104 Ptr<Node> utNode = CreateObject<Node>();
1105 utNode->AggregateObject(mobility);
1108 utNode->AggregateObject(
1109 CreateObject<SatHandoverModule>(utNode,
1110 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
1119 NS_LOG_FUNCTION(
this << satId << filename);
1124 NS_FATAL_ERROR(filename <<
" is not a valid file name");
1128 Ptr<SatTracedMobilityModel> mobility =
1131 Ptr<Node> utNode = CreateObject<Node>();
1132 utNode->AggregateObject(mobility);
1135 utNode->AggregateObject(
1136 CreateObject<SatHandoverModule>(utNode,
1137 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
1146 NS_LOG_FUNCTION(
this);
1148 MobilityHelper mobility;
1150 Ptr<SatListPositionAllocator> gwPosAllocator = CreateObject<SatListPositionAllocator>();
1152 for (uint32_t i = 0; i < gwNodes.GetN(); i++)
1155 gwPosAllocator->Add(
m_satConf->GetGwPosition(i + 1));
1158 mobility.SetPositionAllocator(gwPosAllocator);
1159 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1160 mobility.Install(gwNodes);
1162 for (NodeContainer::Iterator it = gwNodes.Begin(); it != gwNodes.End(); it++)
1164 Ptr<Node> gwNode = *it;
1168 uint32_t gwSatId = Singleton<SatTopology>::Get()->GetClosestSat(
1180 Ptr<SatHandoverModule> ho =
1181 CreateObject<SatHandoverModule>(gwNode,
1182 Singleton<SatTopology>::Get()->GetOrbiterNodes(),
1184 NS_LOG_DEBUG(
"Created Handover Module " << ho <<
" for GW node " << gwNode);
1185 gwNode->AggregateObject(ho);
1193 NS_LOG_FUNCTION(
this);
1195 MobilityHelper mobility;
1197 Ptr<SatPositionAllocator> allocator;
1215 mobility.SetPositionAllocator(allocator);
1216 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1217 mobility.Install(uts);
1221 for (uint32_t i = 0; i < uts.GetN(); ++i)
1224 NS_LOG_INFO(
"Installing mobility observer on Ut Node at "
1225 << position <<
" with antenna gain of "
1228 Singleton<SatTopology>::Get()
1229 ->GetOrbiterNode(satId)
1239 std::vector<std::pair<GeoCoordinate, uint32_t>> positionsAndGroupId)
1241 NS_LOG_FUNCTION(
this << beamId);
1243 MobilityHelper mobility;
1245 Ptr<SatListPositionAllocator> allocator = CreateObject<SatListPositionAllocator>();
1247 NS_ASSERT_MSG(uts.GetN() == positionsAndGroupId.size(),
1248 "Inconsistent number of nodes and positions");
1250 for (uint32_t i = 0; i < positionsAndGroupId.size(); i++)
1252 allocator->Add(positionsAndGroupId[i].first);
1253 m_groupHelper->AddNodeToGroupAfterScenarioCreation(positionsAndGroupId[i].second,
1257 mobility.SetPositionAllocator(allocator);
1258 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1259 mobility.Install(uts);
1263 for (uint32_t i = 0; i < uts.GetN(); ++i)
1266 NS_LOG_INFO(
"Installing mobility observer on Ut Node at "
1267 << position <<
" with antenna gain of "
1270 Singleton<SatTopology>::Get()
1271 ->GetOrbiterNode(satId)
1276Ptr<SatSpotBeamPositionAllocator>
1279 NS_LOG_FUNCTION(
this << beamId);
1284 satPosition = Singleton<SatTopology>::Get()
1291 satPosition =
m_satConf->GetSatPosition();
1293 Ptr<SatSpotBeamPositionAllocator> beamAllocator =
1296 Ptr<UniformRandomVariable> altRnd = CreateObject<UniformRandomVariable>();
1297 altRnd->SetAttribute(
"Min", DoubleValue(0.0));
1298 altRnd->SetAttribute(
"Max", DoubleValue(500.0));
1299 beamAllocator->SetAltitude(altRnd);
1300 return beamAllocator;
1306 NS_LOG_FUNCTION(
this << node);
1307 MobilityHelper mobility;
1309 Ptr<SatListPositionAllocator> satPosAllocator = CreateObject<SatListPositionAllocator>();
1310 satPosAllocator->Add(
m_satConf->GetSatPosition());
1312 mobility.SetPositionAllocator(satPosAllocator);
1313 mobility.SetMobilityModel(
"ns3::SatConstantPositionMobilityModel");
1314 mobility.Install(node);
1320 NS_LOG_FUNCTION(
this);
1322 Ptr<Object>
object = node;
1324 if (model ==
nullptr)
1326 ObjectFactory mobilityFactory;
1327 mobilityFactory.SetTypeId(
"ns3::SatSGP4MobilityModel");
1329 if (model ==
nullptr)
1331 NS_FATAL_ERROR(
"The requested mobility model is not a mobility model: \""
1332 << mobilityFactory.GetTypeId().GetName() <<
"\"");
1335 object->AggregateObject(model);
1344 NS_LOG_FUNCTION(
this);
1346 for (NodeContainer::Iterator i = nodes.Begin(); i != nodes.End(); i++)
1350 if (observer ==
nullptr)
1354 Singleton<SatTopology>::Get()->GetOrbiterNode(satId)->GetObject<
SatMobilityModel>();
1356 NS_ASSERT(ownMobility !=
nullptr);
1359 observer = CreateObject<SatMobilityObserver>(
1362 Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() !=
1365 (*i)->AggregateObject(observer);
1372 NodeContainer receivers,
1373 Ipv4Address sourceAddress,
1374 Ipv4Address groupAddress)
1376 NS_LOG_FUNCTION(
this);
1379 Ptr<NetDevice> routerUserOutputDev;
1380 Ptr<Node> sourceUtNode = Singleton<SatTopology>::Get()->GetUtNode(source);
1395 destNode = sourceUtNode;
1403 if (!beamInfo.empty() || (sourceUtNode && routerUserOutputDev))
1407 Ptr<NetDevice> routerInputDev =
nullptr;
1408 Ptr<NetDevice> gwOutputDev =
nullptr;
1411 NetDeviceContainer gwInputDevices =
1416 (
bool)routerUserOutputDev,
1419 Ipv4StaticRoutingHelper multicast;
1428 else if (!sourceUtNode)
1433 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1437 routerInputDev = devices.second;
1441 NetDeviceContainer routerOutputDevices;
1443 if (routerUserOutputDev)
1445 routerOutputDevices.Add(routerUserOutputDev);
1448 for (NetDeviceContainer::Iterator it = gwInputDevices.Begin(); it != gwInputDevices.End();
1455 routerOutputDevices.Add(matchingDevice);
1462 if (routerInputDev && (routerOutputDevices.GetN() > 0))
1464 multicast.AddMulticastRoute(routerNode,
1468 routerOutputDevices);
1475 std::string context,
1478 *stream->GetStream() << context <<
", " << info << std::endl;
1484 NS_LOG_FUNCTION(
this);
1493 NS_LOG_FUNCTION(
this);
1495 std::ostringstream oss;
1497 oss << std::endl << std::endl << title << std::endl << std::endl;
1498 oss <<
"--- User Info ---" << std::endl << std::endl;
1499 oss <<
"Created GW users: " << Singleton<SatTopology>::Get()->GetNGwUserNodes() <<
", ";
1500 oss <<
"Created UT users: " << Singleton<SatTopology>::Get()->GetNUtUserNodes() << std::endl;
1501 oss <<
m_userHelper->GetRouterInfo() << std::endl << std::endl;
1510 NS_LOG_FUNCTION(
this);
1524 std::pair<Ptr<NetDevice>, Ptr<NetDevice>>& matchingDevices)
1528 for (uint32_t i = 1; ((i < nodeA->GetNDevices()) && !found); i++)
1530 Ptr<NetDevice> devA = nodeA->GetDevice(i);
1535 matchingDevices = std::make_pair(devA, devB);
1546 Ptr<NetDevice> matchingDevice =
nullptr;
1548 Ipv4Address addressA =
1549 devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetLocal();
1551 devA->GetNode()->GetObject<Ipv4L3Protocol>()->GetAddress(devA->GetIfIndex(), 0).GetMask();
1553 Ipv4Address netAddressA = addressA.CombineMask(maskA);
1555 for (uint32_t j = 1; j < nodeB->GetNDevices(); j++)
1557 Ipv4Address addressB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetLocal();
1558 Ipv4Mask maskB = nodeB->GetObject<Ipv4L3Protocol>()->GetAddress(j, 0).GetMask();
1560 Ipv4Address netAddressB = addressB.CombineMask(maskB);
1562 if (netAddressA == netAddressB)
1564 matchingDevice = nodeB->GetDevice(j);
1568 return matchingDevice;
1574 NS_LOG_FUNCTION(
this);
1576 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1580 Ipv4StaticRoutingHelper multicast;
1581 Ptr<Ipv4StaticRouting> staticRouting =
1582 multicast.GetStaticRouting(source->GetObject<ns3::Ipv4>());
1585 bool defaultMulticastRouteExists =
false;
1586 Ipv4Address defMulticastNetwork = Ipv4Address(
"224.0.0.0");
1587 Ipv4Mask defMulticastNetworkMask = Ipv4Mask(
"240.0.0.0");
1589 for (uint32_t i = 0; i < staticRouting->GetNRoutes(); i++)
1591 if (staticRouting->GetRoute(i).GetDestNetwork() == defMulticastNetwork &&
1592 staticRouting->GetRoute(i).GetDestNetworkMask() == defMulticastNetworkMask)
1594 defaultMulticastRouteExists =
true;
1599 if (!defaultMulticastRouteExists)
1601 multicast.SetDefaultMulticastRoute(source, devices.first);
1608 NodeContainer receivers,
1610 Ptr<NetDevice>& routerUserOutputDev)
1612 NS_LOG_FUNCTION(
this);
1614 bool routeToSourceNertwork =
false;
1616 routerUserOutputDev =
nullptr;
1619 for (uint32_t i = 0; i < receivers.GetN(); i++)
1621 Ptr<Node> receiverNode = receivers.Get(i);
1622 Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(receiverNode);
1632 if (sourceUtNode == utNode)
1636 routeToSourceNertwork =
true;
1642 MulticastBeamInfo_t::iterator it = beamInfo.find(beamId);
1645 if (it == beamInfo.end())
1647 std::pair<MulticastBeamInfo_t::iterator, bool> result =
1656 NS_FATAL_ERROR(
"Cannot insert beam to map container");
1661 it->second.insert(utNode);
1666 NS_FATAL_ERROR(
"UT node's beam ID is invalid!!");
1671 if (!routerUserOutputDev)
1675 std::pair<Ptr<NetDevice>, Ptr<NetDevice>> devices;
1679 routerUserOutputDev = devices.second;
1684 routeToSourceNertwork =
true;
1690 NS_FATAL_ERROR(
"Multicast receiver node is expected to be connected UT or GW node!!!");
1694 return routeToSourceNertwork;
1700 NS_LOG_FUNCTION(
this);
1702 std::set<uint32_t> networkAddresses;
1703 std::pair<std::set<uint32_t>::const_iterator,
bool> addressInsertionResult;
1710 if (!addressInsertionResult.second)
1712 NS_FATAL_ERROR(
"GW network address is invalid (same as Beam network address)");
1717 if (!addressInsertionResult.second)
1719 NS_FATAL_ERROR(
"UT network address is invalid (same as Beam or GW network address)");
1723 uint32_t utNetworkAddressCount = 0;
1724 uint32_t utHostAddressCount = 0;
1725 uint32_t beamHostAddressCount = 0;
1726 uint32_t gwNetworkAddressCount = 1;
1728 std::set<uint32_t> gwIds;
1730 for (BeamUserInfoMap_t::const_iterator it = info.begin(); it != info.end(); it++)
1732 uint32_t beamUtCount = it->second.GetUtCount();
1733 utNetworkAddressCount += beamUtCount;
1735 if (beamUtCount > beamHostAddressCount)
1737 beamHostAddressCount = beamUtCount;
1740 for (uint32_t i = 0; i < beamUtCount; i++)
1742 if (it->second.GetUtUserCount(i) > utHostAddressCount)
1744 utHostAddressCount = it->second.GetUtUserCount(i);
1750 if (gwIds.insert(
m_beamHelper->GetGwId(it->first.first, it->first.second)).second)
1752 gwNetworkAddressCount++;
1762 beamHostAddressCount);
1767 gwNetworkAddressCount,
1773 utNetworkAddressCount,
1774 utHostAddressCount);
1784 const Ipv4Address& firstNetwork,
1785 const Ipv4Mask& mask,
1786 const std::set<uint32_t>& networkAddresses,
1787 uint32_t networkCount,
1788 uint32_t hostCount)
const
1790 NS_LOG_FUNCTION(
this);
1792 uint16_t addressPrefixLength = mask.GetPrefixLength();
1798 NS_FATAL_ERROR(networkName
1799 <<
" network mask value out of range (0xFFFFFF70 to 0x10000000).");
1803 if ((firstNetwork.Get() & mask.GetInverse()) != 0)
1805 NS_FATAL_ERROR(networkName <<
" network address and mask inconsistent.");
1808 std::set<uint32_t>::const_iterator currentAddressIt = networkAddresses.find(firstNetwork.Get());
1811 if (currentAddressIt != networkAddresses.end())
1815 uint32_t hostAddressCount = std::pow(2, (32 - addressPrefixLength)) - 2;
1816 uint32_t firstAddressValue = firstNetwork.Get();
1817 uint32_t networkAddressCount =
1818 mask.Get() - firstAddressValue +
1826 if ((currentAddressIt != networkAddresses.end()) &&
1827 (firstAddressValue + (networkCount << (32 - addressPrefixLength))) >= *currentAddressIt)
1829 NS_FATAL_ERROR(networkName <<
" network's addresses overlaps with some other network)");
1833 if (networkCount > networkAddressCount)
1835 NS_FATAL_ERROR(
"Not enough network addresses for '" << networkName <<
"' network");
1839 if (hostCount > hostAddressCount)
1841 NS_FATAL_ERROR(
"Not enough host addresses for '" << networkName <<
"' network");
1846 NS_FATAL_ERROR(networkName
1847 <<
"network's initial address number not among of the given addresses");
1854 NS_LOG_FUNCTION(
this << pathName);
1857 std::ifstream* ifs =
new std::ifstream(pathName.c_str(), std::ifstream::in);
1859 if (!ifs->is_open())
1863 pathName =
"../../" + pathName;
1864 ifs =
new std::ifstream(pathName.c_str(), std::ifstream::in);
1866 if (!ifs->is_open())
1868 NS_FATAL_ERROR(
"The file " << pathName <<
" is not found.");
1872 std::string standardString;
1873 *ifs >> standardString;
1878 if (standardString ==
"DVB")
1882 else if (standardString ==
"LORA")
1888 NS_FATAL_ERROR(
"Unknown standard: " << standardString <<
". Must be DVB or LORA");
1891 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.
static Ptr< SatEnvVariables > GetInstance()
Build a satellite network set with needed objects and configuration.
Ptr< SatUserHelper > GetUserHelper() const
std::string m_waveformConfDirectoryName
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
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
void LoadConstellationTopology(std::vector< std::string > &tles, std::vector< std::pair< uint32_t, uint32_t > > &isls)
Load a constellation topology.
std::multimap< uint32_t, uint32_t > m_mobileUtsUsersByBeam
List of users by mobile UT by beam ID.
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)
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.
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
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 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.
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.
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.
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.
void SetStartDate(std::string startStr)
Set the simulation absolute start time in string format.
void SetTleInfo(const std::string &tle)
Set satellite's TLE information required for its initialization.
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