From 83ae03cb9aab71745e7ab222c80fac418a67aa57 Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Thu, 5 Jan 2012 18:51:23 +0100 Subject: [PATCH] integrated AntennaModel with spectrum --- src/antenna/model/isotropic-antenna-model.cc | 7 +++ src/antenna/model/isotropic-antenna-model.h | 1 + src/lte/model/lte-spectrum-phy.cc | 15 +++++- src/lte/model/lte-spectrum-phy.h | 13 ++++- .../adhoc-aloha-noack-ideal-phy-helper.cc | 30 +++++++++++ .../adhoc-aloha-noack-ideal-phy-helper.h | 32 ++++++++++++ .../helper/spectrum-analyzer-helper.cc | 30 +++++++++++ .../helper/spectrum-analyzer-helper.h | 33 ++++++++++++ .../helper/waveform-generator-helper.cc | 28 ++++++++++ .../helper/waveform-generator-helper.h | 31 +++++++++++ src/spectrum/model/half-duplex-ideal-phy.cc | 18 ++++++- src/spectrum/model/half-duplex-ideal-phy.h | 12 ++++- .../model/multi-model-spectrum-channel.cc | 52 +++++++++++++------ .../model/multi-model-spectrum-channel.h | 2 +- .../model/single-model-spectrum-channel.cc | 52 +++++++++++++------ .../model/single-model-spectrum-channel.h | 2 +- src/spectrum/model/spectrum-analyzer.cc | 18 ++++++- src/spectrum/model/spectrum-analyzer.h | 11 ++++ src/spectrum/model/spectrum-phy.h | 9 +++- .../model/spectrum-signal-parameters.cc | 2 + .../model/spectrum-signal-parameters.h | 6 +++ src/spectrum/model/waveform-generator.cc | 16 +++++- src/spectrum/model/waveform-generator.h | 14 ++++- src/spectrum/wscript | 2 +- 24 files changed, 394 insertions(+), 42 deletions(-) diff --git a/src/antenna/model/isotropic-antenna-model.cc b/src/antenna/model/isotropic-antenna-model.cc index f9ae4f5ad..0a67405c2 100644 --- a/src/antenna/model/isotropic-antenna-model.cc +++ b/src/antenna/model/isotropic-antenna-model.cc @@ -37,13 +37,20 @@ IsotropicAntennaModel::GetTypeId () { static TypeId tid = TypeId ("ns3::IsotropicAntennaModel") .SetParent () + .AddConstructor () ; return tid; } +IsotropicAntennaModel::IsotropicAntennaModel () +{ + NS_LOG_FUNCTION (this); +} + double IsotropicAntennaModel::GetGainDb (Angles a) { + NS_LOG_FUNCTION (this << a); return 0.0; } diff --git a/src/antenna/model/isotropic-antenna-model.h b/src/antenna/model/isotropic-antenna-model.h index 3c7483303..2fe895910 100644 --- a/src/antenna/model/isotropic-antenna-model.h +++ b/src/antenna/model/isotropic-antenna-model.h @@ -36,6 +36,7 @@ class IsotropicAntennaModel : public AntennaModel { public: + IsotropicAntennaModel (); // inherited from Object static TypeId GetTypeId (); diff --git a/src/lte/model/lte-spectrum-phy.cc b/src/lte/model/lte-spectrum-phy.cc index 2e0aa083a..fc9efdcfd 100644 --- a/src/lte/model/lte-spectrum-phy.cc +++ b/src/lte/model/lte-spectrum-phy.cc @@ -26,7 +26,8 @@ #include #include #include -#include "ns3/spectrum-error-model.h" +#include +#include #include "lte-spectrum-phy.h" #include "lte-spectrum-signal-parameters.h" #include "lte-net-device.h" @@ -224,6 +225,18 @@ LteSpectrumPhy::SetGenericPhyRxEndOkCallback (GenericPhyRxEndOkCallback c) m_phyMacRxEndOkCallback = c; } +Ptr +LteSpectrumPhy::GetRxAntenna () +{ + return m_antenna; +} + +void +LteSpectrumPhy::SetAntenna (Ptr a) +{ + NS_LOG_FUNCTION (this << a); + m_antenna = a; +} void LteSpectrumPhy::SetState (State newState) diff --git a/src/lte/model/lte-spectrum-phy.h b/src/lte/model/lte-spectrum-phy.h index e02a00cf6..b582f4136 100644 --- a/src/lte/model/lte-spectrum-phy.h +++ b/src/lte/model/lte-spectrum-phy.h @@ -44,6 +44,9 @@ class LteNetDevice; * \ingroup lte * * The LteSpectrumPhy models the physical layer of LTE + * + * It supports a single antenna model instance which is + * used for both transmission and reception. */ class LteSpectrumPhy : public SpectrumPhy { @@ -69,6 +72,7 @@ public: Ptr GetMobility (); Ptr GetDevice (); Ptr GetRxSpectrumModel () const; + Ptr GetRxAntenna (); void StartRx (Ptr params); /** @@ -97,6 +101,13 @@ public: */ Ptr GetNoisePowerSpectralDensity (void); + /** + * set the AntennaModel to be used + * + * \param a the Antenna Model + */ + void SetAntenna (Ptr a); + /** * Start a transmission * @@ -165,7 +176,7 @@ private: EventId m_endRxEventId; Ptr m_mobility; - + Ptr m_antenna; Ptr m_device; Ptr m_channel; diff --git a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc b/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc index 8ceeb2966..4111d8bda 100644 --- a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc +++ b/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.cc @@ -24,6 +24,7 @@ #include "ns3/config.h" #include "ns3/simulator.h" #include "ns3/names.h" +#include "ns3/antenna-model.h" #include "ns3/spectrum-channel.h" #include "ns3/half-duplex-ideal-phy.h" #include "ns3/mac48-address.h" @@ -43,6 +44,7 @@ AdhocAlohaNoackIdealPhyHelper::AdhocAlohaNoackIdealPhyHelper () m_phy.SetTypeId ("ns3::HalfDuplexIdealPhy"); m_device.SetTypeId ("ns3::AlohaNoackNetDevice"); m_queue.SetTypeId ("ns3::DropTailQueue"); + m_antenna.SetTypeId ("ns3::IsotropicAntennaModel"); } AdhocAlohaNoackIdealPhyHelper::~AdhocAlohaNoackIdealPhyHelper () @@ -89,6 +91,30 @@ AdhocAlohaNoackIdealPhyHelper::SetDeviceAttribute (std::string name, const Attri m_device.Set (name, v); } +void +AdhocAlohaNoackIdealPhyHelper::SetAntenna (std::string type, + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) +{ + ObjectFactory factory; + factory.SetTypeId (type); + factory.Set (n0, v0); + factory.Set (n1, v1); + factory.Set (n2, v2); + factory.Set (n3, v3); + factory.Set (n4, v4); + factory.Set (n5, v5); + factory.Set (n6, v6); + factory.Set (n7, v7); + m_antenna = factory; +} + NetDeviceContainer AdhocAlohaNoackIdealPhyHelper::Install (NodeContainer c) const { @@ -134,6 +160,10 @@ AdhocAlohaNoackIdealPhyHelper::Install (NodeContainer c) const phy->SetGenericPhyRxEndOkCallback (MakeCallback (&AlohaNoackNetDevice::NotifyReceptionEndOk, dev)); dev->SetGenericPhyTxStartCallback (MakeCallback (&HalfDuplexIdealPhy::StartTx, phy)); + Ptr antenna = (m_antenna.Create ())->GetObject (); + NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object"); + phy->SetAntenna (antenna); + node->AddDevice (dev); devices.Add (dev); } diff --git a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.h b/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.h index 70002af95..7f0da8ae1 100644 --- a/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.h +++ b/src/spectrum/helper/adhoc-aloha-noack-ideal-phy-helper.h @@ -88,6 +88,37 @@ public: */ void SetDeviceAttribute (std::string n1, const AttributeValue &v1); + /** + * \param type the type of the model to set + * \param n0 the name of the attribute to set + * \param v0 the value of the attribute to set + * \param n1 the name of the attribute to set + * \param v1 the value of the attribute to set + * \param n2 the name of the attribute to set + * \param v2 the value of the attribute to set + * \param n3 the name of the attribute to set + * \param v3 the value of the attribute to set + * \param n4 the name of the attribute to set + * \param v4 the value of the attribute to set + * \param n5 the name of the attribute to set + * \param v5 the value of the attribute to set + * \param n6 the name of the attribute to set + * \param v6 the value of the attribute to set + * \param n7 the name of the attribute to set + * \param v7 the value of the attribute to set + * + * Configure the AntennaModel instance for each new device to be created + */ + void SetAntenna (std::string type, + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + /** * @param c the set of nodes on which a device must be created @@ -110,6 +141,7 @@ protected: ObjectFactory m_phy; ObjectFactory m_device; ObjectFactory m_queue; + ObjectFactory m_antenna; Ptr m_channel; Ptr m_txPsd; Ptr m_noisePsd; diff --git a/src/spectrum/helper/spectrum-analyzer-helper.cc b/src/spectrum/helper/spectrum-analyzer-helper.cc index 221bbd8b2..aea386fdc 100644 --- a/src/spectrum/helper/spectrum-analyzer-helper.cc +++ b/src/spectrum/helper/spectrum-analyzer-helper.cc @@ -24,6 +24,7 @@ #include "ns3/config.h" #include "ns3/simulator.h" #include "ns3/names.h" +#include "ns3/antenna-model.h" #include "ns3/spectrum-channel.h" #include "ns3/spectrum-analyzer.h" #include "ns3/non-communicating-net-device.h" @@ -70,6 +71,7 @@ SpectrumAnalyzerHelper::SpectrumAnalyzerHelper () NS_LOG_FUNCTION (this); m_phy.SetTypeId ("ns3::SpectrumAnalyzer"); m_device.SetTypeId ("ns3::NonCommunicatingNetDevice"); + m_antenna.SetTypeId ("ns3::IsotropicAntennaModel"); } SpectrumAnalyzerHelper::~SpectrumAnalyzerHelper () @@ -108,6 +110,30 @@ SpectrumAnalyzerHelper::SetDeviceAttribute (std::string name, const AttributeVal m_device.Set (name, v); } +void +SpectrumAnalyzerHelper::SetAntenna (std::string type, + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) +{ + ObjectFactory factory; + factory.SetTypeId (type); + factory.Set (n0, v0); + factory.Set (n1, v1); + factory.Set (n2, v2); + factory.Set (n3, v3); + factory.Set (n4, v4); + factory.Set (n5, v5); + factory.Set (n6, v6); + factory.Set (n7, v7); + m_antenna = factory; +} + void SpectrumAnalyzerHelper::SetRxSpectrumModel (Ptr m) @@ -155,6 +181,10 @@ SpectrumAnalyzerHelper::Install (NodeContainer c) const dev->SetChannel (m_channel); + Ptr antenna = (m_antenna.Create ())->GetObject (); + NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object"); + phy->SetAntenna (antenna); + uint32_t devId = node->AddDevice (dev); devices.Add (dev); diff --git a/src/spectrum/helper/spectrum-analyzer-helper.h b/src/spectrum/helper/spectrum-analyzer-helper.h index fea0e5751..2d2337ed6 100644 --- a/src/spectrum/helper/spectrum-analyzer-helper.h +++ b/src/spectrum/helper/spectrum-analyzer-helper.h @@ -77,6 +77,37 @@ public: */ void SetDeviceAttribute (std::string n1, const AttributeValue &v1); + /** + * \param type the type of the model to set + * \param n0 the name of the attribute to set + * \param v0 the value of the attribute to set + * \param n1 the name of the attribute to set + * \param v1 the value of the attribute to set + * \param n2 the name of the attribute to set + * \param v2 the value of the attribute to set + * \param n3 the name of the attribute to set + * \param v3 the value of the attribute to set + * \param n4 the name of the attribute to set + * \param v4 the value of the attribute to set + * \param n5 the name of the attribute to set + * \param v5 the value of the attribute to set + * \param n6 the name of the attribute to set + * \param v6 the value of the attribute to set + * \param n7 the name of the attribute to set + * \param v7 the value of the attribute to set + * + * Configure the AntennaModel instance for each new device to be created + */ + void SetAntenna (std::string type, + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + /** * Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals * @@ -112,6 +143,8 @@ public: private: ObjectFactory m_phy; ObjectFactory m_device; + ObjectFactory m_antenna; + Ptr m_channel; Ptr m_rxSpectrumModel; std::string m_prefix; diff --git a/src/spectrum/helper/waveform-generator-helper.cc b/src/spectrum/helper/waveform-generator-helper.cc index f08e39357..7fe6e44a3 100644 --- a/src/spectrum/helper/waveform-generator-helper.cc +++ b/src/spectrum/helper/waveform-generator-helper.cc @@ -24,6 +24,7 @@ #include "ns3/config.h" #include "ns3/simulator.h" #include "ns3/names.h" +#include "ns3/antenna-model.h" #include "ns3/spectrum-channel.h" #include "ns3/waveform-generator.h" #include "ns3/non-communicating-net-device.h" @@ -41,6 +42,7 @@ WaveformGeneratorHelper::WaveformGeneratorHelper () { m_phy.SetTypeId ("ns3::WaveformGenerator"); m_device.SetTypeId ("ns3::NonCommunicatingNetDevice"); + m_antenna.SetTypeId ("ns3::IsotropicAntennaModel"); } WaveformGeneratorHelper::~WaveformGeneratorHelper () @@ -81,6 +83,29 @@ WaveformGeneratorHelper::SetDeviceAttribute (std::string name, const AttributeVa m_device.Set (name, v); } +void +WaveformGeneratorHelper::SetAntenna (std::string type, + std::string n0, const AttributeValue &v0, + std::string n1, const AttributeValue &v1, + std::string n2, const AttributeValue &v2, + std::string n3, const AttributeValue &v3, + std::string n4, const AttributeValue &v4, + std::string n5, const AttributeValue &v5, + std::string n6, const AttributeValue &v6, + std::string n7, const AttributeValue &v7) +{ + ObjectFactory factory; + factory.SetTypeId (type); + factory.Set (n0, v0); + factory.Set (n1, v1); + factory.Set (n2, v2); + factory.Set (n3, v3); + factory.Set (n4, v4); + factory.Set (n5, v5); + factory.Set (n6, v6); + factory.Set (n7, v7); + m_antenna = factory; +} NetDeviceContainer WaveformGeneratorHelper::Install (NodeContainer c) const @@ -110,6 +135,9 @@ WaveformGeneratorHelper::Install (NodeContainer c) const phy->SetChannel (m_channel); dev->SetChannel (m_channel); + Ptr antenna = (m_antenna.Create ())->GetObject (); + NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object"); + phy->SetAntenna (antenna); node->AddDevice (dev); devices.Add (dev); diff --git a/src/spectrum/helper/waveform-generator-helper.h b/src/spectrum/helper/waveform-generator-helper.h index 61ae34d0f..8d8a63e13 100644 --- a/src/spectrum/helper/waveform-generator-helper.h +++ b/src/spectrum/helper/waveform-generator-helper.h @@ -85,6 +85,36 @@ public: */ void SetDeviceAttribute (std::string n1, const AttributeValue &v1); + /** + * \param type the type of the model to set + * \param n0 the name of the attribute to set + * \param v0 the value of the attribute to set + * \param n1 the name of the attribute to set + * \param v1 the value of the attribute to set + * \param n2 the name of the attribute to set + * \param v2 the value of the attribute to set + * \param n3 the name of the attribute to set + * \param v3 the value of the attribute to set + * \param n4 the name of the attribute to set + * \param v4 the value of the attribute to set + * \param n5 the name of the attribute to set + * \param v5 the value of the attribute to set + * \param n6 the name of the attribute to set + * \param v6 the value of the attribute to set + * \param n7 the name of the attribute to set + * \param v7 the value of the attribute to set + * + * Configure the AntennaModel instance for each new device to be created + */ + void SetAntenna (std::string type, + std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), + std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), + std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), + std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), + std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), + std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), + std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), + std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** * @param c the set of nodes on which a device must be created @@ -106,6 +136,7 @@ public: protected: ObjectFactory m_phy; ObjectFactory m_device; + ObjectFactory m_antenna; Ptr m_channel; Ptr m_txPsd; }; diff --git a/src/spectrum/model/half-duplex-ideal-phy.cc b/src/spectrum/model/half-duplex-ideal-phy.cc index 6d8ec7442..df3852c05 100644 --- a/src/spectrum/model/half-duplex-ideal-phy.cc +++ b/src/spectrum/model/half-duplex-ideal-phy.cc @@ -18,7 +18,6 @@ * Author: Nicola Baldo */ -#include #include #include #include @@ -26,6 +25,8 @@ #include #include #include +#include + #include "half-duplex-ideal-phy.h" #include "half-duplex-ideal-phy-signal-parameters.h" #include "spectrum-error-model.h" @@ -241,6 +242,20 @@ HalfDuplexIdealPhy::SetGenericPhyRxEndOkCallback (GenericPhyRxEndOkCallback c) m_phyMacRxEndOkCallback = c; } +Ptr +HalfDuplexIdealPhy::GetRxAntenna () +{ + NS_LOG_FUNCTION (this); + return m_antenna; +} + +void +HalfDuplexIdealPhy::SetAntenna (Ptr a) +{ + NS_LOG_FUNCTION (this << a); + m_antenna = a; +} + void HalfDuplexIdealPhy::ChangeState (State newState) { @@ -270,6 +285,7 @@ HalfDuplexIdealPhy::StartTx (Ptr p) double txTimeSeconds = m_rate.CalculateTxTime (p->GetSize ()); txParams->duration = Seconds (txTimeSeconds); txParams->txPhy = GetObject (); + txParams->txAntenna = m_antenna; txParams->psd = m_txPsd; txParams->data = m_txPacket; diff --git a/src/spectrum/model/half-duplex-ideal-phy.h b/src/spectrum/model/half-duplex-ideal-phy.h index 1427bbdeb..8fae43bef 100644 --- a/src/spectrum/model/half-duplex-ideal-phy.h +++ b/src/spectrum/model/half-duplex-ideal-phy.h @@ -71,6 +71,9 @@ namespace ns3 { * total bandwidth used (i.e., how much of the spectrum is occupied), * and communication reliability) * - the signal propagation + * + * This PHY model supports a single antenna model instance which is + * used for both transmission and reception. */ class HalfDuplexIdealPhy : public SpectrumPhy { @@ -97,6 +100,7 @@ public: Ptr GetMobility (); Ptr GetDevice (); Ptr GetRxSpectrumModel () const; + Ptr GetRxAntenna (); void StartRx (Ptr params); @@ -172,7 +176,12 @@ public: */ void SetGenericPhyRxEndOkCallback (GenericPhyRxEndOkCallback c); - + /** + * set the AntennaModel to be used + * + * \param a the Antenna Model + */ + void SetAntenna (Ptr a); private: virtual void DoDispose (void); @@ -185,6 +194,7 @@ private: EventId m_endRxEventId; Ptr m_mobility; + Ptr m_antenna; Ptr m_netDevice; Ptr m_channel; diff --git a/src/spectrum/model/multi-model-spectrum-channel.cc b/src/spectrum/model/multi-model-spectrum-channel.cc index 2630dd4c3..29489d9f5 100644 --- a/src/spectrum/model/multi-model-spectrum-channel.cc +++ b/src/spectrum/model/multi-model-spectrum-channel.cc @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include "multi-model-spectrum-channel.h" @@ -111,15 +113,16 @@ MultiModelSpectrumChannel::GetTypeId (void) DoubleValue (1.0e9), MakeDoubleAccessor (&MultiModelSpectrumChannel::m_maxLossDb), MakeDoubleChecker ()) - .AddTraceSource ("PropagationLoss", - "If a PropagationLossModel is plugged on the channel, this trace is fired " + .AddTraceSource ("PathLoss", + "This trace is fired " "whenever a new path loss value is calculated. The first and second parameters " "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, " "whereas the third parameters is the loss value in dB. Note that the loss value " - "reported by this trace is the single-frequency loss value obtained by " - "PropagationLossModel, and is not affected by whether an additional " - "SpectrumPropagationLossModel is being used or not.", - MakeTraceSourceAccessor (&MultiModelSpectrumChannel::m_propagationLossTrace)) + "reported by this trace is the single-frequency loss value obtained by evaluating " + "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that " + "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value " + "reported in this trace. ", + MakeTraceSourceAccessor (&MultiModelSpectrumChannel::m_pathLossTrace)) ; return tid; } @@ -285,18 +288,37 @@ MultiModelSpectrumChannel::StartTx (Ptr txParams) if (txMobility && receiverMobility) { + double pathLossDb = 0; + if (rxParams->txAntenna != 0) + { + Angles txAngles (receiverMobility->GetPosition (), txMobility->GetPosition ()); + double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles); + NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB"); + pathLossDb -= txAntennaGain; + } + Ptr rxAntenna = (*rxPhyIterator)->GetRxAntenna (); + if (rxAntenna != 0) + { + Angles rxAngles (txMobility->GetPosition (), receiverMobility->GetPosition ()); + double rxAntennaGain = rxAntenna->GetGainDb (rxAngles); + NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB"); + pathLossDb -= rxAntennaGain; + } if (m_propagationLoss) { - double gainDb = m_propagationLoss->CalcRxPower (0, txMobility, receiverMobility); - m_propagationLossTrace (txParams->txPhy, *rxPhyIterator, -gainDb); - if ( (-gainDb) > m_maxLossDb) - { - // beyond range - continue; - } - double gainLinear = pow (10.0, gainDb / 10.0); - *(rxParams->psd) *= gainLinear; + double propagationGainDb = m_propagationLoss->CalcRxPower (0, txMobility, receiverMobility); + NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB"); + pathLossDb -= propagationGainDb; + } + NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB"); + m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb); + if ( pathLossDb > m_maxLossDb) + { + // beyond range + continue; } + double pathGainLinear = pow (10.0, (-pathLossDb) / 10.0); + *(rxParams->psd) *= pathGainLinear; if (m_spectrumPropagationLoss) { diff --git a/src/spectrum/model/multi-model-spectrum-channel.h b/src/spectrum/model/multi-model-spectrum-channel.h index a50f22dae..6c40e7f44 100644 --- a/src/spectrum/model/multi-model-spectrum-channel.h +++ b/src/spectrum/model/multi-model-spectrum-channel.h @@ -187,7 +187,7 @@ private: double m_maxLossDb; - TracedCallback, Ptr, double > m_propagationLossTrace; + TracedCallback, Ptr, double > m_pathLossTrace; }; diff --git a/src/spectrum/model/single-model-spectrum-channel.cc b/src/spectrum/model/single-model-spectrum-channel.cc index d964f02ec..3a58f0eff 100644 --- a/src/spectrum/model/single-model-spectrum-channel.cc +++ b/src/spectrum/model/single-model-spectrum-channel.cc @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include "single-model-spectrum-channel.h" @@ -80,15 +82,16 @@ SingleModelSpectrumChannel::GetTypeId (void) DoubleValue (1.0e9), MakeDoubleAccessor (&SingleModelSpectrumChannel::m_maxLossDb), MakeDoubleChecker ()) - .AddTraceSource ("PropagationLoss", - "If a PropagationLossModel is plugged on the channel, this trace is fired " + .AddTraceSource ("PathLoss", + "This trace is fired " "whenever a new path loss value is calculated. The first and second parameters " "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, " "whereas the third parameters is the loss value in dB. Note that the loss value " - "reported by this trace is the single-frequency loss value obtained by " - "PropagationLossModel, and is not affected by whether an additional " - "SpectrumPropagationLossModel is being used or not.", - MakeTraceSourceAccessor (&SingleModelSpectrumChannel::m_propagationLossTrace)) + "reported by this trace is the single-frequency loss value obtained by evaluating " + "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that " + "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value " + "reported in this trace. ", + MakeTraceSourceAccessor (&SingleModelSpectrumChannel::m_pathLossTrace)) ; return tid; } @@ -140,18 +143,37 @@ SingleModelSpectrumChannel::StartTx (Ptr txParams) if (senderMobility && receiverMobility) { + double pathLossDb = 0; + if (rxParams->txAntenna != 0) + { + Angles txAngles (receiverMobility->GetPosition (), senderMobility->GetPosition ()); + double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles); + NS_LOG_LOGIC ("txAntennaGain = " << txAntennaGain << " dB"); + pathLossDb -= txAntennaGain; + } + Ptr rxAntenna = (*rxPhyIterator)->GetRxAntenna (); + if (rxAntenna != 0) + { + Angles rxAngles (senderMobility->GetPosition (), receiverMobility->GetPosition ()); + double rxAntennaGain = rxAntenna->GetGainDb (rxAngles); + NS_LOG_LOGIC ("rxAntennaGain = " << rxAntennaGain << " dB"); + pathLossDb -= rxAntennaGain; + } if (m_propagationLoss) { - double gainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility); - m_propagationLossTrace (txParams->txPhy, *rxPhyIterator, -gainDb); - if ( (-gainDb) > m_maxLossDb) - { - // beyond range - continue; - } - double gainLinear = pow (10.0, gainDb / 10.0); - *(rxParams->psd) *= gainLinear; + double propagationGainDb = m_propagationLoss->CalcRxPower (0, senderMobility, receiverMobility); + NS_LOG_LOGIC ("propagationGainDb = " << propagationGainDb << " dB"); + pathLossDb -= propagationGainDb; + } + NS_LOG_LOGIC ("total pathLoss = " << pathLossDb << " dB"); + m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb); + if ( pathLossDb > m_maxLossDb) + { + // beyond range + continue; } + double pathGainLinear = pow (10.0, (-pathLossDb) / 10.0); + *(rxParams->psd) *= pathGainLinear; if (m_spectrumPropagationLoss) { diff --git a/src/spectrum/model/single-model-spectrum-channel.h b/src/spectrum/model/single-model-spectrum-channel.h index 1bf4345f8..2320e541f 100644 --- a/src/spectrum/model/single-model-spectrum-channel.h +++ b/src/spectrum/model/single-model-spectrum-channel.h @@ -109,7 +109,7 @@ private: double m_maxLossDb; - TracedCallback, Ptr, double > m_propagationLossTrace; + TracedCallback, Ptr, double > m_pathLossTrace; }; diff --git a/src/spectrum/model/spectrum-analyzer.cc b/src/spectrum/model/spectrum-analyzer.cc index 09e230e85..661f046fc 100644 --- a/src/spectrum/model/spectrum-analyzer.cc +++ b/src/spectrum/model/spectrum-analyzer.cc @@ -18,12 +18,15 @@ * Author: Nicola Baldo */ -#include + #include #include #include #include #include +#include + +#include "spectrum-analyzer.h" NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer"); @@ -133,6 +136,19 @@ SpectrumAnalyzer::SetChannel (Ptr c) } +Ptr +SpectrumAnalyzer::GetRxAntenna () +{ + return m_antenna; +} + +void +SpectrumAnalyzer::SetAntenna (Ptr a) +{ + NS_LOG_FUNCTION (this << a); + m_antenna = a; +} + void diff --git a/src/spectrum/model/spectrum-analyzer.h b/src/spectrum/model/spectrum-analyzer.h index 69c9caab2..ec1f1e2c9 100644 --- a/src/spectrum/model/spectrum-analyzer.h +++ b/src/spectrum/model/spectrum-analyzer.h @@ -41,6 +41,9 @@ namespace ns3 { * Simple SpectrumPhy implemetation that averages the spectrum power * density of incoming transmissions to produce a spectrogram. * + * + * This PHY model supports a single antenna model instance which is + * used for reception (this PHY model never transmits). */ class SpectrumAnalyzer : public SpectrumPhy { @@ -58,6 +61,7 @@ public: Ptr GetMobility (); Ptr GetDevice (); Ptr GetRxSpectrumModel () const; + Ptr GetRxAntenna (); void StartRx (Ptr params); @@ -68,6 +72,12 @@ public: */ void SetRxSpectrumModel (Ptr m); + /** + * set the AntennaModel to be used + * + * \param a the Antenna Model + */ + void SetAntenna (Ptr a); /** * Start the spectrum analyzer @@ -87,6 +97,7 @@ protected: private: Ptr m_mobility; + Ptr m_antenna; Ptr m_netDevice; Ptr m_channel; diff --git a/src/spectrum/model/spectrum-phy.h b/src/spectrum/model/spectrum-phy.h index 4d0c474f9..d7da55524 100644 --- a/src/spectrum/model/spectrum-phy.h +++ b/src/spectrum/model/spectrum-phy.h @@ -30,6 +30,7 @@ namespace ns3 { class PacketBurst; class SpectrumChannel; class MobilityModel; +class AntennaModel; class SpectrumValue; class SpectrumModel; class NetDevice; @@ -77,7 +78,6 @@ public: */ virtual Ptr GetMobility () = 0; - /** * Set the channel attached to this device. * @@ -93,6 +93,13 @@ public: */ virtual Ptr GetRxSpectrumModel () const = 0; + /** + * get the AntennaModel used by the NetDevice for reception + * + * @return a Ptr to the AntennaModel used by the NetDevice for reception + */ + virtual Ptr GetRxAntenna () = 0; + /** * Notify the SpectrumPhy instance of an incoming signal * diff --git a/src/spectrum/model/spectrum-signal-parameters.cc b/src/spectrum/model/spectrum-signal-parameters.cc index 5b7cc38e4..2dec28d7d 100644 --- a/src/spectrum/model/spectrum-signal-parameters.cc +++ b/src/spectrum/model/spectrum-signal-parameters.cc @@ -23,6 +23,7 @@ #include #include #include +#include NS_LOG_COMPONENT_DEFINE ("SpectrumSignalParameters"); @@ -45,6 +46,7 @@ SpectrumSignalParameters::SpectrumSignalParameters (const SpectrumSignalParamete psd = p.psd->Copy (); duration = p.duration; txPhy = p.txPhy; + txAntenna = p.txAntenna; } Ptr diff --git a/src/spectrum/model/spectrum-signal-parameters.h b/src/spectrum/model/spectrum-signal-parameters.h index e99f616da..f2d3db275 100644 --- a/src/spectrum/model/spectrum-signal-parameters.h +++ b/src/spectrum/model/spectrum-signal-parameters.h @@ -32,6 +32,7 @@ namespace ns3 { class SpectrumPhy; class SpectrumValue; +class AntennaModel; /** * This struct provides the generic signal representation to be used by @@ -102,6 +103,11 @@ struct SpectrumSignalParameters : public SimpleRefCount txPhy; + + /** + * The AntennaModel instance that was used to transmit this signal. + */ + Ptr txAntenna; }; diff --git a/src/spectrum/model/waveform-generator.cc b/src/spectrum/model/waveform-generator.cc index 91d1161f5..3d02bc6e0 100644 --- a/src/spectrum/model/waveform-generator.cc +++ b/src/spectrum/model/waveform-generator.cc @@ -18,13 +18,15 @@ * Author: Nicola Baldo */ -#include + #include #include #include #include #include +#include +#include "waveform-generator.h" NS_LOG_COMPONENT_DEFINE ("WaveformGenerator"); @@ -146,7 +148,18 @@ WaveformGenerator::SetTxPowerSpectralDensity (Ptr txPsd) m_txPowerSpectralDensity = txPsd; } +Ptr +WaveformGenerator::GetRxAntenna () +{ + return m_antenna; +} +void +WaveformGenerator::SetAntenna (Ptr a) +{ + NS_LOG_FUNCTION (this << a); + m_antenna = a; +} void WaveformGenerator::SetPeriod (Time period) @@ -184,6 +197,7 @@ WaveformGenerator::GenerateWaveform () txParams->duration = Time (m_period * m_dutyCycle); txParams->psd = m_txPowerSpectralDensity; txParams->txPhy = GetObject (); + txParams->txAntenna = m_antenna; NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity); m_phyTxStartTrace (0); diff --git a/src/spectrum/model/waveform-generator.h b/src/spectrum/model/waveform-generator.h index 2c1efcdcd..0091971ad 100644 --- a/src/spectrum/model/waveform-generator.h +++ b/src/spectrum/model/waveform-generator.h @@ -43,6 +43,10 @@ namespace ns3 { * duration (set with the SetResolution()) . The generator activates * and deactivates periodically with a given period and with a duty * cycle of 1/2. + * + * This PHY model supports a single antenna model instance which is + * used for both transmission and reception (though received signals + * are discarded by this PHY). */ class WaveformGenerator : public SpectrumPhy { @@ -60,6 +64,7 @@ public: Ptr GetMobility (); Ptr GetDevice (); Ptr GetRxSpectrumModel () const; + Ptr GetRxAntenna (); void StartRx (Ptr params); @@ -99,8 +104,12 @@ public: */ double GetDutyCycle () const; - - + /** + * set the AntennaModel to be used + * + * \param a the Antenna Model + */ + void SetAntenna (Ptr a); /** * Start the waveform generator @@ -119,6 +128,7 @@ private: virtual void DoDispose (void); Ptr m_mobility; + Ptr m_antenna; Ptr m_netDevice; Ptr m_channel; diff --git a/src/spectrum/wscript b/src/spectrum/wscript index 08e06d9a6..6df25a48f 100644 --- a/src/spectrum/wscript +++ b/src/spectrum/wscript @@ -2,7 +2,7 @@ def build(bld): - module = bld.create_ns3_module('spectrum', ['internet', 'propagation', 'applications']) + module = bld.create_ns3_module('spectrum', ['internet', 'propagation', 'antenna', 'applications']) module.source = [ 'model/spectrum-model.cc', 'model/spectrum-value.cc',