From bb3bcb627ce5cd5073c34f101db78bdb1ae1b93f Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Mon, 10 Aug 2020 14:03:59 +0200 Subject: [PATCH] Add constructor for channls wih params for constellations --- helper/leo-channel-helper.cc | 60 ++++++++++++++++++++++++++++++++++ helper/leo-channel-helper.h | 12 +++++++ model/leo-starlink-constants.h | 2 +- model/mock-channel.cc | 17 ++++++++-- model/mock-channel.h | 4 ++- model/mock-net-device.cc | 28 +++++++++++++++- model/mock-net-device.h | 15 +++++++++ 7 files changed, 132 insertions(+), 6 deletions(-) diff --git a/helper/leo-channel-helper.cc b/helper/leo-channel-helper.cc index e07bc1b..bb6c984 100644 --- a/helper/leo-channel-helper.cc +++ b/helper/leo-channel-helper.cc @@ -6,9 +6,13 @@ #include "ns3/enum.h" #include "ns3/queue.h" #include "ns3/names.h" +#include "ns3/assert.h" +#include "ns3/string.h" #include "../model/leo-mock-channel.h" #include "../model/leo-mock-net-device.h" +#include "../model/leo-starlink-constants.h" +#include "../model/leo-telesat-constants.h" namespace ns3 { @@ -29,6 +33,61 @@ LeoChannelHelper::LeoChannelHelper () m_channelFactory.SetTypeId ("ns3::LeoMockChannel"); } +LeoChannelHelper::LeoChannelHelper (std::string constellation) : + LeoChannelHelper () +{ + SetConstellation (constellation); +} + +void +LeoChannelHelper::SetConstellation (std::string constellation); +{ + if (constellation == "Starlink") + { + SetConstellationAttributes (LEO_STARLINK_EIRP, + LEO_STARLINK_ELEVATION_ANGLE, + LEO_STARLINK_FSPL, + LEO_STARLINK_ATMOSPHERIC_LOSS, + LEO_STARLINK_LINK_MARGIN, + LEO_STARLINK_DATA_RATE); + } + else if (constellation == "Telesat") + { + SetConstellationAttributes (LEO_TELESAT_EIRP, + LEO_TELESAT_ELEVATION_ANGLE, + LEO_TELESAT_FSPL, + LEO_TELESAT_ATMOSPHERIC_LOSS, + LEO_TELESAT_LINK_MARGIN, + LEO_TELESAT_DATA_RATE); + } + else + { + NS_ASSERT_MSG (false, "Invalid constellation"); + } +} + +void +LeoChannelHelper::SetConstellationAttributes (double eirp, + double elevationAngle, + double fspl, + double atmosphericLoss, + double linkMargin, + double dataRate) +{ + m_gndDeviceFactory.Set ("TxPower", DoubleValue (eirp)); + m_satDeviceFactory.Set ("TxPower", DoubleValue (eirp)); + + m_gndDeviceFactory.Set ("DataRate", DoubleValue (dataRate)); + m_satDeviceFactory.Set ("DataRate", DoubleValue (dataRate)); + + m_propagationLossFactory.SetTypeId ("ns3::LeoPropagationLossModel"); + + m_propagationLossFactory.Set ("ElevationAngle", DoubleValue (elevationAngle)); + m_propagationLossFactory.Set ("FreeSpaceLoss", DoubleValue (fspl)); + m_propagationLossFactory.Set ("AtmosphericLoss", DoubleValue (atmosphericLoss)); + m_propagationLossFactory.Set ("LinkMargin", DoubleValue (linkMargin)); +} + void LeoChannelHelper::SetQueue(ObjectFactory &factory, std::string type, @@ -233,6 +292,7 @@ LeoChannelHelper::Install (std::vector > &satellites, std::vector channel = m_channelFactory.Create (); + channel->SetPropagationLoss (m_propagationLossFactory.Create ()); NetDeviceContainer container; diff --git a/helper/leo-channel-helper.h b/helper/leo-channel-helper.h index d304f5d..6cad740 100644 --- a/helper/leo-channel-helper.h +++ b/helper/leo-channel-helper.h @@ -20,6 +20,7 @@ class LeoChannelHelper : public PcapHelperForDevice, { public: LeoChannelHelper (); + LeoChannelHelper (std::string constellation); virtual ~LeoChannelHelper () {}; @@ -49,6 +50,8 @@ public: Ptr nd, bool explicitFilename); + void SetConstellation (std::string constellation); + private: ObjectFactory m_satQueueFactory; ObjectFactory m_gndDeviceFactory; @@ -58,6 +61,8 @@ private: ObjectFactory m_channelFactory; + ObjectFactory m_propagationLossFactory; + void SetQueue (ObjectFactory &factory, std::string type, std::string n1, const AttributeValue &v1, @@ -65,6 +70,13 @@ private: std::string n3, const AttributeValue &v3, std::string n4, const AttributeValue &v4); + + void SetConstellationAttributes (double eirp, + double elevationAngle, + double fspl, + double atmosphericLoss, + double linkMargin, + double dataRate); }; }; diff --git a/model/leo-starlink-constants.h b/model/leo-starlink-constants.h index f4a7f09..a170eb0 100644 --- a/model/leo-starlink-constants.h +++ b/model/leo-starlink-constants.h @@ -31,7 +31,7 @@ namespace ns3 { #define LEO_STARLINK_PATH_DISTANCE 1684 // km #define LEO_STARLINK_ELEVATION_ANGLE 40 // deg #define LEO_STARLINK_FSPL 186.1 // dB -#define LEO_STARLINK_ATMOSPHERIC_LOSS 2.9 // dBm +#define LEO_STARLINK_ATMOSPHERIC_LOSS 2.9 // dB #define LEO_STARLINK_RX_ANTENNA_GAIN 40.9 // dBi #define LEO_STARLINK_SYSTEM_TEMP 535.9 // K #define LEO_STARLINK_G_T 13.6 // dB/K diff --git a/model/mock-channel.cc b/model/mock-channel.cc index 60ccc8b..8a695c6 100644 --- a/model/mock-channel.cc +++ b/model/mock-channel.cc @@ -155,6 +155,12 @@ MockChannel::GetPropagationLoss () const return m_propagationLoss; } +void +MockChannel::SetPropagationLoss (PropagationLossModel model) +{ + m_propagationLoss = model; +} + bool MockChannel::Deliver ( Ptr p, @@ -168,13 +174,17 @@ MockChannel::Deliver ( Ptr srcMob = src->GetObject (); Ptr dstMob = dst->GetObject (); + double txPower = src->GetTxPower (); + double rxPower = txPower; + if (srcMob != 0 && dstMob != 0) { Ptr pLoss = GetPropagationLoss (); if (pLoss != 0) { - // check if Rx power is below link margin - if (pLoss->CalcRxPower (src->GetTxPower (), srcMob, dstMob) == 0.0) + // check if signal reaches destination + rxPower = pLoss->CalcRxPower (txPower, srcMob, dstMob); + if (rxPower == 0.0) { return false; } @@ -187,7 +197,8 @@ MockChannel::Deliver ( &MockNetDevice::Receive, dst, p->Copy (), - src); + src, + rxPower); // Call the tx anim callback on the net device m_txrxMock (p, src, dst, txTime, delay); diff --git a/model/mock-channel.h b/model/mock-channel.h index 904012b..674e3ca 100644 --- a/model/mock-channel.h +++ b/model/mock-channel.h @@ -72,6 +72,9 @@ public: std::size_t GetNDevices (void) const; virtual bool TransmitStart (Ptr p, uint32_t devId, Address dst, Time txTime) = 0; + Ptr GetPropagationLoss () const; + void SetPropagationLoss (PropagationLossModel model); + protected: TracedCallback, // Packet being transmitted Ptr, // Transmitting NetDevice @@ -87,7 +90,6 @@ protected: Time GetPropagationDelay (Ptr first, Ptr second, Time txTime) const; Ptr GetPropagationDelay () const; - Ptr GetPropagationLoss () const; Ptr GetDevice (Address &addr) const; bool Deliver ( Ptr p, Ptr src, Ptr dst, Time txTime); diff --git a/model/mock-net-device.cc b/model/mock-net-device.cc index 6327900..fb7def4 100644 --- a/model/mock-net-device.cc +++ b/model/mock-net-device.cc @@ -70,6 +70,11 @@ MockNetDevice::GetTypeId (void) TimeValue (Seconds (0.0)), MakeTimeAccessor (&MockNetDevice::m_tInterframeGap), MakeTimeChecker ()) + .AddAttribute ("RxThreshold", + "Receive threshold in dBm", + DoubleValue (0.0), + MakeDoubleAccessor (&MockNetDevice::m_rxThreshold), + MakeDoubleChecker ()) .AddAttribute ("TxPower", "Transmit power in dBm", DoubleValue (1.0), @@ -410,7 +415,9 @@ MockNetDevice::SetReceiveErrorModel (Ptr em) } void -MockNetDevice::Receive (Ptr packet, Ptr senderDevice) +MockNetDevice::Receive (Ptr packet, + Ptr senderDevice, + double rxPower) { NS_LOG_FUNCTION (this << packet << senderDevice); @@ -421,6 +428,13 @@ MockNetDevice::Receive (Ptr packet, Ptr senderDevice) m_phyRxEndTrace (packet); + if (rxPower < m_rxThreshold) + { + // Received power is below threshold + m_phyRxDropTrace (packet); + return; + } + if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) { // @@ -783,4 +797,16 @@ MockNetDevice::SetTxPower (double txPower) m_txPower = txPower; } +double +MockNetDevice::GetRxTreshold () const +{ + return m_rxThreshold; +} + +void +MockNetDevice::SetRxThreshold (double rxThresh) +{ + m_rxThreshold = rxThresh; +} + } // namespace ns3 diff --git a/model/mock-net-device.h b/model/mock-net-device.h index 971bdc7..35d25bb 100644 --- a/model/mock-net-device.h +++ b/model/mock-net-device.h @@ -101,6 +101,16 @@ public: */ void SetTxPower (double txPower); + /** + * Get the receive threshold in dBm + */ + double GetRxTreshold () const; + + /** + * Set the receive threshold in dBm + */ + void SetRxThreshold (double rxThresh); + /** * Attach a queue to the MockNetDevice. * @@ -295,6 +305,11 @@ private: */ double m_txPower; + /** + * Minimum threshold for received power + */ + double m_rxThreshold; + /** * The state of the Net Device transmit state machine. */