Upgrade the underlying NFD to version 0.5.0

Change-Id: I61eb240cb982eb5e675a63aece0c373290c59129
Refs: #3839
diff --git a/app/build.gradle b/app/build.gradle
index 374c9d5..cf11041 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,8 +10,8 @@
         applicationId "net.named_data.nfd"
         minSdkVersion 15
         targetSdkVersion 19
-        versionCode 4001
-        versionName "0.2.1 (NFD 0.4.0-3-g4100646)"
+        versionCode 4002
+        versionName "0.2.2 (NFD 0.5.0)"
     }
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_7
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a5bab95..9ac597f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,8 @@
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.READ_LOGS" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
 
     <application
         android:allowBackup="true"
diff --git a/app/src/main/jni/NFD b/app/src/main/jni/NFD
index 4100646..6701911 160000
--- a/app/src/main/jni/NFD
+++ b/app/src/main/jni/NFD
@@ -1 +1 @@
-Subproject commit 410064619292ca9551c9fdbf0aaca02061df3b54
+Subproject commit 67019110d71d25d9acf1bb7791ad9828dbabd757
diff --git a/app/src/main/jni/ndn-cxx b/app/src/main/jni/ndn-cxx
index 6617e49..ed1e99d 160000
--- a/app/src/main/jni/ndn-cxx
+++ b/app/src/main/jni/ndn-cxx
@@ -1 +1 @@
-Subproject commit 6617e498785ac8b8f88751a9b319308beb5e77cc
+Subproject commit ed1e99daa08642822cb722136294724ec5a9cf26
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
index 92a02e8..f669a93 100644
--- a/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-config.hpp
@@ -1,16 +1,17 @@
 #ifndef W_SRC_NDN_CXX_CONFIG_HPP_WAF
 #define W_SRC_NDN_CXX_CONFIG_HPP_WAF
 
+#define NDN_CXX_HAVE_STD_TO_STRING 1
+#define NDN_CXX_HAVE_VECTOR_INSERT_ERASE_CONST_ITERATOR 1
 #define NDN_CXX_HAVE_IS_DEFAULT_CONSTRUCTIBLE 1
 #define NDN_CXX_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE 1
 #define NDN_CXX_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE 1
-#define NDN_CXX_HAVE_CXX_FRIEND_TYPENAME 1
-#define NDN_CXX_HAVE_CXX_OVERRIDE_FINAL 1
-#define NDN_CXX_NDN_CXX_HAVE_VECTOR_INSERT_ERASE_CONST_ITERATOR 1
-#define NDN_CXX_HAVE_PTHREAD 1
 #define NDN_CXX_HAVE_RT
+#define NDN_CXX_HAVE_PTHREAD 1
 #define NDN_CXX_HAVE_SQLITE3 1
-#define NDN_CXX_HAVE_CRYPTOPP_CONFIG_H 1
 #define NDN_CXX_SYSCONFDIR "./etc"
+#define NDN_CXX_NDEBUG 1
+#define NDEBUG 1
+#define HAVE_NDN_CXX_CUSTOM_LOGGER 1
 
 #endif /* W_SRC_NDN_CXX_CONFIG_HPP_WAF */
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp
new file mode 100644
index 0000000..41cae15
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 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 "ndn-cxx-custom-logger.hpp"
+#include "ndn-cxx-custom-logging.hpp"
+
+#include <cinttypes>
+#include <stdio.h>
+#include <type_traits>
+
+namespace ndn {
+namespace util {
+
+std::ostream&
+operator<<(std::ostream& os, LogLevel level)
+{
+  switch (level) {
+  case LogLevel::FATAL:
+    return os << "FATAL";
+  case LogLevel::NONE:
+    return os << "NONE";
+  case LogLevel::ERROR:
+    return os << "ERROR";
+  case LogLevel::WARN:
+    return os << "WARN";
+  case LogLevel::INFO:
+    return os << "INFO";
+  case LogLevel::DEBUG:
+    return os << "DEBUG";
+  case LogLevel::TRACE:
+    return os << "TRACE";
+  case LogLevel::ALL:
+    return os << "ALL";
+  }
+
+  BOOST_THROW_EXCEPTION(std::invalid_argument("unknown log level " + to_string(static_cast<int>(level))));
+}
+
+LogLevel
+parseLogLevel(const std::string& s)
+{
+  if (s == "FATAL")
+    return LogLevel::FATAL;
+  else if (s == "NONE")
+    return LogLevel::NONE;
+  else if (s == "ERROR")
+    return LogLevel::ERROR;
+  else if (s == "WARN")
+    return LogLevel::WARN;
+  else if (s == "INFO")
+    return LogLevel::INFO;
+  else if (s == "DEBUG")
+    return LogLevel::DEBUG;
+  else if (s == "TRACE")
+    return LogLevel::TRACE;
+  else if (s == "ALL")
+    return LogLevel::ALL;
+
+  BOOST_THROW_EXCEPTION(std::invalid_argument("unrecognized log level '" + s + "'"));
+}
+
+Logger::Logger(const std::string& name)
+  : m_moduleName(name)
+{
+  this->setLevel(LogLevel::NONE);
+  Logging::addLogger(*this);
+}
+
+} // namespace util
+} // namespace ndn
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp
new file mode 100644
index 0000000..892c1d5
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logger.hpp
@@ -0,0 +1,121 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 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 NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
+#define NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
+
+#include "common.hpp"
+#include <atomic>
+#include <android/log.h>
+
+namespace ndn {
+namespace util {
+
+/** \brief indicates the severity level of a log message
+ */
+enum class LogLevel {
+  FATAL   = -1,   ///< fatal (will be logged unconditionally)
+  NONE    = 0,    ///< no messages
+  ERROR   = 1,    ///< serious error messages
+  WARN    = 2,    ///< warning messages
+  INFO    = 3,    ///< informational messages
+  DEBUG   = 4,    ///< debug messages
+  TRACE   = 5,    ///< trace messages (most verbose)
+  ALL     = 255   ///< all messages
+};
+
+/** \brief output LogLevel as string
+ *  \throw std::invalid_argument unknown \p level
+ */
+std::ostream&
+operator<<(std::ostream& os, LogLevel level);
+
+/** \brief parse LogLevel from string
+ *  \throw std::invalid_argument unknown level name
+ */
+LogLevel
+parseLogLevel(const std::string& s);
+
+/** \brief represents a logger in logging facility
+ *  \note User should declare a new logger with \p NDN_LOG_INIT macro.
+ */
+class Logger
+{
+public:
+  explicit
+  Logger(const std::string& name);
+
+  const std::string&
+  getModuleName() const
+  {
+    return m_moduleName;
+  }
+
+  bool
+  isLevelEnabled(LogLevel level) const
+  {
+    return m_currentLevel.load(std::memory_order_relaxed) >= level;
+  }
+
+  void
+  setLevel(LogLevel level)
+  {
+    m_currentLevel.store(level, std::memory_order_relaxed);
+  }
+
+private:
+  const std::string m_moduleName;
+  std::atomic<LogLevel> m_currentLevel;
+};
+
+/** \brief declare a log module
+ */
+#define NDN_LOG_INIT(name) \
+  namespace { \
+    inline ::ndn::util::Logger& getNdnCxxLogger() \
+    { \
+      static ::ndn::util::Logger logger(BOOST_STRINGIZE(name)); \
+      return logger; \
+    } \
+  } \
+  struct ndn_cxx__allow_trailing_semicolon
+
+#define NDN_LOG(level, androidLevel, msg, expression)   \
+  do { \
+      if (getNdnCxxLogger().isLevelEnabled(::ndn::util::LogLevel::level)) {           \
+      std::ostringstream os;                                              \
+      os << expression;                                                   \
+      __android_log_print(ANDROID_LOG_##androidLevel,                     \
+                          getNdnCxxLogger().getModuleName().c_str(), "%s", os.str().c_str()); \
+    }                                                                     \
+  } while (false)
+
+#define NDN_LOG_TRACE(expression) NDN_LOG(TRACE, VERBOSE, TRACE, expression)
+#define NDN_LOG_DEBUG(expression) NDN_LOG(DEBUG, DEBUG, DEBUG,   expression)
+#define NDN_LOG_INFO(expression)  NDN_LOG(INFO,  INFO,  INFO,    expression)
+#define NDN_LOG_WARN(expression)  NDN_LOG(WARN,  WARN,  WARNING, expression)
+#define NDN_LOG_ERROR(expression) NDN_LOG(ERROR, ERROR, ERROR,   expression)
+#define NDN_LOG_FATAL(expression) NDN_LOG(FATAL, FATAL, FATAL,   expression)
+
+} // namespace util
+} // namespace ndn
+
+#endif // NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGER_HPP
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp
new file mode 100644
index 0000000..845d412
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 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 "ndn-cxx-custom-logging.hpp"
+#include "ndn-cxx-custom-logger.hpp"
+
+#include <cstdlib>
+#include <sstream>
+
+namespace ndn {
+namespace util {
+
+static const LogLevel INITIAL_DEFAULT_LEVEL = LogLevel::NONE;
+
+Logging&
+Logging::get()
+{
+  // Initialization of block-scope variables with static storage duration is thread-safe.
+  // See ISO C++ standard [stmt.dcl]/4
+  static Logging instance;
+  return instance;
+}
+
+Logging::Logging()
+{
+}
+
+void
+Logging::addLoggerImpl(Logger& logger)
+{
+  std::lock_guard<std::mutex> lock(m_mutex);
+
+  const std::string& moduleName = logger.getModuleName();
+  m_loggers.insert({moduleName, &logger});
+
+  auto levelIt = m_enabledLevel.find(moduleName);
+  if (levelIt == m_enabledLevel.end()) {
+    levelIt = m_enabledLevel.find("*");
+  }
+  LogLevel level = levelIt == m_enabledLevel.end() ? INITIAL_DEFAULT_LEVEL : levelIt->second;
+  logger.setLevel(level);
+}
+
+void
+Logging::setLevelImpl(const std::string& moduleName, LogLevel level)
+{
+  std::lock_guard<std::mutex> lock(m_mutex);
+
+  if (moduleName == "*") {
+    this->setDefaultLevel(level);
+    return;
+  }
+
+  m_enabledLevel[moduleName] = level;
+  auto range = m_loggers.equal_range(moduleName);
+  for (auto i = range.first; i != range.second; ++i) {
+    i->second->setLevel(level);
+  }
+}
+
+void
+Logging::setDefaultLevel(LogLevel level)
+{
+  m_enabledLevel.clear();
+  m_enabledLevel["*"] = level;
+
+  for (auto i = m_loggers.begin(); i != m_loggers.end(); ++i) {
+    i->second->setLevel(level);
+  }
+}
+
+void
+Logging::setLevelImpl(const std::string& config)
+{
+  std::stringstream ss(config);
+  std::string configModule;
+  while (std::getline(ss, configModule, ':')) {
+    size_t ind = configModule.find('=');
+    if (ind == std::string::npos) {
+      BOOST_THROW_EXCEPTION(std::invalid_argument("malformed logging config: '=' is missing"));
+    }
+
+    std::string moduleName = configModule.substr(0, ind);
+    LogLevel level = parseLogLevel(configModule.substr(ind+1));
+
+    this->setLevelImpl(moduleName, level);
+  }
+}
+
+} // namespace util
+} // namespace ndn
diff --git a/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp
new file mode 100644
index 0000000..b59b927
--- /dev/null
+++ b/app/src/main/jni/ndn-cxx-android/ndn-cxx-custom-logging.hpp
@@ -0,0 +1,126 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 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 NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP
+#define NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP
+
+#include "common.hpp"
+
+#include <mutex>
+#include <unordered_map>
+
+namespace ndn {
+namespace util {
+
+enum class LogLevel;
+class Logger;
+
+/** \brief controls the logging facility
+ *
+ *  \note Public static methods are thread safe.
+ *        Non-public methods are not guaranteed to be thread safe.
+ */
+class Logging : noncopyable
+{
+public:
+  /** \brief register a new logger
+   *  \note App should declare a new logger with \p NDN_LOG_INIT macro.
+   */
+  static void
+  addLogger(Logger& logger);
+
+  /** \brief set severity level
+   *  \param moduleName logger name, or "*" for default level
+   *  \param level minimum severity level
+   *
+   *  Log messages are output only if its severity is greater than the set minimum severity level.
+   *  Initial default severity level is \p LogLevel::NONE which enables FATAL only.
+   *
+   *  Changing the default level overwrites individual settings.
+   */
+  static void
+  setLevel(const std::string& moduleName, LogLevel level);
+
+  /** \brief set severity levels with a config string
+   *  \param config colon-separate key=value pairs
+   *  \throw std::invalid_argument config string is malformed
+   *
+   *  \code
+   *  Logging::setSeverityLevels("*=INFO:Face=DEBUG:NfdController=WARN");
+   *  \endcode
+   *  is equivalent to
+   *  \code
+   *  Logging::setSeverityLevel("*", LogLevel::INFO);
+   *  Logging::setSeverityLevel("Face", LogLevel::DEBUG);
+   *  Logging::setSeverityLevel("NfdController", LogLevel::WARN);
+   *  \endcode
+   */
+  static void
+  setLevel(const std::string& config);
+
+private:
+  Logging();
+
+  void
+  addLoggerImpl(Logger& logger);
+
+  void
+  setLevelImpl(const std::string& moduleName, LogLevel level);
+
+  void
+  setDefaultLevel(LogLevel level);
+
+  void
+  setLevelImpl(const std::string& config);
+
+NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+  static Logging&
+  get();
+
+private:
+  std::mutex m_mutex;
+  std::unordered_map<std::string, LogLevel> m_enabledLevel; ///< moduleName => minimum level
+  std::unordered_multimap<std::string, Logger*> m_loggers; ///< moduleName => logger
+};
+
+inline void
+Logging::addLogger(Logger& logger)
+{
+  get().addLoggerImpl(logger);
+}
+
+inline void
+Logging::setLevel(const std::string& moduleName, LogLevel level)
+{
+  get().setLevelImpl(moduleName, level);
+}
+
+inline void
+Logging::setLevel(const std::string& config)
+{
+  get().setLevelImpl(config);
+}
+
+
+} // namespace util
+} // namespace ndn
+
+#endif // NFD_ANDROID_NDN_CXX_ANDROID_NDN_CXX_CUSTOM_LOGGING_HPP
diff --git a/app/src/main/jni/ndn-cxx.mk b/app/src/main/jni/ndn-cxx.mk
index 34f2302..d467bac 100644
--- a/app/src/main/jni/ndn-cxx.mk
+++ b/app/src/main/jni/ndn-cxx.mk
@@ -4,12 +4,13 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := ndn-cxx
 NDN_CXX_BOOST_LIBS = system filesystem date_time iostreams program_options chrono random
-LOCAL_SHARED_LIBRARIES := cryptopp_shared $(addsuffix _shared,$(addprefix boost_,$(NDN_CXX_BOOST_LIBS)))
+LOCAL_SHARED_LIBRARIES := cryptopp_shared opencrypto_shared openssl_shared $(addsuffix _shared,$(addprefix boost_,$(NDN_CXX_BOOST_LIBS)))
 LOCAL_STATIC_LIBRARIES := sqlite3_static boost_regex_static
 NDN_CXX_SRC_FILES := \
     data.cpp \
-    encoding/block.cpp \
     encoding/block-helpers.cpp \
+    encoding/block.cpp \
+    encoding/buffer-stream.cpp \
     encoding/buffer.cpp \
     encoding/cryptopp/asn_ext.cpp \
     encoding/encoder.cpp \
@@ -27,33 +28,30 @@
     lp/nack-header.cpp \
     lp/nack.cpp \
     lp/packet.cpp \
-    lp/tags.cpp \
-    management/nfd-channel-status.cpp \
-    management/nfd-command-options.cpp \
-    management/nfd-control-command.cpp \
-    management/nfd-control-parameters.cpp \
-    management/nfd-controller.cpp \
-    management/nfd-face-event-notification.cpp \
-    management/nfd-face-query-filter.cpp \
-    management/nfd-face-status.cpp \
-    management/nfd-fib-entry.cpp \
-    management/nfd-forwarder-status.cpp \
-    management/nfd-rib-entry.cpp \
-    management/nfd-strategy-choice.cpp \
     meta-info.cpp \
     mgmt/control-response.cpp \
     mgmt/dispatcher.cpp \
+    mgmt/nfd/channel-status.cpp \
+    mgmt/nfd/command-options.cpp \
+    mgmt/nfd/control-command.cpp \
+    mgmt/nfd/control-parameters.cpp \
+    mgmt/nfd/controller.cpp \
+    mgmt/nfd/face-event-notification.cpp \
+    mgmt/nfd/face-query-filter.cpp \
+    mgmt/nfd/face-status.cpp \
+    mgmt/nfd/fib-entry.cpp \
+    mgmt/nfd/forwarder-status.cpp \
+    mgmt/nfd/rib-entry.cpp \
+    mgmt/nfd/status-dataset.cpp \
+    mgmt/nfd/strategy-choice.cpp \
     mgmt/status-dataset-context.cpp \
     name-component.cpp \
     name.cpp \
-    security/additional-description.cpp \
     security/certificate-cache-ttl.cpp \
     security/certificate-container.cpp \
-    security/certificate-extension.cpp \
-    security/certificate-subject-description.cpp \
-    security/certificate.cpp \
+    security/command-interest-validator.cpp \
+    security/detail/openssl-helper.cpp \
     security/digest-sha256.cpp \
-    security/identity-certificate.cpp \
     security/identity-container.cpp \
     security/identity.cpp \
     security/key-chain.cpp \
@@ -63,7 +61,7 @@
     security/pib-memory.cpp \
     security/pib-sqlite3.cpp \
     security/pib.cpp \
-    security/public-key.cpp \
+    security/safe-bag.cpp \
     security/sec-public-info-sqlite3.cpp \
     security/sec-public-info.cpp \
     security/sec-rule-relative.cpp \
@@ -71,10 +69,35 @@
     security/sec-tpm-file.cpp \
     security/sec-tpm.cpp \
     security/secured-bag.cpp \
+    security/security-common.cpp \
     security/signature-sha256-with-ecdsa.cpp \
     security/signature-sha256-with-rsa.cpp \
     security/signing-helpers.cpp \
     security/signing-info.cpp \
+    security/transform/base64-decode.cpp \
+    security/transform/base64-encode.cpp \
+    security/transform/block-cipher.cpp \
+    security/transform/bool-sink.cpp \
+    security/transform/buffer-source.cpp \
+    security/transform/digest-filter.cpp \
+    security/transform/hex-decode.cpp \
+    security/transform/hex-encode.cpp \
+    security/transform/hmac-filter.cpp \
+    security/transform/private-key.cpp \
+    security/transform/public-key.cpp \
+    security/transform/signer-filter.cpp \
+    security/transform/step-source.cpp \
+    security/transform/stream-sink.cpp \
+    security/transform/stream-source.cpp \
+    security/transform/strip-space.cpp \
+    security/transform/transform-base.cpp \
+    security/transform/verifier-filter.cpp \
+    security/v1/certificate-extension.cpp \
+    security/v1/certificate-subject-description.cpp \
+    security/v1/certificate.cpp \
+    security/v1/identity-certificate.cpp \
+    security/v1/public-key.cpp \
+    security/v2/additional-description.cpp \
     security/validator-config.cpp \
     security/validator-regex.cpp \
     security/validator.cpp \
@@ -83,6 +106,7 @@
     signature-info.cpp \
     signature.cpp \
     transport/tcp-transport.cpp \
+    transport/transport.cpp \
     transport/unix-transport.cpp \
     util/config-file.cpp \
     util/crypto.cpp \
@@ -98,6 +122,7 @@
     util/in-memory-storage-persistent.cpp \
     util/in-memory-storage.cpp \
     util/indented-stream.cpp \
+    util/io.cpp \
     util/network-monitor.cpp \
     util/random.cpp \
     util/regex/regex-top-matcher.cpp \
@@ -109,13 +134,17 @@
     util/sqlite3-statement.cpp \
     util/string-helper.cpp \
     util/time-unit-test-clock.cpp \
-    util/time.cpp
+    util/time.cpp \
+    ../../ndn-cxx-android/ndn-cxx-custom-logger.cpp \
+    ../../ndn-cxx-android/ndn-cxx-custom-logging.cpp
 LOCAL_SRC_FILES := $(addprefix ndn-cxx/src/,$(NDN_CXX_SRC_FILES))
 LOCAL_CPPFLAGS := -I$(LOCAL_PATH)/ndn-cxx/src -I$(LOCAL_PATH)/ndn-cxx-android -I$(LOCAL_PATH)/../../../build/generated/source/ndn-cxx
 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ndn-cxx-android $(LOCAL_PATH)/../../../build/generated/source/include
+LOCAL_LDLIBS := -llog
 include $(BUILD_SHARED_LIBRARY)
 
 include $(LOCAL_PATH_SAVED)/cryptopp/extras/jni/Android.mk
 
 $(call import-module,boost/1.59.0)
 $(call import-module,sqlite/3)
+$(call import-module,openssl/1.0.2h)
diff --git a/app/src/main/jni/nfd-android/config.hpp b/app/src/main/jni/nfd-android/core/config.hpp
similarity index 86%
rename from app/src/main/jni/nfd-android/config.hpp
rename to app/src/main/jni/nfd-android/core/config.hpp
index bcbd6a6..30c61c2 100644
--- a/app/src/main/jni/nfd-android/config.hpp
+++ b/app/src/main/jni/nfd-android/core/config.hpp
@@ -3,10 +3,9 @@
 
 #define HAVE_IS_DEFAULT_CONSTRUCTIBLE 1
 #define HAVE_IS_MOVE_CONSTRUCTIBLE 1
-#define HAVE_CXX_OVERRIDE 1
-#define HAVE_STD_TO_STRING 1
 #define HAVE_LIBRT
 #define HAVE_LIBRESOLV
+// #define HAVE_IFADDRS_H 1
 /*#undef HAVE_UNIX_SOCKETS*/
 #define HAVE_WEBSOCKET 1
 #define _WEBSOCKETPP_CPP11_STL_ 1
@@ -14,4 +13,6 @@
 #define HAVE_CUSTOM_LOGGER 1
 #define NDEBUG 1
 
+#define BOOST_LOG_DYN_LINK 1
+
 #endif /* W_CONFIG_HPP_WAF */
diff --git a/app/src/main/jni/nfd-android/version.hpp b/app/src/main/jni/nfd-android/core/version.hpp
similarity index 73%
rename from app/src/main/jni/nfd-android/version.hpp
rename to app/src/main/jni/nfd-android/core/version.hpp
index e62d6b7..0b1f451 100644
--- a/app/src/main/jni/nfd-android/version.hpp
+++ b/app/src/main/jni/nfd-android/core/version.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  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
+ * Copyright (c) 2014-2016,  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.
@@ -23,8 +23,8 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef NFD_VERSION_HPP
-#define NFD_VERSION_HPP
+#ifndef NFD_CORE_VERSION_HPP
+#define NFD_CORE_VERSION_HPP
 
 namespace nfd {
 
@@ -38,13 +38,13 @@
  *
  *  MAJOR*1000000 + MINOR*1000 + PATCH
  */
-#define NFD_VERSION 4000
+#define NFD_VERSION 5000
 
 /** \brief NFD version represented as a string
  *
  *  MAJOR.MINOR.PATCH
  */
-#define NFD_VERSION_STRING "0.4.0"
+#define NFD_VERSION_STRING "0.5.0"
 
 /** \brief NFD version string, including git commit information, if NFD is build from
  *         specific git commit
@@ -60,15 +60,15 @@
  *
  * Example, 0.1.0-rc1-1-g5c86570
  */
-#define NFD_VERSION_BUILD_STRING "0.4.0-3-g4100646"
+#define NFD_VERSION_BUILD_STRING "0.5.0"
 
 /// MAJOR version
 #define NFD_VERSION_MAJOR 0
 /// MINOR version
-#define NFD_VERSION_MINOR 4
+#define NFD_VERSION_MINOR 5
 /// PATCH version
 #define NFD_VERSION_PATCH 0
 
 } // namespace nfd
 
-#endif // NFD_VERSION_HPP
+#endif // NFD_CORE_VERSION_HPP
diff --git a/app/src/main/jni/nfd-android/custom-logger-factory.cpp b/app/src/main/jni/nfd-android/custom-logger-factory.cpp
index f84a663..c1d2157 100644
--- a/app/src/main/jni/nfd-android/custom-logger-factory.cpp
+++ b/app/src/main/jni/nfd-android/custom-logger-factory.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  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
+ * Copyright (c) 2014-2016,  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.
@@ -20,7 +21,7 @@
  *
  * 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/>.
- **/
+ */
 
 #include "custom-logger-factory.hpp"
 
diff --git a/app/src/main/jni/nfd-android/custom-logger-factory.hpp b/app/src/main/jni/nfd-android/custom-logger-factory.hpp
index 10a961e..f158b81 100644
--- a/app/src/main/jni/nfd-android/custom-logger-factory.hpp
+++ b/app/src/main/jni/nfd-android/custom-logger-factory.hpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  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
+ * Copyright (c) 2014-2016,  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.
@@ -20,12 +21,12 @@
  *
  * 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_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
 #define NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
 
-#include "common.hpp"
+#include "core/common.hpp"
 
 #include "core/config-file.hpp"
 #include "core/logger.hpp"
diff --git a/app/src/main/jni/nfd-android/custom-logger.cpp b/app/src/main/jni/nfd-android/custom-logger.cpp
index 6b5d3ae..d5e7ca1 100644
--- a/app/src/main/jni/nfd-android/custom-logger.cpp
+++ b/app/src/main/jni/nfd-android/custom-logger.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
diff --git a/app/src/main/jni/nfd-android/custom-logger.hpp b/app/src/main/jni/nfd-android/custom-logger.hpp
index 5355657..2033967 100644
--- a/app/src/main/jni/nfd-android/custom-logger.hpp
+++ b/app/src/main/jni/nfd-android/custom-logger.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  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
+ * Copyright (c) 2014-2016,  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.
@@ -26,7 +26,7 @@
 #ifndef NFD_ANDROID_CUSTOM_LOGGER_HPP
 #define NFD_ANDROID_CUSTOM_LOGGER_HPP
 
-#include "common.hpp"
+#include "core/common.hpp"
 #include <android/log.h>
 
 namespace nfd {
diff --git a/app/src/main/jni/nfd-wrapper.cpp b/app/src/main/jni/nfd-wrapper.cpp
index 8bf6379..90e19ed 100644
--- a/app/src/main/jni/nfd-wrapper.cpp
+++ b/app/src/main/jni/nfd-wrapper.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2015 Regents of the University of California
+ * Copyright (c) 2015-2016 Regents of the University of California
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
  * See AUTHORS.md for complete list of NFD Android authors and contributors.
@@ -20,7 +20,7 @@
 #include "nfd-wrapper.hpp"
 
 #include "daemon/nfd.hpp"
-#include "rib/nrd.hpp"
+#include "rib/service.hpp"
 
 #include "core/global-io.hpp"
 #include "core/config-file.hpp"
@@ -152,7 +152,7 @@
 
     std::unique_lock<std::mutex> lock(m_pointerMutex);
     m_nfd.reset(new Nfd(m_config, m_keyChain));
-    m_nrd.reset(new rib::Nrd(m_config, m_keyChain));
+    m_nrd.reset(new rib::Service(m_config, m_keyChain));
 
     m_nfd->initialize();
     m_nrd->initialize();
@@ -193,7 +193,7 @@
   boost::asio::io_service* m_io;
   ndn::KeyChain m_keyChain;
   unique_ptr<Nfd> m_nfd; // will use globalIoService
-  unique_ptr<rib::Nrd> m_nrd; // will use globalIoService
+  unique_ptr<rib::Service> m_nrd; // will use globalIoService
 
   nfd::ConfigSection m_config;
 };
diff --git a/app/src/main/jni/nfd.mk b/app/src/main/jni/nfd.mk
index daeebb5..c8e6818 100644
--- a/app/src/main/jni/nfd.mk
+++ b/app/src/main/jni/nfd.mk
@@ -6,11 +6,12 @@
 # nfd itself
 include $(CLEAR_VARS)
 LOCAL_MODULE := nfd-daemon
-LOCAL_SHARED_LIBRARIES := cryptopp_shared ndn-cxx $(addsuffix _shared,$(addprefix boost_,$(NFD_BOOST_LIBS)))
+LOCAL_SHARED_LIBRARIES := cryptopp_shared openssl_shared ndn-cxx $(addsuffix _shared,$(addprefix boost_,$(NFD_BOOST_LIBS)))
 NFD_DAEMON_SRC_FILES := \
     core/city-hash.cpp \
     core/config-file.cpp \
     core/global-io.cpp \
+    core/manager-base.cpp \
     core/network-interface.cpp \
     core/network.cpp \
     core/privilege-helper.cpp \
@@ -20,8 +21,8 @@
     ../nfd-android/custom-logger-factory.cpp \
     \
     daemon/face/channel.cpp \
-    daemon/face/face.cpp \
     daemon/face/face-counters.cpp \
+    daemon/face/face.cpp \
     daemon/face/generic-link-service.cpp \
     daemon/face/internal-face.cpp \
     daemon/face/internal-transport.cpp \
@@ -42,32 +43,38 @@
     daemon/face/websocket-factory.cpp \
     daemon/face/websocket-transport.cpp \
     daemon/fw/access-strategy.cpp \
+    daemon/fw/asf-measurements.cpp \
+    daemon/fw/asf-probing-module.cpp \
+    daemon/fw/asf-strategy.cpp \
     daemon/fw/best-route-strategy.cpp \
     daemon/fw/best-route-strategy2.cpp \
-    daemon/fw/broadcast-strategy.cpp \
     daemon/fw/client-control-strategy.cpp \
     daemon/fw/face-table.cpp \
     daemon/fw/forwarder.cpp \
     daemon/fw/multicast-strategy.cpp \
     daemon/fw/ncc-strategy.cpp \
+    daemon/fw/pit-algorithm.cpp \
     daemon/fw/retx-suppression-exponential.cpp \
     daemon/fw/retx-suppression-fixed.cpp \
     daemon/fw/retx-suppression.cpp \
     daemon/fw/rtt-estimator.cpp \
     daemon/fw/strategy-registry.cpp \
     daemon/fw/strategy.cpp \
-    daemon/mgmt/command-validator.cpp \
+    daemon/fw/unsolicited-data-policy.cpp \
+    daemon/main.cpp \
+    daemon/mgmt/command-authenticator.cpp \
     daemon/mgmt/face-manager.cpp \
     daemon/mgmt/fib-manager.cpp \
     daemon/mgmt/forwarder-status-manager.cpp \
     daemon/mgmt/general-config-section.cpp \
-    daemon/mgmt/manager-base.cpp \
+    daemon/mgmt/nfd-manager-base.cpp \
     daemon/mgmt/strategy-choice-manager.cpp \
     daemon/mgmt/tables-config-section.cpp \
     daemon/nfd.cpp \
+    daemon/table/cleanup.cpp \
     daemon/table/cs-entry-impl.cpp \
     daemon/table/cs-entry.cpp \
-    daemon/table/cs-policy-lru.cpp  \
+    daemon/table/cs-policy-lru.cpp \
     daemon/table/cs-policy-priority-fifo.cpp \
     daemon/table/cs-policy.cpp \
     daemon/table/cs.cpp \
@@ -79,11 +86,14 @@
     daemon/table/measurements-entry.cpp \
     daemon/table/measurements.cpp \
     daemon/table/name-tree-entry.cpp \
+    daemon/table/name-tree-hashtable.cpp \
+    daemon/table/name-tree-iterator.cpp \
     daemon/table/name-tree.cpp \
     daemon/table/network-region-table.cpp \
     daemon/table/pit-entry.cpp \
     daemon/table/pit-face-record.cpp \
     daemon/table/pit-in-record.cpp \
+    daemon/table/pit-iterator.cpp \
     daemon/table/pit-out-record.cpp \
     daemon/table/pit.cpp \
     daemon/table/strategy-choice-entry.cpp \
@@ -93,15 +103,14 @@
     rib/auto-prefix-propagator.cpp \
     rib/fib-update.cpp \
     rib/fib-updater.cpp \
-    rib/nrd.cpp \
     rib/propagated-entry.cpp \
     rib/rib-entry.cpp \
     rib/rib-manager.cpp \
-    rib/rib-status-publisher.cpp \
     rib/rib-update-batch.cpp \
     rib/rib-update.cpp \
     rib/rib.cpp \
-    rib/route.cpp
+    rib/route.cpp \
+    rib/service.cpp
 LOCAL_SRC_FILES := $(addprefix NFD/,$(NFD_DAEMON_SRC_FILES))
 LOCAL_CPPFLAGS := \
     -I$(LOCAL_PATH)/nfd-android \