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")
121 auto phyIt = std::find (rxInfoIterator->second.m_rxPhys.begin(), rxInfoIterator->second.m_rxPhys.end(),
phy);
122 if (phyIt != rxInfoIterator->second.m_rxPhys.end ())
124 rxInfoIterator->second.m_rxPhys.erase (phyIt);
138 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)");
151 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
155 ret.first->second.m_rxPhys.push_back (
phy);
165 if (rxSpectrumModelUid != txSpectrumModelUid && !txSpectrumModel->
IsOrthogonal (*rxSpectrumModel))
167 NS_LOG_LOGIC (
"Creating converter between SpectrumModelUid " << txSpectrumModel->
GetUid () <<
" and " << rxSpectrumModelUid);
169 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
170 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
178 rxInfoIterator->second.m_rxPhys.push_back (
phy);
182 TxSpectrumModelInfoMap_t::const_iterator
193 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
196 txInfoIterator = ret.first;
206 if (rxSpectrumModelUid != txSpectrumModelUid && !txSpectrumModel->
IsOrthogonal (*rxSpectrumModel))
208 NS_LOG_LOGIC (
"Creating converter between SpectrumModelUid " << txSpectrumModelUid <<
" and " << rxSpectrumModelUid);
211 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
212 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
219 NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid <<
" already present");
221 return txInfoIterator;
236 NS_LOG_LOGIC (
"txSpectrumModelUid " << txSpectrumModelUid);
242 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
243 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
244 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
250 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
251 NS_LOG_LOGIC (
"rxSpectrumModelUids " << rxSpectrumModelUid);
254 if (txSpectrumModelUid == rxSpectrumModelUid)
257 convertedTxPowerSpectrum = txParams->psd;
261 NS_LOG_LOGIC (
"converting txPowerSpectrum SpectrumModelUids " << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
262 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
263 if (rxConverterIterator == txInfoIteratorerator->second.m_spectrumConverterMap.end ())
268 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
271 for (
auto rxPhyIterator = rxInfoIterator->second.m_rxPhys.begin ();
272 rxPhyIterator != rxInfoIterator->second.m_rxPhys.end ();
275 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
276 "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
278 if ((*rxPhyIterator) != txParams->txPhy)
283 if (rxNetDevice && txNetDevice)
288 NS_LOG_DEBUG (
"Skipping the pathloss calculation among different antennas of the same node, not supported yet by any pathloss model in ns-3.");
293 NS_LOG_LOGIC (
"copying signal parameters " << txParams);
295 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
300 if (txMobility && receiverMobility)
302 double txAntennaGain = 0;
303 double rxAntennaGain = 0;
304 double propagationGainDb = 0;
305 double pathLossDb = 0;
306 if (rxParams->txAntenna != 0)
309 txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
310 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
311 pathLossDb -= txAntennaGain;
313 Ptr<AntennaModel> rxAntenna = DynamicCast<AntennaModel>((*rxPhyIterator)->GetAntenna ());
317 rxAntennaGain = rxAntenna->
GetGainDb (rxAngles);
318 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
319 pathLossDb -= rxAntennaGain;
324 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
325 pathLossDb -= propagationGainDb;
327 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
329 m_gainTrace (txMobility, receiverMobility, txAntennaGain, rxAntennaGain, propagationGainDb, pathLossDb);
337 double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
338 *(rxParams->psd) *= pathGainLinear;
349 NS_ASSERT_MSG (txPhasedArrayModel && rxPhasedArrayModel,
"PhasedArrayModel instances should be installed at both TX and RX SpectrumPhy in order to use PhasedArraySpectrumPropagationLoss.");
365 rxParams, *rxPhyIterator);
371 rxParams, *rxPhyIterator);
410 for (
const auto &phyIt : rxInfoIterator->second.m_rxPhys)
414 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(void) const
This SpectrumChannel implementation can handle the presence of SpectrumPhy instances which can use di...
virtual std::size_t GetNDevices(void) const
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.
static TypeId GetTypeId(void)
Get the type ID.
TxSpectrumModelInfoMap_t::const_iterator FindAndEventuallyAddTxSpectrumModel(Ptr< const SpectrumModel > txSpectrumModel)
This method checks if m_rxSpectrumModelInfoMap contains an entry for the given TX SpectrumModel.
virtual void RemoveRx(Ptr< SpectrumPhy > phy)
Remove a SpectrumPhy from a channel.
void DoDispose()
Destructor implementation.
virtual void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
Used internally to reschedule transmission after the propagation delay.
virtual void StartTx(Ptr< SpectrumSignalParameters > params)
Used by attached PHY instances to transmit signals on the channel.
MultiModelSpectrumChannel()
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
virtual void AddRx(Ptr< SpectrumPhy > phy)
Add a SpectrumPhy to a channel, so it can receive packets.
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
Data structure holding, for each RX spectrum model, all the corresponding SpectrumPhy instances.
virtual Ptr< Node > GetNode(void) const =0
uint32_t GetId(void) const
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(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Defines the interface for spectrum-aware channel implementations.
TracedCallback< Ptr< const SpectrumPhy >, Ptr< const SpectrumPhy >, double > m_pathLossTrace
The PathLoss trace source.
TracedCallback< Ptr< SpectrumSignalParameters > > m_txSigParamsTrace
Traced callback for SpectrumSignalParameters in StartTx requests.
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
virtual void DoDispose(void)
Destructor implementation.
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 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.
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)