21 #include <ns3/object.h>
22 #include <ns3/simulator.h>
24 #include <ns3/packet.h>
25 #include <ns3/packet-burst.h>
26 #include <ns3/net-device.h>
28 #include <ns3/double.h>
29 #include <ns3/mobility-model.h>
30 #include <ns3/spectrum-phy.h>
31 #include <ns3/spectrum-converter.h>
32 #include <ns3/spectrum-propagation-loss-model.h>
33 #include <ns3/propagation-loss-model.h>
34 #include <ns3/propagation-delay-model.h>
35 #include <ns3/antenna-model.h>
36 #include <ns3/angles.h>
54 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
58 SpectrumConverterMap_t::iterator jt;
59 for (jt = it->second.m_spectrumConverterMap.begin ();
60 jt != it->second.m_spectrumConverterMap.end ();
63 lhs <<
"(" << it->first <<
"," << jt->first <<
") ";
70 : m_txSpectrumModel (txSpectrumModel)
76 : m_rxSpectrumModel (rxSpectrumModel)
101 static TypeId tid =
TypeId (
"ns3::MultiModelSpectrumChannel")
103 .AddConstructor<MultiModelSpectrumChannel> ()
104 .AddAttribute (
"MaxLossDb",
105 "If a single-frequency PropagationLossModel is used, this value "
106 "represents the maximum loss in dB for which transmissions will be "
107 "passed to the receiving PHY. Signals for which the PropagationLossModel "
108 "returns a loss bigger than this value will not be propagated to the receiver. "
109 "This parameter is to be used to reduce "
110 "the computational load by not propagating signals that are far beyond "
111 "the interference range. Note that the default value corresponds to "
112 "considering all signals for reception. Tune this value with care. ",
115 MakeDoubleChecker<double> ())
116 .AddTraceSource (
"PathLoss",
117 "This trace is fired "
118 "whenever a new path loss value is calculated. The first and second parameters "
119 "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, "
120 "whereas the third parameters is the loss value in dB. Note that the loss value "
121 "reported by this trace is the single-frequency loss value obtained by evaluating "
122 "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that "
123 "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value "
124 "reported in this trace. ",
139 NS_ASSERT_MSG ((0 != rxSpectrumModel),
"phy->GetRxSpectrumModel () returned 0. Please check that the RxSpectrumModel is already set for the phy before calling MultiModelSpectrumChannel::AddRx (phy)");
143 std::vector<Ptr<SpectrumPhy> >::const_iterator it;
153 std::set<Ptr<SpectrumPhy> >::iterator phyIt = rxInfoIterator->second.m_rxPhySet.find (phy);
154 if (phyIt != rxInfoIterator->second.m_rxPhySet.end ())
156 rxInfoIterator->second.m_rxPhySet.erase (phyIt);
169 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
173 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = ret.first->second.m_rxPhySet.insert (phy);
182 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModel->GetUid () <<
" and " << rxSpectrumModelUid );
184 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
185 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
192 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = rxInfoIterator->second.m_rxPhySet.insert (phy);
199 TxSpectrumModelInfoMap_t::const_iterator
210 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
213 txInfoIterator = ret.first;
223 if (rxSpectrumModelUid != txSpectrumModelUid)
225 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModelUid <<
" and " << rxSpectrumModelUid );
228 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
229 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
236 NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
238 return txInfoIterator;
254 NS_LOG_LOGIC (
" txSpectrumModelUid " << txSpectrumModelUid);
260 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
261 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
262 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
268 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
269 NS_LOG_LOGIC (
" rxSpectrumModelUids " << rxSpectrumModelUid);
272 if (txSpectrumModelUid == rxSpectrumModelUid)
275 convertedTxPowerSpectrum = txParams->psd;
279 NS_LOG_LOGIC (
" converting txPowerSpectrum SpectrumModelUids" << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
280 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
281 NS_ASSERT (rxConverterIterator != txInfoIteratorerator->second.m_spectrumConverterMap.end ());
282 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
286 for (std::set<
Ptr<SpectrumPhy> >::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhySet.begin ();
287 rxPhyIterator != rxInfoIterator->second.m_rxPhySet.end ();
290 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
291 "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
293 if ((*rxPhyIterator) != txParams->txPhy)
295 NS_LOG_LOGIC (
" copying signal parameters " << txParams);
297 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
298 Time delay = MicroSeconds (0);
302 if (txMobility && receiverMobility)
304 double pathLossDb = 0;
305 if (rxParams->txAntenna != 0)
308 double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
309 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
310 pathLossDb -= txAntennaGain;
316 double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
317 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
318 pathLossDb -= rxAntennaGain;
323 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
324 pathLossDb -= propagationGainDb;
326 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
333 double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
334 *(rxParams->psd) *= pathGainLinear;
351 uint32_t dstNode = netDev->GetNode ()->GetId ();
353 rxParams, *rxPhyIterator);
359 rxParams, *rxPhyIterator);
402 for (std::set<
Ptr<SpectrumPhy> >::const_iterator phyIt = rxInfoIterator->second.m_rxPhySet.begin ();
403 phyIt != rxInfoIterator->second.m_rxPhySet.end ();
408 return (*phyIt)->GetDevice ();
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
frequency-dependent propagation loss model to be used with this channel
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
uint32_t SpectrumModelUid_t
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
#define NS_ASSERT(condition)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
set the single-frequency propagation loss model to be used
Vector GetPosition(void) const
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
data structure holding, for each RX spectrum model, all the corresponding SpectrumPhy instances...
virtual Ptr< const SpectrumModel > GetRxSpectrumModel() const =0
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual Ptr< SpectrumPropagationLossModel > GetSpectrumPropagationLossModel(void)
Ptr< PropagationDelayModel > m_propagationDelay
propagation delay model to be used with this channel
Ptr< PropagationLossModel > m_propagationLoss
single-frequency propagation loss model to be used with this channel
Class which implements a converter between SpectrumValue which are defined over different SpectrumMod...
virtual uint32_t GetNDevices(void) const
static TypeId GetTypeId(void)
virtual void AddRx(Ptr< SpectrumPhy > phy)
add a SpectrumPhy to a channel, so it can receive packets
TxSpectrumModelInfoMap_t::const_iterator FindAndEventuallyAddTxSpectrumModel(Ptr< const SpectrumModel > txSpectrumModel)
this method checks if m_rxSpectrumModelInfoMap contains an entry for the given TX SpectrumModel...
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
#define NS_LOG_LOGIC(msg)
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
RxSpectrumModelInfo(Ptr< const SpectrumModel > rxSpectrumModel)
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
virtual void AddSpectrumPropagationLossModel(Ptr< SpectrumPropagationLossModel > loss)
set the frequency-dependent propagation loss model to be used
#define NS_ASSERT_MSG(condition, message)
TracedCallback< Ptr< SpectrumPhy >, Ptr< SpectrumPhy >, double > m_pathLossTrace
virtual void StartTx(Ptr< SpectrumSignalParameters > params)
Used by attached PHY instances to transmit signals on the channel.
std::map< SpectrumModelUid_t, TxSpectrumModelInfo > TxSpectrumModelInfoMap_t
virtual Ptr< NetDevice > GetDevice(uint32_t i) const
virtual void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
set the propagation delay model to be used
TxSpectrumModelInfoMap_t m_txSpectrumModelInfoMap
data structure holding, for each TX SpectrumModel, all the converters to any RX SpectrumModel, and all the corresponding SpectrumPhy instances.
Defines the interface for spectrum-aware channel implementations.
struct holding the azimuth and inclination angles of spherical coordinates.
TxSpectrumModelInfo(Ptr< const SpectrumModel > txSpectrumModel)
NS_LOG_COMPONENT_DEFINE("MultiModelSpectrumChannel")
Hold a floating point type.
MultiModelSpectrumChannel()
a unique identifier for an interface.
virtual void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
used internally to reschedule transmission after the propagation delay
TypeId SetParent(TypeId tid)