From: Tomek Mrugalski Date: Tue, 23 Dec 2014 15:18:50 +0000 (+0100) Subject: [3553] Unit-tests added for getMACFromDocsisModem(), getMACfromDocsisCMTS() X-Git-Tag: trac3712_base~69^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e1e0c3aa697a46b63be140eeceb77ba4df9c2121;p=thirdparty%2Fkea.git [3553] Unit-tests added for getMACFromDocsisModem(), getMACfromDocsisCMTS() --- diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc index 73735325f4..a87d99083a 100755 --- a/src/lib/dhcp/pkt6.cc +++ b/src/lib/dhcp/pkt6.cc @@ -15,8 +15,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -630,11 +630,11 @@ Pkt6::getMACFromIPv6RelayOpt() { HWAddrPtr Pkt6::getMACFromDocsisModem() { - OptionUint32Ptr vendor = boost::dynamic_pointer_cast< - OptionUint32>(getOption(D6O_VENDOR_OPTS)); + OptionVendorPtr vendor = boost::dynamic_pointer_cast< + OptionVendor>(getOption(D6O_VENDOR_OPTS)); // Check if this is indeed DOCSIS3 environment - if (!vendor || vendor->getValue() != VENDOR_ID_CABLE_LABS) { + if (!vendor || vendor->getVendorId() != VENDOR_ID_CABLE_LABS) { return (HWAddrPtr()); } @@ -660,12 +660,12 @@ Pkt6::getMACFromDocsisCMTS() { return (HWAddrPtr()); } - OptionUint32Ptr vendor = boost::dynamic_pointer_cast< - OptionUint32>(getAnyRelayOption(D6O_VENDOR_OPTS, + OptionVendorPtr vendor = boost::dynamic_pointer_cast< + OptionVendor>(getAnyRelayOption(D6O_VENDOR_OPTS, RELAY_SEARCH_FROM_CLIENT)); // Check if this is indeed DOCSIS3 environment - if (!vendor || vendor->getValue() != VENDOR_ID_CABLE_LABS) { + if (!vendor || vendor->getVendorId() != VENDOR_ID_CABLE_LABS) { return (HWAddrPtr()); } diff --git a/src/lib/dhcp/tests/Makefile.am b/src/lib/dhcp/tests/Makefile.am index 2fac037101..186396ce8c 100644 --- a/src/lib/dhcp/tests/Makefile.am +++ b/src/lib/dhcp/tests/Makefile.am @@ -69,6 +69,7 @@ libdhcp___unittests_SOURCES += option_space_unittest.cc libdhcp___unittests_SOURCES += option_string_unittest.cc libdhcp___unittests_SOURCES += option_vendor_unittest.cc libdhcp___unittests_SOURCES += option_vendor_class_unittest.cc +libdhcp___unittests_SOURCES += pkt_captures4.cc pkt_captures6.cc pkt_captures.h libdhcp___unittests_SOURCES += pkt4_unittest.cc libdhcp___unittests_SOURCES += pkt6_unittest.cc libdhcp___unittests_SOURCES += pkt_filter_unittest.cc diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc index 72ff84b1bd..08dc785fc4 100644 --- a/src/lib/dhcp/tests/pkt6_unittest.cc +++ b/src/lib/dhcp/tests/pkt6_unittest.cc @@ -21,10 +21,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -1183,4 +1185,61 @@ TEST_F(Pkt6Test, getMACFromDUID) { EXPECT_FALSE(pkt.getMAC(HWAddr::HWADDR_SOURCE_DUID)); } +// Test checks whether getMAC(DOCSIS_MODEM) is working properly. +// We only have a small number of actual traffic captures from +// cable networks, so the scope of unit-tests is somewhat limited. +TEST_F(Pkt6Test, getMAC_DOCSIS_Modem) { + + // Let's use a captured traffic. The one we have comes from a + // modem with MAC address 10:0d:7f:00:07:88. + Pkt6Ptr pkt = isc::test::PktCaptures::captureDocsisRelayedSolicit(); + ASSERT_NO_THROW(pkt->unpack()); + + // The method should return MAC based on the vendor-specific info, + // suboption 36, which is inserted by the modem itself. + HWAddrPtr found = pkt->getMAC(Pkt::HWADDR_SOURCE_DOCSIS_MODEM); + ASSERT_TRUE(found); + + // Let's check the info. + EXPECT_EQ("hwtype=1 10:0d:7f:00:07:88", found->toText(true)); + + // Now let's remove the option + OptionVendorPtr vendor = boost::dynamic_pointer_cast< + OptionVendor>(pkt->getOption(D6O_VENDOR_OPTS)); + ASSERT_TRUE(vendor); + ASSERT_TRUE(vendor->delOption(DOCSIS3_V6_DEVICE_ID)); + + // Ok, there's no more suboption 36. Now getMAC() should fail. + EXPECT_FALSE(pkt->getMAC(Pkt::HWADDR_SOURCE_DOCSIS_MODEM)); +} + +// Test checks whether getMAC(DOCSIS_CMTS) is working properly. +// We only have a small number of actual traffic captures from +// cable networks, so the scope of unit-tests is somewhat limited. +TEST_F(Pkt6Test, getMAC_DOCSIS_CMTS) { + + // Let's use a captured traffic. The one we have comes from a + // modem with MAC address 20:e5:2a:b8:15:14. + Pkt6Ptr pkt = isc::test::PktCaptures::captureeRouterRelayedSolicit(); + ASSERT_NO_THROW(pkt->unpack()); + + // The method should return MAC based on the vendor-specific info, + // suboption 36, which is inserted by the modem itself. + HWAddrPtr found = pkt->getMAC(Pkt::HWADDR_SOURCE_DOCSIS_CMTS); + ASSERT_TRUE(found); + + // Let's check the info. + EXPECT_EQ("hwtype=1 20:e5:2a:b8:15:14", found->toText(true)); + + // Now let's remove the suboption 1026 that is inserted by the + // relay. + OptionVendorPtr vendor = boost::dynamic_pointer_cast< + OptionVendor>(pkt->getAnyRelayOption(D6O_VENDOR_OPTS, + isc::dhcp::Pkt6::RELAY_SEARCH_FROM_CLIENT)); + ASSERT_TRUE(vendor); + EXPECT_TRUE(vendor->delOption(DOCSIS3_V6_CMTS_CM_MAC)); + + EXPECT_FALSE(pkt->getMAC(Pkt::HWADDR_SOURCE_DOCSIS_CMTS)); +} + } diff --git a/src/lib/dhcp/tests/pkt_captures6.cc b/src/lib/dhcp/tests/pkt_captures6.cc index d5dc73614c..b1348d6721 100644 --- a/src/lib/dhcp/tests/pkt_captures6.cc +++ b/src/lib/dhcp/tests/pkt_captures6.cc @@ -117,6 +117,7 @@ Pkt6Ptr isc::test::PktCaptures::captureDocsisRelayedSolicit() { // - IA_NA (iaid=7f000788, t2=0, t2=0) // - IAAddress (::, pref=0,valid=0) // - rapid-commit + // - elapsed // - ORO // - Reconfigure-accept // - Vendor-Class ("docsis3.0")