diff --git a/samples/main-ap-wifi.cc b/samples/main-ap-wifi.cc index 42ee59af0..c341c71cd 100644 --- a/samples/main-ap-wifi.cc +++ b/samples/main-ap-wifi.cc @@ -20,6 +20,8 @@ #include "ns3/wifi-net-device.h" #include "ns3/wifi-channel.h" +#include "ns3/wifi-phy.h" + #include "ns3/simulator.h" #include "ns3/callback.h" #include "ns3/ptr.h" @@ -44,6 +46,26 @@ WifiNetDeviceTrace (const TraceContext &context, Packet p, Mac48Address address) { std::cout << context << " ad=" << address << " p: " << p << std::endl; } +static void +WifiPhyStateTrace (const TraceContext &context, Time start, Time duration, enum WifiPhy::State state) +{ + std::cout << context << " state="; + switch (state) { + 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="<AddComposite ("phy", m_phy); resolver->SetParentResolver (NetDevice::GetTraceResolver ()); return resolver; } diff --git a/src/devices/wifi/wifi-phy.cc b/src/devices/wifi/wifi-phy.cc index 92f857f64..6643acb01 100644 --- a/src/devices/wifi/wifi-phy.cc +++ b/src/devices/wifi/wifi-phy.cc @@ -29,6 +29,7 @@ #include "ns3/random-variable.h" #include "ns3/assert.h" #include "ns3/log.h" +#include "ns3/composite-trace-resolver.h" #include NS_LOG_COMPONENT_DEFINE ("WifiPhy"); @@ -203,6 +204,20 @@ WifiPhy::~WifiPhy () m_modes.clear (); } +Ptr +WifiPhy::GetTraceResolver (void) const +{ + Ptr resolver = + Create (); + resolver->AddSource ("state", + TraceDoc ("The WifiPhy state", + "Time", "start time", + "Time", "duration", + "enum WifiPhy::State", "the state of the PHY layer."), + m_stateLogger); + resolver->SetParentResolver (Object::GetTraceResolver ()); + return resolver; +} void @@ -494,7 +509,7 @@ WifiPhy::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble } char const * -WifiPhy::StateToString (enum WifiPhyState state) +WifiPhy::StateToString (enum State state) { switch (state) { case TX: @@ -514,7 +529,7 @@ WifiPhy::StateToString (enum WifiPhyState state) break; } } -enum WifiPhy::WifiPhyState +enum WifiPhy::State WifiPhy::GetState (void) { if (m_endTx > Simulator::Now ()) @@ -617,9 +632,9 @@ WifiPhy::LogPreviousIdleAndCcaBusyStates (void) m_endCcaBusy > m_endTx) { Time ccaBusyStart = Max (m_endTx, m_endSync); ccaBusyStart = Max (ccaBusyStart, m_startCcaBusy); - m_stateLogger (ccaBusyStart, idleStart - ccaBusyStart, 2); + m_stateLogger (ccaBusyStart, idleStart - ccaBusyStart, WifiPhy::CCA_BUSY); } - m_stateLogger (idleStart, now - idleStart, 3); + m_stateLogger (idleStart, now - idleStart, WifiPhy::IDLE); } void @@ -632,12 +647,12 @@ WifiPhy::SwitchToTx (Time txDuration) * as its endSync event are cancelled by the caller. */ m_syncing = false; - m_stateLogger (m_startSync, now - m_startSync, 1); + m_stateLogger (m_startSync, now - m_startSync, WifiPhy::SYNC); break; case WifiPhy::CCA_BUSY: { Time ccaStart = Max (m_endSync, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); - m_stateLogger (ccaStart, now - ccaStart, 2); + m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); } break; case WifiPhy::IDLE: LogPreviousIdleAndCcaBusyStates (); @@ -646,7 +661,7 @@ WifiPhy::SwitchToTx (Time txDuration) NS_ASSERT (false); break; } - m_stateLogger (now, txDuration, 0); + m_stateLogger (now, txDuration, WifiPhy::TX); m_previousStateChangeTime = now; m_endTx = now + txDuration; m_startTx = now; @@ -664,7 +679,7 @@ WifiPhy::SwitchToSync (Time rxDuration) case WifiPhy::CCA_BUSY: { Time ccaStart = Max (m_endSync, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); - m_stateLogger (ccaStart, now - ccaStart, 2); + m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); } break; case WifiPhy::SYNC: case WifiPhy::TX: @@ -684,7 +699,7 @@ WifiPhy::SwitchFromSync (void) NS_ASSERT (m_syncing); Time now = Simulator::Now (); - m_stateLogger (m_startSync, now - m_startSync, 1); + m_stateLogger (m_startSync, now - m_startSync, WifiPhy::SYNC); m_previousStateChangeTime = now; m_syncing = false; diff --git a/src/devices/wifi/wifi-phy.h b/src/devices/wifi/wifi-phy.h index ccf3cc43c..a19e2ba01 100644 --- a/src/devices/wifi/wifi-phy.h +++ b/src/devices/wifi/wifi-phy.h @@ -72,6 +72,12 @@ public: class WifiPhy : public Object { public: + enum State { + SYNC, + TX, + CCA_BUSY, + IDLE + }; typedef Callback SyncOkCallback; typedef Callback SyncErrorCallback; @@ -105,12 +111,6 @@ public: double CalculateSnr (WifiMode txMode, double ber) const; private: - enum WifiPhyState { - SYNC, - TX, - CCA_BUSY, - IDLE - }; class NiChange { public: NiChange (Time time, double delta); @@ -126,10 +126,12 @@ private: typedef std::list > Events; typedef std::vector NiChanges; -private: +private: + // inherited from ns3::Object. + virtual Ptr GetTraceResolver (void) const; void Configure80211a (void); - char const *StateToString (enum WifiPhyState state); - enum WifiPhyState GetState (void); + char const *StateToString (enum State state); + enum WifiPhy::State GetState (void); double GetEdThresholdW (void) const; double DbmToW (double dbm) const; double DbToRatio (double db) const; @@ -236,12 +238,7 @@ private: * Invoked whenever we send the first bit of a signal. */ CallbackTraceSource m_startTxLogger; - /* 80211-phy-state - * param1: Start - * param2: Duration - * param3: state: 0 -> TX, 1 -> SYNC, 2 -> CCA, 3 -> IDLE - */ - CallbackTraceSource m_stateLogger; + CallbackTraceSource m_stateLogger; }; } // namespace ns3 diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index 3647196bf..47a8e52e2 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -41,4 +41,5 @@ def build(bld): 'wifi-mode.h', 'ssid.h', 'wifi-preamble.h', + 'wifi-phy.h', ]