24 #include <ns3/object.h>
25 #include <ns3/simulator.h>
27 #include <ns3/packet.h>
28 #include <ns3/packet-burst.h>
29 #include <ns3/net-device.h>
31 #include <ns3/double.h>
32 #include <ns3/mobility-model.h>
33 #include <ns3/spectrum-phy.h>
34 #include <ns3/spectrum-converter.h>
35 #include <ns3/spectrum-propagation-loss-model.h>
36 #include <ns3/propagation-loss-model.h>
37 #include <ns3/propagation-delay-model.h>
38 #include <ns3/antenna-model.h>
39 #include <ns3/angles.h>
56 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
60 SpectrumConverterMap_t::iterator jt;
61 for (jt = it->second.m_spectrumConverterMap.begin ();
62 jt != it->second.m_spectrumConverterMap.end ();
65 lhs <<
"(" << it->first <<
"," << jt->first <<
") ";
72 : m_txSpectrumModel (txSpectrumModel)
77 : m_rxSpectrumModel (rxSpectrumModel)
99 static TypeId tid =
TypeId (
"ns3::MultiModelSpectrumChannel")
101 .SetGroupName (
"Spectrum")
115 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)");
127 auto phyIt = std::find (rxInfoIterator->second.m_rxPhys.begin(), rxInfoIterator->second.m_rxPhys.end(),
phy);
128 if (phyIt != rxInfoIterator->second.m_rxPhys.end ())
130 rxInfoIterator->second.m_rxPhys.erase (phyIt);
143 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
147 ret.first->second.m_rxPhys.push_back (
phy);
157 if (rxSpectrumModelUid != txSpectrumModelUid && !txSpectrumModel->
IsOrthogonal (*rxSpectrumModel))
159 NS_LOG_LOGIC (
"Creating converter between SpectrumModelUid " << txSpectrumModel->
GetUid () <<
" and " << rxSpectrumModelUid);
161 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
162 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
170 rxInfoIterator->second.m_rxPhys.push_back (
phy);
174 TxSpectrumModelInfoMap_t::const_iterator
185 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
188 txInfoIterator = ret.first;
198 if (rxSpectrumModelUid != txSpectrumModelUid && !txSpectrumModel->
IsOrthogonal (*rxSpectrumModel))
200 NS_LOG_LOGIC (
"Creating converter between SpectrumModelUid " << txSpectrumModelUid <<
" and " << rxSpectrumModelUid);
203 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
204 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
211 NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
213 return txInfoIterator;
228 NS_LOG_LOGIC (
"txSpectrumModelUid " << txSpectrumModelUid);
234 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
235 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
236 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
242 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
243 NS_LOG_LOGIC (
"rxSpectrumModelUids " << rxSpectrumModelUid);
246 if (txSpectrumModelUid == rxSpectrumModelUid)
249 convertedTxPowerSpectrum = txParams->psd;
253 NS_LOG_LOGIC (
"converting txPowerSpectrum SpectrumModelUids " << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
254 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
255 if (rxConverterIterator == txInfoIteratorerator->second.m_spectrumConverterMap.end ())
260 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
263 for (
auto rxPhyIterator = rxInfoIterator->second.m_rxPhys.begin ();
264 rxPhyIterator != rxInfoIterator->second.m_rxPhys.end ();
267 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
268 "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
270 if ((*rxPhyIterator) != txParams->txPhy)
272 NS_LOG_LOGIC (
"copying signal parameters " << txParams);
274 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
279 if (txMobility && receiverMobility)
281 double txAntennaGain = 0;
282 double rxAntennaGain = 0;
283 double propagationGainDb = 0;
284 double pathLossDb = 0;
285 if (rxParams->txAntenna != 0)
288 txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
289 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
290 pathLossDb -= txAntennaGain;
296 rxAntennaGain = rxAntenna->
GetGainDb (rxAngles);
297 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
298 pathLossDb -= rxAntennaGain;
303 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
304 pathLossDb -= propagationGainDb;
306 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
308 m_gainTrace (txMobility, receiverMobility, txAntennaGain, rxAntennaGain, propagationGainDb, pathLossDb);
316 double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
317 *(rxParams->psd) *= pathGainLinear;
336 rxParams, *rxPhyIterator);
342 rxParams, *rxPhyIterator);
381 for (
const auto &phyIt : rxInfoIterator->second.m_rxPhys)
385 return (*phyIt).GetDevice ();