From 70c70a19ceedeb68036c707edc176728c793ce2b Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sun, 23 Aug 2020 21:25:54 +0200 Subject: [PATCH] Add lat long conversion --- doc/leo.rst | 4 +- examples/leo-delay-tracing-example.cc | 57 +++++++++++++++++++++------ helper/ground-node-helper.cc | 37 +++++++++++++++++ helper/ground-node-helper.h | 14 +++++++ model/leo-lat-long.cc | 28 +++++++++++++ model/leo-lat-long.h | 26 ++++++++++++ model/orbit.h | 17 ++++++++ wscript | 4 +- 8 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 model/leo-lat-long.cc create mode 100644 model/leo-lat-long.h create mode 100644 model/orbit.h diff --git a/doc/leo.rst b/doc/leo.rst index 3c7ef50..71a2754 100644 --- a/doc/leo.rst +++ b/doc/leo.rst @@ -155,8 +155,8 @@ given as pairs of longitude and latitude. --orbitsFile=orbits.csv \ --groundFile=ground-stations.csv \ --traceFile=delay-trace.csv \ - --source=54.4,77.1 \ - --destination=-10.0,25.8 \ + --source=54.4:77.1 \ + --destination=-10.0:25.8 \ --islRate=1Gbps \ --constellation="StarlinkGateway" \ --duration=10.0 \ diff --git a/examples/leo-delay-tracing-example.cc b/examples/leo-delay-tracing-example.cc index 85081da..1e6832c 100644 --- a/examples/leo-delay-tracing-example.cc +++ b/examples/leo-delay-tracing-example.cc @@ -26,28 +26,59 @@ int main (int argc, char *argv[]) CommandLine cmd; std::string orbitFile; + std::string groundFile; + std::string traceFile; + LeoLatLong source; + LeoLatLong destination; + std::string islRate; + std::string constellation; + Time interval; + Time duration; cmd.AddValue("orbitFile", "CSV file with orbit parameters", orbitFile); + cmd.AddValue("traceFile", "CSV file to store mobility trace in", traceFile); // TODO write position allocator for long,lat - cmd.AddValue("groundFile", "CSV file with ground station locations", orbitFile); - cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel"); + cmd.AddValue("groundFile", "CSV file with ground station locations", groundFile); + cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision"); + cmd.AddValue("duration", "Duration of the simulation", duration); + // TODO LeoLatLong + cmd.AddValue("source", "Traffic source", source); + cmd.AddValue("destination", "Traffic destination", destination); + cmd.AddValue("islRate", "Throughput of the ISL link", islRate); + cmd.AddValue("constellation", "LEO constellation link settings name", constellation); + cmd.AddValue("interval", "Echo interval", interval); cmd.Parse (argc, argv); + std::streambuf *coutbuf = std::cout.rdbuf(); + // redirect cout if traceFile + std::ofstream out; + out.open (traceFile); + if (out.is_open ()) + { + std::cout.rdbuf(out.rdbuf()); + } + LeoOrbitNodeHelper orbit; NodeContainer satellites = orbit.Install (orbitFile); LeoGndNodeHelper ground; - NodeContainer stations = ground.Install ("contrib/leo/data/ground-stations/usa-60.waypoints"); + NodeContainer stations = ground.Install (groundFile); + NodeContainer users = ground.Install (source, destination); + stations.Add (users); + + // TODO create source and sink with ConstantPosition MobilityHelper + Ptr client = users.Get (0); + Ptr server = users.Get (1); NetDeviceContainer islNet, utNet; IslHelper islCh; - islCh.SetDeviceAttribute ("DataRate", StringValue ("1Gbps")); + islCh.SetDeviceAttribute ("DataRate", StringValue (islRate)); islCh.SetChannelAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel")); islCh.SetChannelAttribute ("PropagationLoss", StringValue ("ns3::IslPropagationLossModel")); islNet = islCh.Install (satellites); LeoChannelHelper utCh; - utCh.SetConstellation ("StarlinkUser"); + utCh.SetConstellation (constellation); utNet = utCh.Install (satellites, stations); // Install internet stack on nodes @@ -67,9 +98,6 @@ int main (int argc, char *argv[]) ipv4.SetBase ("10.3.0.0", "255.255.0.0"); Ipv4InterfaceContainer utIp = ipv4.Assign (utNet); - Ptr client = stations.Get (0); - Ptr server = stations.Get (1); - // we want to ping terminals UdpServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (server); @@ -78,8 +106,8 @@ int main (int argc, char *argv[]) ApplicationContainer clientApps; Address remote = server->GetObject ()->GetAddress (1, 0).GetLocal (); UdpClientHelper echoClient (remote, 9); - echoClient.SetAttribute ("MaxPackets", UintegerValue (6000)); - echoClient.SetAttribute ("Interval", TimeValue (Seconds (1))); + echoClient.SetAttribute ("MaxPackets", UintegerValue (duration.GetDouble ()/interval.GetDouble ())); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (interval))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); clientApps.Add (echoClient.Install (client)); @@ -91,10 +119,10 @@ int main (int argc, char *argv[]) std::cout << "Context,Sequence Number,Timestamp,Delay" << std::endl; - serverApps.Start (Seconds (1)); - clientApps.Start (Seconds (1)); + //serverApps.Start (Seconds (1)); + //clientApps.Start (Seconds (1)); - Simulator::Stop (Minutes (10)); + Simulator::Stop (duration); Simulator::Run (); Simulator::Destroy (); @@ -102,5 +130,8 @@ int main (int argc, char *argv[]) std::cout << "Received,Lost" << std::endl << result->GetReceived () << "," << result->GetLost () << std::endl; + out.close (); + std::cout.rdbuf(coutbuf); + return 0; } diff --git a/helper/ground-node-helper.cc b/helper/ground-node-helper.cc index 4e80030..8e49860 100644 --- a/helper/ground-node-helper.cc +++ b/helper/ground-node-helper.cc @@ -1,5 +1,7 @@ #include +#include "math.h" + #include "ns3/log.h" #include "ns3/config.h" #include "ns3/waypoint.h" @@ -52,4 +54,39 @@ LeoGndNodeHelper::Install (const std::string &wpFile) return nodes; } +Vector3D +LeoGndNodeHelper::GetEarthPosition (const LeoLatLong &loc) +{ + double lat = loc.latitude * (M_PI / 90); + double lon = loc.longitude * (M_PI / 180); + Vector3D pos = Vector3D (LEO_GND_RAD_EARTH * sin (lat) * cos (lon), + LEO_GND_RAD_EARTH * sin (lat) * sin (lon), + LEO_GND_RAD_EARTH * cos (lat)); + return pos; +} + +NodeContainer +LeoGndNodeHelper::Install (const LeoLatLong &location1, + const LeoLatLong &location2) +{ + NS_LOG_FUNCTION (this << location1 << location2); + + NodeContainer nodes; + + for (const LeoLatLong loc : { location1, location2 }) + { + Vector pos = GetEarthPosition (loc); + Ptr mob = CreateObject (); + mob->SetPosition (pos); + Ptr node = m_gndNodeFactory.Create (); + node->AggregateObject (mob); + nodes.Add (node); + NS_LOG_INFO ("Added ground node at " << pos); + } + + NS_LOG_INFO ("Added " << nodes.GetN () << " ground nodes"); + + return nodes; +} + }; // namespace ns3 diff --git a/helper/ground-node-helper.h b/helper/ground-node-helper.h index 922fdca..e7ab16f 100644 --- a/helper/ground-node-helper.h +++ b/helper/ground-node-helper.h @@ -8,6 +8,9 @@ #include "ns3/object-factory.h" #include "ns3/node-container.h" #include "ns3/constant-position-mobility-model.h" +#include "ns3/leo-lat-long.h" + +#define LEO_GND_RAD_EARTH 6.371e6 /** * \brief Builds a node container of nodes with constant positions @@ -31,6 +34,15 @@ public: */ NodeContainer Install (const std::string &wpFile); + /** + * + * \param location1 first location + * \param location2 second location + * \returns a node container containing nodes using the specified attributes + */ + NodeContainer Install (const LeoLatLong &location1, + const LeoLatLong &location2); + /** * Set an attribute for each node * @@ -41,6 +53,8 @@ public: private: ObjectFactory m_gndNodeFactory; + + static Vector3D GetEarthPosition (const LeoLatLong &loc); }; }; // namespace ns3 diff --git a/model/leo-lat-long.cc b/model/leo-lat-long.cc new file mode 100644 index 0000000..6c2eb4a --- /dev/null +++ b/model/leo-lat-long.cc @@ -0,0 +1,28 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "leo-lat-long.h" + +namespace ns3 { + +std::ostream &operator << (std::ostream &os, const LeoLatLong &l) +{ + os << l.latitude << ":" << l.longitude; + return os; +} + +std::istream &operator >> (std::istream &is, LeoLatLong &l) +{ + char c1; + is >> l.latitude >> c1 >> l.longitude; + if (c1 != ':') + { + is.setstate (std::ios_base::failbit); + } + return is; +} + +LeoLatLong::LeoLatLong () : latitude (0), longitude (0) {} +LeoLatLong::LeoLatLong (double la, double lo) : latitude (la), longitude (lo) {} +LeoLatLong::~LeoLatLong () {} + +}; diff --git a/model/leo-lat-long.h b/model/leo-lat-long.h new file mode 100644 index 0000000..3684432 --- /dev/null +++ b/model/leo-lat-long.h @@ -0,0 +1,26 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_LAT_LONG_H +#define LEO_LAT_LONG_H + +#include + +namespace ns3 { + +class LeoLatLong +{ +public: + LeoLatLong (); + LeoLatLong (double latitude, double longitude); + virtual ~LeoLatLong(); + + double latitude; + double longitude; +}; + +std::ostream &operator << (std::ostream &os, const LeoLatLong &latLong); +std::istream &operator >> (std::istream &is, LeoLatLong &latLong); + +}; + +#endif diff --git a/model/orbit.h b/model/orbit.h new file mode 100644 index 0000000..6928de3 --- /dev/null +++ b/model/orbit.h @@ -0,0 +1,17 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_ORBIT_H +#define LEO_ORBIT_H + +#include "ns3/uinteger.h" + +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; +}; + +#endif diff --git a/wscript b/wscript index 51f596b..39ede19 100644 --- a/wscript +++ b/wscript @@ -22,6 +22,7 @@ def build(bld): 'model/leo-mock-channel.cc', 'model/leo-mock-net-device.cc', 'model/leo-orbit.cc', + 'model/leo-lat-long.cc', 'model/leo-propagation-loss-model.cc', 'model/mock-net-device.cc', 'model/mock-channel.cc', @@ -63,6 +64,8 @@ def build(bld): 'model/leo-mock-channel.h', 'model/leo-mock-net-device.h', 'model/leo-oneweb-constants.h', + 'model/leo-orbit.h', + 'model/leo-lat-long.h', 'model/leo-propagation-loss-model.h', 'model/leo-starlink-constants.h', 'model/leo-telesat-constants.h', @@ -70,7 +73,6 @@ 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', ]