Add polar position allocator

This commit is contained in:
Tim Schubert 2020-08-23 22:10:21 +02:00
parent 70c70a19ce
commit ab7c9881f6
7 changed files with 147 additions and 12 deletions

View file

@ -40,7 +40,6 @@ int main (int argc, char *argv[])
cmd.AddValue("groundFile", "CSV file with ground station locations", groundFile); cmd.AddValue("groundFile", "CSV file with ground station locations", groundFile);
cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision"); cmd.AddValue("precision", "ns3::LeoCircularOrbitMobilityModel::Precision");
cmd.AddValue("duration", "Duration of the simulation", duration); cmd.AddValue("duration", "Duration of the simulation", duration);
// TODO LeoLatLong
cmd.AddValue("source", "Traffic source", source); cmd.AddValue("source", "Traffic source", source);
cmd.AddValue("destination", "Traffic destination", destination); cmd.AddValue("destination", "Traffic destination", destination);
cmd.AddValue("islRate", "Throughput of the ISL link", islRate); cmd.AddValue("islRate", "Throughput of the ISL link", islRate);

View file

@ -30,24 +30,25 @@ LeoGndNodeHelper::SetAttribute (string name, const AttributeValue &value)
} }
NodeContainer NodeContainer
LeoGndNodeHelper::Install (const std::string &wpFile) LeoGndNodeHelper::Install (const std::string &file)
{ {
NS_LOG_FUNCTION (wpFile); NS_LOG_FUNCTION (this << file);
NodeContainer nodes; NodeContainer nodes;
ifstream waypoints; ifstream stream;
waypoints.open (wpFile, ifstream::in); stream.open (file, ifstream::in);
Vector pos; LeoLatLong loc;
while ((waypoints >> pos)) while ((stream >> loc))
{ {
Ptr<ConstantPositionMobilityModel> mob = CreateObject<ConstantPositionMobilityModel> (); Ptr<ConstantPositionMobilityModel> mob = CreateObject<ConstantPositionMobilityModel> ();
Vector pos = GetEarthPosition (loc);
mob->SetPosition (pos); mob->SetPosition (pos);
Ptr<Node> node = m_gndNodeFactory.Create<Node> (); Ptr<Node> node = m_gndNodeFactory.Create<Node> ();
node->AggregateObject (mob); node->AggregateObject (mob);
nodes.Add (node); nodes.Add (node);
NS_LOG_INFO ("Added ground node at " << pos); NS_LOG_INFO ("Added ground node at " << pos);
} }
waypoints.close (); stream.close ();
NS_LOG_INFO ("Added " << nodes.GetN () << " ground nodes"); NS_LOG_INFO ("Added " << nodes.GetN () << " ground nodes");

View file

@ -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 * \returns a node container containing nodes using the specified attributes
*/ */
NodeContainer Install (const std::string &wpFile); NodeContainer Install (const std::string &file);
/** /**
* *

View file

@ -1,7 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#ifndef LEO_CIRCULAR_ORBIT_HELPER_H #ifndef LEO_CIRCULAR_ORBIT_POSITION_ALLOCATOR_H
#define LEO_CIRCULAR_ORBIT_HELPER_H #define LEO_CIRCULAR_ORBIT_POSITION_ALLOCATOR_H
#include "ns3/position-allocator.h" #include "ns3/position-allocator.h"

View file

@ -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<PositionAllocator> ()
.SetGroupName ("Leo")
.AddConstructor<LeoPolarPositionAllocator> ()
.AddAttribute ("LatStart",
"Start at this latitude",
DoubleValue (-90),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latStart),
MakeDoubleChecker<double> ())
.AddAttribute ("LatStop",
"Stop at this longitude",
DoubleValue (90),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latEnd),
MakeDoubleChecker<double> ())
.AddAttribute ("LongStart",
"Start at this longitude",
DoubleValue (-180),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_lonStart),
MakeDoubleChecker<double> ())
.AddAttribute ("LongStop",
"Stop at this longitude",
DoubleValue (180),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_lonEnd),
MakeDoubleChecker<double> ())
.AddAttribute ("Step",
"The degrees inbetween neighboring locations",
DoubleValue (5),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_step),
MakeDoubleChecker<double> ())
;
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;
}
};

View file

@ -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

View file

@ -23,6 +23,7 @@ def build(bld):
'model/leo-mock-net-device.cc', 'model/leo-mock-net-device.cc',
'model/leo-orbit.cc', 'model/leo-orbit.cc',
'model/leo-lat-long.cc', 'model/leo-lat-long.cc',
'model/leo-polar-position-allocator.cc',
'model/leo-propagation-loss-model.cc', 'model/leo-propagation-loss-model.cc',
'model/mock-net-device.cc', 'model/mock-net-device.cc',
'model/mock-channel.cc', 'model/mock-channel.cc',
@ -66,6 +67,7 @@ def build(bld):
'model/leo-oneweb-constants.h', 'model/leo-oneweb-constants.h',
'model/leo-orbit.h', 'model/leo-orbit.h',
'model/leo-lat-long.h', 'model/leo-lat-long.h',
'model/leo-polar-position-allocator.h',
'model/leo-propagation-loss-model.h', 'model/leo-propagation-loss-model.h',
'model/leo-starlink-constants.h', 'model/leo-starlink-constants.h',
'model/leo-telesat-constants.h', 'model/leo-telesat-constants.h',