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> 57 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
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)
79 : m_rxSpectrumModel (rxSpectrumModel)
101 static TypeId tid =
TypeId (
"ns3::MultiModelSpectrumChannel")
103 .SetGroupName (
"Spectrum")
119 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)");
131 std::set<Ptr<SpectrumPhy> >::iterator phyIt = rxInfoIterator->second.m_rxPhySet.find (
phy);
132 if (phyIt != rxInfoIterator->second.m_rxPhySet.end ())
134 rxInfoIterator->second.m_rxPhySet.erase (phyIt);
147 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
151 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = ret.first->second.m_rxPhySet.insert (
phy);
162 if (rxSpectrumModelUid != txSpectrumModelUid && !txSpectrumModel->
IsOrthogonal (*rxSpectrumModel))
164 NS_LOG_LOGIC (
"Creating converter between SpectrumModelUid " << txSpectrumModel->
GetUid () <<
" and " << rxSpectrumModelUid);
166 std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
167 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
175 std::pair<std::set<Ptr<SpectrumPhy> >::iterator,
bool> ret2 = rxInfoIterator->second.m_rxPhySet.insert (
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;
238 NS_LOG_LOGIC (
" txSpectrumModelUid " << txSpectrumModelUid);
244 NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
245 NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
246 NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
252 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
253 NS_LOG_LOGIC (
" rxSpectrumModelUids " << rxSpectrumModelUid);
256 if (txSpectrumModelUid == rxSpectrumModelUid)
259 convertedTxPowerSpectrum = txParams->psd;
263 NS_LOG_LOGIC (
" converting txPowerSpectrum SpectrumModelUids" << txSpectrumModelUid <<
" --> " << rxSpectrumModelUid);
264 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
265 if (rxConverterIterator == txInfoIteratorerator->second.m_spectrumConverterMap.end ())
270 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
274 for (std::set<
Ptr<SpectrumPhy> >::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhySet.begin ();
275 rxPhyIterator != rxInfoIterator->second.m_rxPhySet.end ();
278 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
279 "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
281 if ((*rxPhyIterator) != txParams->txPhy)
283 NS_LOG_LOGIC (
" copying signal parameters " << txParams);
285 rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
290 if (txMobility && receiverMobility)
292 double pathLossDb = 0;
293 if (rxParams->txAntenna != 0)
296 double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
297 NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain <<
" dB");
298 pathLossDb -= txAntennaGain;
304 double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
305 NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain <<
" dB");
306 pathLossDb -= rxAntennaGain;
311 NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb <<
" dB");
312 pathLossDb -= propagationGainDb;
314 NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb <<
" dB");
321 double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
322 *(rxParams->psd) *= pathGainLinear;
339 uint32_t dstNode = netDev->GetNode ()->GetId ();
341 rxParams, *rxPhyIterator);
347 rxParams, *rxPhyIterator);
386 for (std::set<
Ptr<SpectrumPhy> >::const_iterator phyIt = rxInfoIterator->second.m_rxPhySet.begin ();
387 phyIt != rxInfoIterator->second.m_rxPhySet.end ();
392 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.
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.