diff --git a/examples/leo-delay-tracing-example.cc b/examples/leo-delay-tracing-example.cc index 1e6832c..7c26636 100644 --- a/examples/leo-delay-tracing-example.cc +++ b/examples/leo-delay-tracing-example.cc @@ -40,7 +40,6 @@ int main (int argc, char *argv[]) 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); diff --git a/helper/ground-node-helper.cc b/helper/ground-node-helper.cc index 8e49860..a8293fd 100644 --- a/helper/ground-node-helper.cc +++ b/helper/ground-node-helper.cc @@ -30,24 +30,25 @@ LeoGndNodeHelper::SetAttribute (string name, const AttributeValue &value) } NodeContainer -LeoGndNodeHelper::Install (const std::string &wpFile) +LeoGndNodeHelper::Install (const std::string &file) { - NS_LOG_FUNCTION (wpFile); + NS_LOG_FUNCTION (this << file); NodeContainer nodes; - ifstream waypoints; - waypoints.open (wpFile, ifstream::in); - Vector pos; - while ((waypoints >> pos)) + ifstream stream; + stream.open (file, ifstream::in); + LeoLatLong loc; + while ((stream >> loc)) { Ptr mob = CreateObject (); + Vector pos = GetEarthPosition (loc); mob->SetPosition (pos); Ptr node = m_gndNodeFactory.Create (); node->AggregateObject (mob); nodes.Add (node); NS_LOG_INFO ("Added ground node at " << pos); } - waypoints.close (); + stream.close (); NS_LOG_INFO ("Added " << nodes.GetN () << " ground nodes"); diff --git a/helper/ground-node-helper.h b/helper/ground-node-helper.h index e7ab16f..31be233 100644 --- a/helper/ground-node-helper.h +++ b/helper/ground-node-helper.h @@ -29,10 +29,10 @@ public: /** * - * \param wpFile path to waypoint file + * \param wpFile path to latitude longitude file * \returns a node container containing nodes using the specified attributes */ - NodeContainer Install (const std::string &wpFile); + NodeContainer Install (const std::string &file); /** * diff --git a/model/leo-circular-orbit-position-allocator.h b/model/leo-circular-orbit-position-allocator.h index 194a82b..0c5b322 100644 --- a/model/leo-circular-orbit-position-allocator.h +++ b/model/leo-circular-orbit-position-allocator.h @@ -1,7 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -#ifndef LEO_CIRCULAR_ORBIT_HELPER_H -#define LEO_CIRCULAR_ORBIT_HELPER_H +#ifndef LEO_CIRCULAR_ORBIT_POSITION_ALLOCATOR_H +#define LEO_CIRCULAR_ORBIT_POSITION_ALLOCATOR_H #include "ns3/position-allocator.h" diff --git a/model/leo-polar-position-allocator.cc b/model/leo-polar-position-allocator.cc new file mode 100644 index 0000000..1cbc635 --- /dev/null +++ b/model/leo-polar-position-allocator.cc @@ -0,0 +1,88 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "math.h" + +#include "ns3/double.h" + +#include "leo-polar-position-allocator.h" + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (LeoPolarPositionAllocator); + +LeoPolarPositionAllocator::LeoPolarPositionAllocator () + : m_latStart (0), m_lonStart (0), m_latEnd (0), m_lonEnd (0), m_step (5), m_lat (-1000.0), m_lon (-1000.0) +{} + +LeoPolarPositionAllocator::~LeoPolarPositionAllocator () +{} + +TypeId +LeoPolarPositionAllocator::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::LeoPolarPositionAllocator") + .SetParent () + .SetGroupName ("Leo") + .AddConstructor () + .AddAttribute ("LatStart", + "Start at this latitude", + DoubleValue (-90), + MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latStart), + MakeDoubleChecker ()) + .AddAttribute ("LatStop", + "Stop at this longitude", + DoubleValue (90), + MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latEnd), + MakeDoubleChecker ()) + .AddAttribute ("LongStart", + "Start at this longitude", + DoubleValue (-180), + MakeDoubleAccessor (&LeoPolarPositionAllocator::m_lonStart), + MakeDoubleChecker ()) + .AddAttribute ("LongStop", + "Stop at this longitude", + DoubleValue (180), + MakeDoubleAccessor (&LeoPolarPositionAllocator::m_lonEnd), + MakeDoubleChecker ()) + .AddAttribute ("Step", + "The degrees inbetween neighboring locations", + DoubleValue (5), + MakeDoubleAccessor (&LeoPolarPositionAllocator::m_step), + MakeDoubleChecker ()) + ; + return tid; +} + +int64_t +LeoPolarPositionAllocator::AssignStreams (int64_t stream) +{ + return -1; +} + +Vector +LeoPolarPositionAllocator::GetNext () const +{ + m_lat = std::max (m_latStart, m_lat); + m_lon = std::max (m_lonStart, m_lon); + + double lat = m_lat * (M_PI / 90); + double lon = m_lon * (M_PI / 180); + Vector3D next = Vector3D (LEO_GND_RAD_EARTH * sin (lat) * cos (lon), + LEO_GND_RAD_EARTH * sin (lat) * sin (lon), + LEO_GND_RAD_EARTH * cos (lat)); + + m_lat = m_lat + m_step; + if (m_lat > m_latEnd) + { + m_lat = m_latStart; + m_lon += m_step; + if (m_lon > m_lonEnd) + { + m_lon = m_lonStart; + } + } + + return next; +} + +}; diff --git a/model/leo-polar-position-allocator.h b/model/leo-polar-position-allocator.h new file mode 100644 index 0000000..d4d64a4 --- /dev/null +++ b/model/leo-polar-position-allocator.h @@ -0,0 +1,45 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_POLAR_POSITION_ALLOCATOR_H +#define LEO_POLAR_POSITION_ALLOCATOR_H + +#include "ns3/position-allocator.h" + +#define LEO_GND_RAD_EARTH 6.371e6 + +namespace ns3 { + +/** + * \brief Allocate pairs of latitude and longitude. + */ +class LeoPolarPositionAllocator : public PositionAllocator +{ +public: + /** + * Register this type with the TypeId system. + * \return the object TypeId + */ + static TypeId GetTypeId (); + + LeoPolarPositionAllocator (); + virtual ~LeoPolarPositionAllocator (); + + virtual Vector GetNext (void) const; + virtual int64_t AssignStreams (int64_t stream); + +private: + double m_latStart; + double m_lonStart; + + double m_latEnd; + double m_lonEnd; + + double m_step; + + mutable double m_lat; + mutable double m_lon; +}; + +}; + +#endif diff --git a/wscript b/wscript index 39ede19..e17975e 100644 --- a/wscript +++ b/wscript @@ -23,6 +23,7 @@ def build(bld): 'model/leo-mock-net-device.cc', 'model/leo-orbit.cc', 'model/leo-lat-long.cc', + 'model/leo-polar-position-allocator.cc', 'model/leo-propagation-loss-model.cc', 'model/mock-net-device.cc', 'model/mock-channel.cc', @@ -66,6 +67,7 @@ def build(bld): 'model/leo-oneweb-constants.h', 'model/leo-orbit.h', 'model/leo-lat-long.h', + 'model/leo-polar-position-allocator.h', 'model/leo-propagation-loss-model.h', 'model/leo-starlink-constants.h', 'model/leo-telesat-constants.h',