ndn-stack-helper: Update method was added

Change-Id: I1e4bafe8559ef87135de6cb6f209fc94dfa232b1
Refs: #2717
diff --git a/helper/ndn-stack-helper.cpp b/helper/ndn-stack-helper.cpp
index fd319a6..a9dbfe7 100644
--- a/helper/ndn-stack-helper.cpp
+++ b/helper/ndn-stack-helper.cpp
@@ -143,8 +143,8 @@
   Ptr<FaceContainer> faces = Create<FaceContainer>();
 
   if (node->GetObject<L3Protocol>() != 0) {
-    NS_FATAL_ERROR("StackHelper::Install (): Installing "
-                   "a NdnStack to a node with an existing Ndn object");
+    NS_FATAL_ERROR("Cannot re-install NDN stack on node "
+                   << node->GetId());
     return 0;
   }
 
@@ -170,27 +170,7 @@
     // if (DynamicCast<LoopbackNetDevice> (device) != 0)
     //   continue; // don't create face for a LoopbackNetDevice
 
-    shared_ptr<NetDeviceFace> face;
-
-    for (const auto& item : m_netDeviceCallbacks) {
-      if (device->GetInstanceTypeId() == item.first ||
-          device->GetInstanceTypeId().IsChildOf(item.first)) {
-        face = item.second(node, ndn, device);
-        if (face != 0)
-          break;
-      }
-    }
-
-    if (face == 0) {
-      face = DefaultNetDeviceCallback(node, ndn, device);
-    }
-
-    if (m_needSetDefaultRoutes) {
-      // default route with lowest priority possible
-      FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
-    }
-
-    faces->Add(face);
+    faces->Add(this->createAndRegisterFace(node, ndn, device));
   }
 
   return faces;
@@ -261,5 +241,71 @@
   return Install(node);
 }
 
+void
+StackHelper::Update(Ptr<Node> node)
+{
+  if (node->GetObject<L3Protocol>() == 0) {
+    Install(node);
+    return;
+  }
+
+  Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
+
+  for (uint32_t index = 0; index < node->GetNDevices(); index++) {
+
+    Ptr<NetDevice> device = node->GetDevice(index);
+
+    if (ndn->getFaceByNetDevice(device) == nullptr) {
+      this->createAndRegisterFace(node, ndn, device);
+    }
+  }
+}
+
+void
+StackHelper::Update(const NodeContainer& c)
+{
+  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
+    Update(*i);
+  }
+}
+
+void
+StackHelper::Update(const std::string& nodeName)
+{
+  Ptr<Node> node = Names::Find<Node>(nodeName);
+  Update(node);
+}
+
+void
+StackHelper::UpdateAll()
+{
+  Update(NodeContainer::GetGlobal());
+}
+
+shared_ptr<NetDeviceFace>
+StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const
+{
+  shared_ptr<NetDeviceFace> face;
+
+  for (const auto& item : m_netDeviceCallbacks) {
+    if (device->GetInstanceTypeId() == item.first ||
+        device->GetInstanceTypeId().IsChildOf(item.first)) {
+      face = item.second(node, ndn, device);
+      if (face != 0)
+        break;
+    }
+  }
+
+  if (face == 0) {
+    face = DefaultNetDeviceCallback(node, ndn, device);
+  }
+
+  if (m_needSetDefaultRoutes) {
+    // default route with lowest priority possible
+    FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max());
+  }
+  return face;
+}
+
 } // namespace ndn
 } // namespace ns3
diff --git a/helper/ndn-stack-helper.hpp b/helper/ndn-stack-helper.hpp
index a05e520..472f0ab 100644
--- a/helper/ndn-stack-helper.hpp
+++ b/helper/ndn-stack-helper.hpp
@@ -182,6 +182,36 @@
   static KeyChain&
   getKeyChain();
 
+   /**
+   * \brief Update Ndn stack on a given node (Add faces for new devices)
+   *
+   * \param node The node on which to update the stack.
+   */
+  void
+  Update(Ptr<Node> node);
+
+  /**
+   *\brief Update Ndn stack on given nodes (Add faces for new devices)
+   *
+   * \param c The nodes on which to update the stack.
+   */
+  void
+  Update(const NodeContainer& c);
+
+  /**
+   *\brief Update Ndn stack on a given node name (Add faces for new devices)
+   *
+   * \param nodeName The name of the node on which to update the stack.
+   */
+  void
+  Update(const std::string& nodeName);
+
+  /**
+   *\brief Update Ndn stack on all the nodes (Add faces for new devices)
+   */
+  void
+  UpdateAll();
+
 private:
   shared_ptr<NetDeviceFace>
   DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
@@ -189,6 +219,8 @@
   shared_ptr<NetDeviceFace>
   PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
                                 Ptr<NetDevice> netDevice) const;
+  shared_ptr<NetDeviceFace>
+  createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const;
 
 public:
   void