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;
334 uint32_t dstNode = netDev->GetNode ()->GetId ();
336 rxParams, *rxPhyIterator);
342 rxParams, *rxPhyIterator);
381 for (
const auto &phyIt : rxInfoIterator->second.m_rxPhys)
385 return (*phyIt).GetDevice ();
Simulation virtual time values and global simulation resolution.
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
#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
Uid for SpectrumModels.
The Rx spectrum model information.
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...
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.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
TracedCallback< Ptr< const SpectrumPhy >, Ptr< const SpectrumPhy >, double > m_pathLossTrace
The PathLoss trace source.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
double m_maxLossDb
Maximum loss [dB].
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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...
This SpectrumChannel implementation can handle the presence of SpectrumPhy instances which can use di...
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
SpectrumModelUid_t GetUid() const
std::size_t m_numDevices
Number of devices connected to the 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.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
Frequency-dependent propagation loss model to be used with this channel.
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...
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.
virtual std::size_t GetNDevices(void) const
RxSpectrumModelInfo(Ptr< const SpectrumModel > rxSpectrumModel)
Constructor.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void DoDispose()
Destructor implementation.
Vector GetPosition(void) const
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.
Ptr< PropagationLossModel > m_propagationLoss
Single-frequency propagation loss model to be used with this channel.
TracedCallback< Ptr< SpectrumSignalParameters > > m_txSigParamsTrace
Traced callback for SpectrumSignalParameters in StartTx requests.
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.
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
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)
Constructor.
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.
TracedCallback< Ptr< const MobilityModel >, Ptr< const MobilityModel >, double, double, double, double > m_gainTrace
The Gain trace source.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void DoDispose(void)
Destructor implementation.
std::map< SpectrumModelUid_t, TxSpectrumModelInfo > TxSpectrumModelInfoMap_t
Container: SpectrumModelUid_t, TxSpectrumModelInfo.
The Tx spectrum model information.