face: Add ability to specify RIB flags for setInterestFilter and registerPrefix

Change-Id: I0976c74856970e0d68cbf46956cfa8d494f064d5
Refs: #1842
diff --git a/src/detail/face-impl.hpp b/src/detail/face-impl.hpp
index 187d7fa..2d23611 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -188,6 +188,7 @@
                  const shared_ptr<InterestFilterRecord>& filter,
                  const RegisterPrefixSuccessCallback& onSuccess,
                  const RegisterPrefixFailureCallback& onFailure,
+                 uint64_t flags,
                  const SignatureGenerator& signatureGenerator)
   {
     using namespace nfd;
@@ -199,19 +200,21 @@
        const SignatureGenerator&,
        const time::milliseconds&);
 
+    ControlParameters parameters;
+    parameters.setName(prefix);
+
     Registrator registrator, unregistrator;
     if (!m_face.m_isDirectNfdFibManagementRequested) {
       registrator = static_cast<Registrator>(&Controller::start<RibRegisterCommand>);
       unregistrator = static_cast<Registrator>(&Controller::start<RibUnregisterCommand>);
+
+      parameters.setFlags(flags);
     }
     else {
       registrator = static_cast<Registrator>(&Controller::start<FibAddNextHopCommand>);
       unregistrator = static_cast<Registrator>(&Controller::start<FibRemoveNextHopCommand>);
     }
 
-    ControlParameters parameters;
-    parameters.setName(prefix);
-
     RegisteredPrefix::Unregistrator bindedUnregistrator =
       bind(unregistrator, m_face.m_nfdController, parameters, _1, _2,
            signatureGenerator,
diff --git a/src/encoding/nfd-constants.hpp b/src/encoding/nfd-constants.hpp
new file mode 100644
index 0000000..54794bb
--- /dev/null
+++ b/src/encoding/nfd-constants.hpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 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_ENCODING_NFD_CONSTANTS_HPP
+#define NDN_ENCODING_NFD_CONSTANTS_HPP
+
+namespace ndn {
+namespace nfd {
+
+static const uint64_t INVALID_FACE_ID = std::numeric_limits<uint64_t>::max();
+
+/**
+ * \ingroup management
+ */
+enum {
+  // route origin
+  ROUTE_ORIGIN_APP      = 0,
+  ROUTE_ORIGIN_AUTOREG  = 64,
+  ROUTE_ORIGIN_CLIENT   = 65,
+  ROUTE_ORIGIN_AUTOCONF = 66,
+  ROUTE_ORIGIN_NLSR     = 128,
+  ROUTE_ORIGIN_STATIC   = 255,
+
+  // route inheritance flags
+  ROUTE_FLAG_CHILD_INHERIT = 1,
+  ROUTE_FLAG_CAPTURE       = 2
+};
+
+} // namespace nfd
+} // namespace ndn
+
+#endif // NDN_ENCODING_NFD_CONSTANTS_HPP
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index ba00cad..3cde88b 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -23,6 +23,7 @@
 #define NDN_ENCODING_TLV_NFD_HPP
 
 #include "../common.hpp"
+#include "nfd-constants.hpp"
 
 namespace ndn {
 namespace tlv {
@@ -94,13 +95,6 @@
 
 } // namespace nfd
 } // namespace tlv
-
-namespace nfd {
-
-static const uint64_t INVALID_FACE_ID = std::numeric_limits<uint64_t>::max();
-
-} // namespace nfd
-
 } // namespace ndn
 
 #endif // NDN_ENCODING_TLV_NFD_HPP
diff --git a/src/face.cpp b/src/face.cpp
index e67b9a1..79d8dc1 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -198,13 +198,15 @@
                         const OnInterest& onInterest,
                         const RegisterPrefixSuccessCallback& onSuccess,
                         const RegisterPrefixFailureCallback& onFailure,
-                        const IdentityCertificate& certificate)
+                        const IdentityCertificate& certificate,
+                        uint64_t flags)
 {
   shared_ptr<InterestFilterRecord> filter =
     make_shared<InterestFilterRecord>(interestFilter, onInterest);
 
   return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
                                 onSuccess, onFailure,
+                                flags,
                                 certificate);
 }
 
@@ -212,13 +214,15 @@
 Face::setInterestFilter(const InterestFilter& interestFilter,
                         const OnInterest& onInterest,
                         const RegisterPrefixFailureCallback& onFailure,
-                        const IdentityCertificate& certificate)
+                        const IdentityCertificate& certificate,
+                        uint64_t flags)
 {
   shared_ptr<InterestFilterRecord> filter =
     make_shared<InterestFilterRecord>(interestFilter, onInterest);
 
   return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
                                 RegisterPrefixSuccessCallback(), onFailure,
+                                flags,
                                 certificate);
 }
 
@@ -227,13 +231,15 @@
                         const OnInterest& onInterest,
                         const RegisterPrefixSuccessCallback& onSuccess,
                         const RegisterPrefixFailureCallback& onFailure,
-                        const Name& identity)
+                        const Name& identity,
+                        uint64_t flags)
 {
   shared_ptr<InterestFilterRecord> filter =
     make_shared<InterestFilterRecord>(interestFilter, onInterest);
 
   return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
                                 onSuccess, onFailure,
+                                flags,
                                 identity);
 }
 
@@ -241,13 +247,15 @@
 Face::setInterestFilter(const InterestFilter& interestFilter,
                         const OnInterest& onInterest,
                         const RegisterPrefixFailureCallback& onFailure,
-                        const Name& identity)
+                        const Name& identity,
+                        uint64_t flags)
 {
   shared_ptr<InterestFilterRecord> filter =
     make_shared<InterestFilterRecord>(interestFilter, onInterest);
 
   return m_impl->registerPrefix(interestFilter.getPrefix(), filter,
                                 RegisterPrefixSuccessCallback(), onFailure,
+                                flags,
                                 identity);
 }
 
@@ -268,10 +276,12 @@
 Face::registerPrefix(const Name& prefix,
                      const RegisterPrefixSuccessCallback& onSuccess,
                      const RegisterPrefixFailureCallback& onFailure,
-                     const IdentityCertificate& certificate)
+                     const IdentityCertificate& certificate,
+                     uint64_t flags)
 {
   return m_impl->registerPrefix(prefix, shared_ptr<InterestFilterRecord>(),
                                 onSuccess, onFailure,
+                                flags,
                                 certificate);
 }
 
@@ -279,14 +289,15 @@
 Face::registerPrefix(const Name& prefix,
                      const RegisterPrefixSuccessCallback& onSuccess,
                      const RegisterPrefixFailureCallback& onFailure,
-                     const Name& identity)
+                     const Name& identity,
+                     uint64_t flags)
 {
   return m_impl->registerPrefix(prefix, shared_ptr<InterestFilterRecord>(),
                                 onSuccess, onFailure,
+                                flags,
                                 identity);
 }
 
-
 void
 Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId)
 {
diff --git a/src/face.hpp b/src/face.hpp
index 9427b03..974aa69 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -238,6 +238,7 @@
    * @param onInterest     A callback to be called when a matching interest is received
    * @param onSuccess      A callback to be called when prefixRegister command succeeds
    * @param onFailure      A callback to be called when prefixRegister command fails
+   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
    * @param certificate    (optional) A certificate under which the prefix registration
    *                       command interest is signed.  When omitted, a default certificate
    *                       of the default identity is used to sign the registration command
@@ -250,7 +251,8 @@
                     const OnInterest& onInterest,
                     const RegisterPrefixSuccessCallback& onSuccess,
                     const RegisterPrefixFailureCallback& onFailure,
-                    const IdentityCertificate& certificate = IdentityCertificate());
+                    const IdentityCertificate& certificate = IdentityCertificate(),
+                    uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
@@ -265,6 +267,7 @@
    * @param interestFilter Interest filter (prefix part will be registered with the forwarder)
    * @param onInterest     A callback to be called when a matching interest is received
    * @param onFailure      A callback to be called when prefixRegister command fails
+   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
    * @param certificate    (optional) A certificate under which the prefix registration
    *                       command interest is signed.  When omitted, a default certificate
    *                       of the default identity is used to sign the registration command
@@ -276,7 +279,8 @@
   setInterestFilter(const InterestFilter& interestFilter,
                     const OnInterest& onInterest,
                     const RegisterPrefixFailureCallback& onFailure,
-                    const IdentityCertificate& certificate = IdentityCertificate());
+                    const IdentityCertificate& certificate = IdentityCertificate(),
+                    uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
@@ -294,6 +298,7 @@
    * @param onFailure      A callback to be called when prefixRegister command fails
    * @param identity       A signing identity. A command interest is signed under the default
    *                       certificate of this identity
+   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
    *
    * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
    */
@@ -302,7 +307,8 @@
                     const OnInterest& onInterest,
                     const RegisterPrefixSuccessCallback& onSuccess,
                     const RegisterPrefixFailureCallback& onFailure,
-                    const Name& identity);
+                    const Name& identity,
+                    uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Set InterestFilter to dispatch incoming matching interest to onInterest
@@ -319,6 +325,7 @@
    * @param onFailure      A callback to be called when prefixRegister command fails
    * @param identity       A signing identity. A command interest is signed under the default
    *                       certificate of this identity
+   * @param flags          (optional) RIB flags (not used when direct FIB management is requested)
    *
    * @return Opaque registered prefix ID which can be used with removeRegisteredPrefix
    */
@@ -326,7 +333,8 @@
   setInterestFilter(const InterestFilter& interestFilter,
                     const OnInterest& onInterest,
                     const RegisterPrefixFailureCallback& onFailure,
-                    const Name& identity);
+                    const Name& identity,
+                    uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Set InterestFilter to dispatch incoming matching interest to onInterest callback
@@ -358,6 +366,7 @@
    * @param certificate (optional) A certificate under which the prefix registration
    *                    command interest is signed.  When omitted, a default certificate
    *                    of the default identity is used to sign the registration command
+   * @param flags       (optional) RIB flags (not used when direct FIB management is requested)
    *
    * @return The registered prefix ID which can be used with unregisterPrefix
    */
@@ -365,7 +374,8 @@
   registerPrefix(const Name& prefix,
                  const RegisterPrefixSuccessCallback& onSuccess,
                  const RegisterPrefixFailureCallback& onFailure,
-                 const IdentityCertificate& certificate = IdentityCertificate());
+                 const IdentityCertificate& certificate = IdentityCertificate(),
+                 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Register prefix with the connected NDN forwarder and call onInterest when a matching
@@ -380,6 +390,7 @@
    * @param onFailure A callback to be called when prefixRegister command fails
    * @param identity  A signing identity. A command interest is signed under the default
    *                  certificate of this identity
+   * @param flags     (optional) RIB flags (not used when direct FIB management is requested)
    *
    * @return The registered prefix ID which can be used with unregisterPrefix
    */
@@ -387,8 +398,8 @@
   registerPrefix(const Name& prefix,
                  const RegisterPrefixSuccessCallback& onSuccess,
                  const RegisterPrefixFailureCallback& onFailure,
-                 const Name& identity);
-
+                 const Name& identity,
+                 uint64_t flags = nfd::ROUTE_FLAG_CHILD_INHERIT);
 
   /**
    * @brief Remove the registered prefix entry with the registeredPrefixId
diff --git a/src/management/nfd-control-command.hpp b/src/management/nfd-control-command.hpp
index 252812c..3a4ad80 100644
--- a/src/management/nfd-control-command.hpp
+++ b/src/management/nfd-control-command.hpp
@@ -455,24 +455,6 @@
 
 /**
  * \ingroup management
- */
-enum {
-  // route origin
-  ROUTE_ORIGIN_APP      = 0,
-  ROUTE_ORIGIN_AUTOREG  = 64,
-  ROUTE_ORIGIN_CLIENT   = 65,
-  ROUTE_ORIGIN_AUTOCONF = 66,
-  ROUTE_ORIGIN_NLSR     = 128,
-  ROUTE_ORIGIN_STATIC   = 255,
-
-  // route inheritance flags
-  ROUTE_FLAG_CHILD_INHERIT = 1,
-  ROUTE_FLAG_CAPTURE       = 2
-};
-
-
-/**
- * \ingroup management
  * \brief represents a rib/register command
  * \sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Register-a-route
  */