A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
pcap-test.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@cutebugs.net>
7 */
8
9#ifndef PCAP_TEST_H
10#define PCAP_TEST_H
11
12#include "pcap-file.h"
13
14#include "ns3/test.h"
15
16#include <sstream>
17#include <stdint.h>
18#include <string>
19
20/**
21 * \brief Test that a pair of reference/new pcap files are equal
22 *
23 * The filename is interpreted as a stream.
24 *
25 * \param filename The name of the file to read in the reference/temporary
26 * directories
27 */
28#define NS_PCAP_TEST_EXPECT_EQ(filename) \
29 do \
30 { \
31 std::ostringstream oss; \
32 oss << filename; \
33 std::string expected = CreateDataDirFilename(oss.str()); \
34 std::string got = CreateTempDirFilename(oss.str()); \
35 uint32_t sec{0}; \
36 uint32_t usec{0}; \
37 uint32_t packets{0}; \
38 /** \todo support default PcapWriter snap length here */ \
39 bool diff = PcapFile::Diff(got, expected, sec, usec, packets); \
40 NS_TEST_EXPECT_MSG_EQ(diff, \
41 false, \
42 "PCAP traces " << got << " and " << expected \
43 << " differ starting from packet " << packets \
44 << " at " << sec << " s " << usec << " us"); \
45 } while (false)
46
47#endif /* PCAP_TEST_H */