lsdb: rebuild using boost::multi_index to replace 3 LSA lists

refs: #4127

Co-authored-by: Nick Gordon <nmgordon@memphis.edu>

Change-Id: Ic179f90019e472157b0d61c6db02a4afaf4843b6
diff --git a/src/route/map.hpp b/src/route/map.hpp
index ae92d25..be62d2d 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -22,6 +22,7 @@
 #define NLSR_MAP_HPP
 
 #include "common.hpp"
+#include "lsa/adj-lsa.hpp"
 
 #include <boost/multi_index_container.hpp>
 #include <boost/multi_index/hashed_index.hpp>
@@ -81,8 +82,9 @@
   {
     BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
     for (auto lsa = begin; lsa != end; lsa++) {
-      addEntry(lsa->getOriginRouter());
-      for (const auto& adjacent : lsa->getAdl().getAdjList()) {
+      auto adjLsa = std::static_pointer_cast<AdjLsa>(*lsa);
+      addEntry(adjLsa->getOriginRouter());
+      for (const auto& adjacent : adjLsa->getAdl().getAdjList()) {
         addEntry(adjacent.getName());
       }
     }
@@ -98,7 +100,7 @@
   {
     BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
     for (auto lsa = begin; lsa != end; lsa++) {
-      addEntry(lsa->getOriginRouter());
+      addEntry((*lsa)->getOriginRouter());
     }
   }
 
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 04cc78f..2d283eb 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
@@ -17,7 +17,7 @@
  *
  * 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/>.
- **/
+ */
 
 #include "routing-table-calculator.hpp"
 #include "lsdb.hpp"
@@ -61,13 +61,15 @@
 }
 
 void
-RoutingTableCalculator::makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap)
+RoutingTableCalculator::makeAdjMatrix(const Lsdb& lsdb, Map& pMap)
 {
   // For each LSA represented in the map
-  for (const auto& adjLsa : adjLsaList) {
-    ndn::optional<int32_t> row = pMap.getMappingNoByRouterName(adjLsa.getOriginRouter());
+  auto lsaRange = lsdb.getLsdbIterator<AdjLsa>();
+  for (auto lsaIt = lsaRange.first; lsaIt != lsaRange.second; ++lsaIt) {
+    auto adjLsa = std::static_pointer_cast<AdjLsa>(*lsaIt);
+    ndn::optional<int32_t> row = pMap.getMappingNoByRouterName(adjLsa->getOriginRouter());
 
-    std::list<Adjacent> adl = adjLsa.getAdl().getAdjList();
+    std::list<Adjacent> adl = adjLsa->getAdl().getAdjList();
     // For each adjacency represented in the LSA
     for (const auto& adjacent : adl) {
       ndn::optional<int32_t> col = pMap.getMappingNoByRouterName(adjacent.getName());
@@ -217,7 +219,6 @@
   linkCosts = new double[vNoLink];
 }
 
-
 void
 RoutingTableCalculator::freeLinks()
 {
@@ -232,12 +233,12 @@
 void
 LinkStateRoutingTableCalculator::calculatePath(Map& pMap, RoutingTable& rt,
                                                ConfParameter& confParam,
-                                               const std::list<AdjLsa>& adjLsaList)
+                                               const Lsdb& lsdb)
 {
   NLSR_LOG_DEBUG("LinkStateRoutingTableCalculator::calculatePath Called");
   allocateAdjMatrix();
   initMatrix();
-  makeAdjMatrix(adjLsaList, pMap);
+  makeAdjMatrix(lsdb, pMap);
   writeAdjMatrixLog(pMap);
   ndn::optional<int32_t> sourceRouter =
     pMap.getMappingNoByRouterName(confParam.getRouterPrefix());
@@ -497,15 +498,8 @@
 
   double distance = UNKNOWN_DISTANCE;
 
-  ndn::Name srcLsaKey = src;
-  srcLsaKey.append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE));
-
-  CoordinateLsa* srcLsa = lsdb.findCoordinateLsa(srcLsaKey);
-
-  ndn::Name destLsaKey = dest;
-  destLsaKey.append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE));
-
-  CoordinateLsa* destLsa = lsdb.findCoordinateLsa(destLsaKey);
+  auto srcLsa  = lsdb.findLsa<CoordinateLsa>(src);
+  auto destLsa = lsdb.findLsa<CoordinateLsa>(dest);
 
   // Coordinate LSAs do not exist for these routers
   if (srcLsa == nullptr || destLsa == nullptr) {
diff --git a/src/route/routing-table-calculator.hpp b/src/route/routing-table-calculator.hpp
index 16d64d7..9c0c6b5 100644
--- a/src/route/routing-table-calculator.hpp
+++ b/src/route/routing-table-calculator.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
@@ -16,8 +16,7 @@
  *
  * 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/>.
- *
- **/
+ */
 
 #ifndef NLSR_ROUTING_TABLE_CALCULATOR_HPP
 #define NLSR_ROUTING_TABLE_CALCULATOR_HPP
@@ -25,6 +24,7 @@
 #include "common.hpp"
 #include "lsa/lsa.hpp"
 #include "lsa/adj-lsa.hpp"
+#include "lsdb.hpp"
 #include "conf-parameter.hpp"
 
 #include <list>
@@ -56,11 +56,11 @@
   initMatrix();
 
   /*! \brief Constructs an adj. matrix to calculate with.
-    \param adjLsaList The Adjacency Lsa list.
+    \param lsdb Reference to the Lsdb
     \param pMap The map to populate with the adj. data.
   */
   void
-  makeAdjMatrix(const std::list<AdjLsa>& adjLsaList, Map& pMap);
+  makeAdjMatrix(const Lsdb& lsdb, Map& pMap);
 
   /*! \brief Writes a formated adjacent matrix to DEBUG log
     \param map The map containing adjacent matrix data
@@ -137,7 +137,7 @@
 
   void
   calculatePath(Map& pMap, RoutingTable& rt, ConfParameter& confParam,
-                const std::list<AdjLsa>& adjLsaList);
+                const Lsdb& lsdb);
 
 private:
   /*! \brief Performs a Dijkstra's calculation over the adjacency matrix.
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index a2ec12b..74d3c11 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -52,9 +52,7 @@
 void
 RoutingTable::calculate()
 {
-  m_lsdb.writeCorLsdbLog();
-  m_lsdb.writeNameLsdbLog();
-  m_lsdb.writeAdjLsdbLog();
+  m_lsdb.writeLog();
   m_namePrefixTable.writeLog();
   if (m_isRoutingTableCalculating == false) {
     // setting routing table calculation
@@ -63,14 +61,10 @@
     bool isHrEnabled = m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF;
 
     if ((!isHrEnabled &&
-         m_lsdb
-         .doesLsaExist(ndn::Name{m_confParam.getRouterPrefix()}
-                       .append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY)), Lsa::Type::ADJACENCY))
+         m_lsdb.doesLsaExist(m_confParam.getRouterPrefix(), Lsa::Type::ADJACENCY))
         ||
         (isHrEnabled &&
-         m_lsdb
-         .doesLsaExist(ndn::Name{m_confParam.getRouterPrefix()}
-                       .append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE)), Lsa::Type::COORDINATE))) {
+         m_lsdb.doesLsaExist(m_confParam.getRouterPrefix(), Lsa::Type::COORDINATE))) {
       if (m_lsdb.getIsBuildAdjLsaSheduled() != 1) {
         NLSR_LOG_TRACE("Clearing old routing table");
         clearRoutingTable();
@@ -80,8 +74,8 @@
         NLSR_LOG_DEBUG("Calculating routing table");
 
         // calculate Link State routing
-        if ((m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF)
-            || (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
+        if ((m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) ||
+            (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
           calculateLsRoutingTable();
         }
         // calculate hyperbolic routing
@@ -126,25 +120,26 @@
 void
 RoutingTable::calculateLsRoutingTable()
 {
-  NLSR_LOG_DEBUG("RoutingTable::calculateLsRoutingTable Called");
+  NLSR_LOG_TRACE("CalculateLsRoutingTable Called");
 
   Map map;
-  map.createFromAdjLsdb(m_lsdb.getAdjLsdb().begin(), m_lsdb.getAdjLsdb().end());
+  auto lsaRange = m_lsdb.getLsdbIterator<AdjLsa>();
+  map.createFromAdjLsdb(lsaRange.first, lsaRange.second);
   map.writeLog();
 
   size_t nRouters = map.getMapSize();
 
   LinkStateRoutingTableCalculator calculator(nRouters);
 
-  calculator.calculatePath(map, *this, m_confParam, m_lsdb.getAdjLsdb());
+  calculator.calculatePath(map, *this, m_confParam, m_lsdb);
 }
 
 void
 RoutingTable::calculateHypRoutingTable(bool isDryRun)
 {
   Map map;
-  map.createFromCoordinateLsdb(m_lsdb.getCoordinateLsdb().begin(),
-                               m_lsdb.getCoordinateLsdb().end());
+  auto lsaRange = m_lsdb.getLsdbIterator<CoordinateLsa>();
+  map.createFromCoordinateLsdb(lsaRange.first, lsaRange.second);
   map.writeLog();
 
   size_t nRouters = map.getMapSize();