Browse Source

[3316] Implemented unit test to cover packet with short Vendor Class.

Marcin Siodelski 11 years ago
parent
commit
f665cef1bc

+ 25 - 0
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.

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

+ 24 - 0
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<uint8_t> 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