author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 19 Apr 2010 20:47:57 +0200 | |
changeset 6250 | 5b6c35b27f62 |
parent 6249 | bb33e80b06b0 |
child 6370 | 0a0b6bf5fdfd |
permissions | -rw-r--r-- |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2009 University of Washington |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
17 |
* |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
18 |
* Author: Craig Dowell (craigdo@ee.washington.edu) |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
*/ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
#include <iostream> |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
22 |
#include <cstring> |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
23 |
#include "ns3/assert.h" |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
24 |
#include "ns3/packet.h" |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
25 |
#include "ns3/fatal-error.h" |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
26 |
#include "ns3/header.h" |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
27 |
#include "ns3/buffer.h" |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
#include "pcap-file.h" |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
// This file is used as part of the ns-3 test framework, so please refrain from |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
// adding any ns-3 specific constructs such as Packet to this file. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
namespace ns3 { |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
const uint32_t MAGIC = 0xa1b2c3d4; /**< Magic number identifying standard pcap file format */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
const uint32_t SWAPPED_MAGIC = 0xd4c3b2a1; /**< Looks this way if byte swapping is required */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
const uint32_t NS_MAGIC = 0xa1b23cd4; /**< Magic number identifying nanosec resolution pcap file format */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
const uint32_t NS_SWAPPED_MAGIC = 0xd43cb2a1; /**< Looks this way if byte swapping is required */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
const uint16_t VERSION_MAJOR = 2; /**< Major version of supported pcap file format */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
const uint16_t VERSION_MINOR = 4; /**< Minor version of supported pcap file format */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
const int32_t SIGFIGS_DEFAULT = 0; /**< Significant figures for timestamps (libpcap doesn't even bother) */ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
PcapFile::PcapFile () |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
46 |
: m_file (), |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
m_swapMode (false) |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
48 |
{} |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
PcapFile::~PcapFile () |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
Close (); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
55 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
56 |
bool |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
57 |
PcapFile::Fail (void) const |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
58 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
59 |
return m_file.fail (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
60 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
61 |
bool |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
62 |
PcapFile::Eof (void) const |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
63 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
64 |
return m_file.eof (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
65 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
66 |
void |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
67 |
PcapFile::Clear (void) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
68 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
69 |
m_file.clear (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
70 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
71 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
72 |
|
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
void |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
PcapFile::Close (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
76 |
m_file.close (); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
uint32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
PcapFile::GetMagic (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
return m_fileHeader.m_magicNumber; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
uint16_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
PcapFile::GetVersionMajor (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
return m_fileHeader.m_versionMajor; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
uint16_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
PcapFile::GetVersionMinor (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
return m_fileHeader.m_versionMinor; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
int32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
PcapFile::GetTimeZoneOffset (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
return m_fileHeader.m_zone; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
uint32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
PcapFile::GetSigFigs (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
return m_fileHeader.m_sigFigs; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
uint32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
PcapFile::GetSnapLen (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
return m_fileHeader.m_snapLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
uint32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
PcapFile::GetDataLinkType (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
return m_fileHeader.m_type; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
bool |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
PcapFile::GetSwapMode (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
return m_swapMode; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
uint8_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
PcapFile::Swap (uint8_t val) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
return val; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
uint16_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
PcapFile::Swap (uint16_t val) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
uint32_t |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
PcapFile::Swap (uint32_t val) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | ((val << 24) & 0xff000000); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
void |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
PcapFile::Swap (PcapFileHeader *from, PcapFileHeader *to) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
to->m_magicNumber = Swap (from->m_magicNumber); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
to->m_versionMajor = Swap (from->m_versionMajor); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
to->m_versionMinor = Swap (from->m_versionMinor); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
to->m_zone = Swap (uint32_t(from->m_zone)); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
to->m_sigFigs = Swap (from->m_sigFigs); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
to->m_snapLen = Swap (from->m_snapLen); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
to->m_type = Swap (from->m_type); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
void |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
PcapFile::Swap (PcapRecordHeader *from, PcapRecordHeader *to) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
to->m_tsSec = Swap (from->m_tsSec); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
to->m_tsUsec = Swap (from->m_tsUsec); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
to->m_inclLen = Swap (from->m_inclLen); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
to->m_origLen = Swap (from->m_origLen); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
166 |
void |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
PcapFile::WriteFileHeader (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
169 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
// If we're initializing the file, we need to write the pcap file header |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
171 |
// at the start of the file. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
173 |
m_file.seekp (0, std::ios::beg); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
// We have the ability to write out the pcap file header in a foreign endian |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
// format, so we need a temp place to swap on the way out. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
179 |
PcapFileHeader header; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
// the pointer headerOut selects either the swapped or non-swapped version of |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
// the pcap file header. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
PcapFileHeader *headerOut = 0; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
if (m_swapMode == false) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
headerOut = &m_fileHeader; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
else |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
Swap (&m_fileHeader, &header); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
headerOut = &header; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
195 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
196 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
197 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
// Watch out for memory alignment differences between machines, so write |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
// them all individually. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
201 |
m_file.write ((const char *)&headerOut->m_magicNumber, sizeof(headerOut->m_magicNumber)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
202 |
m_file.write ((const char *)&headerOut->m_versionMajor, sizeof(headerOut->m_versionMajor)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
203 |
m_file.write ((const char *)&headerOut->m_versionMinor, sizeof(headerOut->m_versionMinor)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
204 |
m_file.write ((const char *)&headerOut->m_zone, sizeof(headerOut->m_zone)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
205 |
m_file.write ((const char *)&headerOut->m_sigFigs, sizeof(headerOut->m_sigFigs)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
206 |
m_file.write ((const char *)&headerOut->m_snapLen, sizeof(headerOut->m_snapLen)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
207 |
m_file.write ((const char *)&headerOut->m_type, sizeof(headerOut->m_type)); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
210 |
void |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
211 |
PcapFile::ReadAndVerifyFileHeader (void) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
212 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
213 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
214 |
// Pcap file header is always at the start of the file |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
215 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
216 |
m_file.seekg (0, std::ios::beg); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
217 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
// Watch out for memory alignment differences between machines, so read |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
// them all individually. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
222 |
m_file.read ((char *)&m_fileHeader.m_magicNumber, sizeof(m_fileHeader.m_magicNumber)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
223 |
m_file.read ((char *)&m_fileHeader.m_versionMajor, sizeof(m_fileHeader.m_versionMajor)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
224 |
m_file.read ((char *)&m_fileHeader.m_versionMinor, sizeof(m_fileHeader.m_versionMinor)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
225 |
m_file.read ((char *)&m_fileHeader.m_zone, sizeof(m_fileHeader.m_zone)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
226 |
m_file.read ((char *)&m_fileHeader.m_sigFigs, sizeof(m_fileHeader.m_sigFigs)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
227 |
m_file.read ((char *)&m_fileHeader.m_snapLen, sizeof(m_fileHeader.m_snapLen)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
228 |
m_file.read ((char *)&m_fileHeader.m_type, sizeof(m_fileHeader.m_type)); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
229 |
|
6250
5b6c35b27f62
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6249
diff
changeset
|
230 |
if (m_file.fail ()) |
5b6c35b27f62
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6249
diff
changeset
|
231 |
{ |
5b6c35b27f62
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6249
diff
changeset
|
232 |
return; |
5b6c35b27f62
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6249
diff
changeset
|
233 |
} |
5b6c35b27f62
fix valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6249
diff
changeset
|
234 |
|
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
// There are four possible magic numbers that can be there. Normal and byte |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
// swapped versions of the standard magic number, and normal and byte swapped |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
// versions of the magic number indicating nanosecond resolution timestamps. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
if (m_fileHeader.m_magicNumber != MAGIC && m_fileHeader.m_magicNumber != SWAPPED_MAGIC && |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
m_fileHeader.m_magicNumber != NS_MAGIC && m_fileHeader.m_magicNumber != NS_SWAPPED_MAGIC) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
243 |
m_file.setstate (std::ios::failbit); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
244 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
// If the magic number is swapped, then we can assume that everything else we read |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
// is swapped. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
250 |
m_swapMode = (m_fileHeader.m_magicNumber == SWAPPED_MAGIC |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
251 |
|| m_fileHeader.m_magicNumber == NS_SWAPPED_MAGIC) ? true : false; |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
253 |
if (m_swapMode) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
Swap (&m_fileHeader, &m_fileHeader); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
256 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
257 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
258 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
259 |
// We only deal with one version of the pcap file format. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
260 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
261 |
if (m_fileHeader.m_versionMajor != VERSION_MAJOR || m_fileHeader.m_versionMinor != VERSION_MINOR) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
262 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
263 |
m_file.setstate (std::ios::failbit); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
264 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
265 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
266 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
267 |
// A quick test of reasonablness for the time zone offset corresponding to |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
268 |
// a real place on the planet. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
269 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
270 |
if (m_fileHeader.m_zone < -12 || m_fileHeader.m_zone > 12) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
271 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
272 |
m_file.setstate (std::ios::failbit); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
273 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
274 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
275 |
if (m_file.fail ()) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
276 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
277 |
m_file.close (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
278 |
} |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
279 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
280 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
281 |
void |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
282 |
PcapFile::Open (std::string const &filename, std::ios::openmode mode) |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
283 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
284 |
NS_ASSERT ((mode & std::ios::app) == 0); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
285 |
NS_ASSERT (!m_file.fail ()); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
286 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
287 |
// All pcap files are binary files, so we just do this automatically. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
288 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
289 |
mode |= std::ios::binary; |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
290 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
291 |
m_file.open (filename.c_str (), mode); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
292 |
if (mode & std::ios::in) |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
293 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
294 |
// will set the fail bit if file header is invalid. |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
295 |
ReadAndVerifyFileHeader (); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
296 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
297 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
298 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
299 |
void |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
300 |
PcapFile::Init (uint32_t dataLinkType, uint32_t snapLen, int32_t timeZoneCorrection, bool swapMode) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
301 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
302 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
303 |
// Initialize the in-memory file header. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
304 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
305 |
m_fileHeader.m_magicNumber = MAGIC; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
306 |
m_fileHeader.m_versionMajor = VERSION_MAJOR; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
307 |
m_fileHeader.m_versionMinor = VERSION_MINOR; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
308 |
m_fileHeader.m_zone = timeZoneCorrection; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
309 |
m_fileHeader.m_sigFigs = 0; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
310 |
m_fileHeader.m_snapLen = snapLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
311 |
m_fileHeader.m_type = dataLinkType; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
312 |
|
6062
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
313 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
314 |
// We use pcap files for regression testing. We do byte-for-byte comparisons |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
315 |
// in those tests to determine pass or fail. If we allow big endian systems |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
316 |
// to write big endian headers, they will end up byte-swapped and the |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
317 |
// regression tests will fail. Until we get rid of the regression tests, we |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
318 |
// have to pick an endianness and stick with it. The precedent is little |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
319 |
// endian, so we set swap mode if required to pick little endian. |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
320 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
321 |
// We do want to allow a user or test suite to enable swapmode irrespective |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
322 |
// of what we decide here, so we allow setting swapmode from formal parameter |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
323 |
// as well. |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
324 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
325 |
// So, determine the endianness of the running system. |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
326 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
327 |
union { |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
328 |
uint32_t a; |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
329 |
uint8_t b[4]; |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
330 |
} u; |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
331 |
|
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
332 |
u.a = 1; |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
333 |
bool bigEndian = u.b[3]; |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
334 |
|
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
335 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
336 |
// And set swap mode if requested or we are on a big-endian system. |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
337 |
// |
f62b76f5c92a
Forgot to force little-endian pcap headers on big-endian machines
Craig Dowell <craigdo@ee.washington.edu>
parents:
5465
diff
changeset
|
338 |
m_swapMode = swapMode | bigEndian; |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
339 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
340 |
WriteFileHeader (); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
341 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
342 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
343 |
uint32_t |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
344 |
PcapFile::WritePacketHeader (uint32_t tsSec, uint32_t tsUsec, uint32_t totalLen) |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
345 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
346 |
NS_ASSERT (m_file.good ()); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
347 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
348 |
uint32_t inclLen = totalLen > m_fileHeader.m_snapLen ? m_fileHeader.m_snapLen : totalLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
349 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
350 |
PcapRecordHeader header; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
351 |
header.m_tsSec = tsSec; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
352 |
header.m_tsUsec = tsUsec; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
353 |
header.m_inclLen = inclLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
354 |
header.m_origLen = totalLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
355 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
356 |
if (m_swapMode) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
357 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
358 |
Swap (&header, &header); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
359 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
360 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
361 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
362 |
// Watch out for memory alignment differences between machines, so write |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
363 |
// them all individually. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
364 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
365 |
m_file.write ((const char *)&header.m_tsSec, sizeof(header.m_tsSec)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
366 |
m_file.write ((const char *)&header.m_tsUsec, sizeof(header.m_tsUsec)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
367 |
m_file.write ((const char *)&header.m_inclLen, sizeof(header.m_inclLen)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
368 |
m_file.write ((const char *)&header.m_origLen, sizeof(header.m_origLen)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
369 |
return inclLen; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
370 |
} |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
371 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
372 |
void |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
373 |
PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, uint8_t const * const data, uint32_t totalLen) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
374 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
375 |
uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, totalLen); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
376 |
m_file.write ((const char *)data, inclLen); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
377 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
378 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
379 |
void |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
380 |
PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, Ptr<const Packet> p) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
381 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
382 |
uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, p->GetSize ()); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
383 |
p->CopyData (&m_file, inclLen); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
384 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
385 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
386 |
void |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
387 |
PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, Header &header, Ptr<const Packet> p) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
388 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
389 |
uint32_t headerSize = header.GetSerializedSize (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
390 |
uint32_t totalSize = headerSize + p->GetSize (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
391 |
uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, totalSize); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
392 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
393 |
Buffer headerBuffer; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
394 |
headerBuffer.AddAtStart (headerSize); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
395 |
header.Serialize (headerBuffer.Begin ()); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
396 |
uint32_t toCopy = std::min (headerSize, inclLen); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
397 |
headerBuffer.CopyData (&m_file, toCopy); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
398 |
inclLen -= toCopy; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
399 |
p->CopyData (&m_file, inclLen); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
400 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
401 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
402 |
void |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
403 |
PcapFile::Read ( |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
404 |
uint8_t * const data, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
405 |
uint32_t maxBytes, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
406 |
uint32_t &tsSec, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
407 |
uint32_t &tsUsec, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
408 |
uint32_t &inclLen, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
409 |
uint32_t &origLen, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
410 |
uint32_t &readLen) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
411 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
412 |
NS_ASSERT (m_file.good ()); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
413 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
414 |
PcapRecordHeader header; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
415 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
416 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
417 |
// Watch out for memory alignment differences between machines, so read |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
418 |
// them all individually. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
419 |
// |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
420 |
m_file.read ((char *)&header.m_tsSec, sizeof(header.m_tsSec)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
421 |
m_file.read ((char *)&header.m_tsUsec, sizeof(header.m_tsUsec)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
422 |
m_file.read ((char *)&header.m_inclLen, sizeof(header.m_inclLen)); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
423 |
m_file.read ((char *)&header.m_origLen, sizeof(header.m_origLen)); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
424 |
|
6244
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
425 |
if (m_file.fail ()) |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
426 |
{ |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
427 |
return; |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
428 |
} |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
429 |
|
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
430 |
if (m_swapMode) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
431 |
{ |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
432 |
Swap (&header, &header); |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
433 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
434 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
435 |
tsSec = header.m_tsSec; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
436 |
tsUsec = header.m_tsUsec; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
437 |
inclLen = header.m_inclLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
438 |
origLen = header.m_origLen; |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
439 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
440 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
441 |
// We don't always want to force the client to keep a maximum length buffer |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
442 |
// around so we allow her to specify a minimum number of bytes to read. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
443 |
// Usually 64 bytes is enough information to print all of the headers, so |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
444 |
// it isn't typically necessary to read all thousand bytes of an echo packet, |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
445 |
// for example, to figure out what is going on. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
446 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
447 |
readLen = maxBytes < header.m_inclLen ? maxBytes : header.m_inclLen; |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
448 |
m_file.read ((char *)data, readLen); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
449 |
|
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
450 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
451 |
// To keep the file pointer pointed in the right place, however, we always |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
452 |
// need to account for the entire packet as stored originally. |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
453 |
// |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
454 |
if (readLen < header.m_inclLen) |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
455 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
456 |
m_file.seekg (header.m_inclLen - readLen, std::ios::cur); |
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
457 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
458 |
} |
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
459 |
|
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
460 |
bool |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
461 |
PcapFile::Diff (std::string const & f1, std::string const & f2, |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
462 |
uint32_t & sec, uint32_t & usec, |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
463 |
uint32_t snapLen) |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
464 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
465 |
PcapFile pcap1, pcap2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
466 |
pcap1.Open (f1, std::ios::in); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
467 |
pcap2.Open (f2, std::ios::in); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
468 |
bool bad = pcap1.Fail () || pcap2.Fail (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
469 |
if (bad) |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
470 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
471 |
return true; |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
472 |
} |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
473 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
474 |
uint8_t *data1 = new uint8_t [snapLen] (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
475 |
uint8_t *data2 = new uint8_t [snapLen] (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
476 |
uint32_t tsSec1, tsSec2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
477 |
uint32_t tsUsec1, tsUsec2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
478 |
uint32_t inclLen1, inclLen2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
479 |
uint32_t origLen1, origLen2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
480 |
uint32_t readLen1, readLen2; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
481 |
bool diff = false; |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
482 |
|
6244
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
483 |
while (!pcap1.Eof () && !pcap2.Eof ()) |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
484 |
{ |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
485 |
pcap1.Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
486 |
pcap2.Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
487 |
|
6249
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
488 |
bool same = pcap1.Fail () == pcap2.Fail (); |
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
489 |
if (!same) |
6244
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
490 |
{ |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
491 |
diff = true; |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
492 |
break; |
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
493 |
} |
6249
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
494 |
if (pcap1.Eof ()) |
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
495 |
{ |
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
496 |
break; |
bb33e80b06b0
fix failing testcase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6244
diff
changeset
|
497 |
} |
6244
ec4b512688d8
workaround valgrind warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6240
diff
changeset
|
498 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
499 |
if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2) |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
500 |
{ |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
501 |
diff = true; // Next packet timestamps do not match |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
502 |
break; |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
503 |
} |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
504 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
505 |
if (readLen1 != readLen2) |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
506 |
{ |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
507 |
diff = true; // Packet lengths do not match |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
508 |
break; |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
509 |
} |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
510 |
|
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
511 |
if (std::memcmp(data1, data2, readLen1) != 0) |
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
512 |
{ |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
513 |
diff = true; // Packet data do not match |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
514 |
break; |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
515 |
} |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
516 |
} |
6206
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
517 |
sec = tsSec1; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
518 |
usec = tsUsec1; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
519 |
|
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
520 |
bad = pcap1.Fail () || pcap2.Fail (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
521 |
bool eof = pcap1.Eof () && pcap2.Eof (); |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
522 |
if (bad && !eof) |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
523 |
{ |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
524 |
diff = true; |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
525 |
} |
9787dc9fdd84
bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6062
diff
changeset
|
526 |
|
6240
c11fdb044daa
fix memory leak in PcapFile::Diff
Craig Dowell <craigdo@ee.washington.edu>
parents:
6206
diff
changeset
|
527 |
delete[] data1; |
c11fdb044daa
fix memory leak in PcapFile::Diff
Craig Dowell <craigdo@ee.washington.edu>
parents:
6206
diff
changeset
|
528 |
delete[] data2; |
c11fdb044daa
fix memory leak in PcapFile::Diff
Craig Dowell <craigdo@ee.washington.edu>
parents:
6206
diff
changeset
|
529 |
|
5465
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
530 |
return diff; |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
531 |
} |
917f7367691e
Pcap::Diff() method added to compare PCAP traces packet-by-packet
Pavel Boyko <boyko@iitp.ru>
parents:
4772
diff
changeset
|
532 |
|
4772
7b6ae6bf0055
add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
533 |
} //namespace ns3 |