src: Replace Tokenizer with the methods of ndn::Name

Purpose of this commit is to replace Tokenizer in all
places except conf-file-processor.*pp with the methods
of ndn::Name. One static method in class NameHelper
is added. Tokenizer will be removed finally when
configuration file parsing commit is complete.

Refs: 1533

Change-Id: I14a67655eb963c5cc5b045c3c9f7d516e405ff19
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index c8b5ec9..10a40ec 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -1,7 +1,7 @@
 #include "nlsr.hpp"
 #include "sync-logic-handler.hpp"
-// #include "security/key-manager.hpp"
-#include "utility/tokenizer.hpp"
+#include "utility/name-helper.hpp"
+#include "lsa.hpp"
 
 
 namespace nlsr {
@@ -13,7 +13,7 @@
 SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
 {
   std::cout << "Creating Sync socket ......" << std::endl;
-  std::cout << "Sync prefix: " << m_syncPrefix.toUri() << std::endl;
+  std::cout << "Sync prefix: " << m_syncPrefix << std::endl;
   m_syncSocket = make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
                                                m_syncFace,
                                                bind(&SyncLogicHandler::nsyncUpdateCallBack, this,
@@ -43,116 +43,97 @@
 }
 
 void
-SyncLogicHandler::removeRouterFromSyncing(const string& routerPrefix)
+SyncLogicHandler::removeRouterFromSyncing(const ndn::Name& routerPrefix)
 {
 }
 
 void
-SyncLogicHandler::processUpdateFromSync(const std::string& updateName,
+SyncLogicHandler::processUpdateFromSync(const ndn::Name& updateName,
                                         uint64_t seqNo,  Nlsr& pnlsr)
 {
-  Tokenizer nt(updateName, "/");
+  //const ndn::Name name(updateName);
   string chkString("LSA");
-  if (nt.doesTokenExist(chkString))
+  int32_t lasPosition = util::getNameComponentPosition(updateName, chkString);
+  if (lasPosition >= 0)
   {
-    //process LSA Update here
-    string routerName = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
+    ndn::Name routerName = updateName.getSubName(lasPosition + 1);
     processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
-  }
-  chkString = "keys";
-  if (nt.doesTokenExist(chkString))
-  {
-    //process keys update here
-    std::string certName = nt.getTokenString(0);
-    // processKeysUpdateFromSync(certName, seqNo, pnlsr);
+    return;
   }
 }
 
 void
-SyncLogicHandler::processRoutingUpdateFromSync(const std::string& routerName,
+SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
                                                uint64_t seqNo,  Nlsr& pnlsr)
 {
+  ndn::Name rName = routerName;
   if (routerName != pnlsr.getConfParameter().getRouterPrefix())
   {
     SequencingManager sm(seqNo);
     std::cout << sm;
     std::cout << "Router Name: " << routerName << endl;
-    if (pnlsr.getLsdb().isNameLsaNew(routerName + "/1", sm.getNameLsaSeq()))
+    try
     {
-      std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
-      string lsaPrefix =
-        pnlsr.getConfParameter().getChronosyncLsaPrefix() +
-        routerName + "/1/" +
-        boost::lexical_cast<std::string>(sm.getNameLsaSeq());
-      pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
-                                                 pnlsr.getConfParameter().getInterestResendTime());
+      if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq()))
+      {
+        std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
+        ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+        interestName.append(routerName);
+        interestName.append("name");
+        interestName.appendNumber(sm.getNameLsaSeq());
+        pnlsr.getLsdb().expressInterest(interestName,
+                                        pnlsr.getConfParameter().getInterestResendTime());
+      }
+      if (pnlsr.getLsdb().isAdjLsaNew(rName.append("adjacency"),
+                                      sm.getAdjLsaSeq()))
+      {
+        std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
+        ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+        interestName.append(routerName);
+        interestName.append("adjacency");
+        interestName.appendNumber(sm.getAdjLsaSeq());
+        pnlsr.getLsdb().expressInterest(interestName,
+                                        pnlsr.getConfParameter().getInterestResendTime());
+      }
+      if (pnlsr.getLsdb().isCoordinateLsaNew(rName.append("coordinate"),
+                                             sm.getCorLsaSeq()))
+      {
+        std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
+        ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
+        interestName.append(routerName);
+        interestName.append("coordinate");
+        interestName.appendNumber(sm.getCorLsaSeq());
+        pnlsr.getLsdb().expressInterest(interestName,
+                                        pnlsr.getConfParameter().getInterestResendTime());
+      }
     }
-    if (pnlsr.getLsdb().isAdjLsaNew(routerName + "/2", sm.getAdjLsaSeq()))
+    catch (std::exception& e)
     {
-      std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
-      string lsaPrefix =
-        pnlsr.getConfParameter().getChronosyncLsaPrefix() +
-        routerName + "/2/" +
-        boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
-      pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
-                                                 pnlsr.getConfParameter().getInterestResendTime());
-    }
-    if (pnlsr.getLsdb().isCoordinateLsaNew(routerName + "/3", sm.getCorLsaSeq()))
-    {
-      std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
-      string lsaPrefix =
-        pnlsr.getConfParameter().getChronosyncLsaPrefix() +
-        routerName + "/3/" +
-        boost::lexical_cast<std::string>(sm.getCorLsaSeq());
-      pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
-                                                 pnlsr.getConfParameter().getInterestResendTime());
+      std::cerr << e.what() << std::endl;
+      return;
     }
   }
 }
 
-// void
-// SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
-//                                             uint64_t seqNo, Nlsr& pnlsr)
-// {
-//   std::cout << "Cert Name: " << certName << std::endl;
-//   // if (pnlsr.getKeyManager().isNewCertificate(certName, seqNo))
-//   {
-//     string certNamePrefix = certName + "/" +
-//                             boost::lexical_cast<string>(seqNo);
-//     pnlsr.getIm().expressInterest(certNamePrefix, 3,
-//                                   pnlsr.getConfParameter().getInterestResendTime());
-//   }
-// }
-
 void
 SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
-                                       const string& updatePrefix)
+                                       const ndn::Name& updatePrefix)
 {
   sm.writeSeqNoToFile();
   publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo());
 }
 
-// void
-// SyncLogicHandler::publishKeyUpdate(KeyManager& km)
-// {
-//   publishSyncUpdate(km.getProcessCertName().toUri(), km.getCertSeqNo());
-// }
-
 void
-SyncLogicHandler::publishIdentityUpdate(const string& identityName)
-{
-  publishSyncUpdate(identityName, 0);
-}
-
-void
-SyncLogicHandler::publishSyncUpdate(const string& updatePrefix, uint64_t seqNo)
+SyncLogicHandler::publishSyncUpdate(const ndn::Name& updatePrefix,
+                                    uint64_t seqNo)
 {
   std::cout << "Publishing Sync Update ......" << std::endl;
   std::cout << "Update in prefix: " << updatePrefix << std::endl;
   std::cout << "Seq No: " << seqNo << std::endl;
   ndn::Name updateName(updatePrefix);
   string data("NoData");
-  m_syncSocket->publishData(updateName, 0, data.c_str(), data.size(), 1000,
+  m_syncSocket->publishData(updateName.toUri(), 0, data.c_str(), data.size(),
+                            1000,
                             seqNo);
 }