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 () override | |
void | Clear () |
Clear all state bits of the underlying iostream. | |
void | Close () |
Close the underlying pcap file. | |
bool | Eof () const |
bool | Fail () const |
uint32_t | GetDataLinkType () |
Returns the data link type field of the pcap file as defined by the network field in the pcap global header. | |
uint32_t | GetMagic () |
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global header. | |
uint32_t | GetSigFigs () |
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap global header. | |
uint32_t | GetSnapLen () |
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the pcap global header. | |
int32_t | GetTimeZoneOffset () |
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global header. | |
uint16_t | GetVersionMajor () |
Returns the major version of the pcap file as defined by the version_major field in the pcap global header. | |
uint16_t | GetVersionMinor () |
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global header. | |
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. | |
void | Open (const std::string &filename, std::ios::openmode mode) |
Create a new pcap file or open an existing pcap file. | |
Ptr< Packet > | Read (Time &t) |
Read the next packet from the file. | |
void | Write (Time t, const Header &header, Ptr< const Packet > p) |
Write the provided header along with the packet to the pcap file. | |
void | Write (Time t, const uint8_t *buffer, uint32_t length) |
Write the provided data buffer to the pcap file. | |
void | Write (Time t, Ptr< const Packet > p) |
Write the next packet to file. | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. | |
~Object () override | |
Destructor. | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. | |
void | Dispose () |
Dispose of this Object. | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. | |
bool | IsInitialized () const |
Check if the object has been initialized. | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. | |
void | GetAttribute (std::string name, AttributeValue &value) const |
Get the value of an attribute, raising fatal errors if unsuccessful. | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. | |
virtual TypeId | GetInstanceTypeId () const =0 |
Get the most derived TypeId for this Object. | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Get the type ID. | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. | |
Private Attributes | |
PcapFile | m_file |
Pcap file. | |
bool | m_nanosecMode |
Timestamps in nanosecond mode. | |
uint32_t | m_snapLen |
max length of saved packets | |
Additional Inherited Members | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. | |
virtual void | DoDispose () |
Destructor implementation. | |
virtual void | DoInitialize () |
Initialize() implementation. | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. | |
Related Functions inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
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.
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.
Size of this type is 608 bytes (on a 64-bit architecture).
Definition at line 41 of file pcap-file-wrapper.h.
ns3::PcapFileWrapper::PcapFileWrapper | ( | ) |
Definition at line 55 of file pcap-file-wrapper.cc.
References NS_LOG_FUNCTION.
|
override |
Definition at line 60 of file pcap-file-wrapper.cc.
References Close(), and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Clear | ( | ) |
Clear all state bits of the underlying iostream.
Definition at line 81 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Clear(), m_file, and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Close | ( | ) |
Close the underlying pcap file.
Definition at line 88 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Close(), m_file, and NS_LOG_FUNCTION.
Referenced by ~PcapFileWrapper().
bool ns3::PcapFileWrapper::Eof | ( | ) | const |
Definition at line 74 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Eof(), m_file, and NS_LOG_FUNCTION.
bool ns3::PcapFileWrapper::Fail | ( | ) | const |
Definition at line 67 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Fail(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetDataLinkType | ( | ) |
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 253 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetDataLinkType(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetMagic | ( | ) |
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 211 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetMagic(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetSigFigs | ( | ) |
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 239 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetSigFigs(), m_file, and NS_LOG_FUNCTION.
uint32_t ns3::PcapFileWrapper::GetSnapLen | ( | ) |
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 246 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetSnapLen(), m_file, and NS_LOG_FUNCTION.
int32_t ns3::PcapFileWrapper::GetTimeZoneOffset | ( | ) |
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 232 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetTimeZoneOffset(), m_file, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 34 of file pcap-file-wrapper.cc.
References m_nanosecMode, m_snapLen, ns3::MakeBooleanAccessor(), ns3::MakeBooleanChecker(), ns3::MakeUintegerAccessor(), ns3::TypeId::SetParent(), and ns3::PcapFile::SNAPLEN_DEFAULT.
uint16_t ns3::PcapFileWrapper::GetVersionMajor | ( | ) |
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 218 of file pcap-file-wrapper.cc.
References ns3::PcapFile::GetVersionMajor(), m_file, and NS_LOG_FUNCTION.
uint16_t ns3::PcapFileWrapper::GetVersionMinor | ( | ) |
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 225 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 102 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Init(), m_file, m_nanosecMode, m_snapLen, and NS_LOG_FUNCTION.
void ns3::PcapFileWrapper::Open | ( | const std::string & | 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 95 of file pcap-file-wrapper.cc.
References m_file, NS_LOG_FUNCTION, and ns3::PcapFile::Open().
Read the next packet from the file.
t | Reference to packet timestamp as ns3::Time. |
Definition at line 181 of file pcap-file-wrapper.cc.
References ns3::PcapFile::Fail(), ns3::PcapFile::IsNanoSecMode(), m_file, ns3::MicroSeconds(), ns3::NanoSeconds(), and ns3::PcapFile::Read().
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 141 of file pcap-file-wrapper.cc.
References ns3::Time::GetMicroSeconds(), ns3::Time::GetNanoSeconds(), ns3::PcapFile::IsNanoSecMode(), m_file, NS_LOG_FUNCTION, and ns3::PcapFile::Write().
Write the provided data buffer to the pcap file.
Definition at line 161 of file pcap-file-wrapper.cc.
References ns3::Time::GetMicroSeconds(), ns3::Time::GetNanoSeconds(), ns3::PcapFile::IsNanoSecMode(), m_file, NS_LOG_FUNCTION, and ns3::PcapFile::Write().
Write the next packet to file.
Definition at line 121 of file pcap-file-wrapper.cc.
References ns3::Time::GetMicroSeconds(), ns3::Time::GetNanoSeconds(), ns3::PcapFile::IsNanoSecMode(), m_file, NS_LOG_FUNCTION, and ns3::PcapFile::Write().
|
private |
Pcap file.
Definition at line 225 of file pcap-file-wrapper.h.
Referenced by Clear(), Close(), Eof(), Fail(), GetDataLinkType(), GetMagic(), GetSigFigs(), GetSnapLen(), GetTimeZoneOffset(), GetVersionMajor(), GetVersionMinor(), Init(), Open(), Read(), and Write().
|
private |
Timestamps in nanosecond mode.
Definition at line 227 of file pcap-file-wrapper.h.
Referenced by GetTypeId(), and Init().
|
private |
max length of saved packets
Definition at line 226 of file pcap-file-wrapper.h.
Referenced by GetTypeId(), and Init().