A Discrete-Event Network Simulator
API
pcap-file-wrapper.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef PCAP_FILE_WRAPPER_H
20 #define PCAP_FILE_WRAPPER_H
21 
22 #include <cstring>
23 #include <limits>
24 #include <fstream>
25 #include "ns3/ptr.h"
26 #include "ns3/packet.h"
27 #include "ns3/object.h"
28 #include "ns3/nstime.h"
29 #include "pcap-file.h"
30 
31 namespace ns3 {
32 
39 class PcapFileWrapper : public Object
40 {
41 public:
46  static TypeId GetTypeId (void);
47 
48  PcapFileWrapper ();
50 
51 
55  bool Fail (void) const;
59  bool Eof (void) const;
63  void Clear (void);
64 
78  void Open (std::string const &filename, std::ios::openmode mode);
79 
83  void Close (void);
84 
108  void Init (uint32_t dataLinkType,
109  uint32_t snapLen = std::numeric_limits<uint32_t>::max (),
110  int32_t tzCorrection = PcapFile::ZONE_DEFAULT);
111 
119  void Write (Time t, Ptr<const Packet> p);
120 
133  void Write (Time t, const Header &header, Ptr<const Packet> p);
134 
143  void Write (Time t, uint8_t const *buffer, uint32_t length);
144 
151  Ptr<Packet> Read (Time &t);
152 
161  uint32_t GetMagic (void);
162 
171  uint16_t GetVersionMajor (void);
172 
181  uint16_t GetVersionMinor (void);
182 
191  int32_t GetTimeZoneOffset (void);
192 
201  uint32_t GetSigFigs (void);
202 
211  uint32_t GetSnapLen (void);
212 
221  uint32_t GetDataLinkType (void);
222 
223 private:
225  uint32_t m_snapLen;
227 };
228 
229 } // namespace ns3
230 
231 #endif /* PCAP_FILE_WRAPPER_H */
pcap-file.h
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::PcapFileWrapper::~PcapFileWrapper
~PcapFileWrapper()
Definition: pcap-file-wrapper.cc:59
ns3::PcapFileWrapper::m_file
PcapFile m_file
Pcap file.
Definition: pcap-file-wrapper.h:224
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::PcapFileWrapper::GetVersionMajor
uint16_t GetVersionMajor(void)
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
Definition: pcap-file-wrapper.cc:217
ns3::PcapFileWrapper::m_snapLen
uint32_t m_snapLen
max length of saved packets
Definition: pcap-file-wrapper.h:225
ns3::PcapFileWrapper::Read
Ptr< Packet > Read(Time &t)
Read the next packet from the file.
Definition: pcap-file-wrapper.cc:179
ns3::PcapFileWrapper::GetSnapLen
uint32_t GetSnapLen(void)
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
Definition: pcap-file-wrapper.cc:245
ns3::PcapFile
A class representing a pcap file.
Definition: pcap-file.h:43
ns3::Ptr< const Packet >
max
#define max(a, b)
Definition: 80211b.c:43
ns3::PcapFileWrapper::Clear
void Clear(void)
Clear all state bits of the underlying iostream.
Definition: pcap-file-wrapper.cc:79
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::PcapFileWrapper::GetSigFigs
uint32_t GetSigFigs(void)
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
Definition: pcap-file-wrapper.cc:238
ns3::PcapFileWrapper::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: pcap-file-wrapper.cc:33
ns3::PcapFileWrapper::GetTimeZoneOffset
int32_t GetTimeZoneOffset(void)
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
Definition: pcap-file-wrapper.cc:231
ns3::PcapFileWrapper::PcapFileWrapper
PcapFileWrapper()
Definition: pcap-file-wrapper.cc:54
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Header
Protocol header serialization and deserialization.
Definition: header.h:43
ns3::PcapFileWrapper::GetMagic
uint32_t GetMagic(void)
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
Definition: pcap-file-wrapper.cc:210
ns3::PcapFileWrapper::GetVersionMinor
uint16_t GetVersionMinor(void)
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
Definition: pcap-file-wrapper.cc:224
ns3::PcapFileWrapper::Close
void Close(void)
Close the underlying pcap file.
Definition: pcap-file-wrapper.cc:86
ns3::PcapFileWrapper::Eof
bool Eof(void) const
Definition: pcap-file-wrapper.cc:73
ns3::PcapFileWrapper::Fail
bool Fail(void) const
Definition: pcap-file-wrapper.cc:66
ns3::PcapFile::ZONE_DEFAULT
static const int32_t ZONE_DEFAULT
Time zone offset for current location.
Definition: pcap-file.h:45
ns3::PcapFileWrapper::Init
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.
Definition: pcap-file-wrapper.cc:100
ns3::PcapFileWrapper::GetDataLinkType
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
Definition: pcap-file-wrapper.cc:252
ns3::PcapFileWrapper::Write
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
Definition: pcap-file-wrapper.cc:119
ns3::PcapFileWrapper::Open
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
Definition: pcap-file-wrapper.cc:93
ns3::PcapFileWrapper::m_nanosecMode
bool m_nanosecMode
Timestamps in nanosecond mode.
Definition: pcap-file-wrapper.h:226
ns3::PcapFileWrapper
A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low...
Definition: pcap-file-wrapper.h:40