diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index 76926b718..fb05744de 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -8,11 +8,32 @@ #include "ns3/propagation-loss-model.h" #include "ns3/mobility-model.h" #include "ns3/log.h" +#include "ns3/pcap-writer.h" +#include "ns3/wifi-mode.h" +#include "ns3/wifi-preamble.h" +#include "ns3/config.h" + + NS_LOG_COMPONENT_DEFINE ("WifiHelper"); namespace ns3 { +static void PhyTxEvent (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) +{ + writer->WritePacket (packet); +} + + WifiHelper::WifiHelper () { m_stationManager.SetTypeId ("ns3::ArfWifiManager"); @@ -89,6 +110,21 @@ WifiHelper::SetPhy (std::string type, m_phy.Set (n7, v7); } +void +WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid) +{ + std::ostringstream oss; + oss << filename << "-" << nodeid << "-" << deviceid; + Ptr pcap = Create (); + pcap->Open (oss.str ()); + pcap->WriteWifiHeader (); + oss.str (""); + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx"; + Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PhyTxEvent, pcap)); + oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk"; + Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PhyRxEvent, pcap)); +} + NetDeviceContainer WifiHelper::Build (NodeContainer c) const { @@ -121,4 +157,5 @@ WifiHelper::Build (NodeContainer c, Ptr channel) const } return devices; } + } // namespace ns3 diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index 1481202e5..eabab0829 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -119,6 +119,9 @@ public: std::string n6 = "", Attribute v6 = Attribute (), std::string n7 = "", Attribute v7 = Attribute ()); + + static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid); + /** * \param c a set of nodes *