From: Tomek Mrugalski Date: Fri, 4 Dec 2015 20:33:23 +0000 (+0100) Subject: [4212] HostID implemented. X-Git-Tag: trac4268a_base^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d0bf8b178385c5edb1babd471888fd545b73d2e;p=thirdparty%2Fkea.git [4212] HostID implemented. --- diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc index 43efb86299..4ab549fd18 100644 --- a/src/lib/dhcpsrv/host.cc +++ b/src/lib/dhcpsrv/host.cc @@ -86,7 +86,7 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len, ipv6_subnet_id_(ipv6_subnet_id), ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()), hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes), - dhcp6_client_classes_(dhcp6_client_classes) { + dhcp6_client_classes_(dhcp6_client_classes), host_id_(0) { // Initialize HWAddr or DUID setIdentifier(identifier, identifier_len, identifier_type); @@ -107,7 +107,7 @@ Host::Host(const std::string& identifier, const std::string& identifier_name, ipv6_subnet_id_(ipv6_subnet_id), ipv4_reservation_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()), hostname_(hostname), dhcp4_client_classes_(dhcp4_client_classes), - dhcp6_client_classes_(dhcp6_client_classes) { + dhcp6_client_classes_(dhcp6_client_classes), host_id_(0) { // Initialize HWAddr or DUID setIdentifier(identifier, identifier_name); diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h index 0f30d59471..f04ec847fd 100644 --- a/src/lib/dhcpsrv/host.h +++ b/src/lib/dhcpsrv/host.h @@ -29,6 +29,9 @@ namespace isc { namespace dhcp { +/// @brief HostID (used only when storing in MySQL or Postgres) +typedef uint64_t HostID; + /// @brief IPv6 reservation for a host. /// /// This class represents a reservation for a host of a single IPv6 @@ -420,6 +423,18 @@ public: /// @brief Returns information about the host in the textual format. std::string toText() const; + /// @brief Sets Host ID (primary key in MySQL and Postgres backends) + /// @param id HostId value + void setHostId(HostID id) { + host_id_ = id; + } + + /// @brief Returns Host ID (primary key in MySQL and Postgres backends) + /// @return id HostId value (or 0 if not set) + HostID getHostId() const { + return (host_id_); + } + private: /// @brief Adds new client class for DHCPv4 or DHCPv6. @@ -455,6 +470,10 @@ private: ClientClasses dhcp4_client_classes_; /// @brief Collection of classes associated with a DHCPv6 client. ClientClasses dhcp6_client_classes_; + + /// @brief HostID (a unique identifier assigned when the host is stored in + /// MySQL or Pgsql) + uint64_t host_id_; }; /// @brief Pointer to the @c Host object. diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc index c67c648328..e9248beb66 100644 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@ -597,4 +597,18 @@ TEST(HostTest, toText) { host->toText()); } +// Test verifies if the host can store HostId properly. +TEST(HostTest, hostId) { + 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"), + "myhost.example.com"))); + EXPECT_EQ(0, host->getHostId()); + + EXPECT_NO_THROW(host->setHostId(12345)); + + EXPECT_EQ(12345, host->getHostId()); +} + } // end of anonymous namespace