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> 
   39 #include "multi-model-spectrum-channel.h" 
   48 NS_OBJECT_ENSURE_REGISTERED (MultiModelSpectrumChannel);
 
   51 std::ostream& 
operator<< (std::ostream& lhs, TxSpectrumModelInfoMap_t& rhs)
 
   53   for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin ();
 
   57       SpectrumConverterMap_t::iterator jt;
 
   58       for (jt = it->second.m_spectrumConverterMap.begin ();
 
   59            jt != it->second.m_spectrumConverterMap.end ();
 
   62           lhs << 
"(" << it->first << 
"," << jt->first << 
") ";
 
   68 TxSpectrumModelInfo::TxSpectrumModelInfo (Ptr<const SpectrumModel> txSpectrumModel)
 
   69   : m_txSpectrumModel (txSpectrumModel)
 
   74 RxSpectrumModelInfo::RxSpectrumModelInfo (Ptr<const SpectrumModel> rxSpectrumModel)
 
   75   : m_rxSpectrumModel (rxSpectrumModel)
 
   80 MultiModelSpectrumChannel::MultiModelSpectrumChannel ()
 
   98 MultiModelSpectrumChannel::GetTypeId (
void)
 
  100   static TypeId tid = 
TypeId (
"ns3::MultiModelSpectrumChannel")
 
  102     .AddConstructor<MultiModelSpectrumChannel> ()
 
  103     .AddAttribute (
"MaxLossDb",
 
  104                    "If a single-frequency PropagationLossModel is used, this value " 
  105                    "represents the maximum loss in dB for which transmissions will be " 
  106                    "passed to the receiving PHY. Signals for which the PropagationLossModel " 
  107                    "returns a loss bigger than this value will not be propagated to the receiver. " 
  108                    "This parameter is to be used to reduce " 
  109                    "the computational load by not propagating signals that are far beyond " 
  110                    "the interference range. Note that the default value corresponds to " 
  111                    "considering all signals for reception. Tune this value with care. ",
 
  113                    MakeDoubleAccessor (&MultiModelSpectrumChannel::m_maxLossDb),
 
  114                    MakeDoubleChecker<double> ())
 
  115     .AddTraceSource (
"PathLoss",
 
  116                      "This trace is fired " 
  117                      "whenever a new path loss value is calculated. The first and second parameters " 
  118                      "to the trace are pointers respectively to the TX and RX SpectrumPhy instances, " 
  119                      "whereas the third parameters is the loss value in dB. Note that the loss value " 
  120                      "reported by this trace is the single-frequency loss value obtained by evaluating " 
  121                      "only the TX and RX AntennaModels and the PropagationLossModel. In particular, note that " 
  122                      "SpectrumPropagationLossModel (even if present) is never used to evaluate the loss value " 
  123                      "reported in this trace. ",
 
  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)");
 
  140   SpectrumModelUid_t rxSpectrumModelUid = rxSpectrumModel->GetUid ();
 
  142   std::vector<Ptr<SpectrumPhy> >::const_iterator it;
 
  152       std::set<Ptr<SpectrumPhy> >::iterator phyIt = rxInfoIterator->second.m_rxPhySet.find (phy);
 
  153       if (phyIt !=  rxInfoIterator->second.m_rxPhySet.end ())
 
  155           rxInfoIterator->second.m_rxPhySet.erase (phyIt);
 
  168       std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret;
 
  172       std::pair<std::set<Ptr<SpectrumPhy> >::iterator, 
bool> ret2 = ret.first->second.m_rxPhySet.insert (phy);
 
  181           NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModel->GetUid () << 
" and " << rxSpectrumModelUid );
 
  183           std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
 
  184           ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
 
  191       std::pair<std::set<Ptr<SpectrumPhy> >::iterator, 
bool> ret2 = rxInfoIterator->second.m_rxPhySet.insert (phy);
 
  198 TxSpectrumModelInfoMap_t::const_iterator
 
  202   SpectrumModelUid_t txSpectrumModelUid = txSpectrumModel->GetUid ();
 
  209       std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret;
 
  212       txInfoIterator = ret.first;
 
  220           SpectrumModelUid_t rxSpectrumModelUid = rxSpectrumModel->GetUid ();
 
  222           if (rxSpectrumModelUid != txSpectrumModelUid)
 
  224               NS_LOG_LOGIC (
"Creating converters between SpectrumModelUids " << txSpectrumModelUid << 
" and " << rxSpectrumModelUid );
 
  227               std::pair<SpectrumConverterMap_t::iterator, bool> ret2;
 
  228               ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make_pair (rxSpectrumModelUid, converter));
 
  235       NS_LOG_LOGIC (
"SpectrumModelUid " << txSpectrumModelUid << 
" already present");
 
  237   return txInfoIterator;
 
  252   SpectrumModelUid_t txSpectrumModelUid = txParams->psd->GetSpectrumModelUid ();
 
  253   NS_LOG_LOGIC (
" txSpectrumModelUid " << txSpectrumModelUid);
 
  259   NS_LOG_LOGIC (
"converter map for TX SpectrumModel with Uid " << txInfoIteratorerator->first);
 
  260   NS_LOG_LOGIC (
"converter map size: " << txInfoIteratorerator->second.m_spectrumConverterMap.size ());
 
  261   NS_LOG_LOGIC (
"converter map first element: " << txInfoIteratorerator->second.m_spectrumConverterMap.begin ()->first);
 
  267       SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectrumModel->GetUid ();
 
  268       NS_LOG_LOGIC (
" rxSpectrumModelUids " << rxSpectrumModelUid);
 
  271       if (txSpectrumModelUid == rxSpectrumModelUid)
 
  274           convertedTxPowerSpectrum = txParams->psd;
 
  278           NS_LOG_LOGIC (
" converting txPowerSpectrum SpectrumModelUids" << txSpectrumModelUid << 
" --> " << rxSpectrumModelUid);
 
  279           SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIteratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid);
 
  280           NS_ASSERT (rxConverterIterator != txInfoIteratorerator->second.m_spectrumConverterMap.end ());
 
  281           convertedTxPowerSpectrum = rxConverterIterator->second.Convert (txParams->psd);
 
  285       for (std::set<
Ptr<SpectrumPhy> >::const_iterator rxPhyIterator = rxInfoIterator->second.m_rxPhySet.begin ();
 
  286            rxPhyIterator != rxInfoIterator->second.m_rxPhySet.end ();
 
  289           NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == rxSpectrumModelUid,
 
  290                          "SpectrumModel change was not notified to MultiModelSpectrumChannel (i.e., AddRx should be called again after model is changed)");
 
  292           if ((*rxPhyIterator) != txParams->txPhy)
 
  294               NS_LOG_LOGIC (
" copying signal parameters " << txParams);
 
  296               rxParams->psd = Copy<SpectrumValue> (convertedTxPowerSpectrum);
 
  301               if (txMobility && receiverMobility)
 
  303                   double pathLossDb = 0;
 
  304                   if (rxParams->txAntenna != 0)
 
  307                       double txAntennaGain = rxParams->txAntenna->GetGainDb (txAngles);
 
  308                       NS_LOG_LOGIC (
"txAntennaGain = " << txAntennaGain << 
" dB");
 
  309                       pathLossDb -= txAntennaGain;
 
  315                       double rxAntennaGain = rxAntenna->GetGainDb (rxAngles);
 
  316                       NS_LOG_LOGIC (
"rxAntennaGain = " << rxAntennaGain << 
" dB");
 
  317                       pathLossDb -= rxAntennaGain;
 
  322                       NS_LOG_LOGIC (
"propagationGainDb = " << propagationGainDb << 
" dB");
 
  323                       pathLossDb -= propagationGainDb;
 
  325                   NS_LOG_LOGIC (
"total pathLoss = " << pathLossDb << 
" dB");    
 
  326                   m_pathLossTrace (txParams->txPhy, *rxPhyIterator, pathLossDb);
 
  327                   if ( pathLossDb > m_maxLossDb)
 
  332                   double pathGainLinear = std::pow (10.0, (-pathLossDb) / 10.0);
 
  333                   *(rxParams->psd) *= pathGainLinear;              
 
  350                   uint32_t dstNode =  netDev->GetNode ()->GetId ();
 
  352                                                   rxParams, *rxPhyIterator);
 
  358                                        rxParams, *rxPhyIterator);
 
  401       for (std::set<
Ptr<SpectrumPhy> >::const_iterator phyIt = rxInfoIterator->second.m_rxPhySet.begin ();
 
  402            phyIt != rxInfoIterator->second.m_rxPhySet.end ();
 
  407               return (*phyIt)->GetDevice ();
 
  440 MultiModelSpectrumChannel::GetSpectrumPropagationLossModel (
void)
 
Ptr< SpectrumPropagationLossModel > m_spectrumPropagationLoss
#define NS_LOG_FUNCTION(parameters)
virtual void StartRx(Ptr< SpectrumSignalParameters > params)=0
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Vector GetPosition(void) const 
virtual void DoDispose(void)
RxSpectrumModelInfoMap_t m_rxSpectrumModelInfoMap
virtual Ptr< const SpectrumModel > GetRxSpectrumModel() const =0
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
#define NS_FATAL_ERROR(msg)
fatal error handling 
Ptr< PropagationDelayModel > m_propagationDelay
Ptr< PropagationLossModel > m_propagationLoss
virtual uint32_t GetNDevices(void) const 
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)
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const 
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
#define NS_LOG_LOGIC(msg)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual void AddSpectrumPropagationLossModel(Ptr< SpectrumPropagationLossModel > loss)
#define NS_ASSERT_MSG(condition, message)
virtual void StartTx(Ptr< SpectrumSignalParameters > params)
virtual Ptr< NetDevice > GetDevice(uint32_t i) const 
virtual void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
TxSpectrumModelInfoMap_t m_txSpectrumModelInfoMap
Hold an floating point type. 
a unique identifier for an interface. 
virtual void StartRx(Ptr< SpectrumSignalParameters > params, Ptr< SpectrumPhy > receiver)
TypeId SetParent(TypeId tid)
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.