A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
leo-orbit-node-helper.cc
Go to the documentation of this file.
1// Copyright (c) Tim Schubert
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Tim Schubert <ns-3-leo@timschubert.net>
6// Porting: Thiago Miyazaki <miyathiago@gmail.com> <t.miyazaki@unesp.br>
7
9
10#include "mobility-helper.h"
11
12#include "ns3/csv-reader.h"
13#include "ns3/double.h"
14#include "ns3/log.h"
15#include "ns3/uinteger.h"
16
17#include <fstream>
18
19using namespace std;
20
21namespace ns3
22{
23NS_LOG_COMPONENT_DEFINE("LeoOrbitNodeHelper");
24
26{
27 NS_LOG_FUNCTION(this << resolution.As(Time::S));
28 m_nodeFactory.SetTypeId("ns3::Node");
29 m_resolution = resolution;
30}
31
32void
34{
35 NS_LOG_FUNCTION(this);
36 m_nodeFactory.Set(name, value);
37}
38
39void
41{
42 NS_LOG_FUNCTION(this << resolution.As(Time::S));
43 m_resolution = resolution;
44}
45
46std::size_t
51
54{
55 NS_LOG_FUNCTION(this << orbit);
56
57 NodeContainer satelliteContainer;
58 for (std::size_t i = 0; i < CalculateNumberOfOrbitSatellites(orbit); i++)
59 {
60 satelliteContainer.Add(m_nodeFactory.Create<Node>());
61 }
62
63 Install(satelliteContainer, orbit);
64
65 return satelliteContainer;
66}
67
68void
70{
71 NS_LOG_FUNCTION(this << &orbit);
72
73 NS_LOG_INFO("Installing shell: altitude = "
74 << orbit.alt << " km, inclination = " << orbit.inc << " deg, " << orbit.planes
75 << " planes, " << orbit.sats << " sats/plane, phasing = " << orbit.phasing
76 << ", RAAN span = " << orbit.raanSpanDeg << " deg");
77
78 bool planes = orbit.planes == 0;
79 bool sats = orbit.sats == 0;
80 bool alt = orbit.alt <= 0;
81 bool raan = orbit.raanSpanDeg <= 0 || orbit.raanSpanDeg > 360;
82 bool phasing = orbit.phasing >= orbit.planes;
83
84 NS_ABORT_MSG_IF(planes || sats || alt || raan || phasing,
85 (planes ? "Number of orbital planes must be > 0; " : "")
86 << (sats ? "Number of satellites per plane must be > 0; " : "")
87 << (alt ? "Orbital altitude must be > 0 km; " : "")
88 << (raan ? "RAAN span must be in (0, 360] degrees; " : "")
89 << (phasing ? "Phasing factor must be in [0, planes - 1]" : ""));
90
91 if (nodes.GetN() != static_cast<uint32_t>(orbit.planes * orbit.sats))
92 {
93 NS_LOG_WARN("Number of nodes " << nodes.GetN() << " does not match constellation size "
94 << orbit.planes * orbit.sats);
95 }
96
97 MobilityHelper mobility;
98 mobility.SetPositionAllocator("ns3::LeoCircularOrbitPositionAllocator",
99 "NumOrbits",
100 UintegerValue(orbit.planes),
101 "NumSatellites",
102 UintegerValue(orbit.sats),
103 "PhasingFactor",
104 UintegerValue(orbit.phasing),
105 "RaanSpanDeg",
106 DoubleValue(orbit.raanSpanDeg));
107 mobility.SetMobilityModel("ns3::LeoCircularOrbitMobilityModel",
108 "Altitude",
109 DoubleValue(orbit.alt),
110 "Inclination",
111 DoubleValue(orbit.inc),
112 "Resolution",
114 mobility.Install(nodes);
115}
116
119{
120 NS_LOG_FUNCTION(this << orbitFile);
121
122 // Read orbit file contents
123 std::vector<LeoOrbitalShell> orbits;
124 CsvReader csv(orbitFile);
125 while (csv.FetchNextRow())
126 {
127 // Require at least 4 columns; allow up to 6
128 if (csv.ColumnCount() < 4)
129 {
130 NS_LOG_WARN("Skipping row " << csv.RowNumber() << " of " << orbitFile
131 << ": expected at least 4 columns, got "
132 << csv.ColumnCount());
133 continue;
134 }
135
136 LeoOrbitalShell orbit{};
137
138 bool ok = csv.GetValue(0, orbit.alt);
139 ok &= csv.GetValue(1, orbit.inc);
140 ok &= csv.GetValue(2, orbit.planes);
141 ok &= csv.GetValue(3, orbit.sats);
142 if (!ok)
143 {
144 NS_LOG_WARN("Skipping row " << csv.RowNumber() << " of " << orbitFile
145 << ": non-numeric value in required column");
146 continue;
147 }
148
149 // Optional 5th column: Walker Delta phasing factor
150 csv.GetValue(4, orbit.phasing);
151 // Optional 6th column: RAAN span in degrees (360 = Delta, 180 = Star)
152 csv.GetValue(5, orbit.raanSpanDeg);
153 orbits.push_back(orbit);
154 }
155
156 NS_ABORT_MSG_IF(orbits.empty(),
157 "No valid orbit rows found in " << orbitFile << "; check file format");
158
159 return CreateNodesAndInstallMobility(orbits);
160}
161
163LeoOrbitNodeHelper::CreateNodesAndInstallMobility(const vector<LeoOrbitalShell>& orbits)
164{
165 NS_LOG_FUNCTION(this << orbits);
166
168 for (auto& orbit : orbits)
169 {
171 NS_LOG_DEBUG("Added orbit plane");
172 }
173
174 NS_LOG_DEBUG("Added " << nodes.GetN() << " nodes");
175
176 return nodes;
177}
178
179}; // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Provides functions for parsing and extracting data from Comma Separated Value (CSV) formatted text fi...
Definition csv-reader.h:221
bool GetValue(std::size_t columnIndex, T &value) const
Attempt to convert from the string data in the specified column to the specified data type.
Definition csv-reader.h:399
std::size_t RowNumber() const
The number of lines that have been read.
Definition csv-reader.cc:91
std::size_t ColumnCount() const
Returns the number of columns in the csv data.
Definition csv-reader.cc:83
bool FetchNextRow()
Reads one line from the input until a new line is encountered.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
void SetAttribute(std::string name, const AttributeValue &value)
Set an attribute for each node.
LeoOrbitNodeHelper(const Time &resolution=Seconds(0))
Construct a LEO Orbit Node Helper.
void Install(NodeContainer nodes, const LeoOrbitalShell &orbit)
Install orbital mobility on a node container using an orbit definition.
std::size_t CalculateNumberOfOrbitSatellites(const LeoOrbitalShell &orbit)
Calculates the total number of satellites in a given LEO orbit.
ObjectFactory m_nodeFactory
Node factory.
void SetResolution(Time resolution)
Set the time resolution for course change notifications.
NodeContainer CreateNodesAndInstallMobility(const std::string &orbitFile)
Create satellite nodes and install orbital mobility from a CSV file.
Time m_resolution
Time interval between CourseChange notifications.
Orbit definition.
double inc
Inclination of orbit (degrees).
std::size_t sats
Number of satellites in those planes.
double raanSpanDeg
RAAN span in degrees (360 for Walker Delta, 180 for Walker Star).
std::size_t planes
Number of planes with that altitude and inclination.
double alt
Altitude of orbit (km, from earth surface).
double phasing
Walker Delta phasing factor F (0 means no inter-plane stagger).
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
A network Node.
Definition node.h:46
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:408
@ S
second
Definition nstime.h:106
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:253
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
LeoOrbitNodeHelper class declaration.
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.