22 #include <ns3/angles.h>
23 #include <ns3/antenna-model.h>
24 #include <ns3/double.h>
26 #include <ns3/mobility-model.h>
27 #include <ns3/net-device.h>
29 #include <ns3/object.h>
30 #include <ns3/packet-burst.h>
31 #include <ns3/packet.h>
32 #include <ns3/propagation-delay-model.h>
33 #include <ns3/propagation-loss-model.h>
34 #include <ns3/simulator.h>
35 #include <ns3/spectrum-converter.h>
36 #include <ns3/spectrum-phy.h>
37 #include <ns3/spectrum-propagation-loss-model.h>
59 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin(); it != rhs.end(); ++it)
61 SpectrumConverterMap_t::iterator jt;
62 for (jt = it->second.m_spectrumConverterMap.begin();
63 jt != it->second.m_spectrumConverterMap.end();
66 lhs <<
"(" << it->first <<
"," << jt->first <<
") ";
73 : m_txSpectrumModel(txSpectrumModel)
78 : m_rxSpectrumModel(rxSpectrumModel)
100 static TypeId tid =
TypeId(
"ns3::MultiModelSpectrumChannel")
102 .SetGroupName(
"Spectrum")
122 auto phyIt = std::find(rxInfoIterator->second.m_rxPhys.begin(),
123 rxInfoIterator->second.m_rxPhys.end(),
125 if (phyIt != rxInfoIterator->second.m_rxPhys.end())
127 rxInfoIterator->second.m_rxPhys.erase(phyIt);
142 "phy->GetRxSpectrumModel () returned 0. Please check that the RxSpectrumModel is "
143 "already set for the phy before calling MultiModelSpectrumChannel::AddRx (phy)");
151 auto [rxInfoIterator, inserted] =
156 rxInfoIterator->second.m_rxPhys.push_back(
phy);
168 if (rxSpectrumModelUid != txSpectrumModelUid &&
171 NS_LOG_LOGIC(
"Creating converter between SpectrumModelUid "
172 << txSpectrumModel->
GetUid() <<
" and " << rxSpectrumModelUid);
174 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
175 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert(
176 std::make_pair(rxSpectrumModelUid, converter));
183 TxSpectrumModelInfoMap_t::const_iterator
189 TxSpectrumModelInfoMap_t::iterator txInfoIterator =
196 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
200 txInfoIterator = ret.first;
203 for (RxSpectrumModelInfoMap_t::const_iterator rxInfoIterator =
211 if (rxSpectrumModelUid != txSpectrumModelUid &&
214 NS_LOG_LOGIC(
"Creating converter between SpectrumModelUid "
215 << txSpectrumModelUid <<
" and " << rxSpectrumModelUid);
218 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
219 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert(
220 std::make_pair(rxSpectrumModelUid, converter));
227 NS_LOG_LOGIC(
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
229 return txInfoIterator;
246 NS_LOG_LOGIC(
"txSpectrumModelUid " << txSpectrumModelUid);
249 TxSpectrumModelInfoMap_t::const_iterator txInfoIteratorerator =
253 NS_LOG_LOGIC(
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
255 "converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size());
257 << txInfoIteratorerator->second.m_spectrumConverterMap.begin()->first);
263 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid();
264 NS_LOG_LOGIC(
"rxSpectrumModelUids " << rxSpectrumModelUid);
267 if (txSpectrumModelUid == rxSpectrumModelUid)
270 convertedTxPowerSpectrum = txParams->
psd;
274 NS_LOG_LOGIC(
"converting txPowerSpectrum SpectrumModelUids "
275 << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
276 SpectrumConverterMap_t::const_iterator rxConverterIterator =
277 txInfoIteratorerator->second.m_spectrumConverterMap.find(rxSpectrumModelUid);
278 if (rxConverterIterator == txInfoIteratorerator->second.m_spectrumConverterMap.end())
283 convertedTxPowerSpectrum = rxConverterIterator->second.Convert(txParams->
psd);
286 for (
auto rxPhyIterator = rxInfoIterator->second.m_rxPhys.begin();
287 rxPhyIterator != rxInfoIterator->second.m_rxPhys.end();
290 NS_ASSERT_MSG((*rxPhyIterator)->GetRxSpectrumModel()->GetUid() == rxSpectrumModelUid,
291 "SpectrumModel change was not notified to MultiModelSpectrumChannel "
292 "(i.e., AddRx should be called again after model is changed)");
294 if ((*rxPhyIterator) != txParams->
txPhy)
299 if (rxNetDevice && txNetDevice)
302 if (rxNetDevice->GetNode()->GetId() == txNetDevice->GetNode()->GetId())
305 "Skipping the pathloss calculation among different antennas of the "
306 "same node, not supported yet by any pathloss model in ns-3.");
313 rxParams->
psd = Copy<SpectrumValue>(convertedTxPowerSpectrum);
318 if (txMobility && receiverMobility)
320 double txAntennaGain = 0;
321 double rxAntennaGain = 0;
322 double propagationGainDb = 0;
323 double pathLossDb = 0;
328 NS_LOG_LOGIC(
"txAntennaGain = " << txAntennaGain <<
" dB");
329 pathLossDb -= txAntennaGain;
332 DynamicCast<AntennaModel>((*rxPhyIterator)->GetAntenna());
336 rxAntennaGain = rxAntenna->
GetGainDb(rxAngles);
337 NS_LOG_LOGIC(
"rxAntennaGain = " << rxAntennaGain <<
" dB");
338 pathLossDb -= rxAntennaGain;
344 NS_LOG_LOGIC(
"propagationGainDb = " << propagationGainDb <<
" dB");
345 pathLossDb -= propagationGainDb;
347 NS_LOG_LOGIC(
"total pathLoss = " << pathLossDb <<
" dB");
362 double pathGainLinear = std::pow(10.0, (-pathLossDb) / 10.0);
363 *(rxParams->
psd) *= pathGainLinear;
374 uint32_t dstNode = rxNetDevice->GetNode()->GetId();
405 params->txPhy->GetMobility(),
411 DynamicCast<PhasedArrayModel>(
params->txPhy->GetAntenna());
413 DynamicCast<PhasedArrayModel>(receiver->
GetAntenna());
416 "PhasedArrayModel instances should be installed at both TX and RX "
417 "SpectrumPhy in order to use PhasedArraySpectrumPropagationLoss.");
421 params->txPhy->GetMobility(),
452 for (
const auto& phyIt : rxInfoIterator->second.m_rxPhys)
456 return (*phyIt).GetDevice();
Class holding the azimuth and inclination angles of spherical coordinates.
virtual double GetGainDb(Angles a)=0
this method is expected to be re-implemented by each antenna model
Vector GetPosition() const
This SpectrumChannel implementation can handle the presence of SpectrumPhy instances which can use di...
void RemoveRx(Ptr< SpectrumPhy > phy) override
Remove a SpectrumPhy from a channel.
Ptr< NetDevice > GetDevice(std::size_t i) const override
std::size_t GetNDevices() const override
void AddRx(Ptr< SpectrumPhy > phy) override
Add a SpectrumPhy to a channel, so it can receive packets.
TxSpectrumModelInfoMap_t m_txSpectrumModelInfoMap
Data structure holding, for each TX SpectrumModel, all the converters to any RX SpectrumModel,...
std::size_t m_numDevices
Number of devices connected to the channel.
void DoDispose() override
Destructor implementation.
void StartTx(Ptr< SpectrumSignalParameters > params) override
Used by attached PHY instances to transmit signals on the channel.
TxSpectrumModelInfoMap_t::const_iterator FindAndEventuallyAddTxSpectrumModel(Ptr< const SpectrumModel > txSpectrumModel)
This method checks if m_rxSpectrumModelInfoMap contains an entry for the given TX SpectrumModel.
static TypeId GetTypeId()
Get the type ID.
virtual void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
Used internally to reschedule transmission after the propagation delay.
MultiModelSpectrumChannel()
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
Data structure holding, for each RX spectrum model, all the corresponding SpectrumPhy instances.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
The Rx spectrum model information.
RxSpectrumModelInfo(Ptr< const SpectrumModel > rxSpectrumModel)
Constructor.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Defines the interface for spectrum-aware channel implementations.
TracedCallback< Ptr< SpectrumSignalParameters > > m_txSigParamsTrace
Traced callback for SpectrumSignalParameters in StartTx requests.
void DoDispose() override
Destructor implementation.
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
Ptr< PhasedArraySpectrumPropagationLossModel > m_phasedArraySpectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
TracedCallback< Ptr< const SpectrumPhy >, Ptr< const SpectrumPhy >, double > m_pathLossTrace
The PathLoss trace source.
TracedCallback< Ptr< const MobilityModel >, Ptr< const MobilityModel >, double, double, double, double > m_gainTrace
The Gain trace source.
Ptr< PropagationLossModel > m_propagationLoss
Single-frequency propagation loss model to be used with this channel.
double m_maxLossDb
Maximum loss [dB].
Class which implements a converter between SpectrumValue which are defined over different SpectrumMod...
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
SpectrumModelUid_t GetUid() const
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
Notify the SpectrumPhy instance of an incoming signal.
virtual Ptr< Object > GetAntenna() const =0
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
virtual Ptr< MobilityModel > GetMobility() const =0
Get the associated MobilityModel instance.
virtual Ptr< NetDevice > GetDevice() const =0
Get the associated NetDevice instance.
Ptr< const SpectrumModel > GetSpectrumModel() const
SpectrumModelUid_t GetSpectrumModelUid() const
Simulation virtual time values and global simulation resolution.
The Tx spectrum model information.
TxSpectrumModelInfo(Ptr< const SpectrumModel > txSpectrumModel)
Constructor.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
std::map< SpectrumModelUid_t, TxSpectrumModelInfo > TxSpectrumModelInfoMap_t
Container: SpectrumModelUid_t, TxSpectrumModelInfo.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
std::ostream & operator<<(std::ostream &os, const Angles &a)
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
Ptr< AntennaModel > txAntenna
The AntennaModel instance that was used to transmit this signal.
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
virtual Ptr< SpectrumSignalParameters > Copy() const
make a "virtual" copy of this class, where "virtual" refers to the fact that if the actual object is ...
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.