From: Tomek Mrugalski Date: Wed, 17 Dec 2014 19:16:32 +0000 (+0100) Subject: [3553] Wireshark captures for DHCPv4 moved to a common class. X-Git-Tag: trac3712_base~69^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f6cc701a073a579e7967fd8fb5cb4c151f2ad96;p=thirdparty%2Fkea.git [3553] Wireshark captures for DHCPv4 moved to a common class. --- diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am index 0d990cd5c0..9a1a3df915 100644 --- a/src/bin/dhcp4/tests/Makefile.am +++ b/src/bin/dhcp4/tests/Makefile.am @@ -80,7 +80,6 @@ dhcp4_unittests_SOURCES += dhcp4_unittests.cc dhcp4_unittests_SOURCES += dhcp4_srv_unittest.cc dhcp4_unittests_SOURCES += dhcp4_test_utils.cc dhcp4_test_utils.h dhcp4_unittests_SOURCES += direct_client_unittest.cc -dhcp4_unittests_SOURCES += wireshark.cc dhcp4_unittests_SOURCES += ctrl_dhcp4_srv_unittest.cc dhcp4_unittests_SOURCES += config_parser_unittest.cc dhcp4_unittests_SOURCES += fqdn_unittest.cc diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 5c79dccd21..54ca39421e 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,7 @@ using namespace isc::data; using namespace isc::asiolink; using namespace isc::hooks; using namespace isc::dhcp::test; +using namespace isc::test; namespace { @@ -1159,7 +1161,7 @@ TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) { // added option 82 (relay agent info) with 3 suboptions. The server // is supposed to echo it back in its response. Pkt4Ptr dis; - ASSERT_NO_THROW(dis = captureRelayedDiscover()); + ASSERT_NO_THROW(dis = PktCaptures::captureRelayedDiscover()); // Simulate that we have received that traffic srv.fakeReceive(dis); @@ -1235,7 +1237,7 @@ TEST_F(Dhcpv4SrvTest, vendorOptionsDocsis) { // added option 82 (relay agent info) with 3 suboptions. The server // is supposed to echo it back in its response. Pkt4Ptr dis; - ASSERT_NO_THROW(dis = captureRelayedDiscover()); + ASSERT_NO_THROW(dis = PktCaptures::captureRelayedDiscover()); // Simulate that we have received that traffic srv.fakeReceive(dis); @@ -2935,7 +2937,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) { TEST_F(Dhcpv4SrvTest, docsisVendorOptionsParse) { // Let's get a traffic capture from DOCSIS3.0 modem - Pkt4Ptr dis = captureRelayedDiscover(); + Pkt4Ptr dis = PktCaptures::captureRelayedDiscover(); ASSERT_NO_THROW(dis->unpack()); // Check if the packet contain @@ -2959,7 +2961,7 @@ TEST_F(Dhcpv4SrvTest, docsisVendorOptionsParse) { TEST_F(Dhcpv4SrvTest, docsisVendorORO) { // Let's get a traffic capture from DOCSIS3.0 modem - Pkt4Ptr dis = captureRelayedDiscover(); + Pkt4Ptr dis = PktCaptures::captureRelayedDiscover(); EXPECT_NO_THROW(dis->unpack()); // Check if the packet contains vendor specific information option @@ -3127,7 +3129,7 @@ TEST_F(Dhcpv4SrvTest, clientClassification) { // Let's create a relayed DISCOVER. This particular relayed DISCOVER has // vendor-class set to docsis3.0 Pkt4Ptr dis1; - ASSERT_NO_THROW(dis1 = captureRelayedDiscover()); + ASSERT_NO_THROW(dis1 = PktCaptures::captureRelayedDiscover()); ASSERT_NO_THROW(dis1->unpack()); srv.classifyPacket(dis1); @@ -3138,7 +3140,7 @@ TEST_F(Dhcpv4SrvTest, clientClassification) { // Let's create a relayed DISCOVER. This particular relayed DISCOVER has // vendor-class set to eRouter1.0 Pkt4Ptr dis2; - ASSERT_NO_THROW(dis2 = captureRelayedDiscover2()); + ASSERT_NO_THROW(dis2 = PktCaptures::captureRelayedDiscover2()); ASSERT_NO_THROW(dis2->unpack()); srv.classifyPacket(dis2); diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index b6e4ff72d2..6cd4a56ecf 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -335,21 +335,6 @@ public: /// @param expected_clientid expected value of client-id void checkClientId(const Pkt4Ptr& rsp, const OptionPtr& expected_clientid); - /// @brief sets default fields in a captured packet - /// - /// Sets UDP ports, addresses and interface. - /// - /// @param pkt packet to have default fields set - void captureSetDefaultFields(const Pkt4Ptr& pkt); - - /// @brief returns captured DISCOVER that went through a relay - /// - /// See method code for a detailed explanation. This is a discover from - /// docsis3.0 device (Cable Modem) - /// - /// @return relayed DISCOVER - Pkt4Ptr captureRelayedDiscover(); - /// @brief Create packet from output buffer of another packet. /// /// This function creates a packet using an output buffer from another @@ -373,21 +358,8 @@ public: /// @return assertion result indicating if a function completed with /// success or failure. static ::testing::AssertionResult - createPacketFromBuffer(const Pkt4Ptr& src_pkt, - Pkt4Ptr& dst_pkt); - - /// @brief returns captured DISCOVER that went through a relay - /// - /// See method code for a detailed explanation. This is a discover from - /// eRouter1.0 device (CPE device integrated with cable modem) - /// - /// @return relayed DISCOVER - Pkt4Ptr captureRelayedDiscover2(); - - /// @brief generates a DHCPv4 packet based on provided hex string - /// - /// @return created packet - Pkt4Ptr packetFromCapture(const std::string& hex_string); + createPacketFromBuffer(const isc::dhcp::Pkt4Ptr& src_pkt, + isc::dhcp::Pkt4Ptr& dst_pkt); /// @brief Tests if Discover or Request message is processed correctly /// diff --git a/src/lib/dhcp/tests/Makefile.am b/src/lib/dhcp/tests/Makefile.am index 48b6683a62..2fac037101 100644 --- a/src/lib/dhcp/tests/Makefile.am +++ b/src/lib/dhcp/tests/Makefile.am @@ -37,7 +37,7 @@ noinst_LTLIBRARIES = libdhcptest.la libdhcptest_la_SOURCES = iface_mgr_test_config.cc iface_mgr_test_config.h libdhcptest_la_SOURCES += pkt_filter_test_stub.cc pkt_filter_test_stub.h libdhcptest_la_SOURCES += pkt_filter6_test_stub.cc pkt_filter6_test_stub.h -libdhcptest_la_SOURCES += wireshark/pkt_captures6.cc wireshark/pkt_captures.h +libdhcptest_la_SOURCES += pkt_captures4.cc pkt_captures6.cc pkt_captures.h libdhcptest_la_CXXFLAGS = $(AM_CXXFLAGS) libdhcptest_la_CPPFLAGS = $(AM_CPPFLAGS) libdhcptest_la_LDFLAGS = $(AM_LDFLAGS) diff --git a/src/bin/dhcp4/tests/wireshark.cc b/src/lib/dhcp/tests/pkt_captures4.cc similarity index 95% rename from src/bin/dhcp4/tests/wireshark.cc rename to src/lib/dhcp/tests/pkt_captures4.cc index c07bc1bc29..ff422274ae 100644 --- a/src/bin/dhcp4/tests/wireshark.cc +++ b/src/lib/dhcp/tests/pkt_captures4.cc @@ -13,7 +13,7 @@ // PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include #include #include @@ -41,13 +41,13 @@ /// contain whatever expansion level you have in the graphical tree.) using namespace std; +using namespace isc::dhcp; using namespace isc::asiolink; namespace isc { -namespace dhcp { namespace test { -Pkt4Ptr Dhcpv4SrvTest::packetFromCapture(const std::string& hex_string) { +Pkt4Ptr PktCaptures::packetFromCapture(const std::string& hex_string) { std::vector bin; // Decode the hex string and store it in bin (which happens @@ -60,7 +60,7 @@ Pkt4Ptr Dhcpv4SrvTest::packetFromCapture(const std::string& hex_string) { return (pkt); } -void Dhcpv4SrvTest::captureSetDefaultFields(const Pkt4Ptr& pkt) { +void PktCaptures::captureSetDefaultFields(const Pkt4Ptr& pkt) { pkt->setRemotePort(546); pkt->setRemoteAddr(IOAddress("fe80::1")); pkt->setLocalPort(0); @@ -69,7 +69,7 @@ void Dhcpv4SrvTest::captureSetDefaultFields(const Pkt4Ptr& pkt) { pkt->setIface("eth0"); } -Pkt4Ptr Dhcpv4SrvTest::captureRelayedDiscover() { +Pkt4Ptr PktCaptures::captureRelayedDiscover() { /* This is packet 1 from capture dhcp-val/pcap/docsis-*-CG3000DCR-Registration-Filtered.cap @@ -132,7 +132,7 @@ Bootstrap Protocol return (packetFromCapture(hex_string)); } -Pkt4Ptr Dhcpv4SrvTest::captureRelayedDiscover2() { +Pkt4Ptr PktCaptures::captureRelayedDiscover2() { /* This is packet 5 from capture dhcp-val/pcap/docsis-*-CG3000DCR-Registration-Filtered.cap @@ -185,6 +185,5 @@ Bootstrap Protocol return (packetFromCapture(hex_string)); } -}; // end of isc::dhcp::test namespace -}; // end of isc::dhcp namespace +}; // end of isc::test namespace }; // end of isc namespace diff --git a/src/lib/dhcp/tests/wireshark/pkt_captures6.cc b/src/lib/dhcp/tests/pkt_captures6.cc similarity index 100% rename from src/lib/dhcp/tests/wireshark/pkt_captures6.cc rename to src/lib/dhcp/tests/pkt_captures6.cc