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>
53 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
57 SpectrumConverterMap_t::iterator jt;
58 for (jt = it->second.m_spectrumConverterMap.begin ();
59 jt != it->second.m_spectrumConverterMap.end ();
62 lhs <<
"(" << it->first <<
"," << jt->first <<
") ";
69 : m_txSpectrumModel (txSpectrumModel)
75 : 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;
157 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
161 ret.first->second.m_rxPhyList.push_back (phy);
169 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModel->
GetUid () <<
" and " << rxSpectrumModelUid );
171 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
172 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
179 rxInfoIterator->second.m_rxPhyList.push_back (phy);
185 TxSpectrumModelInfoMap_t::const_iterator
196 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
199 txInfoIterator = ret.first;
209 if (rxSpectrumModelUid != txSpectrumModelUid)
211 NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModelUid <<
" and " << rxSpectrumModelUid );
214 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
215 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
222 NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
224 return txInfoIterator;
239 NS_LOG_LOGIC (
" txSpectrumModelUid " << txSpectrumModelUid);
245 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
246 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
247 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
253 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
254 NS_LOG_LOGIC (
" rxSpectrumModelUids " << rxSpectrumModelUid);
257 if (txSpectrumModelUid == rxSpectrumModelUid)
260 convertedTxPowerSpectrum = txParams->psd;
264 NS_LOG_LOGIC (
" converting txPowerSpectrum SpectrumModelUids" << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
265 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
266 NS_ASSERT (rxConverterIterator != txInfoIteratorerator->second.m_spectrumConverterMap.end ());
267 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
272 rxPhyIterator != rxInfoIterator->second.m_rxPhyList.end ();
275 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
276 "MultiModelSpectrumChannel only supports devices that use a single RxSpectrumModel that does not change for the whole simulation");
280 if ((*rxPhyIterator) != txParams->txPhy)
282 NS_LOG_LOGIC (
" copying signal parameters " << txParams);
284 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
289 if (txMobility && receiverMobility)
291 double pathLossDb = 0;
292 if (rxParams->txAntenna != 0)
295 double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
296 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
297 pathLossDb -= txAntennaGain;
303 double rxAntennaGain = rxAntenna->
GetGainDb (rxAngles);
304 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
305 pathLossDb -= rxAntennaGain;
310 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
311 pathLossDb -= propagationGainDb;
313 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
320 double pathGainLinear = pow (10.0, (-pathLossDb) / 10.0);
321 *(rxParams->psd) *= pathGainLinear;
340 rxParams, *rxPhyIterator);
346 rxParams, *rxPhyIterator);