conf: make ChronoSync's sync interest lifetime configurable
refs: #4490
Change-Id: Id3eabeed1049d1208ba49c47206f73f798f37a35
diff --git a/nlsr.conf b/nlsr.conf
index d5421ed..3f01975 100644
--- a/nlsr.conf
+++ b/nlsr.conf
@@ -19,6 +19,9 @@
; InterestLifetime (in seconds) for LSA fetching
lsa-interest-lifetime 4 ; default value 4. Valid values 1-60
+ ; sync interest lifetime of ChronoSync in milliseconds
+ sync-interest-lifetime 60000 ; default value 60000. Valid values 1000-120,000
+
seq-dir /var/lib/nlsr ; path for sequence directory (Absolute path)
}
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 6b392af..6257be5 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -53,7 +53,7 @@
}
void
-SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix)
+SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix, const ndn::time::milliseconds& syncInterestLifetime)
{
if (m_syncSocket != nullptr) {
NLSR_LOG_WARN("Trying to create Sync socket, but Sync socket already exists");
@@ -72,7 +72,9 @@
std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
- std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1));
+ std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1),
+ chronosync::Socket::DEFAULT_NAME, chronosync::Socket::DEFAULT_VALIDATOR,
+ syncInterestLifetime);
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
m_syncSocket->addSyncNode(m_adjLsaUserPrefix);
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 46bb18f..f4bd31a 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -22,6 +22,7 @@
#ifndef NLSR_SYNC_LOGIC_HANDLER_HPP
#define NLSR_SYNC_LOGIC_HANDLER_HPP
+#include "conf-parameter.hpp"
#include "test-access-control.hpp"
#include "signals.hpp"
#include "lsa.hpp"
@@ -90,10 +91,13 @@
*
* In a typical situation this only needs to be called once, when NLSR starts.
* \param syncPrefix The sync prefix you want this ChronoSync to use
+ * \param syncInterestLifetime ChronoSync sends a periodic sync interest every \p syncInterestLifetime / 2 ms
* \sa Nlsr::initialize
*/
void
- createSyncSocket(const ndn::Name& syncPrefix);
+ createSyncSocket(const ndn::Name& syncPrefix,
+ const ndn::time::milliseconds& syncInterestLifetime =
+ ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Simple function to glue Name components together
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index e93ef35..d388221 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -287,6 +287,19 @@
return false;
}
+ uint32_t syncInterestLifetime = section.get<uint32_t>("sync-interest-lifetime", SYNC_INTEREST_LIFETIME_DEFAULT);
+ if (syncInterestLifetime >= SYNC_INTEREST_LIFETIME_MIN &&
+ syncInterestLifetime <= SYNC_INTEREST_LIFETIME_MAX) {
+ m_nlsr.getConfParameter().setSyncInterestLifetime(syncInterestLifetime);
+ }
+ else {
+ std::cerr << "Wrong value for sync-interest-lifetime. "
+ << "Allowed value:" << SYNC_INTEREST_LIFETIME_MIN << "-"
+ << SYNC_INTEREST_LIFETIME_MAX << std::endl;
+
+ return false;
+ }
+
try {
std::string seqDir = section.get<std::string>("seq-dir");
if (boost::filesystem::exists(seqDir)) {
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index ee22764..ac32e04 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -106,6 +106,12 @@
HYPERBOLIC_STATE_DEFAULT = 0
};
+enum {
+ SYNC_INTEREST_LIFETIME_MIN = 1000,
+ SYNC_INTEREST_LIFETIME_DEFAULT = 60000,
+ SYNC_INTEREST_LIFETIME_MAX = 120000,
+};
+
/*! \brief A class to house all the configuration parameters for NLSR.
*
* This class is conceptually a singleton (but not mechanically) which
@@ -421,6 +427,18 @@
}
void
+ setSyncInterestLifetime(uint32_t syncInterestLifetime)
+ {
+ m_syncInterestLifetime = ndn::time::milliseconds(syncInterestLifetime);
+ }
+
+ const ndn::time::milliseconds&
+ getSyncInterestLifetime() const
+ {
+ return m_syncInterestLifetime;
+ }
+
+ void
writeLog();
private:
@@ -459,7 +477,7 @@
uint32_t m_maxFacesPerPrefix;
std::string m_seqFileDir;
-
+ ndn::time::milliseconds m_syncInterestLifetime;
};
} // namespace nlsr
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 120092b..ebc469d 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -260,7 +260,8 @@
m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
- m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix());
+ m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix(),
+ m_confParam.getSyncInterestLifetime());
// Logging start
m_confParam.writeLog();
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 2249dab..65f3ee5 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -44,6 +44,7 @@
" lsa-refresh-time 1800\n"
" lsa-interest-lifetime 3\n"
" router-dead-interval 86400\n"
+ " sync-interest-lifetime 10000\n"
" seq-dir /tmp\n"
"}\n\n";
@@ -176,6 +177,7 @@
BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
+ BOOST_CHECK_EQUAL(conf.getSyncInterestLifetime(), ndn::time::milliseconds(10000));
BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
// Neighbors
diff --git a/tests/test-lsa-rule.cpp b/tests/test-lsa-rule.cpp
index e776942..5aadaac 100644
--- a/tests/test-lsa-rule.cpp
+++ b/tests/test-lsa-rule.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -90,6 +90,8 @@
nlsr.getConfParameter().setNetwork("/ndn");
nlsr.getConfParameter().setSiteName("/edu/test-site");
nlsr.getConfParameter().setRouterName("/%C1.Router/router1");
+ // Otherwise code coverage node fails with default 60 seconds lifetime
+ nlsr.getConfParameter().setSyncInterestLifetime(1000);
// Initialize NLSR to initialize the keyChain
nlsr.initialize();
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index c74ab38..51797e5 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -45,6 +45,8 @@
conf.setSiteName("/site");
conf.setRouterName("/%C1.Router/this-router");
conf.buildRouterPrefix();
+ // Otherwise code coverage node fails with default 60 seconds lifetime
+ conf.setSyncInterestLifetime(1000);
addIdentity(conf.getRouterPrefix());
diff --git a/tests/update/test-prefix-update-processor.cpp b/tests/update/test-prefix-update-processor.cpp
index 5bb61f1..70d18c9 100644
--- a/tests/update/test-prefix-update-processor.cpp
+++ b/tests/update/test-prefix-update-processor.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, The University of Memphis,
+ * Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -117,6 +117,8 @@
nlsr.getConfParameter().setSiteName("/edu/test-site");
nlsr.getConfParameter().setRouterName("/%C1.Router/this-router");
nlsr.getConfParameter().buildRouterPrefix();
+ // Otherwise code coverage node fails with default 60 seconds lifetime
+ nlsr.getConfParameter().setSyncInterestLifetime(1000);
addIdentity(ndn::Name("/ndn/edu/test-site/%C1.Router/this-router"));