management: add CachingPolicy to LocalControlHeader
Breaks: NFD:commit:9cfeecaa2ffad1a1be79aed2321dcc7d042ecc5f
Breaks: ndnSIM:commit:ffe2586cfc466935c0632a5a64384f0fda709086
Change-Id: Idcce2b7ee9be31b55f9ec16c17e915d93974bff4
Refs: #2183
diff --git a/src/data.cpp b/src/data.cpp
index fc3dfa7..f127a12 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -300,6 +300,15 @@
return *this;
}
+Data&
+Data::setCachingPolicy(nfd::LocalControlHeader::CachingPolicy cachingPolicy)
+{
+ getLocalControlHeader().setCachingPolicy(cachingPolicy);
+ // ! do not reset Data's wire !
+
+ return *this;
+}
+
void
Data::onChanged()
{
diff --git a/src/data.hpp b/src/data.hpp
index 2f56dfc..078938a 100644
--- a/src/data.hpp
+++ b/src/data.hpp
@@ -297,6 +297,12 @@
Data&
setIncomingFaceId(uint64_t incomingFaceId);
+ nfd::LocalControlHeader::CachingPolicy
+ getCachingPolicy() const;
+
+ Data&
+ setCachingPolicy(nfd::LocalControlHeader::CachingPolicy cachingPolicy);
+
public: // EqualityComparable concept
bool
operator==(const Data& other) const;
@@ -387,6 +393,11 @@
return getLocalControlHeader().getIncomingFaceId();
}
+inline nfd::LocalControlHeader::CachingPolicy
+Data::getCachingPolicy() const
+{
+ return getLocalControlHeader().getCachingPolicy();
+}
} // namespace ndn
diff --git a/src/detail/face-impl.hpp b/src/detail/face-impl.hpp
index 6844813..f6d7d91 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -119,11 +119,11 @@
m_pendingInterestTable.push_back(make_shared<PendingInterest>(interest, onData, onTimeout));
- if (!interest->getLocalControlHeader().empty(false, true))
+ if (!interest->getLocalControlHeader().empty(nfd::LocalControlHeader::ENCODE_NEXT_HOP))
{
// encode only NextHopFaceId towards the forwarder
m_face.m_transport->send(interest->getLocalControlHeader()
- .wireEncode(*interest, false, true),
+ .wireEncode(*interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP),
interest->wireEncode());
}
else
@@ -149,10 +149,12 @@
{
this->ensureConnected();
- if (!data->getLocalControlHeader().empty(false, false))
+ if (!data->getLocalControlHeader().empty(nfd::LocalControlHeader::ENCODE_CACHING_POLICY))
{
- m_face.m_transport->send(data->getLocalControlHeader().wireEncode(*data, false, false),
- data->wireEncode());
+ m_face.m_transport->send(
+ data->getLocalControlHeader().wireEncode(*data,
+ nfd::LocalControlHeader::ENCODE_CACHING_POLICY),
+ data->wireEncode());
}
else
{
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index c6c330b..77533df 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -94,7 +94,9 @@
// Local Control Header
LocalControlHeader = 80,
IncomingFaceId = 81,
- NextHopFaceId = 82
+ NextHopFaceId = 82,
+ CachingPolicy = 83,
+ NoCache = 96
};
} // namespace nfd
diff --git a/src/management/nfd-local-control-header.hpp b/src/management/nfd-local-control-header.hpp
index 5f8d667..8108230 100644
--- a/src/management/nfd-local-control-header.hpp
+++ b/src/management/nfd-local-control-header.hpp
@@ -47,9 +47,23 @@
}
};
+ enum EncodeFlags : uint8_t {
+ ENCODE_NONE = 0,
+ ENCODE_INCOMING_FACE_ID = (1 << 0),
+ ENCODE_NEXT_HOP = (1 << 1),
+ ENCODE_CACHING_POLICY = (1 << 2),
+ ENCODE_ALL = 0xff
+ };
+
+ enum CachingPolicy : uint8_t {
+ INVALID_POLICY = 0,
+ NO_CACHE = 1
+ };
+
LocalControlHeader()
: m_incomingFaceId(INVALID_FACE_ID)
, m_nextHopFaceId(INVALID_FACE_ID)
+ , m_cachingPolicy(CachingPolicy::INVALID_POLICY)
{
}
@@ -59,10 +73,9 @@
* @sa wireDecode
*/
explicit
- LocalControlHeader(const Block& wire,
- bool encodeIncomingFaceId = true, bool encodeNextHopFaceId = true)
+ LocalControlHeader(const Block& wire, uint8_t encodeMask = ENCODE_ALL)
{
- wireDecode(wire, encodeIncomingFaceId, encodeNextHopFaceId);
+ wireDecode(wire, encodeMask);
}
/**
@@ -71,8 +84,8 @@
* The caller is responsible of checking whether LocalControlHeader contains
* any information.
*
- * !It is an error to call this method if neither IncomingFaceId nor NextHopFaceId is
- * set, or neither of them is enabled.
+ * !It is an error to call this method if none of IncomingFaceId, NextHopFaceId and CachingPolicy
+ * are set, or neither of them are enabled.
*
* @throws LocalControlHeader::Error when empty LocalControlHeader be produced
*
@@ -86,8 +99,7 @@
*/
template<class U>
inline Block
- wireEncode(const U& payload,
- bool encodeIncomingFaceId, bool encodeNextHopFaceId) const;
+ wireEncode(const U& payload, uint8_t encodeMask = ENCODE_ALL) const;
/**
* @brief Decode from the wire format and set LocalControlHeader on the supplied item
@@ -96,8 +108,7 @@
* LocalControlHeader should be done before calling this method.
*/
inline void
- wireDecode(const Block& wire,
- bool encodeIncomingFaceId = true, bool encodeNextHopFaceId = true);
+ wireDecode(const Block& wire, uint8_t encodeMask = ENCODE_ALL);
inline static const Block&
getPayload(const Block& wire);
@@ -108,10 +119,15 @@
// Getters/setters
bool
- empty(bool encodeIncomingFaceId, bool encodeNextHopFaceId) const
+ empty(uint8_t encodeMask) const
{
- return !((encodeIncomingFaceId && hasIncomingFaceId()) ||
- (encodeNextHopFaceId && hasNextHopFaceId()));
+ bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID;
+ bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP;
+ bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY;
+
+ return !((needIncomingFaceId && hasIncomingFaceId()) ||
+ (needNextHopFaceId && hasNextHopFaceId()) ||
+ (needCachingPolicy && hasCachingPolicy()));
}
//
@@ -154,15 +170,35 @@
m_nextHopFaceId = nextHopFaceId;
}
+ //
+
+ bool
+ hasCachingPolicy() const
+ {
+ return m_cachingPolicy != CachingPolicy::INVALID_POLICY;
+ }
+
+ CachingPolicy
+ getCachingPolicy() const
+ {
+ return m_cachingPolicy;
+ }
+
+ void
+ setCachingPolicy(CachingPolicy cachingPolicy)
+ {
+ m_cachingPolicy = cachingPolicy;
+ }
+
private:
template<encoding::Tag TAG>
inline size_t
- wireEncode(EncodingImpl<TAG>& block, size_t payloadSize,
- bool encodeIncomingFaceId, bool encodeNextHopFaceId) const;
+ wireEncode(EncodingImpl<TAG>& block, size_t payloadSize, uint8_t encodeMask) const;
private:
uint64_t m_incomingFaceId;
uint64_t m_nextHopFaceId;
+ CachingPolicy m_cachingPolicy;
};
@@ -172,22 +208,37 @@
template<encoding::Tag TAG>
inline size_t
LocalControlHeader::wireEncode(EncodingImpl<TAG>& block, size_t payloadSize,
- bool encodeIncomingFaceId, bool encodeNextHopFaceId) const
+ uint8_t encodeMask) const
{
+ bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID;
+ bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP;
+ bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY;
+
size_t totalLength = payloadSize;
- if (encodeIncomingFaceId && hasIncomingFaceId())
+ if (needIncomingFaceId && hasIncomingFaceId())
{
totalLength += prependNonNegativeIntegerBlock(block,
tlv::nfd::IncomingFaceId, getIncomingFaceId());
}
- if (encodeNextHopFaceId && hasNextHopFaceId())
+ if (needNextHopFaceId && hasNextHopFaceId())
{
totalLength += prependNonNegativeIntegerBlock(block,
tlv::nfd::NextHopFaceId, getNextHopFaceId());
}
+ if (needCachingPolicy && hasCachingPolicy())
+ {
+ size_t cachingPolicyLength = 0;
+ cachingPolicyLength += block.prependVarNumber(0);
+ cachingPolicyLength += block.prependVarNumber(tlv::nfd::NoCache);
+ cachingPolicyLength += block.prependVarNumber(cachingPolicyLength);
+ cachingPolicyLength += block.prependVarNumber(tlv::nfd::CachingPolicy);
+
+ totalLength += cachingPolicyLength;
+ }
+
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(tlv::nfd::LocalControlHeader);
return totalLength;
@@ -195,34 +246,34 @@
template<class U>
inline Block
-LocalControlHeader::wireEncode(const U& payload,
- bool encodeIncomingFaceId, bool encodeNextHopFaceId) const
+LocalControlHeader::wireEncode(const U& payload, uint8_t encodeMask) const
{
/// @todo should this be BOOST_ASSERT instead? This is kind of unnecessary overhead
- if (empty(encodeIncomingFaceId, encodeNextHopFaceId))
+ if (empty(encodeMask))
throw Error("Requested wire for LocalControlHeader, but none of the fields are set or enabled");
EncodingEstimator estimator;
- size_t length = wireEncode(estimator, payload.wireEncode().size(),
- encodeIncomingFaceId, encodeNextHopFaceId);
+ size_t length = wireEncode(estimator, payload.wireEncode().size(), encodeMask);
EncodingBuffer buffer(length);
- wireEncode(buffer, payload.wireEncode().size(),
- encodeIncomingFaceId, encodeNextHopFaceId);
+ wireEncode(buffer, payload.wireEncode().size(), encodeMask);
return buffer.block(false);
}
inline void
-LocalControlHeader::wireDecode(const Block& wire,
- bool encodeIncomingFaceId/* = true*/,
- bool encodeNextHopFaceId/* = true*/)
+LocalControlHeader::wireDecode(const Block& wire, uint8_t encodeMask)
{
+ bool needIncomingFaceId = encodeMask & ENCODE_INCOMING_FACE_ID;
+ bool needNextHopFaceId = encodeMask & ENCODE_NEXT_HOP;
+ bool needCachingPolicy = encodeMask & ENCODE_CACHING_POLICY;
+
BOOST_ASSERT(wire.type() == tlv::nfd::LocalControlHeader);
wire.parse();
m_incomingFaceId = INVALID_FACE_ID;
m_nextHopFaceId = INVALID_FACE_ID;
+ m_cachingPolicy = CachingPolicy::INVALID_POLICY;
for (Block::element_const_iterator i = wire.elements_begin();
i != wire.elements_end();
@@ -231,13 +282,25 @@
switch (i->type())
{
case tlv::nfd::IncomingFaceId:
- if (encodeIncomingFaceId)
+ if (needIncomingFaceId)
m_incomingFaceId = readNonNegativeInteger(*i);
break;
case tlv::nfd::NextHopFaceId:
- if (encodeNextHopFaceId)
+ if (needNextHopFaceId)
m_nextHopFaceId = readNonNegativeInteger(*i);
break;
+ case tlv::nfd::CachingPolicy:
+ if (needCachingPolicy) {
+ i->parse();
+ Block::element_const_iterator it = i->elements_begin();
+ if (it != i->elements_end() && it->type() == tlv::nfd::NoCache) {
+ m_cachingPolicy = CachingPolicy::NO_CACHE;
+ }
+ else {
+ throw Error("CachingPolicy: Missing required NoCache field");
+ }
+ }
+ break;
default:
// ignore all unsupported
break;
@@ -262,7 +325,6 @@
}
}
-
} // namespace nfd
} // namespace ndn
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index f5e1172..24348e9 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -169,9 +169,10 @@
DummyClientFace::receive(const Packet& packet)
{
// do not restrict what injected control header can contain
- if (!packet.getLocalControlHeader().empty(true, true)) {
+ if (!packet.getLocalControlHeader().empty(nfd::LocalControlHeader::ENCODE_ALL)) {
- Block header = packet.getLocalControlHeader().wireEncode(packet, true, true);
+ Block header = packet.getLocalControlHeader().wireEncode(packet,
+ nfd::LocalControlHeader::ENCODE_ALL);
Block payload = packet.wireEncode();
EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
diff --git a/tests/unit-tests/test-data.cpp b/tests/unit-tests/test-data.cpp
index 2493b89..2f8329b 100644
--- a/tests/unit-tests/test-data.cpp
+++ b/tests/unit-tests/test-data.cpp
@@ -120,6 +120,19 @@
0x0a, 0xb6
};
+const uint8_t DataWithLocalControlHeader[] = {
+ 0x50, 0x29, 0x53, 0x02, 0x60, 0x00,
+ 0x06, 0x23, 0x07, 0x03, 0x08, 0x01, 0x41, 0x14, 0x04, 0x19, 0x02, 0x27, 0x10, 0x15,
+ 0x09, 0x73, 0x6F, 0x6D, 0x65, 0x44, 0x61, 0x74, 0x61, 0x00, 0x16, 0x05, 0x1B, 0x01,
+ 0x01, 0x1C, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00
+};
+
+const uint8_t DataWithoutLocalControlHeader[] = {
+ 0x06, 0x23, 0x07, 0x03, 0x08, 0x01, 0x41, 0x14, 0x04, 0x19, 0x02, 0x27, 0x10, 0x15,
+ 0x09, 0x73, 0x6F, 0x6D, 0x65, 0x44, 0x61, 0x74, 0x61, 0x00, 0x16, 0x05, 0x1B, 0x01,
+ 0x01, 0x1C, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00
+};
+
BOOST_AUTO_TEST_CASE(DataEqualityChecks)
{
using namespace time;
@@ -200,6 +213,114 @@
BOOST_CHECK_EQUAL(a != b, false);
}
+BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
+{
+ Data data("ndn:/A");
+ data.setFreshnessPeriod(time::seconds(10));
+ static const uint8_t someData[] = "someData";
+ data.setContent(someData, sizeof(someData));
+ data.setSignature(SignatureSha256WithRsa());
+ data.setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
+
+ BOOST_CHECK(!data.hasWire());
+
+ Block headerBlock =
+ data.getLocalControlHeader().wireEncode(data, nfd::LocalControlHeader::ENCODE_CACHING_POLICY);
+
+ BOOST_CHECK(data.hasWire());
+ BOOST_CHECK(headerBlock.hasWire());
+
+ BOOST_CHECK_NE(headerBlock.wire(), data.wireEncode().wire());
+ BOOST_CHECK_NE(headerBlock.size(), data.wireEncode().size());
+ BOOST_CHECK_EQUAL(headerBlock.size(), 6);
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(DataWithLocalControlHeader,
+ DataWithLocalControlHeader + 6,
+ headerBlock.begin(), headerBlock.end());
+
+ data.setFreshnessPeriod(time::seconds(1000));
+
+ Block updatedHeaderBlock = data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_CACHING_POLICY);
+ BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
+
+ // only length should have changed
+ BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(),
+ headerBlock.begin() + 2, headerBlock.end());
+
+ // adding IncomingFaceId
+ data.setIncomingFaceId(10);
+ updatedHeaderBlock =
+ data.getLocalControlHeader().wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID
+ | nfd::LocalControlHeader::ENCODE_CACHING_POLICY);
+ BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
+
+ // masking CachingPolicy
+ updatedHeaderBlock = data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID);
+ BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
+
+ // masking everything
+ BOOST_CHECK_THROW(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_NONE),
+ nfd::LocalControlHeader::Error);
+}
+
+BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader)
+{
+ Block wireBlock(DataWithLocalControlHeader, sizeof(DataWithLocalControlHeader));
+ const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
+ BOOST_REQUIRE_NE(&payload, &wireBlock);
+
+ BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(tlv::Data));
+ BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader));
+
+ Data data(payload);
+ BOOST_CHECK(!data.getLocalControlHeader().hasCachingPolicy());
+ BOOST_CHECK(!data.getLocalControlHeader().hasIncomingFaceId());
+
+ data.getLocalControlHeader().wireDecode(wireBlock);
+
+ BOOST_CHECK_EQUAL(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_CACHING_POLICY).size(),
+ 6);
+
+ BOOST_CHECK(data.getLocalControlHeader().hasCachingPolicy());
+ BOOST_CHECK(!data.getLocalControlHeader().hasIncomingFaceId());
+
+ BOOST_CHECK_THROW(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_NONE),
+ nfd::LocalControlHeader::Error);
+
+ BOOST_CHECK_THROW(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID),
+ nfd::LocalControlHeader::Error);
+
+ BOOST_CHECK_NO_THROW(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_CACHING_POLICY));
+ BOOST_CHECK_NO_THROW(
+ data.getLocalControlHeader().wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_CACHING_POLICY));
+
+ BOOST_CHECK_NE((void*)data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_CACHING_POLICY)
+ .wire(),
+ (void*)wireBlock.wire());
+
+ BOOST_CHECK_EQUAL(data.getLocalControlHeader()
+ .wireEncode(data, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_CACHING_POLICY).size(),
+ 6);
+}
+
+BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)
+{
+ Block wireBlock(DataWithoutLocalControlHeader, sizeof(DataWithoutLocalControlHeader));
+ const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
+ BOOST_CHECK_EQUAL(&payload, &wireBlock);
+}
+
class TestDataFixture
{
public:
diff --git a/tests/unit-tests/test-face.cpp b/tests/unit-tests/test-face.cpp
index b519d5c..e901e54 100644
--- a/tests/unit-tests/test-face.cpp
+++ b/tests/unit-tests/test-face.cpp
@@ -367,6 +367,7 @@
Interest i("/Hello/World");
i.setNextHopFaceId(1000);
i.setIncomingFaceId(2000);
+ i.getLocalControlHeader().setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
face->expressInterest(i, bind([]{}), bind([]{}));
advanceClocks(time::milliseconds(10));
@@ -375,6 +376,7 @@
// only NextHopFaceId is allowed to go out
BOOST_CHECK(face->sentInterests[0].getLocalControlHeader().hasNextHopFaceId());
BOOST_CHECK(!face->sentInterests[0].getLocalControlHeader().hasIncomingFaceId());
+ BOOST_CHECK(!face->sentInterests[0].getLocalControlHeader().hasCachingPolicy());
BOOST_CHECK_EQUAL(face->sentInterests[0].getNextHopFaceId(), 1000);
}
@@ -384,8 +386,11 @@
[] (const InterestFilter&, const Interest& i) {
BOOST_CHECK(i.getLocalControlHeader().hasNextHopFaceId());
BOOST_CHECK(i.getLocalControlHeader().hasIncomingFaceId());
+ BOOST_CHECK(i.getLocalControlHeader().hasCachingPolicy());
BOOST_CHECK_EQUAL(i.getNextHopFaceId(), 1000);
BOOST_CHECK_EQUAL(i.getIncomingFaceId(), 2000);
+ BOOST_CHECK_EQUAL(i.getLocalControlHeader().getCachingPolicy(),
+ nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
},
bind([]{}),
bind([] {
@@ -396,6 +401,7 @@
Interest i("/Hello/World/!");
i.setNextHopFaceId(1000);
i.setIncomingFaceId(2000);
+ i.getLocalControlHeader().setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
face->receive(i);
advanceClocks(time::milliseconds(10));
@@ -405,8 +411,8 @@
{
shared_ptr<Data> d = util::makeData("/Bye/World/!");
d->setIncomingFaceId(2000);
- d->getLocalControlHeader().setNextHopFaceId(1000); // setNextHopFaceId is intentionally
- // not exposed directly
+ d->getLocalControlHeader().setNextHopFaceId(1000);
+ d->setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
face->put(*d);
advanceClocks(time::milliseconds(10));
@@ -414,6 +420,9 @@
BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
BOOST_CHECK(!face->sentDatas[0].getLocalControlHeader().hasNextHopFaceId());
BOOST_CHECK(!face->sentDatas[0].getLocalControlHeader().hasIncomingFaceId());
+ BOOST_CHECK(face->sentDatas[0].getLocalControlHeader().hasCachingPolicy());
+ BOOST_CHECK_EQUAL(face->sentDatas[0].getCachingPolicy(),
+ nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
}
BOOST_AUTO_TEST_CASE(ReceiveDataWithLocalControlHeader)
@@ -422,6 +431,9 @@
[&] (const Interest& i, const Data& d) {
BOOST_CHECK(d.getLocalControlHeader().hasNextHopFaceId());
BOOST_CHECK(d.getLocalControlHeader().hasIncomingFaceId());
+ BOOST_CHECK(d.getLocalControlHeader().hasCachingPolicy());
+ BOOST_CHECK_EQUAL(d.getCachingPolicy(),
+ nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
BOOST_CHECK_EQUAL(d.getIncomingFaceId(), 2000);
BOOST_CHECK_EQUAL(d.getLocalControlHeader().getNextHopFaceId(), 1000);
},
@@ -433,8 +445,8 @@
shared_ptr<Data> d = util::makeData("/Hello/World/!");
d->setIncomingFaceId(2000);
- d->getLocalControlHeader().setNextHopFaceId(1000); // setNextHopFaceId is intentionally
- // not exposed directly
+ d->getLocalControlHeader().setNextHopFaceId(1000);
+ d->setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
face->receive(*d);
advanceClocks(time::milliseconds(10), 100);
diff --git a/tests/unit-tests/test-interest.cpp b/tests/unit-tests/test-interest.cpp
index 71d6d29..7151c56 100644
--- a/tests/unit-tests/test-interest.cpp
+++ b/tests/unit-tests/test-interest.cpp
@@ -365,7 +365,10 @@
BOOST_CHECK(!interest.hasWire());
- Block headerBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
+ Block headerBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK(interest.hasWire());
BOOST_CHECK(headerBlock.hasWire());
@@ -380,7 +383,10 @@
interest.setNonce(1000);
- Block updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
+ Block updatedHeaderBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
// only length should have changed
@@ -389,30 +395,43 @@
// updating IncomingFaceId that keeps the length
interest.setIncomingFaceId(100);
- updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
+ updatedHeaderBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4));
// updating IncomingFaceId that increases the length by 2
interest.setIncomingFaceId(1000);
- updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
+ updatedHeaderBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
// adding NextHopId
interest.setNextHopFaceId(1);
- updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
+ updatedHeaderBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
// masking IncomingFaceId
- updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, false, true);
+ updatedHeaderBlock = interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
// masking NextHopId
- updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, false);
+ updatedHeaderBlock =
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID);
BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
// masking everything
- BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
+ BOOST_CHECK_THROW(interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
nfd::LocalControlHeader::Error);
}
@@ -432,24 +451,42 @@
BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock));
- BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
+ BOOST_CHECK_EQUAL(
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
+ 5);
BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10);
BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
- BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
+ BOOST_CHECK_THROW(interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
nfd::LocalControlHeader::Error);
- BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, true),
+ BOOST_CHECK_THROW(interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP),
nfd::LocalControlHeader::Error);
- BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, false));
- BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, true));
+ BOOST_CHECK_NO_THROW(
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID));
+ BOOST_CHECK_NO_THROW(
+ interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP));
- BOOST_CHECK_NE((void*)interest.getLocalControlHeader().wireEncode(interest, true, true).wire(),
- (void*)wireBlock.wire());
+ BOOST_CHECK_NE(
+ (void*)interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP)
+ .wire(),
+ (void*)wireBlock.wire());
- BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
+ BOOST_CHECK_EQUAL(interest.getLocalControlHeader()
+ .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
+ nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
+ 5);
}
BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)