Browse Source

[5241] Minor changes after review.

Tomek Mrugalski 7 years ago
parent
commit
71d40d828e

+ 1 - 1
doc/guide/dhcp4-srv.xml

@@ -1007,7 +1007,7 @@ temporarily override a list of interface names and listen on all interfaces.
     ]
     ]
 }
 }
         </screen>
         </screen>
-        The effect is the same than adding the option code in the
+        The effect is the same as if the client added the option code in the
         Parameter Request List option (or its equivalent for vendor
         Parameter Request List option (or its equivalent for vendor
         options) so in:
         options) so in:
         <screen>
         <screen>

+ 1 - 1
doc/guide/dhcp6-srv.xml

@@ -1035,7 +1035,7 @@ temporarily override a list of interface names and listen on all interfaces.
     ]
     ]
 }
 }
         </screen>
         </screen>
-        The effect is the same than adding the option code in the
+        The effect is the same as if the client added the option code in the
         Option Request Option (or its equivalent for vendor options) so in:
         Option Request Option (or its equivalent for vendor options) so in:
         <screen>
         <screen>
 "Dhcp6": {
 "Dhcp6": {

+ 33 - 36
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

@@ -93,8 +93,33 @@ const char* CONFIGS[] = {
         "    \"valid-lifetime\": 4000,"
         "    \"valid-lifetime\": 4000,"
         "    \"interface\": \"eth0\" "
         "    \"interface\": \"eth0\" "
         " } ],"
         " } ],"
-    "\"valid-lifetime\": 4000 }"
+    "\"valid-lifetime\": 4000 }",
-};
+
+    // Configuration 2:
+    // - 1 subnet, 2 global options (one forced with always-send)
+    "{"
+    "    \"interfaces-config\": {"
+    "    \"interfaces\": [ \"*\" ] }, "
+    "    \"rebind-timer\": 2000, "
+    "    \"renew-timer\": 1000, "
+    "    \"valid-lifetime\": 4000, "
+    "    \"subnet4\": [ {"
+    "        \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], "
+    "        \"subnet\": \"192.0.2.0/24\""
+    "    } ], "
+    "    \"option-data\": ["
+    "        {"
+    "            \"name\": \"default-ip-ttl\", "
+    "            \"data\": \"FF\", "
+    "            \"csv-format\": false"
+    "        }, "
+    "        {"
+    "            \"name\": \"ip-forwarding\", "
+    "            \"data\": \"false\", "
+    "            \"always-send\": true"
+    "        }"
+    "    ]"
+    "}" };
 
 
 // This test verifies that the destination address of the response
 // This test verifies that the destination address of the response
 // message is set to giaddr, when giaddr is set to non-zero address
 // message is set to giaddr, when giaddr is set to non-zero address
@@ -751,7 +776,7 @@ TEST_F(Dhcpv4SrvTest, discoverEchoClientId) {
     CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
     CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->add(subnets->at(0));
     CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
     CfgMgr::instance().getStagingCfg()->setEchoClientId(false);
     CfgMgr::instance().commit();
     CfgMgr::instance().commit();
-    
+
     offer = srv.processDiscover(dis);
     offer = srv.processDiscover(dis);
 
 
     // Check if we get response at all
     // Check if we get response at all
@@ -2175,35 +2200,7 @@ TEST_F(Dhcpv4SrvTest, prlPersistency) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
     IfaceMgr::instance().openSockets4();
 
 
-    NakedDhcpv4Srv srv(0);
+    ASSERT_NO_THROW(configure(CONFIGS[2]));
-
-    string config = "{ \"interfaces-config\": {"
-        "    \"interfaces\": [ \"*\" ] }, "
-        "\"rebind-timer\": 2000, "
-        "\"renew-timer\": 1000, "
-        "\"valid-lifetime\": 4000, "
-        "\"subnet4\": [ "
-        "{   \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], "
-        "    \"subnet\": \"192.0.2.0/24\" } ], "
-        "\"option-data\": ["
-        "    {    \"name\": \"default-ip-ttl\", "
-        "         \"data\": \"FF\", "
-        "          \"csv-format\": false }, "
-        "    {    \"name\": \"ip-forwarding\", "
-        "         \"data\": \"false\", "
-        "         \"always-send\": true } ] }";
-
-    ConstElementPtr json;
-    ASSERT_NO_THROW(json = parseDHCP4(config));
-    ConstElementPtr status;
-
-    // Configure the server and make sure the config is accepted
-    EXPECT_NO_THROW(status = configureDhcp4Server(srv, json));
-    ASSERT_TRUE(status);
-    comment_ = config::parseAnswer(rcode_, status);
-    ASSERT_EQ(0, rcode_);
-
-    CfgMgr::instance().commit();
 
 
     // Create a packet with enough to select the subnet and go through
     // Create a packet with enough to select the subnet and go through
     // the DISCOVER processing
     // the DISCOVER processing
@@ -2225,8 +2222,8 @@ TEST_F(Dhcpv4SrvTest, prlPersistency) {
     ASSERT_TRUE(hostname);
     ASSERT_TRUE(hostname);
     query->addOption(hostname);
     query->addOption(hostname);
 
 
-    // Process the query
+    // Let the server process it.
-    Pkt4Ptr response = srv.processDiscover(query);
+    Pkt4Ptr response = srv_.processDiscover(query);
 
 
     // Processing should add an ip-forwarding option
     // Processing should add an ip-forwarding option
     ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));
     ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));
@@ -2240,8 +2237,8 @@ TEST_F(Dhcpv4SrvTest, prlPersistency) {
     prl->addValue(DHO_DEFAULT_IP_TTL);
     prl->addValue(DHO_DEFAULT_IP_TTL);
     query->addOption(prl);
     query->addOption(prl);
 
 
-    // Process query
+    // Let the server process it again.
-    response = srv.processDiscover(query);
+    response = srv_.processDiscover(query);
 
 
     // Processing should add an ip-forwarding option
     // Processing should add an ip-forwarding option
     ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));
     ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));

+ 34 - 35
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -99,7 +99,33 @@ const char* CONFIGS[] = {
     "    \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
     "    \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
     "    \"subnet\": \"2001:db8:1::/48\" "
     "    \"subnet\": \"2001:db8:1::/48\" "
     " } ],"
     " } ],"
-    "\"valid-lifetime\": 4000 }"
+    "\"valid-lifetime\": 4000 }",
+
+    // Configuration 2:
+    // - a single subnet
+    // - two global options (one enforced with always-send)
+    "{"
+    "    \"interfaces-config\": { \"interfaces\": [ \"*\" ] }, "
+    "    \"preferred-lifetime\": 3000, "
+    "    \"rebind-timer\": 2000, "
+    "    \"renew-timer\": 1000, "
+    "    \"valid-lifetime\": 4000, "
+    "    \"subnet6\": [ {"
+    "       \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], "
+    "       \"subnet\": \"2001:db8:1::/48\""
+    "    } ], "
+    "    \"option-data\": ["
+    "    {"
+    "        \"name\": \"dns-servers\", "
+    "        \"data\": \"2001:db8:1234:FFFF::1\""
+    "    }, "
+    "    {"
+    "        \"name\": \"subscriber-id\", "
+    "         \"data\": \"1234\", "
+    "         \"always-send\": true"
+    "    }"
+    "    ]"
+    "}"
 };
 };
 
 
 // This test verifies that incoming SOLICIT can be handled properly when
 // This test verifies that incoming SOLICIT can be handled properly when
@@ -1506,35 +1532,7 @@ TEST_F(Dhcpv6SrvTest, portsRelayedTraffic) {
 TEST_F(Dhcpv6SrvTest, prlPersistency) {
 TEST_F(Dhcpv6SrvTest, prlPersistency) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgrTestConfig test_config(true);
 
 
-    NakedDhcpv6Srv srv(0);
+    ASSERT_NO_THROW(configure(CONFIGS[2]));
-
-    string config = "{ \"interfaces-config\": {"
-        "    \"interfaces\": [ \"*\" ] }, "
-        "\"preferred-lifetime\": 3000, "
-        "\"rebind-timer\": 2000, "
-        "\"renew-timer\": 1000, "
-        "\"valid-lifetime\": 4000, "
-        "\"subnet6\": [ "
-        "{   \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], "
-        "    \"subnet\": \"2001:db8:1::/48\" } ], "
-        "\"option-data\": ["
-        "    {    \"name\": \"dns-servers\", "
-        "         \"data\": \"2001:db8:1234:FFFF::1\" }, "
-        "    {    \"name\": \"subscriber-id\", "
-        "         \"data\": \"1234\", "
-        "         \"always-send\": true } ] }";
-
-    ConstElementPtr json;
-    ASSERT_NO_THROW(json = parseDHCP6(config));
-    ConstElementPtr status;
-
-    // Configure the server and make sure the config is accepted
-    EXPECT_NO_THROW(status = configureDhcp6Server(srv, json));
-    ASSERT_TRUE(status);
-    comment_ = config::parseAnswer(rcode_, status);
-    ASSERT_EQ(0, rcode_);
-
-    CfgMgr::instance().commit();
 
 
     // Create a packet with enough to select the subnet and go through
     // Create a packet with enough to select the subnet and go through
     // the SOLICIT processing
     // the SOLICIT processing
@@ -1551,10 +1549,10 @@ TEST_F(Dhcpv6SrvTest, prlPersistency) {
     oro->addValue(D6O_SNTP_SERVERS);
     oro->addValue(D6O_SNTP_SERVERS);
     sol->addOption(oro);
     sol->addOption(oro);
 
 
-    // Process the solicit
+    // Let the server process it and generate a response.
-    Pkt6Ptr response = srv.processSolicit(sol);
+    Pkt6Ptr response = srv_.processSolicit(sol);
 
 
-    // Processing should add a subscriber-id option
+    // The server should a subscriber-id option
     ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));
     ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));
     // But no dns-servers
     // But no dns-servers
     ASSERT_FALSE(response->getOption(D6O_NAME_SERVERS));
     ASSERT_FALSE(response->getOption(D6O_NAME_SERVERS));
@@ -1566,8 +1564,9 @@ TEST_F(Dhcpv6SrvTest, prlPersistency) {
     oro->addValue(D6O_NAME_SERVERS);
     oro->addValue(D6O_NAME_SERVERS);
     sol->addOption(oro);
     sol->addOption(oro);
 
 
-    // Process solicit
+    // Let the server process it again. This time the name-servers
-    response = srv.processSolicit(sol);
+    // option should be present.
+    response = srv_.processSolicit(sol);
 
 
     // Processing should add a subscriber-id option
     // Processing should add a subscriber-id option
     ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));
     ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));