face: use IncomingFaceId, NextHopFaceId, CachePolicy tags
This commit replaces all LocalControlHeader usages with these tags,
and deletes LocalFace.
This commit also does minor improvements in RIB test suites.
refs #3339
Change-Id: I14cbfc296a6723a5860bf8bd95d9804d3bac3da5
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 25b7fdf..d964ef1 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -46,7 +46,7 @@
/// identifies the InternalFace used in management
const FaceId FACEID_INTERNAL_FACE = 1;
-/// identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId
+/// identifies a packet comes from the ContentStore
const FaceId FACEID_CONTENT_STORE = 254;
/// identifies the NullFace that drops every packet
const FaceId FACEID_NULL = 255;
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index d6d6c02..d1536ce 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -49,29 +49,31 @@
, m_reassembler(m_options.reassemblerOptions, this)
, m_lastSeqNo(-2)
{
- m_reassembler.beforeTimeout.connect(bind([this] { ++nReassemblyTimeouts; }));
+ m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; }));
}
void
GenericLinkService::doSendInterest(const Interest& interest)
{
lp::Packet lpPacket(interest.wireEncode());
+
if (m_options.allowLocalFields) {
encodeLocalFields(interest, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
void
GenericLinkService::doSendData(const Data& data)
{
lp::Packet lpPacket(data.wireEncode());
+
if (m_options.allowLocalFields) {
encodeLocalFields(data, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
void
@@ -79,50 +81,21 @@
{
lp::Packet lpPacket(nack.getInterest().wireEncode());
lpPacket.add<lp::NackField>(nack.getHeader());
+
if (m_options.allowLocalFields) {
- encodeLocalFields(nack.getInterest(), lpPacket);
+ encodeLocalFields(nack, lpPacket);
}
- sendNetPacket(std::move(lpPacket));
+ this->sendNetPacket(std::move(lpPacket));
}
-bool
-GenericLinkService::encodeLocalFields(const Interest& interest, lp::Packet& lpPacket)
+void
+GenericLinkService::encodeLocalFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket)
{
- if (interest.getLocalControlHeader().hasIncomingFaceId()) {
- lpPacket.add<lp::IncomingFaceIdField>(interest.getIncomingFaceId());
+ shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
+ if (incomingFaceIdTag != nullptr) {
+ lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
}
-
- if (interest.getLocalControlHeader().hasCachingPolicy()) {
- // Packet must be dropped
- return false;
- }
-
- return true;
-}
-
-bool
-GenericLinkService::encodeLocalFields(const Data& data, lp::Packet& lpPacket)
-{
- if (data.getLocalControlHeader().hasIncomingFaceId()) {
- lpPacket.add<lp::IncomingFaceIdField>(data.getIncomingFaceId());
- }
-
- if (data.getLocalControlHeader().hasCachingPolicy()) {
- switch (data.getCachingPolicy()) {
- case ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE: {
- lp::CachePolicy cachePolicy;
- cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
- lpPacket.add<lp::CachePolicyField>(cachePolicy);
- break;
- }
- default: {
- break;
- }
- }
- }
-
- return true;
}
void
@@ -135,7 +108,7 @@
std::tie(isOk, frags) = m_fragmenter.fragmentPacket(pkt, mtu);
if (!isOk) {
// fragmentation failed (warning is logged by LpFragmenter)
- ++nFragmentationErrors;
+ ++this->nFragmentationErrors;
return;
}
}
@@ -145,7 +118,7 @@
if (frags.size() > 1) {
// sequence is needed only if packet is fragmented
- assignSequences(frags);
+ this->assignSequences(frags);
}
else {
// even if indexed fragmentation is enabled, the fragmenter should not
@@ -158,11 +131,11 @@
for (const lp::Packet& frag : frags) {
Transport::Packet tp(frag.wireEncode());
if (mtu != MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
- ++nOutOverMtu;
+ ++this->nOutOverMtu;
NFD_LOG_FACE_WARN("attempt to send packet over MTU limit");
continue;
}
- sendPacket(std::move(tp));
+ this->sendPacket(std::move(tp));
}
}
@@ -249,7 +222,7 @@
if (firstPkt.has<lp::NextHopFaceIdField>()) {
if (m_options.allowLocalFields) {
- interest->setNextHopFaceId(firstPkt.get<lp::NextHopFaceIdField>());
+ interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
}
else {
NFD_LOG_FACE_WARN("received NextHopFaceId, but local fields disabled: DROP");
@@ -292,16 +265,9 @@
if (firstPkt.has<lp::CachePolicyField>()) {
if (m_options.allowLocalFields) {
- lp::CachePolicyType policy = firstPkt.get<lp::CachePolicyField>().getPolicy();
- switch (policy) {
- case lp::CachePolicyType::NO_CACHE:
- data->setCachingPolicy(ndn::nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
- break;
- default:
- ++this->nInNetInvalid;
- NFD_LOG_FACE_WARN("unrecognized CachePolicyType " << policy << ": DROP");
- return;
- }
+ // In case of an invalid CachePolicyType, get<lp::CachePolicyField> will throw,
+ // so it's unnecessary to check here.
+ data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
}
else {
NFD_LOG_FACE_WARN("received CachePolicy, but local fields disabled: IGNORE");
diff --git a/daemon/face/generic-link-service.hpp b/daemon/face/generic-link-service.hpp
index d7cc22f..8afc693 100644
--- a/daemon/face/generic-link-service.hpp
+++ b/daemon/face/generic-link-service.hpp
@@ -130,33 +130,28 @@
getCounters() const DECL_OVERRIDE;
private: // send path
- /** \brief sends Interest
+ /** \brief send Interest
*/
void
doSendInterest(const Interest& interest) DECL_OVERRIDE;
- /** \brief sends Data
+ /** \brief send Data
*/
void
doSendData(const Data& data) DECL_OVERRIDE;
- /** \brief sends Nack
- * This class does not send out a Nack.
+ /** \brief send Nack
*/
void
doSendNack(const ndn::lp::Nack& nack) DECL_OVERRIDE;
- /** \brief encode IncomingFaceId into LpPacket and verify local fields
+ /** \brief encode local fields from tags onto outgoing LpPacket
+ * \param pkt LpPacket containing a complete network layer packet
*/
- static bool
- encodeLocalFields(const Interest& interest, lp::Packet& lpPacket);
+ static void
+ encodeLocalFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket);
- /** \brief encode CachingPolicy and IncomingFaceId into LpPacket and verify local fields
- */
- static bool
- encodeLocalFields(const Data& data, lp::Packet& lpPacket);
-
- /** \brief encode and send a complete network layer packet
+ /** \brief send a complete network layer packet
* \param pkt LpPacket containing a complete network layer packet
*/
void
diff --git a/daemon/face/local-face.hpp b/daemon/face/local-face.hpp
deleted file mode 100644
index f13cf9b..0000000
--- a/daemon/face/local-face.hpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_FACE_LOCAL_FACE_HPP
-#define NFD_DAEMON_FACE_LOCAL_FACE_HPP
-
-#include "face.hpp"
-#include <ndn-cxx/management/nfd-control-parameters.hpp>
-
-namespace nfd {
-
-using ndn::nfd::LocalControlFeature;
-using ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID;
-using ndn::nfd::LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID;
-
-/** \brief represents a face
- */
-class LocalFace : public Face
-{
-public:
- LocalFace(const FaceUri& remoteUri, const FaceUri& localUri);
-
- /** \brief get whether any LocalControlHeader feature is enabled
- *
- * \returns true if any feature is enabled.
- */
- bool
- isLocalControlHeaderEnabled() const;
-
- /** \brief get whether a specific LocalControlHeader feature is enabled
- *
- * \param feature The feature.
- * \returns true if the specified feature is enabled.
- */
- bool
- isLocalControlHeaderEnabled(LocalControlFeature feature) const;
-
- /** \brief enable or disable a LocalControlHeader feature
- *
- * \param feature The feature. Cannot be LOCAL_CONTROL_FEATURE_ANY
- * or LOCAL_CONTROL_FEATURE_MAX
- * \param enabled true/false enable/disable the feature
- */
- void
- setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled = true);
-
-public:
-
- static const size_t LOCAL_CONTROL_FEATURE_MAX = 3; /// upper bound of LocalControlFeature enum
- static const size_t LOCAL_CONTROL_FEATURE_ANY = 0; /// any feature
-
-protected:
- // statically overridden from Face
-
- /** \brief Decode block into Interest/Data, considering potential LocalControlHeader
- *
- * If LocalControlHeader is present, the encoded data is filtered out, based
- * on enabled features on the face.
- */
- bool
- decodeAndDispatchInput(const Block& element);
-
- // LocalFace-specific methods
-
- /** \brief Check if LocalControlHeader needs to be included, taking into account
- * both set parameters in supplied LocalControlHeader and features
- * enabled on the local face.
- */
- bool
- isEmptyFilteredLocalControlHeader(const ndn::nfd::LocalControlHeader& header) const;
-
- /** \brief Create LocalControlHeader, considering enabled features
- */
- template<class Packet>
- Block
- filterAndEncodeLocalControlHeader(const Packet& packet);
-
-private:
- std::vector<bool> m_localControlHeaderFeatures;
-};
-
-inline
-LocalFace::LocalFace(const FaceUri& remoteUri, const FaceUri& localUri)
- : Face(remoteUri, localUri, true)
- , m_localControlHeaderFeatures(LocalFace::LOCAL_CONTROL_FEATURE_MAX)
-{
-}
-
-inline bool
-LocalFace::isLocalControlHeaderEnabled() const
-{
- return m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY];
-}
-
-inline bool
-LocalFace::isLocalControlHeaderEnabled(LocalControlFeature feature) const
-{
- BOOST_ASSERT(0 < feature &&
- static_cast<size_t>(feature) < m_localControlHeaderFeatures.size());
- return m_localControlHeaderFeatures[feature];
-}
-
-inline void
-LocalFace::setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled/* = true*/)
-{
- BOOST_ASSERT(0 < feature &&
- static_cast<size_t>(feature) < m_localControlHeaderFeatures.size());
-
- m_localControlHeaderFeatures[feature] = enabled;
-
- m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY] =
- std::find(m_localControlHeaderFeatures.begin() + 1,
- m_localControlHeaderFeatures.end(), true) <
- m_localControlHeaderFeatures.end();
- // 'find(..) < .end()' instead of 'find(..) != .end()' due to LLVM Bug 16816
-}
-
-inline bool
-LocalFace::decodeAndDispatchInput(const Block& element)
-{
- try {
- const Block& payload = ndn::nfd::LocalControlHeader::getPayload(element);
-
- // If received LocalControlHeader, but it is not enabled on the face
- if ((&payload != &element) && !this->isLocalControlHeaderEnabled())
- return false;
-
- if (payload.type() == tlv::Interest)
- {
- shared_ptr<Interest> i = make_shared<Interest>();
- i->wireDecode(payload);
- if (&payload != &element)
- {
- uint8_t mask = 0;
- if (this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)) {
- mask |= ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP;
- }
- i->getLocalControlHeader().wireDecode(element, mask);
- }
-
- this->emitSignal(onReceiveInterest, *i);
- }
- else if (payload.type() == tlv::Data)
- {
- shared_ptr<Data> d = make_shared<Data>();
- d->wireDecode(payload);
-
- /// \todo Uncomment and correct the following when we have more
- /// options in LocalControlHeader that apply for incoming
- /// Data packets (if ever)
- // if (&payload != &element)
- // {
- //
- // d->getLocalControlHeader().wireDecode(element,
- // false,
- // false);
- // }
-
- this->emitSignal(onReceiveData, *d);
- }
- else
- return false;
-
- return true;
- }
- catch (const tlv::Error&) {
- return false;
- }
-}
-
-inline bool
-LocalFace::isEmptyFilteredLocalControlHeader(const ndn::nfd::LocalControlHeader& header) const
-{
- if (!this->isLocalControlHeaderEnabled())
- return true;
-
- uint8_t mask = 0;
- if (this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)) {
- mask |= ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID;
- }
- return header.empty(mask);
-}
-
-template<class Packet>
-inline Block
-LocalFace::filterAndEncodeLocalControlHeader(const Packet& packet)
-{
- uint8_t mask = 0;
- if (this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)) {
- mask |= ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID;
- }
- return packet.getLocalControlHeader().wireEncode(packet, mask);
-}
-
-} // namespace nfd
-
-#endif // NFD_DAEMON_FACE_LOCAL_FACE_HPP
diff --git a/daemon/face/lp-face.hpp b/daemon/face/lp-face.hpp
index 17746f2..130fe00 100644
--- a/daemon/face/lp-face.hpp
+++ b/daemon/face/lp-face.hpp
@@ -42,7 +42,7 @@
const FaceId INVALID_FACEID = 0;
/// identifies the InternalFace used in management
const FaceId FACEID_INTERNAL_FACE = 1;
-/// identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId
+/// identifies a packet comes from the ContentStore
const FaceId FACEID_CONTENT_STORE = 254;
/// identifies the NullFace that drops every packet
const FaceId FACEID_NULL = 255;
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index 31efe8b..6af5bb8 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -27,6 +27,7 @@
#define NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP
#include "channel.hpp"
+#include <ndn-cxx/encoding/nfd-constants.hpp>
namespace nfd {
diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp
index 8735de6..626809c 100644
--- a/daemon/face/transport.hpp
+++ b/daemon/face/transport.hpp
@@ -28,6 +28,7 @@
#include "core/counter.hpp"
#include "face-log.hpp"
+#include <ndn-cxx/encoding/nfd-constants.hpp>
namespace nfd {
namespace face {