From 9f88bd50f09456870cfb003aa48df90a7001e01b Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Wed, 4 Feb 2015 12:35:17 -0800 Subject: [PATCH] On mismatch PcapFile::Diff reports packet number. --- src/network/test/pcap-file-test-suite.cc | 7 ++++--- src/network/utils/pcap-file.cc | 4 +++- src/network/utils/pcap-file.h | 2 +- src/network/utils/pcap-test.h | 12 +++++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/network/test/pcap-file-test-suite.cc b/src/network/test/pcap-file-test-suite.cc index a1bb74ef2..19ebf3e56 100644 --- a/src/network/test/pcap-file-test-suite.cc +++ b/src/network/test/pcap-file-test-suite.cc @@ -1090,8 +1090,8 @@ DiffTestCase::DoRun (void) // Check that PcapDiff(file, file) is false // std::string filename = CreateDataDirFilename ("known.pcap"); - uint32_t sec (0), usec (0); - bool diff = PcapFile::Diff (filename, filename, sec, usec); + uint32_t sec (0), usec (0), packets (0); + bool diff = PcapFile::Diff (filename, filename, sec, usec, packets); NS_TEST_EXPECT_MSG_EQ (diff, false, "PcapDiff(file, file) must always be false"); // @@ -1114,7 +1114,8 @@ DiffTestCase::DoRun (void) } f.Close (); - diff = PcapFile::Diff (filename, filename2, sec, usec); + packets = 0; + diff = PcapFile::Diff (filename, filename2, sec, usec, packets); NS_TEST_EXPECT_MSG_EQ (diff, true, "PcapDiff(file, file2) must be true"); NS_TEST_EXPECT_MSG_EQ (sec, 2, "Files are different from 2.3696 seconds"); NS_TEST_EXPECT_MSG_EQ (usec, 3696, "Files are different from 2.3696 seconds"); diff --git a/src/network/utils/pcap-file.cc b/src/network/utils/pcap-file.cc index f14784c85..f67d26905 100644 --- a/src/network/utils/pcap-file.cc +++ b/src/network/utils/pcap-file.cc @@ -494,7 +494,7 @@ PcapFile::Read ( bool PcapFile::Diff (std::string const & f1, std::string const & f2, - uint32_t & sec, uint32_t & usec, + uint32_t & sec, uint32_t & usec, uint32_t & packets, uint32_t snapLen) { NS_LOG_FUNCTION (f1 << f2 << sec << usec << snapLen); @@ -537,6 +537,8 @@ PcapFile::Diff (std::string const & f1, std::string const & f2, break; } + ++packets; + if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2) { diff = true; // Next packet timestamps do not match diff --git a/src/network/utils/pcap-file.h b/src/network/utils/pcap-file.h index c370018c7..f3ed7a309 100644 --- a/src/network/utils/pcap-file.h +++ b/src/network/utils/pcap-file.h @@ -273,7 +273,7 @@ public: * \param snapLen Snap length (if used) */ static bool Diff (std::string const & f1, std::string const & f2, - uint32_t & sec, uint32_t & usec, + uint32_t & sec, uint32_t & usec, uint32_t & packets, uint32_t snapLen = SNAPLEN_DEFAULT); private: diff --git a/src/network/utils/pcap-test.h b/src/network/utils/pcap-test.h index c3d6fd4f9..6318be6a8 100644 --- a/src/network/utils/pcap-test.h +++ b/src/network/utils/pcap-test.h @@ -21,12 +21,14 @@ oss << filename; \ std::string expected = CreateDataDirFilename (oss.str()); \ std::string got = CreateTempDirFilename (oss.str()); \ - uint32_t sec(0), usec(0); \ - /** \todo support default PcapWriter snap length here */ \ - bool diff = PcapFile::Diff (got, expected, sec, usec); \ + uint32_t sec(0), usec(0), packets(0); \ + /** \todo support default PcapWriter snap length here */ \ + bool diff = PcapFile::Diff (got, expected, sec, usec, packets); \ NS_TEST_EXPECT_MSG_EQ (diff, false, \ - "PCAP traces " << got << " and " << expected \ - << " differ starting from " << sec << " s " \ + "PCAP traces " \ + << got << " and " << expected \ + << " differ starting from packet " \ + << packets << " at " << sec << " s " \ << usec << " us"); \ } while (false)