A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low-level public methods of PcapFile. More...
#include <pcap-file-wrapper.h>
Public Member Functions | |
PcapFileWrapper () | |
~PcapFileWrapper () | |
void | Clear (void) |
Clear all state bits of the underlying iostream. More... | |
void | Close (void) |
Close the underlying pcap file. More... | |
bool | Eof (void) const |
bool | Fail (void) const |
uint32_t | GetDataLinkType (void) |
Returns the data link type field of the pcap file as defined by the network field in the pcap global header. More... | |
uint32_t | GetMagic (void) |
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global header. More... | |
uint32_t | GetSigFigs (void) |
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap global header. More... | |
uint32_t | GetSnapLen (void) |
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the pcap global header. More... | |
int32_t | GetTimeZoneOffset (void) |
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global header. More... | |
uint16_t | GetVersionMajor (void) |
Returns the major version of the pcap file as defined by the version_major field in the pcap global header. More... | |
uint16_t | GetVersionMinor (void) |
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global header. More... | |
void | Init (uint32_t dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=PcapFile::ZONE_DEFAULT) |
Initialize the pcap file associated with this wrapper. More... | |
void | Open (std::string const &filename, std::ios::openmode mode) |
Create a new pcap file or open an existing pcap file. More... | |
void | Write (Time t, Ptr< const Packet > p) |
Write the next packet to file. More... | |
void | Write (Time t, Header &header, Ptr< const Packet > p) |
Write the provided header along with the packet to the pcap file. More... | |
void | Write (Time t, uint8_t const *buffer, uint32_t length) |
Write the provided data buffer to the pcap file. More... | |
![]() | |
Object () | |
virtual | ~Object () |
void | AggregateObject (Ptr< Object > other) |
void | Dispose (void) |
Run the DoDispose methods of this object and all the objects aggregated to it. More... | |
AggregateIterator | GetAggregateIterator (void) const |
virtual TypeId | GetInstanceTypeId (void) const |
template<typename T > | |
Ptr< T > | GetObject (void) const |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
void | Initialize (void) |
This method calls the virtual DoInitialize method on all the objects aggregated to this object. More... | |
![]() | |
SimpleRefCount () | |
Constructor. More... | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount (void) const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment. More... | |
void | Ref (void) const |
Increment the reference count. More... | |
void | Unref (void) const |
Decrement the reference count. More... | |
![]() | |
virtual | ~ObjectBase () |
Virtual destructor. More... | |
void | GetAttribute (std::string name, AttributeValue &value) const |
bool | GetAttributeFailSafe (std::string name, AttributeValue &attribute) const |
void | SetAttribute (std::string name, const AttributeValue &value) |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
![]() | |
static TypeId | GetTypeId (void) |
Register this type. More... | |
![]() | |
static void | Cleanup (void) |
Noop. More... | |
![]() | |
static TypeId | GetTypeId (void) |
Get the type ID. More... | |
Private Attributes | |
PcapFile | m_file |
Pcap file. More... | |
uint32_t | m_snapLen |
max length of saved packets More... | |
Additional Inherited Members | |
![]() | |
Object (const Object &o) | |
virtual void | DoDispose (void) |
This method is called by Object::Dispose or by the object's destructor, whichever comes first. More... | |
virtual void | DoInitialize (void) |
This method is called only once by Object::Initialize. More... | |
virtual void | NotifyNewAggregate (void) |
This method is invoked whenever two sets of objects are aggregated together. More... | |
![]() | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
virtual void | NotifyConstructionCompleted (void) |
This method is invoked once all member attributes have been initialized. More... | |
A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low-level public methods of PcapFile.
Doxygen introspection did not find any typical Config paths.
Users are encouraged to use this object instead of class ns3::PcapFile in ns-3 public APIs.
No TraceSources are defined for this type.
Definition at line 39 of file pcap-file-wrapper.h.
ns3::PcapFileWrapper::PcapFileWrapper | ( | ) |
Definition at line 47 of file pcap-file-wrapper.cc.
References NS_LOG_FUNCTION.
ns3::PcapFileWrapper::~PcapFileWrapper | ( | ) |
Definition at line 52 of file pcap-file-wrapper.cc.
References Close(), and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Clear | ( | void | ) |
Clear all state bits of the underlying iostream.
Definition at line 72 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Clear(), m_file, and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Close | ( | void | ) |
Close the underlying pcap file.
Definition at line 79 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Close(), m_file, and NS_LOG_FUNCTION.
Referenced by ~PcapFileWrapper().
bool ns3::PcapFileWrapper::Eof | ( | void | ) | const |
Definition at line 66 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Eof(), m_file, and NS_LOG_FUNCTION.
bool ns3::PcapFileWrapper::Fail | ( | void | ) | const |
Definition at line 60 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Fail(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetDataLinkType | ( | void | ) |
Returns the data link type field of the pcap file as defined by the network field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 187 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetDataLinkType(), m_file, and NS_LOG_FUNCTION.
Referenced by ns3::PcapSniffRxEvent(), and ns3::PcapSniffTxEvent().
uint32_t ns3::PcapFileWrapper::GetMagic | ( | void | ) |
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 145 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetMagic(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetSigFigs | ( | void | ) |
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 173 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetSigFigs(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetSnapLen | ( | void | ) |
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 180 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetSnapLen(), m_file, and NS_LOG_FUNCTION.
int32_t ns3::PcapFileWrapper::GetTimeZoneOffset | ( | void | ) |
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 166 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetTimeZoneOffset(), m_file, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 32 of file pcap-file-wrapper.cc.
References m_snapLen, ns3::TypeId::SetParent(), and ns3::PcapFile::SNAPLEN_DEFAULT.
uint16_t ns3::PcapFileWrapper::GetVersionMajor | ( | void | ) |
Returns the major version of the pcap file as defined by the version_major field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 152 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetVersionMajor(), m_file, and NS_LOG_FUNCTION.
uint16_t ns3::PcapFileWrapper::GetVersionMinor | ( | void | ) |
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global header.
See http://wiki.wireshark.org/Development/LibpcapFileFormat
Definition at line 159 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetVersionMinor(), m_file, and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Init | ( | uint32_t | dataLinkType, |
uint32_t | snapLen = std::numeric_limits<uint32_t>::max () , |
||
int32_t | tzCorrection = PcapFile::ZONE_DEFAULT |
||
) |
Initialize the pcap file associated with this wrapper.
This file must have been previously opened with write permissions.
dataLinkType | A data link type as defined in the pcap library. If you want to make resulting pcap files visible in existing tools, the data link type must match existing definitions, such as PCAP_ETHERNET, PCAP_PPP, PCAP_80211, etc. If you are storing different kinds of packet data, such as naked TCP headers, you are at liberty to locally define your own data link types. According to the pcap-linktype man page, "well-known" pcap linktypes range from 0 to 177. If you use a large random number for your type, chances are small for a collision. |
snapLen | An optional maximum size for packets written to the file. Defaults to 65535. If packets exceed this length they are truncated. |
tzCorrection | An integer describing the offset of your local time zone from UTC/GMT. For example, Pacific Standard Time in the US is GMT-8, so one would enter -8 for that correction. Defaults to 0 (UTC). |
Definition at line 93 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Init(), m_file, m_snapLen, and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Open | ( | std::string const & | filename, |
std::ios::openmode | mode | ||
) |
Create a new pcap file or open an existing pcap file.
Semantics are similar to the stdc++ io stream classes.
Since a pcap file is always a binary file, the file type is automatically selected as a binary file (fstream::binary is automatically ored with the mode field).
filename | String containing the name of the file. |
mode | String containing the access mode for the file. |
Definition at line 86 of file pcap-file-wrapper.cc.
References m_file, NS_LOG_FUNCTION, and ns3::PcapFile::Open().
Write the next packet to file.
Definition at line 112 of file pcap-file-wrapper.cc.
References current, ns3::Time::GetMicroSeconds(), m_file, NS_LOG_FUNCTION, s, and ns3::PcapFile::Write().
Referenced by ns3::Ipv4L3ProtocolRxTxSink(), ns3::Ipv6L3ProtocolRxTxSink(), ns3::PcapSniffLrWpan(), ns3::PcapSniffRxEvent(), ns3::PcapSniffTxEvent(), ns3::PcapSniffTxRxEvent(), and RxDrop().
Write the provided header along with the packet to the pcap file.
It is the case that adding a header to a packet prior to writing it to a file must trigger a deep copy in the Packet. By providing the header separately, we can avoid that copy.
t | Packet timestamp as ns3::Time. |
header | The Header to prepend to the packet. |
p | Packet to write to the pcap file. |
Definition at line 123 of file pcap-file-wrapper.cc.
References current, ns3::Time::GetMicroSeconds(), m_file, NS_LOG_FUNCTION, s, and ns3::PcapFile::Write().
void ns3::PcapFileWrapper::Write | ( | Time | t, |
uint8_t const * | buffer, | ||
uint32_t | length | ||
) |
Write the provided data buffer to the pcap file.
Definition at line 134 of file pcap-file-wrapper.cc.
References current, ns3::Time::GetMicroSeconds(), m_file, NS_LOG_FUNCTION, s, and ns3::PcapFile::Write().
|
private |
Pcap file.
Definition at line 216 of file pcap-file-wrapper.h.
Referenced by Clear(), Close(), Eof(), Fail(), GetDataLinkType(), GetMagic(), GetSigFigs(), GetSnapLen(), GetTimeZoneOffset(), GetVersionMajor(), GetVersionMinor(), Init(), Open(), and Write().
|
private |
max length of saved packets
Definition at line 217 of file pcap-file-wrapper.h.
Referenced by GetTypeId(), and Init().