Browse Source

[4212] HostID implemented.

Tomek Mrugalski 9 years ago
parent
commit
3d0bf8b178
3 changed files with 35 additions and 2 deletions
  1. 2 2
      src/lib/dhcpsrv/host.cc
  2. 19 0
      src/lib/dhcpsrv/host.h
  3. 14 0
      src/lib/dhcpsrv/tests/host_unittest.cc

+ 2 - 2
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);

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

+ 14 - 0
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> 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