A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::PcapFileWrapper Class Reference

#include <pcap-file-wrapper.h>

+ Inheritance diagram for ns3::PcapFileWrapper:
+ Collaboration diagram for ns3::PcapFileWrapper:

Public Member Functions

 PcapFileWrapper ()
 ~PcapFileWrapper ()
void Clear (void)
void Close (void)
bool Eof (void) const
bool Fail (void) const
uint32_t GetDataLinkType (void)
uint32_t GetMagic (void)
uint32_t GetSigFigs (void)
uint32_t GetSnapLen (void)
int32_t GetTimeZoneOffset (void)
uint16_t GetVersionMajor (void)
uint16_t GetVersionMinor (void)
void Init (uint32_t dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=PcapFile::ZONE_DEFAULT)
void Open (std::string const &filename, std::ios::openmode mode)
void Write (Time t, Ptr< const Packet > p)
 Write the next packet to file.
void Write (Time t, Header &header, Ptr< const Packet > p)
 Write the provided header along with the packet to the pcap file.
void Write (Time t, uint8_t const *buffer, uint32_t length)
 Write the provided data buffer to the pcap file.
- Public Member Functions inherited from ns3::Object
 Object ()
virtual ~Object ()
void AggregateObject (Ptr< Object > other)
void Dispose (void)
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 Start (void)
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 SimpleRefCount (const SimpleRefCount &o)
uint32_t GetReferenceCount (void) const
SimpleRefCountoperator= (const SimpleRefCount &o)
void Ref (void) const
void Unref (void) const
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
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)
 This method returns the TypeId associated to ns3::PcapFileWrapper.

Private Attributes

PcapFile m_file
uint32_t m_snapLen

Additional Inherited Members

- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
virtual void DoDispose (void)
virtual void DoStart (void)
virtual void NotifyNewAggregate (void)

Detailed Description

Definition at line 39 of file pcap-file-wrapper.h.

Constructor & Destructor Documentation

ns3::PcapFileWrapper::PcapFileWrapper ( )

Definition at line 47 of file pcap-file-wrapper.cc.

ns3::PcapFileWrapper::~PcapFileWrapper ( )

Definition at line 51 of file pcap-file-wrapper.cc.

References Close().

+ Here is the call graph for this function:

Member Function Documentation

void ns3::PcapFileWrapper::Clear ( void  )

Clear all state bits of the underlying iostream.

Definition at line 68 of file pcap-file-wrapper.cc.

References ns3::PcapFile::Clear(), and m_file.

+ Here is the call graph for this function:

void ns3::PcapFileWrapper::Close ( void  )

Close the underlying pcap file.

Definition at line 74 of file pcap-file-wrapper.cc.

References ns3::PcapFile::Close(), and m_file.

Referenced by ~PcapFileWrapper().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::PcapFileWrapper::Eof ( void  ) const
Returns
true if the 'eof' bit is set in the underlying iostream, false otherwise.

Definition at line 63 of file pcap-file-wrapper.cc.

References ns3::PcapFile::Eof(), and m_file.

+ Here is the call graph for this function:

bool ns3::PcapFileWrapper::Fail ( void  ) const
Returns
true if the 'fail' bit is set in the underlying iostream, false otherwise.

Definition at line 58 of file pcap-file-wrapper.cc.

References ns3::PcapFile::Fail(), and m_file.

+ Here is the call graph for this function:

uint32_t ns3::PcapFileWrapper::GetDataLinkType ( void  )

Definition at line 170 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetDataLinkType(), and m_file.

Referenced by ns3::PcapSniffRxEvent(), and ns3::PcapSniffTxEvent().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32_t ns3::PcapFileWrapper::GetMagic ( void  )

Definition at line 134 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetMagic(), and m_file.

+ Here is the call graph for this function:

uint32_t ns3::PcapFileWrapper::GetSigFigs ( void  )

Definition at line 158 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetSigFigs(), and m_file.

+ Here is the call graph for this function:

uint32_t ns3::PcapFileWrapper::GetSnapLen ( void  )

Definition at line 164 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetSnapLen(), and m_file.

+ Here is the call graph for this function:

int32_t ns3::PcapFileWrapper::GetTimeZoneOffset ( void  )

Definition at line 152 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetTimeZoneOffset(), and m_file.

+ Here is the call graph for this function:

TypeId ns3::PcapFileWrapper::GetTypeId ( void  )
static

This method returns the TypeId associated to ns3::PcapFileWrapper.

Attributes defined for this type:

  • CaptureSize: Maximum length of captured packets (cf. pcap snaplen)

No TraceSources defined for this type.

Reimplemented from ns3::Object.

Definition at line 32 of file pcap-file-wrapper.cc.

References m_snapLen, ns3::TypeId::SetParent(), and ns3::PcapFile::SNAPLEN_DEFAULT.

+ Here is the call graph for this function:

uint16_t ns3::PcapFileWrapper::GetVersionMajor ( void  )

Definition at line 140 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetVersionMajor(), and m_file.

+ Here is the call graph for this function:

uint16_t ns3::PcapFileWrapper::GetVersionMinor ( void  )

Definition at line 146 of file pcap-file-wrapper.cc.

References ns3::PcapFile::GetVersionMinor(), and m_file.

+ Here is the call graph for this 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.

Parameters
dataLinkTypeA 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.
snapLenAn optional maximum size for packets written to the file. Defaults to 65535. If packets exceed this length they are truncated.
tzCorrectionAn 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).
Warning
Calling this method on an existing file will result in the loss any existing data.

Definition at line 86 of file pcap-file-wrapper.cc.

References ns3::PcapFile::Init(), m_file, and m_snapLen.

+ Here is the call graph for this 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).

Parameters
filenameString containing the name of the file.
modeString containing the access mode for the file.

Definition at line 80 of file pcap-file-wrapper.cc.

References m_file, and ns3::PcapFile::Open().

+ Here is the call graph for this function:

void ns3::PcapFileWrapper::Write ( Time  t,
Ptr< const Packet p 
)

Write the next packet to file.

Parameters
tPacket timestamp as ns3::Time.
pPacket to write to the pcap file.

Definition at line 104 of file pcap-file-wrapper.cc.

References ns3::Time::GetMicroSeconds(), m_file, and ns3::PcapFile::Write().

Referenced by ns3::Ipv4L3ProtocolRxTxSink(), ns3::Ipv6L3ProtocolRxTxSink(), ns3::PcapSniffRxEvent(), ns3::PcapSniffTxEvent(), and ns3::PcapSniffTxRxEvent().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::PcapFileWrapper::Write ( Time  t,
Header header,
Ptr< const Packet p 
)

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.

Parameters
tPacket timestamp as ns3::Time.
headerThe Header to prepend to the packet.
pPacket to write to the pcap file.

Definition at line 114 of file pcap-file-wrapper.cc.

References ns3::Time::GetMicroSeconds(), m_file, and ns3::PcapFile::Write().

+ Here is the call graph for this function:

void ns3::PcapFileWrapper::Write ( Time  t,
uint8_t const *  buffer,
uint32_t  length 
)

Write the provided data buffer to the pcap file.

Parameters
tPacket timestamp as ns3::Time.
bufferThe buffer to write.
lengthThe size of the buffer.

Definition at line 124 of file pcap-file-wrapper.cc.

References ns3::Time::GetMicroSeconds(), m_file, and ns3::PcapFile::Write().

+ Here is the call graph for this function:

Member Data Documentation

uint32_t ns3::PcapFileWrapper::m_snapLen
private

Definition at line 199 of file pcap-file-wrapper.h.

Referenced by GetTypeId(), and Init().


The documentation for this class was generated from the following files: