Routing: Print labels on adjacency matrix when logging

refs: #2045

Change-Id: I0fa36eed1a6afdca6f135c80a20aa062a5e8cd63
diff --git a/src/route/map.cpp b/src/route/map.cpp
index a3ca7d1..f5f928e 100644
--- a/src/route/map.cpp
+++ b/src/route/map.cpp
@@ -45,7 +45,7 @@
 }
 
 ndn::optional<ndn::Name>
-Map::getRouterNameByMappingNo(int32_t mn)
+Map::getRouterNameByMappingNo(int32_t mn) const
 {
   auto&& mappingNumberView = m_entries.get<detail::byMappingNumber>();
   auto iterator = mappingNumberView.find(mn);
diff --git a/src/route/map.hpp b/src/route/map.hpp
index 04cf0e4..01801be 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2017,  The University of Memphis,
+ * Copyright (c) 2014-2018,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -105,7 +105,7 @@
   }
 
   ndn::optional<ndn::Name>
-  getRouterNameByMappingNo(int32_t mn);
+  getRouterNameByMappingNo(int32_t mn) const;
 
   ndn::optional<int32_t>
   getMappingNoByRouterName(const ndn::Name& rName);
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index a35df65..0be5e54 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -29,6 +29,7 @@
 
 #include <iostream>
 #include <boost/math/constants/constants.hpp>
+#include <ndn-cxx/util/logger.hpp>
 #include <cmath>
 
 namespace nlsr {
@@ -56,7 +57,7 @@
 }
 
 void
-RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
+RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map& pMap)
 {
   std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
   // For each LSA represented in the map
@@ -116,14 +117,34 @@
 }
 
 void
-RoutingTableCalculator::writeAdjMatrixLog()
+RoutingTableCalculator::writeAdjMatrixLog(const Map& map) const
 {
+  if (!getNdnCxxLogger().isLevelEnabled(ndn::util::LogLevel::DEBUG)) {
+    return;
+  }
+
+  NLSR_LOG_DEBUG("-----------Legend (routerName -> index)------");
+  std::string routerIndex;
+  std::string indexToNameMapping;
+  std::string lengthOfDash = "--";
+
   for (size_t i = 0; i < m_nRouters; i++) {
-    std::string line="";
+      routerIndex += boost::lexical_cast<std::string>(i);
+      routerIndex += " ";
+      lengthOfDash += "--";
+      NLSR_LOG_DEBUG("Router:" + map.getRouterNameByMappingNo(i)->toUri() +
+                     "Index:" + boost::lexical_cast<std::string>(i));
+  }
+  NLSR_LOG_DEBUG(" |" + routerIndex);
+  NLSR_LOG_DEBUG(lengthOfDash);
+
+  for (size_t i = 0; i < m_nRouters; i++) {
+    std::string line;
     for (size_t j = 0; j < m_nRouters; j++) {
       line += boost::lexical_cast<std::string>(adjMatrix[i][j]);
       line += " ";
     }
+    line = boost::lexical_cast<std::string>(i) + "|" + line;
     NLSR_LOG_DEBUG(line);
   }
 }
@@ -210,7 +231,7 @@
   allocateAdjMatrix();
   initMatrix();
   makeAdjMatrix(pnlsr, pMap);
-  writeAdjMatrixLog();
+  writeAdjMatrixLog(pMap);
   ndn::optional<int32_t> sourceRouter =
     pMap.getMappingNoByRouterName(pnlsr.getConfParameter().getRouterPrefix());
   allocateParent(); // These two matrices are used in Dijkstra's algorithm.
@@ -232,7 +253,7 @@
     for (int i = 0 ; i < vNoLink; i++) {
       // Simulate that only the current neighbor is accessible
       adjustAdMatrix(*sourceRouter, links[i], linkCosts[i]);
-      writeAdjMatrixLog();
+      writeAdjMatrixLog(pMap);
       // Do Dijkstra's algorithm using the current neighbor as your start.
       doDijkstraPathCalculation(*sourceRouter);
       // Update the routing table with the calculations.
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index 7158fd6..6024fbd 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2017,  The University of Memphis,
+ * Copyright (c) 2014-2018,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -61,10 +61,10 @@
     \param pMap The map to populate with the adj. data.
   */
   void
-  makeAdjMatrix(Nlsr& pnlsr, Map pMap);
+  makeAdjMatrix(Nlsr& pnlsr, Map& pMap);
 
   void
-  writeAdjMatrixLog();
+  writeAdjMatrixLog(const Map& map) const;
 
   /*! \brief Returns how many links a router in the matrix has.
     \param sRouter The router to count the links of.