re-enable tracing of wifi phy state.
--- a/examples/wifi-ap.cc Thu Jun 12 11:14:54 2008 -0700
+++ b/examples/wifi-ap.cc Thu Jun 12 11:55:22 2008 -0700
@@ -173,10 +173,10 @@
Config::Connect ("/NodeList/*/DeviceList/*/Tx", MakeCallback (&DevTxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Rx", MakeCallback (&DevRxTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback (&PhyRxOkTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback (&PhyRxErrorTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback (&PhyTxTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/State", MakeCallback (&PhyStateTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", MakeCallback (&PhyRxOkTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&PhyRxErrorTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace));
Simulator::Run ();
--- a/src/devices/wifi/wifi-phy-state-helper.cc Thu Jun 12 11:14:54 2008 -0700
+++ b/src/devices/wifi/wifi-phy-state-helper.cc Thu Jun 12 11:55:22 2008 -0700
@@ -20,11 +20,33 @@
#include "wifi-phy-state-helper.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
+#include "ns3/trace-source-accessor.h"
NS_LOG_COMPONENT_DEFINE ("WifiPhyStateHelper");
namespace ns3 {
+TypeId
+WifiPhyStateHelper::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::WifiPhyStateHelper")
+ .SetParent<Object> ()
+ .AddConstructor<WifiPhyStateHelper> ()
+ .AddTraceSource ("State",
+ "The state of the PHY layer",
+ MakeTraceSourceAccessor (&WifiPhyStateHelper::m_stateLogger))
+ .AddTraceSource ("RxOk",
+ "A packet has been received successfully.",
+ MakeTraceSourceAccessor (&WifiPhyStateHelper::m_rxOkTrace))
+ .AddTraceSource ("RxError",
+ "A packet has been received unsuccessfully.",
+ MakeTraceSourceAccessor (&WifiPhyStateHelper::m_rxErrorTrace))
+ .AddTraceSource ("Tx", "Packet transmission is starting.",
+ MakeTraceSourceAccessor (&WifiPhyStateHelper::m_txTrace))
+ ;
+ return tid;
+}
+
WifiPhyStateHelper::WifiPhyStateHelper ()
: m_syncing (false),
m_endTx (Seconds (0)),
--- a/src/devices/wifi/wifi-phy-state-helper.h Thu Jun 12 11:14:54 2008 -0700
+++ b/src/devices/wifi/wifi-phy-state-helper.h Thu Jun 12 11:55:22 2008 -0700
@@ -22,13 +22,16 @@
#include "wifi-phy.h"
#include "ns3/traced-callback.h"
+#include "ns3/object.h"
#include <vector>
namespace ns3 {
-class WifiPhyStateHelper
+class WifiPhyStateHelper : public Object
{
public:
+ static TypeId GetTypeId (void);
+
WifiPhyStateHelper ();
void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback);
@@ -50,6 +53,7 @@
void SwitchFromSyncEndError (Ptr<const Packet> packet, double snr);
void SwitchMaybeToCcaBusy (Time duration);
+ TracedCallback<Time,Time,enum WifiPhy::State> m_stateLogger;
private:
typedef std::vector<WifiPhyListener *> Listeners;
@@ -72,7 +76,7 @@
Time m_startSync;
Time m_startCcaBusy;
Time m_previousStateChangeTime;
- TracedCallback<Time,Time,enum WifiPhy::State> m_stateLogger;
+
Listeners m_listeners;
TracedCallback<Ptr<const Packet>, double, WifiMode, enum WifiPreamble> m_rxOkTrace;
TracedCallback<Ptr<const Packet>, double> m_rxErrorTrace;
--- a/src/devices/wifi/yans-wifi-phy.cc Thu Jun 12 11:14:54 2008 -0700
+++ b/src/devices/wifi/yans-wifi-phy.cc Thu Jun 12 11:55:22 2008 -0700
@@ -19,9 +19,10 @@
*/
#include "yans-wifi-phy.h"
+#include "yans-wifi-channel.h"
#include "wifi-mode.h"
-#include "yans-wifi-channel.h"
#include "wifi-preamble.h"
+#include "wifi-phy-state-helper.h"
#include "ns3/simulator.h"
#include "ns3/packet.h"
#include "ns3/random-variable.h"
@@ -30,7 +31,7 @@
#include "ns3/double.h"
#include "ns3/uinteger.h"
#include "ns3/enum.h"
-#include "ns3/trace-source-accessor.h"
+#include "ns3/pointer.h"
#include <math.h>
NS_LOG_COMPONENT_DEFINE ("YansWifiPhy");
@@ -197,19 +198,10 @@
MakeEnumAccessor (&YansWifiPhy::SetStandard),
MakeEnumChecker (WIFI_PHY_STANDARD_80211a, "802.11a",
WIFI_PHY_STANDARD_holland, "holland"))
-#if 0
- .AddTraceSource ("State",
- "The YansWifiPhy state",
- MakeTraceSourceAccessor (&YansWifiPhy::m_stateLogger))
- .AddTraceSource ("RxOk",
- "A packet has been received successfully.",
- MakeTraceSourceAccessor (&YansWifiPhy::m_rxOkTrace))
- .AddTraceSource ("RxError",
- "A packet has been received unsuccessfully.",
- MakeTraceSourceAccessor (&YansWifiPhy::m_rxErrorTrace))
- .AddTraceSource ("Tx", "Packet transmission is starting.",
- MakeTraceSourceAccessor (&YansWifiPhy::m_txTrace))
-#endif
+ .AddAttribute ("State", "The state of the PHY layer",
+ PointerValue (),
+ MakePointerAccessor (&YansWifiPhy::m_state),
+ MakePointerChecker<WifiPhyStateHelper> ())
;
return tid;
}
@@ -219,6 +211,7 @@
m_random (0.0, 1.0)
{
NS_LOG_FUNCTION (this);
+ m_state = CreateObject<WifiPhyStateHelper> ();
}
YansWifiPhy::~YansWifiPhy ()
@@ -343,12 +336,12 @@
void
YansWifiPhy::SetReceiveOkCallback (SyncOkCallback callback)
{
- m_state.SetReceiveOkCallback (callback);
+ m_state->SetReceiveOkCallback (callback);
}
void
YansWifiPhy::SetReceiveErrorCallback (SyncErrorCallback callback)
{
- m_state.SetReceiveErrorCallback (callback);
+ m_state->SetReceiveErrorCallback (callback);
}
void
YansWifiPhy::StartReceivePacket (Ptr<Packet> packet,
@@ -369,11 +362,11 @@
rxPowerW);
AppendEvent (event);
- switch (m_state.GetState ()) {
+ switch (m_state->GetState ()) {
case YansWifiPhy::SYNC:
NS_LOG_DEBUG ("drop packet because already in Sync (power="<<
rxPowerW<<"W)");
- if (endRx > Simulator::Now () + m_state.GetDelayUntilIdle ())
+ if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
{
// that packet will be noise _after_ the reception of the
// currently-received packet.
@@ -383,7 +376,7 @@
case YansWifiPhy::TX:
NS_LOG_DEBUG ("drop packet because already in Tx (power="<<
rxPowerW<<"W)");
- if (endRx > Simulator::Now () + m_state.GetDelayUntilIdle ())
+ if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
{
// that packet will be noise _after_ the transmission of the
// currently-transmitted packet.
@@ -396,7 +389,7 @@
{
NS_LOG_DEBUG ("sync (power="<<rxPowerW<<"W)");
// sync to signal
- m_state.SwitchToSync (rxDuration);
+ m_state->SwitchToSync (rxDuration);
NS_ASSERT (m_endSyncEvent.IsExpired ());
m_endSyncEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndSync, this,
packet,
@@ -417,7 +410,7 @@
if (rxPowerW > m_edThresholdW)
{
- m_state.SwitchMaybeToCcaBusy (rxDuration);
+ m_state->SwitchMaybeToCcaBusy (rxDuration);
}
else
{
@@ -438,7 +431,7 @@
if (end > Simulator::Now ())
{
Time delta = end - Simulator::Now ();
- m_state.SwitchMaybeToCcaBusy (delta);
+ m_state->SwitchMaybeToCcaBusy (delta);
}
}
@@ -453,14 +446,14 @@
* prevent it.
* - we are idle
*/
- NS_ASSERT (!m_state.IsStateTx ());
+ NS_ASSERT (!m_state->IsStateTx ());
Time txDuration = CalculateTxDuration (packet->GetSize (), txMode, preamble);
- if (m_state.IsStateSync ())
+ if (m_state->IsStateSync ())
{
m_endSyncEvent.Cancel ();
}
- m_state.SwitchToTx (txDuration, packet, txMode, preamble, txPower);
+ m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
m_channel->Send (this, packet, GetPowerDbm (txPower) + m_txGainDb, txMode, preamble);
}
@@ -567,51 +560,51 @@
void
YansWifiPhy::RegisterListener (WifiPhyListener *listener)
{
- m_state.RegisterListener (listener);
+ m_state->RegisterListener (listener);
}
bool
YansWifiPhy::IsStateCcaBusy (void)
{
- return m_state.IsStateCcaBusy ();
+ return m_state->IsStateCcaBusy ();
}
bool
YansWifiPhy::IsStateIdle (void)
{
- return m_state.IsStateIdle ();
+ return m_state->IsStateIdle ();
}
bool
YansWifiPhy::IsStateBusy (void)
{
- return m_state.IsStateBusy ();
+ return m_state->IsStateBusy ();
}
bool
YansWifiPhy::IsStateSync (void)
{
- return m_state.IsStateSync ();
+ return m_state->IsStateSync ();
}
bool
YansWifiPhy::IsStateTx (void)
{
- return m_state.IsStateTx ();
+ return m_state->IsStateTx ();
}
Time
YansWifiPhy::GetStateDuration (void)
{
- return m_state.GetStateDuration ();
+ return m_state->GetStateDuration ();
}
Time
YansWifiPhy::GetDelayUntilIdle (void)
{
- return m_state.GetDelayUntilIdle ();
+ return m_state->GetDelayUntilIdle ();
}
Time
YansWifiPhy::GetLastRxStartTime (void) const
{
- return m_state.GetLastRxStartTime ();
+ return m_state->GetLastRxStartTime ();
}
@@ -1126,12 +1119,12 @@
if (m_random.GetValue () > per)
{
- m_state.SwitchFromSyncEndOk (packet, snr, event->GetPayloadMode (), event->GetPreambleType ());
+ m_state->SwitchFromSyncEndOk (packet, snr, event->GetPayloadMode (), event->GetPreambleType ());
}
else
{
/* failure. */
- m_state.SwitchFromSyncEndError (packet, snr);
+ m_state->SwitchFromSyncEndError (packet, snr);
}
}
--- a/src/devices/wifi/yans-wifi-phy.h Thu Jun 12 11:14:54 2008 -0700
+++ b/src/devices/wifi/yans-wifi-phy.h Thu Jun 12 11:55:22 2008 -0700
@@ -36,7 +36,6 @@
#include "wifi-mode.h"
#include "wifi-preamble.h"
#include "wifi-phy-standard.h"
-#include "wifi-phy-state-helper.h"
namespace ns3 {
@@ -44,6 +43,7 @@
class RandomUniform;
class RxEvent;
class YansWifiChannel;
+class WifiPhyStateHelper;
/**
@@ -180,15 +180,13 @@
double m_txPowerEndDbm;
uint32_t m_nTxPower;
-
-
Ptr<YansWifiChannel> m_channel;
Modes m_modes;
EventId m_endSyncEvent;
Events m_events;
UniformVariable m_random;
WifiPhyStandard m_standard;
- WifiPhyStateHelper m_state;
+ Ptr<WifiPhyStateHelper> m_state;
};
} // namespace ns3
--- a/src/helper/wifi-helper.cc Thu Jun 12 11:14:54 2008 -0700
+++ b/src/helper/wifi-helper.cc Thu Jun 12 11:55:22 2008 -0700
@@ -137,10 +137,10 @@
pcap->Open (oss.str ());
pcap->WriteWifiHeader ();
oss.str ("");
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx";
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyTxEvent, pcap));
oss.str ("");
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk";
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap));
}
void
@@ -178,10 +178,10 @@
{
Packet::EnableMetadata ();
std::ostringstream oss;
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk";
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os));
oss.str ("");
- oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx";
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
}
void