]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2414] toText() and get() implemented in Subnet
authorTomek Mrugalski <tomasz@isc.org>
Tue, 30 Oct 2012 17:07:53 +0000 (18:07 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 30 Oct 2012 17:07:53 +0000 (18:07 +0100)
src/lib/dhcp/subnet.cc
src/lib/dhcp/subnet.h
src/lib/dhcp/tests/subnet_unittest.cc

index f6ce1b154aa60cbfaa359779632212ef4c534146..39c7a5fcadf4766e61891582a6692baca6379ddb 100644 (file)
@@ -15,6 +15,7 @@
 #include <dhcp/addr_utilities.h>
 #include <asiolink/io_address.h>
 #include <dhcp/subnet.h>
+#include <sstream>
 
 using namespace isc::asiolink;
 
@@ -52,6 +53,12 @@ Subnet::delOptions() {
     options_.clear();
 }
 
+std::string Subnet::toText() {
+    std::stringstream tmp;
+    tmp << prefix_.toText() << "/" << static_cast<unsigned int>(prefix_len_);
+    return (tmp.str());
+}
+
 Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
                  const Triplet<uint32_t>& t1,
                  const Triplet<uint32_t>& t2,
index 894d8079905e275c39110b78a77dbfbfb0e7f332..b009b3cde0136c4d3a2c2285b95212733ea79dcf 100644 (file)
@@ -279,6 +279,12 @@ public:
     /// @return unique ID for that subnet
     SubnetID getID() const { return (id_); }
 
+    std::pair<isc::asiolink::IOAddress, uint8_t> get() {
+        return (std::pair<isc::asiolink::IOAddress, uint8_t>(prefix_, prefix_len_));
+    }
+
+    virtual std::string toText();
+
 protected:
     /// @brief protected constructor
     //
index be25bc1ac9b6a34392a63a471900cff9bdb453c0..75d9529d301f4fc1cdbeb5476c1f3ef5bae53c57 100644 (file)
@@ -158,6 +158,19 @@ TEST(Subnet4Test, inRangeinPool) {
     EXPECT_FALSE(subnet->inPool(IOAddress("192.3.0.0")));
 }
 
+// This test checks if the toText() method returns text representation
+TEST(Subnet4Test, toText) {
+    Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3));
+    EXPECT_EQ("192.0.2.0/24", subnet->toText());
+}
+
+// This test checks if the get() method returns proper parameters
+TEST(Subnet4Test, get) {
+    Subnet4Ptr subnet(new Subnet4(IOAddress("192.0.2.0"), 28, 1, 2, 3));
+    EXPECT_EQ("192.0.2.0", subnet->get().first.toText());
+    EXPECT_EQ(28, subnet->get().second);
+}
+
 // Tests for Subnet6
 
 TEST(Subnet6Test, constructor) {
@@ -418,4 +431,17 @@ TEST(Subnet6Test, inRangeinPool) {
     EXPECT_FALSE(subnet->inPool(IOAddress("2001:db8::21")));
 }
 
+// This test checks if the toText() method returns text representation
+TEST(Subnet6Test, toText) {
+    Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));
+    EXPECT_EQ("2001:db8::/32", subnet->toText());
+}
+
+// This test checks if the get() method returns proper parameters
+TEST(Subnet6Test, get) {
+    Subnet6Ptr subnet(new Subnet6(IOAddress("2001:db8::"), 32, 1, 2, 3, 4));
+    EXPECT_EQ("2001:db8::", subnet->get().first.toText());
+    EXPECT_EQ(32, subnet->get().second);
+}
+
 };