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/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