diff --git a/examples/wireless/wifi-ap.cc b/examples/wireless/wifi-ap.cc index 39935a93a..49ccaf377 100644 --- a/examples/wireless/wifi-ap.cc +++ b/examples/wireless/wifi-ap.cc @@ -79,25 +79,7 @@ PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::Sta { if (g_verbose) { - std::cout << " state="; - switch (state) { - case WifiPhy::SWITCHING: - std::cout << "switchng"; - break; - case WifiPhy::TX: - std::cout << "tx "; - break; - case WifiPhy::SYNC: - std::cout << "sync "; - break; - case WifiPhy::CCA_BUSY: - std::cout << "cca-busy"; - break; - case WifiPhy::IDLE: - std::cout << "idle "; - break; - } - std::cout << " start="< Simulator::Now ()) { @@ -218,21 +189,21 @@ WifiPhyStateHelper::NotifyTxStart (Time duration) } } void -WifiPhyStateHelper::NotifySyncStart (Time duration) +WifiPhyStateHelper::NotifyRxStart (Time duration) { for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++) { (*i)->NotifyRxStart (duration); } } void -WifiPhyStateHelper::NotifySyncEndOk (void) +WifiPhyStateHelper::NotifyRxEndOk (void) { for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++) { (*i)->NotifyRxEndOk (); } } void -WifiPhyStateHelper::NotifySyncEndError (void) +WifiPhyStateHelper::NotifyRxEndError (void) { for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++) { (*i)->NotifyRxEndError (); @@ -257,14 +228,14 @@ void WifiPhyStateHelper::LogPreviousIdleAndCcaBusyStates (void) { Time now = Simulator::Now (); - Time idleStart = Max (m_endCcaBusy, m_endSync); + Time idleStart = Max (m_endCcaBusy, m_endRx); idleStart = Max (idleStart, m_endTx); idleStart = Max (idleStart, m_endSwitching); NS_ASSERT (idleStart <= now); - if (m_endCcaBusy > m_endSync && + if (m_endCcaBusy > m_endRx && m_endCcaBusy > m_endSwitching && m_endCcaBusy > m_endTx) { - Time ccaBusyStart = Max (m_endTx, m_endSync); + Time ccaBusyStart = Max (m_endTx, m_endRx); ccaBusyStart = Max (ccaBusyStart, m_startCcaBusy); ccaBusyStart = Max (ccaBusyStart, m_endSwitching); m_stateLogger (ccaBusyStart, idleStart - ccaBusyStart, WifiPhy::CCA_BUSY); @@ -280,16 +251,16 @@ WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr packet, WifiM NotifyTxStart (txDuration); Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::SYNC: + case WifiPhy::RX: /* The packet which is being received as well - * as its endSync event are cancelled by the caller. + * as its endRx event are cancelled by the caller. */ - m_syncing = false; - m_stateLogger (m_startSync, now - m_startSync, WifiPhy::SYNC); - m_endSync = now; + m_rxing = false; + m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_endRx = now; break; case WifiPhy::CCA_BUSY: { - Time ccaStart = Max (m_endSync, m_endTx); + Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); @@ -299,7 +270,7 @@ WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr packet, WifiM break; case WifiPhy::SWITCHING: default: - NS_ASSERT (false); + NS_FATAL_ERROR ("Invalid WifiPhy state."); break; } m_stateLogger (now, txDuration, WifiPhy::TX); @@ -308,33 +279,33 @@ WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr packet, WifiM m_startTx = now; } void -WifiPhyStateHelper::SwitchToSync (Time rxDuration) +WifiPhyStateHelper::SwitchToRx (Time rxDuration) { NS_ASSERT (IsStateIdle () || IsStateCcaBusy ()); - NS_ASSERT (!m_syncing); - NotifySyncStart (rxDuration); + NS_ASSERT (!m_rxing); + NotifyRxStart (rxDuration); Time now = Simulator::Now (); switch (GetState ()) { case WifiPhy::IDLE: LogPreviousIdleAndCcaBusyStates (); break; case WifiPhy::CCA_BUSY: { - Time ccaStart = Max (m_endSync, m_endTx); + Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); } break; case WifiPhy::SWITCHING: - case WifiPhy::SYNC: + case WifiPhy::RX: case WifiPhy::TX: - NS_ASSERT (false); + NS_FATAL_ERROR ("Invalid WifiPhy state."); break; } m_previousStateChangeTime = now; - m_syncing = true; - m_startSync = now; - m_endSync = now + rxDuration; - NS_ASSERT (IsStateSync ()); + m_rxing = true; + m_startRx = now; + m_endRx = now + rxDuration; + NS_ASSERT (IsStateRx ()); } void @@ -343,16 +314,16 @@ WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration) NotifySwitchingStart (switchingDuration); Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::SYNC: + case WifiPhy::RX: /* The packet which is being received as well - * as its endSync event are cancelled by the caller. + * as its endRx event are cancelled by the caller. */ - m_syncing = false; - m_stateLogger (m_startSync, now - m_startSync, WifiPhy::SYNC); - m_endSync = now; + m_rxing = false; + m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_endRx = now; break; case WifiPhy::CCA_BUSY: { - Time ccaStart = Max (m_endSync, m_endTx); + Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); @@ -363,7 +334,7 @@ WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration) case WifiPhy::TX: case WifiPhy::SWITCHING: default: - NS_ASSERT (false); + NS_FATAL_ERROR ("Invalid WifiPhy state."); break; } @@ -380,39 +351,39 @@ WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration) } void -WifiPhyStateHelper::SwitchFromSyncEndOk (Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) +WifiPhyStateHelper::SwitchFromRxEndOk (Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) { m_rxOkTrace (packet, snr, mode, preamble); - NotifySyncEndOk (); - DoSwitchFromSync (); - if (!m_syncOkCallback.IsNull ()) + NotifyRxEndOk (); + DoSwitchFromRx (); + if (!m_rxOkCallback.IsNull ()) { - m_syncOkCallback (packet, snr, mode, preamble); + m_rxOkCallback (packet, snr, mode, preamble); } } void -WifiPhyStateHelper::SwitchFromSyncEndError (Ptr packet, double snr) +WifiPhyStateHelper::SwitchFromRxEndError (Ptr packet, double snr) { m_rxErrorTrace (packet, snr); - NotifySyncEndError (); - DoSwitchFromSync (); - if (!m_syncErrorCallback.IsNull ()) + NotifyRxEndError (); + DoSwitchFromRx (); + if (!m_rxErrorCallback.IsNull ()) { - m_syncErrorCallback (packet, snr); + m_rxErrorCallback (packet, snr); } } void -WifiPhyStateHelper::DoSwitchFromSync (void) +WifiPhyStateHelper::DoSwitchFromRx (void) { - NS_ASSERT (IsStateSync ()); - NS_ASSERT (m_syncing); + NS_ASSERT (IsStateRx ()); + NS_ASSERT (m_rxing); Time now = Simulator::Now (); - m_stateLogger (m_startSync, now - m_startSync, WifiPhy::SYNC); + m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); m_previousStateChangeTime = now; - m_syncing = false; + m_rxing = false; NS_ASSERT (IsStateIdle () || IsStateCcaBusy ()); } @@ -429,7 +400,7 @@ WifiPhyStateHelper::SwitchMaybeToCcaBusy (Time duration) break; case WifiPhy::CCA_BUSY: break; - case WifiPhy::SYNC: + case WifiPhy::RX: break; case WifiPhy::TX: break; diff --git a/src/devices/wifi/wifi-phy-state-helper.h b/src/devices/wifi/wifi-phy-state-helper.h index 649c97775..f01d47ec2 100644 --- a/src/devices/wifi/wifi-phy-state-helper.h +++ b/src/devices/wifi/wifi-phy-state-helper.h @@ -34,14 +34,14 @@ public: WifiPhyStateHelper (); - void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback); - void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback); + void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); + void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); void RegisterListener (WifiPhyListener *listener); enum WifiPhy::State GetState (void); bool IsStateCcaBusy (void); bool IsStateIdle (void); bool IsStateBusy (void); - bool IsStateSync (void); + bool IsStateRx (void); bool IsStateTx (void); bool IsStateSwitching (void); Time GetStateDuration (void); @@ -49,35 +49,34 @@ public: Time GetLastRxStartTime (void) const; void SwitchToTx (Time txDuration, Ptr packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower); - void SwitchToSync (Time syncDuration); + void SwitchToRx (Time rxDuration); void SwitchToChannelSwitching (Time switchingDuration); - void SwitchFromSyncEndOk (Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble); - void SwitchFromSyncEndError (Ptr packet, double snr); + void SwitchFromRxEndOk (Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble); + void SwitchFromRxEndError (Ptr packet, double snr); void SwitchMaybeToCcaBusy (Time duration); TracedCallback m_stateLogger; private: typedef std::vector Listeners; - const char *StateToString (enum WifiPhy::State state); void LogPreviousIdleAndCcaBusyStates (void); void NotifyTxStart (Time duration); void NotifyWakeup (void); - void NotifySyncStart (Time duration); - void NotifySyncEndOk (void); - void NotifySyncEndError (void); + void NotifyRxStart (Time duration); + void NotifyRxEndOk (void); + void NotifyRxEndError (void); void NotifyMaybeCcaBusyStart (Time duration); void NotifySwitchingStart (Time duration); - void DoSwitchFromSync (void); + void DoSwitchFromRx (void); - bool m_syncing; + bool m_rxing; Time m_endTx; - Time m_endSync; + Time m_endRx; Time m_endCcaBusy; Time m_endSwitching; Time m_startTx; - Time m_startSync; + Time m_startRx; Time m_startCcaBusy; Time m_startSwitching; Time m_previousStateChangeTime; @@ -86,8 +85,8 @@ private: TracedCallback, double, WifiMode, enum WifiPreamble> m_rxOkTrace; TracedCallback, double> m_rxErrorTrace; TracedCallback,WifiMode,WifiPreamble,uint8_t> m_txTrace; - WifiPhy::SyncOkCallback m_syncOkCallback; - WifiPhy::SyncErrorCallback m_syncErrorCallback; + WifiPhy::RxOkCallback m_rxOkCallback; + WifiPhy::RxErrorCallback m_rxErrorCallback; }; } // namespace ns3 diff --git a/src/devices/wifi/wifi-phy.cc b/src/devices/wifi/wifi-phy.cc index 1981b1e6a..e7bbcd66b 100644 --- a/src/devices/wifi/wifi-phy.cc +++ b/src/devices/wifi/wifi-phy.cc @@ -416,6 +416,24 @@ WifiPhy::Get13_5mb5Mhz (void) return mode; } +std::ostream& operator<< (std::ostream& os, enum WifiPhy::State state) +{ + switch (state) { + case WifiPhy::IDLE: + return (os << "IDLE"); + case WifiPhy::CCA_BUSY: + return (os << "CCA_BUSY"); + case WifiPhy::TX: + return (os << "TX"); + case WifiPhy::RX: + return (os << "RX"); + case WifiPhy::SWITCHING: + return (os << "SWITCHING"); + default: + NS_FATAL_ERROR ("Invalid WifiPhy state"); + return (os << "INVALID"); + } +} } // namespace ns3 diff --git a/src/devices/wifi/wifi-phy.h b/src/devices/wifi/wifi-phy.h index 2e2092748..86ae5a729 100644 --- a/src/devices/wifi/wifi-phy.h +++ b/src/devices/wifi/wifi-phy.h @@ -120,39 +120,39 @@ public: */ enum State { /** - * The PHY layer is synchronized upon a packet. + * The PHY layer is IDLE. */ - SYNC, + IDLE, + /** + * The PHY layer has sense the medium busy through the CCA mechanism + */ + CCA_BUSY, /** * The PHY layer is sending a packet. */ TX, /** - * The PHY layer has sense the medium busy through - * the CCA mechanism + * The PHY layer is receiving a packet. */ - CCA_BUSY, - /** - * The PHY layer is IDLE. - */ - IDLE, + RX, /** * The PHY layer is switching to other channel. */ SWITCHING }; + /** * arg1: packet received successfully * arg2: snr of packet * arg3: mode of packet * arg4: type of preamble used for packet. */ - typedef Callback, double, WifiMode, enum WifiPreamble> SyncOkCallback; + typedef Callback, double, WifiMode, enum WifiPreamble> RxOkCallback; /** * arg1: packet received unsuccessfully * arg2: snr of packet */ - typedef Callback, double> SyncErrorCallback; + typedef Callback, double> RxErrorCallback; static TypeId GetTypeId (void); @@ -170,12 +170,12 @@ public: * \param callback the callback to invoke * upon successful packet reception. */ - virtual void SetReceiveOkCallback (SyncOkCallback callback) = 0; + virtual void SetReceiveOkCallback (RxOkCallback callback) = 0; /** * \param callback the callback to invoke * upon erronous packet reception. */ - virtual void SetReceiveErrorCallback (SyncErrorCallback callback) = 0; + virtual void SetReceiveErrorCallback (RxErrorCallback callback) = 0; /** * \param packet the packet to send @@ -194,26 +194,30 @@ public: */ virtual void RegisterListener (WifiPhyListener *listener) = 0; - /** - * \returns true of the current state of the PHY layer is WifiPhy::CCA_BUSY, false otherwise. - */ - virtual bool IsStateCcaBusy (void) = 0; /** * \returns true of the current state of the PHY layer is WifiPhy::IDLE, false otherwise. */ virtual bool IsStateIdle (void) = 0; + /** + * \returns true of the current state of the PHY layer is WifiPhy::CCA_BUSY, false otherwise. + */ + virtual bool IsStateCcaBusy (void) = 0; /** * \returns true of the current state of the PHY layer is not WifiPhy::IDLE, false otherwise. */ virtual bool IsStateBusy (void) = 0; /** - * \returns true of the current state of the PHY layer is WifiPhy::SYNC, false otherwise. + * \returns true of the current state of the PHY layer is WifiPhy::RX, false otherwise. */ - virtual bool IsStateSync (void) = 0; + virtual bool IsStateRx (void) = 0; /** * \returns true of the current state of the PHY layer is WifiPhy::TX, false otherwise. */ virtual bool IsStateTx (void) = 0; + /** + * \returns true of the current state of the PHY layer is WifiPhy::SWITCHING, false otherwise. + */ + virtual bool IsStateSwitching (void) = 0; /** * \returns the amount of time since the current state has started. */ @@ -253,7 +257,7 @@ public: * the requested ber for the specified transmission mode. (W/W) */ virtual double CalculateSnr (WifiMode txMode, double ber) const = 0; - + /** * \brief Set channel number. * @@ -449,7 +453,12 @@ private: }; +/** + * \param os output stream + * \param state wifi state to stringify + */ +std::ostream& operator<< (std::ostream& os, enum WifiPhy::State state); + } // namespace ns3 - #endif /* WIFI_PHY_H */ diff --git a/src/devices/wifi/yans-wifi-phy.cc b/src/devices/wifi/yans-wifi-phy.cc index 7c0bf4fd7..24de83ecd 100644 --- a/src/devices/wifi/yans-wifi-phy.cc +++ b/src/devices/wifi/yans-wifi-phy.cc @@ -127,7 +127,7 @@ YansWifiPhy::GetTypeId (void) YansWifiPhy::YansWifiPhy () : m_channelNumber (1), - m_endSyncEvent (), + m_endRxEvent (), m_random (0.0, 1.0), m_channelStartingFrequency (0) { @@ -333,9 +333,9 @@ YansWifiPhy::SetChannelNumber (uint16_t nch) NS_ASSERT (!IsStateSwitching()); switch (m_state->GetState ()) { - case YansWifiPhy::SYNC: + case YansWifiPhy::RX: NS_LOG_DEBUG ("drop packet because of channel switching while reception"); - m_endSyncEvent.Cancel(); + m_endRxEvent.Cancel(); goto switchChannel; break; case YansWifiPhy::TX: @@ -381,12 +381,12 @@ YansWifiPhy::GetChannelFrequencyMhz() const } void -YansWifiPhy::SetReceiveOkCallback (SyncOkCallback callback) +YansWifiPhy::SetReceiveOkCallback (RxOkCallback callback) { m_state->SetReceiveOkCallback (callback); } void -YansWifiPhy::SetReceiveErrorCallback (SyncErrorCallback callback) +YansWifiPhy::SetReceiveErrorCallback (RxErrorCallback callback) { m_state->SetReceiveErrorCallback (callback); } @@ -428,8 +428,8 @@ YansWifiPhy::StartReceivePacket (Ptr packet, goto maybeCcaBusy; } break; - case YansWifiPhy::SYNC: - NS_LOG_DEBUG ("drop packet because already in Sync (power="<< + case YansWifiPhy::RX: + NS_LOG_DEBUG ("drop packet because already in Rx (power="<< rxPowerW<<"W)"); NotifyRxDrop (packet); if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) @@ -454,14 +454,14 @@ YansWifiPhy::StartReceivePacket (Ptr packet, case YansWifiPhy::IDLE: if (rxPowerW > m_edThresholdW) { - NS_LOG_DEBUG ("sync (power="<SwitchToSync (rxDuration); - NS_ASSERT (m_endSyncEvent.IsExpired ()); + m_state->SwitchToRx (rxDuration); + NS_ASSERT (m_endRxEvent.IsExpired ()); NotifyRxBegin (packet); - m_endSyncEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndSync, this, - packet, - event); + m_endRxEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndReceive, this, + packet, + event); } else { @@ -501,9 +501,9 @@ YansWifiPhy::SendPacket (Ptr packet, WifiMode txMode, WifiPreamble NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ()); Time txDuration = CalculateTxDuration (packet->GetSize (), txMode, preamble); - if (m_state->IsStateSync ()) + if (m_state->IsStateRx ()) { - m_endSyncEvent.Cancel (); + m_endRxEvent.Cancel (); } NotifyTxBegin (packet); uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000; @@ -651,9 +651,9 @@ YansWifiPhy::IsStateBusy (void) return m_state->IsStateBusy (); } bool -YansWifiPhy::IsStateSync (void) +YansWifiPhy::IsStateRx (void) { - return m_state->IsStateSync (); + return m_state->IsStateRx (); } bool YansWifiPhy::IsStateTx (void) @@ -731,10 +731,10 @@ YansWifiPhy::GetPowerDbm (uint8_t power) const } void -YansWifiPhy::EndSync (Ptr packet, Ptr event) +YansWifiPhy::EndReceive (Ptr packet, Ptr event) { NS_LOG_FUNCTION (this << packet << event); - NS_ASSERT (IsStateSync ()); + NS_ASSERT (IsStateRx ()); NS_ASSERT (event->GetEndTime () == Simulator::Now ()); struct InterferenceHelper::SnrPer snrPer; @@ -750,13 +750,13 @@ YansWifiPhy::EndSync (Ptr packet, Ptr event) double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30; double noiseDbm = RatioToDb(event->GetRxPowerW() / snrPer.snr) - GetRxNoiseFigure() + 30 ; NotifyPromiscSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, signalDbm, noiseDbm); - m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ()); + m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ()); } else { /* failure. */ NotifyRxDrop (packet); - m_state->SwitchFromSyncEndError (packet, snrPer.snr); + m_state->SwitchFromRxEndError (packet, snrPer.snr); } } } // namespace ns3 diff --git a/src/devices/wifi/yans-wifi-phy.h b/src/devices/wifi/yans-wifi-phy.h index 26a52817e..55c0e0280 100644 --- a/src/devices/wifi/yans-wifi-phy.h +++ b/src/devices/wifi/yans-wifi-phy.h @@ -82,8 +82,8 @@ public: * has a private attribute m_channelNumber that identifies the channel the * PHY operates on. Channel switching cannot interrupt an ongoing transmission. * When PHY is in TX state, the channel switching is postponed until the end - * of the current transmission. When the PHY is in SYNC state, the channel - * switching causes the drop of the sync packet. + * of the current transmission. When the PHY is in RX state, the channel + * switching causes the drop of the synchronized packet. */ void SetChannelNumber (uint16_t id); /// Return current channel number, see SetChannelNumber() @@ -122,14 +122,14 @@ public: virtual double GetTxPowerStart (void) const; virtual double GetTxPowerEnd (void) const; virtual uint32_t GetNTxPower (void) const; - virtual void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback); - virtual void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback); + virtual void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); + virtual void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); virtual void SendPacket (Ptr packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel); virtual void RegisterListener (WifiPhyListener *listener); virtual bool IsStateCcaBusy (void); virtual bool IsStateIdle (void); virtual bool IsStateBusy (void); - virtual bool IsStateSync (void); + virtual bool IsStateRx (void); virtual bool IsStateTx (void); virtual bool IsStateSwitching (void); virtual Time GetStateDuration (void); @@ -161,7 +161,7 @@ private: double WToDbm (double w) const; double RatioToDb (double ratio) const; double GetPowerDbm (uint8_t power) const; - void EndSync (Ptr packet, Ptr event); + void EndReceive (Ptr packet, Ptr event); private: double m_edThresholdW; @@ -177,7 +177,7 @@ private: Ptr m_device; Ptr m_mobility; Modes m_modes; - EventId m_endSyncEvent; + EventId m_endRxEvent; UniformVariable m_random; /// Standard-dependent center frequency of 0-th channel, MHz double m_channelStartingFrequency;