src: Replace LSA string literals with constants

refs: #2310

Change-Id: I0823c320400fe03b6268982cec05578c04d82ca8
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 94ac76b..4725c9b 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -117,11 +117,6 @@
 const std::string SyncUpdate::NLSR_COMPONENT = "NLSR";
 const std::string SyncUpdate::LSA_COMPONENT = "LSA";
 
-const std::string SyncLogicHandler::NAME_COMPONENT = "name";
-const std::string SyncLogicHandler::ADJACENCY_COMPONENT = "adjacency";
-const std::string SyncLogicHandler::COORDINATE_COMPONENT = "coordinate";
-
-
 template<class T>
 class NullDeleter
 {
@@ -198,22 +193,22 @@
     update.getSequencingManager().writeLog();
 
     try {
-      if (isLsaNew(originRouter, NAME_COMPONENT, update.getNameLsaSeqNo())) {
+      if (isLsaNew(originRouter, NameLsa::TYPE_STRING, update.getNameLsaSeqNo())) {
         _LOG_DEBUG("Received sync update with higher Name LSA sequence number than entry in LSDB");
 
-        expressInterestForLsa(update, NAME_COMPONENT, update.getNameLsaSeqNo());
+        expressInterestForLsa(update, NameLsa::TYPE_STRING, update.getNameLsaSeqNo());
       }
 
-      if (isLsaNew(originRouter, ADJACENCY_COMPONENT, update.getAdjLsaSeqNo())) {
+      if (isLsaNew(originRouter, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo())) {
         _LOG_DEBUG("Received sync update with higher Adj LSA sequence number than entry in LSDB");
 
-        expressInterestForLsa(update, ADJACENCY_COMPONENT, update.getAdjLsaSeqNo());
+        expressInterestForLsa(update, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo());
       }
 
-      if (isLsaNew(originRouter, COORDINATE_COMPONENT, update.getCorLsaSeqNo())) {
+      if (isLsaNew(originRouter, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo())) {
         _LOG_DEBUG("Received sync update with higher Cor LSA sequence number than entry in LSDB");
 
-        expressInterestForLsa(update, COORDINATE_COMPONENT, update.getCorLsaSeqNo());
+        expressInterestForLsa(update, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo());
       }
     }
     catch (std::exception& e) {
@@ -230,15 +225,15 @@
   ndn::Name lsaKey = originRouter;
   lsaKey.append(lsaType);
 
-  if (lsaType == NAME_COMPONENT)
+  if (lsaType == NameLsa::TYPE_STRING)
   {
     return m_lsdb.isNameLsaNew(lsaKey, seqNo);
   }
-  else if (lsaType == ADJACENCY_COMPONENT)
+  else if (lsaType == AdjLsa::TYPE_STRING)
   {
     return m_lsdb.isAdjLsaNew(lsaKey, seqNo);
   }
-  else if (lsaType == COORDINATE_COMPONENT)
+  else if (lsaType == CoordinateLsa::TYPE_STRING)
   {
     return m_lsdb.isCoordinateLsaNew(lsaKey, seqNo);
   }
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 6a2c443..6f0726c 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -97,9 +97,6 @@
 private:
   static const std::string NLSR_COMPONENT;
   static const std::string LSA_COMPONENT;
-  static const std::string NAME_COMPONENT;
-  static const std::string ADJACENCY_COMPONENT;
-  static const std::string COORDINATE_COMPONENT;
 
 };
 
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 99b69a8..8b15741 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -42,11 +42,15 @@
 
 using namespace std;
 
+const std::string NameLsa::TYPE_STRING = "name";
+const std::string AdjLsa::TYPE_STRING = "adjacency";
+const std::string CoordinateLsa::TYPE_STRING = "coordinate";
+
 const ndn::Name
 NameLsa::getKey() const
 {
   ndn::Name key = m_origRouter;
-  key.append("name");
+  key.append(NameLsa::TYPE_STRING);
   return key;
 }
 
@@ -68,7 +72,7 @@
 NameLsa::getData()
 {
   string nameLsaData;
-  nameLsaData = m_origRouter.toUri() + "|" + "name" + "|"
+  nameLsaData = m_origRouter.toUri() + "|" + NameLsa::TYPE_STRING + "|"
                 + boost::lexical_cast<std::string>(m_lsSeqNo) + "|"
                 + ndn::time::toIsoString(m_expirationTimePoint);
   nameLsaData += "|";
@@ -144,7 +148,7 @@
 CoordinateLsa::getKey() const
 {
   ndn::Name key = m_origRouter;
-  key.append("coordinate");
+  key.append(CoordinateLsa::TYPE_STRING);
   return key;
 }
 
@@ -162,7 +166,7 @@
 {
   string corLsaData;
   corLsaData = m_origRouter.toUri() + "|";
-  corLsaData += "coordinate";
+  corLsaData += CoordinateLsa::TYPE_STRING;
   corLsaData += "|";
   corLsaData += (boost::lexical_cast<std::string>(m_lsSeqNo) + "|");
   corLsaData += (ndn::time::toIsoString(m_expirationTimePoint) + "|");
@@ -228,7 +232,7 @@
 AdjLsa::getKey() const
 {
   ndn::Name key = m_origRouter;
-  key.append("adjacency");
+  key.append(AdjLsa::TYPE_STRING);
   return key;
 }
 
@@ -243,7 +247,7 @@
 AdjLsa::getData()
 {
   string adjLsaData;
-  adjLsaData = m_origRouter.toUri() + "|" + "adjacency" + "|"
+  adjLsaData = m_origRouter.toUri() + "|" + AdjLsa::TYPE_STRING + "|"
                + boost::lexical_cast<std::string>(m_lsSeqNo) + "|"
                + ndn::time::toIsoString(m_expirationTimePoint);
   adjLsaData += "|";
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 2137069..6ba85c9 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -120,7 +120,7 @@
     : Lsa()
     , m_npl()
   {
-    setLsType("name");
+    setLsType(NameLsa::TYPE_STRING);
   }
 
   NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
@@ -159,7 +159,8 @@
 
 private:
   NamePrefixList m_npl;
-
+public:
+  static const std::string TYPE_STRING;
 };
 
 class AdjLsa: public Lsa
@@ -169,7 +170,7 @@
     : Lsa()
     , m_adl()
   {
-    setLsType("adjacency");
+    setLsType(AdjLsa::TYPE_STRING);
   }
 
   AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
@@ -218,6 +219,9 @@
 private:
   uint32_t m_noLink;
   AdjacencyList m_adl;
+
+public:
+  static const std::string TYPE_STRING;
 };
 
 class CoordinateLsa: public Lsa
@@ -228,7 +232,7 @@
     , m_corRad(0)
     , m_corTheta(0)
   {
-    setLsType("coordinate");
+    setLsType(CoordinateLsa::TYPE_STRING);
   }
 
   CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
@@ -278,6 +282,8 @@
   double m_corRad;
   double m_corTheta;
 
+public:
+  static const std::string TYPE_STRING;
 };
 
 }//namespace nlsr
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index ce7c706..42f0f16 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -55,7 +55,7 @@
 Lsdb::buildAndInstallOwnNameLsa()
 {
   NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                  "name",
+                  NameLsa::TYPE_STRING,
                   m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
                   getLsaExpirationTimePoint(),
                   m_nlsr.getNamePrefixList());
@@ -261,7 +261,7 @@
 Lsdb::buildAndInstallOwnCoordinateLsa()
 {
   CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                       "coordinate",
+                       CoordinateLsa::TYPE_STRING,
                        m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
                        getLsaExpirationTimePoint(),
                        m_nlsr.getConfParameter().getCorR(),
@@ -443,7 +443,7 @@
       }
       else {
         ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
-        key.append("adjacency");
+        key.append(AdjLsa::TYPE_STRING);
         removeAdjLsa(key);
         m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
       }
@@ -563,7 +563,7 @@
 Lsdb::buildAndInstallOwnAdjLsa()
 {
   AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                "adjacency",
+                AdjLsa::TYPE_STRING,
                 m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
                 getLsaExpirationTimePoint(),
                 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
@@ -787,13 +787,13 @@
 
     std::string interestedLsType = interestName[-2].toUri();
 
-    if (interestedLsType == "name") {
+    if (interestedLsType == NameLsa::TYPE_STRING) {
       processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo);
     }
-    else if (interestedLsType == "adjacency") {
+    else if (interestedLsType == AdjLsa::TYPE_STRING) {
       processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo);
     }
-    else if (interestedLsType == "coordinate") {
+    else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
       processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo);
     }
     else {
@@ -913,13 +913,13 @@
 
     std::string interestedLsType  = dataName[-3].toUri();
 
-    if (interestedLsType == "name") {
+    if (interestedLsType == NameLsa::TYPE_STRING) {
       processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent);
     }
-    else if (interestedLsType == "adjacency") {
+    else if (interestedLsType == AdjLsa::TYPE_STRING) {
       processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent);
     }
-    else if (interestedLsType == "coordinate") {
+    else if (interestedLsType == CoordinateLsa::TYPE_STRING) {
       processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent);
     }
     else {
@@ -1040,13 +1040,13 @@
 bool
 Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
 {
-  if (lsType == "name") {
+  if (lsType == NameLsa::TYPE_STRING) {
     return doesNameLsaExist(key);
   }
-  else if (lsType == "adjacency") {
+  else if (lsType == AdjLsa::TYPE_STRING) {
     return doesAdjLsaExist(key);
   }
-  else if (lsType == "coordinate") {
+  else if (lsType == CoordinateLsa::TYPE_STRING) {
     return doesCoordinateLsaExist(key);
   }
   return false;
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index d9c63e4..1d8a90c 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.cpp
@@ -85,12 +85,12 @@
     ndn::Name destRouter = rte.getDestination();
     (*it).removeRoutingTableEntry(rte);
     if (((*it).getRteListSize() == 0) &&
-        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/name"),
-                                        std::string("name"))) &&
-        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/adjacency"),
-                                        std::string("adjacency"))) &&
-        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/coordinate"),
-                                        std::string("coordinate")))) {
+        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + NameLsa::TYPE_STRING),
+                                        (NameLsa::TYPE_STRING))) &&
+        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + AdjLsa::TYPE_STRING),
+                                        (AdjLsa::TYPE_STRING))) &&
+        (!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/" + CoordinateLsa::TYPE_STRING),
+                                        (CoordinateLsa::TYPE_STRING)))) {
       m_table.erase(it);
       m_nlsr.getFib().remove(name);
     }