face/mgmt/fw/tools: add localUri to FaceStatus and FaceEventNotification

refs #1396

Change-Id: I6084745c62c44a409ecbd4a795cb712475e32416
diff --git a/daemon/face/face-counter.hpp b/daemon/face/face-counter.hpp
index ba3b98e..683e6e5 100644
--- a/daemon/face/face-counter.hpp
+++ b/daemon/face/face-counter.hpp
@@ -28,94 +28,94 @@
 
   /// incoming Interest (total packets since Face establishment)
   const FaceCounter&
-  getInInterest() const;
+  getNInInterests() const;
 
   FaceCounter&
-  getInInterest();
+  getNInInterests();
 
   /// incoming Data (total packets since Face establishment)
   const FaceCounter&
-  getInData() const;
+  getNInDatas() const;
 
   FaceCounter&
-  getInData();
+  getNInDatas();
 
   /// outgoing Interest (total packets since Face establishment)
   const FaceCounter&
-  getOutInterest() const;
+  getNOutInterests() const;
 
   FaceCounter&
-  getOutInterest();
+  getNOutInterests();
 
   /// outgoing Data (total packets since Face establishment)
   const FaceCounter&
-  getOutData() const;
+  getNOutDatas() const;
 
   FaceCounter&
-  getOutData();
+  getNOutDatas();
 
 private:
-  FaceCounter m_inInterest;
-  FaceCounter m_inData;
-  FaceCounter m_outInterest;
-  FaceCounter m_outData;
+  FaceCounter m_nInInterests;
+  FaceCounter m_nInDatas;
+  FaceCounter m_outInterests;
+  FaceCounter m_outDatas;
 };
 
 inline
 FaceCounters::FaceCounters()
-  : m_inInterest(0)
-  , m_inData(0)
-  , m_outInterest(0)
-  , m_outData(0)
+  : m_nInInterests(0)
+  , m_nInDatas(0)
+  , m_outInterests(0)
+  , m_outDatas(0)
 {
 }
 
 inline const FaceCounter&
-FaceCounters::getInInterest() const
+FaceCounters::getNInInterests() const
 {
-  return m_inInterest;
+  return m_nInInterests;
 }
 
 inline FaceCounter&
-FaceCounters::getInInterest()
+FaceCounters::getNInInterests()
 {
-  return m_inInterest;
+  return m_nInInterests;
 }
 
 inline const FaceCounter&
-FaceCounters::getInData() const
+FaceCounters::getNInDatas() const
 {
-  return m_inData;
+  return m_nInDatas;
 }
 
 inline FaceCounter&
-FaceCounters::getInData()
+FaceCounters::getNInDatas()
 {
-  return m_inData;
+  return m_nInDatas;
 }
 
 inline const FaceCounter&
-FaceCounters::getOutInterest() const
+FaceCounters::getNOutInterests() const
 {
-  return m_outInterest;
+  return m_outInterests;
 }
 
 inline FaceCounter&
-FaceCounters::getOutInterest()
+FaceCounters::getNOutInterests()
 {
-  return m_outInterest;
+  return m_outInterests;
 }
 
 inline const FaceCounter&
-FaceCounters::getOutData() const
+FaceCounters::getNOutDatas() const
 {
-  return m_outData;
+  return m_outDatas;
 }
 
 inline FaceCounter&
-FaceCounters::getOutData()
+FaceCounters::getNOutDatas()
 {
-  return m_outData;
+  return m_outDatas;
 }
 
 
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index c0241fc..517b230 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -24,10 +24,10 @@
   , m_localUri(localUri)
   , m_isOnDemand(false)
 {
-  onReceiveInterest += bind(&increaseCounter, boost::ref(m_counters.getInInterest()));
-  onReceiveData     += bind(&increaseCounter, boost::ref(m_counters.getInData()));
-  onSendInterest    += bind(&increaseCounter, boost::ref(m_counters.getOutInterest()));
-  onSendData        += bind(&increaseCounter, boost::ref(m_counters.getOutData()));
+  onReceiveInterest += bind(&increaseCounter, boost::ref(m_counters.getNInInterests()));
+  onReceiveData     += bind(&increaseCounter, boost::ref(m_counters.getNInDatas()));
+  onSendInterest    += bind(&increaseCounter, boost::ref(m_counters.getNOutInterests()));
+  onSendData        += bind(&increaseCounter, boost::ref(m_counters.getNOutDatas()));
 }
 
 Face::~Face()
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index 3cb7160..2f555a6 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -120,11 +120,6 @@
   const FaceCounters&
   getCounters() const;
 
-  /** \deprecated use getRemoteUri instead
-   */
-  const FaceUri&
-  getUri() const;
-
   /** \return a FaceUri that represents the remote endpoint
    */
   const FaceUri&
@@ -183,12 +178,6 @@
 }
 
 inline const FaceUri&
-Face::getUri() const
-{
-  return this->getRemoteUri();
-}
-
-inline const FaceUri&
 Face::getRemoteUri() const
 {
   return m_remoteUri;
diff --git a/daemon/face/multicast-udp-face.cpp b/daemon/face/multicast-udp-face.cpp
index 7866603..d96c183 100644
--- a/daemon/face/multicast-udp-face.cpp
+++ b/daemon/face/multicast-udp-face.cpp
@@ -10,8 +10,8 @@
 
 NFD_LOG_INIT("MulticastUdpFace");
 
-MulticastUdpFace::MulticastUdpFace(const shared_ptr<protocol::socket>& socket,
-                                   const protocol::endpoint& localEndpoint)
+MulticastUdpFace::MulticastUdpFace(const shared_ptr<MulticastUdpFace::protocol::socket>& socket,
+                                   const MulticastUdpFace::protocol::endpoint& localEndpoint)
   : DatagramFace<protocol>(FaceUri(socket->local_endpoint()),
                            FaceUri(localEndpoint),
                            socket, false)
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index f59ff14..7b096fa 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -36,7 +36,8 @@
   FaceId faceId = ++m_lastFaceId;
   face->setId(faceId);
   m_faces[faceId] = face;
-  NFD_LOG_INFO("Added face id=" << faceId << " uri=" << face->getUri());
+  NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri() <<
+                                              " local=" << face->getLocalUri());
 
   face->onReceiveInterest += bind(&Forwarder::onInterest,
                                   &m_forwarder, boost::ref(*face), _1);
@@ -56,7 +57,8 @@
   FaceId faceId = face->getId();
   m_faces.erase(faceId);
   face->setId(INVALID_FACEID);
-  NFD_LOG_INFO("Removed face id=" << faceId << " uri=" << face->getUri());
+  NFD_LOG_INFO("Removed face id=" << faceId << " remote=" << face->getRemoteUri() <<
+                                                 " local=" << face->getLocalUri());
 
   // XXX This clears all subscriptions, because EventEmitter
   //     does not support only removing Forwarder's subscription
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 8ffda2f..8ce48f7 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -39,7 +39,7 @@
   NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
                 " interest=" << interest.getName());
   const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
-  m_counters.getInInterest() ++;
+  m_counters.getNInInterests() ++;
 
   // /localhost scope control
   bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -155,7 +155,7 @@
 
   // send Interest
   outFace.sendInterest(interest);
-  m_counters.getOutInterest() ++;
+  m_counters.getNOutInterests() ++;
 }
 
 void
@@ -186,7 +186,7 @@
   // receive Data
   NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName());
   const_cast<Data&>(data).setIncomingFaceId(inFace.getId());
-  m_counters.getInData() ++;
+  m_counters.getNInDatas() ++;
 
   // /localhost scope control
   bool isViolatingLocalhost = !inFace.isLocal() &&
@@ -282,7 +282,7 @@
 
   // send Data
   outFace.sendData(data);
-  m_counters.getOutData() ++;
+  m_counters.getNOutDatas() ++;
 }
 
 static inline bool
diff --git a/daemon/mgmt/face-flags.hpp b/daemon/mgmt/face-flags.hpp
new file mode 100644
index 0000000..f9c50e1
--- /dev/null
+++ b/daemon/mgmt/face-flags.hpp
@@ -0,0 +1,30 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_MGMT_FACE_FLAGS_HPP
+#define NFD_MGMT_FACE_FLAGS_HPP
+
+#include "face/face.hpp"
+#include <ndn-cpp-dev/management/nfd-face-flags.hpp>
+
+namespace nfd {
+
+inline uint64_t
+getFaceFlags(const Face& face)
+{
+  uint64_t flags = 0;
+  if (face.isLocal()) {
+    flags |= ndn::nfd::FACE_IS_LOCAL;
+  }
+  if (face.isOnDemand()) {
+    flags |= ndn::nfd::FACE_IS_ON_DEMAND;
+  }
+  return flags;
+}
+
+} // namespace nfd
+
+#endif // NFD_MGMT_FACE_FLAGS_HPP
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index e184c00..183af17 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -5,6 +5,7 @@
  */
 
 #include "face-manager.hpp"
+#include "face-flags.hpp"
 
 #include "core/logger.hpp"
 #include "core/face-uri.hpp"
@@ -562,7 +563,7 @@
 {
   m_faceTable.add(newFace);
 
-  NFD_LOG_DEBUG("Created face " << newFace->getUri() << " ID " << newFace->getId());
+  //NFD_LOG_DEBUG("Created face " << newFace->getRemoteUri() << " ID " << newFace->getId());
 }
 
 void
@@ -642,25 +643,27 @@
 void
 FaceManager::onAddFace(shared_ptr<Face> face)
 {
-  ndn::nfd::FaceEventNotification faceCreated(ndn::nfd::FACE_EVENT_CREATED,
-                                              face->getId(),
-                                              face->getUri().toString(),
-                                              (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) |
-                                              (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0));
+  ndn::nfd::FaceEventNotification notification;
+  notification.setKind(ndn::nfd::FACE_EVENT_CREATED)
+              .setFaceId(face->getId())
+              .setRemoteUri(face->getRemoteUri().toString())
+              .setLocalUri(face->getLocalUri().toString())
+              .setFlags(getFaceFlags(*face));
 
-  m_notificationStream.postNotification(faceCreated);
+  m_notificationStream.postNotification(notification);
 }
 
 void
 FaceManager::onRemoveFace(shared_ptr<Face> face)
 {
-  ndn::nfd::FaceEventNotification faceDestroyed(ndn::nfd::FACE_EVENT_DESTROYED,
-                                                face->getId(),
-                                                face->getUri().toString(),
-                                                (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) |
-                                                (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0));
+  ndn::nfd::FaceEventNotification notification;
+  notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
+              .setFaceId(face->getId())
+              .setRemoteUri(face->getRemoteUri().toString())
+              .setLocalUri(face->getLocalUri().toString())
+              .setFlags(getFaceFlags(*face));
 
-  m_notificationStream.postNotification(faceDestroyed);
+  m_notificationStream.postNotification(notification);
 }
 
 
diff --git a/daemon/mgmt/face-status-publisher.cpp b/daemon/mgmt/face-status-publisher.cpp
index 3589d7b..06b205f 100644
--- a/daemon/mgmt/face-status-publisher.cpp
+++ b/daemon/mgmt/face-status-publisher.cpp
@@ -5,7 +5,9 @@
  */
 
 #include "face-status-publisher.hpp"
+#include "face-flags.hpp"
 #include "core/logger.hpp"
+#include <ndn-cpp-dev/management/nfd-face-status.hpp>
 
 namespace nfd {
 
@@ -33,45 +35,22 @@
   size_t totalLength = 0;
 
   for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
-       i != m_faceTable.rend();
-       ++i)
-    {
-      const shared_ptr<Face>& face = *i;
-      const FaceCounters& counters = face->getCounters();
-      const std::string uri = face->getUri().toString();
+       i != m_faceTable.rend(); ++i) {
+    const shared_ptr<Face>& face = *i;
+    const FaceCounters& counters = face->getCounters();
 
-      size_t statusLength = 0;
+    ndn::nfd::FaceStatus status;
+    status.setFaceId(face->getId())
+          .setRemoteUri(face->getRemoteUri().toString())
+          .setLocalUri(face->getLocalUri().toString())
+          .setFlags(getFaceFlags(*face))
+          .setNInInterests(counters.getNInInterests())
+          .setNInDatas(counters.getNInDatas())
+          .setNOutInterests(counters.getNOutInterests())
+          .setNOutDatas(counters.getNOutDatas());
 
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NOutDatas,
-                                                     counters.getOutData());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NOutInterests,
-                                                     counters.getOutInterest());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NInDatas,
-                                                     counters.getInData());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NInInterests,
-                                                     counters.getInInterest());
-
-      statusLength += prependByteArrayBlock(outBuffer,
-                                            ndn::tlv::nfd::Uri,
-                                            reinterpret_cast<const uint8_t*>(uri.c_str()),
-                                            uri.size());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::FaceId,
-                                                     face->getId());
-
-      statusLength += outBuffer.prependVarNumber(statusLength);
-      statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus);
-
-      totalLength += statusLength;
-    }
+    totalLength += status.wireEncode(outBuffer);
+  }
   return totalLength;
 }
 
diff --git a/daemon/mgmt/status-server.cpp b/daemon/mgmt/status-server.cpp
index 5c4bd1a..6176659 100644
--- a/daemon/mgmt/status-server.cpp
+++ b/daemon/mgmt/status-server.cpp
@@ -54,10 +54,10 @@
   status->setNCsEntries(m_forwarder.getCs().size());
 
   const ForwarderCounters& counters = m_forwarder.getCounters();
-  status->setNInInterests(counters.getInInterest());
-  status->setNInDatas(counters.getInData());
-  status->setNOutInterests(counters.getOutInterest());
-  status->setNOutDatas(counters.getOutData());
+  status->setNInInterests(counters.getNInInterests());
+  status->setNInDatas(counters.getNInDatas());
+  status->setNOutInterests(counters.getNOutInterests());
+  status->setNOutDatas(counters.getNOutDatas());
 
   return status;
 }