nlsr: refactor Adjacent to use FaceUri objects

Change-Id: Ib46f70570669c381572182eeea5c047a38a05104
refs: #4063
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index 56807c7..ccbea1b 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -258,8 +258,18 @@
                                 _1, faceId));
 }
 
+AdjacencyList::iterator
+AdjacencyList::findAdjacent(const ndn::util::FaceUri& faceUri)
+{
+  return std::find_if(m_adjList.begin(),
+                      m_adjList.end(),
+                      [&faceUri] (const Adjacent& adj) {
+                        return faceUri == adj.getFaceUri();
+                      });
+}
+
 uint64_t
-AdjacencyList::getFaceId(const std::string& faceUri)
+AdjacencyList::getFaceId(const ndn::util::FaceUri& faceUri)
 {
   std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
                                                   m_adjList.end(),
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index c9553de..daceae1 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -145,8 +145,11 @@
   AdjacencyList::iterator
   findAdjacent(uint64_t faceId);
 
+  AdjacencyList::iterator
+  findAdjacent(const ndn::util::FaceUri& faceUri);
+
   uint64_t
-  getFaceId(const std::string& faceUri);
+  getFaceId(const ndn::util::FaceUri& faceUri);
 
   void
   writeLog();
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index fb22ed3..55ddff5 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -16,9 +16,6 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
  **/
 #include <iostream>
 #include <string>
@@ -33,13 +30,11 @@
 
 INIT_LOGGER("Adjacent");
 
-using namespace std;
-
 const float Adjacent::DEFAULT_LINK_COST = 10.0;
 
 Adjacent::Adjacent()
     : m_name()
-    , m_connectingFaceUri()
+    , m_faceUri()
     , m_linkCost(DEFAULT_LINK_COST)
     , m_status(STATUS_INACTIVE)
     , m_interestTimedOutNo(0)
@@ -49,7 +44,7 @@
 
 Adjacent::Adjacent(const ndn::Name& an)
     : m_name(an)
-    , m_connectingFaceUri()
+    , m_faceUri()
     , m_linkCost(DEFAULT_LINK_COST)
     , m_status(STATUS_INACTIVE)
     , m_interestTimedOutNo(0)
@@ -57,32 +52,31 @@
   {
   }
 
-Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu,  double lc,
+Adjacent::Adjacent(const ndn::Name& an, const ndn::util::FaceUri& faceUri,  double lc,
                    Status s, uint32_t iton, uint64_t faceId)
     : m_name(an)
-    , m_connectingFaceUri(cfu)
+    , m_faceUri(faceUri)
     , m_linkCost(lc)
     , m_status(s)
     , m_interestTimedOutNo(iton)
     , m_faceId(faceId)
   {
-
   }
 
 bool
 Adjacent::operator==(const Adjacent& adjacent) const
 {
   return (m_name == adjacent.getName()) &&
-         (m_connectingFaceUri == adjacent.getConnectingFaceUri()) &&
+         (m_faceUri == adjacent.getFaceUri()) &&
          (std::abs(m_linkCost - adjacent.getLinkCost()) <
-          std::numeric_limits<double>::epsilon()) ;
+          std::numeric_limits<double>::epsilon());
 }
 
 void
 Adjacent::writeLog()
 {
   _LOG_DEBUG("Adjacent : " << m_name);
-  _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri);
+  _LOG_DEBUG("Connecting FaceUri: " << m_faceUri);
   _LOG_DEBUG("Link Cost: " << m_linkCost);
   _LOG_DEBUG("Status: " << m_status);
   _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo);
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index d1995cf..4aded01 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -16,14 +16,13 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
  **/
 #include <string>
 #include <cmath>
 #include <boost/cstdint.hpp>
+
 #include <ndn-cxx/face.hpp>
+#include <ndn-cxx/util/face-uri.hpp>
 
 #ifndef NLSR_ADJACENT_HPP
 #define NLSR_ADJACENT_HPP
@@ -45,7 +44,7 @@
 
   Adjacent(const ndn::Name& an);
 
-  Adjacent(const ndn::Name& an, const std::string& cfu,  double lc,
+  Adjacent(const ndn::Name& an, const ndn::util::FaceUri& faceUri, double lc,
            Status s, uint32_t iton, uint64_t faceId);
 
   const ndn::Name&
@@ -60,16 +59,16 @@
     m_name = an;
   }
 
-  const std::string&
-  getConnectingFaceUri() const
+  const ndn::util::FaceUri&
+  getFaceUri() const
   {
-    return m_connectingFaceUri;
+    return m_faceUri;
   }
 
   void
-  setConnectingFaceUri(const std::string& cfu)
+  setFaceUri(const ndn::util::FaceUri& faceUri)
   {
-    m_connectingFaceUri = cfu;
+    m_faceUri = faceUri;
   }
 
   uint64_t
@@ -131,15 +130,15 @@
   }
 
   inline bool
-  compareFaceId(uint64_t faceId)
+  compareFaceId(const uint64_t faceId)
   {
     return m_faceId == faceId;
   }
 
   inline bool
-  compareFaceUri(std::string& faceUri)
+  compareFaceUri(const ndn::util::FaceUri& faceUri)
   {
-    return m_connectingFaceUri == faceUri;
+    return m_faceUri == faceUri;
   }
 
   void
@@ -150,7 +149,7 @@
 
 private:
   ndn::Name m_name;
-  std::string m_connectingFaceUri;
+  ndn::util::FaceUri m_faceUri;
   double m_linkCost;
   Status m_status;
   uint32_t m_interestTimedOutNo;
@@ -159,4 +158,4 @@
 
 } // namespace nlsr
 
-#endif //NLSR_ADJACENT_HPP
+#endif // NLSR_ADJACENT_HPP
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 70600fb..211609a 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -474,12 +474,13 @@
       try {
         ConfigSection CommandAttriTree = tn->second;
         std::string name = CommandAttriTree.get<std::string>("name");
-        std::string faceUri = CommandAttriTree.get<std::string>("face-uri");
+        std::string uriString = CommandAttriTree.get<std::string>("face-uri");
 
-        ndn::util::FaceUri uri;
-
-        if (!uri.parse(faceUri)) {
-          std::cerr << "Malformed face-uri <" << faceUri << "> for " << name << std::endl;
+        ndn::util::FaceUri faceUri;
+        try {
+          faceUri = ndn::util::FaceUri(uriString);
+        } catch (ndn::util::FaceUri::Error e) {
+          std::cerr << "Malformed face-uri <" << uriString << "> for " << name << std::endl;
           return false;
         }
 
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 2f27020..52e8997 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -72,7 +72,7 @@
     // successful registration prompts a callback that sends the hello
     // Interest to the new Face.
     else {
-      registerPrefixes((*it).getName(), (*it).getConnectingFaceUri(),
+      registerPrefixes((*it).getName(), (*it).getFaceUri().toString(),
                        (*it).getLinkCost(), ndn::time::milliseconds::max());
     }
   }
@@ -129,7 +129,7 @@
       // If the originator of the Interest currently lacks a Face, we
       // need to give it one.
       else {
-        registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(),
+        registerPrefixes(adjacent->getName(), adjacent->getFaceUri().toString(),
                          adjacent->getLinkCost(), ndn::time::milliseconds::max());
       }
     }
@@ -262,7 +262,7 @@
     adjacent->setFaceId(commandSuccessResult.getFaceId());
     ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX;
     broadcastKeyPrefix.append("KEYS");
-    std::string faceUri = adjacent->getConnectingFaceUri();
+    std::string faceUri = adjacent->getFaceUri().toString();
     double linkCost = adjacent->getLinkCost();
     m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(),
                                  faceUri, linkCost, timeout,
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 46dc1c4..78e5837 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -253,7 +253,7 @@
   os << m_origRouter << "|" << AdjLsa::TYPE_STRING << "|" << m_lsSeqNo << "|"
      << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_adl.getSize();
   for (const auto& adjacent : m_adl.getAdjList()) {
-    os << "|" << adjacent.getName() << "|" << adjacent.getConnectingFaceUri()
+    os << "|" << adjacent.getName() << "|" << adjacent.getFaceUri()
        << "|" << adjacent.getLinkCost();
   }
   os << "|";
@@ -290,7 +290,8 @@
       ndn::Name adjName(*tok_iter++);
       std::string connectingFaceUri(*tok_iter++);
       double linkCost = boost::lexical_cast<double>(*tok_iter++);
-      Adjacent adjacent(adjName, connectingFaceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0);
+      Adjacent adjacent(adjName, ndn::util::FaceUri(connectingFaceUri), linkCost,
+                        Adjacent::STATUS_INACTIVE, 0, 0);
       addAdjacent(adjacent);
     }
     catch (const std::exception& e) {
@@ -342,7 +343,7 @@
   for (const Adjacent& adjacency : adjLsa) {
   os << "    Adjacent " << adjacencyIndex++ << ":\n"
      << "      Adjacent Name: " << adjacency.getName() << "\n"
-     << "      Connecting FaceUri: " << adjacency.getConnectingFaceUri() << "\n"
+     << "      Connecting FaceUri: " << adjacency.getFaceUri() << "\n"
      << "      Link Cost: " << adjacency.getLinkCost() << "\n";
   }
   os << "adj_lsa_end";
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index f00bbe1..02df4aa 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -198,15 +198,15 @@
                            std::function<void(std::list<Adjacent>::iterator)> then)
 {
   if (currentNeighbor != m_adjacencyList.getAdjList().end()) {
-    ndn::util::FaceUri uri(currentNeighbor->getConnectingFaceUri());
+    ndn::util::FaceUri uri(currentNeighbor->getFaceUri());
     uri.canonize([this, then, currentNeighbor] (ndn::util::FaceUri canonicalUri) {
-        _LOG_DEBUG("Canonized URI: " << currentNeighbor->getConnectingFaceUri()
+        _LOG_DEBUG("Canonized URI: " << currentNeighbor->getFaceUri()
                    << " to: " << canonicalUri);
-        currentNeighbor->setConnectingFaceUri(canonicalUri.toString());
+        currentNeighbor->setFaceUri(canonicalUri);
         then(std::next(currentNeighbor));
       },
       [this, then, currentNeighbor] (const std::string& reason) {
-        _LOG_ERROR("Could not canonize URI: " << currentNeighbor->getConnectingFaceUri()
+        _LOG_ERROR("Could not canonize URI: " << currentNeighbor->getFaceUri()
                    << " because: " << reason);
         then(std::next(currentNeighbor));
       },
@@ -388,7 +388,7 @@
   std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
   for (std::list<Adjacent>::iterator it = adjacents.begin();
        it != adjacents.end(); it++) {
-    m_fib.destroyFace((*it).getConnectingFaceUri(),
+    m_fib.destroyFace((*it).getFaceUri().toString(),
                       std::bind(&Nlsr::onDestroyFaceSuccess, this, _1),
                       std::bind(&Nlsr::onDestroyFaceFailure, this, _1));
   }
diff --git a/src/publisher/lsa-publisher.cpp b/src/publisher/lsa-publisher.cpp
index 3d16581..7060c05 100644
--- a/src/publisher/lsa-publisher.cpp
+++ b/src/publisher/lsa-publisher.cpp
@@ -52,7 +52,7 @@
     for (const Adjacent& adj : lsa.getAdl().getAdjList()) {
       tlv::Adjacency tlvAdj;
       tlvAdj.setName(adj.getName());
-      tlvAdj.setUri(adj.getConnectingFaceUri());
+      tlvAdj.setUri(adj.getFaceUri().toString());
       tlvAdj.setCost(adj.getLinkCost());
       tlvLsa.addAdjacency(tlvAdj);
     }
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 777ab1b..c4ddad8 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -266,7 +266,7 @@
                     uint64_t faceCost, const ndn::time::milliseconds& timeout,
                     uint64_t flags, uint8_t times)
 {
-  uint64_t faceId = m_adjacencyList.getFaceId(faceUri);
+  uint64_t faceId = m_adjacencyList.getFaceId(ndn::util::FaceUri(faceUri));
   if (faceId != 0) {
     ndn::nfd::ControlParameters faceParameters;
     faceParameters
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index e464c49..54d486d 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -252,7 +252,7 @@
   int v, u;
   int* Q = new int[m_nRouters]; // Each cell represents the router with that mapping no.
   int head = 0;
-  /* Initiate the Parent */
+  // Initiate the Parent
   for (i = 0 ; i < static_cast<int>(m_nRouters); i++) {
     m_parent[i] = EMPTY_PARENT;
     // Array where the ith element is the distance to the router with mapping no i.
@@ -318,7 +318,7 @@
         // Fetch its actual name
         ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(nextHopRouter);
         std::string nextHopFace =
-          pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFaceUri();
+          pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getFaceUri().toString();
         // Add next hop to routing table
         NextHop nh(nextHopFace, routeCost);
         rt.addNextHop(pMap.getRouterNameByMappingNo(i), nh);
@@ -426,7 +426,7 @@
       continue;
     }
 
-    std::string srcFaceUri = adj->getConnectingFaceUri();
+    std::string srcFaceUri = adj->getFaceUri().toString();
 
     // Install nexthops for this router to the neighbor; direct neighbors have a 0 cost link
     addNextHop(srcRouterName, srcFaceUri, 0, rt);
@@ -479,7 +479,7 @@
   CoordinateLsa* destLsa = lsdb.findCoordinateLsa(destLsaKey);
 
   // Coordinate LSAs do not exist for these routers
-  if (srcLsa == NULL || destLsa == NULL) {
+  if (srcLsa == nullptr || destLsa == nullptr) {
     return UNKNOWN_DISTANCE;
   }