Commit e1e0c3aa authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3553] Unit-tests added for getMACFromDocsisModem(), getMACfromDocsisCMTS()

parent bcb5369a
......@@ -15,8 +15,8 @@
#include <dhcp/dhcp6.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option.h>
#include <dhcp/option_int.h>
#include <dhcp/option_vendor_class.h>
#include <dhcp/option_vendor.h>
#include <dhcp/pkt6.h>
#include <dhcp/docsis3_option_defs.h>
#include <util/io_utilities.h>
......@@ -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());
}
......
......@@ -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
......
......@@ -21,10 +21,12 @@
#include <dhcp/option6_ia.h>
#include <dhcp/option_int.h>
#include <dhcp/option_int_array.h>
#include <dhcp/option_vendor.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/pkt6.h>
#include <dhcp/hwaddr.h>
#include <dhcp/docsis3_option_defs.h>
#include <dhcp/tests/pkt_captures.h>
#include <util/range_utilities.h>
#include <boost/bind.hpp>
......@@ -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));
}
}
......@@ -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")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment