interest: Correcting encoding/decoding of Nonce field
Nonce field is now encoded as 4-byte uint8_t value, as defined by
NDN-TLV spec. In addition to that, setNonce will not reset
wireEncoding, rather than just modify the existing wire encoding, if it
is already exists.
Change-Id: Ibec3737ccfba70fec5c0531487782a46fbc5600a
Refs: #1600
diff --git a/tests/unit-tests/test-interest.cpp b/tests/unit-tests/test-interest.cpp
index 6e7c6b4..25f79fa 100644
--- a/tests/unit-tests/test-interest.cpp
+++ b/tests/unit-tests/test-interest.cpp
@@ -36,7 +36,7 @@
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Selectors>));
const uint8_t Interest1[] = {
- 0x05, 0x59, // NDN Interest
+ 0x05, 0x5c, // NDN Interest
0x07, 0x14, // Name
0x08, 0x5, // NameComponent
0x6c, 0x6f, 0x63, 0x61, 0x6c,
@@ -65,8 +65,46 @@
0x79, 0x79, 0x79, 0x79,
0x11, 0x1, // ChildSelector
0x1,
- 0x0a, 0x1, // Nonce
+ 0x0a, 0x4, // Nonce
+ 0x1, 0x0, 0x0, 0x00,
+ 0x0b, 0x1, // Scope
0x1,
+ 0x0c, // InterestLifetime
+ 0x2, 0x3, 0xe8
+};
+
+const uint8_t Interest2[] = {
+ 0x05, 0x5c, // NDN Interest
+ 0x07, 0x14, // Name
+ 0x08, 0x5, // NameComponent
+ 0x6c, 0x6f, 0x63, 0x61, 0x6c,
+ 0x08, 0x3, // NameComponent
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x6, // NameComponent
+ 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
+ 0x09, 0x37, // Selectors
+ 0x0d, 0x1, 0x1, // MinSuffix
+ 0x0e, 0x1, 0x1, // MaxSuffix
+ 0x1c, 0x16, // KeyLocator
+ 0x07, 0x14, // Name
+ 0x08, 0x04,
+ 0x74, 0x65, 0x73, 0x74,
+ 0x08, 0x03,
+ 0x6b, 0x65, 0x79,
+ 0x08, 0x07,
+ 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
+ 0x10, 0x14, // Exclude
+ 0x08, 0x4, // NameComponent
+ 0x61, 0x6c, 0x65, 0x78,
+ 0x08, 0x4, // NameComponent
+ 0x78, 0x78, 0x78, 0x78,
+ 0x13, 0x0, // Any
+ 0x08, 0x4, // NameComponent
+ 0x79, 0x79, 0x79, 0x79,
+ 0x11, 0x1, // ChildSelector
+ 0x1,
+ 0x0a, 0x4, // Nonce
+ 0x2, 0x0, 0x0, 0x00,
0x0b, 0x1, // Scope
0x1,
0x0c, // InterestLifetime
@@ -74,15 +112,16 @@
};
const uint8_t InterestWithLocalControlHeader[] = {
- 0x50, 0x22, 0x51, 0x01, 0x0a, 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61,
- 0x6c, 0x08, 0x03, 0x6e, 0x64, 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09,
- 0x02, 0x12, 0x00, 0x0a, 0x01, 0x01
+ 0x50, 0x25, 0x51, 0x01, 0x0a,
+ 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
+ 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
+ 0x01, 0x00, 0x00, 0x00
};
const uint8_t InterestWithoutLocalControlHeader[] = {
- 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
- 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x01,
- 0x01
+ 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
+ 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
+ 0x01, 0x00, 0x00, 0x00
};
BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
@@ -287,12 +326,22 @@
i.setExclude(exclude);
i.setNonce(1);
+ BOOST_CHECK_EQUAL(i.hasWire(), false);
const Block &wire = i.wireEncode();
+ BOOST_CHECK_EQUAL(i.hasWire(), true);
BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
wire.begin(), wire.end());
-}
+ const uint8_t* originalWire = wire.wire();
+ i.setNonce(2);
+ BOOST_CHECK_EQUAL(i.hasWire(), true);
+ BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
+ BOOST_CHECK_EQUAL(i.hasWire(), true);
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
+ wire.begin(), wire.end());
+}
BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
{