diff -r 24667d1f463f src/uan/model/uan-mac-cw.cc --- a/src/uan/model/uan-mac-cw.cc Fri Mar 09 14:18:54 2018 +0100 +++ b/src/uan/model/uan-mac-cw.cc Fri Mar 09 15:47:24 2018 +0100 @@ -35,10 +35,11 @@ UanMacCw::UanMacCw () : UanMac (), - m_phy (0), - m_pktTx (0), - m_state (IDLE), - m_cleared (false) + m_phy (0), + m_pktTx (0), + m_state (IDLE), + m_txNotified (false), + m_cleared (false) { m_rv = CreateObject (); @@ -63,7 +64,7 @@ m_phy = 0; } m_sendEvent.Cancel (); - m_txEndEvent.Cancel (); + m_txNotified = false; } void @@ -115,7 +116,7 @@ { case CCABUSY: NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " MAC " << GetAddress () << " Starting enqueue CCABUSY"); - if (m_txEndEvent.IsRunning ()) + if (m_txNotified == true) { NS_LOG_DEBUG ("State is TX"); } @@ -253,14 +254,10 @@ void UanMacCw::NotifyTxStart (Time duration) { + m_txNotified = true; - if (m_txEndEvent.IsRunning ()) - { - Simulator::Cancel (m_txEndEvent); - } + NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " Tx Start Notified"); - m_txEndEvent = Simulator::Schedule (duration, &UanMacCw::EndTx, this); - NS_LOG_DEBUG ("Time " << Simulator::Now ().GetSeconds () << " scheduling TxEndEvent with delay " << duration.GetSeconds ()); if (m_state == RUNNING) { NS_ASSERT (0); @@ -271,6 +268,14 @@ } +void +UanMacCw::NotifyTxEnd (void) +{ + EndTx (); + + m_txNotified = false; +} + int64_t UanMacCw::AssignStreams (int64_t stream) { diff -r 24667d1f463f src/uan/model/uan-mac-cw.h --- a/src/uan/model/uan-mac-cw.h Fri Mar 09 14:18:54 2018 +0100 +++ b/src/uan/model/uan-mac-cw.h Fri Mar 09 15:47:24 2018 +0100 @@ -59,7 +59,7 @@ /** * Set the contention window size. - * + * * \param cw Contention window size. */ virtual void SetCw (uint32_t cw); @@ -96,6 +96,7 @@ virtual void NotifyCcaStart (void); virtual void NotifyCcaEnd (void); virtual void NotifyTxStart (Time duration); + virtual void NotifyTxEnd (void); /** * TracedCallback signature for enqueue/dequeue of a packet. @@ -103,12 +104,12 @@ * \param [in] packet The Packet being received. * \param [in] proto The protocol number. */ - typedef void (* QueueTracedCallback) - (Ptr packet, uint16_t proto); + typedef void (* QueueTracedCallback)(Ptr packet, uint16_t proto); private: /** Enum defining possible Phy states. */ - typedef enum { + typedef enum + { IDLE, //!< Idle state. CCABUSY, //!< Channel busy. RUNNING, //!< Delay timer running. @@ -143,8 +144,8 @@ uint16_t m_pktTxProt; /** Scheduled SendPacket event. */ EventId m_sendEvent; - /** Scheduled EndTx event. */ - EventId m_txEndEvent; + /** Tx has been notified from Phy. */ + bool m_txNotified; /** Current state. */ State m_state; diff -r 24667d1f463f src/uan/model/uan-phy-gen.cc --- a/src/uan/model/uan-phy-gen.cc Fri Mar 09 14:18:54 2018 +0100 +++ b/src/uan/model/uan-phy-gen.cc Fri Mar 09 15:47:24 2018 +0100 @@ -149,17 +149,17 @@ if (std::abs (pit->GetAmp ()) > maxAmp) { maxAmp = std::abs (pit->GetAmp ()); - // Modified in order to subtract delay of first tap (maxTapDelay appears to be used later in code + // Modified in order to subtract delay of first tap (maxTapDelay appears to be used later in code // as delay from first reception, not from TX time) - maxTapDelay = pit->GetDelay ().GetSeconds () - pdp.GetTap(0).GetDelay().GetSeconds(); + maxTapDelay = pit->GetDelay ().GetSeconds () - pdp.GetTap (0).GetDelay ().GetSeconds (); } } double effRxPowerDb = rxPowerDb + KpToDb (csp); - //It appears to be just the first elements of the sum in Parrish paper, + //It appears to be just the first elements of the sum in Parrish paper, // "System Design Considerations for Undersea Networks: Link and Multiple Access Protocols", eq. 14 - double isiUpa = DbToKp(rxPowerDb) * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts)); // added DpToKp() + double isiUpa = DbToKp (rxPowerDb) * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts)); // added DpToKp() UanTransducer::ArrivalList::const_iterator it = arrivalList.begin (); double intKp = -DbToKp (effRxPowerDb); for (; it != arrivalList.end (); it++) @@ -493,17 +493,17 @@ /*************** UanPhyGen definition *****************/ UanPhyGen::UanPhyGen () : UanPhy (), - m_state (IDLE), - m_channel (0), - m_transducer (0), - m_device (0), - m_mac (0), - m_txPwrDb (0), - m_rxThreshDb (0), - m_ccaThreshDb (0), - m_pktRx (0), - m_pktTx (0), - m_cleared (false) + m_state (IDLE), + m_channel (0), + m_transducer (0), + m_device (0), + m_mac (0), + m_txPwrDb (0), + m_rxThreshDb (0), + m_ccaThreshDb (0), + m_pktRx (0), + m_pktTx (0), + m_cleared (false) { m_pg = CreateObject (); @@ -741,6 +741,8 @@ m_state = IDLE; } UpdatePowerConsumption (IDLE); + + NotifyListenersTxEnd (); } void @@ -1004,13 +1006,13 @@ UanPhyGen::SetSleepMode (bool sleep ) { if (sleep ) - { - m_state = SLEEP; - if (!m_energyCallback.IsNull ()) - { - m_energyCallback (SLEEP); - } - } + { + m_state = SLEEP; + if (!m_energyCallback.IsNull ()) + { + m_energyCallback (SLEEP); + } + } else if (m_state == SLEEP) { if (GetInterferenceDb ((Ptr) 0) > m_ccaThreshDb) @@ -1155,6 +1157,16 @@ } } +void +UanPhyGen::NotifyListenersTxEnd (void) +{ + ListenerList::const_iterator it = m_listeners.begin (); + for (; it != m_listeners.end (); it++) + { + (*it)->NotifyTxEnd (); + } +} + uint32_t UanPhyGen::GetNModes (void) { diff -r 24667d1f463f src/uan/model/uan-phy-gen.h --- a/src/uan/model/uan-phy-gen.h Fri Mar 09 14:18:54 2018 +0100 +++ b/src/uan/model/uan-phy-gen.h Fri Mar 09 15:47:24 2018 +0100 @@ -215,10 +215,10 @@ * clearing time between symbols transmitted on the same frequency. * This clearing time combats ISI from channel delay spread and also has * a byproduct of possibly reducing interference from other transmitted packets. - * - * Thanks to Randall Plate for the latest model revision based on the following + * + * Thanks to Randall Plate for the latest model revision based on the following * papers: - *
    + *
      *
    • Parrish, "System Design Considerations for Undersea Networks: Link and Multiple Access Protocols" *
    • Siderius, "Effects of Ocean Thermocline Variability on Noncoherent Underwater Acoustic Communications" *
    • Rao, "Channel Coding Techniques for Wireless Communications", ch 2 @@ -442,6 +442,10 @@ * \param duration Duration of transmission. */ void NotifyListenersTxStart (Time duration); + /** + * Call UanListener::NotifyTxEnd on all listeners. + */ + void NotifyListenersTxEnd (void); protected: virtual void DoDispose (); diff -r 24667d1f463f src/uan/model/uan-phy.h --- a/src/uan/model/uan-phy.h Fri Mar 09 14:18:54 2018 +0100 +++ b/src/uan/model/uan-phy.h Fri Mar 09 15:47:24 2018 +0100 @@ -96,7 +96,7 @@ protected: virtual void DoDispose (void); - + }; // class UanPhyCalcSinr /** @@ -147,7 +147,9 @@ { public: /** Default destructor */ - virtual ~UanPhyListener () { } + virtual ~UanPhyListener () + { + } /** Called when UanPhy begins receiving packet. */ virtual void NotifyRxStart (void) = 0; /** Called when UanPhy finishes receiving packet without error. */ @@ -164,7 +166,8 @@ * \param duration Duration of transmission. */ virtual void NotifyTxStart (Time duration) = 0; - + /** Function called when Phy object finishes transmitting packet */ + virtual void NotifyTxEnd (void) = 0; }; // class UanPhyListener /** @@ -210,13 +213,12 @@ * \param [in] sinr The SINR. * \param [in] mode The channel mode. */ - typedef void (* TracedCallback) - (Ptr pkt, double sinr, UanTxMode mode); + typedef void (* TracedCallback)(Ptr pkt, double sinr, UanTxMode mode); + - /** - * Set the DeviceEnergyModel callback for UanPhy device. - * + * Set the DeviceEnergyModel callback for UanPhy device. + * * \param callback The DeviceEnergyModel change state callback. */ virtual void SetEnergyModelCallback (DeviceEnergyModel::ChangeStateCallback callback) = 0; @@ -487,14 +489,14 @@ */ void NotifyRxDrop (Ptr packet); - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. - * - * \param stream First stream index to use. - * \return The number of stream indices assigned by this model. - */ + /** + * Assign a fixed random variable stream number to the random variables + * used by this model. Return the number of streams (possibly zero) that + * have been assigned. + * + * \param stream First stream index to use. + * \return The number of stream indices assigned by this model. + */ virtual int64_t AssignStreams (int64_t stream) = 0; /**