sequencing-manager: remove support for old combined seq no file

refs: #4143

Change-Id: I3334ef136f75b18225828ebfba17f63c468708db
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index bae9e68..c7c6c7e 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -34,11 +34,8 @@
 
 INIT_LOGGER(SequencingManager);
 
-SequencingManager::SequencingManager(std::string filePath, int hypState)
-  : m_nameLsaSeq(0)
-  , m_adjLsaSeq(0)
-  , m_corLsaSeq(0)
-  , m_hyperbolicState(hypState)
+SequencingManager::SequencingManager(const std::string& filePath, int hypState)
+  : m_hyperbolicState(hypState)
 {
   setSeqFileDirectory(filePath);
   initiateSeqNoFromFile();
@@ -63,44 +60,24 @@
   NLSR_LOG_DEBUG("Seq File Name: " << m_seqFileNameWithPath);
   std::ifstream inputFile(m_seqFileNameWithPath.c_str());
 
+  std::string seqType;
   // Good checks that file is not (bad or eof or fail)
   if (inputFile.good()) {
-    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") {
-      NLSR_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 >> seqType >> m_nameLsaSeq;
+    inputFile >> seqType >> m_adjLsaSeq;
+    inputFile >> seqType >> m_corLsaSeq;
 
     inputFile.close();
 
+    // Increment by 10 in case last run of NLSR was not able to write to file
+    // before crashing
     m_nameLsaSeq += 10;
 
     // Increment the adjacency LSA seq. no. if link-state or dry HR is enabled
     if (m_hyperbolicState != HYPERBOLIC_STATE_ON) {
       if (m_corLsaSeq != 0) {
-        NLSR_LOG_WARN("This router was previously configured for hyperbolic"
-                   << " routing without clearing the seq. no. file.");
+        NLSR_LOG_WARN("This router was previously configured for hyperbolic " <<
+                      "routing without clearing the seq. no. file.");
         m_corLsaSeq = 0;
       }
       m_adjLsaSeq += 10;
@@ -109,8 +86,8 @@
     // Similarly, increment the coordinate LSA seq. no only if link-state is disabled.
     if (m_hyperbolicState != HYPERBOLIC_STATE_OFF) {
       if (m_adjLsaSeq != 0) {
-        NLSR_LOG_WARN("This router was previously configured for link-state"
-                  << " routing without clearing the seq. no. file.");
+        NLSR_LOG_WARN("This router was previously configured for link-state " <<
+                      "routing without clearing the seq. no. file.");
         m_adjLsaSeq = 0;
       }
       m_corLsaSeq += 10;
@@ -137,7 +114,6 @@
 void
 SequencingManager::writeLog() const
 {
-  NLSR_LOG_DEBUG("----SequencingManager----");
   if (m_hyperbolicState == HYPERBOLIC_STATE_OFF ||
       m_hyperbolicState == HYPERBOLIC_STATE_DRY_RUN) {
     NLSR_LOG_DEBUG("Adj LSA seq no: " << m_adjLsaSeq);
diff --git a/src/sequencing-manager.hpp b/src/sequencing-manager.hpp
index 85e323b..307aab5 100644
--- a/src/sequencing-manager.hpp
+++ b/src/sequencing-manager.hpp
@@ -36,7 +36,7 @@
 class SequencingManager
 {
 public:
-  SequencingManager(std::string filePath, int hypState);
+  SequencingManager(const std::string& filePath, int hypState);
 
   uint64_t
   getNameLsaSeq() const
@@ -113,9 +113,9 @@
   writeLog() const;
 
 private:
-  uint64_t m_nameLsaSeq;
-  uint64_t m_adjLsaSeq;
-  uint64_t m_corLsaSeq;
+  uint64_t m_nameLsaSeq = 0;
+  uint64_t m_adjLsaSeq = 0;
+  uint64_t m_corLsaSeq = 0;
   std::string m_seqFileNameWithPath;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
diff --git a/tests/test-sequencing-manager.cpp b/tests/test-sequencing-manager.cpp
index d1c928b..6bbcb00 100644
--- a/tests/test-sequencing-manager.cpp
+++ b/tests/test-sequencing-manager.cpp
@@ -46,23 +46,24 @@
   }
 
   void
-  writeToFile(const std::string& testSeq) {
+  writeToFile(const std::string& testSeq)
+  {
     std::ofstream outputFile(seqFile, std::ofstream::trunc);
     outputFile << testSeq;
     outputFile.close();
   }
 
   void
-  initiateFromFile() {
+  initiateFromFile()
+  {
     m_seqManager.initiateSeqNoFromFile();
   }
 
   void
-  checkSeqNumbers(const uint64_t& name, const uint64_t& adj, const uint64_t& cor) {
+  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);
   }
 
@@ -73,36 +74,30 @@
 
 BOOST_FIXTURE_TEST_SUITE(TestSequencingManager, SequencingManagerFixture)
 
-BOOST_AUTO_TEST_CASE(CombinedSeqNumber)
-{
-  // LS
-  writeToFile("27121653322350672");
-  m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF;
-  initiateFromFile();
-  checkSeqNumbers(24667+10, 80+10, 0);
-
-  // HR
-  writeToFile("27121653322350672");
-  m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON;
-  initiateFromFile();
-  // AdjLsa is set to 0 since HR is on
-  checkSeqNumbers(24667+10, 0, 0+10);
-}
-
 BOOST_AUTO_TEST_CASE(SeparateSeqNumber)
 {
+  initiateFromFile();
+  checkSeqNumbers(0, 0, 0);
+
   // LS
   writeToFile("NameLsaSeq 100\nAdjLsaSeq 100\nCorLsaSeq 0");
   m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_OFF;
   initiateFromFile();
-  checkSeqNumbers(100+10, 100+10, 0);
+  checkSeqNumbers(100 + 10, 100 + 10, 0);
 
   // HR
   writeToFile("NameLsa 100\nAdjLsa 0\nCorLsa 100");
   m_seqManager.m_hyperbolicState = HYPERBOLIC_STATE_ON;
   initiateFromFile();
   // AdjLsa is set to 0 since HR is on
-  checkSeqNumbers(100+10, 0, 100+10);
+  checkSeqNumbers(100 + 10, 0, 100 + 10);
+}
+
+BOOST_AUTO_TEST_CASE(CorruptFile)
+{
+  writeToFile("NameLsaSeq");
+  initiateFromFile();
+  checkSeqNumbers(10, 10, 0);
 }
 
 BOOST_AUTO_TEST_SUITE_END()