From: Marcin Siodelski Date: Mon, 10 Feb 2014 14:54:58 +0000 (+0100) Subject: [3316] Implemented unit test to cover packet with short Vendor Class. X-Git-Tag: bind10-1.2.0beta1-release~35^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f665cef1bce4bff3f6493eab063cb95ed3f73d57;p=thirdparty%2Fkea.git [3316] Implemented unit test to cover packet with short Vendor Class. --- diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index b26a7a301c..f799186864 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -1738,6 +1738,31 @@ TEST_F(Dhcpv6SrvTest, clientClassification) { EXPECT_FALSE(sol2->inClass("docsis3.0")); } +// This test checks that the server will handle a Solicit with the Vendor Class +// having a length of 4 (enterprise-id only). +TEST_F(Dhcpv6SrvTest, cableLabsShortVendorClass) { + NakedDhcpv6Srv srv(0); + + // Create a simple Solicit with the 4-byte long vendor class option. + Pkt6Ptr sol = captureCableLabsShortVendorClass(); + + // Simulate that we have received that traffic + srv.fakeReceive(sol); + + // Server will now process to run its normal loop, but instead of calling + // IfaceMgr::receive6(), it will read all packets from the list set by + // fakeReceive() + srv.run(); + + // Get Advertise... + ASSERT_FALSE(srv.fake_sent_.empty()); + Pkt6Ptr adv = srv.fake_sent_.front(); + ASSERT_TRUE(adv); + + // This is sent back to relay, so port is 547 + EXPECT_EQ(DHCP6_SERVER_PORT, adv->getRemotePort()); + +} /// @todo: Add more negative tests for processX(), e.g. extend sanityCheck() test /// to call processX() methods. diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.h b/src/bin/dhcp6/tests/dhcp6_test_utils.h index 17cd9e8cc7..5c6d49978c 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.h +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.h @@ -480,6 +480,7 @@ public: Pkt6Ptr captureRelayedSolicit(); Pkt6Ptr captureDocsisRelayedSolicit(); Pkt6Ptr captureeRouterRelayedSolicit(); + Pkt6Ptr captureCableLabsShortVendorClass(); /// @brief Auxiliary method that sets Pkt6 fields /// diff --git a/src/bin/dhcp6/tests/wireshark.cc b/src/bin/dhcp6/tests/wireshark.cc index cd2909673e..a303035c93 100644 --- a/src/bin/dhcp6/tests/wireshark.cc +++ b/src/bin/dhcp6/tests/wireshark.cc @@ -299,5 +299,29 @@ DHCPv6 return (pkt); } +Pkt6Ptr isc::test::Dhcpv6SrvTest::captureCableLabsShortVendorClass() { + // This is a simple non-relayed Solicit: + // - client-identifier + // - IA_NA + // - Vendor Class (4 bytes) + // - enterprise-id 4491 + // - Vendor-specific Information + // - enterprise-id 4491 + std::string hex_string = + "01671cb90001000e0001000152ea903a08002758f1e80003000c00004bd10000000000" + "000000001000040000118b0011000a0000118b000100020020"; + + std::vector bin; + + // Decode the hex string and store it in bin (which happens + // to be OptionBuffer format) + isc::util::encode::decodeHex(hex_string, bin); + + Pkt6Ptr pkt(new Pkt6(&bin[0], bin.size())); + captureSetDefaultFields(pkt); + return (pkt); + +} + }; // end of isc::test namespace }; // end of isc namespace