src: configuration file parsing
used boost::property_tree::info_parser for parsing nlsr's configuration file and
changed configuration command style to info command style. Removed tokenizer from
nlsr
Refs: #1542
Change-Id: If017ddd7eef5caa59b33940bfc27a71aa4de266b
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index ccc2f5b..2dc106c 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -5,6 +5,8 @@
namespace nlsr {
+const std::string HelloProtocol::INFO_COMPONENT="info";
+
void
HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
{
@@ -25,11 +27,10 @@
{
std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
- ++it)
- {
+ ++it) {
ndn::Name interestName = (*it).getName() ;
- interestName.append("info");
- interestName.append(ndn::Name(m_nlsr.getConfParameter().getRouterPrefix()));
+ interestName.append(INFO_COMPONENT);
+ interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
@@ -50,27 +51,24 @@
{
const ndn::Name interestName = interest.getName();
std::cout << "Interest Received for Name: " << interestName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(interestName, chkString);
- if (infoPosition < 0)
- {
+ if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
- ndn::Name neighbor = interestName.getSubName(infoPosition + 1);
+ ndn::Name neighbor;
+ neighbor.wireDecode(interestName.get(-1).blockFromValue());
std::cout << "Neighbor: " << neighbor << std::endl;
- if (m_nlsr.getAdjacencyList().isNeighbor(neighbor))
- {
+ if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
- data.setContent((const uint8_t*)"info", sizeof("info"));
+ data.setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
+ INFO_COMPONENT.size());
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
m_nlsr.getNlsrFace().put(data);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
- if (status == 0)
- {
+ if (status == 0) {
ndn::Name interestName(neighbor);
- interestName.append("info");
+ interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
@@ -83,13 +81,10 @@
{
const ndn::Name interestName(interest.getName());
std::cout << "Interest timed out for Name: " << interestName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(interestName, chkString);
- if (infoPosition < 0)
- {
+ if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
- ndn::Name neighbor = interestName.getSubName(0, infoPosition);
+ ndn::Name neighbor = interestName.getPrefix(-2);
std::cout << "Neighbor: " << neighbor << std::endl;
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
@@ -98,22 +93,19 @@
std::cout << "Neighbor: " << neighbor << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
- if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber()))
- {
+ if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) {
ndn::Name interestName(neighbor);
- interestName.append("info");
- interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
+ interestName.append(INFO_COMPONENT);
+ interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
else if ((status == 1) &&
- (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
- {
+ (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
m_nlsr.incrementAdjBuildCount();
- if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
- {
- m_nlsr.setIsBuildAdjLsaSheduled(1);
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
@@ -129,11 +121,8 @@
{
ndn::Name dataName = data.getName();
std::cout << "Data received for name: " << dataName << std::endl;
- std::string chkString("info");
- int32_t infoPosition = util::getNameComponentPosition(dataName, chkString);
- if (infoPosition >= 0)
- {
- ndn::Name neighbor = dataName.getSubName(0, infoPosition);
+ if (dataName.get(-3).toUri() == INFO_COMPONENT) {
+ ndn::Name neighbor = dataName.getPrefix(-3);
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
int infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
neighbor);
@@ -154,17 +143,16 @@
std::cout << "Status: " << newStatus << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
//debugging purpose end
- if ((oldStatus - newStatus) != 0) // change in Adjacency list
- {
+ // change in Adjacency list
+ if ((oldStatus - newStatus) != 0) {
m_nlsr.incrementAdjBuildCount();
/* Need to schedule event for Adjacency LSA building */
- if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
- {
- m_nlsr.setIsBuildAdjLsaSheduled(1);
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- boost::ref(m_nlsr.getLsdb())));
+ ndn::ref(m_nlsr.getLsdb())));
}
}
}