basic pcap output

This commit is contained in:
Mathieu Lacage
2008-03-28 17:35:50 -07:00
parent 62308cf1ce
commit a349c602db
2 changed files with 40 additions and 0 deletions

View File

@@ -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<PcapWriter> writer, Ptr<const Packet> packet,
WifiMode mode, WifiPreamble preamble,
uint8_t txLevel)
{
writer->WritePacket (packet);
}
static void PhyRxEvent (Ptr<PcapWriter> writer,
Ptr<const Packet> 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<PcapWriter> pcap = Create<PcapWriter> ();
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<WifiChannel> channel) const
}
return devices;
}
} // namespace ns3

View File

@@ -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
*