diff --git a/src/spectrum/model/constant-spectrum-propagation-loss.cc b/src/spectrum/model/constant-spectrum-propagation-loss.cc new file mode 100644 index 000000000..74ad71e8b --- /dev/null +++ b/src/spectrum/model/constant-spectrum-propagation-loss.cc @@ -0,0 +1,85 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Manuel Requena + */ + +#include "ns3/log.h" + +#include "ns3/constant-spectrum-propagation-loss.h" +#include "ns3/double.h" + + +NS_LOG_COMPONENT_DEFINE ("ConstantSpectrumPropagationLossModel"); + +namespace ns3 { + + +NS_OBJECT_ENSURE_REGISTERED (ConstantSpectrumPropagationLossModel); + +ConstantSpectrumPropagationLossModel::ConstantSpectrumPropagationLossModel () +{ + NS_LOG_FUNCTION (this); +} + +ConstantSpectrumPropagationLossModel::~ConstantSpectrumPropagationLossModel () +{ + NS_LOG_FUNCTION (this); +} + +TypeId +ConstantSpectrumPropagationLossModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::ConstantSpectrumPropagationLossModel") + .SetParent () + .AddConstructor () + .AddAttribute ("Loss", + "Path loss (dB) between transmitter and receiver", + DoubleValue (1.0), + MakeDoubleAccessor (&ConstantSpectrumPropagationLossModel::m_loss), + MakeDoubleChecker ()) + ; + return tid; +} + + +Ptr +ConstantSpectrumPropagationLossModel::DoCalcRxPowerSpectralDensity (Ptr txPsd, + Ptr a, + Ptr b) const +{ + NS_LOG_FUNCTION (this); + + Ptr rxPsd = Copy (txPsd); + Values::iterator vit = rxPsd->ValuesBegin (); + Bands::const_iterator fit = rxPsd->ConstBandsBegin (); + +// NS_LOG_INFO ("Loss = " << m_loss); + while (vit != rxPsd->ValuesEnd ()) + { + NS_ASSERT (fit != rxPsd->ConstBandsEnd ()); +// NS_LOG_INFO ("Ptx = " << *vit); + *vit /= m_loss; // Prx = Ptx / loss +// NS_LOG_INFO ("Prx = " << *vit); + ++vit; + ++fit; + } + return rxPsd; +} + + +} // namespace ns3 diff --git a/src/spectrum/model/constant-spectrum-propagation-loss.h b/src/spectrum/model/constant-spectrum-propagation-loss.h new file mode 100644 index 000000000..4063b0b7e --- /dev/null +++ b/src/spectrum/model/constant-spectrum-propagation-loss.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Manuel Requena + */ + +#ifndef CONSTANT_SPECTRUM_PROPAGATION_LOSS_H +#define CONSTANT_SPECTRUM_PROPAGATION_LOSS_H + +#include "ns3/spectrum-propagation-loss-model.h" + +namespace ns3 { + + +class ConstantSpectrumPropagationLossModel : public SpectrumPropagationLossModel +{ +public: + ConstantSpectrumPropagationLossModel (); + ~ConstantSpectrumPropagationLossModel (); + + static TypeId GetTypeId (); + + virtual Ptr DoCalcRxPowerSpectralDensity (Ptr txPsd, + Ptr a, + Ptr b) const; + +private: + double m_loss; +}; + + +} // namespace ns3 + +#endif /* CONSTANT_SPECTRUM_PROPAGATION_LOSS_MODEL_H */ diff --git a/src/spectrum/wscript b/src/spectrum/wscript index c396aea22..6f88b8d26 100644 --- a/src/spectrum/wscript +++ b/src/spectrum/wscript @@ -10,6 +10,7 @@ def build(bld): 'model/spectrum-type.cc', 'model/spectrum-propagation-loss-model.cc', 'model/friis-spectrum-propagation-loss.cc', + 'model/constant-spectrum-propagation-loss.cc', 'model/spectrum-phy.cc', 'model/spectrum-channel.cc', 'model/single-model-spectrum-channel.cc', @@ -47,6 +48,7 @@ def build(bld): 'model/spectrum-type.h', 'model/spectrum-propagation-loss-model.h', 'model/friis-spectrum-propagation-loss.h', + 'model/constant-spectrum-propagation-loss.h', 'model/spectrum-phy.h', 'model/spectrum-channel.h', 'model/single-model-spectrum-channel.h',