]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Finished merge of trac5452 (unparse subnets)
authorFrancis Dupont <fdupont@isc.org>
Sun, 31 Dec 2017 09:28:48 +0000 (10:28 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sun, 31 Dec 2017 09:28:48 +0000 (10:28 +0100)
1  2 
doc/guide/dhcp4-srv.xml
doc/guide/dhcp6-srv.xml
doc/guide/hooks.xml
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/tests/host_unittest.cc

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index bc17bb13f4c71fa4af526bd86f7d20d41efce1a6,df9501da3e153f97b7788a028ce562e6ee7c225a..d3603fbae7197b9a9f391f3b60d2ecdcefaac96e
@@@ -1031,164 -1010,9 +1031,164 @@@ TEST_F(HostTest, toText) 
                host->toText());
  }
  
 +// This test checks that Host object is correctly unparsed,
 +TEST_F(HostTest, unparse) {
 +    boost::scoped_ptr<Host> host;
 +    ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address",
 +                                        SubnetID(1), SubnetID(2),
 +                                        IOAddress("192.0.2.3"),
 +                                        "myhost.example.com")));
 +
 +    // Add 4 reservations: 2 for NAs, 2 for PDs.
 +    ASSERT_NO_THROW(
 +        host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
 +                                       IOAddress("2001:db8:1::cafe")));
 +        host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
 +                                       IOAddress("2001:db8:1:1::"), 64));
 +        host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
 +                                       IOAddress("2001:db8:1:2::"), 64));
 +        host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA,
 +                                       IOAddress("2001:db8:1::1")));
 +    );
 +
 +    // Add user context
 +    std::string user_context = "{ \"comment\": \"a host reservation\" }";
 +    host->setContext(Element::fromJSON(user_context));
 +
 +    // Make sure that the output is correct,
 +    EXPECT_EQ("{ "
 +              "\"boot-file-name\": \"\", "
 +              "\"client-classes\": [  ], "
 +              "\"comment\": \"a host reservation\", "
 +              "\"hostname\": \"myhost.example.com\", "
 +              "\"hw-address\": \"01:02:03:04:05:06\", "
 +              "\"ip-address\": \"192.0.2.3\", "
 +              "\"next-server\": \"0.0.0.0\", "
 +              "\"option-data\": [  ], "
 +              "\"server-hostname\": \"\" "
 +              "}",
 +              host->toElement4()->str());
 +
 +    EXPECT_EQ("{ "
 +              "\"client-classes\": [  ], "
 +              "\"comment\": \"a host reservation\", "
 +              "\"hostname\": \"myhost.example.com\", "
 +              "\"hw-address\": \"01:02:03:04:05:06\", "
 +              "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], "
 +              "\"option-data\": [  ], "
 +              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] "
 +              "}",
 +              host->toElement6()->str());
 +
 +    // Reset some of the data and make sure that the output is affected.
 +    host->setHostname("");
 +    host->removeIPv4Reservation();
 +    host->setIPv4SubnetID(0);
 +
 +    EXPECT_EQ("{ "
 +              "\"boot-file-name\": \"\", "
 +              "\"client-classes\": [  ], "
 +              "\"comment\": \"a host reservation\", "
 +              "\"hostname\": \"\", "
 +              "\"hw-address\": \"01:02:03:04:05:06\", "
 +              "\"next-server\": \"0.0.0.0\", "
 +              "\"option-data\": [  ], "
 +              "\"server-hostname\": \"\" "
 +              "}",
 +              host->toElement4()->str());
 +
 +    EXPECT_EQ("{ "
 +              "\"client-classes\": [  ], "
 +              "\"comment\": \"a host reservation\", "
 +              "\"hostname\": \"\", "
 +              "\"hw-address\": \"01:02:03:04:05:06\", "
 +              "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], "
 +              "\"option-data\": [  ], "
 +              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] "
 +              "}",
 +              host->toElement6()->str());
 +
 +    // Create host identified by DUID, instead of HWADDR, with a very
 +    // basic configuration.
 +    ASSERT_NO_THROW(host.reset(new Host("11:12:13:14:15", "duid",
 +                                        SubnetID(0), SubnetID(0),
 +                                        IOAddress::IPV4_ZERO_ADDRESS(),
 +                                        "myhost")));
 +
 +    EXPECT_EQ("{ "
 +              "\"boot-file-name\": \"\", "
 +              "\"client-classes\": [  ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"next-server\": \"0.0.0.0\", "
 +              "\"option-data\": [  ], "
 +              "\"server-hostname\": \"\" "
 +              "}",
 +              host->toElement4()->str());
 +
 +    EXPECT_EQ("{ "
 +              "\"client-classes\": [  ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"ip-addresses\": [  ], "
 +              "\"option-data\": [  ], "
 +              "\"prefixes\": [  ] "
 +              "}",
 +              host->toElement6()->str());
 +
 +    // Add some classes.
 +    host->addClientClass4("modem");
 +    host->addClientClass4("router");
 +
 +    EXPECT_EQ("{ "
 +              "\"boot-file-name\": \"\", "
 +              "\"client-classes\": [ \"modem\", \"router\" ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"next-server\": \"0.0.0.0\", "
 +              "\"option-data\": [  ], "
 +              "\"server-hostname\": \"\" "
 +              "}",
 +              host->toElement4()->str());
 +
 +    EXPECT_EQ("{ "
 +              "\"client-classes\": [  ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"ip-addresses\": [  ], "
 +              "\"option-data\": [  ], "
 +              "\"prefixes\": [  ] "
 +              "}",
 +              host->toElement6()->str());
 +
 +    host->addClientClass6("hub");
 +    host->addClientClass6("device");
 +
 +    EXPECT_EQ("{ "
 +              "\"boot-file-name\": \"\", "
 +              "\"client-classes\": [ \"modem\", \"router\" ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"next-server\": \"0.0.0.0\", "
 +              "\"option-data\": [  ], "
 +              "\"server-hostname\": \"\" "
 +              "}",
 +              host->toElement4()->str());
 +
 +    EXPECT_EQ("{ "
 +              "\"client-classes\": [ \"device\", \"hub\" ], "
 +              "\"duid\": \"11:12:13:14:15\", "
 +              "\"hostname\": \"myhost\", "
 +              "\"ip-addresses\": [  ], "
 +              "\"option-data\": [  ], "
 +              "\"prefixes\": [  ] "
 +              "}",
 +              host->toElement6()->str());
 +}
 +
  // Test verifies if the host can store HostId properly.
  TEST_F(HostTest, hostId) {
-     boost::scoped_ptr<Host> host;
+     HostPtr host;
      ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address",
                                          SubnetID(1), SubnetID(2),
                                          IOAddress("192.0.2.3"),