From 9bcf1cdac5084dfbf2da6706d8b20cd89a0fa6bb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 31 Mar 2008 09:34:51 -0700 Subject: [PATCH] add wifi helper tracing. --- src/helper/wifi-helper.cc | 43 +++++++++++++++++++++++++++++++-------- src/helper/wifi-helper.h | 1 + 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index fb05744de..63a997ef9 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -19,20 +19,35 @@ NS_LOG_COMPONENT_DEFINE ("WifiHelper"); namespace ns3 { -static void PhyTxEvent (Ptr writer, Ptr packet, - WifiMode mode, WifiPreamble preamble, - uint8_t txLevel) +static void PcapPhyTxEvent (Ptr writer, Ptr packet, + WifiMode mode, WifiPreamble preamble, + uint8_t txLevel) { writer->WritePacket (packet); } -static void PhyRxEvent (Ptr writer, - Ptr packet, double snr, WifiMode mode, - enum WifiPreamble preamble) +static void PcapPhyRxEvent (Ptr writer, + Ptr packet, double snr, WifiMode mode, + enum WifiPreamble preamble) { writer->WritePacket (packet); } +static void AsciiPhyTxEvent (std::ostream *os, std::string context, + Ptr packet, + WifiMode mode, WifiPreamble preamble, + uint8_t txLevel) +{ + *os << context << " " << *packet << std::endl; +} + +static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, + Ptr packet, double snr, WifiMode mode, + enum WifiPreamble preamble) +{ + *os << context << " " << *packet << std::endl; +} + WifiHelper::WifiHelper () { @@ -120,9 +135,21 @@ WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid pcap->WriteWifiHeader (); oss.str (""); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx"; - Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PhyTxEvent, pcap)); + Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyTxEvent, pcap)); oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk"; - Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PhyRxEvent, pcap)); + Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap)); +} + +void +WifiHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid) +{ + Packet::EnableMetadata (); + std::ostringstream oss; + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk"; + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os)); + oss.str (""); + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx"; + Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os)); } NetDeviceContainer diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index eabab0829..a5539bf81 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -121,6 +121,7 @@ public: static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid); + static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid); /** * \param c a set of nodes