9#include "ns3/iana-link-type-numbers.h"
11#include "ns3/packet.h"
12#include "ns3/pcap-file-wrapper.h"
13#include "ns3/pcap-file.h"
15#include "ns3/simulator.h"
17#include "ns3/trace-helper.h"
48 void DoRun()
override;
64 :
TestCase(
"Reusing one explicit pcap filename for two interfaces yields a valid pcap (#1150)")
97 "CreateFile() for the first interface should succeed");
103 "CreateFile() for the second interface should succeed");
105 std::vector<uint8_t> payloadA(40, 0xa1);
106 std::vector<uint8_t> payloadB(80, 0xb2);
111 fileA->Write(
Seconds(1), pktA);
112 fileB->Write(
Seconds(2), pktB);
113 fileA->Write(
Seconds(3), pktA);
114 fileB->Write(
Seconds(4), pktB);
124 "Resulting pcap file should have a valid global header");
127 "Resulting pcap file should carry the standard pcap magic number");
131 std::fseek(raw, 0, SEEK_END);
132 auto fileSize =
static_cast<uint64_t
>(std::ftell(raw));
139 std::vector<uint8_t> buffer(
SNAP_LEN);
149 reader.
Read(buffer.data(), buffer.size(), tsSec, tsUsec, inclLen, origLen, readLen);
157 "Record " << recordCount <<
" should read without error");
161 "Record " << recordCount
162 <<
" has an implausible included length");
166 "Record " << recordCount <<
" runs past the end of the file");
174 "Record stream should end exactly at the end of the file");
Regression test for Issue 1150.
static constexpr uint32_t PCAP_RECORD_HEADER_LEN
Size, in bytes, of a per-packet pcap record header.
static constexpr uint32_t PCAP_MAGIC
Magic number of a standard (microsecond) little-endian pcap file.
std::string m_testFilename
Explicit pcap file name shared by both "interfaces".
~PcapExplicitFilenameTestCase() override
static constexpr uint32_t SNAP_LEN
Snap length used when initializing the pcap files.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
static constexpr uint32_t PCAP_GLOBAL_HEADER_LEN
Size, in bytes, of the pcap global header.
void DoRun() override
Implementation to actually run this TestCase.
PcapExplicitFilenameTestCase()
Test suite for the Issue 1150 explicit-pcap-filename regression test.
PcapExplicitFilenameTestSuite()
A class representing a pcap file.
void Close()
Close the underlying file.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
uint32_t GetMagic()
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
Manage pcap files for device models.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint16_t dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
Smart pointer class similar to boost::intrusive_ptr.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
constexpr uint16_t RAW
Raw IP; begins with an IPv4 or IPv6 header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static PcapExplicitFilenameTestSuite g_pcapExplicitFilenameTestSuite
Static variable for test initialization.