**breaking** consolidate src/tlv/*lsa* into src/lsa/*lsa*

Lsa de/serialize functions are replaced by wireEncode/Decode.
Update LSA wire formats. Change TLV assignments as required.
Update nlsrc to print using new encoding.

refs: #4787

Change-Id: Ie8d40b7836d51ea5bb444c8db208dc2b3a0d1cec
diff --git a/tools/nlsrc.cpp b/tools/nlsrc.cpp
index f4e5965..a943b85 100644
--- a/tools/nlsrc.cpp
+++ b/tools/nlsrc.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -252,22 +252,22 @@
 void
 Nlsrc::fetchAdjacencyLsas()
 {
-  fetchFromLsdb<nlsr::tlv::AdjacencyLsa>(nlsr::dataset::ADJACENCY_COMPONENT,
-                                         std::bind(&Nlsrc::recordAdjacencyLsa, this, _1));
+  fetchFromLsdb<nlsr::AdjLsa>(nlsr::dataset::ADJACENCY_COMPONENT,
+                              std::bind(&Nlsrc::recordLsa, this, _1));
 }
 
 void
 Nlsrc::fetchCoordinateLsas()
 {
-  fetchFromLsdb<nlsr::tlv::CoordinateLsa>(nlsr::dataset::COORDINATE_COMPONENT,
-                                          std::bind(&Nlsrc::recordCoordinateLsa, this, _1));
+  fetchFromLsdb<nlsr::CoordinateLsa>(nlsr::dataset::COORDINATE_COMPONENT,
+                                     std::bind(&Nlsrc::recordLsa, this, _1));
 }
 
 void
 Nlsrc::fetchNameLsas()
 {
-  fetchFromLsdb<nlsr::tlv::NameLsa>(nlsr::dataset::NAME_COMPONENT,
-                                    std::bind(&Nlsrc::recordNameLsa, this, _1));
+  fetchFromLsdb<nlsr::NameLsa>(nlsr::dataset::NAME_COMPONENT,
+                               std::bind(&Nlsrc::recordLsa, this, _1));
 }
 
 void
@@ -340,66 +340,36 @@
             << ", error: " << error << ")"  << std::endl;
 }
 
-std::string
-Nlsrc::getLsaInfoString(const nlsr::tlv::LsaInfo& info)
-{
-  std::ostringstream os;
-  os << "      info=" << info;
-
-  return os.str();
-}
-
 void
-Nlsrc::recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa)
+Nlsrc::recordLsa(const nlsr::Lsa& lsa)
 {
-  Router& router = getRouterLsdb(lsa.getLsaInfo());
+  const auto& pair = m_routers.emplace(lsa.getOriginRouter(), Router());
+  Router& router = pair.first->second;
 
   std::ostringstream os;
-  os << "    AdjacencyLsa:" << std::endl;
 
-  os << getLsaInfoString(lsa.getLsaInfo()) << std::endl;
-
-  for (const auto& adjacency : lsa.getAdjacencies()) {
-    os << "      adjacency=" << adjacency << std::endl;
+  switch (lsa.getType()) {
+    case nlsr::Lsa::Type::ADJACENCY: {
+      const nlsr::AdjLsa& adjLsa = static_cast<const nlsr::AdjLsa&>(lsa);
+      os << adjLsa;
+      router.adjacencyLsaString = os.str();
+      break;
+    }
+    case nlsr::Lsa::Type::COORDINATE: {
+      const nlsr::CoordinateLsa& coorLsa = static_cast<const nlsr::CoordinateLsa&>(lsa);
+      os << coorLsa;
+      router.coordinateLsaString = os.str();
+      break;
+    }
+    case nlsr::Lsa::Type::NAME: {
+      const nlsr::NameLsa& nameLsa = static_cast<const nlsr::NameLsa&>(lsa);
+      os << nameLsa;
+      router.nameLsaString = os.str();
+      break;
+    }
+    default:
+      break;
   }
-
-  router.adjacencyLsaString = os.str();
-}
-
-void
-Nlsrc::recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa)
-{
-  Router& router = getRouterLsdb(lsa.getLsaInfo());
-
-  std::ostringstream os;
-  os << "    Coordinate LSA:" << std::endl;
-
-  os << getLsaInfoString(lsa.getLsaInfo()) << std::endl;
-
-  int i = 0;
-  for (auto const& value: lsa.getHyperbolicAngle()) {
-    os << "    Hyp Angle " << i++ << ": "<< value << " ";
-  }
-  os << "\n   radius=" << lsa.getHyperbolicRadius() << std::endl;
-
-  router.coordinateLsaString = os.str();
-}
-
-void
-Nlsrc::recordNameLsa(const nlsr::tlv::NameLsa& lsa)
-{
-  Router& router = getRouterLsdb(lsa.getLsaInfo());
-
-  std::ostringstream os;
-  os << "    Name LSA:" << std::endl;
-
-  os << getLsaInfoString(lsa.getLsaInfo()) << std::endl;
-
-  for (const auto& name : lsa.getNames()) {
-    os << "      name=" << name << std::endl;
-  }
-
-  router.nameLsaString = os.str();
 }
 
 void
@@ -469,15 +439,19 @@
   printRT();
 }
 
-Nlsrc::Router&
-Nlsrc::getRouterLsdb(const nlsr::tlv::LsaInfo& info)
+std::string
+Nlsrc::getLsaInfo(const nlsr::Lsa& lsa)
 {
-  const ndn::Name& originRouterName = info.getOriginRouter();
+  auto duration = ndn::time::duration_cast<ndn::time::seconds>(lsa.getExpirationTimePoint() -
+                                                               ndn::time::system_clock::now());
+  std::ostringstream os;
+  os << "     LsaInfo("
+     << "OriginRouter: " << lsa.getOriginRouter() << ", "
+     << "SequenceNumber: " << lsa.getSeqNo() << ", "
+     << "ExpirationPeriod: " << duration;
+     os << ")\n\n";
 
-  const auto& pair =
-    m_routers.insert(std::make_pair(originRouterName, Router()));
-
-  return pair.first->second;
+  return os.str();
 }
 
 } // namespace nlsrc
diff --git a/tools/nlsrc.hpp b/tools/nlsrc.hpp
index e05891c..aab636c 100644
--- a/tools/nlsrc.hpp
+++ b/tools/nlsrc.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -19,12 +19,11 @@
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  **/
 
-#include "tlv/adjacency-lsa.hpp"
-#include "tlv/coordinate-lsa.hpp"
-#include "tlv/name-lsa.hpp"
+#include "lsa/adj-lsa.hpp"
+#include "lsa/coordinate-lsa.hpp"
+#include "lsa/name-lsa.hpp"
 #include "tlv/routing-table-status.hpp"
 
-
 #include <boost/noncopyable.hpp>
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
@@ -120,18 +119,8 @@
   void
   onTimeout(uint32_t errorCode, const std::string& error);
 
-private:
-  std::string
-  getLsaInfoString(const nlsr::tlv::LsaInfo& info);
-
   void
-  recordAdjacencyLsa(const nlsr::tlv::AdjacencyLsa& lsa);
-
-  void
-  recordCoordinateLsa(const nlsr::tlv::CoordinateLsa& lsa);
-
-  void
-  recordNameLsa(const nlsr::tlv::NameLsa& lsa);
+  recordLsa(const nlsr::Lsa& lsa);
 
   void
   recordRtable(const nlsr::tlv::RoutingTableStatus& rts);
@@ -145,6 +134,9 @@
   void
   printAll();
 
+  std::string
+  getLsaInfo(const nlsr::Lsa& lsa);
+
 public:
   const char* programName;
 
@@ -160,11 +152,7 @@
     std::string nameLsaString;
   };
 
-  Router&
-  getRouterLsdb(const nlsr::tlv::LsaInfo& info);
-
-  typedef std::map<const ndn::Name, Router> RouterMap;
-  RouterMap m_routers;
+  std::map<ndn::Name, Router> m_routers;
 
 private:
   ndn::KeyChain m_keyChain;
@@ -184,7 +172,6 @@
   static const uint32_t ERROR_CODE_TIMEOUT;
   static const uint32_t RESPONSE_CODE_SUCCESS;
   static const uint32_t RESPONSE_CODE_SAVE_OR_DELETE;
-
 };
 
 } // namespace nlsrc