BIND 10 trac2414, updated. bd3faa6a3d1d5628509b725ecb61ef91ee3c2bb0 [2414] DUID toText() implemented.

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Oct 30 17:23:40 UTC 2012


The branch, trac2414 has been updated
       via  bd3faa6a3d1d5628509b725ecb61ef91ee3c2bb0 (commit)
       via  4d2adcc95c4a49ff7efa67a1f9e188a9e3e96dca (commit)
       via  53a57b7f2a75f4dded32297f3f95d5700f536036 (commit)
       via  23d08556872bff7288ccd690a09010769639bff1 (commit)
      from  fdcffb798707a238b43f24a7dcc725acc4a4c962 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bd3faa6a3d1d5628509b725ecb61ef91ee3c2bb0
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Tue Oct 30 18:22:50 2012 +0100

    [2414] DUID toText() implemented.

commit 4d2adcc95c4a49ff7efa67a1f9e188a9e3e96dca
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Tue Oct 30 18:19:50 2012 +0100

    [2414] get(), toText() descriptions updated.

commit 53a57b7f2a75f4dded32297f3f95d5700f536036
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Tue Oct 30 18:08:16 2012 +0100

    [2414] T1, T2 fix in Optio6_IA

commit 23d08556872bff7288ccd690a09010769639bff1
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Tue Oct 30 18:07:53 2012 +0100

    [2414] toText() and get() implemented in Subnet

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dhcp/duid.cc                  |   20 +++++++++++++++++++-
 src/lib/dhcp/duid.h                   |    7 +++++--
 src/lib/dhcp/option6_ia.cc            |    2 +-
 src/lib/dhcp/subnet.cc                |    7 +++++++
 src/lib/dhcp/subnet.h                 |   12 ++++++++++++
 src/lib/dhcp/tests/duid_unittest.cc   |    8 ++++++++
 src/lib/dhcp/tests/subnet_unittest.cc |   26 ++++++++++++++++++++++++++
 7 files changed, 78 insertions(+), 4 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/duid.cc b/src/lib/dhcp/duid.cc
index db7ba25..aa06e95 100644
--- a/src/lib/dhcp/duid.cc
+++ b/src/lib/dhcp/duid.cc
@@ -12,11 +12,13 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <vector>
 #include <exceptions/exceptions.h>
 #include <stdint.h>
 #include <util/io_utilities.h>
 #include <dhcp/duid.h>
+#include <vector>
+#include <sstream>
+#include <iomanip>
 
 namespace isc {
 namespace dhcp {
@@ -53,6 +55,22 @@ DUID::DUIDType DUID::getType() const {
     }
 }
 
+std::string DUID::toText() const {
+    std::stringstream tmp;
+
+    bool delim = false;
+    for (std::vector<uint8_t>::const_iterator it = duid_.begin();
+         it != duid_.end(); ++it) {
+        if (delim) {
+            tmp << ":";
+        }
+        tmp.width(2);
+        tmp << std::hex << std::setfill('0') << static_cast<unsigned int>(*it);
+        delim = true;
+    }
+    return (tmp.str());
+}
+
 bool DUID::operator == (const DUID& other) const {
     return (this->duid_ == other.duid_);
 }
diff --git a/src/lib/dhcp/duid.h b/src/lib/dhcp/duid.h
index 5f8ad58..ef7e476 100644
--- a/src/lib/dhcp/duid.h
+++ b/src/lib/dhcp/duid.h
@@ -61,10 +61,13 @@ class DUID {
     /// @brief returns DUID type
     DUIDType getType() const;
 
-    // compares two DUIDs
+    /// returns textual prepresentation (e.g. 00:01:02:03:ff)
+    std::string toText() const;
+
+    /// compares two DUIDs
     bool operator == (const DUID& other) const;
 
-    // compares two DUIDs
+    /// compares two DUIDs
     bool operator != (const DUID& other) const;
 
  protected:
diff --git a/src/lib/dhcp/option6_ia.cc b/src/lib/dhcp/option6_ia.cc
index 65be711..beba75f 100644
--- a/src/lib/dhcp/option6_ia.cc
+++ b/src/lib/dhcp/option6_ia.cc
@@ -29,7 +29,7 @@ namespace isc {
 namespace dhcp {
 
 Option6IA::Option6IA(uint16_t type, uint32_t iaid)
-    :Option(Option::V6, type), iaid_(iaid) {
+    :Option(Option::V6, type), iaid_(iaid), t1_(0), t2_(0) {
 }
 
 Option6IA::Option6IA(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
diff --git a/src/lib/dhcp/subnet.cc b/src/lib/dhcp/subnet.cc
index f6ce1b1..39c7a5f 100644
--- a/src/lib/dhcp/subnet.cc
+++ b/src/lib/dhcp/subnet.cc
@@ -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,
diff --git a/src/lib/dhcp/subnet.h b/src/lib/dhcp/subnet.h
index 894d807..889e24b 100644
--- a/src/lib/dhcp/subnet.h
+++ b/src/lib/dhcp/subnet.h
@@ -279,6 +279,18 @@ public:
     /// @return unique ID for that subnet
     SubnetID getID() const { return (id_); }
 
+    /// @brief returns subnet parameters (prefix and prefix length)
+    ///
+    /// @return (prefix, prefix length) pair
+    std::pair<isc::asiolink::IOAddress, uint8_t> get() {
+        return (std::pair<isc::asiolink::IOAddress, uint8_t>(prefix_, prefix_len_));
+    }
+
+    /// @brief returns textual representation of the subnet (e.g. "2001:db8::/64")
+    ///
+    /// @return textual representation
+    virtual std::string toText();
+
 protected:
     /// @brief protected constructor
     //
diff --git a/src/lib/dhcp/tests/duid_unittest.cc b/src/lib/dhcp/tests/duid_unittest.cc
index aaf6d91..6096acf 100644
--- a/src/lib/dhcp/tests/duid_unittest.cc
+++ b/src/lib/dhcp/tests/duid_unittest.cc
@@ -166,4 +166,12 @@ TEST(ClientIdTest, operators) {
     EXPECT_TRUE(*id1 != *id3);
 }
 
+// Test checks if the toText() returns valid texual representation
+TEST(ClientIdTest, toText) {
+    uint8_t data1[] = {0, 1, 2, 3, 4, 0xff, 0xfe};
+
+    scoped_ptr<DUID> duid1(new DUID(data1, sizeof(data1)));
+    EXPECT_EQ("00:01:02:03:04:ff:fe", duid1->toText());
+}
+
 } // end of anonymous namespace
diff --git a/src/lib/dhcp/tests/subnet_unittest.cc b/src/lib/dhcp/tests/subnet_unittest.cc
index be25bc1..75d9529 100644
--- a/src/lib/dhcp/tests/subnet_unittest.cc
+++ b/src/lib/dhcp/tests/subnet_unittest.cc
@@ -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);
+}
+
 };



More information about the bind10-changes mailing list