Browse Source

[3553] Wireshark captures for DHCPv4 moved to a common class.

Tomek Mrugalski 10 years ago
parent
commit
7f6cc701a0

+ 0 - 1
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

+ 8 - 6
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

@@ -18,6 +18,7 @@
 #include <asiolink/io_address.h>
 #include <config/ccsession.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
+#include <dhcp/tests/pkt_captures.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/option.h>
@@ -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);

+ 2 - 30
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
     ///

+ 1 - 1
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)

+ 7 - 8
src/bin/dhcp4/tests/wireshark.cc

@@ -13,7 +13,7 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <config.h>
-#include <dhcp4/tests/dhcp4_test_utils.h>
+#include <dhcp/tests/pkt_captures.h>
 #include <string>
 #include <asiolink/io_address.h>
 #include <util/encode/hex.h>
@@ -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<uint8_t> 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

src/lib/dhcp/tests/wireshark/pkt_captures6.cc → src/lib/dhcp/tests/pkt_captures6.cc