Browse Source

[3553] PktCaptures added.

Tomek Mrugalski 10 years ago
parent
commit
4f6111afdd

+ 0 - 1
src/bin/dhcp6/tests/Makefile.am

@@ -79,7 +79,6 @@ dhcp6_unittests_SOURCES += dhcp6_test_utils.cc dhcp6_test_utils.h
 dhcp6_unittests_SOURCES += d2_unittest.cc d2_unittest.h
 dhcp6_unittests_SOURCES += marker_file.cc
 dhcp6_unittests_SOURCES += ctrl_dhcp6_srv_unittest.cc
-dhcp6_unittests_SOURCES += wireshark.cc
 dhcp6_unittests_SOURCES += dhcp6_client.cc dhcp6_client.h
 dhcp6_unittests_SOURCES += rebind_unittest.cc
 dhcp6_unittests_SOURCES += sarr_unittest.cc

+ 13 - 11
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -40,6 +40,8 @@
 #include <hooks/server_hooks.h>
 
 #include <dhcp6/tests/dhcp6_test_utils.h>
+#include <dhcp/tests/pkt_captures.h>
+#include <config/ccsession.h>
 #include <boost/pointer_cast.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
@@ -50,7 +52,7 @@
 
 using namespace isc;
 using namespace isc::data;
-using namespace isc::config;
+//using namespace isc::config;
 using namespace isc::test;
 using namespace isc::asiolink;
 using namespace isc::dhcp;
@@ -1443,7 +1445,7 @@ TEST_F(Dhcpv6SrvTest, portsDirectTraffic) {
     NakedDhcpv6Srv srv(0);
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = captureSimpleSolicit();
+    Pkt6Ptr sol = PktCaptures::captureSimpleSolicit();
 
     // Simulate that we have received that traffic
     srv.fakeReceive(sol);
@@ -1468,7 +1470,7 @@ TEST_F(Dhcpv6SrvTest, portsRelayedTraffic) {
     NakedDhcpv6Srv srv(0);
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = captureRelayedSolicit();
+    Pkt6Ptr sol = PktCaptures::captureRelayedSolicit();
 
     // Simulate that we have received that traffic
     srv.fakeReceive(sol);
@@ -1495,7 +1497,7 @@ TEST_F(Dhcpv6SrvTest, docsisTraffic) {
     NakedDhcpv6Srv srv(0);
 
     // Let's get a traffic capture from DOCSIS3.0 modem
-    Pkt6Ptr sol = captureDocsisRelayedSolicit();
+    Pkt6Ptr sol = PktCaptures::captureDocsisRelayedSolicit();
 
     // Simulate that we have received that traffic
     srv.fakeReceive(sol);
@@ -1515,7 +1517,7 @@ TEST_F(Dhcpv6SrvTest, docsisTraffic) {
 TEST_F(Dhcpv6SrvTest, docsisVendorOptionsParse) {
 
     // Let's get a traffic capture from DOCSIS3.0 modem
-    Pkt6Ptr sol = captureDocsisRelayedSolicit();
+    Pkt6Ptr sol = PktCaptures::captureDocsisRelayedSolicit();
     EXPECT_NO_THROW(sol->unpack());
 
     // Check if the packet contain
@@ -1550,7 +1552,7 @@ TEST_F(Dhcpv6SrvTest, docsisVendorORO) {
     NakedDhcpv6Srv srv(0);
 
     // Let's get a traffic capture from DOCSIS3.0 modem
-    Pkt6Ptr sol = captureDocsisRelayedSolicit();
+    Pkt6Ptr sol = PktCaptures::captureDocsisRelayedSolicit();
     ASSERT_NO_THROW(sol->unpack());
 
     // Check if the packet contains vendor options option
@@ -1698,13 +1700,13 @@ TEST_F(Dhcpv6SrvTest, vendorOptionsDocsisDefinitions) {
     // This should fail (missing option definition)
     EXPECT_NO_THROW(x = configureDhcp6Server(srv, json_bogus));
     ASSERT_TRUE(x);
-    comment_ = parseAnswer(rcode_, x);
+    comment_ = isc::config::parseAnswer(rcode_, x);
     ASSERT_EQ(1, rcode_);
 
     // This should work (option definition present)
     EXPECT_NO_THROW(x = configureDhcp6Server(srv, json_valid));
     ASSERT_TRUE(x);
-    comment_ = parseAnswer(rcode_, x);
+    comment_ = isc::config::parseAnswer(rcode_, x);
     ASSERT_EQ(0, rcode_);
 }
 
@@ -1789,7 +1791,7 @@ TEST_F(Dhcpv6SrvTest, clientClassification) {
     // Let's create a relayed SOLICIT. This particular relayed SOLICIT has
     // vendor-class set to docsis3.0
     Pkt6Ptr sol1;
-    ASSERT_NO_THROW(sol1 = captureDocsisRelayedSolicit());
+    ASSERT_NO_THROW(sol1 = PktCaptures::captureDocsisRelayedSolicit());
     ASSERT_NO_THROW(sol1->unpack());
 
     srv.classifyPacket(sol1);
@@ -1801,7 +1803,7 @@ TEST_F(Dhcpv6SrvTest, clientClassification) {
     // Let's get a relayed SOLICIT. This particular relayed SOLICIT has
     // vendor-class set to eRouter1.0
     Pkt6Ptr sol2;
-    ASSERT_NO_THROW(sol2 = captureeRouterRelayedSolicit());
+    ASSERT_NO_THROW(sol2 = PktCaptures::captureeRouterRelayedSolicit());
     ASSERT_NO_THROW(sol2->unpack());
 
     srv.classifyPacket(sol2);
@@ -1902,7 +1904,7 @@ TEST_F(Dhcpv6SrvTest, cableLabsShortVendorClass) {
     NakedDhcpv6Srv srv(0);
 
     // Create a simple Solicit with the 4-byte long vendor class option.
-    Pkt6Ptr sol = captureCableLabsShortVendorClass();
+    Pkt6Ptr sol = PktCaptures::captureCableLabsShortVendorClass();
 
     // Simulate that we have received that traffic
     srv.fakeReceive(sol);

+ 2 - 1
src/bin/dhcp6/tests/dhcp6_test_utils.cc

@@ -15,6 +15,7 @@
 #include <gtest/gtest.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/json_config_parser.h>
+#include <config/ccsession.h>
 
 using namespace isc::data;
 using namespace isc::dhcp;
@@ -603,7 +604,7 @@ Dhcpv6SrvTest::configure(const std::string& config, NakedDhcpv6Srv& srv) {
     EXPECT_NO_THROW(status = configureDhcp6Server(srv, json));
     ASSERT_TRUE(status);
     int rcode;
-    ConstElementPtr comment = config::parseAnswer(rcode, status);
+    ConstElementPtr comment = isc::config::parseAnswer(rcode, status);
     ASSERT_EQ(0, rcode);
 
     CfgMgr::instance().commit();

+ 0 - 17
src/bin/dhcp6/tests/dhcp6_test_utils.h

@@ -33,7 +33,6 @@
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcp6/dhcp6_srv.h>
 #include <hooks/hooks_manager.h>
-#include <config/ccsession.h>
 
 #include <list>
 
@@ -521,22 +520,6 @@ public:
     testReleaseReject(isc::dhcp::Lease::Type type,
                       const isc::asiolink::IOAddress& addr);
 
-    // see wireshark.cc for descriptions
-    // The descriptions are too large and too closely related to the
-    // code, so it is kept in .cc rather than traditionally in .h
-    isc::dhcp::Pkt6Ptr captureSimpleSolicit();
-    isc::dhcp::Pkt6Ptr captureRelayedSolicit();
-    isc::dhcp::Pkt6Ptr captureDocsisRelayedSolicit();
-    isc::dhcp::Pkt6Ptr captureeRouterRelayedSolicit();
-    isc::dhcp::Pkt6Ptr captureCableLabsShortVendorClass();
-
-    /// @brief Auxiliary method that sets Pkt6 fields
-    ///
-    /// Used to reconstruct captured packets. Sets UDP ports, interface names,
-    /// and other fields to some believable values.
-    /// @param pkt packet that will have its fields set
-    void captureSetDefaultFields(const isc::dhcp::Pkt6Ptr& pkt);
-
     /// A subnet used in most tests
     isc::dhcp::Subnet6Ptr subnet_;
 

+ 17 - 15
src/bin/dhcp6/tests/hooks_unittest.cc

@@ -28,6 +28,8 @@
 #include <hooks/server_hooks.h>
 
 #include <dhcp6/tests/dhcp6_test_utils.h>
+#include <dhcp/tests/pkt_captures.h>
+#include <config/ccsession.h>
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
 #include <unistd.h>
@@ -37,7 +39,7 @@
 
 using namespace isc;
 using namespace isc::data;
-using namespace isc::config;
+//using namespace isc::config;
 using namespace isc::test;
 using namespace isc::asiolink;
 using namespace isc::dhcp;
@@ -524,7 +526,7 @@ TEST_F(HooksDhcpv6SrvTest, simple_buffer6_receive) {
                         "buffer6_receive", buffer6_receive_callout));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -557,7 +559,7 @@ TEST_F(HooksDhcpv6SrvTest, valueChange_buffer6_receive) {
                         "buffer6_receive", buffer6_receive_change_clientid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -594,7 +596,7 @@ TEST_F(HooksDhcpv6SrvTest, deleteClientId_buffer6_receive) {
                         "buffer6_receive", buffer6_receive_delete_clientid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -618,7 +620,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_buffer6_receive) {
                         "buffer6_receive", buffer6_receive_skip));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -645,7 +647,7 @@ TEST_F(HooksDhcpv6SrvTest, simple_pkt6_receive) {
                         "pkt6_receive", pkt6_receive_callout));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -678,7 +680,7 @@ TEST_F(HooksDhcpv6SrvTest, valueChange_pkt6_receive) {
                         "pkt6_receive", pkt6_receive_change_clientid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -714,7 +716,7 @@ TEST_F(HooksDhcpv6SrvTest, deleteClientId_pkt6_receive) {
                         "pkt6_receive", pkt6_receive_delete_clientid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -738,7 +740,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_pkt6_receive) {
                         "pkt6_receive", pkt6_receive_skip));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -763,7 +765,7 @@ TEST_F(HooksDhcpv6SrvTest, simple_pkt6_send) {
                         "pkt6_send", pkt6_send_callout));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -799,7 +801,7 @@ TEST_F(HooksDhcpv6SrvTest, valueChange_pkt6_send) {
                         "pkt6_send", pkt6_send_change_serverid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -836,7 +838,7 @@ TEST_F(HooksDhcpv6SrvTest, deleteServerId_pkt6_send) {
                         "pkt6_send", pkt6_send_delete_serverid));
 
     // Let's create a simple SOLICIT
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -867,7 +869,7 @@ TEST_F(HooksDhcpv6SrvTest, skip_pkt6_send) {
                         "pkt6_send", pkt6_send_skip));
 
     // Let's create a simple REQUEST
-    Pkt6Ptr sol = Pkt6Ptr(captureSimpleSolicit());
+    Pkt6Ptr sol = Pkt6Ptr(PktCaptures::captureSimpleSolicit());
 
     // Simulate that we have received that traffic
     srv_->fakeReceive(sol);
@@ -919,7 +921,7 @@ TEST_F(HooksDhcpv6SrvTest, subnet6_select) {
     // Configure the server and make sure the config is accepted
     EXPECT_NO_THROW(status = configureDhcp6Server(*srv_, json));
     ASSERT_TRUE(status);
-    comment_ = parseAnswer(rcode_, status);
+    comment_ = isc::config::parseAnswer(rcode_, status);
     ASSERT_EQ(0, rcode_);
 
     CfgMgr::instance().commit();
@@ -990,7 +992,7 @@ TEST_F(HooksDhcpv6SrvTest, subnet_select_change) {
     // Configure the server and make sure the config is accepted
     EXPECT_NO_THROW(status = configureDhcp6Server(*srv_, json));
     ASSERT_TRUE(status);
-    comment_ = parseAnswer(rcode_, status);
+    comment_ = isc::config::parseAnswer(rcode_, status);
     ASSERT_EQ(0, rcode_);
 
     CfgMgr::instance().commit();

+ 1 - 0
src/lib/dhcp/tests/Makefile.am

@@ -37,6 +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_CXXFLAGS  = $(AM_CXXFLAGS)
 libdhcptest_la_CPPFLAGS  = $(AM_CPPFLAGS)
 libdhcptest_la_LDFLAGS   = $(AM_LDFLAGS)

+ 9 - 7
src/bin/dhcp6/tests/wireshark.cc

@@ -13,7 +13,9 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <config.h>
-#include <dhcp6/tests/dhcp6_test_utils.h>
+#include <dhcp/pkt6.h>
+#include <util/encode/hex.h>
+#include <dhcp/tests/pkt_captures.h>
 #include <string>
 
 /// @file   wireshark.cc
@@ -45,7 +47,7 @@ using namespace std;
 namespace isc {
 namespace test {
 
-void Dhcpv6SrvTest::captureSetDefaultFields(const Pkt6Ptr& pkt) {
+void PktCaptures::captureSetDefaultFields(const Pkt6Ptr& pkt) {
     pkt->setRemotePort(546);
     pkt->setRemoteAddr(IOAddress("fe80::1"));
     pkt->setLocalPort(0);
@@ -55,7 +57,7 @@ void Dhcpv6SrvTest::captureSetDefaultFields(const Pkt6Ptr& pkt) {
 }
 
 // This function returns buffer for very simple Solicit
-Pkt6Ptr Dhcpv6SrvTest::captureSimpleSolicit() {
+Pkt6Ptr PktCaptures::captureSimpleSolicit() {
     uint8_t data[] = {
         1,  // type 1 = SOLICIT
         0xca, 0xfe, 0x01, // trans-id = 0xcafe01
@@ -75,7 +77,7 @@ Pkt6Ptr Dhcpv6SrvTest::captureSimpleSolicit() {
     return (pkt);
 }
 
-Pkt6Ptr Dhcpv6SrvTest::captureRelayedSolicit() {
+Pkt6Ptr PktCaptures::captureRelayedSolicit() {
 
     // This is a very simple relayed SOLICIT message:
     // RELAY-FORW
@@ -105,7 +107,7 @@ Pkt6Ptr Dhcpv6SrvTest::captureRelayedSolicit() {
 }
 
 /// returns a buffer with relayed SOLICIT (from DOCSIS3.0 cable modem)
-Pkt6Ptr isc::test::Dhcpv6SrvTest::captureDocsisRelayedSolicit() {
+Pkt6Ptr isc::test::PktCaptures::captureDocsisRelayedSolicit() {
 
     // This is an actual DOCSIS packet
     // RELAY-FORW (12)
@@ -166,7 +168,7 @@ Pkt6Ptr isc::test::Dhcpv6SrvTest::captureDocsisRelayedSolicit() {
 }
 
 /// returns a buffer with relayed SOLICIT (from DOCSIS3.0 eRouter)
-Pkt6Ptr isc::test::Dhcpv6SrvTest::captureeRouterRelayedSolicit() {
+Pkt6Ptr isc::test::PktCaptures::captureeRouterRelayedSolicit() {
 
 /* Packet description exported from wireshark:
 DHCPv6
@@ -301,7 +303,7 @@ DHCPv6
     return (pkt);
 }
 
-Pkt6Ptr isc::test::Dhcpv6SrvTest::captureCableLabsShortVendorClass() {
+Pkt6Ptr isc::test::PktCaptures::captureCableLabsShortVendorClass() {
     // This is a simple non-relayed Solicit:
     // - client-identifier
     // - IA_NA