Use separate name prefix and sequence number for each LSA type

refs: #1523

Change-Id: I9db6b3a3ea9ce5e17e132d2a4e2ae9f30dd4f591
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 09d5c27..1413b39 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -26,7 +26,6 @@
 #include "logger.hpp"
 #include "lsa.hpp"
 #include "lsdb.hpp"
-#include "sequencing-manager.hpp"
 #include "utility/name-helper.hpp"
 
 namespace nlsr {
@@ -36,85 +35,8 @@
 using namespace ndn;
 using namespace std;
 
-class SyncUpdate
-{
-public:
-  class Error : public std::runtime_error
-  {
-  public:
-    explicit
-    Error(const std::string& what)
-      : std::runtime_error(what)
-    {
-    }
-  };
-
-public:
-  SyncUpdate(const ndn::Name& name, uint64_t seqNo)
-    : m_name(name)
-    , m_seqManager(seqNo)
-  {
-  }
-
-  const ndn::Name&
-  getName() const
-  {
-    return m_name;
-  }
-
-  const ndn::Name
-  getOriginRouter() const
-  {
-    int32_t nlsrPosition = util::getNameComponentPosition(m_name, NLSR_COMPONENT);
-    int32_t lsaPosition = util::getNameComponentPosition(m_name, LSA_COMPONENT);
-
-    if (nlsrPosition < 0 || lsaPosition < 0) {
-      BOOST_THROW_EXCEPTION(Error("Cannot parse update name because expected components are missing"));
-    }
-
-    ndn::Name networkName = m_name.getSubName(1, nlsrPosition-1);
-    ndn::Name routerName = m_name.getSubName(lsaPosition + 1);
-
-    ndn::Name originRouter = networkName;
-    originRouter.append(routerName);
-
-    return originRouter;
-  }
-
-  uint64_t
-  getNameLsaSeqNo() const
-  {
-    return m_seqManager.getNameLsaSeq();
-  }
-
-  uint64_t
-  getAdjLsaSeqNo() const
-  {
-    return m_seqManager.getAdjLsaSeq();
-  }
-
-  uint64_t
-  getCorLsaSeqNo() const
-  {
-    return m_seqManager.getCorLsaSeq();
-  }
-
-  const SequencingManager&
-  getSequencingManager() const
-  {
-    return m_seqManager;
-  }
-
-private:
-  const ndn::Name m_name;
-  SequencingManager m_seqManager;
-
-  static const std::string NLSR_COMPONENT;
-  static const std::string LSA_COMPONENT;
-};
-
-const std::string SyncUpdate::NLSR_COMPONENT = "NLSR";
-const std::string SyncUpdate::LSA_COMPONENT = "LSA";
+const std::string NLSR_COMPONENT = "NLSR";
+const std::string LSA_COMPONENT = "LSA";
 
 template<class T>
 class NullDeleter
@@ -127,13 +49,10 @@
 };
 
 SyncLogicHandler::SyncLogicHandler(ndn::Face& face,
-                                   Lsdb& lsdb, ConfParameter& conf,
-                                   SequencingManager& seqManager)
-  : m_validator(new ndn::ValidatorNull())
-  , m_syncFace(face)
+                                   Lsdb& lsdb, ConfParameter& conf)
+  : m_syncFace(face)
   , m_lsdb(lsdb)
   , m_confParam(conf)
-  , m_sequencingManager(seqManager)
 {
 }
 
@@ -156,8 +75,16 @@
   // of the object
   std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
 
-  m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_updatePrefix, *facePtr,
+
+  m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
                                                       bind(&SyncLogicHandler::onNsyncUpdate, this, _1));
+
+  if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+    m_syncSocket->addSyncNode(m_adjLsaUserPrefix);
+  }
+  else {
+    m_syncSocket->addSyncNode(m_coorLsaUserPrefix);
+  }
 }
 
 void
@@ -166,75 +93,64 @@
   _LOG_DEBUG("Received Nsync update event");
 
   for (size_t i = 0; i < v.size(); i++){
-    _LOG_DEBUG("Update Name: " << v[i].session.getPrefix(-1).toUri() << " Seq no: " << v[i].high);
+    ndn::Name updateName = v[i].session.getPrefix(-1);
 
-    SyncUpdate update(v[i].session.getPrefix(-1), v[i].high);
+    _LOG_DEBUG("Update Name: " << updateName << " Seq no: " << v[i].high);
 
-    processUpdateFromSync(update);
+    int32_t nlsrPosition = util::getNameComponentPosition(updateName, nlsr::NLSR_COMPONENT);
+    int32_t lsaPosition = util::getNameComponentPosition(updateName, nlsr::LSA_COMPONENT);
+
+    if (nlsrPosition < 0 || lsaPosition < 0) {
+      _LOG_WARN("Received malformed sync update");
+      return;
+    }
+
+    ndn::Name networkName = updateName.getSubName(1, nlsrPosition-1);
+    ndn::Name routerName = updateName.getSubName(lsaPosition + 1).getPrefix(-1);
+
+    ndn::Name originRouter = networkName;
+    originRouter.append(routerName);
+
+    processUpdateFromSync(originRouter, updateName, v[i].high);
   }
 }
 
 void
-SyncLogicHandler::onNsyncRemoval(const string& prefix)
+SyncLogicHandler::processUpdateFromSync(const ndn::Name& originRouter,
+                                        const ndn::Name& updateName, const uint64_t& seqNo)
 {
-  _LOG_DEBUG("Received Nsync removal event");
-}
-
-void
-SyncLogicHandler::processUpdateFromSync(const SyncUpdate& update)
-{
-  ndn::Name originRouter;
-
-  try {
-    originRouter = update.getOriginRouter();
-  }
-  catch (const std::exception& e) {
-    _LOG_WARN("Received malformed sync update");
-    return;
-  }
+  _LOG_DEBUG("Origin Router of update: " << originRouter);
 
   // A router should not try to fetch its own LSA
   if (originRouter != m_confParam.getRouterPrefix()) {
 
-    update.getSequencingManager().writeLog();
+    std::string lsaType = updateName.get(updateName.size()-1).toUri();
 
-    if (isLsaNew(originRouter, NameLsa::TYPE_STRING, update.getNameLsaSeqNo())) {
-        _LOG_DEBUG("Received sync update with higher Name LSA sequence number than entry in LSDB");
+    _LOG_DEBUG("Received sync update with higher " << lsaType
+               << " sequence number than entry in LSDB");
 
-        expressInterestForLsa(update, NameLsa::TYPE_STRING, update.getNameLsaSeqNo());
+    if (isLsaNew(originRouter, lsaType, seqNo)) {
+      if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
+          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+        _LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
+                   << " is enabled. Not going to fetch.");
+        return;
       }
 
-      if (isLsaNew(originRouter, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo())) {
-        _LOG_DEBUG("Received sync update with higher Adj LSA sequence number than entry in LSDB");
-        if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-          if (update.getAdjLsaSeqNo() != 0) {
-            _LOG_ERROR("Tried to fetch an adjacency LSA when hyperbolic routing"
-                       << " is enabled.");
-          }
-        }
-        else {
-          expressInterestForLsa(update, AdjLsa::TYPE_STRING, update.getAdjLsaSeqNo());
-        }
+      if (lsaType == CoordinateLsa::TYPE_STRING && seqNo != 0 &&
+          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+        _LOG_ERROR("Got an update for coordinate LSA when link-state"
+                   << " is enabled. Not going to fetch.");
+        return;
       }
-
-      if (isLsaNew(originRouter, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo())) {
-        _LOG_DEBUG("Received sync update with higher Cor LSA sequence number than entry in LSDB");
-        if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
-          if (update.getCorLsaSeqNo() != 0) {
-            _LOG_ERROR("Tried to fetch a coordinate LSA when link-state"
-                       << " is enabled.");
-          }
-        }
-        else {
-          expressInterestForLsa(update, CoordinateLsa::TYPE_STRING, update.getCorLsaSeqNo());
-        }
-      }
+      expressInterestForLsa(updateName, seqNo);
+    }
   }
 }
 
 bool
 SyncLogicHandler::isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
-                           uint64_t seqNo)
+                           const uint64_t& seqNo)
 {
   ndn::Name lsaKey = originRouter;
   lsaKey.append(lsaType);
@@ -256,18 +172,17 @@
 }
 
 void
-SyncLogicHandler::expressInterestForLsa(const SyncUpdate& update, std::string lsaType,
-                                        uint64_t seqNo)
+SyncLogicHandler::expressInterestForLsa(const ndn::Name& updateName,
+                                        const uint64_t& seqNo)
 {
-  ndn::Name interest(update.getName());
-  interest.append(lsaType);
+  ndn::Name interest(updateName);
   interest.appendNumber(seqNo);
 
   m_lsdb.expressInterest(interest, 0);
 }
 
 void
-SyncLogicHandler::publishRoutingUpdate()
+SyncLogicHandler::publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo)
 {
   if (m_syncSocket == nullptr) {
     _LOG_FATAL("Cannot publish routing update; SyncSocket does not exist");
@@ -275,17 +190,32 @@
     BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncSocket does not exist"));
   }
 
-  m_sequencingManager.writeSeqNoToFile();
-
-  publishSyncUpdate(m_updatePrefix, m_sequencingManager.getCombinedSeqNo());
+  if (type == NameLsa::TYPE_STRING) {
+    publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
+  }
+  else if (type == AdjLsa::TYPE_STRING) {
+    publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
+  }
+  else {
+    publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
+  }
 }
 
 void
 SyncLogicHandler::buildUpdatePrefix()
 {
-  m_updatePrefix = m_confParam.getLsaPrefix();
-  m_updatePrefix.append(m_confParam.getSiteName());
-  m_updatePrefix.append(m_confParam.getRouterName());
+  ndn::Name updatePrefix = m_confParam.getLsaPrefix();
+  updatePrefix.append(m_confParam.getSiteName());
+  updatePrefix.append(m_confParam.getRouterName());
+
+  m_nameLsaUserPrefix = updatePrefix;
+  m_nameLsaUserPrefix.append(NameLsa::TYPE_STRING);
+
+  m_adjLsaUserPrefix = updatePrefix;
+  m_adjLsaUserPrefix.append(AdjLsa::TYPE_STRING);
+
+  m_coorLsaUserPrefix = updatePrefix;
+  m_coorLsaUserPrefix.append(CoordinateLsa::TYPE_STRING);
 }
 
 void
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index c8e143e..2b7dd94 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -23,7 +23,6 @@
 #define NLSR_SYNC_LOGIC_HANDLER_HPP
 
 #include <ndn-cxx/face.hpp>
-#include <ndn-cxx/security/validator-null.hpp>
 #include <ChronoSync/socket.hpp>
 
 #include <iostream>
@@ -39,8 +38,6 @@
 
 class ConfParameter;
 class Lsdb;
-class SequencingManager;
-class SyncUpdate;
 
 class SyncLogicHandler
 {
@@ -55,21 +52,29 @@
     }
   };
 
-  SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
+  SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf);
 
-  /*! \brief Simple wrapper function to handle updates from Sync.
+  /*! \brief Receive and parse update from Sync
+
+    Parses the router name the update came from and passes it to processUpdateFromSync
 
     \param v The information that Sync has acquired.
    */
   void
   onNsyncUpdate(const std::vector<chronosync::MissingDataInfo>& v);
 
-  void
-  onNsyncRemoval(const std::string& prefix);
+  /*! \brief Wrapper function to call publishSyncUpdate with correct LSA type
 
+    \param type The LSA type constant
+    \param seqNo The latest seqNo known to lsdb
+   */
   void
-  publishRoutingUpdate();
+  publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo);
 
+  /*! \brief Creates ChronoSync socket and register additional sync nodes (user prefixes)
+
+    \param syncPrefix /localhop/NLSR/sync
+   */
   void
   createSyncSocket(const ndn::Name& syncPrefix);
 
@@ -78,19 +83,20 @@
   buildUpdatePrefix();
 
   void
-  processUpdateFromSync(const SyncUpdate& updateName);
+  processUpdateFromSync(const ndn::Name& originRouter,
+                        const ndn::Name& updateName, const uint64_t& seqNo);
 
   bool
-  isLsaNew(const ndn::Name& originRouter, const std::string& lsaType, uint64_t seqNo);
+  isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
+           const uint64_t& seqNo);
 
   void
-  expressInterestForLsa(const SyncUpdate& updateName, std::string lsaType, uint64_t seqNo);
+  expressInterestForLsa(const ndn::Name& updateName, const uint64_t& seqNo);
 
   void
   publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
 
 private:
-  std::shared_ptr<ndn::ValidatorNull> m_validator;
   ndn::Face& m_syncFace;
   std::shared_ptr<chronosync::Socket> m_syncSocket;
   ndn::Name m_syncPrefix;
@@ -98,10 +104,11 @@
 private:
   Lsdb& m_lsdb;
   ConfParameter& m_confParam;
-  const SequencingManager& m_sequencingManager;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  ndn::Name m_updatePrefix;
+  ndn::Name m_nameLsaUserPrefix;
+  ndn::Name m_adjLsaUserPrefix;
+  ndn::Name m_coorLsaUserPrefix;
 
 private:
   static const std::string NLSR_COMPONENT;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 8468947..61a23f5 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -63,12 +63,13 @@
 const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10);
 const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min();
 
-Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync)
+Lsdb::Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler)
   : m_nlsr(nlsr)
   , m_scheduler(scheduler)
-  , m_sync(sync)
+  , m_sync(m_nlsr.getNlsrFace(), *this, m_nlsr.getConfParameter())
   , m_lsaRefreshTime(0)
   , m_adjLsaBuildInterval(ADJ_LSA_BUILD_INTERVAL_DEFAULT)
+  , m_sequencingManager()
 {
 }
 
@@ -150,10 +151,14 @@
 Lsdb::buildAndInstallOwnNameLsa()
 {
   NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                  m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
+                  m_sequencingManager.getNameLsaSeq() + 1,
                   getLsaExpirationTimePoint(),
                   m_nlsr.getNamePrefixList());
-  m_nlsr.getSequencingManager().increaseNameLsaSeq();
+  m_sequencingManager.increaseNameLsaSeq();
+
+  m_sequencingManager.writeSeqNoToFile();
+  m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
+
   return installNameLsa(nameLsa);
 }
 
@@ -378,15 +383,16 @@
 Lsdb::buildAndInstallOwnCoordinateLsa()
 {
   CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                       m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
+                       m_sequencingManager.getCorLsaSeq() + 1,
                        getLsaExpirationTimePoint(),
                        m_nlsr.getConfParameter().getCorR(),
                        m_nlsr.getConfParameter().getCorTheta());
 
   // Sync coordinate LSAs if using HR or HR dry run.
   if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
-    m_nlsr.getSequencingManager().increaseCorLsaSeq();
-    m_sync.publishRoutingUpdate();
+    m_sequencingManager.increaseCorLsaSeq();
+    m_sequencingManager.writeSeqNoToFile();
+    m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
   }
 
   installCoordinateLsa(corLsa);
@@ -751,15 +757,16 @@
 Lsdb::buildAndInstallOwnAdjLsa()
 {
   AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
-                m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
+                m_sequencingManager.getAdjLsaSeq() + 1,
                 getLsaExpirationTimePoint(),
                 m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
                 m_nlsr.getAdjacencyList());
 
   //Sync adjacency LSAs if link-state or dry-run HR is enabled.
   if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_ON) {
-    m_nlsr.getSequencingManager().increaseAdjLsaSeq();
-    m_sync.publishRoutingUpdate();
+    m_sequencingManager.increaseAdjLsaSeq();
+    m_sequencingManager.writeSeqNoToFile();
+    m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
   }
 
   return installAdjLsa(adjLsa);
@@ -834,7 +841,7 @@
         _LOG_DEBUG("Deleting Name Lsa");
         chkNameLsa->writeLog();
         chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
-        m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
+        m_sequencingManager.setNameLsaSeq(chkNameLsa->getLsSeqNo());
         chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
         _LOG_DEBUG("Adding Name Lsa");
         chkNameLsa->writeLog();
@@ -842,7 +849,8 @@
         chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
                                                                  chkNameLsa->getLsSeqNo(),
                                                                  m_lsaRefreshTime));
-        m_sync.publishRoutingUpdate();
+        m_sequencingManager.writeSeqNoToFile();
+        m_sync.publishRoutingUpdate(NameLsa::TYPE_STRING, m_sequencingManager.getNameLsaSeq());
       }
       // Since we cannot refresh other router's LSAs, our only choice is to expire.
       else {
@@ -877,7 +885,7 @@
         _LOG_DEBUG("Deleting Adj Lsa");
         chkAdjLsa->writeLog();
         chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
-        m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
+        m_sequencingManager.setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
         chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
         _LOG_DEBUG("Adding Adj Lsa");
         chkAdjLsa->writeLog();
@@ -885,7 +893,8 @@
         chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
                                                                chkAdjLsa->getLsSeqNo(),
                                                                m_lsaRefreshTime));
-        m_sync.publishRoutingUpdate();
+        m_sequencingManager.writeSeqNoToFile();
+        m_sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, m_sequencingManager.getAdjLsaSeq());
       }
       // An LSA from another router is expiring
       else {
@@ -924,7 +933,7 @@
         chkCorLsa->writeLog();
         chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
         if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
-          m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
+          m_sequencingManager.setCorLsaSeq(chkCorLsa->getLsSeqNo());
         }
 
         chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint());
@@ -937,7 +946,8 @@
                                         m_lsaRefreshTime));
         // Only sync coordinate LSAs if link-state routing is disabled
         if (m_nlsr.getConfParameter().getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
-          m_sync.publishRoutingUpdate();
+          m_sequencingManager.writeSeqNoToFile();
+          m_sync.publishRoutingUpdate(CoordinateLsa::TYPE_STRING, m_sequencingManager.getCorLsaSeq());
         }
       }
       // We can't refresh other router's LSAs, so we remove it.
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index a2d42cd..1ac25f2 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -30,19 +30,26 @@
 
 #include "conf-parameter.hpp"
 #include "lsa.hpp"
+#include "sequencing-manager.hpp"
 #include "test-access-control.hpp"
+#include "communication/sync-logic-handler.hpp"
 
 namespace nlsr {
 
 using namespace ndn::time;
 
 class Nlsr;
-class SyncLogicHandler;
 
 class Lsdb
 {
 public:
-  Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler, SyncLogicHandler& sync);
+  Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
+
+  SyncLogicHandler&
+  getSyncLogicHandler()
+  {
+    return m_sync;
+  }
 
   bool
   doesLsaExist(const ndn::Name& key, const std::string& lsType);
@@ -181,6 +188,12 @@
     return m_adjLsaBuildInterval;
   }
 
+  SequencingManager&
+  getSequencingManager()
+  {
+    return m_sequencingManager;
+  }
+
   void
   writeAdjLsdbLog();
 
@@ -364,7 +377,7 @@
 private:
   Nlsr& m_nlsr;
   ndn::Scheduler& m_scheduler;
-  SyncLogicHandler& m_sync;
+  SyncLogicHandler m_sync;
 
   std::list<NameLsa> m_nameLsdb;
   std::list<AdjLsa> m_adjLsdb;
@@ -383,6 +396,8 @@
   static const steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
 
   ndn::time::seconds m_adjLsaBuildInterval;
+
+  SequencingManager m_sequencingManager;
 };
 
 } // namespace nlsr
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 8a88c1f..f0c4305 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -46,10 +46,9 @@
   , m_confParam()
   , m_adjacencyList()
   , m_namePrefixList()
-  , m_sequencingManager()
   , m_isDaemonProcess(false)
   , m_configFileName("nlsr.conf")
-  , m_nlsrLsdb(*this, scheduler, m_syncLogicHandler)
+  , m_nlsrLsdb(*this, scheduler)
   , m_adjBuildCount(0)
   , m_isBuildAdjLsaSheduled(false)
   , m_isRouteCalculationScheduled(false)
@@ -57,7 +56,6 @@
   , m_routingTable(scheduler)
   , m_fib(m_nlsrFace, scheduler, m_adjacencyList, m_confParam, m_keyChain)
   , m_namePrefixTable(*this)
-  , m_syncLogicHandler(m_nlsrFace, m_nlsrLsdb, m_confParam, m_sequencingManager)
   , m_lsdbDatasetHandler(m_nlsrLsdb,
                          m_nlsrFace,
                          m_keyChain)
@@ -67,7 +65,6 @@
   , m_prefixUpdateProcessor(m_nlsrFace,
                             m_namePrefixList,
                             m_nlsrLsdb,
-                            m_syncLogicHandler,
                             DEFAULT_BROADCAST_PREFIX,
                             m_keyChain,
                             m_certificateCache,
@@ -75,8 +72,7 @@
   , m_dispatcher(m_nlsrFace, m_keyChain, m_signingInfo)
   , m_nfdRibCommandProcessor(m_dispatcher,
                              m_namePrefixList,
-                             m_nlsrLsdb,
-                             m_syncLogicHandler)
+                             m_nlsrLsdb)
   , m_faceMonitor(m_nlsrFace)
   , m_firstHelloInterval(FIRST_HELLO_INTERVAL_DEFAULT)
 {
@@ -232,10 +228,11 @@
   m_nlsrLsdb.setLsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()));
   m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
   m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
-  m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
-  m_sequencingManager.initiateSeqNoFromFile(m_confParam.getHyperbolicState());
 
-  m_syncLogicHandler.createSyncSocket(m_confParam.getChronosyncPrefix());
+  m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
+  m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
+
+  m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix());
 
   // Logging start
   m_confParam.writeLog();
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 574e53a..3df4fd1 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -40,10 +40,8 @@
 #include "hello-protocol.hpp"
 #include "lsdb.hpp"
 #include "name-prefix-list.hpp"
-#include "sequencing-manager.hpp"
 #include "test-access-control.hpp"
 #include "validator.hpp"
-#include "communication/sync-logic-handler.hpp"
 #include "publisher/lsdb-dataset-interest-handler.hpp"
 #include "route/fib.hpp"
 #include "route/name-prefix-table.hpp"
@@ -140,12 +138,6 @@
     return m_nlsrFace;
   }
 
-  SequencingManager&
-  getSequencingManager()
-  {
-    return m_sequencingManager;
-  }
-
   Lsdb&
   getLsdb()
   {
@@ -224,12 +216,6 @@
     m_isRouteCalculationScheduled = ircs;
   }
 
-  SyncLogicHandler&
-  getSyncLogicHandler()
-  {
-    return m_syncLogicHandler;
-  }
-
   LsdbDatasetInterestHandler&
   getLsdbDatasetHandler()
   {
@@ -408,7 +394,6 @@
   ConfParameter m_confParam;
   AdjacencyList m_adjacencyList;
   NamePrefixList m_namePrefixList;
-  SequencingManager m_sequencingManager;
   bool m_isDaemonProcess;
   std::string m_configFileName;
   Lsdb m_nlsrLsdb;
@@ -419,7 +404,6 @@
   RoutingTable m_routingTable;
   Fib m_fib;
   NamePrefixTable m_namePrefixTable;
-  SyncLogicHandler m_syncLogicHandler;
   LsdbDatasetInterestHandler m_lsdbDatasetHandler;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index 1c91700..6eaab5d 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -25,6 +25,7 @@
 #include <pwd.h>
 #include <cstdlib>
 #include <unistd.h>
+#include <boost/algorithm/string.hpp>
 
 #include "sequencing-manager.hpp"
 #include "logger.hpp"
@@ -36,28 +37,15 @@
 using namespace std;
 
 void
-SequencingManager::splitSequenceNo(uint64_t seqNo)
-{
-  m_combinedSeqNo = seqNo;
-  m_adjLsaSeq = (m_combinedSeqNo & 0xFFFFF);
-  m_corLsaSeq = ((m_combinedSeqNo >> 20) & 0xFFFFF);
-  m_nameLsaSeq = ((m_combinedSeqNo >> 40) & 0xFFFFFF);
-}
-
-void
-SequencingManager::combineSequenceNo()
-{
-  m_combinedSeqNo = 0;
-  m_combinedSeqNo = m_combinedSeqNo | m_adjLsaSeq;
-  m_combinedSeqNo = m_combinedSeqNo | (m_corLsaSeq << 20);
-  m_combinedSeqNo = m_combinedSeqNo | (m_nameLsaSeq << 40);
-}
-
-void
 SequencingManager::writeSeqNoToFile() const
 {
-  std::ofstream outputFile(m_seqFileNameWithPath.c_str(), ios::binary);
-  outputFile << m_combinedSeqNo;
+  writeLog();
+  std::ofstream outputFile(m_seqFileNameWithPath.c_str());
+  std::ostringstream os;
+  os << "NameLsaSeq " << std::to_string(m_nameLsaSeq) << "\n"
+     << "AdjLsaSeq "  << std::to_string(m_adjLsaSeq)  << "\n"
+     << "CorLsaSeq "  << std::to_string(m_corLsaSeq);
+  outputFile << os.str();
   outputFile.close();
 }
 
@@ -65,10 +53,40 @@
 SequencingManager::initiateSeqNoFromFile(int hypState)
 {
   _LOG_DEBUG("Seq File Name: " << m_seqFileNameWithPath);
-  std::ifstream inputFile(m_seqFileNameWithPath.c_str(), ios::binary);
+  std::ifstream inputFile(m_seqFileNameWithPath.c_str());
+
+  // Good checks that file is not (bad or eof or fail)
   if (inputFile.good()) {
-    inputFile >> m_combinedSeqNo;
-    splitSequenceNo(m_combinedSeqNo);
+    std::string lsaOrCombinedSeqNo;
+    uint64_t seqNo = 0;
+
+    // If file has a combined seq number, lsaOrCombinedSeqNo would hold it
+    // and seqNo will be zero everytime
+    inputFile >> lsaOrCombinedSeqNo >> seqNo;
+    m_nameLsaSeq = seqNo;
+
+    inputFile >> lsaOrCombinedSeqNo >> seqNo;
+    m_adjLsaSeq = seqNo;
+
+    inputFile >> lsaOrCombinedSeqNo >> seqNo;;
+    m_corLsaSeq = seqNo;
+
+    // File was in old format and had a combined sequence number
+    // if all of the seqNo should are still zero and
+    // lsaOrCombinedSeqNo != CorLsaSeq
+    if (m_nameLsaSeq == 0 && m_adjLsaSeq == 0 && m_corLsaSeq == 0 &&
+        lsaOrCombinedSeqNo != "CorLsaSeq") {
+      _LOG_DEBUG("Old file had combined sequence number: " << lsaOrCombinedSeqNo);
+      std::istringstream iss(lsaOrCombinedSeqNo);
+      iss >> seqNo;
+      m_adjLsaSeq = (seqNo & 0xFFFFF);
+      m_corLsaSeq = ((seqNo >> 20) & 0xFFFFF);
+      m_nameLsaSeq = ((seqNo >> 40) & 0xFFFFFF);
+    }
+
+    inputFile.close();
+
+    m_nameLsaSeq += 10;
 
     // Increment the adjacency LSA seq. no. if link-state or dry HR is enabled
     if (hypState != HYPERBOLIC_STATE_ON) {
@@ -82,43 +100,32 @@
 
     // Similarly, increment the coordinate LSA seq. no only if link-state is disabled.
     if (hypState != HYPERBOLIC_STATE_OFF) {
-      if (m_adjLsaSeq != 0 &&
-          hypState == HYPERBOLIC_STATE_ON) {
+      if (m_adjLsaSeq != 0) {
         _LOG_WARN("This router was previously configured for link-state"
                   << " routing without clearing the seq. no. file.");
         m_adjLsaSeq = 0;
       }
       m_corLsaSeq += 10;
     }
-    m_nameLsaSeq += 10;
-    combineSequenceNo();
-    inputFile.close();
   }
-  else {
-    splitSequenceNo(0);
-  }
+  writeLog();
 }
 
 void
-SequencingManager::setSeqFileName(string filePath)
+SequencingManager::setSeqFileDirectory(string filePath)
 {
   m_seqFileNameWithPath = filePath;
+
   if (m_seqFileNameWithPath.empty()) {
-    m_seqFileNameWithPath = getUserHomeDirectory();
+    string homeDirPath(getpwuid(getuid())->pw_dir);
+    if (homeDirPath.empty()) {
+      homeDirPath = getenv("HOME");
+    }
+    m_seqFileNameWithPath = homeDirPath;
   }
   m_seqFileNameWithPath = m_seqFileNameWithPath + "/nlsrSeqNo.txt";
 }
 
-string
-SequencingManager::getUserHomeDirectory()
-{
-  string homeDirPath(getpwuid(getuid())->pw_dir);
-  if (homeDirPath.empty()) {
-    homeDirPath = getenv("HOME");
-  }
-  return homeDirPath;
-}
-
 void
 SequencingManager::writeLog() const
 {
@@ -126,7 +133,6 @@
   _LOG_DEBUG("Adj LSA seq no: " << m_adjLsaSeq);
   _LOG_DEBUG("Cor LSA Seq no: " << m_corLsaSeq);
   _LOG_DEBUG("Name LSA Seq no: " << m_nameLsaSeq);
-  _LOG_DEBUG("Combined LSDB Seq no: " << m_combinedSeqNo);
 }
 
 } // namespace nlsr
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index ce06de8..188cea6 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -39,24 +39,10 @@
     : m_nameLsaSeq(0)
     , m_adjLsaSeq(0)
     , m_corLsaSeq(0)
-    , m_combinedSeqNo(0)
     , m_seqFileNameWithPath()
   {
   }
 
-  SequencingManager(uint64_t seqNo)
-  {
-    splitSequenceNo(seqNo);
-  }
-
-  SequencingManager(uint64_t nlsn, uint64_t alsn, uint64_t clsn)
-  {
-    m_nameLsaSeq = nlsn;
-    m_adjLsaSeq  = alsn;
-    m_corLsaSeq  = clsn;
-    combineSequenceNo();
-  }
-
   uint64_t
   getNameLsaSeq() const
   {
@@ -67,7 +53,6 @@
   setNameLsaSeq(uint64_t nlsn)
   {
     m_nameLsaSeq = nlsn;
-    combineSequenceNo();
   }
 
   uint64_t
@@ -80,7 +65,6 @@
   setAdjLsaSeq(uint64_t alsn)
   {
     m_adjLsaSeq = alsn;
-    combineSequenceNo();
   }
 
   uint64_t
@@ -93,34 +77,24 @@
   setCorLsaSeq(uint64_t clsn)
   {
     m_corLsaSeq = clsn;
-    combineSequenceNo();
   }
 
   void
   increaseNameLsaSeq()
   {
     m_nameLsaSeq++;
-    combineSequenceNo();
   }
 
   void
   increaseAdjLsaSeq()
   {
     m_adjLsaSeq++;
-    combineSequenceNo();
   }
 
   void
   increaseCorLsaSeq()
   {
     m_corLsaSeq++;
-    combineSequenceNo();
-  }
-
-  uint64_t
-  getCombinedSeqNo() const
-  {
-    return m_combinedSeqNo;
   }
 
   void
@@ -129,29 +103,24 @@
   void
   initiateSeqNoFromFile(int hypState);
 
-  void
-  setSeqFileName(std::string filePath);
+  /*! \brief Set the sequence file directory
 
-  std::string
-  getUserHomeDirectory();
+    If the string is empty, home directory is set as sequence file directory
+
+  \param filePath The directory where sequence file will be stored
+ */
+  void
+  setSeqFileDirectory(std::string filePath);
 
   void
   writeLog() const;
 
 private:
-  void
-  splitSequenceNo(uint64_t seqNo);
-
-  void
-  combineSequenceNo();
-
-private:
   uint64_t m_nameLsaSeq;
   uint64_t m_adjLsaSeq;
   uint64_t m_corLsaSeq;
-  uint64_t m_combinedSeqNo;
   std::string m_seqFileNameWithPath;
 };
 
 } // namespace nlsr
-#endif //NLSR_SEQUENCING_MANAGER_HPP
+#endif // NLSR_SEQUENCING_MANAGER_HPP
diff --git a/src/update/nfd-rib-command-processor.cpp b/src/update/nfd-rib-command-processor.cpp
index f4baeb5..e90503a 100644
--- a/src/update/nfd-rib-command-processor.cpp
+++ b/src/update/nfd-rib-command-processor.cpp
@@ -33,12 +33,10 @@
 
 NfdRibCommandProcessor::NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
                                                NamePrefixList& namePrefixes,
-                                               Lsdb& lsdb,
-                                               SyncLogicHandler& sync)
+                                               Lsdb& lsdb)
   : m_dispatcher(dispatcher)
   , m_namePrefixList(namePrefixes)
   , m_lsdb(lsdb)
-  , m_sync(sync)
 {
 }
 
@@ -96,7 +94,6 @@
 
   if (m_namePrefixList.insert(castParams.getName())) {
     m_lsdb.buildAndInstallOwnNameLsa();
-    m_sync.publishRoutingUpdate();
   }
 }
 
@@ -110,7 +107,6 @@
 
   if (m_namePrefixList.remove(castParams.getName())) {
     m_lsdb.buildAndInstallOwnNameLsa();
-    m_sync.publishRoutingUpdate();
   }
 }
 
diff --git a/src/update/nfd-rib-command-processor.hpp b/src/update/nfd-rib-command-processor.hpp
index a022b58..239d349 100644
--- a/src/update/nfd-rib-command-processor.hpp
+++ b/src/update/nfd-rib-command-processor.hpp
@@ -26,7 +26,6 @@
 #include "nfd-rib-commands.hpp"
 #include "name-prefix-list.hpp"
 #include "lsdb.hpp"
-#include "communication/sync-logic-handler.hpp"
 
 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
@@ -55,8 +54,7 @@
 public:
   NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
                          NamePrefixList& namePrefixes,
-                         Lsdb& lsdb,
-                         SyncLogicHandler& sync);
+                         Lsdb& lsdb);
 
   /*! \brief Registers an Interest filter with face
 
@@ -116,7 +114,6 @@
   ndn::mgmt::Dispatcher& m_dispatcher;
   NamePrefixList& m_namePrefixList;
   Lsdb& m_lsdb;
-  SyncLogicHandler& m_sync;
 };
 
 } // namespace update
diff --git a/src/update/prefix-update-processor.cpp b/src/update/prefix-update-processor.cpp
index e0c8f3b..ad1f9a6 100644
--- a/src/update/prefix-update-processor.cpp
+++ b/src/update/prefix-update-processor.cpp
@@ -24,7 +24,6 @@
 #include "lsdb.hpp"
 #include "nlsr.hpp"
 #include "prefix-update-commands.hpp"
-#include "communication/sync-logic-handler.hpp"
 
 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
 
@@ -40,7 +39,6 @@
 PrefixUpdateProcessor::PrefixUpdateProcessor(ndn::Face& face,
                                              NamePrefixList& namePrefixList,
                                              Lsdb& lsdb,
-                                             SyncLogicHandler& sync,
                                              const ndn::Name broadcastPrefix,
                                              ndn::KeyChain& keyChain,
                                              std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
@@ -48,7 +46,6 @@
   : m_face(face)
   , m_namePrefixList(namePrefixList)
   , m_lsdb(lsdb)
-  , m_sync(sync)
   , m_keyChain(keyChain)
   , m_validator(m_face, broadcastPrefix, certificateCache, certStore)
   , m_isEnabled(false)
@@ -153,7 +150,6 @@
   if (m_namePrefixList.insert(parameters.getName())) {
     // Only build a Name LSA if the added name is new
     m_lsdb.buildAndInstallOwnNameLsa();
-    m_sync.publishRoutingUpdate();
   }
 }
 
@@ -173,7 +169,6 @@
   if (m_namePrefixList.remove(parameters.getName())) {
     // Only build a Name LSA if a name was actually removed
     m_lsdb.buildAndInstallOwnNameLsa();
-    m_sync.publishRoutingUpdate();
   }
 }
 
diff --git a/src/update/prefix-update-processor.hpp b/src/update/prefix-update-processor.hpp
index 4f08bc7..f1a5b50 100644
--- a/src/update/prefix-update-processor.hpp
+++ b/src/update/prefix-update-processor.hpp
@@ -39,7 +39,6 @@
 namespace nlsr {
 
 class Lsdb;
-class SyncLogicHandler;
 
 namespace security {
   class CertificateStore;
@@ -66,7 +65,6 @@
   PrefixUpdateProcessor(ndn::Face& face,
                         NamePrefixList& namePrefixList,
                         Lsdb& lsdb,
-                        SyncLogicHandler& sync,
                         const ndn::Name broadcastPrefix,
                         ndn::KeyChain& keyChain,
                         std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
@@ -134,7 +132,6 @@
   ndn::Face& m_face;
   NamePrefixList& m_namePrefixList;
   Lsdb& m_lsdb;
-  SyncLogicHandler& m_sync;
   ndn::KeyChain& m_keyChain;
   Validator m_validator;
   bool m_isEnabled;
diff --git a/tests/publisher/publisher-fixture.hpp b/tests/publisher/publisher-fixture.hpp
index 477d7a7..eae6486 100644
--- a/tests/publisher/publisher-fixture.hpp
+++ b/tests/publisher/publisher-fixture.hpp
@@ -38,7 +38,7 @@
   PublisherFixture()
     : face(std::make_shared<ndn::util::DummyClientFace>())
     , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
-    , lsdb(nlsr, g_scheduler, nlsr.getSyncLogicHandler())
+    , lsdb(nlsr, g_scheduler)
   {
   }
 
diff --git a/tests/test-lsa-rule.cpp b/tests/test-lsa-rule.cpp
index d60d6a0..e7f6a69 100644
--- a/tests/test-lsa-rule.cpp
+++ b/tests/test-lsa-rule.cpp
@@ -174,7 +174,7 @@
   lsaInterestName.append(ndn::Name("name"));
 
   // This would be the sequence number of its own NameLsa
-  lsaInterestName.appendNumber(nlsr.getSequencingManager().getNameLsaSeq());
+  lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 
   // Append version, segmentNo
   lsaInterestName.appendNumber(1).appendNumber(1);
@@ -205,7 +205,7 @@
   lsaInterestName.append(ndn::Name("name"));
 
   // This would be the sequence number of its own NameLsa
-  lsaInterestName.appendNumber(nlsr.getSequencingManager().getNameLsaSeq());
+  lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 
   // Append version, segmentNo
   lsaInterestName.appendNumber(1).appendNumber(1);
diff --git a/tests/test-lsdb.cpp b/tests/test-lsdb.cpp
index 5d1613c..abd58d4 100644
--- a/tests/test-lsdb.cpp
+++ b/tests/test-lsdb.cpp
@@ -41,7 +41,7 @@
   LsdbFixture()
     : face(std::make_shared<ndn::util::DummyClientFace>(g_ioService))
     , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
-    , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter(), nlsr.getSequencingManager())
+    , sync(*face, nlsr.getLsdb(), nlsr.getConfParameter())
     , lsdb(nlsr.getLsdb())
     , conf(nlsr.getConfParameter())
     , REGISTER_COMMAND_PREFIX("/localhost/nfd/rib")
@@ -243,7 +243,7 @@
   //1800 is the default life time.
   NameLsa nlsa1(ndn::Name("/router1/1"), 12, testTimePoint, npl1);
 
-  Lsdb lsdb1(nlsr, g_scheduler, nlsr.getSyncLogicHandler());
+  Lsdb lsdb1(nlsr, g_scheduler);
 
   lsdb1.installNameLsa(nlsa1);
   lsdb1.writeNameLsdbLog();
diff --git a/tests/test-nlsr.cpp b/tests/test-nlsr.cpp
index 3553a43..3760289 100644
--- a/tests/test-nlsr.cpp
+++ b/tests/test-nlsr.cpp
@@ -190,7 +190,7 @@
   BOOST_REQUIRE(lsa != nullptr);
 
   uint32_t lastAdjLsaSeqNo = lsa->getLsSeqNo();
-  nlsr.getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo);
+  nlsr.getLsdb().getSequencingManager().setAdjLsaSeq(lastAdjLsaSeqNo);
 
   // Make sure the routing table was calculated
   RoutingTableEntry* rtEntry = nlsr.getRoutingTable().findRoutingTableEntry(failNeighbor.getName());
diff --git a/tests/test-sequencing-manager.cpp b/tests/test-sequencing-manager.cpp
index 186e7df..e05597f 100644
--- a/tests/test-sequencing-manager.cpp
+++ b/tests/test-sequencing-manager.cpp
@@ -19,40 +19,103 @@
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  **/
 
+#include "test-common.hpp"
 #include "sequencing-manager.hpp"
 #include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
+#include <string>
+#include <iostream>
+#include <fstream>
+
+using namespace ndn;
 
 namespace nlsr {
 
 namespace test {
 
-BOOST_AUTO_TEST_SUITE(TestSequencingManager)
-
-BOOST_AUTO_TEST_CASE(SequencingManagerBasic)
+class SequencingManagerFixture : public BaseFixture
 {
-  SequencingManager sm1(120, 121, 122);
+public:
+  SequencingManagerFixture()
+  : m_seqNumbers("")
+  , m_seqManager()
+  {
+    setFileDir();
+  }
 
-  SequencingManager sm2(sm1.getCombinedSeqNo());
+  ~SequencingManagerFixture()
+  {
+    boost::filesystem::remove(seqFile);
+  }
 
-  BOOST_CHECK_EQUAL(sm2.getNameLsaSeq(), (uint32_t)120);
+  void
+  setFileDir() {
+    m_seqManager.setSeqFileDirectory("/tmp");
+  }
 
-  BOOST_CHECK_EQUAL(sm2.getAdjLsaSeq(), (uint32_t)121);
+  void
+  writeToFile(const std::string& testSeq) {
+    std::ofstream outputFile(seqFile, std::ofstream::trunc);
+    outputFile << testSeq;
+    outputFile.close();
+  }
 
-  BOOST_CHECK_EQUAL(sm2.getCorLsaSeq(), (uint32_t)122);
+  void
+  initiateFromFile(const int& type) {
+    m_seqManager.initiateSeqNoFromFile(type);
+  }
+
+  void
+  checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) {
+    BOOST_CHECK_EQUAL(m_seqManager.getNameLsaSeq(), name);
+
+    BOOST_CHECK_EQUAL(m_seqManager.getAdjLsaSeq(), adj);
+
+    BOOST_CHECK_EQUAL(m_seqManager.getCorLsaSeq(), cor);
+  }
+
+private:
+  std::string m_seqNumbers;
+  std::string seqFile = "/tmp/nlsrSeqNo.txt";
+  SequencingManager m_seqManager;
+};
+
+BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture)
+
+BOOST_AUTO_TEST_CASE(CombinedSeqNumber)
+{
+  // LS
+  writeToFile("27121653322350672");
+
+  initiateFromFile(HYPERBOLIC_STATE_OFF);
+
+  checkSeqNumbers(24667+10, 80+10, 0);
+
+  // HR
+  writeToFile("27121653322350672");
+
+  initiateFromFile(HYPERBOLIC_STATE_ON);
+
+  // AdjLsa is set to 0 since HR is on
+  checkSeqNumbers(24667+10, 0, 0+10);
 }
 
-BOOST_AUTO_TEST_CASE(BitMask)
+BOOST_AUTO_TEST_CASE(SeparateSeqNumber)
 {
-  uint64_t nameLsaSeqNoMax = 0xFFFFFF;
-  uint64_t corLsaSeqNoMax = 0xFFFFF;
-  uint64_t adjLsaSeqNoMax = 0xFFFFF;
+  // LS
+  writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0");
 
-  uint64_t seqNo = (nameLsaSeqNoMax << 40) | (corLsaSeqNoMax << 20) | adjLsaSeqNoMax;
-  SequencingManager manager(seqNo);
+  initiateFromFile(HYPERBOLIC_STATE_OFF);
 
-  BOOST_CHECK_EQUAL(manager.getNameLsaSeq(), nameLsaSeqNoMax);
-  BOOST_CHECK_EQUAL(manager.getCorLsaSeq(), corLsaSeqNoMax);
-  BOOST_CHECK_EQUAL(manager.getAdjLsaSeq(), adjLsaSeqNoMax);
+  checkSeqNumbers(100+10, 100+10, 0);
+
+  // HR
+  writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100");
+
+  initiateFromFile(HYPERBOLIC_STATE_ON);
+
+  // AdjLsa is set to 0 since HR is on
+  checkSeqNumbers(100+10, 0, 100+10);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test-sync-logic-handler.cpp b/tests/test-sync-logic-handler.cpp
index ef990cf..ea23571 100644
--- a/tests/test-sync-logic-handler.cpp
+++ b/tests/test-sync-logic-handler.cpp
@@ -37,7 +37,7 @@
   SyncLogicFixture()
     : face(std::make_shared<ndn::util::DummyClientFace>())
     , nlsr(g_ioService, g_scheduler, std::ref(*face), g_keyChain)
-    , sync(nlsr.getSyncLogicHandler())
+    , sync(nlsr.getLsdb().getSyncLogicHandler())
     , CONFIG_NETWORK("/ndn")
     , CONFIG_SITE("/site")
     , CONFIG_ROUTER_NAME("/%C1.Router/this-router")
@@ -72,34 +72,38 @@
   const std::string CONFIG_NETWORK;
   const std::string CONFIG_SITE;
   const std::string CONFIG_ROUTER_NAME;
+  const std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING,
+                                             CoordinateLsa::TYPE_STRING};
 };
 
 BOOST_FIXTURE_TEST_SUITE(TestSyncLogicHandler, SyncLogicFixture)
 
 BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
 {
-  std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_SITE + "/%C1.Router/other-router/";
+  std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, AdjLsa::TYPE_STRING};
 
   uint64_t syncSeqNo = 1;
-  receiveUpdate(updateName, syncSeqNo, sync);
 
-  std::vector<ndn::Interest>& interests = face->sentInterests;
+  for (const std::string& lsaType : lsaTypes) {
+    std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
+                             CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
 
-  std::vector<ndn::Interest>::iterator it = interests.begin();
+    receiveUpdate(updateName, syncSeqNo, sync);
 
-  BOOST_REQUIRE_EQUAL(interests.size(), 2);
+    std::vector<ndn::Interest>& interests = face->sentInterests;
 
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
+    std::vector<ndn::Interest>::iterator it = interests.begin();
 
-  ++it;
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
+    BOOST_REQUIRE_EQUAL(interests.size(), 1);
+
+    BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
+  }
 }
 
 BOOST_AUTO_TEST_CASE(UpdateForOtherHR)
 {
   Nlsr nlsr_hr(g_ioService, g_scheduler, std::ref(*face), g_keyChain);
-  SyncLogicHandler& sync_hr(nlsr_hr.getSyncLogicHandler());
+  SyncLogicHandler& sync_hr(nlsr_hr.getLsdb().getSyncLogicHandler());
 
   nlsr_hr.getConfParameter().setNetwork(CONFIG_NETWORK);
   nlsr_hr.getConfParameter().setSiteName(CONFIG_SITE);
@@ -110,30 +114,30 @@
 
   nlsr_hr.initialize();
 
-  std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_SITE + "/%C1.Router/other-router/";
+  uint64_t syncSeqNo = 1;
 
-  uint64_t syncSeqNo = 0;
-  syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
+  std::vector<std::string> lsaTypes = {NameLsa::TYPE_STRING, CoordinateLsa::TYPE_STRING};
 
-  receiveUpdate(updateName, syncSeqNo, sync_hr);
+  for (const std::string& lsaType : lsaTypes) {
+    std::string updateName = nlsr_hr.getConfParameter().getLsaPrefix().toUri() +
+                           CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
 
-  std::vector<ndn::Interest>& interests = face->sentInterests;
-  std::vector<ndn::Interest>::iterator it = interests.begin();
+    receiveUpdate(updateName, syncSeqNo, sync_hr);
 
-  BOOST_REQUIRE_EQUAL(interests.size(), 2);
+    std::vector<ndn::Interest>& interests = face->sentInterests;
+    std::vector<ndn::Interest>::iterator it = interests.begin();
 
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
+    BOOST_REQUIRE_EQUAL(interests.size(), 1);
 
-  ++it;
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
+    BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
+  }
 }
 
 BOOST_AUTO_TEST_CASE(UpdateForOtherHRDry)
 {
 
   Nlsr nlsr_hrdry(g_ioService, g_scheduler, std::ref(*face),g_keyChain);
-  SyncLogicHandler& sync_hrdry(nlsr_hrdry.getSyncLogicHandler());
+  SyncLogicHandler& sync_hrdry(nlsr_hrdry.getLsdb().getSyncLogicHandler());
 
   nlsr_hrdry.getConfParameter().setNetwork(CONFIG_NETWORK);
   nlsr_hrdry.getConfParameter().setSiteName(CONFIG_SITE);
@@ -144,56 +148,50 @@
 
   nlsr_hrdry.initialize();
 
-  std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_SITE + "/%C1.Router/other-router/";
+  for (const std::string& lsaType : lsaTypes) {
+
+    std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
+                 CONFIG_SITE + "/%C1.Router/other-router/" + lsaType;
 
 
-  uint64_t syncSeqNo = 1;
-  syncSeqNo = syncSeqNo | (static_cast<uint64_t>(1) << 20);
-  receiveUpdate(updateName, syncSeqNo, sync_hrdry);
+    uint64_t syncSeqNo = 1;
 
-  std::vector<ndn::Interest>& interests = face->sentInterests;
-  std::vector<ndn::Interest>::iterator it = interests.begin();
+    receiveUpdate(updateName, syncSeqNo, sync_hrdry);
 
-  BOOST_REQUIRE_EQUAL(interests.size(), 3);
+    std::vector<ndn::Interest>& interests = face->sentInterests;
 
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + NameLsa::TYPE_STRING + "/");
+    std::vector<ndn::Interest>::iterator it = interests.begin();
 
-  if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-      ++it;
-      BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
-  }
-  else if (nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
-      ++it;
-      BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
-  }
-  else {
-      ++it;
-      BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + CoordinateLsa::TYPE_STRING + "/");
-
-      ++it;
-      BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + AdjLsa::TYPE_STRING + "/");
+    // In HR dry-state all LSA's should be published
+    BOOST_REQUIRE_EQUAL(interests.size(), 1);
+    BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
   }
 }
 
+
 BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
 {
-  std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_SITE + CONFIG_ROUTER_NAME;
+  for (const std::string& lsaType : lsaTypes) {
+    std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
+                             CONFIG_SITE + CONFIG_ROUTER_NAME + lsaType;
 
-  receiveUpdate(updateName, 1, sync);
+    receiveUpdate(updateName, 1, sync);
 
-  std::vector<ndn::Interest>& interests = face->sentInterests;
-  BOOST_CHECK_EQUAL(interests.size(), 0);
+    std::vector<ndn::Interest>& interests = face->sentInterests;
+    BOOST_CHECK_EQUAL(interests.size(), 0);
+  }
 }
 
+
 BOOST_AUTO_TEST_CASE(MalformedUpdate)
 {
-  std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_ROUTER_NAME;
+  for (const std::string& lsaType : lsaTypes) {
+    std::string updateName = CONFIG_SITE + nlsr.getConfParameter().getLsaPrefix().toUri() +
+                             CONFIG_ROUTER_NAME + lsaType;
 
-  std::vector<ndn::Interest>& interests = face->sentInterests;
-  BOOST_CHECK_EQUAL(interests.size(), 0);
+    std::vector<ndn::Interest>& interests = face->sentInterests;
+    BOOST_CHECK_EQUAL(interests.size(), 0);
+  }
 }
 
 BOOST_AUTO_TEST_CASE(SequenceNumber)
@@ -219,31 +217,31 @@
   lsdb.installCoordinateLsa(corLsa);
 
   std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
-                           CONFIG_SITE + "/%C1.Router/other-router/";
+                           CONFIG_SITE + "/%C1.Router/other-router/" + NameLsa::TYPE_STRING;
 
   // Lower NameLSA sequence number
-  uint64_t lowerSeqNo = static_cast<uint64_t>(998) << 40;
+  uint64_t lowerSeqNo = 998;
   receiveUpdate(updateName, lowerSeqNo, sync);
 
   std::vector<ndn::Interest>& interests = face->sentInterests;
   BOOST_REQUIRE_EQUAL(interests.size(), 0);
 
   // Same NameLSA sequence number
-  uint64_t sameSeqNo = static_cast<uint64_t>(999) << 40;
+  uint64_t sameSeqNo = 999;
   receiveUpdate(updateName, sameSeqNo, sync);
 
   interests = face->sentInterests;
   BOOST_REQUIRE_EQUAL(interests.size(), 0);
 
   // Higher NameLSA sequence number
-  uint64_t higherSeqNo = static_cast<uint64_t>(1000) << 40;
+  uint64_t higherSeqNo = 1000;
   receiveUpdate(updateName, higherSeqNo, sync);
 
   interests = face->sentInterests;
   BOOST_REQUIRE_EQUAL(interests.size(), 1);
 
   std::vector<ndn::Interest>::iterator it = interests.begin();
-  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "name/");
+  BOOST_CHECK_EQUAL(it->getName().getPrefix(-1), updateName + "/");
 }
 
 BOOST_AUTO_TEST_CASE(UpdatePrefix)
@@ -254,7 +252,9 @@
 
   nlsr.initialize();
 
-  BOOST_CHECK_EQUAL(sync.m_updatePrefix, expectedPrefix);
+  BOOST_CHECK_EQUAL(sync.m_nameLsaUserPrefix, ndn::Name(expectedPrefix).append(NameLsa::TYPE_STRING));
+  BOOST_CHECK_EQUAL(sync.m_adjLsaUserPrefix, ndn::Name(expectedPrefix).append(AdjLsa::TYPE_STRING));
+  BOOST_CHECK_EQUAL(sync.m_coorLsaUserPrefix, ndn::Name(expectedPrefix).append(CoordinateLsa::TYPE_STRING));
 }
 
 BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
@@ -267,7 +267,7 @@
   BOOST_REQUIRE(lsa == nullptr);
 
   // Publish a routing update before an Adjacency LSA is built
-  BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate());
+  BOOST_CHECK_NO_THROW(sync.publishRoutingUpdate(AdjLsa::TYPE_STRING, 0));
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/update/test-nfd-rib-command-processor.cpp b/tests/update/test-nfd-rib-command-processor.cpp
index 3c0ae47..81b66ce 100644
--- a/tests/update/test-nfd-rib-command-processor.cpp
+++ b/tests/update/test-nfd-rib-command-processor.cpp
@@ -56,6 +56,8 @@
 
     this->advanceClocks(ndn::time::milliseconds(10));
     face.sentInterests.clear();
+
+    nameLsaSeqNoBeforeInterest = nlsr.getLsdb().getSequencingManager().getNameLsaSeq();
   }
 
   std::shared_ptr<ndn::Interest>
@@ -73,9 +75,11 @@
     // no longer does face->put(*data) in publishData.
     // Instead it does it in onInterest
     ndn::Name lsaInterestName("/localhop/ndn/NLSR/LSA");
+    lsaInterestName.append(NameLsa::TYPE_STRING);
+
     // The part after LSA is Chronosync getSession
     lsaInterestName.append(sessionTime);
-    lsaInterestName.appendNumber(nlsr.getSequencingManager().getCombinedSeqNo());
+    lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
     shared_ptr<ndn::Interest> lsaInterest = make_shared<ndn::Interest>(lsaInterestName);
 
     face.receive(*lsaInterest);
@@ -89,7 +93,7 @@
     const ndn::Name& lsaPrefix = nlsr.getConfParameter().getLsaPrefix();
 
     const auto& it = std::find_if(face.sentData.begin(), face.sentData.end(),
-      [lsaPrefix] (const ndn::Data& data) {
+      [&] (const ndn::Data& data) {
         return lsaPrefix.isPrefixOf(data.getName());
       });
 
@@ -104,6 +108,7 @@
   NamePrefixList& namePrefixes;
   NfdRibCommandProcessor& processor;
   ndn::Name sessionTime;
+  uint64_t nameLsaSeqNoBeforeInterest;
 };
 
 typedef boost::mpl::vector<NfdRibRegisterCommand, NfdRibUnregisterCommand> Commands;
@@ -150,6 +155,7 @@
   }
   BOOST_CHECK_EQUAL((*itr), parameters.getName());
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_CASE(RemovePrefix)
@@ -170,6 +176,7 @@
     BOOST_FAIL("Prefix was not removed!");
   }
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_CASE(onReceiveInterestRegisterCommand)
@@ -192,6 +199,7 @@
   }
   BOOST_CHECK_EQUAL((*itr), prefixName);
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_CASE(onReceiveInterestUnregisterCommand)
@@ -210,6 +218,7 @@
 
   BOOST_CHECK_EQUAL(namePrefixes.getNameList().size(), 0);
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_CASE(onReceiveInterestInvalidPrefix)
@@ -225,7 +234,10 @@
   this->advanceClocks(ndn::time::milliseconds(10));
 
   BOOST_CHECK_EQUAL(namePrefixes.getNameList().size(), 0);
-  BOOST_CHECK(!wasRoutingUpdatePublished());
+
+  // Cannot use routingUpdatePublish test now since in
+  // initialize nlsr calls buildOwnNameLsa which publishes the routing update
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest == nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/update/test-prefix-update-processor.cpp b/tests/update/test-prefix-update-processor.cpp
index 169fc48..efb24a0 100644
--- a/tests/update/test-prefix-update-processor.cpp
+++ b/tests/update/test-prefix-update-processor.cpp
@@ -161,9 +161,12 @@
     // no longer does face->put(*data) in publishData.
     // Instead it does it in onInterest
     ndn::Name lsaInterestName("/localhop/ndn/NLSR/LSA");
+    lsaInterestName.append(NameLsa::TYPE_STRING);
+
     // The part after LSA is Chronosync getSession
     lsaInterestName.append(sessionTime);
-    lsaInterestName.appendNumber(nlsr.getSequencingManager().getCombinedSeqNo());
+    lsaInterestName.appendNumber(nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
+
     shared_ptr<Interest> lsaInterest = make_shared<Interest>(lsaInterestName);
 
     face.receive(*lsaInterest);
@@ -231,6 +234,7 @@
 
 BOOST_AUTO_TEST_CASE(Basic)
 {
+  uint64_t nameLsaSeqNoBeforeInterest = nlsr.getLsdb().getSequencingManager().getNameLsaSeq();
   updateProcessor.enable();
 
   // Advertise
@@ -252,8 +256,10 @@
   BOOST_CHECK_EQUAL(namePrefixList.getNameList().front(), parameters.getName());
 
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 
   face.sentData.clear();
+  nameLsaSeqNoBeforeInterest = nlsr.getLsdb().getSequencingManager().getNameLsaSeq();
 
   // Withdraw
   ndn::Name withdrawCommand("/localhost/nlsr/prefix-update/withdraw");
@@ -268,6 +274,7 @@
   BOOST_CHECK_EQUAL(namePrefixList.getSize(), 0);
 
   BOOST_CHECK(wasRoutingUpdatePublished());
+  BOOST_CHECK(nameLsaSeqNoBeforeInterest < nlsr.getLsdb().getSequencingManager().getNameLsaSeq());
 }
 
 BOOST_AUTO_TEST_CASE(DisabledAndEnabled)