BIND 10 trac2976, updated. 87fc0368a47156638c189fbf071471ee0d9c4463 [2976] Implemented the rest of the toWire test.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Jun 21 18:13:08 UTC 2013


The branch, trac2976 has been updated
       via  87fc0368a47156638c189fbf071471ee0d9c4463 (commit)
      from  2b6d8c99eedfc5e77477461963bff7ae031192bf (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 87fc0368a47156638c189fbf071471ee0d9c4463
Author: Marcin Siodelski <marcin at isc.org>
Date:   Fri Jun 21 20:12:56 2013 +0200

    [2976] Implemented the rest of the toWire test.

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

Summary of changes:
 src/bin/d2/tests/d2_update_message_unittests.cc |   81 ++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 2 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/d2/tests/d2_update_message_unittests.cc b/src/bin/d2/tests/d2_update_message_unittests.cc
index 020e6b3..9d8e9ad 100644
--- a/src/bin/d2/tests/d2_update_message_unittests.cc
+++ b/src/bin/d2/tests/d2_update_message_unittests.cc
@@ -49,17 +49,26 @@ public:
     // @param buf input buffer, its internal pointer will be moved to
     //        the position after a name being read from it.
     // @param name_length length of the name stored in the buffer
+    // @param no_zero_byte if true it indicates that the given buffer does not
+    //        comprise the zero byte, which signals end of the name. This is
+    //        the case, when dealing with compressed messages which don't have
+    //        this byte.
     //
     // @return string representation of the name.
-    std::string readNameFromWire(InputBuffer& buf, const size_t name_length) {
+    std::string readNameFromWire(InputBuffer& buf, size_t name_length,
+                                 bool no_zero_byte = false) {
         // 64 characters bytes should be sufficent for current tests.
         // It may be extended if required.
         char name_data[64];
         // Create another InputBuffer which holds only the name in the wire
         // format.
         buf.readData(name_data, name_length);
+        if (no_zero_byte) {
+            ++name_length;
+            name_data[name_length-1] = 0;
+        }
         InputBuffer name_buf(name_data, name_length);
-        // Parse the name and returns its textual representation.
+        // Parse the name and return its textual representation.
         Name name(name_buf);
         return (name.toText());
     }
@@ -193,6 +202,74 @@ TEST_F(D2UpdateMessageTest, toWire) {
     // In case of this message, we expect to have two prerequisite RRs.
     // Their structure is checked below.
 
+    // First prerequisite should comprise the 'Name is not in use prerequisite'
+    // for 'foo.example.com'.
+
+    // Check the name first. Message renderer is using compression for domain
+    // names as described in RFC 1035, section 4.1.4. The name in this RR is
+    // foo.example.com. The name of the zone is example.com and it has occured
+    // in this message already at offset 12 (the size of the header is 12).
+    // Therefore, name of this RR is encoded as 'foo', followed by a pointer
+    // to offset in this message where the remainder of this name was used.
+    // This pointer has the following format:
+    // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+    // | 1  1|                 OFFSET                  |
+    // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+    // | 1  1| 0  0  0  0  0  0  0  0  0  0  1  1  0  0|
+    // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+    // which has a following hexadecimal representation: 0xC00C
+
+    // Let's read the non-compressed part first - 'foo.'
+    std::string name_prereq1 = readNameFromWire(buf, 4, true);
+    EXPECT_EQ("foo.", name_prereq1);
+    // The remaining two bytes hold the pointer to 'example.com'.
+    EXPECT_EQ(0xC00C, buf.readUint16());
+    // TYPE is ANY
+    EXPECT_EQ(RRType::ANY().getCode(), buf.readUint16());
+    // CLASS is NONE
+    EXPECT_EQ(RRClass::NONE().getCode(), buf.readUint16());
+    // TTL is a 32-but value, expecting 0
+    EXPECT_EQ(0, buf.readUint32());
+    // There is no RDATA, so RDLENGTH is 0
+    EXPECT_EQ(0, buf.readUint16());
+
+    // Start checking second prerequisite.
+
+    std::string name_prereq2 = readNameFromWire(buf, 4, true);
+    EXPECT_EQ("bar.", name_prereq2);
+    // The remaining two bytes hold the pointer to 'example.com'.
+    EXPECT_EQ(0xC00C, buf.readUint16());
+    // TYPE is ANY
+    EXPECT_EQ(RRType::ANY().getCode(), buf.readUint16());
+    // CLASS is ANY
+    EXPECT_EQ(RRClass::ANY().getCode(), buf.readUint16());
+    // TTL is a 32-but value, expecting 0
+    EXPECT_EQ(0, buf.readUint32());
+    // There is no RDATA, so RDLENGTH is 0
+    EXPECT_EQ(0, buf.readUint16());
+
+    // Start checking Update section. This section contains RRset with
+    // one A RR.
+
+    // The name of the RR is 'foo.example.com'. It is encoded in the
+    // compressed format - as a pointer to the name of prerequisite 1.
+    // This name is in offset 0x1D in this message.
+    EXPECT_EQ(0xC01D, buf.readUint16());
+    // TYPE is A
+    EXPECT_EQ(RRType::A().getCode(), buf.readUint16());
+    // CLASS is IN (same as zone class)
+    EXPECT_EQ(RRClass::IN().getCode(), buf.readUint16());
+    // TTL is a 32-but value, set here to 10.
+    EXPECT_EQ(10, buf.readUint32());
+    // For A records, the RDATA comprises the 4-byte Internet address.
+    // So, RDLENGTH is 4.
+    EXPECT_EQ(4, buf.readUint16());
+    // We have stored the following address in RDATA field: 10.10.1.1
+    // (which is 0A 0A 01 01) in hexadecimal format.
+    EXPECT_EQ(0x0A0A0101, buf.readUint32());
+
+    // @todo: consider extending this test to verify Additional Data
+    // section.
 }
 
 } // End of anonymous namespace



More information about the bind10-changes mailing list