9#include "ns3/boolean.h"
10#include "ns3/buffer.h"
11#include "ns3/header.h"
13#include "ns3/uinteger.h"
26 TypeId(
"ns3::PcapFileWrapper")
28 .SetGroupName(
"Network")
30 .AddAttribute(
"CaptureSize",
31 "Maximum length of captured packets (cf. pcap snaplen)",
35 .AddAttribute(
"NanosecMode",
36 "Whether packet timestamps in the PCAP file are nanoseconds or "
37 "microseconds(default).",
99 if (snapLen != std::numeric_limits<uint32_t>::max())
116 uint64_t s = current / 1000000000;
117 uint64_t ns = current % 1000000000;
123 uint64_t s = current / 1000000;
124 uint64_t us = current % 1000000;
136 uint64_t s = current / 1000000000;
137 uint64_t ns = current % 1000000000;
143 uint64_t s = current / 1000000;
144 uint64_t us = current % 1000000;
156 uint64_t s = current / 1000000000;
157 uint64_t ns = current % 1000000000;
163 uint64_t s = current / 1000000;
164 uint64_t us = current % 1000000;
178 uint8_t datbuf[65536];
180 m_file.
Read(datbuf, 65536, tsSec, tsUsec, inclLen, origLen, readLen);
A base class which provides memory management and object aggregation.
bool IsNanoSecMode()
Get the nanosecond mode of the file.
void Close()
Close the underlying file.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
uint32_t GetDataLinkType()
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
uint32_t GetMagic()
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
uint16_t GetVersionMajor()
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
uint16_t GetVersionMinor()
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
void Clear()
Clear all state bits of the underlying iostream.
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false, bool nanosecMode=false)
Initialize the pcap file associated with this object.
void Write(uint32_t tsSec, uint32_t tsUsec, const uint8_t *const data, uint32_t totalLen)
Write next packet to file.
uint32_t GetSnapLen()
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
static const uint32_t SNAPLEN_DEFAULT
Default value for maximum octets to save per packet.
int32_t GetTimeZoneOffset()
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
uint32_t GetSigFigs()
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low...
Ptr< Packet > Read(Time &t)
Read the next packet from the file.
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
static TypeId GetTypeId()
Get the type ID.
PcapFile m_file
Pcap file.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
int32_t GetTimeZoneOffset()
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
uint32_t m_snapLen
max length of saved packets
uint32_t GetSigFigs()
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
void Close()
Close the underlying pcap file.
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 Clear()
Clear all state bits of the underlying iostream.
uint32_t GetMagic()
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
uint16_t GetVersionMajor()
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
~PcapFileWrapper() override
uint32_t GetSnapLen()
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
uint16_t GetVersionMinor()
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
uint32_t GetDataLinkType()
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
bool m_nanosecMode
Timestamps in nanosecond mode.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)