On mismatch PcapFile::Diff reports packet number.

This commit is contained in:
Peter D. Barnes, Jr.
2015-02-04 12:35:17 -08:00
parent eb4138894f
commit 9f88bd50f0
4 changed files with 15 additions and 10 deletions

View File

@@ -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");

View File

@@ -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

View File

@@ -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:

View File

@@ -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)