helpers: Update face metric based on simulated p2p link delay

Change-Id: I75098293f631b6bc7f6fbd58413e7756f19d0865
refs: #4733
diff --git a/helper/ndn-stack-helper.cpp b/helper/ndn-stack-helper.cpp
index 82dab49..8391843 100644
--- a/helper/ndn-stack-helper.cpp
+++ b/helper/ndn-stack-helper.cpp
@@ -24,6 +24,7 @@
 #include "ns3/string.h"
 #include "ns3/point-to-point-net-device.h"
 #include "ns3/point-to-point-channel.h"
+#include "ns3/node-list.h"
 
 #include "model/ndn-l3-protocol.hpp"
 #include "model/ndn-net-device-transport.hpp"
@@ -428,5 +429,28 @@
   m_isForwarderStatusManagerDisabled = true;
 }
 
+void
+StackHelper::SetLinkDelayAsFaceMetric()
+{
+  for (uint32_t i = 0; i < NodeList::GetNNodes(); ++i) {
+    auto ndn = NodeList::GetNode(i)->GetObject<L3Protocol>();
+    if (ndn == nullptr)
+      continue;
+
+    for (auto& face : ndn->getForwarder()->getFaceTable()) {
+      auto transport = dynamic_cast<NetDeviceTransport*>(face.getTransport());
+      if (transport == nullptr)
+        continue;
+      auto p2p = dynamic_cast<PointToPointChannel*>(&(*(transport->GetNetDevice()->GetChannel())));
+      TimeValue currentDelay;
+      p2p->GetAttribute("Delay", currentDelay);
+      face.setMetric((currentDelay.Get().ToDouble(Time::S)) * 1000);
+
+      std::cout << "Node " << i << ": Face " << face.getId()
+                << " with metric " << face.getMetric() << "\n";
+    }
+  }
+}
+
 } // namespace ndn
 } // namespace ns3
diff --git a/helper/ndn-stack-helper.hpp b/helper/ndn-stack-helper.hpp
index bae814f..2d2b8fb 100644
--- a/helper/ndn-stack-helper.hpp
+++ b/helper/ndn-stack-helper.hpp
@@ -248,6 +248,12 @@
   void
   disableForwarderStatusManager();
 
+  /**
+   * @brief Set face metric of all faces connected through PointToPoint channel to channel latency
+   */
+  static void
+  SetLinkDelayAsFaceMetric();
+
 private:
   shared_ptr<Face>
   DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;