From 244dca6b6cf062feefb00f009f94bc2f8d397a9e Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Mon, 16 Jan 2012 19:26:57 +0100 Subject: [PATCH] add SpectrumChannel::RemoveRx () --- .../model/multi-model-spectrum-channel.cc | 37 +++++++++++++++++++ .../model/multi-model-spectrum-channel.h | 1 + .../model/single-model-spectrum-channel.cc | 21 +++++++++++ .../model/single-model-spectrum-channel.h | 1 + src/spectrum/model/spectrum-channel.h | 12 +++++- 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/spectrum/model/multi-model-spectrum-channel.cc b/src/spectrum/model/multi-model-spectrum-channel.cc index 29489d9f5..91b07372d 100644 --- a/src/spectrum/model/multi-model-spectrum-channel.cc +++ b/src/spectrum/model/multi-model-spectrum-channel.cc @@ -181,6 +181,43 @@ MultiModelSpectrumChannel::AddRx (Ptr phy) } +void +MultiModelSpectrumChannel::RemoveRx (Ptr phy) +{ + NS_LOG_FUNCTION (this << phy); + + bool found = false; + for (std::vector >::iterator it = m_phyVector.begin (); it != m_phyVector.end (); ++it) + { + if (*it == phy) + { + m_phyVector.erase (it); + found = true; + break; + } + } + if (!found) + { + NS_LOG_WARN ("phy instance " << phy << " not found"); + } + else + { + + Ptr rxSpectrumModel = phy->GetRxSpectrumModel (); + + 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)"); + + SpectrumModelUid_t rxSpectrumModelUid = rxSpectrumModel->GetUid (); + RxSpectrumModelInfoMap_t::iterator rxInfoIterator = m_rxSpectrumModelInfoMap.find (rxSpectrumModelUid); + NS_ASSERT (rxInfoIterator != m_rxSpectrumModelInfoMap.end ()); + rxInfoIterator->second.m_rxPhyList.remove (phy); + if (rxInfoIterator->second.m_rxPhyList.empty ()) + { + // no more PHY instances with this spectrum model, so we can remove the converter + m_rxSpectrumModelInfoMap.erase (rxInfoIterator); + } + } +} TxSpectrumModelInfoMap_t::const_iterator MultiModelSpectrumChannel::FindAndEventuallyAddTxSpectrumModel (Ptr txSpectrumModel) diff --git a/src/spectrum/model/multi-model-spectrum-channel.h b/src/spectrum/model/multi-model-spectrum-channel.h index 6c40e7f44..b4b6ccce1 100644 --- a/src/spectrum/model/multi-model-spectrum-channel.h +++ b/src/spectrum/model/multi-model-spectrum-channel.h @@ -92,6 +92,7 @@ public: virtual void AddSpectrumPropagationLossModel (Ptr loss); virtual void SetPropagationDelayModel (Ptr delay); virtual void AddRx (Ptr phy); + virtual void RemoveRx (Ptr phy); virtual void StartTx (Ptr params); diff --git a/src/spectrum/model/single-model-spectrum-channel.cc b/src/spectrum/model/single-model-spectrum-channel.cc index 3a58f0eff..c9011e85b 100644 --- a/src/spectrum/model/single-model-spectrum-channel.cc +++ b/src/spectrum/model/single-model-spectrum-channel.cc @@ -105,6 +105,27 @@ SingleModelSpectrumChannel::AddRx (Ptr phy) } +void +SingleModelSpectrumChannel::RemoveRx (Ptr phy) +{ + NS_LOG_FUNCTION (this << phy); + bool found = false; + for (std::vector >::iterator it = m_phyList.begin (); it != m_phyList.end (); ++it) + { + if (*it == phy) + { + m_phyList.erase (it); + found = true; + break; + } + } + if (!found) + { + NS_LOG_WARN ("phy instance " << phy << " not found"); + } +} + + void SingleModelSpectrumChannel::StartTx (Ptr txParams) { diff --git a/src/spectrum/model/single-model-spectrum-channel.h b/src/spectrum/model/single-model-spectrum-channel.h index 2320e541f..8281ec5e0 100644 --- a/src/spectrum/model/single-model-spectrum-channel.h +++ b/src/spectrum/model/single-model-spectrum-channel.h @@ -51,6 +51,7 @@ public: virtual void AddSpectrumPropagationLossModel (Ptr loss); virtual void SetPropagationDelayModel (Ptr delay); virtual void AddRx (Ptr phy); + virtual void RemoveRx (Ptr phy); virtual void StartTx (Ptr params); diff --git a/src/spectrum/model/spectrum-channel.h b/src/spectrum/model/spectrum-channel.h index a45fc4a82..52dda9ffa 100644 --- a/src/spectrum/model/spectrum-channel.h +++ b/src/spectrum/model/spectrum-channel.h @@ -79,7 +79,8 @@ public: virtual void StartTx (Ptr params) = 0; /** - * @brief add a SpectrumPhy to a channel, so it can receive packets + * @brief add a SpectrumPhy to a channel, so it can receive signals + * transmitted over the channel * * This method is used to attach a SpectrumPhy instance to a * SpectrumChannel instance, so that the SpectrumPhy can receive @@ -95,6 +96,15 @@ public: */ virtual void AddRx (Ptr phy) = 0; + /** + * @brief remove a previously added SpectrumPhy from the channel, so + * that it will not receive any more signals transmitted on the channel + * + * + * @param phy the SpectrumPhy instance to be removed from the channel + */ + virtual void RemoveRx (Ptr phy) = 0; + };