Fix ground station allocator and trace mac drops

This commit is contained in:
Tim Schubert 2020-08-27 17:59:58 +02:00
parent 8d5cbfe8fe
commit 998b7fe2f2
15 changed files with 222 additions and 80 deletions

View file

@ -85,7 +85,7 @@ IslMockChannel::TransmitStart (
}
else
{
NS_LOG_LOGIC ("destination address " << destAddr << " unknown on channel");
NS_LOG_ERROR ("destination address " << destAddr << " unknown on channel");
return false;
}
}

View file

@ -6,16 +6,15 @@ namespace ns3 {
std::ostream &operator << (std::ostream &os, const LeoLatLong &l)
{
os << l.label << "," << l.latitude << "," << l.longitude;
os << l.latitude << ":" << l.longitude;
return os;
}
std::istream &operator >> (std::istream &is, LeoLatLong &l)
{
char c1, c2;
is >> l.label >> c1 >> l.latitude >> c2 >> l.longitude;
if (c1 != ',' ||
c2 != ',')
char c1;
is >> l.latitude >> c1 >> l.longitude;
if (c1 != ':')
{
is.setstate (std::ios_base::failbit);
}
@ -24,7 +23,6 @@ std::istream &operator >> (std::istream &is, LeoLatLong &l)
LeoLatLong::LeoLatLong () : latitude (0), longitude (0) {}
LeoLatLong::LeoLatLong (double la, double lo) : latitude (la), longitude (lo) {}
LeoLatLong::LeoLatLong (std::string label, double la, double lo) : latitude (la), longitude (lo) {}
LeoLatLong::~LeoLatLong () {}
};

View file

@ -12,10 +12,8 @@ class LeoLatLong
public:
LeoLatLong ();
LeoLatLong (double latitude, double longitude);
LeoLatLong (std::string label, double latitude, double longitude);
virtual ~LeoLatLong();
std::string label;
double latitude;
double longitude;
};

View file

@ -79,11 +79,16 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> p,
return false;
}
// make sure to return false if packet has been delivered to *no* device
bool result = false;
for (DeviceIndex::iterator it = dests->begin (); it != dests->end(); it ++)
{
Deliver (p, srcDev, it->second, txTime);
if (Deliver (p, srcDev, it->second, txTime))
{
result = true;
}
}
return true;
return result;
}
int32_t

View file

@ -3,6 +3,8 @@
#include "math.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
#include "ns3/log.h"
#include "leo-polar-position-allocator.h"
@ -10,8 +12,10 @@ namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (LeoPolarPositionAllocator);
NS_LOG_COMPONENT_DEFINE ("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)
: m_latStart (0), m_lonStart (0), m_latStop (0), m_lonStop (0), m_latNum (1), m_lonNum (1), m_lat (0), m_lon (0)
{}
LeoPolarPositionAllocator::~LeoPolarPositionAllocator ()
@ -27,28 +31,37 @@ LeoPolarPositionAllocator::GetTypeId (void)
.AddAttribute ("LatStart",
"Start at this latitude",
DoubleValue (-90),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latStart),
MakeDoubleAccessor (&LeoPolarPositionAllocator::SetLatStart,
&LeoPolarPositionAllocator::GetLatStart),
MakeDoubleChecker<double> ())
.AddAttribute ("LatStop",
"Stop at this longitude",
DoubleValue (90),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_latEnd),
MakeDoubleAccessor (&LeoPolarPositionAllocator::SetLatStop,
&LeoPolarPositionAllocator::GetLatStop),
MakeDoubleChecker<double> ())
.AddAttribute ("LatNum",
"The number nodes along one latitude",
UintegerValue (10),
MakeUintegerAccessor (&LeoPolarPositionAllocator::m_latNum),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("LongStart",
"Start at this longitude",
DoubleValue (-180),
MakeDoubleAccessor (&LeoPolarPositionAllocator::m_lonStart),
MakeDoubleAccessor (&LeoPolarPositionAllocator::SetLonStart,
&LeoPolarPositionAllocator::GetLonStart),
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),
MakeDoubleAccessor (&LeoPolarPositionAllocator::SetLonStop,
&LeoPolarPositionAllocator::GetLonStop),
MakeDoubleChecker<double> ())
.AddAttribute ("LonNum",
"The number nodes along one longitude",
UintegerValue (10),
MakeUintegerAccessor (&LeoPolarPositionAllocator::m_lonNum),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
@ -56,33 +69,88 @@ LeoPolarPositionAllocator::GetTypeId (void)
int64_t
LeoPolarPositionAllocator::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
return -1;
}
Vector
LeoPolarPositionAllocator::GetNext () const
{
m_lat = std::max (m_latStart, m_lat);
m_lon = std::max (m_lonStart, m_lon);
NS_LOG_FUNCTION (this);
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));
double lat = m_lat * (M_PI / m_latNum) - (M_PI / 2);
double lon = m_lon * (2 * M_PI / m_lonNum) - M_PI;
Vector3D next = Vector3D (LEO_GND_RAD_EARTH * cos (lat) * cos (lon),
LEO_GND_RAD_EARTH * cos (lat) * sin (lon),
LEO_GND_RAD_EARTH * sin (lat));
m_lat = m_lat + m_step;
if (m_lat > m_latEnd)
m_lat ++;
if (m_lat > m_latNum)
{
m_lat = m_latStart;
m_lon += m_step;
if (m_lon > m_lonEnd)
{
m_lon = m_lonStart;
}
m_lat = 0;
m_lon = (m_lon+1) % m_lonNum;
}
NS_LOG_INFO ("Ground station at " << lat << ":" << lon << " -> " << next);
return next;
}
double
LeoPolarPositionAllocator::GetLatStart () const
{
NS_LOG_FUNCTION (this);
return m_latStart * (180.0 / M_PI);
}
double
LeoPolarPositionAllocator::GetLonStart () const
{
NS_LOG_FUNCTION (this);
return m_lonStart * (180.0 / M_PI);
}
double
LeoPolarPositionAllocator::GetLatStop () const
{
NS_LOG_FUNCTION (this);
return m_latStop * (180.0 / M_PI);
}
double
LeoPolarPositionAllocator::GetLonStop () const
{
NS_LOG_FUNCTION (this);
return m_lonStop * (180.0 / M_PI);
}
void
LeoPolarPositionAllocator::SetLatStart (double lat)
{
NS_LOG_FUNCTION (this << lat);
m_latStart = (lat / 180.0) * M_PI;
}
void
LeoPolarPositionAllocator::SetLonStart (double lon)
{
NS_LOG_FUNCTION (this << lon);
m_lonStart = (lon / 180.0) * M_PI;
}
void
LeoPolarPositionAllocator::SetLatStop (double lat)
{
NS_LOG_FUNCTION (this << lat);
m_latStop = (lat / 180.0) * M_PI;
}
void
LeoPolarPositionAllocator::SetLonStop (double lon)
{
NS_LOG_FUNCTION (this << lon);
m_lonStop = (lon / 180.0) * M_PI;
}
};

View file

@ -27,17 +27,28 @@ public:
virtual Vector GetNext (void) const;
virtual int64_t AssignStreams (int64_t stream);
double GetLatStart () const;
double GetLonStart () const;
double GetLatStop () const;
double GetLonStop () const;
private:
double m_latStart;
double m_lonStart;
double m_latEnd;
double m_lonEnd;
double m_latStop;
double m_lonStop;
double m_step;
uint32_t m_latNum;
uint32_t m_lonNum;
mutable double m_lat;
mutable double m_lon;
mutable uint32_t m_lat;
mutable uint32_t m_lon;
void SetLatStart (double lat);
void SetLonStart (double lon);
void SetLatStop (double lat);
void SetLonStop (double lon);
};
};

View file

@ -23,7 +23,7 @@ LeoPropagationLossModel::GetTypeId (void)
.AddConstructor<LeoPropagationLossModel> ()
.AddAttribute ("MaxDistance",
"Cut-off distance for signal propagation",
DoubleValue (2000.0),
DoubleValue (3000.0),
MakeDoubleAccessor (&LeoPropagationLossModel::SetCutoffDistance,
&LeoPropagationLossModel::GetCutoffDistance),
MakeDoubleChecker<double> ())

View file

@ -170,6 +170,7 @@ MockChannel::Deliver (
rxPower = pLoss->CalcRxPower (txPower, srcMob, dstMob);
if (rxPower <= -1000.0)
{
NS_LOG_WARN (this << "unable to reach destination " << dst->GetNode ()->GetId () << " from " << src->GetNode ()->GetId ());
return false;
}
}

View file

@ -102,14 +102,12 @@ MockNetDevice::GetTypeId (void)
"This is a non-promiscuous trace,",
MakeTraceSourceAccessor (&MockNetDevice::m_macRxTrace),
"ns3::Packet::TracedCallback")
#if 0
// Not currently implemented for this device
.AddTraceSource ("MacRxDrop",
"Trace source indicating a packet was dropped "
"before being forwarded up the stack",
MakeTraceSourceAccessor (&MockNetDevice::m_macRxDropTrace),
"ns3::Packet::TracedCallback")
#endif
//
// Trace sources at the "bottom" of the net device, where packets transition
// to/from the channel.
@ -413,6 +411,7 @@ MockNetDevice::Receive (Ptr<Packet> packet,
if (senderDevice == this)
{
m_macRxDropTrace (packet);
return;
}
@ -684,10 +683,15 @@ MockNetDevice::Send (Ptr<Packet> packet,
m_snifferTrace (packet);
TransmitStart (packet, dest);
}
else
{
NS_LOG_LOGIC (this << "channel not ready, postponing transmit start: " << m_queue->GetCurrentSize () << "/" << m_queue->GetMaxSize ());
}
return true;
}
// Enqueue may fail (overflow)
NS_LOG_WARN ("queue overflowed: " << m_queue->GetCurrentSize () << "/" << m_queue->GetMaxSize ());
m_macTxDropTrace (packet);
return false;