From b7f459e36a286d50452a8b89eb24d98db54e488c Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sun, 23 Aug 2020 19:37:40 +0200 Subject: [PATCH] Create command line options for orbit trace --- doc/leo.rst | 1 + .../leo-circular-orbit-tracing-example.cc | 65 +++++++---------- examples/leo-delay-tracing-example.cc | 67 +++--------------- examples/wscript | 2 +- helper/leo-orbit-helper.h | 48 +++++++++++++ helper/leo-orbit-node-helper.cc | 69 +++++++++++++++++++ helper/leo-orbit-node-helper.h | 50 ++++++++++++++ model/leo-orbit.cc | 29 ++++++++ model/leo-orbit.h | 28 ++++++++ wscript | 4 ++ 10 files changed, 266 insertions(+), 97 deletions(-) create mode 100644 helper/leo-orbit-helper.h create mode 100644 helper/leo-orbit-node-helper.cc create mode 100644 helper/leo-orbit-node-helper.h create mode 100644 model/leo-orbit.cc create mode 100644 model/leo-orbit.h diff --git a/doc/leo.rst b/doc/leo.rst index aa8f541..3c7ef50 100644 --- a/doc/leo.rst +++ b/doc/leo.rst @@ -140,6 +140,7 @@ planes,number of satellites per plane``. The duration is given in seconds. --orbitsFile=orbits.csv \ --traceFile=mobility-trace.csv \ --duration=10.0 + --precision=1.0 leo-delay ######### diff --git a/examples/leo-circular-orbit-tracing-example.cc b/examples/leo-circular-orbit-tracing-example.cc index feda297..0b6d657 100644 --- a/examples/leo-circular-orbit-tracing-example.cc +++ b/examples/leo-circular-orbit-tracing-example.cc @@ -10,59 +10,46 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("LeoCircularOrbitTracingExample"); -ofstream outfile ("leo-circular-orbit-tracing-example.csv"); - void CourseChange (std::string context, Ptr position) { Vector pos = position->GetPosition (); Ptr node = position->GetObject (); - outfile << Simulator::Now () << ":" << node->GetId () << ":" << pos.x << ":" << pos.y << ":" << pos.z << ":" << position->GetVelocity ().GetLength() << std::endl; + std::cout << Simulator::Now () << ":" << node->GetId () << ":" << pos.x << ":" << pos.y << ":" << pos.z << ":" << position->GetVelocity ().GetLength() << std::endl; } - -class Orbit { -public: - Orbit (double a, double i, double p, double s) : alt (a), inc (i), planes (p), sats (s) {} - double alt; - double inc; - uint16_t planes; - uint16_t sats; -}; - int main(int argc, char *argv[]) { - std::vector orbits = { - Orbit (1150, 53.0, 32, 50), - Orbit (1110, 53.8, 32, 50), -// Orbit (1130, 74.0, 8, 50), -// Orbit (1275, 81, 5, 75), -// Orbit (1325, 70, 6, 75), - }; - NodeContainer satellites; - for (Orbit orb: orbits) - { - NodeContainer c; - c.Create (orb.sats*orb.planes); - - MobilityHelper mobility; - mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator", - "NumOrbits", IntegerValue (orb.planes), - "NumSatellites", IntegerValue (orb.sats)); - mobility.SetMobilityModel ("ns3::LeoCircularOrbitMobilityModel", - "Altitude", DoubleValue (orb.alt), - "Inclination", DoubleValue (orb.inc), - "Precision", TimeValue (Minutes (1))); - mobility.Install (c); - satellites.Add (c); - } + CommandLine cmd; + std::string orbitFile; + std::string traceFile; + Time duration; + cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile); + cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile); + cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision"); + cmd.AddValue("duration", "Duration of the simulation", duration); + cmd.Parse (argc, argv); + LeoOrbitNodeHelper orbit; + NodeContainer satellites = orbit.Install (orbitFile); Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChange)); - outfile << "Time,Satellite,x,y,z,Speed" << std::endl; + std::streambuf *coutbuf = std::cout.rdbuf(); + // redirect cout if traceFile is specified + std::ofstream out; + out.open (traceFile); + if (out.is_open ()) + { + std::cout.rdbuf(out.rdbuf()); + } - Simulator::Stop (Hours (1)); + std::cout << "Time,Satellite,x,y,z,Speed" << std::endl; + + Simulator::Stop (duration); Simulator::Run (); Simulator::Destroy (); + + out.close (); + std::cout.rdbuf(coutbuf); } diff --git a/examples/leo-delay-tracing-example.cc b/examples/leo-delay-tracing-example.cc index c0d66f4..85081da 100644 --- a/examples/leo-delay-tracing-example.cc +++ b/examples/leo-delay-tracing-example.cc @@ -21,54 +21,19 @@ EchoRx (std::string context, Ptr packet) std::cout << context << "," << seqTs.GetSeq () << "," << seqTs.GetTs () << "," << Simulator::Now () - seqTs.GetTs () << std::endl; } -class Orbit { -public: - Orbit (double a, double i, double p, double s) : alt (a), inc (i), planes (p), sats (s) {} - double alt; - double inc; - uint16_t planes; - uint16_t sats; -}; - - -// Starlink -//Orbit (1150, 53.0, 32, 50), -//Orbit (1110, 53.8, 32, 50), -//Orbit (1130, 74.0, 8, 50), -//Orbit (1275, 81, 5, 75), -//Orbit (1325, 70, 6, 75), - -// Telesat -//Orbit (1000.0, 99.5, 6, 12), -//Orbit (1248.0, 37.4, 5, 9), - int main (int argc, char *argv[]) { - std::vector orbits = { - //Orbit (1000.0, 99.5, 6, 12), - //Orbit (1248.0, 37.4, 5, 9), -Orbit (1150, 53.0, 32, 50), -Orbit (1110, 53.8, 32, 50), -// Orbit (1150, 53.0, 32, 50), - // Orbit (1110, 53.8, 32, 50), - }; - NodeContainer satellites; - for (Orbit orb: orbits) - { - NodeContainer c; - c.Create (orb.sats*orb.planes); - MobilityHelper mobility; - mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator", - "NumOrbits", IntegerValue (orb.planes), - "NumSatellites", IntegerValue (orb.sats)); - mobility.SetMobilityModel ("ns3::LeoCircularOrbitMobilityModel", - "Altitude", DoubleValue (orb.alt), - "Inclination", DoubleValue (orb.inc), - "Precision", TimeValue (Minutes (1))); - mobility.Install (c); - satellites.Add (c); - } + CommandLine cmd; + std::string orbitFile; + cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile); + // TODO write position allocator for long,lat + cmd.AddValue("groundFile", "CSV file with ground station locations", orbitFile); + cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel"); + cmd.Parse (argc, argv); + + LeoOrbitNodeHelper orbit; + NodeContainer satellites = orbit.Install (orbitFile); LeoGndNodeHelper ground; NodeContainer stations = ground.Install ("contrib/leo/data/ground-stations/usa-60.waypoints"); @@ -89,18 +54,6 @@ Orbit (1110, 53.8, 32, 50), AodvHelper aodv; // This disabled is far better for performance (huge network) aodv.Set ("EnableHello", BooleanValue (false)); - //aodv.Set ("HelloInterval", TimeValue (Seconds (10))); - //aodv.Set ("TtlStart", UintegerValue (2)); - //aodv.Set ("TtlIncrement", UintegerValue (1)); - //aodv.Set ("TtlThreshold", UintegerValue (20)); - //aodv.Set ("RreqRetries", UintegerValue (1000)); - //aodv.Set ("RreqRateLimit", UintegerValue (1)); - //aodv.Set ("RerrRateLimit", UintegerValue (1)); - //aodv.Set ("ActiveRouteTimeout", TimeValue (Minutes (1))); - //aodv.Set ("NextHopWait", TimeValue (MilliSeconds (200))); - //aodv.Set ("NetDiameter", UintegerValue (300)); - //aodv.Set ("AllowedHelloLoss", UintegerValue (10000)); - //aodv.Set ("PathDiscoveryTime", TimeValue (Seconds (1))); InternetStackHelper stack; stack.SetRoutingHelper (aodv); diff --git a/examples/wscript b/examples/wscript index 0c17481..9dd00c3 100644 --- a/examples/wscript +++ b/examples/wscript @@ -4,7 +4,7 @@ def build(bld): if not bld.env['ENABLE_EXAMPLES']: return; - obj = bld.create_ns3_program('leo-circular-orbit', + obj = bld.create_ns3_program('leo-orbit', ['core', 'leo', 'mobility']) obj.source = 'leo-circular-orbit-tracing-example.cc' diff --git a/helper/leo-orbit-helper.h b/helper/leo-orbit-helper.h new file mode 100644 index 0000000..6a44225 --- /dev/null +++ b/helper/leo-orbit-helper.h @@ -0,0 +1,48 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_ORBIT_NODE_HELPER_H +#define LEO_ORBIT_NODE_HELPER_H + +#include + +#include "ns3/object-factory.h" +#include "ns3/node-container.h" +#include "ns3/constant-position-mobility-model.h" + +/** + * \brief Builds a node container of nodes with constant positions + * + * Adds waypoints from file for each node. + */ + +namespace ns3 +{ + +class LeoGndNodeHelper +{ +public: + LeoGndNodeHelper (); + virtual ~LeoGndNodeHelper (); + + /** + * + * \param wpFile path to waypoint file + * \returns a node container containing nodes using the specified attributes + */ + NodeContainer Install (const std::string &wpFile); + + /** + * Set an attribute for each node + * + * \param name name of the attribute + * \param value value of the attribute + */ + void SetAttribute (std::string name, const AttributeValue &value); + +private: + ObjectFactory m_gndNodeFactory; +}; + +}; // namespace ns3 + +#endif diff --git a/helper/leo-orbit-node-helper.cc b/helper/leo-orbit-node-helper.cc new file mode 100644 index 0000000..6d9076b --- /dev/null +++ b/helper/leo-orbit-node-helper.cc @@ -0,0 +1,69 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include + +#include "ns3/log.h" +#include "ns3/config.h" +#include "ns3/waypoint.h" +#include "ns3/mobility-helper.h" +#include "ns3/double.h" +#include "ns3/integer.h" + +#include "leo-orbit-node-helper.h" +#include "../model/leo-orbit.h" + +using namespace std; + +namespace ns3 +{ +NS_LOG_COMPONENT_DEFINE ("LeoOrbitNodeHelper"); + +LeoOrbitNodeHelper::LeoOrbitNodeHelper () +{ + m_nodeFactory.SetTypeId ("ns3::Node"); +} + +LeoOrbitNodeHelper::~LeoOrbitNodeHelper () +{ +} + +void +LeoOrbitNodeHelper::SetAttribute (string name, const AttributeValue &value) +{ + m_nodeFactory.Set (name, value); +} + +NodeContainer +LeoOrbitNodeHelper::Install (const std::string &orbitFile) +{ + NS_LOG_FUNCTION (this << orbitFile); + + NodeContainer nodes; + ifstream orbits; + orbits.open (orbitFile, ifstream::in); + LeoOrbit orbit; + while ((orbits >> orbit)) + { + MobilityHelper mobility; + mobility.SetPositionAllocator ("ns3::LeoCircularOrbitPostionAllocator", + "NumOrbits", IntegerValue (orbit.inc), + "NumSatellites", IntegerValue (orbit.sats)); + mobility.SetMobilityModel ("ns3::LeoCircularOrbitMobilityModel", + "Altitude", DoubleValue (orbit.alt), + "Inclination", DoubleValue (orbit.inc)); + + NodeContainer c; + Ptr node = m_nodeFactory.Create (); + c.Add (node); + mobility.Install (c); + nodes.Add (c); + NS_LOG_DEBUG ("Added orbit plane"); + } + orbits.close (); + + NS_LOG_DEBUG ("Added " << nodes.GetN () << " nodes"); + + return nodes; +} + +}; // namespace ns3 diff --git a/helper/leo-orbit-node-helper.h b/helper/leo-orbit-node-helper.h new file mode 100644 index 0000000..b0cef97 --- /dev/null +++ b/helper/leo-orbit-node-helper.h @@ -0,0 +1,50 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_ORBIT_NODE_HELPER_H +#define LEO_ORBIT_NODE_HELPER_H + +#include + +#include "ns3/object-factory.h" +#include "ns3/node-container.h" +#include "ns3/leo-circular-orbit-mobility-model.h" +#include "ns3/leo-circular-orbit-position-allocator.h" + +/** + * \brief Builds a node container of nodes with LEO positions using a list of + * orbit definitions. + * + * Adds orbits with from a file for each node. + */ + +namespace ns3 +{ + +class LeoOrbitNodeHelper +{ +public: + LeoOrbitNodeHelper (); + virtual ~LeoOrbitNodeHelper (); + + /** + * + * \param orbitFile path to orbit definitions file + * \returns a node container containing nodes using the specified attributes + */ + NodeContainer Install (const std::string &orbitFile); + + /** + * Set an attribute for each node + * + * \param name name of the attribute + * \param value value of the attribute + */ + void SetAttribute (std::string name, const AttributeValue &value); + +private: + ObjectFactory m_nodeFactory; +}; + +}; // namespace ns3 + +#endif diff --git a/model/leo-orbit.cc b/model/leo-orbit.cc new file mode 100644 index 0000000..7e755eb --- /dev/null +++ b/model/leo-orbit.cc @@ -0,0 +1,29 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "leo-orbit.h" + +namespace ns3 { + +std::ostream &operator << (std::ostream &os, const LeoOrbit &orbit) +{ + os << orbit.alt << ":" << orbit.inc << ":" << orbit.planes << ":" << orbit.sats; + return os; +} + +std::istream &operator >> (std::istream &is, LeoOrbit &orbit) +{ + char c1, c2, c3; + is >> orbit.alt >> c1 >> orbit.inc >> c2 >> orbit.planes >> c3 >> orbit.sats; + if (c1 != ':' || + c2 != ':' || + c3 != ':') + { + is.setstate (std::ios_base::failbit); + } + return is; +} + +LeoOrbit::LeoOrbit () : alt (0), inc (0), planes (0), sats (0) {} +LeoOrbit::~LeoOrbit () {} + +}; diff --git a/model/leo-orbit.h b/model/leo-orbit.h new file mode 100644 index 0000000..eda868e --- /dev/null +++ b/model/leo-orbit.h @@ -0,0 +1,28 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_ORBIT_H +#define LEO_ORBIT_H + +#include "ns3/uinteger.h" + +namespace ns3 +{ +class LeoOrbit; + +std::ostream &operator << (std::ostream &os, const LeoOrbit &orbit); +std::istream &operator >> (std::istream &is, LeoOrbit &orbit); + +class LeoOrbit { +public: + LeoOrbit (); + LeoOrbit (double a, double i, double p, double s) : alt (a), inc (i), planes (p), sats (s) {} + virtual ~LeoOrbit (); + double alt; + double inc; + uint16_t planes; + uint16_t sats; +}; + +}; + +#endif diff --git a/wscript b/wscript index 52426da..51f596b 100644 --- a/wscript +++ b/wscript @@ -12,6 +12,7 @@ def build(bld): 'helper/arp-cache-helper.cc', 'helper/isl-helper.cc', 'helper/leo-channel-helper.cc', + 'helper/leo-orbit-node-helper.cc', 'helper/nd-cache-helper.cc', 'helper/ground-node-helper.cc', 'helper/satellite-node-helper.cc', @@ -20,6 +21,7 @@ def build(bld): 'model/leo-circular-orbit-position-allocator.cc', 'model/leo-mock-channel.cc', 'model/leo-mock-net-device.cc', + 'model/leo-orbit.cc', 'model/leo-propagation-loss-model.cc', 'model/mock-net-device.cc', 'model/mock-channel.cc', @@ -51,6 +53,7 @@ def build(bld): 'helper/arp-cache-helper.h', 'helper/isl-helper.h', 'helper/leo-channel-helper.h', + 'helper/leo-orbit-node-helper.h', 'helper/nd-cache-helper.h', 'helper/ground-node-helper.h', 'helper/satellite-node-helper.h', @@ -67,6 +70,7 @@ def build(bld): 'model/mock-channel.h', 'model/isl-mock-channel.h', 'model/isl-propagation-loss-model.h', + 'model/leo-orbit.h', 'utils/leo-input-fstream-container.h', ]