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>
51 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
55 SpectrumConverterMap_t::iterator jt;
56 for (jt = it->second.m_spectrumConverterMap.begin ();
57 jt != it->second.m_spectrumConverterMap.end ();
60 lhs <<
"(" << it->first <<
"," << jt->first <<
") ";
67 : m_txSpectrumModel (txSpectrumModel)
73 : m_rxSpectrumModel (rxSpectrumModel)
98 static TypeId tid =
TypeId (
"ns3::MultiModelSpectrumChannel")
100 .SetGroupName (
"Spectrum")
102 .AddAttribute (
"MaxLossDb",
103 "If a single-frequency PropagationLossModel is used, "
104 "this value represents the maximum loss in dB for which "
105 "transmissions will be passed to the receiving PHY. "
106 "Signals for which the PropagationLossModel returns "
107 "a loss bigger than this value will not be propagated "
108 "to the receiver. This parameter is to be used to reduce "
109 "the computational load by not propagating signals that "
110 "are far beyond the interference range. Note that the "
111 "default value corresponds to considering all signals "
112 "for reception. Tune this value with care. ",
115 MakeDoubleChecker<double> ())
116 .AddTraceSource (
"PathLoss",
117 "This trace is fired whenever a new path loss value "
118 "is calculated. The first and second parameters "
119 "to the trace are pointers respectively to the "
120 "TX and RX SpectrumPhy instances, whereas the "
121 "third parameters is the loss value in dB. "
122 "Note that the loss value reported by this trace is "
123 "the single-frequency loss value obtained by evaluating "
124 "only the TX and RX AntennaModels and the "
125 "PropagationLossModel. In particular, note that "
126 "SpectrumPropagationLossModel (even if present) "
127 "is never used to evaluate the loss value "
128 "reported in this trace. ",
130 "ns3::SpectrumChannel::LossTracedCallback")
144 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)");
148 std::vector<Ptr<SpectrumPhy> >::const_iterator it;
158 std::set<Ptr<SpectrumPhy> >::iterator phyIt = rxInfoIterator->second.m_rxPhySet.find (phy);
159 if (phyIt != rxInfoIterator->second.m_rxPhySet.end ())
161 rxInfoIterator->second.m_rxPhySet.erase (phyIt);
174 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
178 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = ret.first->second.m_rxPhySet.insert (phy);
187 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModel->
GetUid () <<
" and " << rxSpectrumModelUid );
189 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
190 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
197 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = rxInfoIterator->second.m_rxPhySet.insert (phy);
204 TxSpectrumModelInfoMap_t::const_iterator
215 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
218 txInfoIterator = ret.first;
228 if (rxSpectrumModelUid != txSpectrumModelUid)
230 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModelUid <<
" and " << rxSpectrumModelUid );
233 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
234 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
241 NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
243 return txInfoIterator;
259 NS_LOG_LOGIC (
" txSpectrumModelUid " << txSpectrumModelUid);
265 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
266 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
267 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
273 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
274 NS_LOG_LOGIC (
" rxSpectrumModelUids " << rxSpectrumModelUid);
277 if (txSpectrumModelUid == rxSpectrumModelUid)
280 convertedTxPowerSpectrum = txParams->psd;
284 NS_LOG_LOGIC (
" converting txPowerSpectrum SpectrumModelUids" << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
285 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
286 NS_ASSERT (rxConverterIterator != txInfoIteratorerator->second.m_spectrumConverterMap.end ());
287 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
291 for (std::set<
Ptr<SpectrumPhy> >::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhySet.begin ();
292 rxPhyIterator != rxInfoIterator->second.m_rxPhySet.end ();
295 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
296 "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
298 if ((*rxPhyIterator) != txParams->txPhy)
300 NS_LOG_LOGIC (
" copying signal parameters " << txParams);
302 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
307 if (txMobility && receiverMobility)
309 double pathLossDb = 0;
310 if (rxParams->txAntenna != 0)
313 double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
314 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
315 pathLossDb -= txAntennaGain;
321 double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
322 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
323 pathLossDb -= rxAntennaGain;
328 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
329 pathLossDb -= propagationGainDb;
331 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
338 double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
339 *(rxParams->psd) *= pathGainLinear;
356 uint32_t dstNode = netDev->GetNode ()->GetId ();
358 rxParams, *rxPhyIterator);
364 rxParams, *rxPhyIterator);
407 for (std::set<
Ptr<SpectrumPhy> >::const_iterator phyIt = rxInfoIterator->second.m_rxPhySet.begin ();
408 phyIt != rxInfoIterator->second.m_rxPhySet.end ();
413 return (*phyIt)->GetDevice ();
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
frequency-dependent propagation loss model to be used with this channel
Simulation virtual time values and global simulation resolution.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t SpectrumModelUid_t
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
set the single-frequency propagation loss model to be used
Vector GetPosition(void) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
data structure holding, for each RX spectrum model, all the corresponding SpectrumPhy instances...
virtual void DoDispose(void)
Destructor implementation.
virtual Ptr< const SpectrumModel > GetRxSpectrumModel() const =0
This SpectrumChannel implementation can handle the presence of SpectrumPhy instances which can use di...
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
virtual uint32_t GetNDevices(void) const
SpectrumModelUid_t GetUid() 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
Returns the Rx Power taking into account all the PropagatinLossModel(s) chained to the current one...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Every class exported by the ns3 library is enclosed in the ns3 namespace.
RxSpectrumModelInfo(Ptr< const SpectrumModel > rxSpectrumModel)
void DoDispose()
Destructor implementation.
virtual void AddSpectrumPropagationLossModel(Ptr< SpectrumPropagationLossModel > loss)
set the frequency-dependent propagation loss model to be used
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
TracedCallback< Ptr< SpectrumPhy >, Ptr< SpectrumPhy >, double > m_pathLossTrace
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
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.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
struct holding the azimuth and inclination angles of spherical coordinates.
TxSpectrumModelInfo(Ptr< const SpectrumModel > txSpectrumModel)
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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)
Set the parent TypeId.