From b5f518191cc45e1a2a8a7f46d8a62cde3602cd96 Mon Sep 17 00:00:00 2001 From: Andrea Sacco Date: Tue, 16 Aug 2011 20:22:40 +0200 Subject: [PATCH] Bug 1010 - Uan model Sleep patch --- src/uan/model/uan-net-device.cc | 6 +++++ src/uan/model/uan-net-device.h | 2 ++ src/uan/model/uan-phy-dual.h | 5 +++++ src/uan/model/uan-phy-gen.cc | 40 ++++++++++++++++++++++++++++++++- src/uan/model/uan-phy-gen.h | 2 ++ src/uan/model/uan-phy.h | 2 ++ 6 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/uan/model/uan-net-device.cc b/src/uan/model/uan-net-device.cc index 861918b60..3a8dc8087 100644 --- a/src/uan/model/uan-net-device.cc +++ b/src/uan/model/uan-net-device.cc @@ -389,5 +389,11 @@ UanNetDevice::SetAddress (Address address) m_mac->SetAddress (UanAddress::ConvertFrom (address)); } +void +UanNetDevice::SetSleepMode (bool sleep) +{ + m_phy->SetSleepMode (sleep); +} + } // namespace ns3 diff --git a/src/uan/model/uan-net-device.h b/src/uan/model/uan-net-device.h index adaa08431..34fad0be6 100644 --- a/src/uan/model/uan-net-device.h +++ b/src/uan/model/uan-net-device.h @@ -101,6 +101,8 @@ public: */ void Clear (void); + void SetSleepMode (bool sleep); + // Purely virtual functions from base class virtual void SetIfIndex (const uint32_t index); virtual uint32_t GetIfIndex (void) const; diff --git a/src/uan/model/uan-phy-dual.h b/src/uan/model/uan-phy-dual.h index 306b4c768..41c6c6e8e 100644 --- a/src/uan/model/uan-phy-dual.h +++ b/src/uan/model/uan-phy-dual.h @@ -248,6 +248,11 @@ public: */ void SetSinrModelPhy2 (Ptr calcSinr); + virtual void SetSleepMode (bool sleep) + { + //TODO This method has to be implemented + } + /** * \returns Packet currently being received on Phy1 (Null Ptr if none) */ diff --git a/src/uan/model/uan-phy-gen.cc b/src/uan/model/uan-phy-gen.cc index c910e6a84..45a989ddd 100644 --- a/src/uan/model/uan-phy-gen.cc +++ b/src/uan/model/uan-phy-gen.cc @@ -522,6 +522,11 @@ UanPhyGen::SendPacket (Ptr pkt, uint32_t modeNum) NS_LOG_DEBUG ("PHY requested to TX while already Transmitting. Dropping packet."); return; } + else if (m_state == SLEEP) + { + NS_LOG_DEBUG ("PHY requested to TX while sleeping. Dropping packet."); + return; + } UanTxMode txMode = GetMode (modeNum); @@ -544,6 +549,12 @@ UanPhyGen::SendPacket (Ptr pkt, uint32_t modeNum) void UanPhyGen::TxEndEvent () { + if (m_state == SLEEP || m_disabled == true) + { + NS_LOG_DEBUG ("Transmission ended but node sleeping or dead"); + return; + } + NS_ASSERT (m_state == TX); if (GetInterferenceDb ( (Ptr) 0) > m_ccaThreshDb) { @@ -626,7 +637,7 @@ UanPhyGen::StartRxPacket (Ptr pkt, double rxPowerDb, UanTxMode txMode, U } break; case SLEEP: - NS_FATAL_ERROR ("SLEEP state handling not yet implemented!"); + NS_LOG_DEBUG ("Sleep mode. Dropping packet."); break; } @@ -646,6 +657,13 @@ UanPhyGen::RxEndEvent (Ptr pkt, double rxPowerDb, UanTxMode txMode) return; } + if (m_disabled || m_state == SLEEP) + { + NS_LOG_DEBUG ("Sleep mode or dead. Dropping packet"); + m_pktRx = 0; + return; + } + if (GetInterferenceDb ( (Ptr) 0) > m_ccaThreshDb) { m_state = CCABUSY; @@ -811,6 +829,26 @@ UanPhyGen::SetTransducer (Ptr trans) m_transducer->AddPhy (this); } +void +UanPhyGen::SetSleepMode (bool sleep) +{ + if (sleep) + { + m_state = SLEEP; + if (!m_energyCallback.IsNull ()) + { + m_energyCallback (SLEEP); + } + } + else + { + m_state = IDLE; + if (!m_energyCallback.IsNull ()) + { + m_energyCallback (IDLE); + } + } +} void UanPhyGen::NotifyTransStartTx (Ptr packet, double txPowerDb, UanTxMode txMode) diff --git a/src/uan/model/uan-phy-gen.h b/src/uan/model/uan-phy-gen.h index 232b1556a..8cd9a9a6b 100644 --- a/src/uan/model/uan-phy-gen.h +++ b/src/uan/model/uan-phy-gen.h @@ -203,6 +203,8 @@ public: virtual Ptr GetPacketRx (void) const; virtual void Clear (void); + virtual void SetSleepMode (bool sleep); + private: typedef std::list ListenerList; diff --git a/src/uan/model/uan-phy.h b/src/uan/model/uan-phy.h index fe6b55f0c..8c51a5d29 100644 --- a/src/uan/model/uan-phy.h +++ b/src/uan/model/uan-phy.h @@ -374,6 +374,8 @@ public: * Clears all pointer references */ virtual void Clear (void) = 0; + + virtual void SetSleepMode (bool sleep) = 0; }; }