src: ConfParameter variables should be consistent with their min and max values

refs: #2084

Change-Id: Iae71da80ae47fca44ec46f4a3f0d4d86c77e5094
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 1b5dc61..21940d6 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -256,7 +256,7 @@
   }
 
   // lsa-refresh-time
-  int32_t lsaRefreshTime = section.get<int32_t>("lsa-refresh-time", LSA_REFRESH_TIME_DEFAULT);
+  uint32_t lsaRefreshTime = section.get<uint32_t>("lsa-refresh-time", LSA_REFRESH_TIME_DEFAULT);
 
   if (lsaRefreshTime >= LSA_REFRESH_TIME_MIN && lsaRefreshTime <= LSA_REFRESH_TIME_MAX) {
     m_nlsr.getConfParameter().setLsaRefreshTime(lsaRefreshTime);
@@ -270,7 +270,7 @@
   }
 
   // router-dead-interval
-  int32_t routerDeadInterval = section.get<int32_t>("router-dead-interval", (2*lsaRefreshTime));
+  uint32_t routerDeadInterval = section.get<uint32_t>("router-dead-interval", (2*lsaRefreshTime));
 
   if (routerDeadInterval > m_nlsr.getConfParameter().getLsaRefreshTime()) {
     m_nlsr.getConfParameter().setRouterDeadInterval(routerDeadInterval);
@@ -422,7 +422,7 @@
   }
 
   // hello-timeout
-  int timeOut = section.get<int>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
+  uint32_t timeOut = section.get<uint32_t>("hello-timeout", HELLO_TIMEOUT_DEFAULT);
 
   if (timeOut >= HELLO_TIMEOUT_MIN && timeOut <= HELLO_TIMEOUT_MAX) {
     m_nlsr.getConfParameter().setInterestResendTime(timeOut);
@@ -436,7 +436,7 @@
   }
 
   // hello-interval
-  int interval = section.get<int>("hello-interval", HELLO_INTERVAL_DEFAULT);
+  uint32_t interval = section.get<uint32_t>("hello-interval", HELLO_INTERVAL_DEFAULT);
 
   if (interval >= HELLO_INTERVAL_MIN && interval <= HELLO_INTERVAL_MAX) {
     m_nlsr.getConfParameter().setInfoInterestInterval(interval);
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 4edf33e..9c227de 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -188,12 +188,12 @@
   }
 
   void
-  setLsaRefreshTime(int32_t lrt)
+  setLsaRefreshTime(uint32_t lrt)
   {
     m_lsaRefreshTime = lrt;
   }
 
-  int32_t
+  uint32_t
   getLsaRefreshTime() const
   {
     return m_lsaRefreshTime;
@@ -248,12 +248,12 @@
   }
 
   void
-  setRouterDeadInterval(int32_t rdt)
+  setRouterDeadInterval(uint32_t rdt)
   {
     m_routerDeadInterval = rdt;
   }
 
-  int32_t
+  uint32_t
   getRouterDeadInterval() const
   {
     return m_routerDeadInterval;
@@ -284,25 +284,25 @@
   }
 
   void
-  setInterestResendTime(int32_t irt)
+  setInterestResendTime(uint32_t irt)
   {
     m_interestResendTime = irt;
   }
 
-  int32_t
+  uint32_t
   getInterestResendTime() const
   {
     return m_interestResendTime;
   }
 
-  int32_t
+  uint32_t
   getInfoInterestInterval() const
   {
     return m_infoInterestInterval;
   }
 
   void
-  setInfoInterestInterval(int32_t iii)
+  setInfoInterestInterval(uint32_t iii)
   {
     m_infoInterestInterval = iii;
   }
@@ -416,20 +416,20 @@
   ndn::Name m_chronosyncPrefix;
   ndn::Name m_lsaPrefix;
 
-  int32_t  m_lsaRefreshTime;
+  uint32_t  m_lsaRefreshTime;
 
   uint32_t m_adjLsaBuildInterval;
   uint32_t m_firstHelloInterval;
   uint32_t m_routingCalcInterval;
 
   ndn::time::seconds m_lsaInterestLifetime;
-  int32_t  m_routerDeadInterval;
+  uint32_t  m_routerDeadInterval;
   std::string m_logLevel;
 
   uint32_t m_interestRetryNumber;
-  int32_t  m_interestResendTime;
+  uint32_t m_interestResendTime;
 
-  int32_t  m_infoInterestInterval;
+  uint32_t m_infoInterestInterval;
 
   int32_t m_hyperbolicState;
   double m_corR;
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index a86a965..817f149 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -382,7 +382,7 @@
 
   ConfParameter& conf = nlsr.getConfParameter();
 
-  BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<int32_t>(LSA_REFRESH_TIME_DEFAULT));
+  BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
                     static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime()));
@@ -403,8 +403,8 @@
   ConfParameter& conf = nlsr.getConfParameter();
 
   BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
-  BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<int32_t>(HELLO_TIMEOUT_DEFAULT));
-  BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<int32_t>(HELLO_INTERVAL_DEFAULT));
+  BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
+  BOOST_CHECK_EQUAL(conf.getInfoInterestInterval(), static_cast<uint32_t>(HELLO_INTERVAL_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getFirstHelloInterval(),
                     static_cast<uint32_t>(FIRST_HELLO_INTERVAL_DEFAULT));
   BOOST_CHECK_EQUAL(conf.getAdjLsaBuildInterval(),
@@ -454,6 +454,23 @@
   BOOST_CHECK_EQUAL(processConfigurationString(SECTION_FIB_OUT_OF_RANGE), false);
 }
 
+BOOST_AUTO_TEST_CASE(NegativeValue)
+{
+  const std::string SECTION_GENERAL_NEGATIVE_VALUE =
+  "general\n"
+  "{\n"
+  "  network /ndn/\n"
+  "  site /memphis.edu/\n"
+  "  router /cs/pollux/\n"
+  "  lsa-refresh-time -1800\n"
+  "  lsa-interest-lifetime -3\n"
+  "  router-dead-interval -86400\n"
+  "}\n\n";
+
+  // Processing should fail due to negative value
+  BOOST_CHECK_EQUAL(processConfigurationString(SECTION_GENERAL_NEGATIVE_VALUE), false);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } //namespace test