From: Marcin Siodelski Date: Mon, 13 Oct 2014 17:37:38 +0000 (+0200) Subject: [3560] Added new accessors and modifiers to the Host class. X-Git-Tag: trac3162a_base~3^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46918f31b4e8676c0c02e46583774d26f3c8ecd2;p=thirdparty%2Fkea.git [3560] Added new accessors and modifiers to the Host class. --- diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h index d30d51aff3..64b2934147 100644 --- a/src/lib/dhcpsrv/host.h +++ b/src/lib/dhcpsrv/host.h @@ -113,7 +113,7 @@ typedef std::pair IPv6ResrvRange; /// @brief Represents a device with IPv4 and/or IPv6 reservations. /// -/// This class represents a device in the network which can be identified +/// This class represents a network device which can be identified /// by the unique property, such as MAC address on the interface or /// client identifier (DUID), and for which some resources are statically /// assigned: @@ -260,6 +260,20 @@ public: return (duid_); } + /// @brief Sets new IPv4 subnet identifier. + /// + /// @param ipv4_subnet_id New subnet identifier. + void setIPv4SubnetID(const SubnetID ipv4_subnet_id) { + ipv4_subnet_id_ = ipv4_subnet_id; + } + + /// @brief Sets new IPv6 subnet identifier. + /// + /// @param ipv6_subnet_id New subnet identifier. + void setIPv6SubnetID(const SubnetID ipv6_subnet_id) { + ipv6_subnet_id_ = ipv6_subnet_id; + } + /// @brief Returns subnet identifier for IPv4 reservation. SubnetID getIPv4SubnetID() const { return (ipv4_subnet_id_); @@ -270,6 +284,15 @@ public: return (ipv6_subnet_id_); } + /// @brief Sets new IPv4 reservation. + /// + /// The new reservation removes a previous reservation. + /// + /// @param address Address to be reserved for the client. + void setIPv4Reservation(const asiolink::IOAddress& address) { + ipv4_reservation_ = address; + } + /// @brief Returns reserved IPv4 address. /// /// @return IPv4 address or 0.0.0.0 if no IPv4 reservation specified. @@ -290,6 +313,13 @@ public: /// the specified type. IPv6ResrvRange getIPv6Reservations(const IPv6Resrv::Type& type) const; + /// @brief Sets new hostname. + /// + /// @param hostname New hostname. + void setHostname(const std::string& hostname) { + hostname_ = hostname; + } + /// @brief Returns reserved hostname. const std::string& getHostname() const { return (hostname_); diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc index 267b25a67f..60d301437e 100644 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@ -341,5 +341,25 @@ TEST(HostTest, addReservations) { prefixes)); } +// This test checks that various modifiers may be used to replace the current +// values of the Host class. +TEST(HostTest, setValues) { + boost::scoped_ptr 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")))); + + ASSERT_EQ(1, host->getIPv4SubnetID()); + ASSERT_EQ(2, host->getIPv6SubnetID()); + ASSERT_EQ("192.0.2.3", host->getIPv4Reservation().toText()); + + host->setIPv4SubnetID(SubnetID(123)); + host->setIPv6SubnetID(SubnetID(234)); + host->setIPv4Reservation(IOAddress("10.0.0.1")); + + EXPECT_EQ(123, host->getIPv4SubnetID()); + EXPECT_EQ(234, host->getIPv6SubnetID()); + EXPECT_EQ("10.0.0.1", host->getIPv4Reservation().toText()); +} } // end of anonymous namespace