Skip to content

Commit

Permalink
- Remove the filter test
Browse files Browse the repository at this point in the history
- Instead, add a test to read and write SLL2 pcap files
  • Loading branch information
seladb committed Aug 6, 2023
1 parent d9c10a1 commit a90944e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Tests/Pcap++Test/Common/PcapFileNamesDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
#define EXAMPLE_LINKTYPE_IPV6 "PcapExamples/linktype_ipv6.pcap"
#define EXAMPLE_LINKTYPE_IPV4 "PcapExamples/linktype_ipv4.pcap"
#define EXAMPLE_SOLARIS_SNOOP "PcapExamples/solaris.snoop"
#define SLL2_PCAP_PATH "PcapExamples/Sll2Packet.pcap"
#define SLL2_PCAP_PATH "PcapExamples/sll2.pcap"
#define SLL2_PCAP_WRITE_PATH "PcapExamples/sll2_copy.pcap"
File renamed without changes.
1 change: 1 addition & 0 deletions Tests/Pcap++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PTF_TEST_CASE(TestLoggerMultiThread);
// Implemented in FileTests.cpp
PTF_TEST_CASE(TestPcapFileReadWrite);
PTF_TEST_CASE(TestPcapSllFileReadWrite);
PTF_TEST_CASE(TestPcapSll2FileReadWrite);
PTF_TEST_CASE(TestPcapRawIPFileReadWrite);
PTF_TEST_CASE(TestPcapFileAppend);
PTF_TEST_CASE(TestPcapNgFileReadWrite);
Expand Down
44 changes: 44 additions & 0 deletions Tests/Pcap++Test/Tests/FileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,50 @@ PTF_TEST_CASE(TestPcapSllFileReadWrite)



PTF_TEST_CASE(TestPcapSll2FileReadWrite)
{
pcpp::PcapFileReaderDevice readerDev(SLL2_PCAP_PATH);
pcpp::PcapFileWriterDevice writerDev(SLL2_PCAP_WRITE_PATH, pcpp::LINKTYPE_LINUX_SLL2);
PTF_ASSERT_TRUE(readerDev.open());
PTF_ASSERT_TRUE(writerDev.open());
pcpp::RawPacket rawPacket;
int packetCount = 0;
int sll2Count = 0;
int ipCount = 0;

while (readerDev.getNextPacket(rawPacket))
{
packetCount++;
pcpp::Packet packet(&rawPacket);
if (packet.isPacketOfType(pcpp::SLL2))
sll2Count++;
if (packet.isPacketOfType(pcpp::IP))
ipCount++;

PTF_ASSERT_TRUE(writerDev.writePacket(rawPacket));
}

pcpp::IPcapDevice::PcapStats readerStatistics;
pcpp::IPcapDevice::PcapStats writerStatistics;

readerDev.getStatistics(readerStatistics);
PTF_ASSERT_EQUAL((uint32_t)readerStatistics.packetsRecv, 3);
PTF_ASSERT_EQUAL((uint32_t)readerStatistics.packetsDrop, 0);

writerDev.getStatistics(writerStatistics);
PTF_ASSERT_EQUAL((uint32_t)writerStatistics.packetsRecv, 3);
PTF_ASSERT_EQUAL((uint32_t)writerStatistics.packetsDrop, 0);

PTF_ASSERT_EQUAL(packetCount, 3);
PTF_ASSERT_EQUAL(sll2Count, 3);
PTF_ASSERT_EQUAL(ipCount, 3);

readerDev.close();
writerDev.close();
} // TestPcapSll2FileReadWrite



PTF_TEST_CASE(TestPcapRawIPFileReadWrite)
{
pcpp::Logger::getInstance().suppressLogs();
Expand Down
13 changes: 3 additions & 10 deletions Tests/Pcap++Test/Tests/FilterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ PTF_TEST_CASE(TestPcapFilters_LinkLayer)
{
// check if matchPacketWithFilter work properly for packets with different LinkLayerType

// pcpp::LINKTYPE_DLT_RAW1 layer
// pcpp::LINKTYPE_DLT_RAW1 layer
pcpp::PcapFileReaderDevice fileReaderDev1(RAW_IP_PCAP_PATH);
PTF_ASSERT_TRUE(fileReaderDev1.open());
pcpp::RawPacketVector rawPacketVec;
Expand All @@ -764,7 +764,7 @@ PTF_TEST_CASE(TestPcapFilters_LinkLayer)
rawPacketVec.clear();


// pcpp::LINKTYPE_LINUX_SLL layer
// pcpp::LINKTYPE_LINUX_SLL layer
pcpp::PcapFileReaderDevice fileReaderDev2(SLL_PCAP_PATH);
PTF_ASSERT_TRUE(fileReaderDev2.open());
fileReaderDev2.getNextPackets(rawPacketVec);
Expand All @@ -790,7 +790,7 @@ PTF_TEST_CASE(TestPcapFilters_LinkLayer)
rawPacketVec.clear();


// pcpp::LINKTYPE_ETHERNET layer
// pcpp::LINKTYPE_ETHERNET layer
pcpp::PcapNgFileReaderDevice fileReaderDev3(EXAMPLE_PCAPNG_PATH);
PTF_ASSERT_TRUE(fileReaderDev3.open());
fileReaderDev3.getNextPackets(rawPacketVec);
Expand All @@ -814,11 +814,4 @@ PTF_TEST_CASE(TestPcapFilters_LinkLayer)
}
PTF_ASSERT_EQUAL(validCounter, 62);
rawPacketVec.clear();


// pcpp::LINKTYPE_LINUX_SLL2 layer
pcpp::PcapFileReaderDevice fileReaderDev4(SLL2_PCAP_PATH);
PTF_ASSERT_TRUE(fileReaderDev4.open());
fileReaderDev4.getNextPackets(rawPacketVec);
fileReaderDev4.close();
} // TestPcapFilters_LinkLayer
1 change: 1 addition & 0 deletions Tests/Pcap++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ int main(int argc, char* argv[])

PTF_RUN_TEST(TestPcapFileReadWrite, "no_network;pcap");
PTF_RUN_TEST(TestPcapSllFileReadWrite, "no_network;pcap");
PTF_RUN_TEST(TestPcapSll2FileReadWrite, "no_network;pcap");
PTF_RUN_TEST(TestPcapRawIPFileReadWrite, "no_network;pcap");
PTF_RUN_TEST(TestPcapFileAppend, "no_network;pcap");
PTF_RUN_TEST(TestPcapNgFileReadWrite, "no_network;pcap;pcapng");
Expand Down

0 comments on commit a90944e

Please sign in to comment.