Browse Source

[3560] Added new accessors and modifiers to the Host class.

Marcin Siodelski 10 years ago
parent
commit
46918f31b4
2 changed files with 51 additions and 1 deletions
  1. 31 1
      src/lib/dhcpsrv/host.h
  2. 20 0
      src/lib/dhcpsrv/tests/host_unittest.cc

+ 31 - 1
src/lib/dhcpsrv/host.h

@@ -113,7 +113,7 @@ typedef std::pair<IPv6ResrvIterator, IPv6ResrvIterator> 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_);

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