16#include "ns3/angles.h" 
   17#include "ns3/antenna-model.h" 
   18#include "ns3/double.h" 
   20#include "ns3/mobility-model.h" 
   21#include "ns3/net-device.h" 
   23#include "ns3/object.h" 
   24#include "ns3/packet-burst.h" 
   25#include "ns3/packet.h" 
   26#include "ns3/propagation-delay-model.h" 
   27#include "ns3/propagation-loss-model.h" 
   28#include "ns3/simulator.h" 
   50    for (
auto it = rhs.begin(); it != rhs.end(); ++it)
 
   52        for (
auto jt = it->second.m_spectrumConverterMap.begin();
 
   53             jt != it->second.m_spectrumConverterMap.end();
 
   56            lhs << 
"(" << it->first << 
"," << jt->first << 
") ";
 
 
   63    : m_txSpectrumModel(txSpectrumModel)
 
 
   68    : m_rxSpectrumModel(rxSpectrumModel)
 
 
   90    static TypeId tid = 
TypeId(
"ns3::MultiModelSpectrumChannel")
 
   92                            .SetGroupName(
"Spectrum")
 
 
  112        auto phyIt = std::find(rxInfoIterator->second.m_rxPhys.begin(),
 
  113                               rxInfoIterator->second.m_rxPhys.end(),
 
  115        if (phyIt != rxInfoIterator->second.m_rxPhys.end())
 
  117            rxInfoIterator->second.m_rxPhys.erase(phyIt);
 
 
  132                  "phy->GetRxSpectrumModel () returned 0. Please check that the RxSpectrumModel is " 
  133                  "already set for the phy before calling MultiModelSpectrumChannel::AddRx (phy)");
 
  135    const auto rxSpectrumModelUid = rxSpectrumModel->GetUid();
 
  141    auto [rxInfoIterator, inserted] =
 
  146    rxInfoIterator->second.m_rxPhys.push_back(phy);
 
  155            auto txSpectrumModel = txInfoIterator->second.m_txSpectrumModel;
 
  156            const auto txSpectrumModelUid = txSpectrumModel->GetUid();
 
  158            if (rxSpectrumModelUid != txSpectrumModelUid &&
 
  159                !txSpectrumModel->IsOrthogonal(*rxSpectrumModel))
 
  161                NS_LOG_LOGIC(
"Creating converter between SpectrumModelUid " 
  162                             << txSpectrumModel->GetUid() << 
" and " << rxSpectrumModelUid);
 
  164                auto ret2 = txInfoIterator->second.m_spectrumConverterMap.insert(
 
  165                    std::make_pair(rxSpectrumModelUid, converter));
 
 
  172TxSpectrumModelInfoMap_t::const_iterator
 
  177    const auto txSpectrumModelUid = txSpectrumModel->GetUid();
 
  187        txInfoIterator = ret.first;
 
  194            auto rxSpectrumModel = rxInfoIterator->second.m_rxSpectrumModel;
 
  195            const auto rxSpectrumModelUid = rxSpectrumModel->GetUid();
 
  197            if (rxSpectrumModelUid != txSpectrumModelUid &&
 
  198                !txSpectrumModel->IsOrthogonal(*rxSpectrumModel))
 
  200                NS_LOG_LOGIC(
"Creating converter between SpectrumModelUid " 
  201                             << txSpectrumModelUid << 
" and " << rxSpectrumModelUid);
 
  204                auto ret2 = txInfoIterator->second.m_spectrumConverterMap.insert(
 
  205                    std::make_pair(rxSpectrumModelUid, converter));
 
  212        NS_LOG_LOGIC(
"SpectrumModelUid " << txSpectrumModelUid << 
" already present");
 
  214    return txInfoIterator;
 
 
  224    auto txParamsTrace = txParams->Copy(); 
 
  228    auto txMobility = txParams->txPhy->GetMobility();
 
  229    const auto txSpectrumModelUid = txParams->psd->GetSpectrumModelUid();
 
  230    NS_LOG_LOGIC(
"txSpectrumModelUid " << txSpectrumModelUid);
 
  232    const auto txInfoIterator =
 
  236    NS_LOG_LOGIC(
"converter map for TX SpectrumModel with Uid " << txInfoIterator->first);
 
  237    NS_LOG_LOGIC(
"converter map size: " << txInfoIterator->second.m_spectrumConverterMap.size());
 
  239                 << txInfoIterator->second.m_spectrumConverterMap.begin()->first);
 
  241    std::map<SpectrumModelUid_t, Ptr<SpectrumValue>> convertedPsds{};
 
  246        const auto rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid();
 
  247        NS_LOG_LOGIC(
"rxSpectrumModelUids " << rxSpectrumModelUid);
 
  250        if (txSpectrumModelUid == rxSpectrumModelUid)
 
  253            convertedTxPowerSpectrum = txParams->psd;
 
  257            NS_LOG_LOGIC(
"converting txPowerSpectrum SpectrumModelUids " 
  258                         << txSpectrumModelUid << 
" --> " << rxSpectrumModelUid);
 
  259            auto rxConverterIterator =
 
  260                txInfoIterator->second.m_spectrumConverterMap.find(rxSpectrumModelUid);
 
  261            if (rxConverterIterator == txInfoIterator->second.m_spectrumConverterMap.end())
 
  266            convertedTxPowerSpectrum = rxConverterIterator->second.Convert(txParams->psd);
 
  268        convertedPsds.emplace(rxSpectrumModelUid, convertedTxPowerSpectrum);
 
  275        const auto rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid();
 
  277        if ((txSpectrumModelUid != rxSpectrumModelUid) &&
 
  278            !txInfoIterator->second.m_spectrumConverterMap.contains(rxSpectrumModelUid))
 
  284        for (
auto rxPhyIterator = rxInfoIterator->second.m_rxPhys.begin();
 
  285             rxPhyIterator != rxInfoIterator->second.m_rxPhys.end();
 
  288            NS_ASSERT_MSG((*rxPhyIterator)->GetRxSpectrumModel()->GetUid() == rxSpectrumModelUid,
 
  289                          "SpectrumModel change was not notified to MultiModelSpectrumChannel " 
  290                          "(i.e., AddRx should be called again after model is changed)");
 
  292            auto txAntennaGain{0.0};
 
  293            if ((*rxPhyIterator) != txParams->txPhy)
 
  295                auto rxNetDevice = (*rxPhyIterator)->GetDevice();
 
  296                auto txNetDevice = txParams->txPhy->GetDevice();
 
  298                if (rxNetDevice && txNetDevice)
 
  301                    if (rxNetDevice->GetNode()->GetId() == txNetDevice->GetNode()->GetId())
 
  304                            "Skipping the pathloss calculation among different antennas of the " 
  305                            "same node, not supported yet by any pathloss model in ns-3.");
 
  316                auto rxParams = txParams->Copy();
 
  320                auto receiverMobility = (*rxPhyIterator)->GetMobility();
 
  322                if (txMobility && receiverMobility)
 
  324                    if (rxParams->txAntenna)
 
  326                        Angles txAngles(receiverMobility->GetPosition(), txMobility->GetPosition());
 
  327                        txAntennaGain = rxParams->txAntenna->GetGainDb(txAngles);
 
  328                        NS_LOG_LOGIC(
"txAntennaGain = " << txAntennaGain << 
" dB");
 
  339                    auto dstNode = rxNetDevice->GetNode()->GetId();
 
 
  371    double txAntennaGain,
 
  378    const auto rxSpectrumModelUid = params->psd->GetSpectrumModelUid();
 
  379    const auto phySpectrumModelUid = receiver->GetRxSpectrumModel()->GetUid();
 
  380    NS_LOG_LOGIC(
"rxSpectrumModelUid " << rxSpectrumModelUid << 
" phySpectrumModelUid " 
  381                                       << phySpectrumModelUid);
 
  383    if (rxSpectrumModelUid != phySpectrumModelUid)
 
  385        NS_LOG_LOGIC(
"SpectrumModelUid changed since TX started");
 
  387        const auto itConvertedPsd = availableConvertedPsds.find(phySpectrumModelUid);
 
  388        if (itConvertedPsd != availableConvertedPsds.cend())
 
  390            NS_LOG_LOGIC(
"converted PSD already exists for " << phySpectrumModelUid);
 
  391            params->psd = itConvertedPsd->second;
 
  395            const auto txInfoIterator =
 
  399            const auto txSpectrumModelUid = txPsd->GetSpectrumModelUid();
 
  400            NS_LOG_LOGIC(
"converting txPowerSpectrum SpectrumModelUids " 
  401                         << txSpectrumModelUid << 
" --> " << phySpectrumModelUid);
 
  402            const auto rxConverterIterator =
 
  403                txInfoIterator->second.m_spectrumConverterMap.find(phySpectrumModelUid);
 
  404            if (rxConverterIterator == txInfoIterator->second.m_spectrumConverterMap.cend())
 
  411                params->psd = rxConverterIterator->second.Convert(txPsd);
 
  416    auto txMobility = params->txPhy->GetMobility();
 
  417    auto rxMobility = receiver->GetMobility();
 
  418    if (txMobility && rxMobility)
 
  420        auto pathLossDb{-txAntennaGain};
 
  421        auto rxAntennaGain{0.0};
 
  422        auto propagationGainDb{0.0};
 
  426            Angles rxAngles(txMobility->GetPosition(), rxMobility->GetPosition());
 
  427            rxAntennaGain = rxAntenna->GetGainDb(rxAngles);
 
  428            NS_LOG_LOGIC(
"rxAntennaGain = " << rxAntennaGain << 
" dB");
 
  429            pathLossDb -= rxAntennaGain;
 
  432        if (
m_propagationLoss && (txMobility->GetPosition() != rxMobility->GetPosition()))
 
  435            NS_LOG_LOGIC(
"propagationGainDb = " << propagationGainDb << 
" dB");
 
  436            pathLossDb -= propagationGainDb;
 
  439        NS_LOG_LOGIC(
"total pathLoss = " << pathLossDb << 
" dB");
 
  458        const auto pathLossLinear = std::pow(10.0, (-pathLossDb) / 10.0);
 
  459        *(params->psd) *= pathLossLinear;
 
  473                          "PhasedArrayModel instances should be installed at both TX and RX " 
  474                          "SpectrumPhy in order to use PhasedArraySpectrumPropagationLoss.");
 
  485    receiver->StartRx(params);
 
 
  511        for (
const auto& phyIt : rxInfoIterator->second.m_rxPhys)
 
  515                return (*phyIt).GetDevice();
 
 
Class holding the azimuth and inclination angles of spherical coordinates.
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.
virtual void StartRx(Ptr< SpectrumValue > txPsd, double txAntennaGain, Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver, const std::map< SpectrumModelUid_t, Ptr< SpectrumValue > > &availableConvertedPsds)
Used internally to reschedule transmission after the propagation delay.
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.
MultiModelSpectrumChannel()
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
Data structure holding, for each RX spectrum model, all the corresponding SpectrumPhy instances.
Smart pointer class similar to boost::intrusive_ptr.
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< SpectrumTransmitFilter > m_filter
Transmit filter to be used with this channel.
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...
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.