Upgrade underlying NFD/ndn-cxx to version 0.6.5

Change-Id: If83629472f737c017bbd9109fe814a5d5ecc44d4
diff --git a/helper/ndn-app-helper.cpp b/helper/ndn-app-helper.cpp
index 2556659..0fe7f5c 100644
--- a/helper/ndn-app-helper.cpp
+++ b/helper/ndn-app-helper.cpp
@@ -84,15 +84,20 @@
 Ptr<Application>
 AppHelper::InstallPriv(Ptr<Node> node)
 {
+  Ptr<Application> app;
+  Simulator::ScheduleWithContext(node->GetId(), Seconds(0), MakeEvent([=, &app] {
 #ifdef NS3_MPI
-  if (MpiInterface::IsEnabled() && node->GetSystemId() != MpiInterface::GetSystemId()) {
-    // don't create an app if MPI is enabled and node is not in the correct partition
-    return 0;
-  }
+        if (MpiInterface::IsEnabled() && node->GetSystemId() != MpiInterface::GetSystemId()) {
+          // don't create an app if MPI is enabled and node is not in the correct partition
+          return 0;
+        }
 #endif
 
-  Ptr<Application> app = m_factory.Create<Application>();
-  node->AddApplication(app);
+        app = m_factory.Create<Application>();
+        node->AddApplication(app);
+      }));
+  Simulator::Stop(Seconds(0));
+  Simulator::Run();
 
   return app;
 }
diff --git a/helper/ndn-face-container.cpp b/helper/ndn-face-container.cpp
deleted file mode 100644
index 5e9c6e3..0000000
--- a/helper/ndn-face-container.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2015  Regents of the University of California.
- *
- * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
- * contributors.
- *
- * ndnSIM is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndnSIM, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#include "ndn-face-container.hpp"
-
-#include <algorithm>
-
-namespace ns3 {
-namespace ndn {
-
-FaceContainer::FaceContainer() = default;
-
-FaceContainer::FaceContainer(const FaceContainer& other)
-{
-  AddAll(other);
-}
-
-FaceContainer&
-FaceContainer::operator= (const FaceContainer &other)
-{
-  m_faces.clear();
-  AddAll(other);
-
-  return *this;
-}
-
-void
-FaceContainer::AddAll(Ptr<FaceContainer> other)
-{
-  AddAll(*other);
-}
-
-void
-FaceContainer::AddAll(const FaceContainer& other)
-{
-  if (this == &other) { // adding self to self, need to make a copy
-    auto copyOfFaces = other.m_faces;
-    m_faces.insert(m_faces.end(), copyOfFaces.begin(), copyOfFaces.end());
-  }
-  else {
-    m_faces.insert(m_faces.end(), other.m_faces.begin(), other.m_faces.end());
-  }
-}
-
-FaceContainer::Iterator
-FaceContainer::Begin(void) const
-{
-  return m_faces.begin();
-}
-
-FaceContainer::Iterator
-FaceContainer::End(void) const
-{
-  return m_faces.end();
-}
-
-uint32_t
-FaceContainer::GetN(void) const
-{
-  return m_faces.size();
-}
-
-void
-FaceContainer::Add(shared_ptr<Face> face)
-{
-  m_faces.push_back(face);
-}
-
-shared_ptr<Face>
-FaceContainer::Get(size_t i) const
-{
-  return m_faces.at(i);
-}
-
-} // namespace ndn
-} // namespace ns3
diff --git a/helper/ndn-face-container.hpp b/helper/ndn-face-container.hpp
deleted file mode 100644
index 545ff4d..0000000
--- a/helper/ndn-face-container.hpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2011-2015  Regents of the University of California.
- *
- * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
- * contributors.
- *
- * ndnSIM is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndnSIM, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
-
-#ifndef NDN_FACE_CONTAINER_H
-#define NDN_FACE_CONTAINER_H
-
-#include "ns3/ndnSIM/model/ndn-common.hpp"
-
-#include <stdint.h>
-#include <vector>
-
-#include "ns3/ptr.h"
-#include "ns3/simple-ref-count.h"
-
-namespace ns3 {
-namespace ndn {
-
-/**
- * @ingroup ndn-helpers
- * @brief A pool for Ndn faces
- *
- * Provides tools to perform basic manipulation on faces, such as setting metrics and
- * states on faces
- *
- * @see ndn::StackHelper
- */
-class FaceContainer : public SimpleRefCount<FaceContainer> {
-private:
-  typedef std::vector<shared_ptr<Face>> Container;
-
-public:
-  typedef Container::const_iterator Iterator; ///< @brief Iterator over FaceContainer
-
-  /**
-   * @brief Create an empty FaceContainer.
-   */
-  FaceContainer();
-
-  /**
-   * @brief Copy constructor for FaceContainer. Calls AddAll method
-   *
-   * @see FaceContainer::AddAll
-   */
-  FaceContainer(const FaceContainer& other);
-
-  /**
-   * @brief Copy operator for FaceContainer. Empties vector and calls AddAll method
-   *
-   * All previously obtained iterators (Begin() and End()) will be invalidated
-   *
-   * @see FaceContainer::AddAll
-   */
-  FaceContainer&
-  operator=(const FaceContainer& other);
-
-  /**
-   * Add an entry to the container
-   *
-   * @param face a smart pointer to a Face-derived object
-   */
-  void
-  Add(shared_ptr<Face> face);
-
-  /**
-   * @brief Add all entries from other container
-   *
-   * @param other smart pointer to a container
-   */
-  void
-  AddAll(Ptr<FaceContainer> other);
-
-  /**
-   * @brief Add all entries from other container
-   *
-   * @param other container
-   */
-  void
-  AddAll(const FaceContainer& other);
-
-public: // accessors
-  /**
-   * @brief Get an iterator which refers to the first pair in the
-   * container.
-   *
-   * @returns an iterator which refers to the first pair in the container.
-   */
-  Iterator
-  Begin() const;
-
-  /**
-   * @brief Get an iterator which indicates past-the-last Node in the
-   * container.
-   *
-   * @returns an iterator which indicates an ending condition for a loop.
-   */
-  Iterator
-  End() const;
-
-  /**
-   * @brief Get the number of faces stored in this container
-   *
-   * @returns the number of faces stored in this container
-   */
-  uint32_t
-  GetN() const;
-
-  /**
-   * Get a Face stored in the container
-   *
-   * @param pos index of the Face in the container
-   * @throw std::out_of_range if !(pos < GetN()).
-   */
-  shared_ptr<Face>
-  Get(size_t pos) const;
-
-private:
-  Container m_faces;
-};
-
-} // namespace ndn
-} // namespace ns3
-
-#endif /* NDN_FACE_CONTAINER_H */
diff --git a/helper/ndn-fib-helper.cpp b/helper/ndn-fib-helper.cpp
index a74ddb2..921c20f 100644
--- a/helper/ndn-fib-helper.cpp
+++ b/helper/ndn-fib-helper.cpp
@@ -50,7 +50,6 @@
 void
 FibHelper::AddNextHop(const ControlParameters& parameters, Ptr<Node> node)
 {
-  NS_LOG_DEBUG("Add Next Hop command was initialized");
   Block encodedParameters(parameters.wireEncode());
 
   Name commandName("/localhost/nfd/fib");
@@ -58,6 +57,7 @@
   commandName.append(encodedParameters);
 
   shared_ptr<Interest> command(make_shared<Interest>(commandName));
+  command->setCanBePrefix(false);
   StackHelper::getKeyChain().sign(*command);
 
   Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>();
@@ -67,7 +67,6 @@
 void
 FibHelper::RemoveNextHop(const ControlParameters& parameters, Ptr<Node> node)
 {
-  NS_LOG_DEBUG("Remove Next Hop command was initialized");
   Block encodedParameters(parameters.wireEncode());
 
   Name commandName("/localhost/nfd/fib");
@@ -75,6 +74,7 @@
   commandName.append(encodedParameters);
 
   shared_ptr<Interest> command(make_shared<Interest>(commandName));
+  command->setCanBePrefix(false);
   StackHelper::getKeyChain().sign(*command);
 
   Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>();
@@ -87,11 +87,6 @@
   NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << face->getLocalUri()
                    << " metric " << metric);
 
-  // Get L3Protocol object
-  Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>();
-  // Get the forwarder instance
-  shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->getForwarder();
-
   ControlParameters parameters;
   parameters.setName(prefix);
   parameters.setFaceId(face->getId());
@@ -177,6 +172,8 @@
 void
 FibHelper::RemoveRoute(Ptr<Node> node, const Name& prefix, shared_ptr<Face> face)
 {
+  NS_LOG_LOGIC("[" << node->GetId() << "]$ route del " << prefix << " via " << face->getLocalUri());
+
   // Get L3Protocol object
   Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>();
   // Get the forwarder instance
diff --git a/helper/ndn-scenario-helper.cpp b/helper/ndn-scenario-helper.cpp
index af74386..a36a7c7 100644
--- a/helper/ndn-scenario-helper.cpp
+++ b/helper/ndn-scenario-helper.cpp
@@ -65,18 +65,6 @@
 }
 
 void
-ScenarioHelper::disableRibManager()
-{
-  ndnHelper.disableRibManager();
-}
-
-// void
-// ScenarioHelper::disableFaceManager()
-// {
-//   ndnHelper.disableFaceManager();
-// }
-
-void
 ScenarioHelper::disableStrategyChoiceManager()
 {
   ndnHelper.disableStrategyChoiceManager();
diff --git a/helper/ndn-scenario-helper.hpp b/helper/ndn-scenario-helper.hpp
index 292bc85..6a318ac 100644
--- a/helper/ndn-scenario-helper.hpp
+++ b/helper/ndn-scenario-helper.hpp
@@ -166,19 +166,6 @@
   getNetDevice(const std::string& node1, const std::string& node2);
 
   /**
-   * \brief Disable RIB Manager
-   */
-  void
-  disableRibManager();
-
-  // Cannot be disabled for now
-  // /**
-  //  * \brief Disable Face Manager
-  //  */
-  // void
-  // disableFaceManager();
-
-  /**
    * \brief Disable Strategy Choice Manager
    */
   void
diff --git a/helper/ndn-stack-helper.cpp b/helper/ndn-stack-helper.cpp
index 8391843..d2b8abb 100644
--- a/helper/ndn-stack-helper.cpp
+++ b/helper/ndn-stack-helper.cpp
@@ -25,6 +25,7 @@
 #include "ns3/point-to-point-net-device.h"
 #include "ns3/point-to-point-channel.h"
 #include "ns3/node-list.h"
+#include "ns3/simulator.h"
 
 #include "model/ndn-l3-protocol.hpp"
 #include "model/ndn-net-device-transport.hpp"
@@ -46,9 +47,7 @@
 namespace ndn {
 
 StackHelper::StackHelper()
-  : m_isRibManagerDisabled(false)
-  // , m_isFaceManagerDisabled(false)
-  , m_isForwarderStatusManagerDisabled(false)
+  : m_isForwarderStatusManagerDisabled(false)
   , m_isStrategyChoiceManagerDisabled(false)
   , m_needSetDefaultRoutes(false)
   , m_maxCsSize(100)
@@ -152,43 +151,39 @@
   }
 }
 
-Ptr<FaceContainer>
+void
 StackHelper::Install(const NodeContainer& c) const
 {
-  Ptr<FaceContainer> faces = Create<FaceContainer>();
   for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
-    faces->AddAll(Install(*i));
+    Install(*i);
   }
-  return faces;
 }
 
-Ptr<FaceContainer>
+void
 StackHelper::InstallAll() const
 {
-  return Install(NodeContainer::GetGlobal());
+  Install(NodeContainer::GetGlobal());
 }
 
-Ptr<FaceContainer>
+void
 StackHelper::Install(Ptr<Node> node) const
 {
-  Ptr<FaceContainer> faces = Create<FaceContainer>();
-
   if (node->GetObject<L3Protocol>() != 0) {
     NS_FATAL_ERROR("Cannot re-install NDN stack on node "
                    << node->GetId());
-    return 0;
+    return;
   }
+  Simulator::ScheduleWithContext(node->GetId(), Seconds(0), &StackHelper::doInstall, this, node);
+  Simulator::Stop(Seconds(0));
+  Simulator::Run(); // to automatically dispatch events on proper nodes
+}
 
+void
+StackHelper::doInstall(Ptr<Node> node) const
+{
+  // async install to ensure proper context
   Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>();
 
-  if (m_isRibManagerDisabled) {
-    ndn->getConfig().put("ndnSIM.disable_rib_manager", true);
-  }
-
-  // if (m_isFaceManagerDisabled) {
-  //   ndn->getConfig().put("ndnSIM.disable_face_manager", true);
-  // }
-
   if (m_isForwarderStatusManagerDisabled) {
     ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true);
   }
@@ -218,10 +213,8 @@
     // if (DynamicCast<LoopbackNetDevice> (device) != 0)
     //   continue; // don't create face for a LoopbackNetDevice
 
-    faces->Add(this->createAndRegisterFace(node, ndn, device));
+    this->createAndRegisterFace(node, ndn, device);
   }
-
-  return faces;
 }
 
 void
@@ -332,11 +325,11 @@
   return face;
 }
 
-Ptr<FaceContainer>
+void
 StackHelper::Install(const std::string& nodeName) const
 {
   Ptr<Node> node = Names::Find<Node>(nodeName);
-  return Install(node);
+  Install(node);
 }
 
 void
@@ -400,24 +393,14 @@
 
   if (m_needSetDefaultRoutes) {
     // default route with lowest priority possible
-    FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
+    Simulator::ScheduleWithContext(node->GetId(), Seconds(0), MakeEvent([=] {
+          FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
+        }));
   }
   return face;
 }
 
 void
-StackHelper::disableRibManager()
-{
-  m_isRibManagerDisabled = true;
-}
-
-// void
-// StackHelper::disableFaceManager()
-// {
-//   m_isFaceManagerDisabled = true;
-// }
-
-void
 StackHelper::disableStrategyChoiceManager()
 {
   m_isStrategyChoiceManagerDisabled = true;
diff --git a/helper/ndn-stack-helper.hpp b/helper/ndn-stack-helper.hpp
index 2d2b8fb..18ce308 100644
--- a/helper/ndn-stack-helper.hpp
+++ b/helper/ndn-stack-helper.hpp
@@ -27,7 +27,6 @@
 #include "ns3/node.h"
 #include "ns3/node-container.h"
 
-#include "ndn-face-container.hpp"
 #include "ndn-fib-helper.hpp"
 #include "ndn-strategy-choice-helper.hpp"
 
@@ -143,7 +142,7 @@
   * \returns list of installed faces in the form of a smart pointer
   * to NdnFaceContainer object
   */
-  Ptr<FaceContainer>
+  void
   Install(const std::string& nodeName) const;
 
   /**
@@ -157,7 +156,7 @@
    * \returns list of installed faces in the form of a smart pointer
    * to FaceContainer object
    */
-  Ptr<FaceContainer>
+  void
   Install(Ptr<Node> node) const;
 
   /**
@@ -172,7 +171,7 @@
    * \returns list of installed faces in the form of a smart pointer
    * to FaceContainer object
    */
-  Ptr<FaceContainer>
+  void
   Install(const NodeContainer& c) const;
 
   /**
@@ -181,7 +180,7 @@
    * \returns list of installed faces in the form of a smart pointer
    * to FaceContainer object
    */
-  Ptr<FaceContainer>
+  void
   InstallAll() const;
 
   /**
@@ -224,19 +223,6 @@
   UpdateAll();
 
   /**
-   *\brief Disable the RIB manager of NFD
-   */
-  void
-  disableRibManager();
-
-  // Cannot be disabled for now
-  // /**
-  //  * \brief Disable Face Manager
-  //  */
-  // void
-  // disableFaceManager();
-
-  /**
    * \brief Disable Strategy Choice Manager
    */
   void
@@ -255,6 +241,10 @@
   SetLinkDelayAsFaceMetric();
 
 private:
+  void
+  doInstall(Ptr<Node> node) const;
+
+private:
   shared_ptr<Face>
   DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
 
@@ -264,8 +254,6 @@
   shared_ptr<Face>
   createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const;
 
-  bool m_isRibManagerDisabled;
-  // bool m_isFaceManagerDisabled;
   bool m_isForwarderStatusManagerDisabled;
   bool m_isStrategyChoiceManagerDisabled;
 
diff --git a/helper/ndn-strategy-choice-helper.cpp b/helper/ndn-strategy-choice-helper.cpp
index 6958fce..215d34b 100644
--- a/helper/ndn-strategy-choice-helper.cpp
+++ b/helper/ndn-strategy-choice-helper.cpp
@@ -39,6 +39,7 @@
   commandName.append(encodedParameters);
 
   shared_ptr<Interest> command(make_shared<Interest>(commandName));
+  command->setCanBePrefix(false);
   StackHelper::getKeyChain().sign(*command);
 
   Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>();
@@ -60,7 +61,11 @@
   parameters.setName(namePrefix);
   NS_LOG_DEBUG("Node ID: " << node->GetId() << " with forwarding strategy " << strategy);
   parameters.setStrategy(strategy);
-  sendCommand(parameters, node);
+
+  Simulator::ScheduleWithContext(node->GetId(), Seconds(0),
+                                 &StrategyChoiceHelper::sendCommand, parameters, node);
+  Simulator::Stop(Seconds(0));
+  Simulator::Run();
 }
 
 void