src: Discard usage of std::pair of reference type and rename functions
Refs: #1531
Change-Id: Ief2a525b8fb8addbd491d202d6b02d5db2b41ea4
diff --git a/src/adl.cpp b/src/adl.cpp
index 57b3307..605cbd6 100644
--- a/src/adl.cpp
+++ b/src/adl.cpp
@@ -45,7 +45,7 @@
}
int
-Adl::updateAdjacentStatus(string adjName, int s)
+Adl::updateAdjacentStatus(const string& adjName, int s)
{
std::list<Adjacent>::iterator it = find(adjName);
if (it == m_adjList.end())
@@ -57,7 +57,7 @@
}
Adjacent
-Adl::getAdjacent(string adjName)
+Adl::getAdjacent(const string& adjName)
{
Adjacent adj(adjName);
std::list<Adjacent>::iterator it = find(adjName);
@@ -96,7 +96,7 @@
int
-Adl::updateAdjacentLinkCost(string adjName, double lc)
+Adl::updateAdjacentLinkCost(const string& adjName, double lc)
{
std::list<Adjacent>::iterator it = find(adjName);
if (it == m_adjList.end())
@@ -108,7 +108,7 @@
}
bool
-Adl::isNeighbor(string adjName)
+Adl::isNeighbor(const string& adjName)
{
std::list<Adjacent>::iterator it = find(adjName);
if (it == m_adjList.end())
@@ -119,7 +119,7 @@
}
void
-Adl::incrementTimedOutInterestCount(string& neighbor)
+Adl::incrementTimedOutInterestCount(const string& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it == m_adjList.end())
@@ -130,7 +130,7 @@
}
void
-Adl::setTimedOutInterestCount(string& neighbor, int count)
+Adl::setTimedOutInterestCount(const string& neighbor, int count)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it != m_adjList.end())
@@ -140,7 +140,7 @@
}
int
-Adl::getTimedOutInterestCount(string& neighbor)
+Adl::getTimedOutInterestCount(const string& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it == m_adjList.end())
@@ -151,7 +151,7 @@
}
int
-Adl::getStatusOfNeighbor(string& neighbor)
+Adl::getStatusOfNeighbor(const string& neighbor)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it == m_adjList.end())
@@ -162,7 +162,7 @@
}
void
-Adl::setStatusOfNeighbor(string& neighbor, int status)
+Adl::setStatusOfNeighbor(const string& neighbor, int status)
{
std::list<Adjacent>::iterator it = find(neighbor);
if (it != m_adjList.end())
diff --git a/src/adl.hpp b/src/adl.hpp
index 8a7da9f..76f9280 100644
--- a/src/adl.hpp
+++ b/src/adl.hpp
@@ -19,31 +19,31 @@
insert(Adjacent& adj);
int
- updateAdjacentStatus(std::string adjName, int s);
+ updateAdjacentStatus(const std::string& adjName, int s);
int
- updateAdjacentLinkCost(std::string adjName, double lc);
+ updateAdjacentLinkCost(const std::string& adjName, double lc);
std::list<Adjacent>&
getAdjList();
bool
- isNeighbor(std::string adjName);
+ isNeighbor(const std::string& adjName);
void
- incrementTimedOutInterestCount(std::string& neighbor);
+ incrementTimedOutInterestCount(const std::string& neighbor);
int
- getTimedOutInterestCount(std::string& neighbor);
+ getTimedOutInterestCount(const std::string& neighbor);
int
- getStatusOfNeighbor(std::string& neighbor);
+ getStatusOfNeighbor(const std::string& neighbor);
void
- setStatusOfNeighbor(std::string& neighbor, int status);
+ setStatusOfNeighbor(const std::string& neighbor, int status);
void
- setTimedOutInterestCount(std::string& neighbor, int count);
+ setTimedOutInterestCount(const std::string& neighbor, int count);
void
addAdjacentsFromAdl(Adl& adl);
@@ -55,7 +55,7 @@
getNumOfActiveNeighbor();
Adjacent
- getAdjacent(std::string adjName);
+ getAdjacent(const std::string& adjName);
bool
isEqual(Adl& adl);
diff --git a/src/communication/data-manager.cpp b/src/communication/data-manager.cpp
index e4cefe5..bcae456 100644
--- a/src/communication/data-manager.cpp
+++ b/src/communication/data-manager.cpp
@@ -17,7 +17,7 @@
using namespace ndn;
void
-DataManager::processContent(Nlsr& pnlsr, const ndn::Interest& interest,
+DataManager::processContent(const ndn::Interest& interest,
const ndn::Data& data, InterestManager& im)
{
std::cout << "I: " << interest.toUri() << std::endl;
@@ -26,24 +26,24 @@
std::string chkString("keys");
if (nt.doesTokenExist(chkString))
{
- processContentKeys(pnlsr, data);
+ processContentKeys(data);
}
else
{
- if (pnlsr.getKeyManager().verify(data))
+ if (m_nlsr.getKeyManager().verify(data))
{
std::cout << "Verified Data Content" << std::endl;
chkString = "info";
if (nt.doesTokenExist(chkString))
{
string dataContent((char*)data.getContent().value());
- processContentInfo(pnlsr, dataName, dataContent);
+ processContentInfo(dataName, dataContent);
}
chkString = "LSA";
if (nt.doesTokenExist(chkString))
{
string dataContent((char*)data.getContent().value());
- processContentLsa(pnlsr, dataName, dataContent);
+ processContentLsa(dataName, dataContent);
}
}
else
@@ -54,24 +54,24 @@
}
void
-DataManager::processContentInfo(Nlsr& pnlsr, string& dataName,
+DataManager::processContentInfo(const string& dataName,
string& dataContent)
{
Tokenizer nt(dataName, "/");
string chkString("info");
string neighbor = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
- int oldStatus = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
- int infoIntTimedOutCount = pnlsr.getAdl().getTimedOutInterestCount(neighbor);
+ int oldStatus = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
+ int infoIntTimedOutCount = m_nlsr.getAdl().getTimedOutInterestCount(neighbor);
//debugging purpose start
std::cout << "Before Updates: " << std::endl;
std::cout << "Neighbor : " << neighbor << std::endl;
std::cout << "Status: " << oldStatus << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
//debugging purpose end
- pnlsr.getAdl().setStatusOfNeighbor(neighbor, 1);
- pnlsr.getAdl().setTimedOutInterestCount(neighbor, 0);
- int newStatus = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
- infoIntTimedOutCount = pnlsr.getAdl().getTimedOutInterestCount(neighbor);
+ m_nlsr.getAdl().setStatusOfNeighbor(neighbor, 1);
+ m_nlsr.getAdl().setTimedOutInterestCount(neighbor, 0);
+ int newStatus = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
+ infoIntTimedOutCount = m_nlsr.getAdl().getTimedOutInterestCount(neighbor);
//debugging purpose
std::cout << "After Updates: " << std::endl;
std::cout << "Neighbor : " << neighbor << std::endl;
@@ -80,22 +80,21 @@
//debugging purpose end
if ((oldStatus - newStatus) != 0) // change in Adjacency list
{
- pnlsr.incrementAdjBuildCount();
+ m_nlsr.incrementAdjBuildCount();
/* Need to schedule event for Adjacency LSA building */
- if (pnlsr.getIsBuildAdjLsaSheduled() == 0)
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
{
- pnlsr.setIsBuildAdjLsaSheduled(1);
+ m_nlsr.setIsBuildAdjLsaSheduled(1);
// event here
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild, pnlsr.getLsdb(),
- boost::ref(pnlsr)));
+ m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild, m_nlsr.getLsdb(),
+ boost::ref(m_nlsr)));
}
}
}
void
-DataManager::processContentLsa(Nlsr& pnlsr, string& dataName,
- string& dataContent)
+DataManager::processContentLsa(const string& dataName, string& dataContent)
{
Tokenizer nt(dataName, "/");
string chkString("LSA");
@@ -114,17 +113,17 @@
}
if (lsTypeString == "1") //Name Lsa
{
- processContentNameLsa(pnlsr, origRouter + "/" + lsTypeString,
+ processContentNameLsa(origRouter + "/" + lsTypeString,
interestedLsSeqNo, dataContent);
}
else if (lsTypeString == "2") //Adj Lsa
{
- processContentAdjLsa(pnlsr, origRouter + "/" + lsTypeString,
+ processContentAdjLsa(origRouter + "/" + lsTypeString,
interestedLsSeqNo, dataContent);
}
else if (lsTypeString == "3") //Cor Lsa
{
- processContentCorLsa(pnlsr, origRouter + "/" + lsTypeString,
+ processContentCorLsa(origRouter + "/" + lsTypeString,
interestedLsSeqNo, dataContent);
}
else
@@ -134,15 +133,15 @@
}
void
-DataManager::processContentNameLsa(Nlsr& pnlsr, string lsaKey,
+DataManager::processContentNameLsa(const string& lsaKey,
uint32_t lsSeqNo, string& dataContent)
{
- if (pnlsr.getLsdb().isNameLsaNew(lsaKey, lsSeqNo))
+ if (m_nlsr.getLsdb().isNameLsaNew(lsaKey, lsSeqNo))
{
NameLsa nameLsa;
if (nameLsa.initializeFromContent(dataContent))
{
- pnlsr.getLsdb().installNameLsa(pnlsr, nameLsa);
+ m_nlsr.getLsdb().installNameLsa(m_nlsr, nameLsa);
}
else
{
@@ -152,15 +151,15 @@
}
void
-DataManager::processContentAdjLsa(Nlsr& pnlsr, string lsaKey,
+DataManager::processContentAdjLsa(const string& lsaKey,
uint32_t lsSeqNo, string& dataContent)
{
- if (pnlsr.getLsdb().isAdjLsaNew(lsaKey, lsSeqNo))
+ if (m_nlsr.getLsdb().isAdjLsaNew(lsaKey, lsSeqNo))
{
AdjLsa adjLsa;
if (adjLsa.initializeFromContent(dataContent))
{
- pnlsr.getLsdb().installAdjLsa(pnlsr, adjLsa);
+ m_nlsr.getLsdb().installAdjLsa(m_nlsr, adjLsa);
}
else
{
@@ -170,15 +169,15 @@
}
void
-DataManager::processContentCorLsa(Nlsr& pnlsr, string lsaKey,
+DataManager::processContentCorLsa(const string& lsaKey,
uint32_t lsSeqNo, string& dataContent)
{
- if (pnlsr.getLsdb().isCorLsaNew(lsaKey, lsSeqNo))
+ if (m_nlsr.getLsdb().isCoordinateLsaNew(lsaKey, lsSeqNo))
{
- CorLsa corLsa;
+ CoordinateLsa corLsa;
if (corLsa.initializeFromContent(dataContent))
{
- pnlsr.getLsdb().installCorLsa(pnlsr, corLsa);
+ m_nlsr.getLsdb().installCoordinateLsa(m_nlsr, corLsa);
}
else
{
@@ -188,7 +187,7 @@
}
void
-DataManager::processContentKeys(Nlsr& pnlsr, const ndn::Data& data)
+DataManager::processContentKeys(const ndn::Data& data)
{
std::cout << " processContentKeys called " << std::endl;
ndn::shared_ptr<ndn::IdentityCertificate> cert =
@@ -201,15 +200,14 @@
uint32_t seqNum = boost::lexical_cast<uint32_t>(nt.getToken(
nt.getTokenNumber() - 2));
std::cout << "Cert Name: " << certName << " Seq Num: " << seqNum << std::endl;
- if (pnlsr.getKeyManager().verify(pnlsr, *(cert)))
+ if (m_nlsr.getKeyManager().verify(m_nlsr, *(cert)))
{
- pnlsr.getKeyManager().addCertificate(cert, seqNum, true);
+ m_nlsr.getKeyManager().addCertificate(cert, seqNum, true);
}
else
{
- pnlsr.getKeyManager().addCertificate(cert, seqNum, false);
+ m_nlsr.getKeyManager().addCertificate(cert, seqNum, false);
}
-
- pnlsr.getKeyManager().printCertStore();
+ m_nlsr.getKeyManager().printCertStore();
}
}//namespace nlsr
diff --git a/src/communication/data-manager.hpp b/src/communication/data-manager.hpp
index 153e0a0..ece3fca 100644
--- a/src/communication/data-manager.hpp
+++ b/src/communication/data-manager.hpp
@@ -13,32 +13,37 @@
class DataManager
{
public:
+ DataManager(Nlsr& nlsr)
+ : m_nlsr(nlsr)
+ {}
void
- processContent(Nlsr& pnlsr, const ndn::Interest& interest,
+ processContent(const ndn::Interest& interest,
const ndn::Data& data, InterestManager& im);
private:
void
- processContentInfo(Nlsr& pnlsr, std::string& dataName,
+ processContentInfo(const std::string& dataName,
std::string& dataContent);
void
- processContentLsa(Nlsr& pnlsr, std::string& dataName,
- std::string& dataContent);
+ processContentLsa(const std::string& dataName, std::string& dataContent);
void
- processContentNameLsa(Nlsr& pnlsr, std::string lsaKey,
+ processContentNameLsa(const std::string& lsaKey,
uint32_t lsSeqNo, std::string& dataContent);
void
- processContentAdjLsa(Nlsr& pnlsr, std::string lsaKey,
+ processContentAdjLsa(const std::string& lsaKey,
uint32_t lsSeqNo, std::string& dataContent);
void
- processContentCorLsa(Nlsr& pnlsr, std::string lsaKey,
+ processContentCorLsa(const std::string& lsaKey,
uint32_t lsSeqNo, std::string& dataContent);
void
- processContentKeys(Nlsr& pnlsr, const ndn::Data& data);
+ processContentKeys(const ndn::Data& data);
+
+private:
+ Nlsr& m_nlsr;
};
diff --git a/src/communication/interest-manager.cpp b/src/communication/interest-manager.cpp
index 73a43e9..226efaf 100644
--- a/src/communication/interest-manager.cpp
+++ b/src/communication/interest-manager.cpp
@@ -17,8 +17,7 @@
using namespace ndn;
void
-InterestManager::processInterest(Nlsr& pnlsr,
- const ndn::Name& name,
+InterestManager::processInterest(const ndn::Name& name,
const ndn::Interest& interest)
{
cout << "<< I: " << interest << endl;
@@ -30,45 +29,45 @@
{
string nbr = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
cout << "Neighbor: " << nbr << endl;
- processInterestInfo(pnlsr, nbr, interest);
+ processInterestInfo(nbr, interest);
}
chkString = "LSA";
if (nt.doesTokenExist(chkString))
{
- processInterestLsa(pnlsr, interest);
+ processInterestLsa(interest);
}
chkString = "keys";
if (nt.doesTokenExist(chkString))
{
- processInterestKeys(pnlsr, interest);
+ processInterestKeys(interest);
}
}
void
-InterestManager::processInterestInfo(Nlsr& pnlsr, string& neighbor,
+InterestManager::processInterestInfo(const string& neighbor,
const ndn::Interest& interest)
{
- if (pnlsr.getAdl().isNeighbor(neighbor))
+ if (m_nlsr.getAdl().isNeighbor(neighbor))
{
Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
data.setContent((const uint8_t*)"info", sizeof("info"));
- pnlsr.getKeyManager().signData(data);
+ m_nlsr.getKeyManager().signData(data);
cout << ">> D: " << data << endl;
- pnlsr.getNlsrFace()->put(data);
- int status = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
+ m_nlsr.getNlsrFace()->put(data);
+ int status = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
if (status == 0)
{
string intName = neighbor + "/" + "info" +
- pnlsr.getConfParameter().getRouterPrefix();
- expressInterest(pnlsr, intName, 2,
- pnlsr.getConfParameter().getInterestResendTime());
+ m_nlsr.getConfParameter().getRouterPrefix();
+ expressInterest(intName, 2,
+ m_nlsr.getConfParameter().getInterestResendTime());
}
}
}
void
-InterestManager::processInterestLsa(Nlsr& pnlsr, const ndn::Interest& interest)
+InterestManager::processInterestLsa(const ndn::Interest& interest)
{
string intName = interest.getName().toUri();
Tokenizer nt(intName, "/");
@@ -94,17 +93,17 @@
std::cout << "Ls Type: " << interestedLsType << std::endl;
if (lsTypeString == "1") //Name Lsa
{
- processInterestForNameLsa(pnlsr, interest,
+ processInterestForNameLsa(interest,
origRouter + "/" + lsTypeString, interestedLsSeqNo);
}
else if (lsTypeString == "2") //Adj Lsa
{
- processInterestForAdjLsa(pnlsr, interest,
+ processInterestForAdjLsa(interest,
origRouter + "/" + lsTypeString, interestedLsSeqNo);
}
else if (lsTypeString == "3") //Cor Lsa
{
- processInterestForCorLsa(pnlsr, interest,
+ processInterestForCorLsa(interest,
origRouter + "/" + lsTypeString, interestedLsSeqNo);
}
else
@@ -114,70 +113,67 @@
}
void
-InterestManager::processInterestForNameLsa(Nlsr& pnlsr,
- const ndn::Interest& interest,
- string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForNameLsa(const ndn::Interest& interest,
+ const string& lsaKey, uint32_t interestedlsSeqNo)
{
- std::pair<NameLsa&, bool> nameLsa = pnlsr.getLsdb().getNameLsa(lsaKey);
- if (nameLsa.second)
+ NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
+ if (nameLsa != 0)
{
- if (nameLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+ if (nameLsa->getLsSeqNo() >= interestedlsSeqNo)
{
Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
- string content = nameLsa.first.getData();
+ string content = nameLsa->getData();
data.setContent((const uint8_t*)content.c_str(), content.size());
- pnlsr.getKeyManager().signData(data);
+ m_nlsr.getKeyManager().signData(data);
std::cout << ">> D: " << data << std::endl;
- pnlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace()->put(data);
}
}
}
void
-InterestManager::processInterestForAdjLsa(Nlsr& pnlsr,
- const ndn::Interest& interest,
- string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForAdjLsa(const ndn::Interest& interest,
+ const string& lsaKey, uint32_t interestedlsSeqNo)
{
- std::pair<AdjLsa&, bool> adjLsa = pnlsr.getLsdb().getAdjLsa(lsaKey);
- if (adjLsa.second)
+ AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
+ if (adjLsa != 0)
{
- if (adjLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+ if (adjLsa->getLsSeqNo() >= interestedlsSeqNo)
{
Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
- string content = adjLsa.first.getData();
+ string content = adjLsa->getData();
data.setContent((const uint8_t*)content.c_str(), content.size());
- pnlsr.getKeyManager().signData(data);
+ m_nlsr.getKeyManager().signData(data);
std::cout << ">> D: " << data << std::endl;
- pnlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace()->put(data);
}
}
}
void
-InterestManager::processInterestForCorLsa(Nlsr& pnlsr,
- const ndn::Interest& interest,
- string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForCorLsa(const ndn::Interest& interest,
+ const string& lsaKey, uint32_t interestedlsSeqNo)
{
- std::pair<CorLsa&, bool> corLsa = pnlsr.getLsdb().getCorLsa(lsaKey);
- if (corLsa.second)
+ CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
+ if (corLsa != 0)
{
- if (corLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+ if (corLsa->getLsSeqNo() >= interestedlsSeqNo)
{
Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
- string content = corLsa.first.getData();
+ string content = corLsa->getData();
data.setContent((const uint8_t*)content.c_str(), content.size());
- pnlsr.getKeyManager().signData(data);
+ m_nlsr.getKeyManager().signData(data);
std::cout << ">> D: " << data << std::endl;
- pnlsr.getNlsrFace()->put(data);
+ m_nlsr.getNlsrFace()->put(data);
}
}
}
void
-InterestManager::processInterestKeys(Nlsr& pnlsr, const ndn::Interest& interest)
+InterestManager::processInterestKeys(const ndn::Interest& interest)
{
std::cout << "processInterestKeys called " << std::endl;
string intName = interest.getName().toUri();
@@ -192,14 +188,14 @@
{
certName = nt.getTokenString(0, nt.getTokenNumber() - 1);
cout << "Cert Name: " << certName << std::endl;
- chkCert = pnlsr.getKeyManager().getCertificateFromStore(certName);
+ chkCert = m_nlsr.getKeyManager().getCertificateFromStore(certName);
}
else
{
certName = nt.getTokenString(0, nt.getTokenNumber() - 2);
seqNum = boost::lexical_cast<uint32_t>(nt.getToken(nt.getTokenNumber() - 1));
std::cout << "Cert Name: " << certName << " Seq Num: " << seqNum << std::endl;
- chkCert = pnlsr.getKeyManager().getCertificateFromStore(certName, seqNum);
+ chkCert = m_nlsr.getKeyManager().getCertificateFromStore(certName, seqNum);
}
if (chkCert.second)
{
@@ -208,7 +204,7 @@
std::string dn;
dataName = ndn::Name(interest.getName()).appendVersion();
std::pair<uint32_t, bool> seqChk =
- pnlsr.getKeyManager().getCertificateSeqNum(certName);
+ m_nlsr.getKeyManager().getCertificateSeqNum(certName);
if (seqChk.second)
{
dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(seqChk.first);
@@ -219,7 +215,6 @@
dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(10);
dataName = ndn::Name(dn);
}
-
}
else
{
@@ -228,15 +223,14 @@
Data data(dataName.appendVersion());
data.setFreshnessPeriod(time::seconds(10)); //10 sec
data.setContent(chkCert.first->wireEncode());
- pnlsr.getKeyManager().signData(data);
- pnlsr.getNlsrFace()->put(data);
+ m_nlsr.getKeyManager().signData(data);
+ m_nlsr.getNlsrFace()->put(data);
}
}
void
-InterestManager::processInterestTimedOut(Nlsr& pnlsr,
- const ndn::Interest& interest)
+InterestManager::processInterestTimedOut(const ndn::Interest& interest)
{
std::cout << "Timed out interest : " << interest.getName().toUri() << std::endl;
string intName = interest.getName().toUri();
@@ -245,94 +239,92 @@
if (nt.doesTokenExist(chkString))
{
string nbr = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
- processInterestTimedOutInfo(pnlsr , nbr , interest);
+ processInterestTimedOutInfo(nbr , interest);
}
chkString = "LSA";
if (nt.doesTokenExist(chkString))
{
- processInterestTimedOutLsa(pnlsr, interest);
+ processInterestTimedOutLsa(interest);
}
}
void
-InterestManager::processInterestTimedOutInfo(Nlsr& pnlsr, string& neighbor,
+InterestManager::processInterestTimedOutInfo(const string& neighbor,
const ndn::Interest& interest)
{
- pnlsr.getAdl().incrementTimedOutInterestCount(neighbor);
- int status = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
- int infoIntTimedOutCount = pnlsr.getAdl().getTimedOutInterestCount(neighbor);
+ m_nlsr.getAdl().incrementTimedOutInterestCount(neighbor);
+ int status = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
+ int infoIntTimedOutCount = m_nlsr.getAdl().getTimedOutInterestCount(neighbor);
std::cout << "Neighbor: " << neighbor << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
- if ((infoIntTimedOutCount < pnlsr.getConfParameter().getInterestRetryNumber()))
+ if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber()))
{
string intName = neighbor + "/" + "info" +
- pnlsr.getConfParameter().getRouterPrefix();
- expressInterest(pnlsr, intName, 2,
- pnlsr.getConfParameter().getInterestResendTime());
+ m_nlsr.getConfParameter().getRouterPrefix();
+ expressInterest(intName, 2,
+ m_nlsr.getConfParameter().getInterestResendTime());
}
else if ((status == 1) &&
- (infoIntTimedOutCount == pnlsr.getConfParameter().getInterestRetryNumber()))
+ (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
{
- pnlsr.getAdl().setStatusOfNeighbor(neighbor, 0);
- pnlsr.incrementAdjBuildCount();
- if (pnlsr.getIsBuildAdjLsaSheduled() == 0)
+ m_nlsr.getAdl().setStatusOfNeighbor(neighbor, 0);
+ m_nlsr.incrementAdjBuildCount();
+ if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
{
- pnlsr.setIsBuildAdjLsaSheduled(1);
+ m_nlsr.setIsBuildAdjLsaSheduled(1);
// event here
- pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
- ndn::bind(&Lsdb::scheduledAdjLsaBuild,
- &pnlsr.getLsdb(),
- boost::ref(pnlsr)));
+ m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
+ ndn::bind(&Lsdb::scheduledAdjLsaBuild,
+ &m_nlsr.getLsdb(),
+ boost::ref(m_nlsr)));
}
}
}
void
-InterestManager::processInterestTimedOutLsa(Nlsr& pnlsr,
- const ndn::Interest& interest)
+InterestManager::processInterestTimedOutLsa(const ndn::Interest& interest)
{
}
void
-InterestManager::expressInterest(Nlsr& pnlsr, const string& interestNamePrefix,
+InterestManager::expressInterest(const string& interestNamePrefix,
int scope, int seconds)
{
std::cout << "Expressing Interest :" << interestNamePrefix << std::endl;
ndn::Interest i((ndn::Name(interestNamePrefix)));
i.setInterestLifetime(time::seconds(seconds));
i.setMustBeFresh(true);
- pnlsr.getNlsrFace()->expressInterest(i,
- ndn::func_lib::bind(&DataManager::processContent,
- &pnlsr.getDm(),
- boost::ref(pnlsr), _1,
- _2, boost::ref(*this)),
- ndn::func_lib::bind(&InterestManager::processInterestTimedOut,
- this, boost::ref(pnlsr), _1));
+ m_nlsr.getNlsrFace()->expressInterest(i,
+ ndn::bind(&DataManager::processContent,
+ &m_nlsr.getDm(),
+ _1, _2, boost::ref(*this)),
+ ndn::bind(&InterestManager::processInterestTimedOut,
+ this, _1));
}
void
-InterestManager::sendScheduledInfoInterest(Nlsr& pnlsr, int seconds)
+InterestManager::sendScheduledInfoInterest(int seconds)
{
- std::list<Adjacent> adjList = pnlsr.getAdl().getAdjList();
+ std::list<Adjacent> adjList = m_nlsr.getAdl().getAdjList();
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
++it)
{
string adjName = (*it).getName() + "/" + "info" +
- pnlsr.getConfParameter().getRouterPrefix();
- expressInterest(pnlsr, adjName, 2,
- pnlsr.getConfParameter().getInterestResendTime());
+ m_nlsr.getConfParameter().getRouterPrefix();
+ expressInterest(adjName, 2,
+ m_nlsr.getConfParameter().getInterestResendTime());
}
- scheduleInfoInterest(pnlsr, pnlsr.getConfParameter().getInfoInterestInterval());
+ scheduleInfoInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
}
void
-InterestManager::scheduleInfoInterest(Nlsr& pnlsr, int seconds)
+InterestManager::scheduleInfoInterest(int seconds)
{
- EventId eid = pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
- ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
- boost::ref(pnlsr), seconds));
+ EventId eid = m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
+ ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
+ seconds));
}
diff --git a/src/communication/interest-manager.hpp b/src/communication/interest-manager.hpp
index 5975e7f..86d590b 100644
--- a/src/communication/interest-manager.hpp
+++ b/src/communication/interest-manager.hpp
@@ -12,57 +12,55 @@
class InterestManager
{
public:
- InterestManager()
+ InterestManager(Nlsr& nlsr)
+ : m_nlsr(nlsr)
{
}
void
- processInterest(Nlsr& pnlsr, const ndn::Name& name,
- const ndn::Interest& interest);
+ processInterest(const ndn::Name& name, const ndn::Interest& interest);
void
- processInterestInfo(Nlsr& pnlsr, std::string& neighbor,
- const ndn::Interest& interest);
+ processInterestInfo(const std::string& neighbor, const ndn::Interest& interest);
void
- processInterestLsa(Nlsr& pnlsr, const ndn::Interest& interest);
+ processInterestLsa(const ndn::Interest& interest);
void
- processInterestForNameLsa(Nlsr& pnlsr, const ndn::Interest& interest,
- std::string lsaKey, uint32_t interestedlsSeqNo);
+ processInterestForNameLsa(const ndn::Interest& interest,
+ const std::string& lsaKey, uint32_t interestedlsSeqNo);
void
- processInterestForAdjLsa(Nlsr& pnlsr, const ndn::Interest& interest,
- std::string lsaKey, uint32_t interestedlsSeqNo);
+ processInterestForAdjLsa(const ndn::Interest& interest,
+ const std::string& lsaKey, uint32_t interestedlsSeqNo);
void
- processInterestForCorLsa(Nlsr& pnlsr, const ndn::Interest& interest,
- std::string lsaKey, uint32_t interestedlsSeqNo);
+ processInterestForCorLsa(const ndn::Interest& interest,
+ const std::string& lsaKey, uint32_t interestedlsSeqNo);
void
- processInterestKeys(Nlsr& pnlsr, const ndn::Interest& interest);
+ processInterestKeys(const ndn::Interest& interest);
void
- processInterestTimedOut(Nlsr& pnlsr, const ndn::Interest& interest);
+ processInterestTimedOut(const ndn::Interest& interest);
void
- processInterestTimedOutInfo(Nlsr& pnlsr, std::string& neighbor,
+ processInterestTimedOutInfo(const std::string& neighbor,
const ndn::Interest& interest);
void
- processInterestTimedOutLsa(Nlsr& pnlsr, const ndn::Interest& interest);
+ processInterestTimedOutLsa(const ndn::Interest& interest);
void
- expressInterest(Nlsr& pnlsr,
- const std::string& interestNamePrefix, int scope, int seconds);
+ expressInterest(const std::string& interestNamePrefix, int scope, int seconds);
void
- sendScheduledInfoInterest(Nlsr& pnlsr, int seconds);
+ sendScheduledInfoInterest(int seconds);
void
- scheduleInfoInterest(Nlsr& pnlsr, int seconds);
+ scheduleInfoInterest(int seconds);
private:
-
+ Nlsr& m_nlsr;
};
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index a38fe98..696f06a 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -81,7 +81,7 @@
pnlsr.getConfParameter().getChronosyncLsaPrefix() +
routerName + "/1/" +
boost::lexical_cast<std::string>(sm.getNameLsaSeq());
- pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getIm().expressInterest(lsaPrefix, 3,
pnlsr.getConfParameter().getInterestResendTime());
}
if (pnlsr.getLsdb().isAdjLsaNew(routerName + "/2", sm.getAdjLsaSeq()))
@@ -91,17 +91,17 @@
pnlsr.getConfParameter().getChronosyncLsaPrefix() +
routerName + "/2/" +
boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
- pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getIm().expressInterest(lsaPrefix, 3,
pnlsr.getConfParameter().getInterestResendTime());
}
- if (pnlsr.getLsdb().isCorLsaNew(routerName + "/3", sm.getCorLsaSeq()))
+ if (pnlsr.getLsdb().isCoordinateLsaNew(routerName + "/3", sm.getCorLsaSeq()))
{
std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
string lsaPrefix =
pnlsr.getConfParameter().getChronosyncLsaPrefix() +
routerName + "/3/" +
boost::lexical_cast<std::string>(sm.getCorLsaSeq());
- pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getIm().expressInterest(lsaPrefix, 3,
pnlsr.getConfParameter().getInterestResendTime());
}
}
@@ -116,7 +116,7 @@
{
string certNamePrefix = certName + "/" +
boost::lexical_cast<string>(seqNo);
- pnlsr.getIm().expressInterest(pnlsr, certNamePrefix, 3,
+ pnlsr.getIm().expressInterest(certNamePrefix, 3,
pnlsr.getConfParameter().getInterestResendTime());
}
}
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index a19fa09..eac9db6 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -15,7 +15,7 @@
using namespace std;
int
-ConfFileProcessor::processConfFile(Nlsr& pnlsr)
+ConfFileProcessor::processConfFile()
{
int ret = 0;
if (!m_confFileName.empty())
@@ -29,7 +29,7 @@
{
if (line[0] != '#' && line[0] != '!')
{
- ret = processConfCommand(pnlsr, line);
+ ret = processConfCommand(line);
if (ret == -1)
{
break;
@@ -50,85 +50,85 @@
int
-ConfFileProcessor::processConfCommand(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommand(string command)
{
int ret = 0;
Tokenizer nt(command, " ");
if ((nt.getFirstToken() == "network"))
{
- ret = processConfCommandNetwork(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandNetwork(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "site-name"))
{
- ret = processConfCommandSiteName(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandSiteName(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "root-key-prefix"))
{
- ret = processConfCommandRootKeyPrefix(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandRootKeyPrefix(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "router-name"))
{
- ret = processConfCommandRouterName(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandRouterName(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "ndnneighbor"))
{
- ret = processConfCommandNdnNeighbor(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandNdnNeighbor(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "link-cost"))
{
- ret = processConfCommandLinkCost(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandLinkCost(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "ndnname"))
{
- ret = processConfCommandNdnName(pnlsr, nt.getRestOfLine());
+ ret = processConfCommandNdnName(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "interest-retry-num"))
{
- processConfCommandInterestRetryNumber(pnlsr, nt.getRestOfLine());
+ processConfCommandInterestRetryNumber(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "interest-resend-time"))
{
- processConfCommandInterestResendTime(pnlsr, nt.getRestOfLine());
+ processConfCommandInterestResendTime(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "lsa-refresh-time"))
{
- processConfCommandLsaRefreshTime(pnlsr, nt.getRestOfLine());
+ processConfCommandLsaRefreshTime(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "max-faces-per-prefix"))
{
- processConfCommandMaxFacesPerPrefix(pnlsr, nt.getRestOfLine());
+ processConfCommandMaxFacesPerPrefix(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "log-dir"))
{
- processConfCommandLogDir(pnlsr, nt.getRestOfLine());
+ processConfCommandLogDir(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "cert-dir"))
{
- processConfCommandCertDir(pnlsr, nt.getRestOfLine());
+ processConfCommandCertDir(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "detailed-logging"))
{
- processConfCommandDetailedLogging(pnlsr, nt.getRestOfLine());
+ processConfCommandDetailedLogging(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "debugging"))
{
- processConfCommandDebugging(pnlsr, nt.getRestOfLine());
+ processConfCommandDebugging(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "chronosync-sync-prefix"))
{
- processConfCommandChronosyncSyncPrefix(pnlsr, nt.getRestOfLine());
+ processConfCommandChronosyncSyncPrefix(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "hyperbolic-cordinate"))
{
- processConfCommandHyperbolicCordinate(pnlsr, nt.getRestOfLine());
+ processConfCommandHyperbolicCordinate(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "hyperbolic-routing"))
{
- processConfCommandIsHyperbolicCalc(pnlsr, nt.getRestOfLine());
+ processConfCommandIsHyperbolicCalc(nt.getRestOfLine());
}
else if ((nt.getFirstToken() == "tunnel-type"))
{
- processConfCommandTunnelType(pnlsr, nt.getRestOfLine());
+ processConfCommandTunnelType(nt.getRestOfLine());
}
else
{
@@ -138,7 +138,7 @@
}
int
-ConfFileProcessor::processConfCommandNetwork(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandNetwork(string command)
{
if (command.empty())
{
@@ -155,13 +155,13 @@
{
command.erase(0, 1);
}
- pnlsr.getConfParameter().setNetwork(command);
+ m_nlsr.getConfParameter().setNetwork(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandSiteName(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandSiteName(string command)
{
if (command.empty())
{
@@ -178,13 +178,13 @@
{
command.erase(0, 1);
}
- pnlsr.getConfParameter().setSiteName(command);
+ m_nlsr.getConfParameter().setSiteName(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandRootKeyPrefix(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandRootKeyPrefix(string command)
{
if (command.empty())
{
@@ -201,14 +201,14 @@
{
command.erase(0, 1);
}
- pnlsr.getConfParameter().setRootKeyPrefix(command);
+ m_nlsr.getConfParameter().setRootKeyPrefix(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandRouterName(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandRouterName(string command)
{
if (command.empty())
{
@@ -225,14 +225,13 @@
{
command.erase(0, 1);
}
- pnlsr.getConfParameter().setRouterName(command);
+ m_nlsr.getConfParameter().setRouterName(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandInterestRetryNumber(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandInterestRetryNumber(string command)
{
if (command.empty())
{
@@ -245,15 +244,14 @@
ss >> irn;
if (irn >= 1 && irn <= 5)
{
- pnlsr.getConfParameter().setInterestRetryNumber(irn);
+ m_nlsr.getConfParameter().setInterestRetryNumber(irn);
}
}
return 0;
}
int
-ConfFileProcessor::processConfCommandInterestResendTime(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandInterestResendTime(string command)
{
if (command.empty())
{
@@ -266,14 +264,14 @@
ss >> irt;
if (irt >= 1 && irt <= 20)
{
- pnlsr.getConfParameter().setInterestResendTime(irt);
+ m_nlsr.getConfParameter().setInterestResendTime(irt);
}
}
return 0;
}
int
-ConfFileProcessor::processConfCommandLsaRefreshTime(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandLsaRefreshTime(string command)
{
if (command.empty())
{
@@ -286,15 +284,14 @@
ss >> lrt;
if (lrt >= 240 && lrt <= 7200)
{
- pnlsr.getConfParameter().setLsaRefreshTime(lrt);
+ m_nlsr.getConfParameter().setLsaRefreshTime(lrt);
}
}
return 0;
}
int
-ConfFileProcessor::processConfCommandMaxFacesPerPrefix(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandMaxFacesPerPrefix(string command)
{
if (command.empty())
{
@@ -307,14 +304,14 @@
ss >> mfpp;
if (mfpp >= 0 && mfpp <= 60)
{
- pnlsr.getConfParameter().setMaxFacesPerPrefix(mfpp);
+ m_nlsr.getConfParameter().setMaxFacesPerPrefix(mfpp);
}
}
return 0;
}
int
-ConfFileProcessor::processConfCommandTunnelType(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandTunnelType(string command)
{
if (command.empty())
{
@@ -324,11 +321,11 @@
{
if (command == "tcp" || command == "TCP")
{
- pnlsr.getConfParameter().setTunnelType(1);
+ m_nlsr.getConfParameter().setTunnelType(1);
}
else if (command == "udp" || command == "UDP")
{
- pnlsr.getConfParameter().setTunnelType(0);
+ m_nlsr.getConfParameter().setTunnelType(0);
}
else
{
@@ -339,8 +336,7 @@
}
int
-ConfFileProcessor::processConfCommandChronosyncSyncPrefix(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandChronosyncSyncPrefix(string command)
{
if (command.empty())
{
@@ -348,14 +344,14 @@
}
else
{
- pnlsr.getConfParameter().setChronosyncSyncPrefix(command);
+ m_nlsr.getConfParameter().setChronosyncSyncPrefix(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandLogDir(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandLogDir(string command)
{
if (command.empty())
{
@@ -363,13 +359,13 @@
}
else
{
- pnlsr.getConfParameter().setLogDir(command);
+ m_nlsr.getConfParameter().setLogDir(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandCertDir(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandCertDir(string command)
{
if (command.empty())
{
@@ -377,13 +373,13 @@
}
else
{
- pnlsr.getConfParameter().setCertDir(command);
+ m_nlsr.getConfParameter().setCertDir(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandDebugging(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandDebugging(string command)
{
if (command.empty())
{
@@ -393,11 +389,11 @@
{
if (command == "on" || command == "ON")
{
- pnlsr.getConfParameter().setDebugging(1);
+ m_nlsr.getConfParameter().setDebugging(1);
}
else if (command == "off" || command == "off")
{
- pnlsr.getConfParameter().setDebugging(0);
+ m_nlsr.getConfParameter().setDebugging(0);
}
else
{
@@ -408,8 +404,7 @@
}
int
-ConfFileProcessor::processConfCommandDetailedLogging(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandDetailedLogging(string command)
{
if (command.empty())
{
@@ -419,11 +414,11 @@
{
if (command == "on" || command == "ON")
{
- pnlsr.getConfParameter().setDetailedLogging(1);
+ m_nlsr.getConfParameter().setDetailedLogging(1);
}
else if (command == "off" || command == "off")
{
- pnlsr.getConfParameter().setDetailedLogging(0);
+ m_nlsr.getConfParameter().setDetailedLogging(0);
}
else
{
@@ -434,8 +429,7 @@
}
int
-ConfFileProcessor::processConfCommandIsHyperbolicCalc(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandIsHyperbolicCalc(string command)
{
if (command.empty())
{
@@ -445,15 +439,15 @@
{
if (command == "on" || command == "ON")
{
- pnlsr.getConfParameter().setIsHyperbolicCalc(1);
+ m_nlsr.getConfParameter().setIsHyperbolicCalc(1);
}
else if (command == "dry-run" || command == "DRY-RUN")
{
- pnlsr.getConfParameter().setIsHyperbolicCalc(2);
+ m_nlsr.getConfParameter().setIsHyperbolicCalc(2);
}
else if (command == "off" || command == "off")
{
- pnlsr.getConfParameter().setIsHyperbolicCalc(0);
+ m_nlsr.getConfParameter().setIsHyperbolicCalc(0);
}
else
{
@@ -464,13 +458,12 @@
}
int
-ConfFileProcessor::processConfCommandHyperbolicCordinate(Nlsr& pnlsr,
- string command)
+ConfFileProcessor::processConfCommandHyperbolicCordinate(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [hyperbolic-cordinate r 0]!" << endl;
- if (pnlsr.getConfParameter().getIsHyperbolicCalc() > 0)
+ if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0)
{
return -1;
}
@@ -483,15 +476,15 @@
double r, theta;
ssr >> r;
sst >> theta;
- pnlsr.getConfParameter().setCorR(r);
- pnlsr.getConfParameter().setCorTheta(theta);
+ m_nlsr.getConfParameter().setCorR(r);
+ m_nlsr.getConfParameter().setCorTheta(theta);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandNdnNeighbor(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandNdnNeighbor(string command)
{
if (command.empty())
{
@@ -511,14 +504,14 @@
int faceId;
sst >> faceId;
Adjacent adj(nt.getFirstToken(), faceId, 0.0, 0, 0);
- pnlsr.getAdl().insert(adj);
+ m_nlsr.getAdl().insert(adj);
}
}
return 0;
}
int
-ConfFileProcessor::processConfCommandNdnName(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandNdnName(string command)
{
if (command.empty())
{
@@ -526,19 +519,19 @@
}
else
{
- pnlsr.getNpl().insert(command);
+ m_nlsr.getNpl().insert(command);
}
return 0;
}
int
-ConfFileProcessor::processConfCommandLinkCost(Nlsr& pnlsr, string command)
+ConfFileProcessor::processConfCommandLinkCost(string command)
{
if (command.empty())
{
cerr << " Wrong command format ! [link-cost nbr/name cost]!" << endl;
- if (pnlsr.getConfParameter().getIsHyperbolicCalc() > 0)
+ if (m_nlsr.getConfParameter().getIsHyperbolicCalc() > 0)
{
return -1;
}
@@ -549,7 +542,7 @@
stringstream sst(nt.getRestOfLine().c_str());
double cost;
sst >> cost;
- pnlsr.getAdl().updateAdjacentLinkCost(nt.getFirstToken(), cost);
+ m_nlsr.getAdl().updateAdjacentLinkCost(nt.getFirstToken(), cost);
}
return 0;
}
diff --git a/src/conf-file-processor.hpp b/src/conf-file-processor.hpp
index a17ba12..c4015a3 100644
--- a/src/conf-file-processor.hpp
+++ b/src/conf-file-processor.hpp
@@ -4,85 +4,83 @@
#include "nlsr.hpp"
namespace nlsr {
+
class ConfFileProcessor
{
public:
- ConfFileProcessor()
- : m_confFileName()
+ ConfFileProcessor(Nlsr& nlsr, const string& cfile)
+ : m_confFileName(cfile)
+ , m_nlsr(nlsr)
{
}
- ConfFileProcessor(const string& cfile)
- {
- m_confFileName = cfile;
- }
-
- int processConfFile(Nlsr& pnlsr);
+ int processConfFile();
private:
int
- processConfCommand(Nlsr& pnlsr, string command);
+ processConfCommand(string command);
int
- processConfCommandNetwork(Nlsr& pnlsr, string command);
+ processConfCommandNetwork(string command);
int
- processConfCommandSiteName(Nlsr& pnlsr, string command);
+ processConfCommandSiteName(string command);
int
- processConfCommandRootKeyPrefix(Nlsr& pnlsr, string command);
+ processConfCommandRootKeyPrefix(string command);
int
- processConfCommandRouterName(Nlsr& pnlsr, string command);
+ processConfCommandRouterName(string command);
int
- processConfCommandInterestRetryNumber(Nlsr& pnlsr, string command);
+ processConfCommandInterestRetryNumber(string command);
int
- processConfCommandInterestResendTime(Nlsr& pnlsr, string command);
+ processConfCommandInterestResendTime(string command);
int
- processConfCommandLsaRefreshTime(Nlsr& pnlsr, string command);
+ processConfCommandLsaRefreshTime(string command);
int
- processConfCommandMaxFacesPerPrefix(Nlsr& pnlsr, string command);
+ processConfCommandMaxFacesPerPrefix(string command);
int
- processConfCommandTunnelType(Nlsr& pnlsr, string command);
+ processConfCommandTunnelType(string command);
int
- processConfCommandChronosyncSyncPrefix(Nlsr& pnlsr, string command);
+ processConfCommandChronosyncSyncPrefix(string command);
int
- processConfCommandLogDir(Nlsr& pnlsr, string command);
+ processConfCommandLogDir(string command);
int
- processConfCommandCertDir(Nlsr& pnlsr, string command);
+ processConfCommandCertDir(string command);
int
- processConfCommandDebugging(Nlsr& pnlsr, string command);
+ processConfCommandDebugging(string command);
int
- processConfCommandDetailedLogging(Nlsr& pnlsr, string command);
+ processConfCommandDetailedLogging(string command);
int
- processConfCommandIsHyperbolicCalc(Nlsr& pnlsr, string command);
+ processConfCommandIsHyperbolicCalc(string command);
int
- processConfCommandHyperbolicCordinate(Nlsr& pnlsr, string command);
+ processConfCommandHyperbolicCordinate(string command);
int
- processConfCommandNdnNeighbor(Nlsr& pnlsr, string command);
+ processConfCommandNdnNeighbor(string command);
int
- processConfCommandNdnName(Nlsr& pnlsr, string command);
+ processConfCommandNdnName(string command);
int
- processConfCommandLinkCost(Nlsr& pnlsr, string command);
+ processConfCommandLinkCost(string command);
private:
string m_confFileName;
+ Nlsr& m_nlsr;
};
} //namespace nlsr
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 0bd450c..e2b6dcf 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -18,7 +18,7 @@
string
-NameLsa::getKey()
+NameLsa::getKey() const
{
string key;
key = m_origRouter + "/" + boost::lexical_cast<std::string>(1);
@@ -110,8 +110,9 @@
-CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
- , double r, double theta)
+CoordinateLsa::CoordinateLsa(string origR, uint8_t lst, uint32_t lsn,
+ uint32_t lt
+ , double r, double theta)
{
m_origRouter = origR;
m_lsType = lst;
@@ -122,7 +123,7 @@
}
string
-CorLsa::getKey()
+CoordinateLsa::getKey() const
{
string key;
key = m_origRouter + "/" + boost::lexical_cast<std::string>(3);
@@ -130,7 +131,7 @@
}
bool
-CorLsa::isEqual(CorLsa& clsa)
+CoordinateLsa::isEqual(const CoordinateLsa& clsa)
{
return (std::abs(m_corRad - clsa.getCorRadius()) <
std::numeric_limits<double>::epsilon()) &&
@@ -139,7 +140,7 @@
}
string
-CorLsa::getData()
+CoordinateLsa::getData()
{
string corLsaData;
corLsaData = m_origRouter + "|";
@@ -152,7 +153,7 @@
}
bool
-CorLsa::initializeFromContent(string content)
+CoordinateLsa::initializeFromContent(string content)
{
Tokenizer nt(content, "|");
m_origRouter = nt.getNextToken();
@@ -176,7 +177,7 @@
}
std::ostream&
-operator<<(std::ostream& os, CorLsa& cLsa)
+operator<<(std::ostream& os, const CoordinateLsa& cLsa)
{
os << "Cor Lsa: " << endl;
os << " Origination Router: " << cLsa.getOrigRouter() << endl;
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 23ff395..c795159 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -118,7 +118,7 @@
}
std::string
- getKey();
+ getKey() const;
std::string
getData();
@@ -194,10 +194,10 @@
std::ostream&
operator<<(std::ostream& os, AdjLsa& aLsa);
-class CorLsa: public Lsa
+class CoordinateLsa: public Lsa
{
public:
- CorLsa()
+ CoordinateLsa()
: Lsa()
, m_corRad(0)
, m_corTheta(0)
@@ -205,11 +205,11 @@
setLsType(3);
}
- CorLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt
- , double r, double theta);
+ CoordinateLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt
+ , double r, double theta);
std::string
- getKey();
+ getKey() const;
std::string
getData();
@@ -218,7 +218,7 @@
initializeFromContent(std::string content);
double
- getCorRadius()
+ getCorRadius() const
{
if (m_corRad >= 0)
{
@@ -237,7 +237,7 @@
}
double
- getCorTheta()
+ getCorTheta() const
{
return m_corTheta;
}
@@ -249,7 +249,7 @@
}
bool
- isEqual(CorLsa& clsa);
+ isEqual(const CoordinateLsa& clsa);
private:
double m_corRad;
@@ -258,7 +258,7 @@
};
std::ostream&
-operator<<(std::ostream& os, CorLsa& cLsa);
+operator<<(std::ostream& os, const CoordinateLsa& cLsa);
}//namespace nlsr
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index de65646..e4bbb4f 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -14,7 +14,7 @@
}
static bool
-nameLsaCompareByKey(NameLsa& nlsa1, string& key)
+nameLsaCompareByKey(const NameLsa& nlsa1, const string& key)
{
return nlsa1.getKey() == key;
}
@@ -32,27 +32,26 @@
return installNameLsa(pnlsr, nameLsa);
}
-std::pair<NameLsa&, bool>
-Lsdb::getNameLsa(string key)
+NameLsa*
+Lsdb::findNameLsa(const string key)
{
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
m_nameLsdb.end(),
bind(nameLsaCompareByKey, _1, key));
if (it != m_nameLsdb.end())
{
- return std::make_pair(boost::ref((*it)), true);
+ return &(*it);
}
- NameLsa nlsa;
- return std::make_pair(boost::ref(nlsa), false);
+ return 0;
}
bool
Lsdb::isNameLsaNew(string key, uint64_t seqNo)
{
- std::pair<NameLsa&, bool> nameLsaCheck = getNameLsa(key);
- if (nameLsaCheck.second)
+ NameLsa* nameLsaCheck = findNameLsa(key);
+ if (nameLsaCheck != 0)
{
- if (nameLsaCheck.first.getLsSeqNo() < seqNo)
+ if (nameLsaCheck->getLsSeqNo() < seqNo)
{
return true;
}
@@ -76,8 +75,8 @@
Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa)
{
int timeToExpire = m_lsaRefreshTime;
- std::pair<NameLsa&, bool> chkNameLsa = getNameLsa(nlsa.getKey());
- if (!chkNameLsa.second)
+ NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
+ if (chkNameLsa == 0)
{
addNameLsa(nlsa);
nlsa.writeLog();
@@ -107,23 +106,23 @@
}
else
{
- if (chkNameLsa.first.getLsSeqNo() < nlsa.getLsSeqNo())
+ if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo())
{
- chkNameLsa.first.writeLog();
- chkNameLsa.first.setLsSeqNo(nlsa.getLsSeqNo());
- chkNameLsa.first.setLifeTime(nlsa.getLifeTime());
- chkNameLsa.first.getNpl().sort();
+ chkNameLsa->writeLog();
+ chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
+ chkNameLsa->setLifeTime(nlsa.getLifeTime());
+ chkNameLsa->getNpl().sort();
nlsa.getNpl().sort();
std::list<string> nameToAdd;
std::set_difference(nlsa.getNpl().getNameList().begin(),
nlsa.getNpl().getNameList().end(),
- chkNameLsa.first.getNpl().getNameList().begin(),
- chkNameLsa.first.getNpl().getNameList().end(),
+ chkNameLsa->getNpl().getNameList().begin(),
+ chkNameLsa->getNpl().getNameList().end(),
std::inserter(nameToAdd, nameToAdd.begin()));
for (std::list<string>::iterator it = nameToAdd.begin(); it != nameToAdd.end();
++it)
{
- chkNameLsa.first.addName((*it));
+ chkNameLsa->addName((*it));
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
@@ -133,15 +132,15 @@
}
}
std::list<string> nameToRemove;
- std::set_difference(chkNameLsa.first.getNpl().getNameList().begin(),
- chkNameLsa.first.getNpl().getNameList().end(),
+ std::set_difference(chkNameLsa->getNpl().getNameList().begin(),
+ chkNameLsa->getNpl().getNameList().end(),
nlsa.getNpl().getNameList().begin(),
nlsa.getNpl().getNameList().end(),
std::inserter(nameToRemove, nameToRemove.begin()));
for (std::list<string>::iterator it = nameToRemove.begin();
it != nameToRemove.end(); ++it)
{
- chkNameLsa.first.removeName((*it));
+ chkNameLsa->removeName((*it));
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
@@ -155,12 +154,12 @@
timeToExpire = nlsa.getLifeTime();
}
cancelScheduleLsaExpiringEvent(pnlsr,
- chkNameLsa.first.getExpiringEventId());
- chkNameLsa.first.setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
- nlsa.getKey(),
- nlsa.getLsSeqNo(),
- timeToExpire));
- chkNameLsa.first.writeLog();
+ chkNameLsa->getExpiringEventId());
+ chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
+ nlsa.getKey(),
+ nlsa.getLsSeqNo(),
+ timeToExpire));
+ chkNameLsa->writeLog();
}
}
return true;
@@ -236,46 +235,45 @@
static bool
-corLsaCompareByKey(CorLsa& clsa, string& key)
+corLsaCompareByKey(const CoordinateLsa& clsa, const string& key)
{
return clsa.getKey() == key;
}
bool
-Lsdb::buildAndInstallOwnCorLsa(Nlsr& pnlsr)
+Lsdb::buildAndInstallOwnCoordinateLsa(Nlsr& pnlsr)
{
- CorLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
- , 3
- , pnlsr.getSm().getCorLsaSeq() + 1
- , pnlsr.getConfParameter().getRouterDeadInterval()
- , pnlsr.getConfParameter().getCorR()
- , pnlsr.getConfParameter().getCorTheta());
+ CoordinateLsa corLsa(pnlsr.getConfParameter().getRouterPrefix()
+ , 3
+ , pnlsr.getSm().getCorLsaSeq() + 1
+ , pnlsr.getConfParameter().getRouterDeadInterval()
+ , pnlsr.getConfParameter().getCorR()
+ , pnlsr.getConfParameter().getCorTheta());
pnlsr.getSm().setCorLsaSeq(pnlsr.getSm().getCorLsaSeq() + 1);
- installCorLsa(pnlsr, corLsa);
+ installCoordinateLsa(pnlsr, corLsa);
return true;
}
-std::pair<CorLsa&, bool>
-Lsdb::getCorLsa(string key)
+CoordinateLsa*
+Lsdb::findCoordinateLsa(const string& key)
{
- std::list<CorLsa>::iterator it = std::find_if(m_corLsdb.begin(),
- m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
+ std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
+ m_corLsdb.end(),
+ bind(corLsaCompareByKey, _1, key));
if (it != m_corLsdb.end())
{
- return std::make_pair(boost::ref((*it)), true);
+ return &(*it);
}
- CorLsa clsa;
- return std::make_pair(boost::ref(clsa), false);
+ return 0;
}
bool
-Lsdb::isCorLsaNew(string key, uint64_t seqNo)
+Lsdb::isCoordinateLsaNew(const string& key, uint64_t seqNo)
{
- std::pair<CorLsa&, bool> corLsaCheck = getCorLsa(key);
- if (corLsaCheck.second)
+ CoordinateLsa* clsa = findCoordinateLsa(key);
+ if (clsa != 0)
{
- if (corLsaCheck.first.getLsSeqNo() < seqNo)
+ if (clsa->getLsSeqNo() < seqNo)
{
return true;
}
@@ -288,22 +286,23 @@
}
ndn::EventId
-Lsdb::scheduleCorLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
+Lsdb::scheduleCoordinateLsaExpiration(Nlsr& pnlsr, const string& key, int seqNo,
+ int expTime)
{
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
- ndn::bind(&Lsdb::exprireOrRefreshCorLsa,
+ ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
this, boost::ref(pnlsr),
key, seqNo));
}
bool
-Lsdb::installCorLsa(Nlsr& pnlsr, CorLsa& clsa)
+Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa)
{
int timeToExpire = m_lsaRefreshTime;
- std::pair<CorLsa&, bool> chkCorLsa = getCorLsa(clsa.getKey());
- if (!chkCorLsa.second)
+ CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
+ if (chkCorLsa == 0)
{
- addCorLsa(clsa);
+ addCoordinateLsa(clsa);
printCorLsdb(); //debugging purpose
if (clsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
@@ -318,19 +317,19 @@
{
timeToExpire = clsa.getLifeTime();
}
- scheduleCorLsaExpiration(pnlsr, clsa.getKey(),
- clsa.getLsSeqNo(), timeToExpire);
+ scheduleCoordinateLsaExpiration(pnlsr, clsa.getKey(),
+ clsa.getLsSeqNo(), timeToExpire);
}
else
{
- if (chkCorLsa.first.getLsSeqNo() < clsa.getLsSeqNo())
+ if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo())
{
- chkCorLsa.first.setLsSeqNo(clsa.getLsSeqNo());
- chkCorLsa.first.setLifeTime(clsa.getLifeTime());
- if (!chkCorLsa.first.isEqual(clsa))
+ chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
+ chkCorLsa->setLifeTime(clsa.getLifeTime());
+ if (!chkCorLsa->isEqual(clsa))
{
- chkCorLsa.first.setCorRadius(clsa.getCorRadius());
- chkCorLsa.first.setCorTheta(clsa.getCorTheta());
+ chkCorLsa->setCorRadius(clsa.getCorRadius());
+ chkCorLsa->setCorTheta(clsa.getCorTheta());
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
{
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
@@ -341,23 +340,23 @@
timeToExpire = clsa.getLifeTime();
}
cancelScheduleLsaExpiringEvent(pnlsr,
- chkCorLsa.first.getExpiringEventId());
- chkCorLsa.first.setExpiringEventId(scheduleCorLsaExpiration(pnlsr,
- clsa.getKey(),
- clsa.getLsSeqNo(),
- timeToExpire));
+ chkCorLsa->getExpiringEventId());
+ chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(pnlsr,
+ clsa.getKey(),
+ clsa.getLsSeqNo(),
+ timeToExpire));
}
}
return true;
}
bool
-Lsdb::addCorLsa(CorLsa& clsa)
+Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
{
- std::list<CorLsa>::iterator it = std::find_if(m_corLsdb.begin(),
- m_corLsdb.end(),
- bind(corLsaCompareByKey, _1,
- clsa.getKey()));
+ std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
+ m_corLsdb.end(),
+ bind(corLsaCompareByKey, _1,
+ clsa.getKey()));
if (it == m_corLsdb.end())
{
m_corLsdb.push_back(clsa);
@@ -367,11 +366,11 @@
}
bool
-Lsdb::removeCorLsa(Nlsr& pnlsr, string& key)
+Lsdb::removeCoordinateLsa(Nlsr& pnlsr, const string& key)
{
- std::list<CorLsa>::iterator it = std::find_if(m_corLsdb.begin(),
- m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
+ std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
+ m_corLsdb.end(),
+ bind(corLsaCompareByKey, _1, key));
if (it != m_corLsdb.end())
{
if ((*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
@@ -385,11 +384,11 @@
}
bool
-Lsdb::doesCorLsaExist(string key)
+Lsdb::doesCoordinateLsaExist(const string& key)
{
- std::list<CorLsa>::iterator it = std::find_if(m_corLsdb.begin(),
- m_corLsdb.end(),
- bind(corLsaCompareByKey, _1, key));
+ std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
+ m_corLsdb.end(),
+ bind(corLsaCompareByKey, _1, key));
if (it == m_corLsdb.end())
{
return false;
@@ -401,7 +400,7 @@
Lsdb::printCorLsdb() //debugging
{
cout << "---------------Cor LSDB-------------------" << endl;
- for (std::list<CorLsa>::iterator it = m_corLsdb.begin();
+ for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin();
it != m_corLsdb.end() ; it++)
{
cout << (*it) << endl;
@@ -468,28 +467,27 @@
return false;
}
-std::pair<AdjLsa&, bool>
-Lsdb::getAdjLsa(string key)
+AdjLsa*
+Lsdb::findAdjLsa(const string key)
{
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
m_adjLsdb.end(),
bind(adjLsaCompareByKey, _1, key));
if (it != m_adjLsdb.end())
{
- return std::make_pair(boost::ref((*it)), true);
+ return &(*it);
}
- AdjLsa alsa;
- return std::make_pair(boost::ref(alsa), false);
+ return 0;
}
bool
Lsdb::isAdjLsaNew(string key, uint64_t seqNo)
{
- std::pair<AdjLsa&, bool> adjLsaCheck = getAdjLsa(key);
- if (adjLsaCheck.second)
+ AdjLsa* adjLsaCheck = findAdjLsa(key);
+ if (adjLsaCheck != 0)
{
- if (adjLsaCheck.first.getLsSeqNo() < seqNo)
+ if (adjLsaCheck->getLsSeqNo() < seqNo)
{
return true;
}
@@ -515,8 +513,8 @@
Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa)
{
int timeToExpire = m_lsaRefreshTime;
- std::pair<AdjLsa&, bool> chkAdjLsa = getAdjLsa(alsa.getKey());
- if (!chkAdjLsa.second)
+ AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
+ if (chkAdjLsa == 0)
{
addAdjLsa(alsa);
alsa.addNptEntries(pnlsr);
@@ -530,26 +528,25 @@
}
else
{
- if (chkAdjLsa.first.getLsSeqNo() < alsa.getLsSeqNo())
+ if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo())
{
- chkAdjLsa.first.setLsSeqNo(alsa.getLsSeqNo());
- chkAdjLsa.first.setLifeTime(alsa.getLifeTime());
- if (!chkAdjLsa.first.isEqual(alsa))
+ chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
+ chkAdjLsa->setLifeTime(alsa.getLifeTime());
+ if (!chkAdjLsa->isEqual(alsa))
{
- chkAdjLsa.first.getAdl().reset();
- chkAdjLsa.first.getAdl().addAdjacentsFromAdl(alsa.getAdl());
+ chkAdjLsa->getAdl().reset();
+ chkAdjLsa->getAdl().addAdjacentsFromAdl(alsa.getAdl());
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
}
if (alsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
{
timeToExpire = alsa.getLifeTime();
}
- cancelScheduleLsaExpiringEvent(pnlsr,
- chkAdjLsa.first.getExpiringEventId());
- chkAdjLsa.first.setExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
- alsa.getKey(),
- alsa.getLsSeqNo(),
- timeToExpire));
+ cancelScheduleLsaExpiringEvent(pnlsr, chkAdjLsa->getExpiringEventId());
+ chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
+ alsa.getKey(),
+ alsa.getLsSeqNo(),
+ timeToExpire));
}
}
return true;
@@ -622,19 +619,19 @@
{
cout << "Lsdb::exprireOrRefreshNameLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
- std::pair<NameLsa&, bool> chkNameLsa = getNameLsa(lsaKey);
- if (chkNameLsa.second)
+ NameLsa* chkNameLsa = findNameLsa(lsaKey);
+ if (chkNameLsa != 0)
{
- cout << " LSA Exists with seq no: " << chkNameLsa.first.getLsSeqNo() << endl;
- if (chkNameLsa.first.getLsSeqNo() == seqNo)
+ cout << " LSA Exists with seq no: " << chkNameLsa->getLsSeqNo() << endl;
+ if (chkNameLsa->getLsSeqNo() == seqNo)
{
- if (chkNameLsa.first.getOrigRouter() == m_thisRouterPrefix)
+ if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix)
{
- chkNameLsa.first.writeLog();
+ chkNameLsa->writeLog();
cout << "Own Name LSA, so refreshing name LSA" << endl;
- chkNameLsa.first.setLsSeqNo(chkNameLsa.first.getLsSeqNo() + 1);
- pnlsr.getSm().setNameLsaSeq(chkNameLsa.first.getLsSeqNo());
- chkNameLsa.first.writeLog();
+ chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
+ pnlsr.getSm().setNameLsaSeq(chkNameLsa->getLsSeqNo());
+ chkNameLsa->writeLog();
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
@@ -654,17 +651,17 @@
{
cout << "Lsdb::exprireOrRefreshAdjLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
- std::pair<AdjLsa&, bool> chkAdjLsa = getAdjLsa(lsaKey);
- if (chkAdjLsa.second)
+ AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
+ if (chkAdjLsa != 0)
{
- cout << " LSA Exists with seq no: " << chkAdjLsa.first.getLsSeqNo() << endl;
- if (chkAdjLsa.first.getLsSeqNo() == seqNo)
+ cout << " LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo() << endl;
+ if (chkAdjLsa->getLsSeqNo() == seqNo)
{
- if (chkAdjLsa.first.getOrigRouter() == m_thisRouterPrefix)
+ if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix)
{
cout << "Own Adj LSA, so refreshing Adj LSA" << endl;
- chkAdjLsa.first.setLsSeqNo(chkAdjLsa.first.getLsSeqNo() + 1);
- pnlsr.getSm().setAdjLsaSeq(chkAdjLsa.first.getLsSeqNo());
+ chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
+ pnlsr.getSm().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
@@ -682,21 +679,22 @@
}
void
-Lsdb::exprireOrRefreshCorLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo)
+Lsdb::exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const string& lsaKey,
+ uint64_t seqNo)
{
cout << "Lsdb::exprireOrRefreshCorLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
- std::pair<CorLsa&, bool> chkCorLsa = getCorLsa(lsaKey);
- if (chkCorLsa.second)
+ CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
+ if (chkCorLsa != 0)
{
- cout << " LSA Exists with seq no: " << chkCorLsa.first.getLsSeqNo() << endl;
- if (chkCorLsa.first.getLsSeqNo() == seqNo)
+ cout << " LSA Exists with seq no: " << chkCorLsa->getLsSeqNo() << endl;
+ if (chkCorLsa->getLsSeqNo() == seqNo)
{
- if (chkCorLsa.first.getOrigRouter() == m_thisRouterPrefix)
+ if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix)
{
cout << "Own Cor LSA, so refreshing Cor LSA" << endl;
- chkCorLsa.first.setLsSeqNo(chkCorLsa.first.getLsSeqNo() + 1);
- pnlsr.getSm().setCorLsaSeq(chkCorLsa.first.getLsSeqNo());
+ chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
+ pnlsr.getSm().setCorLsaSeq(chkCorLsa->getLsSeqNo());
// publish routing update
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
+ pnlsr.getConfParameter().getRouterPrefix();
@@ -705,7 +703,7 @@
else
{
cout << "Other's Cor LSA, so removing form LSDB" << endl;
- removeCorLsa(pnlsr, lsaKey);
+ removeCoordinateLsa(pnlsr, lsaKey);
}
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
{
@@ -741,7 +739,7 @@
}
else if (lsType == 3)
{
- return doesCorLsaExist(key);
+ return doesCoordinateLsaExist(key);
}
return false;
}
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 96f0ff1..9814034 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -23,8 +23,8 @@
bool
buildAndInstallOwnNameLsa(Nlsr& pnlsr);
- std::pair<NameLsa&, bool>
- getNameLsa(std::string key);
+ NameLsa*
+ findNameLsa(const std::string key);
bool
installNameLsa(Nlsr& pnlsr, NameLsa& nlsa);
@@ -40,19 +40,19 @@
//function related to Cor LSDB
bool
- buildAndInstallOwnCorLsa(Nlsr& pnlsr);
+ buildAndInstallOwnCoordinateLsa(Nlsr& pnlsr);
- std::pair<CorLsa&, bool>
- getCorLsa(std::string key);
+ CoordinateLsa*
+ findCoordinateLsa(const std::string& key);
bool
- installCorLsa(Nlsr& pnlsr, CorLsa& clsa);
+ installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa);
bool
- removeCorLsa(Nlsr& pnlsr, std::string& key);
+ removeCoordinateLsa(Nlsr& pnlsr, const std::string& key);
bool
- isCorLsaNew(std::string key, uint64_t seqNo);
+ isCoordinateLsaNew(const std::string& key, uint64_t seqNo);
void
printCorLsdb(); //debugging
@@ -72,8 +72,8 @@
bool
installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa);
- std::pair<AdjLsa&, bool>
- getAdjLsa(std::string key);
+ AdjLsa*
+ findAdjLsa(std::string key);
std::list<AdjLsa>&
getAdjLsdb();
@@ -97,10 +97,10 @@
bool
- addCorLsa(CorLsa& clsa);
+ addCoordinateLsa(CoordinateLsa& clsa);
bool
- doesCorLsaExist(std::string key);
+ doesCoordinateLsaExist(const std::string& key);
bool
addAdjLsa(AdjLsa& alsa);
@@ -121,10 +121,12 @@
exprireOrRefreshAdjLsa(Nlsr& pnlsr, std::string lsaKey, uint64_t seqNo);
ndn::EventId
- scheduleCorLsaExpiration(Nlsr& pnlsr, std::string key, int seqNo, int expTime);
+ scheduleCoordinateLsaExpiration(Nlsr& pnlsr, const std::string& key, int seqNo,
+ int expTime);
void
- exprireOrRefreshCorLsa(Nlsr& pnlsr, std::string lsaKey, uint64_t seqNo);
+ exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const std::string& lsaKey,
+ uint64_t seqNo);
private:
@@ -133,7 +135,7 @@
std::list<NameLsa> m_nameLsdb;
std::list<AdjLsa> m_adjLsdb;
- std::list<CorLsa> m_corLsdb;
+ std::list<CoordinateLsa> m_corLsdb;
int m_lsaRefreshTime;
std::string m_thisRouterPrefix;
diff --git a/src/main.cpp b/src/main.cpp
index 20c132e..b074385 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,47 +26,46 @@
int
main(int argc, char** argv)
{
- nlsr::Nlsr nlsr_;
+ nlsr::Nlsr nlsr;
string programName(argv[0]);
- nlsr_.setConfFileName("nlsr.conf");
+ nlsr.setConfFileName("nlsr.conf");
int opt;
while ((opt = getopt(argc, argv, "df:p:h")) != -1)
{
switch (opt)
- {
+ {
case 'f':
- nlsr_.setConfFileName(optarg);
+ nlsr.setConfFileName(optarg);
break;
case 'd':
- nlsr_.setIsDaemonProcess(optarg);
+ nlsr.setIsDaemonProcess(optarg);
break;
case 'p':
{
stringstream sst(optarg);
int ap;
sst >> ap;
- nlsr_.setApiPort(ap);
+ nlsr.setApiPort(ap);
}
break;
case 'h':
-
default:
- nlsr_.usage(programName);
+ nlsr.usage(programName);
return EXIT_FAILURE;
- }
+ }
}
- ConfFileProcessor cfp(nlsr_.getConfFileName());
- int res = cfp.processConfFile(nlsr_);
+ ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
+ int res = cfp.processConfFile();
if (res < 0)
{
std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
std::endl;
return EXIT_FAILURE;
}
- nlsr_.initialize();
+ nlsr.initialize();
try
{
- nlsr_.startEventLoop();
+ nlsr.startEventLoop();
}
catch (std::exception& e)
{
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 00bd510..70a07cf 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -28,9 +28,8 @@
Nlsr::setInterestFilterNlsr(const string& name)
{
getNlsrFace()->setInterestFilter(name,
- func_lib::bind(&InterestManager::processInterest, &m_im,
- boost::ref(*this), _1, _2),
- func_lib::bind(&Nlsr::registrationFailed, this, _1));
+ ndn::bind(&InterestManager::processInterest, &m_im,_1, _2),
+ ndn::bind(&Nlsr::registrationFailed, this, _1));
}
void
@@ -52,7 +51,7 @@
m_npl.print();
/* debugging purpose end */
m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
- m_nlsrLsdb.buildAndInstallOwnCorLsa(boost::ref(*this));
+ m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
setInterestFilterNlsr(m_confParam.getRouterPrefix());
setInterestFilterNlsr(m_confParam.getChronosyncLsaPrefix() +
m_confParam.getRouterPrefix());
@@ -60,7 +59,7 @@
m_slh.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
m_slh.createSyncSocket(boost::ref(*this));
m_slh.publishKeyUpdate(m_km);
- m_im.scheduleInfoInterest(boost::ref(*this), 10);
+ m_im.scheduleInfoInterest(10);
}
void
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index bef8189..ac254c3 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -33,13 +33,13 @@
Nlsr()
: m_io(new boost::asio::io_service)
, m_nlsrFace(new Face(ndn::shared_ptr<boost::asio::io_service>(&*m_io,
- &NullDeleter)))
+ &NullDeleter)))
, m_scheduler(*m_io)
, m_confParam()
, m_adl()
, m_npl()
- , m_im()
- , m_dm()
+ , m_im(*this)
+ , m_dm(*this)
, m_sm()
, m_km()
, m_isDaemonProcess(false)
diff --git a/src/route/npt.cpp b/src/route/npt.cpp
index 665dbb2..e094fe3 100644
--- a/src/route/npt.cpp
+++ b/src/route/npt.cpp
@@ -83,11 +83,11 @@
void
Npt::addNpteByDestName(string name, string destRouter, Nlsr& pnlsr)
{
- std::pair<RoutingTableEntry&, bool> rteCheck =
+ RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
- if (rteCheck.second)
+ if (rteCheck != 0)
{
- addNpte(name, rteCheck.first, pnlsr);
+ addNpte(name, *(rteCheck) , pnlsr);
}
else
{
@@ -99,11 +99,11 @@
void
Npt::removeNpte(string name, string destRouter, Nlsr& pnlsr)
{
- std::pair<RoutingTableEntry&, bool> rteCheck =
+ RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
- if (rteCheck.second)
+ if (rteCheck != 0)
{
- removeNpte(name, rteCheck.first, pnlsr);
+ removeNpte(name, *(rteCheck), pnlsr);
}
else
{
@@ -122,11 +122,11 @@
for (std::list<RoutingTableEntry>::iterator rteit = rteList.begin();
rteit != rteList.end(); ++rteit)
{
- std::pair<RoutingTableEntry&, bool> rteCheck =
+ RoutingTableEntry* rteCheck =
pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
- if (rteCheck.second)
+ if (rteCheck != 0)
{
- addNpte((*it).getNamePrefix(), rteCheck.first, pnlsr);
+ addNpte((*it).getNamePrefix(), *(rteCheck), pnlsr);
}
else
{
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 6c6dad3..d63904e 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -448,13 +448,14 @@
double distance = 0.0;
string srcRouterKey = pMap.getRouterNameByMappingNo(src) + "/3";
string destRouterKey = pMap.getRouterNameByMappingNo(dest) + "/3";
- double srcRadius = (pnlsr.getLsdb().getCorLsa(
- srcRouterKey).first).getCorRadius();
- double srcTheta = (pnlsr.getLsdb().getCorLsa(srcRouterKey).first).getCorTheta();
- double destRadius = (pnlsr.getLsdb().getCorLsa(
- destRouterKey).first).getCorRadius();
- double destTheta = (pnlsr.getLsdb().getCorLsa(
- destRouterKey).first).getCorTheta();
+ double srcRadius = (pnlsr.getLsdb().findCoordinateLsa(
+ srcRouterKey))->getCorRadius();
+ double srcTheta = (pnlsr.getLsdb().findCoordinateLsa(
+ srcRouterKey))->getCorTheta();
+ double destRadius = (pnlsr.getLsdb().findCoordinateLsa(
+ destRouterKey))->getCorRadius();
+ double destTheta = (pnlsr.getLsdb().findCoordinateLsa(
+ destRouterKey))->getCorTheta();
double diffTheta = fabs(srcTheta - destTheta);
if (diffTheta > MATH_PI)
{
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index 9e2c19c..097e95a 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -140,8 +140,8 @@
void
RoutingTable::addNextHop(string destRouter, NextHop& nh)
{
- std::pair<RoutingTableEntry&, bool> rte = findRoutingTableEntry(destRouter);
- if (!rte.second)
+ RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter);
+ if (rteChk == 0)
{
RoutingTableEntry rte(destRouter);
rte.getNhl().addNextHop(nh);
@@ -149,22 +149,21 @@
}
else
{
- (rte.first).getNhl().addNextHop(nh);
+ rteChk->getNhl().addNextHop(nh);
}
}
-std::pair<RoutingTableEntry&, bool>
-RoutingTable::findRoutingTableEntry(string destRouter)
+RoutingTableEntry*
+RoutingTable::findRoutingTableEntry(const string destRouter)
{
std::list<RoutingTableEntry>::iterator it = std::find_if(m_rTable.begin(),
m_rTable.end(),
bind(&routingTableEntryCompare, _1, destRouter));
if (it != m_rTable.end())
{
- return std::make_pair(boost::ref((*it)), true);
+ return &(*it);
}
- RoutingTableEntry rteEmpty;
- return std::make_pair(boost::ref(rteEmpty), false);
+ return 0;
}
void
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index cc04915..8518b12 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -34,8 +34,8 @@
void
printDryRoutingTable();
- std::pair<RoutingTableEntry&, bool>
- findRoutingTableEntry(std::string destRouter);
+ RoutingTableEntry*
+ findRoutingTableEntry(const std::string destRouter);
void
scheduleRoutingTableCalculation(Nlsr& pnlsr);
diff --git a/src/security/certificate-store.cpp b/src/security/certificate-store.cpp
index 3ac5361..6990b07 100644
--- a/src/security/certificate-store.cpp
+++ b/src/security/certificate-store.cpp
@@ -58,7 +58,6 @@
}
}
}
-
//remove that entry from waiting list
m_waitingList.remove(respCertName);
}
@@ -149,7 +148,6 @@
{
return it->getIsSignerVerified();
}
-
return false;
}
diff --git a/src/security/key-manager.cpp b/src/security/key-manager.cpp
index 5ab63a8..7379c1b 100644
--- a/src/security/key-manager.cpp
+++ b/src/security/key-manager.cpp
@@ -339,27 +339,21 @@
ndn::SignatureSha256WithRsa signature(packet.getSignature());
std::string signingCertName = signature.getKeyLocator().getName().toUri();
std::string packetName = packet.getName().toUri();
-
std::cout << "Packet Name: " << packetName << std::endl;
std::cout << "Signee Name: " << signingCertName << std::endl;
-
int paketCertType = getKeyTypeFromName(packetName);
int signingCertType = getKeyTypeFromName(signingCertName);
-
if (signingCertType > paketCertType) //lower level Cert can not sign
{
//upper level Cert
return false;
}
-
if ((signingCertType == paketCertType) && (paketCertType != KEY_TYPE_ROOT))
{
return false;
}
-
std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> signee =
m_certStore.getCertificateFromStore(signingCertName);
-
if (signee.second)
{
switch (paketCertType)
@@ -393,7 +387,7 @@
else
{
std::cout << "Certificate Not Found in store. Sending Interest" << std::endl;
- pnlsr.getIm().expressInterest(pnlsr, signingCertName, 3,
+ pnlsr.getIm().expressInterest(signingCertName, 3,
pnlsr.getConfParameter().getInterestResendTime());
return false;
}
diff --git a/src/security/key-manager.hpp b/src/security/key-manager.hpp
index 9becfe2..c343108 100644
--- a/src/security/key-manager.hpp
+++ b/src/security/key-manager.hpp
@@ -180,9 +180,7 @@
verify(T& packet)
{
std::cout << "KeyManager::verify Called" << std::endl;
-
return verifyDataPacket(packet);
-
return false;
}
diff --git a/src/security/waiting-list-entry.cpp b/src/security/waiting-list-entry.cpp
index 1172698..6b83904 100644
--- a/src/security/waiting-list-entry.cpp
+++ b/src/security/waiting-list-entry.cpp
@@ -20,7 +20,6 @@
m_waitingCerts.push_back(waiteeName);
return true;
}
-
return false;
}
diff --git a/src/security/waiting-list.cpp b/src/security/waiting-list.cpp
index dbf9b68..39a7192 100644
--- a/src/security/waiting-list.cpp
+++ b/src/security/waiting-list.cpp
@@ -17,10 +17,8 @@
{
return std::make_pair(*(it), true);
}
-
WaitingListEntry wle;
return std::make_pair(wle, false);
-
}
bool