integrated AntennaModel with spectrum

This commit is contained in:
Nicola Baldo
2012-01-05 18:51:23 +01:00
parent 5a05c22d02
commit 83ae03cb9a
24 changed files with 394 additions and 42 deletions

View File

@@ -37,13 +37,20 @@ IsotropicAntennaModel::GetTypeId ()
{
static TypeId tid = TypeId ("ns3::IsotropicAntennaModel")
.SetParent<AntennaModel> ()
.AddConstructor<IsotropicAntennaModel> ()
;
return tid;
}
IsotropicAntennaModel::IsotropicAntennaModel ()
{
NS_LOG_FUNCTION (this);
}
double
IsotropicAntennaModel::GetGainDb (Angles a)
{
NS_LOG_FUNCTION (this << a);
return 0.0;
}

View File

@@ -36,6 +36,7 @@ class IsotropicAntennaModel : public AntennaModel
{
public:
IsotropicAntennaModel ();
// inherited from Object
static TypeId GetTypeId ();

View File

@@ -26,7 +26,8 @@
#include <math.h>
#include <ns3/simulator.h>
#include <ns3/trace-source-accessor.h>
#include "ns3/spectrum-error-model.h"
#include <ns3/antenna-model.h>
#include <ns3/spectrum-error-model.h>
#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<AntennaModel>
LteSpectrumPhy::GetRxAntenna ()
{
return m_antenna;
}
void
LteSpectrumPhy::SetAntenna (Ptr<AntennaModel> a)
{
NS_LOG_FUNCTION (this << a);
m_antenna = a;
}
void
LteSpectrumPhy::SetState (State newState)

View File

@@ -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<MobilityModel> GetMobility ();
Ptr<NetDevice> GetDevice ();
Ptr<const SpectrumModel> GetRxSpectrumModel () const;
Ptr<AntennaModel> GetRxAntenna ();
void StartRx (Ptr<SpectrumSignalParameters> params);
/**
@@ -97,6 +101,13 @@ public:
*/
Ptr<const SpectrumValue> GetNoisePowerSpectralDensity (void);
/**
* set the AntennaModel to be used
*
* \param a the Antenna Model
*/
void SetAntenna (Ptr<AntennaModel> a);
/**
* Start a transmission
*
@@ -165,7 +176,7 @@ private:
EventId m_endRxEventId;
Ptr<MobilityModel> m_mobility;
Ptr<AntennaModel> m_antenna;
Ptr<NetDevice> m_device;
Ptr<SpectrumChannel> m_channel;

View File

@@ -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<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
phy->SetAntenna (antenna);
node->AddDevice (dev);
devices.Add (dev);
}

View File

@@ -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<SpectrumChannel> m_channel;
Ptr<SpectrumValue> m_txPsd;
Ptr<SpectrumValue> m_noisePsd;

View File

@@ -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<SpectrumModel> m)
@@ -155,6 +181,10 @@ SpectrumAnalyzerHelper::Install (NodeContainer c) const
dev->SetChannel (m_channel);
Ptr<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
phy->SetAntenna (antenna);
uint32_t devId = node->AddDevice (dev);
devices.Add (dev);

View File

@@ -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<SpectrumChannel> m_channel;
Ptr<SpectrumModel> m_rxSpectrumModel;
std::string m_prefix;

View File

@@ -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<AntennaModel> antenna = (m_antenna.Create ())->GetObject<AntennaModel> ();
NS_ASSERT_MSG (antenna, "error in creating the AntennaModel object");
phy->SetAntenna (antenna);
node->AddDevice (dev);
devices.Add (dev);

View File

@@ -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<SpectrumChannel> m_channel;
Ptr<SpectrumValue> m_txPsd;
};

View File

@@ -18,7 +18,6 @@
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include <ns3/waveform-generator.h>
#include <ns3/object-factory.h>
#include <ns3/log.h>
#include <math.h>
@@ -26,6 +25,8 @@
#include <ns3/trace-source-accessor.h>
#include <ns3/packet-burst.h>
#include <ns3/callback.h>
#include <ns3/antenna-model.h>
#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<AntennaModel>
HalfDuplexIdealPhy::GetRxAntenna ()
{
NS_LOG_FUNCTION (this);
return m_antenna;
}
void
HalfDuplexIdealPhy::SetAntenna (Ptr<AntennaModel> a)
{
NS_LOG_FUNCTION (this << a);
m_antenna = a;
}
void
HalfDuplexIdealPhy::ChangeState (State newState)
{
@@ -270,6 +285,7 @@ HalfDuplexIdealPhy::StartTx (Ptr<Packet> p)
double txTimeSeconds = m_rate.CalculateTxTime (p->GetSize ());
txParams->duration = Seconds (txTimeSeconds);
txParams->txPhy = GetObject<SpectrumPhy> ();
txParams->txAntenna = m_antenna;
txParams->psd = m_txPsd;
txParams->data = m_txPacket;

View File

@@ -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<MobilityModel> GetMobility ();
Ptr<NetDevice> GetDevice ();
Ptr<const SpectrumModel> GetRxSpectrumModel () const;
Ptr<AntennaModel> GetRxAntenna ();
void StartRx (Ptr<SpectrumSignalParameters> params);
@@ -172,7 +176,12 @@ public:
*/
void SetGenericPhyRxEndOkCallback (GenericPhyRxEndOkCallback c);
/**
* set the AntennaModel to be used
*
* \param a the Antenna Model
*/
void SetAntenna (Ptr<AntennaModel> a);
private:
virtual void DoDispose (void);
@@ -185,6 +194,7 @@ private:
EventId m_endRxEventId;
Ptr<MobilityModel> m_mobility;
Ptr<AntennaModel> m_antenna;
Ptr<NetDevice> m_netDevice;
Ptr<SpectrumChannel> m_channel;

View File

@@ -32,6 +32,8 @@
#include <ns3/spectrum-propagation-loss-model.h>
#include <ns3/propagation-loss-model.h>
#include <ns3/propagation-delay-model.h>
#include <ns3/antenna-model.h>
#include <ns3/angles.h>
#include <iostream>
#include <utility>
#include "multi-model-spectrum-channel.h"
@@ -111,15 +113,16 @@ MultiModelSpectrumChannel::GetTypeId (void)
DoubleValue (1.0e9),
MakeDoubleAccessor (&MultiModelSpectrumChannel::m_maxLossDb),
MakeDoubleChecker<double> ())
.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<SpectrumSignalParameters> 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<AntennaModel> 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)
{

View File

@@ -187,7 +187,7 @@ private:
double m_maxLossDb;
TracedCallback<Ptr<SpectrumPhy>, Ptr<SpectrumPhy>, double > m_propagationLossTrace;
TracedCallback<Ptr<SpectrumPhy>, Ptr<SpectrumPhy>, double > m_pathLossTrace;
};

View File

@@ -31,6 +31,8 @@
#include <ns3/spectrum-propagation-loss-model.h>
#include <ns3/propagation-loss-model.h>
#include <ns3/propagation-delay-model.h>
#include <ns3/antenna-model.h>
#include <ns3/angles.h>
#include "single-model-spectrum-channel.h"
@@ -80,15 +82,16 @@ SingleModelSpectrumChannel::GetTypeId (void)
DoubleValue (1.0e9),
MakeDoubleAccessor (&SingleModelSpectrumChannel::m_maxLossDb),
MakeDoubleChecker<double> ())
.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<SpectrumSignalParameters> 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<AntennaModel> 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)
{

View File

@@ -109,7 +109,7 @@ private:
double m_maxLossDb;
TracedCallback<Ptr<SpectrumPhy>, Ptr<SpectrumPhy>, double > m_propagationLossTrace;
TracedCallback<Ptr<SpectrumPhy>, Ptr<SpectrumPhy>, double > m_pathLossTrace;
};

View File

@@ -18,12 +18,15 @@
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include <ns3/spectrum-analyzer.h>
#include <ns3/object-factory.h>
#include <ns3/log.h>
#include <ns3/double.h>
#include <ns3/simulator.h>
#include <ns3/trace-source-accessor.h>
#include <ns3/antenna-model.h>
#include "spectrum-analyzer.h"
NS_LOG_COMPONENT_DEFINE ("SpectrumAnalyzer");
@@ -133,6 +136,19 @@ SpectrumAnalyzer::SetChannel (Ptr<SpectrumChannel> c)
}
Ptr<AntennaModel>
SpectrumAnalyzer::GetRxAntenna ()
{
return m_antenna;
}
void
SpectrumAnalyzer::SetAntenna (Ptr<AntennaModel> a)
{
NS_LOG_FUNCTION (this << a);
m_antenna = a;
}
void

View File

@@ -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<MobilityModel> GetMobility ();
Ptr<NetDevice> GetDevice ();
Ptr<const SpectrumModel> GetRxSpectrumModel () const;
Ptr<AntennaModel> GetRxAntenna ();
void StartRx (Ptr<SpectrumSignalParameters> params);
@@ -68,6 +72,12 @@ public:
*/
void SetRxSpectrumModel (Ptr<SpectrumModel> m);
/**
* set the AntennaModel to be used
*
* \param a the Antenna Model
*/
void SetAntenna (Ptr<AntennaModel> a);
/**
* Start the spectrum analyzer
@@ -87,6 +97,7 @@ protected:
private:
Ptr<MobilityModel> m_mobility;
Ptr<AntennaModel> m_antenna;
Ptr<NetDevice> m_netDevice;
Ptr<SpectrumChannel> m_channel;

View File

@@ -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<MobilityModel> GetMobility () = 0;
/**
* Set the channel attached to this device.
*
@@ -93,6 +93,13 @@ public:
*/
virtual Ptr<const SpectrumModel> 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<AntennaModel> GetRxAntenna () = 0;
/**
* Notify the SpectrumPhy instance of an incoming signal
*

View File

@@ -23,6 +23,7 @@
#include <ns3/spectrum-phy.h>
#include <ns3/spectrum-value.h>
#include <ns3/log.h>
#include <ns3/antenna-model.h>
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<SpectrumSignalParameters>

View File

@@ -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<SpectrumSignalParameters
* The SpectrumPhy instance that is making the transmission
*/
Ptr<SpectrumPhy> txPhy;
/**
* The AntennaModel instance that was used to transmit this signal.
*/
Ptr<AntennaModel> txAntenna;
};

View File

@@ -18,13 +18,15 @@
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include <ns3/waveform-generator.h>
#include <ns3/object-factory.h>
#include <ns3/log.h>
#include <ns3/simulator.h>
#include <ns3/double.h>
#include <ns3/packet-burst.h>
#include <ns3/antenna-model.h>
#include "waveform-generator.h"
NS_LOG_COMPONENT_DEFINE ("WaveformGenerator");
@@ -146,7 +148,18 @@ WaveformGenerator::SetTxPowerSpectralDensity (Ptr<SpectrumValue> txPsd)
m_txPowerSpectralDensity = txPsd;
}
Ptr<AntennaModel>
WaveformGenerator::GetRxAntenna ()
{
return m_antenna;
}
void
WaveformGenerator::SetAntenna (Ptr<AntennaModel> 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<SpectrumPhy> ();
txParams->txAntenna = m_antenna;
NS_LOG_LOGIC ("generating waveform : " << *m_txPowerSpectralDensity);
m_phyTxStartTrace (0);

View File

@@ -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<MobilityModel> GetMobility ();
Ptr<NetDevice> GetDevice ();
Ptr<const SpectrumModel> GetRxSpectrumModel () const;
Ptr<AntennaModel> GetRxAntenna ();
void StartRx (Ptr<SpectrumSignalParameters> params);
@@ -99,8 +104,12 @@ public:
*/
double GetDutyCycle () const;
/**
* set the AntennaModel to be used
*
* \param a the Antenna Model
*/
void SetAntenna (Ptr<AntennaModel> a);
/**
* Start the waveform generator
@@ -119,6 +128,7 @@ private:
virtual void DoDispose (void);
Ptr<MobilityModel> m_mobility;
Ptr<AntennaModel> m_antenna;
Ptr<NetDevice> m_netDevice;
Ptr<SpectrumChannel> m_channel;

View File

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