Manage pcap files for device models. More...
#include "trace-helper.h"
Public Types | |
enum | DataLinkType { DLT_NULL = 0 , DLT_EN10MB = 1 , DLT_PPP = 9 , DLT_RAW = 101 , DLT_IEEE802_11 = 105 , DLT_LINUX_SLL = 113 , DLT_PRISM_HEADER = 119 , DLT_IEEE802_11_RADIO = 127 , DLT_IEEE802_15_4 = 195 , DLT_NETLINK = 253 , DLT_LORATAP = 270 } |
This enumeration holds the data link types that will be written to the pcap file. More... | |
Public Member Functions | |
PcapHelper () | |
Create a pcap helper. More... | |
~PcapHelper () | |
Destroy a pcap helper. More... | |
Ptr< PcapFileWrapper > | CreateFile (std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0) |
Create and initialize a pcap file. More... | |
std::string | GetFilenameFromDevice (std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true) |
Let the pcap helper figure out a reasonable filename to use for a pcap file associated with a device. More... | |
std::string | GetFilenameFromInterfacePair (std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true) |
Let the pcap helper figure out a reasonable filename to use for the pcap file associated with a node. More... | |
template<typename T > | |
void | HookDefaultSink (Ptr< T > object, std::string traceName, Ptr< PcapFileWrapper > file) |
Hook a trace source to the default trace sink. More... | |
Static Private Member Functions | |
static void | DefaultSink (Ptr< PcapFileWrapper > file, Ptr< const Packet > p) |
The basic default trace sink. More... | |
static void | SinkWithHeader (Ptr< PcapFileWrapper > file, const Header &header, Ptr< const Packet > p) |
This trace sink passes a header separately from the packet to prevent creating a new packet (for performance reasons) More... | |
Manage pcap files for device models.
Handling pcap files is a common operation for ns-3 devices. It is useful to provide a common base class for dealing with these ops.
Definition at line 38 of file trace-helper.h.
This enumeration holds the data link types that will be written to the pcap file.
We don't include pcap-bpf.h to avoid an explicit dependency on the real pcap and we don't make an enumeration of all of the values to make it easy to pass new values in.
For a list of Data Link Types see http://www.tcpdump.org/linktypes.html
Enumerator | |
---|---|
DLT_NULL | |
DLT_EN10MB | |
DLT_PPP | |
DLT_RAW | |
DLT_IEEE802_11 | |
DLT_LINUX_SLL | |
DLT_PRISM_HEADER | |
DLT_IEEE802_11_RADIO | |
DLT_IEEE802_15_4 | |
DLT_NETLINK | |
DLT_LORATAP |
Definition at line 50 of file trace-helper.h.
ns3::PcapHelper::PcapHelper | ( | ) |
Create a pcap helper.
Definition at line 38 of file trace-helper.cc.
References NS_LOG_FUNCTION_NOARGS.
ns3::PcapHelper::~PcapHelper | ( | ) |
Destroy a pcap helper.
Definition at line 43 of file trace-helper.cc.
References NS_LOG_FUNCTION_NOARGS.
Ptr< PcapFileWrapper > ns3::PcapHelper::CreateFile | ( | std::string | filename, |
std::ios::openmode | filemode, | ||
DataLinkType | dataLinkType, | ||
uint32_t | snapLen = std::numeric_limits<uint32_t>::max () , |
||
int32_t | tzCorrection = 0 |
||
) |
Create and initialize a pcap file.
filename | file name |
filemode | file mode |
dataLinkType | data link type of packet data |
snapLen | maximum length of packet data stored in records |
tzCorrection | time zone correction to be applied to timestamps of packets |
Definition at line 49 of file trace-helper.cc.
References create-module::file, NS_ABORT_MSG_IF, and NS_LOG_FUNCTION.
Referenced by ns3::WimaxHelper::EnablePcapInternal(), ns3::CsmaHelper::EnablePcapInternal(), ns3::FdNetDeviceHelper::EnablePcapInternal(), ns3::LrWpanHelper::EnablePcapInternal(), ns3::PointToPointHelper::EnablePcapInternal(), ns3::YansWavePhyHelper::EnablePcapInternal(), ns3::WifiPhyHelper::EnablePcapInternal(), ns3::InternetStackHelper::EnablePcapIpv4Internal(), and ns3::InternetStackHelper::EnablePcapIpv6Internal().
|
staticprivate |
The basic default trace sink.
This one just writes the packet to the pcap file which is good enough for most kinds of captures.
file | the file to write to |
p | the packet to write |
Definition at line 167 of file trace-helper.cc.
References create-module::file, ns3::Simulator::Now(), and NS_LOG_FUNCTION.
Referenced by HookDefaultSink().
std::string ns3::PcapHelper::GetFilenameFromDevice | ( | std::string | prefix, |
Ptr< NetDevice > | device, | ||
bool | useObjectNames = true |
||
) |
Let the pcap helper figure out a reasonable filename to use for a pcap file associated with a device.
prefix | prefix string |
device | NetDevice |
useObjectNames | use node and device names instead of indexes |
Definition at line 80 of file trace-helper.cc.
References ns3::Names::FindName(), ns3::Node::GetId(), ns3::NetDevice::GetIfIndex(), ns3::NetDevice::GetNode(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
Referenced by ns3::WimaxHelper::EnablePcapInternal(), ns3::CsmaHelper::EnablePcapInternal(), ns3::FdNetDeviceHelper::EnablePcapInternal(), ns3::LrWpanHelper::EnablePcapInternal(), ns3::PointToPointHelper::EnablePcapInternal(), ns3::YansWavePhyHelper::EnablePcapInternal(), and ns3::WifiPhyHelper::EnablePcapInternal().
std::string ns3::PcapHelper::GetFilenameFromInterfacePair | ( | std::string | prefix, |
Ptr< Object > | object, | ||
uint32_t | interface, | ||
bool | useObjectNames = true |
||
) |
Let the pcap helper figure out a reasonable filename to use for the pcap file associated with a node.
prefix | prefix string |
object | interface (such as Ipv4Interface or Ipv6Interface) |
interface | interface id |
useObjectNames | use node and device names instead of indexes |
Definition at line 125 of file trace-helper.cc.
References ns3::Names::FindName(), ns3::Node::GetId(), ns3::Object::GetObject(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
Referenced by ns3::InternetStackHelper::EnablePcapIpv4Internal(), and ns3::InternetStackHelper::EnablePcapIpv6Internal().
void ns3::PcapHelper::HookDefaultSink | ( | Ptr< T > | object, |
std::string | traceName, | ||
Ptr< PcapFileWrapper > | file | ||
) |
Hook a trace source to the default trace sink.
object | object |
traceName | trace source name |
file | file wrapper |
Definition at line 148 of file trace-helper.h.
References DefaultSink(), create-module::file, ns3::MakeBoundCallback(), NS_ASSERT_MSG, and test-ns3::result.
Referenced by ns3::CsmaHelper::EnablePcapInternal(), ns3::FdNetDeviceHelper::EnablePcapInternal(), and ns3::PointToPointHelper::EnablePcapInternal().
|
staticprivate |
This trace sink passes a header separately from the packet to prevent creating a new packet (for performance reasons)
file | the file to write to |
header | header of the packet |
p | the packet to write |
Definition at line 174 of file trace-helper.cc.
References create-module::file, ns3::Simulator::Now(), and NS_LOG_FUNCTION.