1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2005,2006 INRIA
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;
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.
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
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
25 #include "ns3/object.h"
34 * \brief Pcap output for Packet logger
36 * Log Packets to a file in pcap format which can be
37 * read by pcap readers.
39 class PcapWriter : public Object
42 static TypeId GetTypeId (void);
47 * \param name the name of the file to store packet log into.
48 * This method creates the file if it does not exist. If it
49 * exists, the file is emptied.
51 void Open (std::string const &name);
54 * Write a pcap header in the output file which specifies
55 * that the content of the file will be Packets with
56 * Ethernet/LLC/SNAP encapsulation. This method should
57 * be invoked before ns3::PcapWriter::writePacket and after
58 * ns3::PcapWriter::open.
60 void WriteEthernetHeader (void);
63 * Write a pcap header in the output file which specifies
64 * that the content of the file will be IPv4 Packets. This
65 * method should be invoked before ns3::PcapWriter::WritePacket
66 * and after ns3::PcapWriter::Open.
68 void WriteIpHeader (void);
71 * Write a pcap header in the output file which specifies
72 * that the content of the file will be 802.11 Packets. This
73 * method should be invoked before ns3::PcapWriter::WritePacket
74 * and after ns3::PcapWriter::Open.
76 void WriteWifiHeader (void);
79 * Write a pcap header in the output file which specifies
80 * that the content of the file will be 802.11 Packets preceded by a
81 * radiotap header providing PHY layer info. This method should be
82 * invoked before ns3::PcapWriter::WritePacket and after
83 * ns3::PcapWriter::Open.
85 void WriteWifiRadiotapHeader (void);
88 * Write a pcap header in the output file which specifies
89 * that the content of the file will be 802.11 Packets preceded by a
90 * prism header providing PHY layer info. This method should be
91 * invoked before ns3::PcapWriter::WritePacket and after
92 * ns3::PcapWriter::Open.
94 void WriteWifiPrismHeader (void);
97 * Write a pcap header in the output file which specifies
98 * that the content of the file will be ppp Packets. This
99 * method should be invoked before ns3::PcapWriter::WritePacket
100 * and after ns3::PcapWriter::Open.
102 void WritePppHeader (void);
105 * \param packet packet to write to output file
107 void WritePacket (Ptr<const Packet> packet);
110 * Write a Packet, possibly adding wifi PHY layer information to it
112 * @param packet the packet being received
113 * @param channelFreqMhz the frequency in MHz at which the packet is
114 * received. Note that in real devices this is normally the
115 * frequency to which the receiver is tuned, and this can be
116 * different than the frequency at which the packet was originally
117 * transmitted. This is because it is possible to have the receiver
118 * tuned on a given channel and still to be able to receive packets
119 * on a nearby channel.
120 * @param rate the PHY data rate in units of 500kbps (i.e., the same
121 * units used both for the radiotap and for the prism header)
122 * @param isShortPreamble true if short preamble is used, false otherwise
123 * @param isTx true if packet is being transmitted, false when
124 * packet is being received
125 * @param signalDbm signal power in dBm
126 * @param noiseDbm noise power in dBm
128 void WriteWifiMonitorPacket(Ptr<const Packet> packet, uint16_t channelFreqMhz,
129 uint32_t rate, bool isShortPreamble, bool isTx,
130 double signalDbm, double noiseDbm);
133 * Set the maximum number of bytes to be captured for each packet.
135 * @param size the maximum number of bytes to be captured. If zero
136 * (default), the whole packet will be captured.
138 void SetCaptureSize (uint32_t size);
142 void WriteData (uint8_t const*buffer, uint32_t size);
143 void Write64 (uint64_t data);
144 void Write32 (uint32_t data);
145 void Write16 (uint16_t data);
146 void Write8 (uint8_t data);
147 void WriteHeader (uint32_t network);
148 int8_t RoundToInt8 (double value);
149 std::ofstream *m_writer;
151 uint32_t m_captureSize;
157 #endif /* PCAP_WRITER_H */