lp: IncomingFaceId, NextHopFaceId, CachePolicy tags

LocalControlHeader is deprecated.

This commit also adjusts includes in some lp/ headers.

refs #3296

Change-Id: Icdc7b469d70739fe5c65da51817c92ff9136c923
diff --git a/src/common.hpp b/src/common.hpp
index 8212a7e..a51f58d 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -63,6 +63,7 @@
 #  error "ndn-cxx applications must be compiled using the C++11 standard"
 #endif
 
+#include <algorithm>
 #include <cstddef>
 #include <cstdint>
 #include <cstring>
diff --git a/src/data.cpp b/src/data.cpp
index f96fb8f..724335e 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -289,26 +289,6 @@
   return *this;
 }
 
-//
-
-Data&
-Data::setIncomingFaceId(uint64_t incomingFaceId)
-{
-  getLocalControlHeader().setIncomingFaceId(incomingFaceId);
-  // ! do not reset Data's wire !
-
-  return *this;
-}
-
-Data&
-Data::setCachingPolicy(nfd::LocalControlHeader::CachingPolicy cachingPolicy)
-{
-  getLocalControlHeader().setCachingPolicy(cachingPolicy);
-  // ! do not reset Data's wire !
-
-  return *this;
-}
-
 void
 Data::onChanged()
 {
@@ -349,4 +329,53 @@
   return os;
 }
 
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+// Permit deprecated usage for gcc only.
+// clang allows deprecated usage in deprecated functions, so it doesn't need this directive.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
+lp::LocalControlHeaderFacade
+Data::getLocalControlHeader()
+{
+  return lp::LocalControlHeaderFacade(*this);
+}
+
+const lp::LocalControlHeaderFacade
+Data::getLocalControlHeader() const
+{
+  return lp::LocalControlHeaderFacade(const_cast<Data&>(*this));
+}
+
+uint64_t
+Data::getIncomingFaceId() const
+{
+  return getLocalControlHeader().getIncomingFaceId();
+}
+
+Data&
+Data::setIncomingFaceId(uint64_t incomingFaceId)
+{
+  getLocalControlHeader().setIncomingFaceId(incomingFaceId);
+  return *this;
+}
+
+lp::LocalControlHeaderFacade::CachingPolicy
+Data::getCachingPolicy() const
+{
+  return getLocalControlHeader().getCachingPolicy();
+}
+
+Data&
+Data::setCachingPolicy(lp::LocalControlHeaderFacade::CachingPolicy cachingPolicy)
+{
+  getLocalControlHeader().setCachingPolicy(cachingPolicy);
+  return *this;
+}
+
+#pragma GCC diagnostic pop
+
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
 } // namespace ndn
diff --git a/src/data.hpp b/src/data.hpp
index b5e1c02..17c04a5 100644
--- a/src/data.hpp
+++ b/src/data.hpp
@@ -29,7 +29,7 @@
 #include "signature.hpp"
 #include "meta-info.hpp"
 #include "key-locator.hpp"
-#include "management/nfd-local-control-header.hpp"
+#include "lp/tags.hpp"
 #include "tag-host.hpp"
 
 namespace ndn {
@@ -285,23 +285,43 @@
 
   ///////////////////////////////////////////////////////////////
 
-  nfd::LocalControlHeader&
-  getLocalControlHeader();
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+  /** @deprecated use getTag and setTag with lp::IncomingFaceIdTag, lp::CachePolicyTag
+   */
+  DEPRECATED(
+  lp::LocalControlHeaderFacade
+  getLocalControlHeader());
 
-  const nfd::LocalControlHeader&
-  getLocalControlHeader() const;
+  /** @deprecated use getTag with lp::IncomingFaceIdTag, lp::CachePolicyTag
+   */
+  DEPRECATED(
+  const lp::LocalControlHeaderFacade
+  getLocalControlHeader() const);
 
+  /** @deprecated use getTag<lp::IncomingFaceIdTag>
+   */
+  DEPRECATED(
   uint64_t
-  getIncomingFaceId() const;
+  getIncomingFaceId() const);
 
+  /** @deprecated use setTag<lp::IncomingFaceIdTag>
+   */
+  DEPRECATED(
   Data&
-  setIncomingFaceId(uint64_t incomingFaceId);
+  setIncomingFaceId(uint64_t incomingFaceId));
 
-  nfd::LocalControlHeader::CachingPolicy
-  getCachingPolicy() const;
+  /** @deprecated use getTag<lp::CachePolicyTag>
+   */
+  DEPRECATED(
+  lp::LocalControlHeaderFacade::CachingPolicy
+  getCachingPolicy() const);
 
+  /** @deprecated use setTag<lp::CachePolicyTag>
+   */
+  DEPRECATED(
   Data&
-  setCachingPolicy(nfd::LocalControlHeader::CachingPolicy cachingPolicy);
+  setCachingPolicy(lp::LocalControlHeaderFacade::CachingPolicy cachingPolicy));
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
 
 public: // EqualityComparable concept
   bool
@@ -325,9 +345,6 @@
 
   mutable Block m_wire;
   mutable Name m_fullName;
-
-  nfd::LocalControlHeader m_localControlHeader;
-  friend class nfd::LocalControlHeader;
 };
 
 std::ostream&
@@ -375,30 +392,6 @@
   return m_signature;
 }
 
-inline nfd::LocalControlHeader&
-Data::getLocalControlHeader()
-{
-  return m_localControlHeader;
-}
-
-inline const nfd::LocalControlHeader&
-Data::getLocalControlHeader() const
-{
-  return m_localControlHeader;
-}
-
-inline uint64_t
-Data::getIncomingFaceId() const
-{
-  return getLocalControlHeader().getIncomingFaceId();
-}
-
-inline nfd::LocalControlHeader::CachingPolicy
-Data::getCachingPolicy() const
-{
-  return getLocalControlHeader().getCachingPolicy();
-}
-
 } // namespace ndn
 
 #endif
diff --git a/src/detail/face-impl.hpp b/src/detail/face-impl.hpp
index 808355f..ef49992 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -39,9 +39,9 @@
 
 #include "../management/nfd-controller.hpp"
 #include "../management/nfd-command-options.hpp"
-#include "../management/nfd-local-control-header.hpp"
 
 #include "../lp/packet.hpp"
+#include "../lp/tags.hpp"
 
 namespace ndn {
 
@@ -149,9 +149,9 @@
 
     lp::Packet packet;
 
-    nfd::LocalControlHeader localControlHeader = interest->getLocalControlHeader();
-    if (localControlHeader.hasNextHopFaceId()) {
-      packet.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId());
+    shared_ptr<lp::NextHopFaceIdTag> nextHopFaceIdTag = interest->getTag<lp::NextHopFaceIdTag>();
+    if (nextHopFaceIdTag != nullptr) {
+      packet.add<lp::NextHopFaceIdField>(*nextHopFaceIdTag);
     }
 
     packet.add<lp::FragmentField>(std::make_pair(interest->wireEncode().begin(),
@@ -179,18 +179,9 @@
 
     lp::Packet packet;
 
-    nfd::LocalControlHeader localControlHeader = data->getLocalControlHeader();
-    if (localControlHeader.hasCachingPolicy()) {
-      switch (localControlHeader.getCachingPolicy()) {
-        case nfd::LocalControlHeader::CachingPolicy::NO_CACHE: {
-          lp::CachePolicy cachePolicy;
-          cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE);
-          packet.add<lp::CachePolicyField>(cachePolicy);
-          break;
-        }
-        default:
-          break;
-      }
+    shared_ptr<lp::CachePolicyTag> cachePolicyTag = data->getTag<lp::CachePolicyTag>();
+    if (cachePolicyTag != nullptr) {
+      packet.add<lp::CachePolicyField>(*cachePolicyTag);
     }
 
     packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(),
diff --git a/src/face.cpp b/src/face.cpp
index 9d6b0dd..0212fd7 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -473,8 +473,7 @@
 extractLpLocalFields(NETPKT& netPacket, const lp::Packet& lpPacket)
 {
   if (lpPacket.has<lp::IncomingFaceIdField>()) {
-    netPacket.getLocalControlHeader().
-      setIncomingFaceId(lpPacket.get<lp::IncomingFaceIdField>());
+    netPacket.setTag(make_shared<lp::IncomingFaceIdTag>(lpPacket.get<lp::IncomingFaceIdField>()));
   }
 }
 
diff --git a/src/face.hpp b/src/face.hpp
index e07f541..9a01d17 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -28,8 +28,9 @@
 #include "interest.hpp"
 #include "interest-filter.hpp"
 #include "data.hpp"
-#include "security/signing-info.hpp"
+#include "encoding/nfd-constants.hpp"
 #include "lp/nack.hpp"
+#include "security/signing-info.hpp"
 
 #define NDN_FACE_KEEP_DEPRECATED_REGISTRATION_SIGNING
 
diff --git a/src/interest.cpp b/src/interest.cpp
index 35be5ce..1ad619c 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -485,4 +485,53 @@
   return os;
 }
 
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+// Permit deprecated usage for gcc only.
+// clang allows deprecated usage in deprecated functions, so it doesn't need this directive.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
+lp::LocalControlHeaderFacade
+Interest::getLocalControlHeader()
+{
+  return lp::LocalControlHeaderFacade(*this);
+}
+
+const lp::LocalControlHeaderFacade
+Interest::getLocalControlHeader() const
+{
+  return lp::LocalControlHeaderFacade(const_cast<Interest&>(*this));
+}
+
+uint64_t
+Interest::getIncomingFaceId() const
+{
+  return getLocalControlHeader().getIncomingFaceId();
+}
+
+Interest&
+Interest::setIncomingFaceId(uint64_t incomingFaceId)
+{
+  getLocalControlHeader().setIncomingFaceId(incomingFaceId);
+  return *this;
+}
+
+uint64_t
+Interest::getNextHopFaceId() const
+{
+  return getLocalControlHeader().getNextHopFaceId();
+}
+
+Interest&
+Interest::setNextHopFaceId(uint64_t nextHopFaceId)
+{
+  getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
+  return *this;
+}
+
+#pragma GCC diagnostic pop
+
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
 } // namespace ndn
diff --git a/src/interest.hpp b/src/interest.hpp
index b87cd50..c61d328 100644
--- a/src/interest.hpp
+++ b/src/interest.hpp
@@ -27,7 +27,7 @@
 #include "name.hpp"
 #include "selectors.hpp"
 #include "util/time.hpp"
-#include "management/nfd-local-control-header.hpp"
+#include "lp/tags.hpp"
 #include "tag-host.hpp"
 #include "link.hpp"
 
@@ -275,46 +275,44 @@
   void
   refreshNonce();
 
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
 public: // local control header
-  nfd::LocalControlHeader&
-  getLocalControlHeader()
-  {
-    return m_localControlHeader;
-  }
+  /** @deprecated use getTag and setTag with lp::IncomingFaceIdTag, lp::NextHopFaceIdTag
+   */
+  DEPRECATED(
+  lp::LocalControlHeaderFacade
+  getLocalControlHeader());
 
-  const nfd::LocalControlHeader&
-  getLocalControlHeader() const
-  {
-    return m_localControlHeader;
-  }
+  /** @deprecated use getTag with lp::IncomingFaceIdTag, lp::NextHopFaceIdTag
+   */
+  DEPRECATED(
+  const lp::LocalControlHeaderFacade
+  getLocalControlHeader() const);
 
+  /** @deprecated use getTag<lp::IncomingFaceIdTag>
+   */
+  DEPRECATED(
   uint64_t
-  getIncomingFaceId() const
-  {
-    return getLocalControlHeader().getIncomingFaceId();
-  }
+  getIncomingFaceId() const);
 
+  /** @deprecated use setTag<lp::IncomingFaceIdTag>
+   */
+  DEPRECATED(
   Interest&
-  setIncomingFaceId(uint64_t incomingFaceId)
-  {
-    getLocalControlHeader().setIncomingFaceId(incomingFaceId);
-    // ! do not reset Interest's wire !
-    return *this;
-  }
+  setIncomingFaceId(uint64_t incomingFaceId));
 
+  /** @deprecated use getTag<lp::NextHopFaceIdTag>
+   */
+  DEPRECATED(
   uint64_t
-  getNextHopFaceId() const
-  {
-    return getLocalControlHeader().getNextHopFaceId();
-  }
+  getNextHopFaceId() const);
 
+  /** @deprecated use setTag<lp::NextHopFaceIdTag>
+   */
+  DEPRECATED(
   Interest&
-  setNextHopFaceId(uint64_t nextHopFaceId)
-  {
-    getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
-    // ! do not reset Interest's wire !
-    return *this;
-  }
+  setNextHopFaceId(uint64_t nextHopFaceId));
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
 
 public: // Selectors
   /**
@@ -447,9 +445,6 @@
   mutable shared_ptr<Link> m_linkCached;
   size_t m_selectedDelegationIndex;
   mutable Block m_wire;
-
-  nfd::LocalControlHeader m_localControlHeader;
-  friend class nfd::LocalControlHeader;
 };
 
 std::ostream&
diff --git a/src/lp/cache-policy.hpp b/src/lp/cache-policy.hpp
index a67a9c3..5c5c5d1 100644
--- a/src/lp/cache-policy.hpp
+++ b/src/lp/cache-policy.hpp
@@ -25,6 +25,7 @@
 #define NDN_CXX_LP_CACHE_POLICY_HPP
 
 #include "../common.hpp"
+#include "../tag.hpp"
 #include "../encoding/encoding-buffer.hpp"
 #include "../encoding/block-helpers.hpp"
 
@@ -109,4 +110,4 @@
 } // namespace lp
 } // namespace ndn
 
-#endif // NDN_CXX_LP_CACHE_POLICY_HPP
\ No newline at end of file
+#endif // NDN_CXX_LP_CACHE_POLICY_HPP
diff --git a/src/lp/detail/field-decl.hpp b/src/lp/detail/field-decl.hpp
index 02a3677..44df431 100644
--- a/src/lp/detail/field-decl.hpp
+++ b/src/lp/detail/field-decl.hpp
@@ -22,14 +22,11 @@
 #ifndef NDN_CXX_LP_DETAIL_FIELD_DECL_HPP
 #define NDN_CXX_LP_DETAIL_FIELD_DECL_HPP
 
-#include "../../common.hpp"
-
 #include "../field.hpp"
-#include "../sequence.hpp"
-#include "../cache-policy.hpp"
-#include "../nack.hpp"
 #include "../tlv.hpp"
 
+#include "../../encoding/block-helpers.hpp"
+#include "../../util/concepts.hpp"
 #include <boost/concept/requires.hpp>
 
 namespace ndn {
diff --git a/src/lp/field.hpp b/src/lp/field.hpp
index 199fb16..712bd86 100644
--- a/src/lp/field.hpp
+++ b/src/lp/field.hpp
@@ -25,6 +25,8 @@
 #include "../common.hpp"
 #include "../encoding/encoding-buffer.hpp"
 
+#include <boost/concept/assert.hpp>
+#include <boost/concept/usage.hpp>
 #include <boost/type_traits.hpp>
 
 namespace ndn {
@@ -79,4 +81,4 @@
 } // namespace lp
 } // namespace ndn
 
-#endif // NDN_CXX_LP_FIELD_HPP
\ No newline at end of file
+#endif // NDN_CXX_LP_FIELD_HPP
diff --git a/src/lp/fields.hpp b/src/lp/fields.hpp
index ad656be..ff9db28 100644
--- a/src/lp/fields.hpp
+++ b/src/lp/fields.hpp
@@ -22,11 +22,11 @@
 #ifndef NDN_CXX_LP_FIELDS_HPP
 #define NDN_CXX_LP_FIELDS_HPP
 
-#include "../common.hpp"
-
-#include "tlv.hpp"
 #include "detail/field-decl.hpp"
-#include "field.hpp"
+
+#include "sequence.hpp"
+#include "cache-policy.hpp"
+#include "nack-header.hpp"
 
 #include <boost/mpl/set.hpp>
 
@@ -94,4 +94,4 @@
 } // namespace lp
 } // namespace ndn
 
-#endif // NDN_CXX_LP_FIELDS_HPP
\ No newline at end of file
+#endif // NDN_CXX_LP_FIELDS_HPP
diff --git a/src/lp/nack.hpp b/src/lp/nack.hpp
index a50221c..3b23cf6 100644
--- a/src/lp/nack.hpp
+++ b/src/lp/nack.hpp
@@ -27,16 +27,15 @@
 #include "../common.hpp"
 #include "../tag-host.hpp"
 #include "../interest.hpp"
-#include "../management/nfd-local-control-header.hpp"
 
 #include "nack-header.hpp"
 
 namespace ndn {
 namespace lp {
 
-/**
- * \brief represents a Network NACK
- * \details This type binds a NackHeader and an Interest, and is intended for use in network layer.
+/** \brief represents a Network Nack
+ *
+ *  This type binds a NackHeader and an Interest, and is intended for use in network layer.
  */
 class Nack : public TagHost
 {
@@ -88,18 +87,6 @@
     return *this;
   }
 
-  nfd::LocalControlHeader&
-  getLocalControlHeader()
-  {
-    return m_interest.getLocalControlHeader();
-  }
-
-  const nfd::LocalControlHeader&
-  getLocalControlHeader() const
-  {
-    return m_interest.getLocalControlHeader();
-  }
-
 public: // NackHeader proxy
   NackReason
   getReason() const
diff --git a/src/lp/tags.cpp b/src/lp/tags.cpp
new file mode 100644
index 0000000..53e0138
--- /dev/null
+++ b/src/lp/tags.cpp
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2015 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "tags.hpp"
+#include "../encoding/nfd-constants.hpp"
+
+namespace ndn {
+namespace lp {
+
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+using ndn::nfd::INVALID_FACE_ID;
+
+LocalControlHeaderFacade::LocalControlHeaderFacade(TagHost& pkt)
+  : m_pkt(pkt)
+{
+}
+
+bool
+LocalControlHeaderFacade::hasIncomingFaceId() const
+{
+  return m_pkt.getTag<IncomingFaceIdTag>() != nullptr;
+}
+
+uint64_t
+LocalControlHeaderFacade::getIncomingFaceId() const
+{
+  shared_ptr<IncomingFaceIdTag> tag = m_pkt.getTag<IncomingFaceIdTag>();
+  if (tag == nullptr) {
+    return INVALID_FACE_ID;
+  }
+  return *tag;
+}
+
+void
+LocalControlHeaderFacade::setIncomingFaceId(uint64_t incomingFaceId)
+{
+  if (incomingFaceId == INVALID_FACE_ID) {
+    m_pkt.removeTag<IncomingFaceIdTag>();
+    return;
+  }
+
+  auto tag = make_shared<IncomingFaceIdTag>(incomingFaceId);
+  m_pkt.setTag(tag);
+}
+
+bool
+LocalControlHeaderFacade::hasNextHopFaceId() const
+{
+  return m_pkt.getTag<NextHopFaceIdTag>() != nullptr;
+}
+
+uint64_t
+LocalControlHeaderFacade::getNextHopFaceId() const
+{
+  shared_ptr<NextHopFaceIdTag> tag = m_pkt.getTag<NextHopFaceIdTag>();
+  if (tag == nullptr) {
+    return INVALID_FACE_ID;
+  }
+  return *tag;
+}
+
+void
+LocalControlHeaderFacade::setNextHopFaceId(uint64_t nextHopFaceId)
+{
+  if (nextHopFaceId == INVALID_FACE_ID) {
+    m_pkt.removeTag<NextHopFaceIdTag>();
+    return;
+  }
+
+  auto tag = make_shared<NextHopFaceIdTag>(nextHopFaceId);
+  m_pkt.setTag(tag);
+}
+
+bool
+LocalControlHeaderFacade::hasCachingPolicy() const
+{
+  return m_pkt.getTag<CachePolicyTag>() != nullptr;
+}
+
+LocalControlHeaderFacade::CachingPolicy
+LocalControlHeaderFacade::getCachingPolicy() const
+{
+  shared_ptr<CachePolicyTag> tag = m_pkt.getTag<CachePolicyTag>();
+  if (tag == nullptr) {
+    return INVALID_POLICY;
+  }
+  switch (tag->get().getPolicy()) {
+    case CachePolicyType::NO_CACHE:
+      return NO_CACHE;
+    default:
+      return INVALID_POLICY;
+  }
+}
+
+void
+LocalControlHeaderFacade::setCachingPolicy(CachingPolicy cachingPolicy)
+{
+  switch (cachingPolicy) {
+    case NO_CACHE: {
+      m_pkt.setTag(make_shared<CachePolicyTag>(CachePolicy().setPolicy(CachePolicyType::NO_CACHE)));
+      break;
+    }
+    default:
+      m_pkt.removeTag<CachePolicyTag>();
+      break;
+  }
+}
+
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+} // namespace lp
+} // namespace ndn
diff --git a/src/lp/tags.hpp b/src/lp/tags.hpp
new file mode 100644
index 0000000..f91b3f1
--- /dev/null
+++ b/src/lp/tags.hpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2015 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_CXX_LP_TAGS_HPP
+#define NDN_CXX_LP_TAGS_HPP
+
+#include "cache-policy.hpp"
+#include "../tag-host.hpp"
+
+namespace ndn {
+namespace lp {
+
+/** \class IncomingFaceIdTag
+ *  \brief a packet tag for IncomingFaceId field
+ *
+ *  This tag can be attached to Interest, Data, Nack.
+ */
+typedef SimpleTag<uint64_t, 10> IncomingFaceIdTag;
+
+/** \class NextHopFaceIdTag
+ *  \brief a packet tag for NextHopFaceId field
+ *
+ *  This tag can be attached to Interest.
+ */
+typedef SimpleTag<uint64_t, 11> NextHopFaceIdTag;
+
+/** \class CachePolicyTag
+ *  \brief a packet tag for CachePolicy field
+ *
+ *  This tag can be attached to Data.
+ */
+typedef SimpleTag<CachePolicy, 12> CachePolicyTag;
+
+
+#define NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+/** \brief expose NDNLPv2 tags as LocalControlHeader API
+ *
+ *  This class has the same public API as ndn::nfd::LocalControlHeader,
+ *  but internally accesses IncomingFaceIdTag, NextHopFaceIdTag, CachePolicyTag
+ *  on the host packet.
+ *
+ *  \deprecated use getTag and setTag with IncomingFaceIdTag, NextHopFaceIdTag, CachePolicyTag
+ */
+class LocalControlHeaderFacade
+{
+public:
+  DEPRECATED(
+  explicit
+  LocalControlHeaderFacade(TagHost& pkt));
+
+  bool
+  hasIncomingFaceId() const;
+
+  uint64_t
+  getIncomingFaceId() const;
+
+  void
+  setIncomingFaceId(uint64_t incomingFaceId);
+
+  bool
+  hasNextHopFaceId() const;
+
+  uint64_t
+  getNextHopFaceId() const;
+
+  void
+  setNextHopFaceId(uint64_t nextHopFaceId);
+
+  bool
+  hasCachingPolicy() const;
+
+  enum CachingPolicy : uint8_t {
+    INVALID_POLICY = 0,
+    NO_CACHE       = 1
+  };
+
+  CachingPolicy
+  getCachingPolicy() const;
+
+  void
+  setCachingPolicy(CachingPolicy cachingPolicy);
+
+private:
+  TagHost& m_pkt;
+};
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+
+} // namespace lp
+} // namespace ndn
+
+#endif // NDN_CXX_LP_TAGS_HPP
diff --git a/src/management/nfd-local-control-header.hpp b/src/management/nfd-local-control-header.hpp
index 327035d..3bc049e 100644
--- a/src/management/nfd-local-control-header.hpp
+++ b/src/management/nfd-local-control-header.hpp
@@ -22,309 +22,16 @@
 #ifndef NDN_MANAGEMENT_NFD_LOCAL_CONTROL_HEADER_HPP
 #define NDN_MANAGEMENT_NFD_LOCAL_CONTROL_HEADER_HPP
 
-#include "../encoding/encoding-buffer.hpp"
-#include "../encoding/tlv-nfd.hpp"
-#include "../encoding/block-helpers.hpp"
+#include "../lp/tags.hpp"
 
 namespace ndn {
 namespace nfd {
 
-/**
- * @ingroup management
- * @brief Class to handle work with LocalControlHeader
- * @sa http://redmine.named-data.net/projects/nfd/wiki/LocalControlHeader
- */
-class LocalControlHeader
-{
-public:
-  class Error : public std::runtime_error
-  {
-  public:
-    explicit
-    Error(const std::string& what)
-      : std::runtime_error(what)
-    {
-    }
-  };
-
-  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)
-  {
-  }
-
-  /**
-   * @brief Create from wire encoding
-   *
-   * @sa wireDecode
-   */
-  explicit
-  LocalControlHeader(const Block& wire, uint8_t encodeMask = ENCODE_ALL)
-  {
-    wireDecode(wire, encodeMask);
-  }
-
-  /**
-   * @brief Create wire encoding with options LocalControlHeader and the supplied item
-   *
-   * The caller is responsible of checking whether LocalControlHeader contains
-   * any information.
-   *
-   * !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
-   *
-   * @returns Block, containing LocalControlHeader. Top-level length field of the
-   *          returned LocalControlHeader includes payload length, but the memory
-   *          block is independent of the payload's wire buffer.  It is expected
-   *          that both LocalControlHeader's and payload's wire will be send out
-   *          together within a single send call.
-   *
-   * @see http://redmine.named-data.net/projects/nfd/wiki/LocalControlHeader
-   */
-  template<class U>
-  inline Block
-  wireEncode(const U& payload, uint8_t encodeMask = ENCODE_ALL) const;
-
-  /**
-   * @brief Decode from the wire format and set LocalControlHeader on the supplied item
-   *
-   * The supplied wire MUST contain LocalControlHeader.  Determination whether the optional
-   * LocalControlHeader should be done before calling this method.
-   */
-  inline void
-  wireDecode(const Block& wire, uint8_t encodeMask = ENCODE_ALL);
-
-  inline static const Block&
-  getPayload(const Block& wire);
-
-  ///////////////////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////////////////
-  // Getters/setters
-
-  bool
-  empty(uint8_t encodeMask) const
-  {
-    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()));
-  }
-
-  //
-
-  bool
-  hasIncomingFaceId() const
-  {
-    return m_incomingFaceId != INVALID_FACE_ID;
-  }
-
-  uint64_t
-  getIncomingFaceId() const
-  {
-    return m_incomingFaceId;
-  }
-
-  void
-  setIncomingFaceId(uint64_t incomingFaceId)
-  {
-    m_incomingFaceId = incomingFaceId;
-  }
-
-  //
-
-  bool
-  hasNextHopFaceId() const
-  {
-    return m_nextHopFaceId != INVALID_FACE_ID;
-  }
-
-  uint64_t
-  getNextHopFaceId() const
-  {
-    return m_nextHopFaceId;
-  }
-
-  void
-  setNextHopFaceId(uint64_t nextHopFaceId)
-  {
-    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, uint8_t encodeMask) const;
-
-private:
-  uint64_t m_incomingFaceId;
-  uint64_t m_nextHopFaceId;
-  CachingPolicy m_cachingPolicy;
-};
-
-
-/**
- * @brief Fast encoding or block size estimation
- */
-template<encoding::Tag TAG>
-inline size_t
-LocalControlHeader::wireEncode(EncodingImpl<TAG>& block, size_t payloadSize,
-                               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 (needIncomingFaceId && hasIncomingFaceId())
-    {
-      totalLength += prependNonNegativeIntegerBlock(block,
-                                                    tlv::nfd::IncomingFaceId, getIncomingFaceId());
-    }
-
-  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;
-}
-
-template<class U>
-inline Block
-LocalControlHeader::wireEncode(const U& payload, uint8_t encodeMask) const
-{
-  /// @todo should this be BOOST_ASSERT instead?  This is kind of unnecessary overhead
-  if (empty(encodeMask))
-    BOOST_THROW_EXCEPTION(Error("Requested wire for LocalControlHeader, but none of the fields are "
-                                "set or enabled"));
-
-  EncodingEstimator estimator;
-  size_t length = wireEncode(estimator, payload.wireEncode().size(), encodeMask);
-
-  EncodingBuffer buffer(length);
-  wireEncode(buffer, payload.wireEncode().size(), encodeMask);
-
-  return buffer.block(false);
-}
-
-inline void
-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();
-       ++i)
-    {
-      switch (i->type())
-        {
-        case tlv::nfd::IncomingFaceId:
-          if (needIncomingFaceId)
-            m_incomingFaceId = readNonNegativeInteger(*i);
-          break;
-        case tlv::nfd::NextHopFaceId:
-          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 {
-              BOOST_THROW_EXCEPTION(Error("CachingPolicy: Missing required NoCache field"));
-            }
-          }
-          break;
-        default:
-          // ignore all unsupported
-          break;
-        }
-    }
-}
-
-inline const Block&
-LocalControlHeader::getPayload(const Block& wire)
-{
-  if (wire.type() == tlv::nfd::LocalControlHeader)
-    {
-      wire.parse();
-      if (wire.elements_size() < 1)
-        return wire; // don't throw an error, but don't continue processing
-
-      return wire.elements()[wire.elements().size()-1];
-    }
-  else
-    {
-      return wire;
-    }
-}
+#ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
+typedef ndn::lp::LocalControlHeaderFacade LocalControlHeader;
+#else
+#error "LocalControlHeader is deleted"
+#endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
 
 } // namespace nfd
 } // namespace ndn
diff --git a/src/tag.hpp b/src/tag.hpp
index 195d821..cd36445 100644
--- a/src/tag.hpp
+++ b/src/tag.hpp
@@ -25,13 +25,13 @@
 namespace ndn {
 
 /**
- * @brief Base class for interest/data tags that can hold any arbitrary information
+ * @brief Base class for packet tags that can hold any arbitrary information
  */
 class Tag
 {
 public:
   virtual
-  ~Tag() = 0;
+  ~Tag();
 
   /**
    * @fn static constexpr int getTypeId()
@@ -48,9 +48,49 @@
 };
 
 inline
-Tag::~Tag()
+Tag::~Tag() = default;
+
+/** @brief provides a tag type for simple types
+ *  @tparam T the value type
+ *  @tparam TypeId the TypeId
+ */
+template<typename T, int TypeId>
+class SimpleTag : public Tag
 {
-}
+public:
+  static constexpr int
+  getTypeId()
+  {
+    return TypeId;
+  }
+
+  /** \brief explicitly convertible from T
+   */
+  explicit
+  SimpleTag(const T& value)
+    : m_value(value)
+  {
+  }
+
+  /** \brief implicitly convertible to T
+   *  \return a copy of the enclosed value
+   */
+  operator T() const
+  {
+    return m_value;
+  }
+
+  /** \return the enclosed value
+   */
+  const T&
+  get() const
+  {
+    return m_value;
+  }
+
+private:
+  T m_value;
+};
 
 } // namespace ndn
 
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index 676a7a0..aadb6bc 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -115,14 +115,13 @@
         shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
         nack->setHeader(lpPacket.get<lp::NackField>());
         if (lpPacket.has<lp::NextHopFaceIdField>()) {
-          nack->getLocalControlHeader().setNextHopFaceId(lpPacket.get<lp::NextHopFaceIdField>());
+          nack->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
         }
         onSendNack(*nack);
       }
       else {
         if (lpPacket.has<lp::NextHopFaceIdField>()) {
-          interest->getLocalControlHeader().
-            setNextHopFaceId(lpPacket.get<lp::NextHopFaceIdField>());
+          interest->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
         }
         onSendInterest(*interest);
       }
@@ -131,9 +130,7 @@
       shared_ptr<Data> data = make_shared<Data>(block);
 
       if (lpPacket.has<lp::CachePolicyField>()) {
-        if (lpPacket.get<lp::CachePolicyField>().getPolicy() == lp::CachePolicyType::NO_CACHE) {
-          data->getLocalControlHeader().setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
-        }
+        data->setTag(make_shared<lp::CachePolicyTag>(lpPacket.get<lp::CachePolicyField>()));
       }
 
       onSendData(*data);
@@ -196,16 +193,17 @@
 {
   lp::Packet lpPacket(packet.wireEncode());
 
-  nfd::LocalControlHeader localControlHeader = packet.getLocalControlHeader();
-
-  if (localControlHeader.hasIncomingFaceId()) {
-    lpPacket.add<lp::IncomingFaceIdField>(localControlHeader.getIncomingFaceId());
+  shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag =
+    static_cast<const TagHost&>(packet).getTag<lp::IncomingFaceIdTag>();
+  if (incomingFaceIdTag != nullptr) {
+    lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
   }
 
-  if (localControlHeader.hasNextHopFaceId()) {
-    lpPacket.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId());
+  shared_ptr<lp::NextHopFaceIdTag> nextHopFaceIdTag =
+    static_cast<const TagHost&>(packet).getTag<lp::NextHopFaceIdTag>();
+  if (nextHopFaceIdTag != nullptr) {
+    lpPacket.add<lp::NextHopFaceIdField>(*nextHopFaceIdTag);
   }
-
   m_transport->receive(lpPacket.wireEncode());
 }
 
@@ -224,10 +222,9 @@
   Block interest = nack.getInterest().wireEncode();
   lpPacket.add<lp::FragmentField>(make_pair(interest.begin(), interest.end()));
 
-  nfd::LocalControlHeader localControlHeader = nack.getLocalControlHeader();
-
-  if (localControlHeader.hasIncomingFaceId()) {
-    lpPacket.add<lp::IncomingFaceIdField>(localControlHeader.getIncomingFaceId());
+  shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = nack.getTag<lp::IncomingFaceIdTag>();
+  if (incomingFaceIdTag != nullptr) {
+    lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
   }
 
   m_transport->receive(lpPacket.wireEncode());