src: Replace Tokenizer with the methods of ndn::Name
Purpose of this commit is to replace Tokenizer in all places except conf-file-processor.*pp with the methods of ndn::Name. One static method in class NameHelper is added. Tokenizer will be removed finally when configuration file parsing commit is complete. Refs: 1533 Change-Id: I14a67655eb963c5cc5b045c3c9f7d516e405ff19
This commit is contained in:
1 parent
fdbddb114e
commit
31d1d4b331
40 files changed
+1211
-1362
No files matched your search
+14
-13
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <ndn-cxx/common.hpp>
|
||||
#include "adjacency-list.hpp"
|
||||
#include "adjacent.hpp"
|
||||
#include "nlsr.hpp"
|
||||
@@ -41,7 +41,7 @@ AdjacencyList::addAdjacents(AdjacencyList& adl)
|
||||
}
|
||||
|
||||
int32_t
|
||||
AdjacencyList::updateAdjacentStatus(const string& adjName, int32_t s)
|
||||
AdjacencyList::updateAdjacentStatus(const ndn::Name& adjName, int32_t s)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(adjName);
|
||||
if (it == m_adjList.end())
|
||||
@@ -53,7 +53,7 @@ AdjacencyList::updateAdjacentStatus(const string& adjName, int32_t s)
|
||||
}
|
||||
|
||||
Adjacent
|
||||
AdjacencyList::getAdjacent(const string& adjName)
|
||||
AdjacencyList::getAdjacent(const ndn::Name& adjName)
|
||||
{
|
||||
Adjacent adj(adjName);
|
||||
std::list<Adjacent>::iterator it = find(adjName);
|
||||
@@ -96,7 +96,7 @@ AdjacencyList::operator==(AdjacencyList& adl)
|
||||
}
|
||||
|
||||
int32_t
|
||||
AdjacencyList::updateAdjacentLinkCost(const string& adjName, double lc)
|
||||
AdjacencyList::updateAdjacentLinkCost(const ndn::Name& adjName, double lc)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(adjName);
|
||||
if (it == m_adjList.end())
|
||||
@@ -108,7 +108,7 @@ AdjacencyList::updateAdjacentLinkCost(const string& adjName, double lc)
|
||||
}
|
||||
|
||||
bool
|
||||
AdjacencyList::isNeighbor(const string& adjName)
|
||||
AdjacencyList::isNeighbor(const ndn::Name& adjName)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(adjName);
|
||||
if (it == m_adjList.end())
|
||||
@@ -119,7 +119,7 @@ AdjacencyList::isNeighbor(const string& adjName)
|
||||
}
|
||||
|
||||
void
|
||||
AdjacencyList::incrementTimedOutInterestCount(const string& neighbor)
|
||||
AdjacencyList::incrementTimedOutInterestCount(const ndn::Name& neighbor)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(neighbor);
|
||||
if (it == m_adjList.end())
|
||||
@@ -130,7 +130,8 @@ AdjacencyList::incrementTimedOutInterestCount(const string& neighbor)
|
||||
}
|
||||
|
||||
void
|
||||
AdjacencyList::setTimedOutInterestCount(const string& neighbor, uint32_t count)
|
||||
AdjacencyList::setTimedOutInterestCount(const ndn::Name& neighbor,
|
||||
uint32_t count)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(neighbor);
|
||||
if (it != m_adjList.end())
|
||||
@@ -140,7 +141,7 @@ AdjacencyList::setTimedOutInterestCount(const string& neighbor, uint32_t count)
|
||||
}
|
||||
|
||||
int32_t
|
||||
AdjacencyList::getTimedOutInterestCount(const string& neighbor)
|
||||
AdjacencyList::getTimedOutInterestCount(const ndn::Name& neighbor)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(neighbor);
|
||||
if (it == m_adjList.end())
|
||||
@@ -151,7 +152,7 @@ AdjacencyList::getTimedOutInterestCount(const string& neighbor)
|
||||
}
|
||||
|
||||
uint32_t
|
||||
AdjacencyList::getStatusOfNeighbor(const string& neighbor)
|
||||
AdjacencyList::getStatusOfNeighbor(const ndn::Name& neighbor)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(neighbor);
|
||||
if (it == m_adjList.end())
|
||||
@@ -162,7 +163,7 @@ AdjacencyList::getStatusOfNeighbor(const string& neighbor)
|
||||
}
|
||||
|
||||
void
|
||||
AdjacencyList::setStatusOfNeighbor(const string& neighbor, int32_t status)
|
||||
AdjacencyList::setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status)
|
||||
{
|
||||
std::list<Adjacent>::iterator it = find(neighbor);
|
||||
if (it != m_adjList.end())
|
||||
@@ -220,12 +221,12 @@ AdjacencyList::getNumOfActiveNeighbor()
|
||||
}
|
||||
|
||||
std::list<Adjacent>::iterator
|
||||
AdjacencyList::find(std::string adjName)
|
||||
AdjacencyList::find(const ndn::Name& adjName)
|
||||
{
|
||||
Adjacent adj(adjName);
|
||||
std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
|
||||
m_adjList.end(),
|
||||
bind(&Adjacent::compareName, &adj, _1));
|
||||
ndn::bind(&Adjacent::compare,
|
||||
_1, ndn::cref(adjName)));
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -21,31 +21,31 @@ public:
|
||||
insert(Adjacent& adjacent);
|
||||
|
||||
int32_t
|
||||
updateAdjacentStatus(const std::string& adjName, int32_t s);
|
||||
updateAdjacentStatus(const ndn::Name& adjName, int32_t s);
|
||||
|
||||
int32_t
|
||||
updateAdjacentLinkCost(const std::string& adjName, double lc);
|
||||
updateAdjacentLinkCost(const ndn::Name& adjName, double lc);
|
||||
|
||||
std::list<Adjacent>&
|
||||
getAdjList();
|
||||
|
||||
bool
|
||||
isNeighbor(const std::string& adjName);
|
||||
isNeighbor(const ndn::Name& adjName);
|
||||
|
||||
void
|
||||
incrementTimedOutInterestCount(const std::string& neighbor);
|
||||
incrementTimedOutInterestCount(const ndn::Name& neighbor);
|
||||
|
||||
int32_t
|
||||
getTimedOutInterestCount(const std::string& neighbor);
|
||||
getTimedOutInterestCount(const ndn::Name& neighbor);
|
||||
|
||||
uint32_t
|
||||
getStatusOfNeighbor(const std::string& neighbor);
|
||||
getStatusOfNeighbor(const ndn::Name& neighbor);
|
||||
|
||||
void
|
||||
setStatusOfNeighbor(const std::string& neighbor, int32_t status);
|
||||
setStatusOfNeighbor(const ndn::Name& neighbor, int32_t status);
|
||||
|
||||
void
|
||||
setTimedOutInterestCount(const std::string& neighbor, uint32_t count);
|
||||
setTimedOutInterestCount(const ndn::Name& neighbor, uint32_t count);
|
||||
|
||||
void
|
||||
addAdjacents(AdjacencyList& adl);
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
getNumOfActiveNeighbor();
|
||||
|
||||
Adjacent
|
||||
getAdjacent(const std::string& adjName);
|
||||
getAdjacent(const ndn::Name& adjName);
|
||||
|
||||
bool
|
||||
operator==(AdjacencyList& adl);
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
private:
|
||||
std::list<Adjacent>::iterator
|
||||
find(std::string adjName);
|
||||
find(const ndn::Name& adjName);
|
||||
|
||||
private:
|
||||
std::list<Adjacent> m_adjList;
|
||||
|
||||
+4
-3
@@ -10,7 +10,8 @@ namespace nlsr {
|
||||
|
||||
using namespace std;
|
||||
|
||||
Adjacent::Adjacent(const string& an, uint32_t cf, double lc, uint32_t s, uint32_t iton)
|
||||
Adjacent::Adjacent(const ndn::Name& an, uint32_t cf, double lc, uint32_t s,
|
||||
uint32_t iton)
|
||||
{
|
||||
m_name = an;
|
||||
m_connectingFace = cf;
|
||||
@@ -29,9 +30,9 @@ Adjacent::operator==(const Adjacent& adjacent) const
|
||||
}
|
||||
|
||||
bool
|
||||
Adjacent::compareName(const Adjacent& adjacent)
|
||||
Adjacent::compare(const ndn::Name& adjacencyName)
|
||||
{
|
||||
return m_name == adjacent.getName();
|
||||
return m_name == adjacencyName;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
|
||||
+10
-8
@@ -1,5 +1,6 @@
|
||||
#include <string>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/face.hpp>
|
||||
|
||||
#ifndef NLSR_ADJACENT_HPP
|
||||
#define NLSR_ADJACENT_HPP
|
||||
@@ -10,7 +11,7 @@ class Adjacent
|
||||
|
||||
public:
|
||||
Adjacent()
|
||||
: m_name("")
|
||||
: m_name()
|
||||
, m_connectingFace(0)
|
||||
, m_linkCost(10.0)
|
||||
, m_status(0)
|
||||
@@ -18,7 +19,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Adjacent(const std::string& an)
|
||||
Adjacent(const ndn::Name& an)
|
||||
: m_connectingFace(0)
|
||||
, m_linkCost(0.0)
|
||||
, m_status(0)
|
||||
@@ -27,16 +28,17 @@ public:
|
||||
m_name = an;
|
||||
}
|
||||
|
||||
Adjacent(const std::string& an, uint32_t cf, double lc, uint32_t s, uint32_t iton);
|
||||
Adjacent(const ndn::Name& an, uint32_t cf, double lc, uint32_t s,
|
||||
uint32_t iton);
|
||||
|
||||
std::string
|
||||
const ndn::Name&
|
||||
getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void
|
||||
setName(const std::string& an)
|
||||
setName(const ndn::Name& an)
|
||||
{
|
||||
m_name = an;
|
||||
}
|
||||
@@ -93,10 +95,10 @@ public:
|
||||
operator==(const Adjacent& adjacent) const;
|
||||
|
||||
bool
|
||||
compareName(const Adjacent& adjacent);
|
||||
|
||||
compare(const ndn::Name& adjacencyName);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
ndn::Name m_name;
|
||||
uint32_t m_connectingFace;
|
||||
double m_linkCost;
|
||||
uint32_t m_status;
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
|
||||
#include <ndn-cxx/security/identity-certificate.hpp>
|
||||
#include <ndn-cxx/util/io.hpp>
|
||||
|
||||
#include "nlsr.hpp"
|
||||
#include "data-manager.hpp"
|
||||
#include "utility/tokenizer.hpp"
|
||||
#include "lsdb.hpp"
|
||||
// #include "security/key-manager.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
using namespace std;
|
||||
using namespace ndn;
|
||||
|
||||
void
|
||||
DataManager::processContent(const ndn::Interest& interest,
|
||||
const ndn::Data& data, InterestManager& im)
|
||||
{
|
||||
std::cout << "I: " << interest.toUri() << std::endl;
|
||||
string dataName(data.getName().toUri());
|
||||
Tokenizer nt(dataName, "/");
|
||||
std::string chkString("keys");
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
processContentKeys(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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(dataName, dataContent);
|
||||
}
|
||||
chkString = "LSA";
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
string dataContent((char*)data.getContent().value());
|
||||
processContentLsa(dataName, dataContent);
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// std::cout << "Unverified Data Content. Discarded" << std::endl;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentInfo(const string& dataName,
|
||||
string& dataContent)
|
||||
{
|
||||
Tokenizer nt(dataName, "/");
|
||||
string chkString("info");
|
||||
string neighbor = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
|
||||
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
int infoIntTimedOutCount = m_nlsr.getAdjacencyList().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
|
||||
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1);
|
||||
m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
|
||||
int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
|
||||
//debugging purpose
|
||||
std::cout << "After Updates: " << std::endl;
|
||||
std::cout << "Neighbor : " << neighbor << std::endl;
|
||||
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
|
||||
{
|
||||
m_nlsr.incrementAdjBuildCount();
|
||||
/* Need to schedule event for Adjacency LSA building */
|
||||
if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
|
||||
{
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(1);
|
||||
// event here
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild, m_nlsr.getLsdb(),
|
||||
boost::ref(m_nlsr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentLsa(const string& dataName, string& dataContent)
|
||||
{
|
||||
Tokenizer nt(dataName, "/");
|
||||
string chkString("LSA");
|
||||
string origRouter = nt.getTokenString(nt.getTokenPosition(chkString) + 1,
|
||||
nt.getTokenNumber() - 4);
|
||||
string lsTypeString = nt.getToken(nt.getTokenNumber() - 3);
|
||||
string lsSeNoString = nt.getToken(nt.getTokenNumber() - 2);
|
||||
uint32_t interestedLsSeqNo;
|
||||
try
|
||||
{
|
||||
interestedLsSeqNo = boost::lexical_cast<uint32_t>(lsSeNoString);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (lsTypeString == "1") //Name Lsa
|
||||
{
|
||||
processContentNameLsa(origRouter + "/" + lsTypeString,
|
||||
interestedLsSeqNo, dataContent);
|
||||
}
|
||||
else if (lsTypeString == "2") //Adj Lsa
|
||||
{
|
||||
processContentAdjLsa(origRouter + "/" + lsTypeString,
|
||||
interestedLsSeqNo, dataContent);
|
||||
}
|
||||
else if (lsTypeString == "3") //Cor Lsa
|
||||
{
|
||||
processContentCorLsa(origRouter + "/" + lsTypeString,
|
||||
interestedLsSeqNo, dataContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unrecognized LSA Type :(" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentNameLsa(const string& lsaKey,
|
||||
uint32_t lsSeqNo, string& dataContent)
|
||||
{
|
||||
if (m_nlsr.getLsdb().isNameLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
NameLsa nameLsa;
|
||||
if (nameLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
m_nlsr.getLsdb().installNameLsa(m_nlsr, nameLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentAdjLsa(const string& lsaKey,
|
||||
uint32_t lsSeqNo, string& dataContent)
|
||||
{
|
||||
if (m_nlsr.getLsdb().isAdjLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
AdjLsa adjLsa;
|
||||
if (adjLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
m_nlsr.getLsdb().installAdjLsa(m_nlsr, adjLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentCorLsa(const string& lsaKey,
|
||||
uint32_t lsSeqNo, string& dataContent)
|
||||
{
|
||||
if (m_nlsr.getLsdb().isCoordinateLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
CoordinateLsa corLsa;
|
||||
if (corLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
m_nlsr.getLsdb().installCoordinateLsa(m_nlsr, corLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DataManager::processContentKeys(const ndn::Data& data)
|
||||
{
|
||||
std::cout << " processContentKeys called " << std::endl;
|
||||
ndn::shared_ptr<ndn::IdentityCertificate> cert =
|
||||
ndn::make_shared<ndn::IdentityCertificate>();
|
||||
cert->wireDecode(data.getContent().blockFromValue());
|
||||
std::cout << *(cert) << std::endl;
|
||||
std::string dataName = data.getName().toUri();
|
||||
Tokenizer nt(dataName, "/");
|
||||
std::string certName = nt.getTokenString(0, nt.getTokenNumber() - 3);
|
||||
uint32_t seqNum = boost::lexical_cast<uint32_t>(nt.getToken(
|
||||
nt.getTokenNumber() - 2));
|
||||
std::cout << "Cert Name: " << certName << " Seq Num: " << seqNum << std::endl;
|
||||
// if (m_nlsr.getKeyManager().verify(m_nlsr, *(cert)))
|
||||
// {
|
||||
// m_nlsr.getKeyManager().addCertificate(cert, seqNum, true);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_nlsr.getKeyManager().addCertificate(cert, seqNum, false);
|
||||
// }
|
||||
// m_nlsr.getKeyManager().printCertStore();
|
||||
}
|
||||
}//namespace nlsr
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef NLSR_DATA_MANAGER_HPP
|
||||
#define NLSR_DATA_MANAGER_HPP
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
|
||||
#include "interest-manager.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
class Nlsr;
|
||||
|
||||
class DataManager
|
||||
{
|
||||
public:
|
||||
DataManager(Nlsr& nlsr)
|
||||
: m_nlsr(nlsr)
|
||||
{}
|
||||
void
|
||||
processContent(const ndn::Interest& interest,
|
||||
const ndn::Data& data, InterestManager& im);
|
||||
private:
|
||||
void
|
||||
processContentInfo(const std::string& dataName,
|
||||
std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentLsa(const std::string& dataName, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentNameLsa(const std::string& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentAdjLsa(const std::string& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentCorLsa(const std::string& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentKeys(const ndn::Data& data);
|
||||
|
||||
private:
|
||||
Nlsr& m_nlsr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}//namespace nlsr
|
||||
|
||||
#endif //NLSR_DATA_MANAGER_HPP
|
||||
@@ -1,334 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <ndn-cxx/security/identity-certificate.hpp>
|
||||
#include <ndn-cxx/util/io.hpp>
|
||||
|
||||
#include "nlsr.hpp"
|
||||
#include "interest-manager.hpp"
|
||||
#include "data-manager.hpp"
|
||||
#include "utility/tokenizer.hpp"
|
||||
#include "lsdb.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
using namespace std;
|
||||
using namespace ndn;
|
||||
|
||||
void
|
||||
InterestManager::processInterest(const ndn::Name& name,
|
||||
const ndn::Interest& interest)
|
||||
{
|
||||
cout << "<< I: " << interest << endl;
|
||||
string intName = interest.getName().toUri();
|
||||
cout << "Interest Received for Name: " << intName << endl;
|
||||
Tokenizer nt(intName, "/");
|
||||
string chkString("info");
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
string nbr = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
|
||||
cout << "Neighbor: " << nbr << endl;
|
||||
processInterestInfo(nbr, interest);
|
||||
}
|
||||
chkString = "LSA";
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
processInterestLsa(interest);
|
||||
}
|
||||
chkString = "keys";
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
processInterestKeys(interest);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestInfo(const string& neighbor,
|
||||
const ndn::Interest& interest)
|
||||
{
|
||||
if (m_nlsr.getAdjacencyList().isNeighbor(neighbor))
|
||||
{
|
||||
Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
|
||||
data.setContent((const uint8_t*)"info", sizeof("info"));
|
||||
// m_nlsr.getKeyManager().signData(data);
|
||||
m_keyChain.sign(data);
|
||||
cout << ">> D: " << data << endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
if (status == 0)
|
||||
{
|
||||
string intName = neighbor + "/" + "info" +
|
||||
m_nlsr.getConfParameter().getRouterPrefix();
|
||||
expressInterest(intName, 2,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestLsa(const ndn::Interest& interest)
|
||||
{
|
||||
string intName = interest.getName().toUri();
|
||||
Tokenizer nt(intName, "/");
|
||||
string chkString("LSA");
|
||||
string origRouter = nt.getTokenString(nt.getTokenPosition(chkString) + 1,
|
||||
nt.getTokenNumber() - 3);
|
||||
string lsTypeString = nt.getToken(nt.getTokenNumber() - 2);
|
||||
string lsSeqString = nt.getToken(nt.getTokenNumber() - 1);
|
||||
std::cout << "Router Name: " << origRouter << std::endl;
|
||||
std::cout << "Ls Type : " << lsTypeString << std::endl;
|
||||
std::cout << "Ls Seq : " << lsSeqString << endl;
|
||||
uint8_t interestedLsType;
|
||||
uint32_t interestedLsSeqNo;
|
||||
try
|
||||
{
|
||||
interestedLsType = boost::lexical_cast<uint8_t>(lsTypeString);
|
||||
interestedLsSeqNo = boost::lexical_cast<uint32_t>(lsSeqString);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::cout << "Ls Type: " << interestedLsType << std::endl;
|
||||
if (lsTypeString == "1") //Name Lsa
|
||||
{
|
||||
processInterestForNameLsa(interest,
|
||||
origRouter + "/" + lsTypeString, interestedLsSeqNo);
|
||||
}
|
||||
else if (lsTypeString == "2") //Adj Lsa
|
||||
{
|
||||
processInterestForAdjLsa(interest,
|
||||
origRouter + "/" + lsTypeString, interestedLsSeqNo);
|
||||
}
|
||||
else if (lsTypeString == "3") //Cor Lsa
|
||||
{
|
||||
processInterestForCorLsa(interest,
|
||||
origRouter + "/" + lsTypeString, interestedLsSeqNo);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unrecognized LSA Type :(" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestForNameLsa(const ndn::Interest& interest,
|
||||
const string& lsaKey, uint32_t interestedlsSeqNo)
|
||||
{
|
||||
NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
|
||||
if (nameLsa != 0)
|
||||
{
|
||||
if (nameLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
|
||||
string content = nameLsa->getData();
|
||||
data.setContent((const uint8_t*)content.c_str(), content.size());
|
||||
// m_nlsr.getKeyManager().signData(data);
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestForAdjLsa(const ndn::Interest& interest,
|
||||
const string& lsaKey, uint32_t interestedlsSeqNo)
|
||||
{
|
||||
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
|
||||
if (adjLsa != 0)
|
||||
{
|
||||
if (adjLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
|
||||
string content = adjLsa->getData();
|
||||
data.setContent((const uint8_t*)content.c_str(), content.size());
|
||||
// m_nlsr.getKeyManager().signData(data);
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestForCorLsa(const ndn::Interest& interest,
|
||||
const string& lsaKey, uint32_t interestedlsSeqNo)
|
||||
{
|
||||
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
|
||||
if (corLsa != 0)
|
||||
{
|
||||
if (corLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(time::seconds(10)); // 10 sec
|
||||
string content = corLsa->getData();
|
||||
data.setContent((const uint8_t*)content.c_str(), content.size());
|
||||
// m_nlsr.getKeyManager().signData(data);
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestKeys(const ndn::Interest& interest)
|
||||
{
|
||||
std::cout << "processInterestKeys called " << std::endl;
|
||||
// string intName = interest.getName().toUri();
|
||||
// std::cout << "Interest Name for Key: " << intName << std::endl;
|
||||
// Tokenizer nt(intName, "/");
|
||||
// std::string chkString("ID-CERT");
|
||||
// std::string certName;
|
||||
// uint32_t seqNum;
|
||||
// ndn::Name dataName;
|
||||
// std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> chkCert;
|
||||
// if (nt.getTokenPosition(chkString) == nt.getTokenNumber() - 1)
|
||||
// {
|
||||
// certName = nt.getTokenString(0, nt.getTokenNumber() - 1);
|
||||
// cout << "Cert Name: " << certName << std::endl;
|
||||
// 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 = m_nlsr.getKeyManager().getCertificateFromStore(certName, seqNum);
|
||||
// }
|
||||
// if (chkCert.second)
|
||||
// {
|
||||
// if (nt.getTokenPosition(chkString) == nt.getTokenNumber() - 1)
|
||||
// {
|
||||
// std::string dn;
|
||||
// dataName = ndn::Name(interest.getName()).appendVersion();
|
||||
// std::pair<uint32_t, bool> seqChk =
|
||||
// m_nlsr.getKeyManager().getCertificateSeqNum(certName);
|
||||
// if (seqChk.second)
|
||||
// {
|
||||
// dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(seqChk.first);
|
||||
// dataName = ndn::Name(dn);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(10);
|
||||
// dataName = ndn::Name(dn);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dataName = ndn::Name(interest.getName());
|
||||
// }
|
||||
// Data data(dataName.appendVersion());
|
||||
// data.setFreshnessPeriod(time::seconds(10)); //10 sec
|
||||
// data.setContent(chkCert.first->wireEncode());
|
||||
// m_nlsr.getKeyManager().signData(data);
|
||||
// m_nlsr.getNlsrFace()->put(data);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterestManager::processInterestTimedOut(const ndn::Interest& interest)
|
||||
{
|
||||
std::cout << "Timed out interest : " << interest.getName().toUri() << std::endl;
|
||||
string intName = interest.getName().toUri();
|
||||
Tokenizer nt(intName, "/");
|
||||
string chkString("info");
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
string nbr = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
|
||||
processInterestTimedOutInfo(nbr , interest);
|
||||
}
|
||||
chkString = "LSA";
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
processInterestTimedOutLsa(interest);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestTimedOutInfo(const string& neighbor,
|
||||
const ndn::Interest& interest)
|
||||
{
|
||||
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
|
||||
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
uint32_t infoIntTimedOutCount = m_nlsr.getAdjacencyList().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 < m_nlsr.getConfParameter().getInterestRetryNumber()))
|
||||
{
|
||||
string intName = neighbor + "/" + "info" +
|
||||
m_nlsr.getConfParameter().getRouterPrefix();
|
||||
expressInterest(intName, 2,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
else if ((status == 1) &&
|
||||
(infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
|
||||
{
|
||||
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
|
||||
m_nlsr.incrementAdjBuildCount();
|
||||
if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
|
||||
{
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(1);
|
||||
// event here
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
|
||||
&m_nlsr.getLsdb(),
|
||||
boost::ref(m_nlsr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::processInterestTimedOutLsa(const ndn::Interest& interest)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::expressInterest(const string& interestNamePrefix,
|
||||
int32_t scope, int32_t seconds)
|
||||
{
|
||||
std::cout << "Expressing Interest :" << interestNamePrefix << std::endl;
|
||||
ndn::Interest i((ndn::Name(interestNamePrefix)));
|
||||
i.setInterestLifetime(time::seconds(seconds));
|
||||
i.setMustBeFresh(true);
|
||||
m_nlsr.getNlsrFace().expressInterest(i,
|
||||
ndn::bind(&DataManager::processContent,
|
||||
&m_nlsr.getDataManager(),
|
||||
_1, _2, boost::ref(*this)),
|
||||
ndn::bind(&InterestManager::processInterestTimedOut,
|
||||
this, _1));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterestManager::sendScheduledInfoInterest(int32_t seconds)
|
||||
{
|
||||
std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
|
||||
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
|
||||
++it)
|
||||
{
|
||||
string adjName = (*it).getName() + "/" + "info" +
|
||||
m_nlsr.getConfParameter().getRouterPrefix();
|
||||
expressInterest(adjName, 2,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
scheduleInfoInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
|
||||
}
|
||||
|
||||
void
|
||||
InterestManager::scheduleInfoInterest(int32_t seconds)
|
||||
{
|
||||
EventId eid = m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
|
||||
ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
|
||||
seconds));
|
||||
}
|
||||
|
||||
|
||||
} //namespace nlsr
|
||||
@@ -1,72 +0,0 @@
|
||||
#ifndef NLSR_INTEREST_MANAGER_HPP
|
||||
#define NLSR_INTEREST_MANAGER_HPP
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
class Nlsr;
|
||||
|
||||
class InterestManager
|
||||
{
|
||||
public:
|
||||
InterestManager(Nlsr& nlsr)
|
||||
: m_nlsr(nlsr)
|
||||
{
|
||||
}
|
||||
void
|
||||
processInterest(const ndn::Name& name, const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestInfo(const std::string& neighbor, const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestLsa(const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestForNameLsa(const ndn::Interest& interest,
|
||||
const std::string& lsaKey, uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processInterestForAdjLsa(const ndn::Interest& interest,
|
||||
const std::string& lsaKey, uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processInterestForCorLsa(const ndn::Interest& interest,
|
||||
const std::string& lsaKey, uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processInterestKeys(const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestTimedOut(const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestTimedOutInfo(const std::string& neighbor,
|
||||
const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processInterestTimedOutLsa(const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
expressInterest(const std::string& interestNamePrefix, int32_t scope, int32_t seconds);
|
||||
|
||||
void
|
||||
sendScheduledInfoInterest(int32_t seconds);
|
||||
|
||||
void
|
||||
scheduleInfoInterest(int32_t seconds);
|
||||
|
||||
private:
|
||||
Nlsr& m_nlsr;
|
||||
|
||||
ndn::KeyChain m_keyChain;
|
||||
};
|
||||
|
||||
}//namespace nlsr
|
||||
|
||||
#endif //NLSR_INTEREST_MANAGER_HPP
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "nlsr.hpp"
|
||||
#include "sync-logic-handler.hpp"
|
||||
// #include "security/key-manager.hpp"
|
||||
#include "utility/tokenizer.hpp"
|
||||
#include "utility/name-helper.hpp"
|
||||
#include "lsa.hpp"
|
||||
|
||||
|
||||
namespace nlsr {
|
||||
@@ -13,7 +13,7 @@ void
|
||||
SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
|
||||
{
|
||||
std::cout << "Creating Sync socket ......" << std::endl;
|
||||
std::cout << "Sync prefix: " << m_syncPrefix.toUri() << std::endl;
|
||||
std::cout << "Sync prefix: " << m_syncPrefix << std::endl;
|
||||
m_syncSocket = make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
|
||||
m_syncFace,
|
||||
bind(&SyncLogicHandler::nsyncUpdateCallBack, this,
|
||||
@@ -43,116 +43,97 @@ SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogicHandler::removeRouterFromSyncing(const string& routerPrefix)
|
||||
SyncLogicHandler::removeRouterFromSyncing(const ndn::Name& routerPrefix)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogicHandler::processUpdateFromSync(const std::string& updateName,
|
||||
SyncLogicHandler::processUpdateFromSync(const ndn::Name& updateName,
|
||||
uint64_t seqNo, Nlsr& pnlsr)
|
||||
{
|
||||
Tokenizer nt(updateName, "/");
|
||||
//const ndn::Name name(updateName);
|
||||
string chkString("LSA");
|
||||
if (nt.doesTokenExist(chkString))
|
||||
int32_t lasPosition = util::getNameComponentPosition(updateName, chkString);
|
||||
if (lasPosition >= 0)
|
||||
{
|
||||
//process LSA Update here
|
||||
string routerName = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
|
||||
ndn::Name routerName = updateName.getSubName(lasPosition + 1);
|
||||
processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
|
||||
}
|
||||
chkString = "keys";
|
||||
if (nt.doesTokenExist(chkString))
|
||||
{
|
||||
//process keys update here
|
||||
std::string certName = nt.getTokenString(0);
|
||||
// processKeysUpdateFromSync(certName, seqNo, pnlsr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogicHandler::processRoutingUpdateFromSync(const std::string& routerName,
|
||||
SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
|
||||
uint64_t seqNo, Nlsr& pnlsr)
|
||||
{
|
||||
ndn::Name rName = routerName;
|
||||
if (routerName != pnlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
SequencingManager sm(seqNo);
|
||||
std::cout << sm;
|
||||
std::cout << "Router Name: " << routerName << endl;
|
||||
if (pnlsr.getLsdb().isNameLsaNew(routerName + "/1", sm.getNameLsaSeq()))
|
||||
try
|
||||
{
|
||||
std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
|
||||
string lsaPrefix =
|
||||
pnlsr.getConfParameter().getChronosyncLsaPrefix() +
|
||||
routerName + "/1/" +
|
||||
boost::lexical_cast<std::string>(sm.getNameLsaSeq());
|
||||
pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq()))
|
||||
{
|
||||
std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
|
||||
ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
|
||||
interestName.append(routerName);
|
||||
interestName.append("name");
|
||||
interestName.appendNumber(sm.getNameLsaSeq());
|
||||
pnlsr.getLsdb().expressInterest(interestName,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
if (pnlsr.getLsdb().isAdjLsaNew(rName.append("adjacency"),
|
||||
sm.getAdjLsaSeq()))
|
||||
{
|
||||
std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
|
||||
ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
|
||||
interestName.append(routerName);
|
||||
interestName.append("adjacency");
|
||||
interestName.appendNumber(sm.getAdjLsaSeq());
|
||||
pnlsr.getLsdb().expressInterest(interestName,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
if (pnlsr.getLsdb().isCoordinateLsaNew(rName.append("coordinate"),
|
||||
sm.getCorLsaSeq()))
|
||||
{
|
||||
std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
|
||||
ndn::Name interestName(pnlsr.getConfParameter().getChronosyncLsaPrefix());
|
||||
interestName.append(routerName);
|
||||
interestName.append("coordinate");
|
||||
interestName.appendNumber(sm.getCorLsaSeq());
|
||||
pnlsr.getLsdb().expressInterest(interestName,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
}
|
||||
if (pnlsr.getLsdb().isAdjLsaNew(routerName + "/2", sm.getAdjLsaSeq()))
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
|
||||
string lsaPrefix =
|
||||
pnlsr.getConfParameter().getChronosyncLsaPrefix() +
|
||||
routerName + "/2/" +
|
||||
boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
|
||||
pnlsr.getInterestManager().expressInterest(lsaPrefix, 3,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
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.getInterestManager().expressInterest(lsaPrefix, 3,
|
||||
pnlsr.getConfParameter().getInterestResendTime());
|
||||
std::cerr << e.what() << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void
|
||||
// SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
|
||||
// uint64_t seqNo, Nlsr& pnlsr)
|
||||
// {
|
||||
// std::cout << "Cert Name: " << certName << std::endl;
|
||||
// // if (pnlsr.getKeyManager().isNewCertificate(certName, seqNo))
|
||||
// {
|
||||
// string certNamePrefix = certName + "/" +
|
||||
// boost::lexical_cast<string>(seqNo);
|
||||
// pnlsr.getIm().expressInterest(certNamePrefix, 3,
|
||||
// pnlsr.getConfParameter().getInterestResendTime());
|
||||
// }
|
||||
// }
|
||||
|
||||
void
|
||||
SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
|
||||
const string& updatePrefix)
|
||||
const ndn::Name& updatePrefix)
|
||||
{
|
||||
sm.writeSeqNoToFile();
|
||||
publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo());
|
||||
}
|
||||
|
||||
// void
|
||||
// SyncLogicHandler::publishKeyUpdate(KeyManager& km)
|
||||
// {
|
||||
// publishSyncUpdate(km.getProcessCertName().toUri(), km.getCertSeqNo());
|
||||
// }
|
||||
|
||||
void
|
||||
SyncLogicHandler::publishIdentityUpdate(const string& identityName)
|
||||
{
|
||||
publishSyncUpdate(identityName, 0);
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogicHandler::publishSyncUpdate(const string& updatePrefix, uint64_t seqNo)
|
||||
SyncLogicHandler::publishSyncUpdate(const ndn::Name& updatePrefix,
|
||||
uint64_t seqNo)
|
||||
{
|
||||
std::cout << "Publishing Sync Update ......" << std::endl;
|
||||
std::cout << "Update in prefix: " << updatePrefix << std::endl;
|
||||
std::cout << "Seq No: " << seqNo << std::endl;
|
||||
ndn::Name updateName(updatePrefix);
|
||||
string data("NoData");
|
||||
m_syncSocket->publishData(updateName, 0, data.c_str(), data.size(), 1000,
|
||||
m_syncSocket->publishData(updateName.toUri(), 0, data.c_str(), data.size(),
|
||||
1000,
|
||||
seqNo);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
#include "sequencing-manager.hpp"
|
||||
|
||||
// class KeyManager;
|
||||
|
||||
extern "C" {
|
||||
#include <unistd.h>
|
||||
}
|
||||
@@ -42,16 +40,10 @@ public:
|
||||
nsyncRemoveCallBack(const std::string& prefix, Nlsr& pnlsr);
|
||||
|
||||
void
|
||||
removeRouterFromSyncing(const std::string& routerPrefix);
|
||||
removeRouterFromSyncing(const ndn::Name& routerPrefix);
|
||||
|
||||
void
|
||||
publishRoutingUpdate(SequencingManager& sm, const std::string& updatePrefix);
|
||||
|
||||
// void
|
||||
// publishKeyUpdate(KeyManager& km);
|
||||
|
||||
void
|
||||
publishIdentityUpdate(const std::string& identityName);
|
||||
publishRoutingUpdate(SequencingManager& sm, const ndn::Name& updatePrefix);
|
||||
|
||||
void
|
||||
setSyncPrefix(const std::string& sp)
|
||||
@@ -62,17 +54,15 @@ public:
|
||||
|
||||
private:
|
||||
void
|
||||
processUpdateFromSync(const std::string& updateName, uint64_t seqNo, Nlsr& pnlsr);
|
||||
processUpdateFromSync(const ndn::Name& updateName, uint64_t seqNo,
|
||||
Nlsr& pnlsr);
|
||||
|
||||
void
|
||||
processRoutingUpdateFromSync(const std::string& routerName, uint64_t seqNo,
|
||||
processRoutingUpdateFromSync(const ndn::Name& routerName, uint64_t seqNo,
|
||||
Nlsr& pnlsr);
|
||||
|
||||
// void
|
||||
// processKeysUpdateFromSync(std::string certName, uint64_t seqNo, Nlsr& pnlsr);
|
||||
|
||||
void
|
||||
publishSyncUpdate(const std::string& updatePrefix, uint64_t seqNo);
|
||||
publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
|
||||
|
||||
private:
|
||||
ndn::shared_ptr<ndn::ValidatorNull> m_validator;
|
||||
|
||||
@@ -503,7 +503,7 @@ ConfFileProcessor::processConfCommandNdnNeighbor(string command)
|
||||
stringstream sst(nt.getRestOfLine().c_str());
|
||||
int faceId;
|
||||
sst >> faceId;
|
||||
Adjacent adj(nt.getFirstToken(), faceId, 0.0, 0, 0);
|
||||
Adjacent adj(nt.getFirstToken(), faceId, 10, 0, 0);
|
||||
m_nlsr.getAdjacencyList().insert(adj);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-22
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/common.hpp>
|
||||
#include <ndn-cxx/face.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
class ConfParameter
|
||||
@@ -32,10 +34,10 @@ public:
|
||||
void
|
||||
setRouterName(const std::string& rn)
|
||||
{
|
||||
m_routerName = rn;
|
||||
m_routerName = ndn::Name(rn);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getRouterName()
|
||||
{
|
||||
return m_routerName;
|
||||
@@ -44,10 +46,10 @@ public:
|
||||
void
|
||||
setSiteName(const std::string& sn)
|
||||
{
|
||||
m_siteName = sn;
|
||||
m_siteName = ndn::Name(sn);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getSiteName()
|
||||
{
|
||||
return m_siteName;
|
||||
@@ -56,10 +58,10 @@ public:
|
||||
void
|
||||
setNetwork(const std::string& nn)
|
||||
{
|
||||
m_network = nn;
|
||||
m_network = ndn::Name(nn);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getNetwork()
|
||||
{
|
||||
return m_network;
|
||||
@@ -68,16 +70,19 @@ public:
|
||||
void
|
||||
buildRouterPrefix()
|
||||
{
|
||||
m_routerPrefix = "/" + m_network + "/" + m_siteName + "/" + m_routerName;
|
||||
//m_routerPrefix = "/" + m_network + "/" + m_siteName + "/" + m_routerName;
|
||||
m_routerPrefix = m_network;
|
||||
m_routerPrefix.append(m_siteName);
|
||||
m_routerPrefix.append(m_routerName);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getRouterPrefix()
|
||||
{
|
||||
return m_routerPrefix;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getRootKeyPrefix()
|
||||
{
|
||||
return m_rootKeyPrefix;
|
||||
@@ -86,7 +91,7 @@ public:
|
||||
void
|
||||
setRootKeyPrefix(std::string rkp)
|
||||
{
|
||||
m_rootKeyPrefix = rkp;
|
||||
m_rootKeyPrefix = ndn::Name(rkp);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -261,10 +266,10 @@ public:
|
||||
void
|
||||
setChronosyncSyncPrefix(const std::string& csp)
|
||||
{
|
||||
m_chronosyncSyncPrefix = csp;
|
||||
m_chronosyncSyncPrefix = ndn::Name(csp);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getChronosyncSyncPrefix()
|
||||
{
|
||||
return m_chronosyncSyncPrefix;
|
||||
@@ -273,10 +278,10 @@ public:
|
||||
void
|
||||
setChronosyncLsaPrefix(const std::string& clp)
|
||||
{
|
||||
m_chronosyncLsaPrefix = clp;
|
||||
m_chronosyncLsaPrefix = ndn::Name(clp);
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getChronosyncLsaPrefix()
|
||||
{
|
||||
return m_chronosyncLsaPrefix;
|
||||
@@ -295,16 +300,16 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_routerName;
|
||||
std::string m_siteName;
|
||||
std::string m_network;
|
||||
ndn::Name m_routerName;
|
||||
ndn::Name m_siteName;
|
||||
ndn::Name m_network;
|
||||
|
||||
std::string m_routerPrefix;
|
||||
std::string m_lsaRouterPrefix;
|
||||
ndn::Name m_routerPrefix;
|
||||
ndn::Name m_lsaRouterPrefix;
|
||||
|
||||
std::string m_chronosyncSyncPrefix;
|
||||
std::string m_chronosyncLsaPrefix;
|
||||
std::string m_rootKeyPrefix;
|
||||
ndn::Name m_chronosyncSyncPrefix;
|
||||
ndn::Name m_chronosyncLsaPrefix;
|
||||
ndn::Name m_rootKeyPrefix;
|
||||
|
||||
uint32_t m_interestRetryNumber;
|
||||
int32_t m_interestResendTime;
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
#include "nlsr.hpp"
|
||||
#include "lsdb.hpp"
|
||||
#include "hello-protocol.hpp"
|
||||
#include "utility/name-helper.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
void
|
||||
HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
|
||||
{
|
||||
std::cout << "Expressing Interest :" << interestName << std::endl;
|
||||
ndn::Interest i(interestName);
|
||||
i.setInterestLifetime(ndn::time::seconds(seconds));
|
||||
i.setMustBeFresh(true);
|
||||
m_nlsr.getNlsrFace().expressInterest(i,
|
||||
ndn::bind(&HelloProtocol::processContent,
|
||||
this,
|
||||
_1, _2),
|
||||
ndn::bind(&HelloProtocol::processInterestTimedOut,
|
||||
this, _1));
|
||||
}
|
||||
|
||||
void
|
||||
HelloProtocol::sendScheduledInterest(uint32_t seconds)
|
||||
{
|
||||
std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList();
|
||||
for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
|
||||
++it)
|
||||
{
|
||||
ndn::Name interestName = (*it).getName() ;
|
||||
interestName.append("info");
|
||||
interestName.append(ndn::Name(m_nlsr.getConfParameter().getRouterPrefix()));
|
||||
expressInterest(interestName,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
scheduleInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
|
||||
}
|
||||
|
||||
void
|
||||
HelloProtocol::scheduleInterest(uint32_t seconds)
|
||||
{
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
|
||||
ndn::bind(&HelloProtocol::sendScheduledInterest,
|
||||
this, seconds));
|
||||
}
|
||||
|
||||
void
|
||||
HelloProtocol::processInterest(const ndn::Name& name,
|
||||
const ndn::Interest& interest)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ndn::Name neighbor = interestName.getSubName(infoPosition + 1);
|
||||
std::cout << "Neighbor: " << neighbor << std::endl;
|
||||
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"));
|
||||
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)
|
||||
{
|
||||
ndn::Name interestName(neighbor);
|
||||
interestName.append("info");
|
||||
interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
expressInterest(interestName,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ndn::Name neighbor = interestName.getSubName(0, infoPosition);
|
||||
std::cout << "Neighbor: " << neighbor << std::endl;
|
||||
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
|
||||
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
uint32_t infoIntTimedOutCount =
|
||||
m_nlsr.getAdjacencyList().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 < m_nlsr.getConfParameter().getInterestRetryNumber()))
|
||||
{
|
||||
ndn::Name interestName(neighbor);
|
||||
interestName.append("info");
|
||||
interestName.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
expressInterest(interestName,
|
||||
m_nlsr.getConfParameter().getInterestResendTime());
|
||||
}
|
||||
else if ((status == 1) &&
|
||||
(infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
|
||||
{
|
||||
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
|
||||
m_nlsr.incrementAdjBuildCount();
|
||||
if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
|
||||
{
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(1);
|
||||
// event here
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
|
||||
&m_nlsr.getLsdb()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HelloProtocol::processContent(const ndn::Interest& interest,
|
||||
const ndn::Data& data)
|
||||
{
|
||||
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);
|
||||
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
int infoIntTimedOutCount = m_nlsr.getAdjacencyList().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
|
||||
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 1);
|
||||
m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0);
|
||||
int newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
|
||||
infoIntTimedOutCount = m_nlsr.getAdjacencyList().getTimedOutInterestCount(
|
||||
neighbor);
|
||||
//debugging purpose
|
||||
std::cout << "After Updates: " << std::endl;
|
||||
std::cout << "Neighbor : " << neighbor << std::endl;
|
||||
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
|
||||
{
|
||||
m_nlsr.incrementAdjBuildCount();
|
||||
/* Need to schedule event for Adjacency LSA building */
|
||||
if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
|
||||
{
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(1);
|
||||
// event here
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
|
||||
boost::ref(m_nlsr.getLsdb())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace nlsr
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef NLSR_HELLO_PROTOCOL_HPP
|
||||
#define NLSR_HELLO_PROTOCOL_HPP
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
class Nlsr;
|
||||
|
||||
class HelloProtocol
|
||||
{
|
||||
|
||||
public:
|
||||
HelloProtocol(Nlsr& nlsr)
|
||||
: m_nlsr(nlsr)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void
|
||||
scheduleInterest(uint32_t seconds);
|
||||
|
||||
void
|
||||
expressInterest(const ndn::Name& interestNamePrefix, uint32_t seconds);
|
||||
|
||||
void
|
||||
sendScheduledInterest(uint32_t seconds);
|
||||
|
||||
void
|
||||
processInterest(const ndn::Name& name, const ndn::Interest& interest);
|
||||
|
||||
private:
|
||||
void
|
||||
processInterestTimedOut(const ndn::Interest& interest);
|
||||
|
||||
void
|
||||
processContent(const ndn::Interest& interest, const ndn::Data& data);
|
||||
|
||||
private:
|
||||
Nlsr& m_nlsr;
|
||||
ndn::KeyChain m_keyChain;
|
||||
};
|
||||
|
||||
} //namespace nlsr
|
||||
|
||||
#endif // NLSR_HELLO_PROTOCOL_HPP
|
||||
+82
-76
@@ -4,6 +4,8 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "nlsr.hpp"
|
||||
#include "lsa.hpp"
|
||||
@@ -17,23 +19,24 @@ namespace nlsr {
|
||||
using namespace std;
|
||||
|
||||
|
||||
string
|
||||
const ndn::Name
|
||||
NameLsa::getKey() const
|
||||
{
|
||||
string key;
|
||||
key = m_origRouter + "/" + boost::lexical_cast<std::string>(1);
|
||||
ndn::Name key = m_origRouter;
|
||||
key.append("name");
|
||||
return key;
|
||||
}
|
||||
|
||||
NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
|
||||
NameLsa::NameLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
|
||||
uint32_t lt,
|
||||
NamePrefixList& npl)
|
||||
{
|
||||
m_origRouter = origR;
|
||||
m_lsType = lst;
|
||||
m_lsSeqNo = lsn;
|
||||
m_lifeTime = lt;
|
||||
std::list<string> nl = npl.getNameList();
|
||||
for (std::list<string>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
std::list<ndn::Name>& nl = npl.getNameList();
|
||||
for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
{
|
||||
addName((*it));
|
||||
}
|
||||
@@ -43,44 +46,45 @@ string
|
||||
NameLsa::getData()
|
||||
{
|
||||
string nameLsaData;
|
||||
nameLsaData = m_origRouter + "|" + boost::lexical_cast<std::string>(1) + "|"
|
||||
nameLsaData = m_origRouter.toUri() + "|" + "name" + "|"
|
||||
+ boost::lexical_cast<std::string>(m_lsSeqNo) + "|"
|
||||
+ boost::lexical_cast<std::string>(m_lifeTime);
|
||||
nameLsaData += "|";
|
||||
nameLsaData += boost::lexical_cast<std::string>(m_npl.getSize());
|
||||
std::list<string> nl = m_npl.getNameList();
|
||||
for (std::list<string>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
std::list<ndn::Name> nl = m_npl.getNameList();
|
||||
for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
{
|
||||
nameLsaData += "|";
|
||||
nameLsaData += (*it);
|
||||
nameLsaData += (*it).toUri();
|
||||
}
|
||||
return nameLsaData + "|";
|
||||
}
|
||||
|
||||
bool
|
||||
NameLsa::initializeFromContent(string content)
|
||||
NameLsa::initializeFromContent(const std::string& content)
|
||||
{
|
||||
uint32_t numName = 0;
|
||||
Tokenizer nt(content, "|");
|
||||
m_origRouter = nt.getNextToken();
|
||||
if (m_origRouter.empty())
|
||||
boost::char_separator<char> sep("|");
|
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
|
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
|
||||
tokens.begin();
|
||||
m_origRouter = ndn::Name(*tok_iter++);
|
||||
if (!(m_origRouter.size() > 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
m_lsType = boost::lexical_cast<uint8_t>(nt.getNextToken());
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
numName = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
try {
|
||||
m_lsType = *tok_iter++;
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
numName = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
catch (std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < numName; i++)
|
||||
{
|
||||
string name = nt.getNextToken();
|
||||
string name(*tok_iter++);
|
||||
addName(name);
|
||||
}
|
||||
return true;
|
||||
@@ -96,13 +100,13 @@ operator<<(std::ostream& os, NameLsa& nLsa)
|
||||
{
|
||||
os << "Name Lsa: " << endl;
|
||||
os << " Origination Router: " << nLsa.getOrigRouter() << endl;
|
||||
os << " Ls Type: " << (unsigned short)nLsa.getLsType() << endl;
|
||||
os << " Ls Type: " << nLsa.getLsType() << endl;
|
||||
os << " Ls Seq No: " << (unsigned int)nLsa.getLsSeqNo() << endl;
|
||||
os << " Ls Lifetime: " << (unsigned int)nLsa.getLifeTime() << endl;
|
||||
os << " Names: " << endl;
|
||||
int i = 1;
|
||||
std::list<string> nl = nLsa.getNpl().getNameList();
|
||||
for (std::list<string>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
std::list<ndn::Name> nl = nLsa.getNpl().getNameList();
|
||||
for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
|
||||
{
|
||||
os << " Name " << i << ": " << (*it) << endl;
|
||||
}
|
||||
@@ -111,7 +115,8 @@ operator<<(std::ostream& os, NameLsa& nLsa)
|
||||
|
||||
|
||||
|
||||
CoordinateLsa::CoordinateLsa(string origR, uint8_t lst, uint32_t lsn,
|
||||
CoordinateLsa::CoordinateLsa(const ndn::Name& origR, const string lst,
|
||||
uint32_t lsn,
|
||||
uint32_t lt
|
||||
, double r, double theta)
|
||||
{
|
||||
@@ -123,11 +128,11 @@ CoordinateLsa::CoordinateLsa(string origR, uint8_t lst, uint32_t lsn,
|
||||
m_corTheta = theta;
|
||||
}
|
||||
|
||||
string
|
||||
const ndn::Name
|
||||
CoordinateLsa::getKey() const
|
||||
{
|
||||
string key;
|
||||
key = m_origRouter + "/" + boost::lexical_cast<std::string>(3);
|
||||
ndn::Name key = m_origRouter;
|
||||
key.append("coordinate");
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -144,8 +149,9 @@ string
|
||||
CoordinateLsa::getData()
|
||||
{
|
||||
string corLsaData;
|
||||
corLsaData = m_origRouter + "|";
|
||||
corLsaData += (boost::lexical_cast<std::string>(3) + "|");
|
||||
corLsaData = m_origRouter.toUri() + "|";
|
||||
corLsaData += "coordinate";
|
||||
corLsaData += "|";
|
||||
corLsaData += (boost::lexical_cast<std::string>(m_lsSeqNo) + "|");
|
||||
corLsaData += (boost::lexical_cast<std::string>(m_lifeTime) + "|");
|
||||
corLsaData += (boost::lexical_cast<std::string>(m_corRad) + "|");
|
||||
@@ -154,24 +160,25 @@ CoordinateLsa::getData()
|
||||
}
|
||||
|
||||
bool
|
||||
CoordinateLsa::initializeFromContent(string content)
|
||||
CoordinateLsa::initializeFromContent(const std::string& content)
|
||||
{
|
||||
Tokenizer nt(content, "|");
|
||||
m_origRouter = nt.getNextToken();
|
||||
if (m_origRouter.empty())
|
||||
boost::char_separator<char> sep("|");
|
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
|
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
|
||||
tokens.begin();
|
||||
m_origRouter = ndn::Name(*tok_iter++);
|
||||
if (!(m_origRouter.size() > 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
m_lsType = boost::lexical_cast<uint8_t>(nt.getNextToken());
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
m_corRad = boost::lexical_cast<double>(nt.getNextToken());
|
||||
m_corTheta = boost::lexical_cast<double>(nt.getNextToken());
|
||||
try {
|
||||
m_lsType = *tok_iter++;
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
m_corRad = boost::lexical_cast<double>(*tok_iter++);
|
||||
m_corTheta = boost::lexical_cast<double>(*tok_iter++);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
catch (std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -182,7 +189,7 @@ operator<<(std::ostream& os, const CoordinateLsa& cLsa)
|
||||
{
|
||||
os << "Cor Lsa: " << endl;
|
||||
os << " Origination Router: " << cLsa.getOrigRouter() << endl;
|
||||
os << " Ls Type: " << (unsigned short)cLsa.getLsType() << endl;
|
||||
os << " Ls Type: " << cLsa.getLsType() << endl;
|
||||
os << " Ls Seq No: " << (unsigned int)cLsa.getLsSeqNo() << endl;
|
||||
os << " Ls Lifetime: " << (unsigned int)cLsa.getLifeTime() << endl;
|
||||
os << " Hyperbolic Radius: " << cLsa.getCorRadius() << endl;
|
||||
@@ -191,7 +198,8 @@ operator<<(std::ostream& os, const CoordinateLsa& cLsa)
|
||||
}
|
||||
|
||||
|
||||
AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
|
||||
AdjLsa::AdjLsa(const ndn::Name& origR, const string& lst, uint32_t lsn,
|
||||
uint32_t lt,
|
||||
uint32_t nl , AdjacencyList& adl)
|
||||
{
|
||||
m_origRouter = origR;
|
||||
@@ -209,11 +217,11 @@ AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
AdjLsa::getKey()
|
||||
const ndn::Name
|
||||
AdjLsa::getKey() const
|
||||
{
|
||||
string key;
|
||||
key = m_origRouter + "/" + boost::lexical_cast<std::string>(2);
|
||||
ndn::Name key = m_origRouter;
|
||||
key.append("adjacency");
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -228,7 +236,7 @@ string
|
||||
AdjLsa::getData()
|
||||
{
|
||||
string adjLsaData;
|
||||
adjLsaData = m_origRouter + "|" + boost::lexical_cast<std::string>(2) + "|"
|
||||
adjLsaData = m_origRouter.toUri() + "|" + "adjacency" + "|"
|
||||
+ boost::lexical_cast<std::string>(m_lsSeqNo) + "|"
|
||||
+ boost::lexical_cast<std::string>(m_lifeTime);
|
||||
adjLsaData += "|";
|
||||
@@ -237,7 +245,7 @@ AdjLsa::getData()
|
||||
for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++)
|
||||
{
|
||||
adjLsaData += "|";
|
||||
adjLsaData += (*it).getName();
|
||||
adjLsaData += (*it).getName().toUri();
|
||||
adjLsaData += "|";
|
||||
adjLsaData += boost::lexical_cast<std::string>((*it).getConnectingFace());
|
||||
adjLsaData += "|";
|
||||
@@ -247,38 +255,37 @@ AdjLsa::getData()
|
||||
}
|
||||
|
||||
bool
|
||||
AdjLsa::initializeFromContent(string content)
|
||||
AdjLsa::initializeFromContent(const std::string& content)
|
||||
{
|
||||
uint32_t numLink = 0;
|
||||
Tokenizer nt(content, "|");
|
||||
m_origRouter = nt.getNextToken();
|
||||
if (m_origRouter.empty())
|
||||
boost::char_separator<char> sep("|");
|
||||
boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
|
||||
boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
|
||||
tokens.begin();
|
||||
m_origRouter = ndn::Name(*tok_iter++);
|
||||
if (!(m_origRouter.size() > 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
m_lsType = boost::lexical_cast<uint8_t>(nt.getNextToken());
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
numLink = boost::lexical_cast<uint32_t>(nt.getNextToken());
|
||||
try {
|
||||
m_lsType = *tok_iter++;
|
||||
m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
numLink = boost::lexical_cast<uint32_t>(*tok_iter++);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
catch (std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < numLink; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
string adjName = nt.getNextToken();
|
||||
int connectingFace = boost::lexical_cast<int>(nt.getNextToken());
|
||||
double linkCost = boost::lexical_cast<double>(nt.getNextToken());
|
||||
try {
|
||||
string adjName(*tok_iter++);
|
||||
int connectingFace = boost::lexical_cast<int>(*tok_iter++);
|
||||
double linkCost = boost::lexical_cast<double>(*tok_iter++);
|
||||
Adjacent adjacent(adjName, connectingFace, linkCost, 0, 0);
|
||||
addAdjacent(adjacent);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
catch (std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -291,8 +298,7 @@ AdjLsa::addNptEntries(Nlsr& pnlsr)
|
||||
{
|
||||
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter(),
|
||||
pnlsr);
|
||||
pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +308,7 @@ AdjLsa::removeNptEntries(Nlsr& pnlsr)
|
||||
{
|
||||
if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter(), pnlsr);
|
||||
pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +319,7 @@ operator<<(std::ostream& os, AdjLsa& aLsa)
|
||||
{
|
||||
os << "Adj Lsa: " << endl;
|
||||
os << " Origination Router: " << aLsa.getOrigRouter() << endl;
|
||||
os << " Ls Type: " << (unsigned short)aLsa.getLsType() << endl;
|
||||
os << " Ls Type: " << aLsa.getLsType() << endl;
|
||||
os << " Ls Seq No: " << (unsigned int)aLsa.getLsSeqNo() << endl;
|
||||
os << " Ls Lifetime: " << (unsigned int)aLsa.getLifeTime() << endl;
|
||||
os << " No Link: " << (unsigned int)aLsa.getNoLink() << endl;
|
||||
|
||||
+25
-21
@@ -8,6 +8,7 @@
|
||||
#include "adjacency-list.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
class Lsa
|
||||
{
|
||||
public:
|
||||
@@ -21,12 +22,12 @@ public:
|
||||
|
||||
|
||||
void
|
||||
setLsType(uint8_t lst)
|
||||
setLsType(const std::string& lst)
|
||||
{
|
||||
m_lsType = lst;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
const std::string&
|
||||
getLsType() const
|
||||
{
|
||||
return m_lsType;
|
||||
@@ -44,14 +45,14 @@ public:
|
||||
return m_lsSeqNo;
|
||||
}
|
||||
|
||||
std::string
|
||||
const ndn::Name&
|
||||
getOrigRouter() const
|
||||
{
|
||||
return m_origRouter;
|
||||
}
|
||||
|
||||
void
|
||||
setOrigRouter(const std::string& org)
|
||||
setOrigRouter(const ndn::Name& org)
|
||||
{
|
||||
m_origRouter = org;
|
||||
}
|
||||
@@ -81,8 +82,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_origRouter;
|
||||
uint8_t m_lsType;
|
||||
ndn::Name m_origRouter;
|
||||
std::string m_lsType;
|
||||
uint32_t m_lsSeqNo;
|
||||
uint32_t m_lifeTime;
|
||||
ndn::EventId m_expiringEventId;
|
||||
@@ -95,10 +96,11 @@ public:
|
||||
: Lsa()
|
||||
, m_npl()
|
||||
{
|
||||
setLsType(1);
|
||||
setLsType("name");
|
||||
}
|
||||
|
||||
NameLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
|
||||
NameLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
|
||||
uint32_t lt,
|
||||
NamePrefixList& npl);
|
||||
|
||||
NamePrefixList&
|
||||
@@ -108,25 +110,25 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
addName(std::string& name)
|
||||
addName(const ndn::Name& name)
|
||||
{
|
||||
m_npl.insert(name);
|
||||
}
|
||||
|
||||
void
|
||||
removeName(std::string& name)
|
||||
removeName(const ndn::Name& name)
|
||||
{
|
||||
m_npl.remove(name);
|
||||
}
|
||||
|
||||
std::string
|
||||
const ndn::Name
|
||||
getKey() const;
|
||||
|
||||
std::string
|
||||
getData();
|
||||
|
||||
bool
|
||||
initializeFromContent(std::string content);
|
||||
initializeFromContent(const std::string& content);
|
||||
|
||||
void
|
||||
writeLog();
|
||||
@@ -146,10 +148,11 @@ public:
|
||||
: Lsa()
|
||||
, m_adl()
|
||||
{
|
||||
setLsType(2);
|
||||
setLsType("adjacency");
|
||||
}
|
||||
|
||||
AdjLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
|
||||
AdjLsa(const ndn::Name& origR, const std::string& lst, uint32_t lsn,
|
||||
uint32_t lt,
|
||||
uint32_t nl , AdjacencyList& adl);
|
||||
|
||||
AdjacencyList&
|
||||
@@ -164,14 +167,14 @@ public:
|
||||
m_adl.insert(adj);
|
||||
}
|
||||
|
||||
std::string
|
||||
getKey();
|
||||
const ndn::Name
|
||||
getKey() const;
|
||||
|
||||
std::string
|
||||
getData();
|
||||
|
||||
bool
|
||||
initializeFromContent(std::string content);
|
||||
initializeFromContent(const std::string& content);
|
||||
|
||||
uint32_t
|
||||
getNoLink()
|
||||
@@ -204,20 +207,21 @@ public:
|
||||
, m_corRad(0)
|
||||
, m_corTheta(0)
|
||||
{
|
||||
setLsType(3);
|
||||
setLsType("coordinate");
|
||||
}
|
||||
|
||||
CoordinateLsa(std::string origR, uint8_t lst, uint32_t lsn, uint32_t lt
|
||||
CoordinateLsa(const ndn::Name& origR, const std::string lst, uint32_t lsn,
|
||||
uint32_t lt
|
||||
, double r, double theta);
|
||||
|
||||
std::string
|
||||
const ndn::Name
|
||||
getKey() const;
|
||||
|
||||
std::string
|
||||
getData();
|
||||
|
||||
bool
|
||||
initializeFromContent(std::string content);
|
||||
initializeFromContent(const std::string& content);
|
||||
|
||||
double
|
||||
getCorRadius() const
|
||||
|
||||
+404
-174
@@ -2,38 +2,39 @@
|
||||
#include <utility>
|
||||
#include "lsdb.hpp"
|
||||
#include "nlsr.hpp"
|
||||
#include "utility/name-helper.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
Lsdb::cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, ndn::EventId eid)
|
||||
Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid)
|
||||
{
|
||||
pnlsr.getScheduler().cancelEvent(eid);
|
||||
m_nlsr.getScheduler().cancelEvent(eid);
|
||||
}
|
||||
|
||||
static bool
|
||||
nameLsaCompareByKey(const NameLsa& nlsa1, const string& key)
|
||||
nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key)
|
||||
{
|
||||
return nlsa1.getKey() == key;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Lsdb::buildAndInstallOwnNameLsa(Nlsr& pnlsr)
|
||||
Lsdb::buildAndInstallOwnNameLsa()
|
||||
{
|
||||
NameLsa nameLsa(pnlsr.getConfParameter().getRouterPrefix(),
|
||||
1,
|
||||
pnlsr.getSequencingManager().getNameLsaSeq() + 1,
|
||||
pnlsr.getConfParameter().getRouterDeadInterval(),
|
||||
pnlsr.getNamePrefixList());
|
||||
pnlsr.getSequencingManager().increaseNameLsaSeq();
|
||||
return installNameLsa(pnlsr, nameLsa);
|
||||
NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(),
|
||||
"name",
|
||||
m_nlsr.getSequencingManager().getNameLsaSeq() + 1,
|
||||
m_nlsr.getConfParameter().getRouterDeadInterval(),
|
||||
m_nlsr.getNamePrefixList());
|
||||
m_nlsr.getSequencingManager().increaseNameLsaSeq();
|
||||
return installNameLsa(nameLsa);
|
||||
}
|
||||
|
||||
NameLsa*
|
||||
Lsdb::findNameLsa(const string key)
|
||||
Lsdb::findNameLsa(const ndn::Name& key)
|
||||
{
|
||||
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
|
||||
m_nameLsdb.end(),
|
||||
@@ -46,7 +47,7 @@ Lsdb::findNameLsa(const string key)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::isNameLsaNew(string key, uint64_t seqNo)
|
||||
Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo)
|
||||
{
|
||||
NameLsa* nameLsaCheck = findNameLsa(key);
|
||||
if (nameLsaCheck != 0)
|
||||
@@ -64,15 +65,15 @@ Lsdb::isNameLsaNew(string key, uint64_t seqNo)
|
||||
}
|
||||
|
||||
ndn::EventId
|
||||
Lsdb::scheduleNameLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
|
||||
Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, int expTime)
|
||||
{
|
||||
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
|
||||
this, boost::ref(pnlsr), key, seqNo));
|
||||
return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshNameLsa,
|
||||
this, key, seqNo));
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa)
|
||||
Lsdb::installNameLsa(NameLsa& nlsa)
|
||||
{
|
||||
int timeToExpire = m_lsaRefreshTime;
|
||||
NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
|
||||
@@ -81,26 +82,25 @@ Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa)
|
||||
addNameLsa(nlsa);
|
||||
nlsa.writeLog();
|
||||
printNameLsdb();
|
||||
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
|
||||
nlsa.getOrigRouter(), pnlsr);
|
||||
std::list<string> nameList = nlsa.getNpl().getNameList();
|
||||
for (std::list<string>::iterator it = nameList.begin(); it != nameList.end();
|
||||
m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
|
||||
nlsa.getOrigRouter());
|
||||
std::list<ndn::Name> nameList = nlsa.getNpl().getNameList();
|
||||
for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end();
|
||||
it++)
|
||||
{
|
||||
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = nlsa.getLifeTime();
|
||||
}
|
||||
nlsa.setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
|
||||
nlsa.getKey(),
|
||||
nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
|
||||
nlsa.getLsSeqNo(),
|
||||
timeToExpire));
|
||||
}
|
||||
@@ -113,50 +113,49 @@ Lsdb::installNameLsa(Nlsr& pnlsr, NameLsa& nlsa)
|
||||
chkNameLsa->setLifeTime(nlsa.getLifeTime());
|
||||
chkNameLsa->getNpl().sort();
|
||||
nlsa.getNpl().sort();
|
||||
std::list<string> nameToAdd;
|
||||
std::list<ndn::Name> nameToAdd;
|
||||
std::set_difference(nlsa.getNpl().getNameList().begin(),
|
||||
nlsa.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();
|
||||
for (std::list<ndn::Name>::iterator it = nameToAdd.begin();
|
||||
it != nameToAdd.end();
|
||||
++it)
|
||||
{
|
||||
chkNameLsa->addName((*it));
|
||||
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter());
|
||||
}
|
||||
}
|
||||
}
|
||||
std::list<string> nameToRemove;
|
||||
std::list<ndn::Name> nameToRemove;
|
||||
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();
|
||||
for (std::list<ndn::Name>::iterator it = nameToRemove.begin();
|
||||
it != nameToRemove.end(); ++it)
|
||||
{
|
||||
chkNameLsa->removeName((*it));
|
||||
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
if ((*it) != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if ((*it) != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nlsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = nlsa.getLifeTime();
|
||||
}
|
||||
cancelScheduleLsaExpiringEvent(pnlsr,
|
||||
chkNameLsa->getExpiringEventId());
|
||||
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
|
||||
nlsa.getKey(),
|
||||
cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId());
|
||||
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
|
||||
nlsa.getLsSeqNo(),
|
||||
timeToExpire));
|
||||
chkNameLsa->writeLog();
|
||||
@@ -181,7 +180,7 @@ Lsdb::addNameLsa(NameLsa& nlsa)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::removeNameLsa(Nlsr& pnlsr, string& key)
|
||||
Lsdb::removeNameLsa(const ndn::Name& key)
|
||||
{
|
||||
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
|
||||
m_nameLsdb.end(),
|
||||
@@ -189,16 +188,17 @@ Lsdb::removeNameLsa(Nlsr& pnlsr, string& key)
|
||||
if (it != m_nameLsdb.end())
|
||||
{
|
||||
(*it).writeLog();
|
||||
if ((*it).getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if ((*it).getOrigRouter() !=
|
||||
m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
|
||||
(*it).getOrigRouter(), pnlsr);
|
||||
for (std::list<string>::iterator nit = (*it).getNpl().getNameList().begin();
|
||||
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
|
||||
(*it).getOrigRouter());
|
||||
for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin();
|
||||
nit != (*it).getNpl().getNameList().end(); ++nit)
|
||||
{
|
||||
if ((*nit) != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,7 +209,7 @@ Lsdb::removeNameLsa(Nlsr& pnlsr, string& key)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::doesNameLsaExist(string key)
|
||||
Lsdb::doesNameLsaExist(const ndn::Name& key)
|
||||
{
|
||||
std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(),
|
||||
m_nameLsdb.end(),
|
||||
@@ -236,27 +236,27 @@ Lsdb::printNameLsdb()
|
||||
|
||||
|
||||
static bool
|
||||
corLsaCompareByKey(const CoordinateLsa& clsa, const string& key)
|
||||
corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key)
|
||||
{
|
||||
return clsa.getKey() == key;
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::buildAndInstallOwnCoordinateLsa(Nlsr& pnlsr)
|
||||
Lsdb::buildAndInstallOwnCoordinateLsa()
|
||||
{
|
||||
CoordinateLsa corLsa(pnlsr.getConfParameter().getRouterPrefix(),
|
||||
3,
|
||||
pnlsr.getSequencingManager().getCorLsaSeq() + 1,
|
||||
pnlsr.getConfParameter().getRouterDeadInterval(),
|
||||
pnlsr.getConfParameter().getCorR(),
|
||||
pnlsr.getConfParameter().getCorTheta());
|
||||
pnlsr.getSequencingManager().increaseCorLsaSeq();
|
||||
installCoordinateLsa(pnlsr, corLsa);
|
||||
CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(),
|
||||
"coordinate",
|
||||
m_nlsr.getSequencingManager().getCorLsaSeq() + 1,
|
||||
m_nlsr.getConfParameter().getRouterDeadInterval(),
|
||||
m_nlsr.getConfParameter().getCorR(),
|
||||
m_nlsr.getConfParameter().getCorTheta());
|
||||
m_nlsr.getSequencingManager().increaseCorLsaSeq();
|
||||
installCoordinateLsa(corLsa);
|
||||
return true;
|
||||
}
|
||||
|
||||
CoordinateLsa*
|
||||
Lsdb::findCoordinateLsa(const string& key)
|
||||
Lsdb::findCoordinateLsa(const ndn::Name& key)
|
||||
{
|
||||
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
|
||||
m_corLsdb.end(),
|
||||
@@ -269,7 +269,7 @@ Lsdb::findCoordinateLsa(const string& key)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::isCoordinateLsaNew(const string& key, uint64_t seqNo)
|
||||
Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo)
|
||||
{
|
||||
CoordinateLsa* clsa = findCoordinateLsa(key);
|
||||
if (clsa != 0)
|
||||
@@ -287,17 +287,16 @@ Lsdb::isCoordinateLsaNew(const string& key, uint64_t seqNo)
|
||||
}
|
||||
|
||||
ndn::EventId
|
||||
Lsdb::scheduleCoordinateLsaExpiration(Nlsr& pnlsr, const string& key, int seqNo,
|
||||
Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
|
||||
int expTime)
|
||||
{
|
||||
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
|
||||
this, boost::ref(pnlsr),
|
||||
key, seqNo));
|
||||
return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa,
|
||||
this, key, seqNo));
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa)
|
||||
Lsdb::installCoordinateLsa(CoordinateLsa& clsa)
|
||||
{
|
||||
int timeToExpire = m_lsaRefreshTime;
|
||||
CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
|
||||
@@ -305,20 +304,20 @@ Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa)
|
||||
{
|
||||
addCoordinateLsa(clsa);
|
||||
printCorLsdb(); //debugging purpose
|
||||
if (clsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
|
||||
clsa.getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(),
|
||||
clsa.getOrigRouter());
|
||||
}
|
||||
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
{
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
if (clsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = clsa.getLifeTime();
|
||||
}
|
||||
scheduleCoordinateLsaExpiration(pnlsr, clsa.getKey(),
|
||||
scheduleCoordinateLsaExpiration(clsa.getKey(),
|
||||
clsa.getLsSeqNo(), timeToExpire);
|
||||
}
|
||||
else
|
||||
@@ -331,19 +330,17 @@ Lsdb::installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa)
|
||||
{
|
||||
chkCorLsa->setCorRadius(clsa.getCorRadius());
|
||||
chkCorLsa->setCorTheta(clsa.getCorTheta());
|
||||
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
{
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
}
|
||||
if (clsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = clsa.getLifeTime();
|
||||
}
|
||||
cancelScheduleLsaExpiringEvent(pnlsr,
|
||||
chkCorLsa->getExpiringEventId());
|
||||
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(pnlsr,
|
||||
clsa.getKey(),
|
||||
cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId());
|
||||
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
|
||||
clsa.getLsSeqNo(),
|
||||
timeToExpire));
|
||||
}
|
||||
@@ -367,17 +364,18 @@ Lsdb::addCoordinateLsa(CoordinateLsa& clsa)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::removeCoordinateLsa(Nlsr& pnlsr, const string& key)
|
||||
Lsdb::removeCoordinateLsa(const ndn::Name& 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())
|
||||
if ((*it).getOrigRouter() !=
|
||||
m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
pnlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
|
||||
(*it).getOrigRouter(), pnlsr);
|
||||
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
|
||||
(*it).getOrigRouter());
|
||||
}
|
||||
m_corLsdb.erase(it);
|
||||
return true;
|
||||
@@ -386,7 +384,7 @@ Lsdb::removeCoordinateLsa(Nlsr& pnlsr, const string& key)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::doesCoordinateLsaExist(const string& key)
|
||||
Lsdb::doesCoordinateLsaExist(const ndn::Name& key)
|
||||
{
|
||||
std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(),
|
||||
m_corLsdb.end(),
|
||||
@@ -413,43 +411,44 @@ Lsdb::printCorLsdb() //debugging
|
||||
// Adj LSA and LSDB related function starts here
|
||||
|
||||
static bool
|
||||
adjLsaCompareByKey(AdjLsa& alsa, string& key)
|
||||
adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key)
|
||||
{
|
||||
return alsa.getKey() == key;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Lsdb::scheduledAdjLsaBuild(Nlsr& pnlsr)
|
||||
Lsdb::scheduledAdjLsaBuild()
|
||||
{
|
||||
cout << "scheduledAdjLsaBuild Called" << endl;
|
||||
pnlsr.setIsBuildAdjLsaSheduled(0);
|
||||
if (pnlsr.getAdjacencyList().isAdjLsaBuildable(pnlsr))
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(0);
|
||||
if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr))
|
||||
{
|
||||
int adjBuildCount = pnlsr.getAdjBuildCount();
|
||||
int adjBuildCount = m_nlsr.getAdjBuildCount();
|
||||
if (adjBuildCount > 0)
|
||||
{
|
||||
if (pnlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0)
|
||||
if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0)
|
||||
{
|
||||
buildAndInstallOwnAdjLsa(pnlsr);
|
||||
buildAndInstallOwnAdjLsa();
|
||||
}
|
||||
else
|
||||
{
|
||||
string key = pnlsr.getConfParameter().getRouterPrefix() + "/2";
|
||||
removeAdjLsa(pnlsr, key);
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix();
|
||||
key.append("adjacency");
|
||||
removeAdjLsa(key);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
pnlsr.setAdjBuildCount(pnlsr.getAdjBuildCount() - adjBuildCount);
|
||||
m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pnlsr.setIsBuildAdjLsaSheduled(1);
|
||||
int schedulingTime = pnlsr.getConfParameter().getInterestRetryNumber() *
|
||||
pnlsr.getConfParameter().getInterestResendTime();
|
||||
pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
|
||||
pnlsr.getLsdb(), boost::ref(pnlsr)));
|
||||
m_nlsr.setIsBuildAdjLsaSheduled(1);
|
||||
int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
|
||||
m_nlsr.getConfParameter().getInterestResendTime();
|
||||
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
|
||||
ndn::bind(&Lsdb::scheduledAdjLsaBuild,
|
||||
this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,7 +469,7 @@ Lsdb::addAdjLsa(AdjLsa& alsa)
|
||||
}
|
||||
|
||||
AdjLsa*
|
||||
Lsdb::findAdjLsa(const string key)
|
||||
Lsdb::findAdjLsa(const ndn::Name& key)
|
||||
{
|
||||
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
|
||||
m_adjLsdb.end(),
|
||||
@@ -484,7 +483,7 @@ Lsdb::findAdjLsa(const string key)
|
||||
|
||||
|
||||
bool
|
||||
Lsdb::isAdjLsaNew(string key, uint64_t seqNo)
|
||||
Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo)
|
||||
{
|
||||
AdjLsa* adjLsaCheck = findAdjLsa(key);
|
||||
if (adjLsaCheck != 0)
|
||||
@@ -503,29 +502,28 @@ Lsdb::isAdjLsaNew(string key, uint64_t seqNo)
|
||||
|
||||
|
||||
ndn::EventId
|
||||
Lsdb::scheduleAdjLsaExpiration(Nlsr& pnlsr, string key, int seqNo, int expTime)
|
||||
Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, int expTime)
|
||||
{
|
||||
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
|
||||
this, boost::ref(pnlsr),
|
||||
key, seqNo));
|
||||
return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(expTime),
|
||||
ndn::bind(&Lsdb::exprireOrRefreshAdjLsa,
|
||||
this, key, seqNo));
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa)
|
||||
Lsdb::installAdjLsa(AdjLsa& alsa)
|
||||
{
|
||||
int timeToExpire = m_lsaRefreshTime;
|
||||
AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
|
||||
if (chkAdjLsa == 0)
|
||||
{
|
||||
addAdjLsa(alsa);
|
||||
alsa.addNptEntries(pnlsr);
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
if (alsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
alsa.addNptEntries(m_nlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = alsa.getLifeTime();
|
||||
}
|
||||
scheduleAdjLsaExpiration(pnlsr, alsa.getKey(),
|
||||
scheduleAdjLsaExpiration(alsa.getKey(),
|
||||
alsa.getLsSeqNo(), timeToExpire);
|
||||
}
|
||||
else
|
||||
@@ -538,15 +536,14 @@ Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa)
|
||||
{
|
||||
chkAdjLsa->getAdl().reset();
|
||||
chkAdjLsa->getAdl().addAdjacents(alsa.getAdl());
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
if (alsa.getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix())
|
||||
if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix())
|
||||
{
|
||||
timeToExpire = alsa.getLifeTime();
|
||||
}
|
||||
cancelScheduleLsaExpiringEvent(pnlsr, chkAdjLsa->getExpiringEventId());
|
||||
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
|
||||
alsa.getKey(),
|
||||
cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId());
|
||||
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
|
||||
alsa.getLsSeqNo(),
|
||||
timeToExpire));
|
||||
}
|
||||
@@ -555,31 +552,32 @@ Lsdb::installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::buildAndInstallOwnAdjLsa(Nlsr& pnlsr)
|
||||
Lsdb::buildAndInstallOwnAdjLsa()
|
||||
{
|
||||
AdjLsa adjLsa(pnlsr.getConfParameter().getRouterPrefix(),
|
||||
2,
|
||||
pnlsr.getSequencingManager().getAdjLsaSeq() + 1,
|
||||
pnlsr.getConfParameter().getRouterDeadInterval(),
|
||||
pnlsr.getAdjacencyList().getNumOfActiveNeighbor(),
|
||||
pnlsr.getAdjacencyList());
|
||||
pnlsr.getSequencingManager().increaseAdjLsaSeq();
|
||||
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix() +
|
||||
pnlsr.getConfParameter().getRouterPrefix();
|
||||
pnlsr.getSyncLogicHandler().publishRoutingUpdate(pnlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
return pnlsr.getLsdb().installAdjLsa(pnlsr, adjLsa);
|
||||
AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(),
|
||||
"adjacency",
|
||||
m_nlsr.getSequencingManager().getAdjLsaSeq() + 1,
|
||||
m_nlsr.getConfParameter().getRouterDeadInterval(),
|
||||
m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(),
|
||||
m_nlsr.getAdjacencyList());
|
||||
m_nlsr.getSequencingManager().increaseAdjLsaSeq();
|
||||
// publish routing update
|
||||
ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
|
||||
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
return installAdjLsa(adjLsa);
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::removeAdjLsa(Nlsr& pnlsr, string& key)
|
||||
Lsdb::removeAdjLsa(const ndn::Name& key)
|
||||
{
|
||||
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
|
||||
m_adjLsdb.end(),
|
||||
bind(adjLsaCompareByKey, _1, key));
|
||||
if (it != m_adjLsdb.end())
|
||||
{
|
||||
(*it).removeNptEntries(pnlsr);
|
||||
(*it).removeNptEntries(m_nlsr);
|
||||
m_adjLsdb.erase(it);
|
||||
return true;
|
||||
}
|
||||
@@ -587,7 +585,7 @@ Lsdb::removeAdjLsa(Nlsr& pnlsr, string& key)
|
||||
}
|
||||
|
||||
bool
|
||||
Lsdb::doesAdjLsaExist(string key)
|
||||
Lsdb::doesAdjLsaExist(const ndn::Name& key)
|
||||
{
|
||||
std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(),
|
||||
m_adjLsdb.end(),
|
||||
@@ -618,7 +616,7 @@ Lsdb::setThisRouterPrefix(string trp)
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo)
|
||||
Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
|
||||
{
|
||||
cout << "Lsdb::exprireOrRefreshNameLsa Called " << endl;
|
||||
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
|
||||
@@ -633,30 +631,29 @@ Lsdb::exprireOrRefreshNameLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo)
|
||||
chkNameLsa->writeLog();
|
||||
cout << "Own Name LSA, so refreshing name LSA" << endl;
|
||||
chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
|
||||
pnlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
|
||||
m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
|
||||
chkNameLsa->writeLog();
|
||||
// schedule refreshing event again
|
||||
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(pnlsr,
|
||||
chkNameLsa->getKey(),
|
||||
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(),
|
||||
chkNameLsa->getLsSeqNo(),
|
||||
m_lsaRefreshTime));
|
||||
// publish routing update
|
||||
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
|
||||
+ pnlsr.getConfParameter().getRouterPrefix();
|
||||
pnlsr.getSyncLogicHandler().publishRoutingUpdate(pnlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
|
||||
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Other's Name LSA, so removing form LSDB" << endl;
|
||||
removeNameLsa(pnlsr, lsaKey);
|
||||
removeNameLsa(lsaKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo)
|
||||
Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo)
|
||||
{
|
||||
cout << "Lsdb::exprireOrRefreshAdjLsa Called " << endl;
|
||||
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
|
||||
@@ -670,31 +667,30 @@ Lsdb::exprireOrRefreshAdjLsa(Nlsr& pnlsr, string lsaKey, uint64_t seqNo)
|
||||
{
|
||||
cout << "Own Adj LSA, so refreshing Adj LSA" << endl;
|
||||
chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
|
||||
pnlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
|
||||
m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
|
||||
// schedule refreshing event again
|
||||
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(pnlsr,
|
||||
chkAdjLsa->getKey(),
|
||||
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(),
|
||||
chkAdjLsa->getLsSeqNo(),
|
||||
m_lsaRefreshTime));
|
||||
// publish routing update
|
||||
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
|
||||
+ pnlsr.getConfParameter().getRouterPrefix();
|
||||
pnlsr.getSyncLogicHandler().publishRoutingUpdate(pnlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
|
||||
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Other's Adj LSA, so removing form LSDB" << endl;
|
||||
removeAdjLsa(pnlsr, lsaKey);
|
||||
removeAdjLsa(lsaKey);
|
||||
}
|
||||
// schedule Routing table calculaiton
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const string& lsaKey,
|
||||
Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
|
||||
uint64_t seqNo)
|
||||
{
|
||||
cout << "Lsdb::exprireOrRefreshCorLsa Called " << endl;
|
||||
@@ -709,32 +705,266 @@ Lsdb::exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const string& lsaKey,
|
||||
{
|
||||
cout << "Own Cor LSA, so refreshing Cor LSA" << endl;
|
||||
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
|
||||
pnlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
|
||||
m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
|
||||
// schedule refreshing event again
|
||||
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(pnlsr,
|
||||
chkCorLsa->getKey(),
|
||||
chkCorLsa->getLsSeqNo(),
|
||||
m_lsaRefreshTime));
|
||||
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(
|
||||
chkCorLsa->getKey(),
|
||||
chkCorLsa->getLsSeqNo(),
|
||||
m_lsaRefreshTime));
|
||||
// publish routing update
|
||||
string lsaPrefix = pnlsr.getConfParameter().getChronosyncLsaPrefix()
|
||||
+ pnlsr.getConfParameter().getRouterPrefix();
|
||||
pnlsr.getSyncLogicHandler().publishRoutingUpdate(pnlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
ndn::Name lsaPrefix = m_nlsr.getConfParameter().getChronosyncLsaPrefix();
|
||||
lsaPrefix.append(m_nlsr.getConfParameter().getRouterPrefix());
|
||||
m_nlsr.getSyncLogicHandler().publishRoutingUpdate(m_nlsr.getSequencingManager(),
|
||||
lsaPrefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Other's Cor LSA, so removing form LSDB" << endl;
|
||||
removeCoordinateLsa(pnlsr, lsaKey);
|
||||
removeCoordinateLsa(lsaKey);
|
||||
}
|
||||
if (pnlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
if (m_nlsr.getConfParameter().getIsHyperbolicCalc() >= 1)
|
||||
{
|
||||
pnlsr.getRoutingTable().scheduleRoutingTableCalculation(pnlsr);
|
||||
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Lsdb::expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime)
|
||||
{
|
||||
std::cout << "Expressing Interest :" << interestName << std::endl;
|
||||
ndn::Interest interest(interestName);
|
||||
interest.setInterestLifetime(ndn::time::seconds(interestLifeTime));
|
||||
interest.setMustBeFresh(true);
|
||||
m_nlsr.getNlsrFace().expressInterest(interest,
|
||||
ndn::bind(&Lsdb::processContent,
|
||||
this, _1, _2),
|
||||
ndn::bind(&Lsdb::processInterestTimedOut,
|
||||
this, _1));
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest)
|
||||
{
|
||||
const ndn::Name& intName(interest.getName());
|
||||
std::cout << "Interest recevied for LSA: " << intName << std::endl;
|
||||
string chkString("LSA");
|
||||
int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
|
||||
chkString);
|
||||
if (lsaPosition >= 0)
|
||||
{
|
||||
std::string interestedLsType;
|
||||
uint64_t interestedLsSeqNo;
|
||||
ndn::Name origRouter = intName.getSubName(lsaPosition + 1,
|
||||
interest.getName().size() - lsaPosition - 3);
|
||||
interestedLsType = intName[-2].toEscapedString();
|
||||
interestedLsSeqNo = intName[-1].toNumber();
|
||||
std::cout << "Router Name: " << origRouter << std::endl;
|
||||
std::cout << "Ls Type : " << interestedLsType << std::endl;
|
||||
std::cout << "Ls Seq : " << interestedLsSeqNo << endl;
|
||||
std::cout << "Ls Type: " << interestedLsType << std::endl;
|
||||
if (interestedLsType == "name")
|
||||
{
|
||||
processInterestForNameLsa(interest,
|
||||
origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo);
|
||||
return;
|
||||
}
|
||||
else if (interestedLsType == "adjacency")
|
||||
{
|
||||
processInterestForAdjacencyLsa(interest,
|
||||
origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo);
|
||||
return;
|
||||
}
|
||||
else if (interestedLsType == "coordinate")
|
||||
{
|
||||
processInterestForCoordinateLsa(interest,
|
||||
origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unrecognized LSA Type :(" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo)
|
||||
{
|
||||
NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
|
||||
if (nameLsa != 0)
|
||||
{
|
||||
if (nameLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
|
||||
std::string content = nameLsa->getData();
|
||||
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
|
||||
content.size());
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo)
|
||||
{
|
||||
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
|
||||
if (adjLsa != 0)
|
||||
{
|
||||
if (adjLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
|
||||
std::string content = adjLsa->getData();
|
||||
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
|
||||
content.size());
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo)
|
||||
{
|
||||
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
|
||||
if (corLsa != 0)
|
||||
{
|
||||
if (corLsa->getLsSeqNo() >= interestedlsSeqNo)
|
||||
{
|
||||
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
|
||||
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
|
||||
std::string content = corLsa->getData();
|
||||
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
|
||||
content.size());
|
||||
m_keyChain.sign(data);
|
||||
std::cout << ">> D: " << data << std::endl;
|
||||
m_nlsr.getNlsrFace().put(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processContent(const ndn::Interest& interest, const ndn::Data& data)
|
||||
{
|
||||
const ndn::Name& dataName = data.getName();
|
||||
std::cout << "Data received for name: " << dataName << std::endl;
|
||||
string dataContent(reinterpret_cast<const char*>(data.getContent().value()));
|
||||
string chkString("LSA");
|
||||
int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
|
||||
if (lsaPosition >= 0)
|
||||
{
|
||||
std::string interestedLsType;
|
||||
uint64_t interestedLsSeqNo;
|
||||
ndn::Name origRouter = dataName.getSubName(lsaPosition + 1,
|
||||
dataName.size() - lsaPosition - 4);
|
||||
interestedLsType = dataName[-3].toEscapedString();
|
||||
interestedLsSeqNo = dataName[-2].toNumber();
|
||||
std::cout << "Ls Type : " << interestedLsType << std::endl;
|
||||
std::cout << "Ls Seq : " << interestedLsSeqNo << std::endl;
|
||||
std::cout << "Ls Type: " << interestedLsType << std::endl;
|
||||
if (interestedLsType == "name")
|
||||
{
|
||||
processContentNameLsa(origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo, dataContent);
|
||||
return;
|
||||
}
|
||||
else if (interestedLsType == "adjacency")
|
||||
{
|
||||
processContentAdjacencyLsa(origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo, dataContent);
|
||||
return;
|
||||
}
|
||||
else if (interestedLsType == "coordinate")
|
||||
{
|
||||
processContentCoordinateLsa(origRouter.append(interestedLsType),
|
||||
interestedLsSeqNo, dataContent);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unrecognized LSA Type :(" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processContentNameLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent)
|
||||
{
|
||||
if (isNameLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
NameLsa nameLsa;
|
||||
if (nameLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
installNameLsa(nameLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent)
|
||||
{
|
||||
if (isAdjLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
AdjLsa adjLsa;
|
||||
if (adjLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
installAdjLsa(adjLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent)
|
||||
{
|
||||
if (isCoordinateLsaNew(lsaKey, lsSeqNo))
|
||||
{
|
||||
CoordinateLsa corLsa;
|
||||
if (corLsa.initializeFromContent(dataContent))
|
||||
{
|
||||
installCoordinateLsa(corLsa);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "LSA data decoding error :(" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Lsdb::processInterestTimedOut(const ndn::Interest& interest)
|
||||
{
|
||||
const ndn::Name& interestName(interest.getName());
|
||||
cout << "Interest timed out for Name: " << interestName << endl;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Lsdb::printAdjLsdb()
|
||||
{
|
||||
@@ -748,17 +978,17 @@ Lsdb::printAdjLsdb()
|
||||
|
||||
//-----utility function -----
|
||||
bool
|
||||
Lsdb::doesLsaExist(string key, int lsType)
|
||||
Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType)
|
||||
{
|
||||
if (lsType == 1)
|
||||
if (lsType == "name")
|
||||
{
|
||||
return doesNameLsaExist(key);
|
||||
}
|
||||
else if (lsType == 2)
|
||||
else if (lsType == "adjacency")
|
||||
{
|
||||
return doesAdjLsaExist(key);
|
||||
}
|
||||
else if (lsType == 3)
|
||||
else if (lsType == "coordinate")
|
||||
{
|
||||
return doesCoordinateLsaExist(key);
|
||||
}
|
||||
|
||||
+72
-29
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <utility>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
|
||||
#include "lsa.hpp"
|
||||
|
||||
@@ -12,70 +13,71 @@ class Nlsr;
|
||||
class Lsdb
|
||||
{
|
||||
public:
|
||||
Lsdb()
|
||||
: m_lsaRefreshTime(0)
|
||||
Lsdb(Nlsr& nlsr)
|
||||
: m_nlsr(nlsr)
|
||||
, m_lsaRefreshTime(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
doesLsaExist(std::string key, int lsType);
|
||||
doesLsaExist(const ndn::Name& key, const std::string& lsType);
|
||||
// function related to Name LSDB
|
||||
|
||||
bool
|
||||
buildAndInstallOwnNameLsa(Nlsr& pnlsr);
|
||||
buildAndInstallOwnNameLsa();
|
||||
|
||||
NameLsa*
|
||||
findNameLsa(const std::string key);
|
||||
findNameLsa(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
installNameLsa(Nlsr& pnlsr, NameLsa& nlsa);
|
||||
installNameLsa(NameLsa& nlsa);
|
||||
|
||||
bool
|
||||
removeNameLsa(Nlsr& pnlsr, std::string& key);
|
||||
removeNameLsa(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
isNameLsaNew(std::string key, uint64_t seqNo);
|
||||
isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
|
||||
|
||||
void
|
||||
printNameLsdb(); //debugging
|
||||
|
||||
//function related to Cor LSDB
|
||||
bool
|
||||
buildAndInstallOwnCoordinateLsa(Nlsr& pnlsr);
|
||||
buildAndInstallOwnCoordinateLsa();
|
||||
|
||||
CoordinateLsa*
|
||||
findCoordinateLsa(const std::string& key);
|
||||
findCoordinateLsa(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
installCoordinateLsa(Nlsr& pnlsr, CoordinateLsa& clsa);
|
||||
installCoordinateLsa(CoordinateLsa& clsa);
|
||||
|
||||
bool
|
||||
removeCoordinateLsa(Nlsr& pnlsr, const std::string& key);
|
||||
removeCoordinateLsa(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
isCoordinateLsaNew(const std::string& key, uint64_t seqNo);
|
||||
isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
|
||||
|
||||
void
|
||||
printCorLsdb(); //debugging
|
||||
|
||||
//function related to Adj LSDB
|
||||
void
|
||||
scheduledAdjLsaBuild(Nlsr& pnlsr);
|
||||
scheduledAdjLsaBuild();
|
||||
|
||||
bool
|
||||
buildAndInstallOwnAdjLsa(Nlsr& pnlsr);
|
||||
buildAndInstallOwnAdjLsa();
|
||||
|
||||
bool
|
||||
removeAdjLsa(Nlsr& pnlsr, std::string& key);
|
||||
removeAdjLsa(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
isAdjLsaNew(std::string key, uint64_t seqNo);
|
||||
isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
|
||||
bool
|
||||
installAdjLsa(Nlsr& pnlsr, AdjLsa& alsa);
|
||||
installAdjLsa(AdjLsa& alsa);
|
||||
|
||||
AdjLsa*
|
||||
findAdjLsa(std::string key);
|
||||
findAdjLsa(const ndn::Name& key);
|
||||
|
||||
std::list<AdjLsa>&
|
||||
getAdjLsdb();
|
||||
@@ -95,46 +97,87 @@ private:
|
||||
addNameLsa(NameLsa& nlsa);
|
||||
|
||||
bool
|
||||
doesNameLsaExist(std::string key);
|
||||
doesNameLsaExist(const ndn::Name& key);
|
||||
|
||||
|
||||
bool
|
||||
addCoordinateLsa(CoordinateLsa& clsa);
|
||||
|
||||
bool
|
||||
doesCoordinateLsaExist(const std::string& key);
|
||||
doesCoordinateLsaExist(const ndn::Name& key);
|
||||
|
||||
bool
|
||||
addAdjLsa(AdjLsa& alsa);
|
||||
|
||||
bool
|
||||
doesAdjLsaExist(std::string key);
|
||||
doesAdjLsaExist(const ndn::Name& key);
|
||||
|
||||
ndn::EventId
|
||||
scheduleNameLsaExpiration(Nlsr& pnlsr, std::string key, int seqNo, int expTime);
|
||||
scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
|
||||
|
||||
void
|
||||
exprireOrRefreshNameLsa(Nlsr& pnlsr, std::string lsaKey, uint64_t seqNo);
|
||||
exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
|
||||
|
||||
ndn::EventId
|
||||
scheduleAdjLsaExpiration(Nlsr& pnlsr, std::string key, int seqNo, int expTime);
|
||||
scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, int expTime);
|
||||
|
||||
void
|
||||
exprireOrRefreshAdjLsa(Nlsr& pnlsr, std::string lsaKey, uint64_t seqNo);
|
||||
exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
|
||||
|
||||
ndn::EventId
|
||||
scheduleCoordinateLsaExpiration(Nlsr& pnlsr, const std::string& key, int seqNo,
|
||||
scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
|
||||
int expTime);
|
||||
|
||||
void
|
||||
exprireOrRefreshCoordinateLsa(Nlsr& pnlsr, const std::string& lsaKey,
|
||||
exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
|
||||
uint64_t seqNo);
|
||||
public:
|
||||
void
|
||||
expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime);
|
||||
|
||||
void
|
||||
processInterest(const ndn::Name& name, const ndn::Interest& interest);
|
||||
|
||||
private:
|
||||
void
|
||||
cancelScheduleLsaExpiringEvent(Nlsr& pnlsr, ndn::EventId eid);
|
||||
processInterestForNameLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processInterestForAdjacencyLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processInterestForCoordinateLsa(const ndn::Interest& interest,
|
||||
const ndn::Name& lsaKey,
|
||||
uint32_t interestedlsSeqNo);
|
||||
|
||||
void
|
||||
processContent(const ndn::Interest& interest, const ndn::Data& data);
|
||||
|
||||
void
|
||||
processContentNameLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentAdjacencyLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processContentCoordinateLsa(const ndn::Name& lsaKey,
|
||||
uint32_t lsSeqNo, std::string& dataContent);
|
||||
|
||||
void
|
||||
processInterestTimedOut(const ndn::Interest& interest);
|
||||
|
||||
private:
|
||||
void
|
||||
cancelScheduleLsaExpiringEvent(ndn::EventId eid);
|
||||
|
||||
Nlsr& m_nlsr;
|
||||
ndn::KeyChain m_keyChain;
|
||||
std::list<NameLsa> m_nameLsdb;
|
||||
std::list<AdjLsa> m_adjLsdb;
|
||||
std::list<CoordinateLsa> m_corLsdb;
|
||||
|
||||
+2
-2
@@ -66,9 +66,9 @@ main(int32_t argc, char** argv)
|
||||
try {
|
||||
nlsr.startEventLoop();
|
||||
}
|
||||
catch (std::exception& e){
|
||||
catch (std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
nlsr.getFib().clean(nlsr);
|
||||
nlsr.getFib().clean();
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+13
-11
@@ -18,17 +18,18 @@ NamePrefixList::~NamePrefixList()
|
||||
}
|
||||
|
||||
static bool
|
||||
nameCompare(const string& s1, const string& s2)
|
||||
nameCompare(const ndn::Name& name1, const ndn::Name& name2)
|
||||
{
|
||||
return s1 == s2;
|
||||
return name1 == name2;
|
||||
}
|
||||
|
||||
int32_t
|
||||
NamePrefixList::insert(const string& name)
|
||||
NamePrefixList::insert(const ndn::Name& name)
|
||||
{
|
||||
std::list<string>::iterator it = std::find_if(m_nameList.begin(),
|
||||
m_nameList.end(),
|
||||
ndn::bind(&nameCompare, _1 , name));
|
||||
std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
|
||||
m_nameList.end(),
|
||||
ndn::bind(&nameCompare, _1 ,
|
||||
ndn::cref(name)));
|
||||
if (it != m_nameList.end())
|
||||
{
|
||||
return -1;
|
||||
@@ -38,11 +39,12 @@ NamePrefixList::insert(const string& name)
|
||||
}
|
||||
|
||||
int32_t
|
||||
NamePrefixList::remove(const string& name)
|
||||
NamePrefixList::remove(const ndn::Name& name)
|
||||
{
|
||||
std::list<string>::iterator it = std::find_if(m_nameList.begin(),
|
||||
m_nameList.end(),
|
||||
ndn::bind(&nameCompare, _1 , name));
|
||||
std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
|
||||
m_nameList.end(),
|
||||
ndn::bind(&nameCompare, _1 ,
|
||||
ndn::cref(name)));
|
||||
if (it != m_nameList.end())
|
||||
{
|
||||
m_nameList.erase(it);
|
||||
@@ -60,7 +62,7 @@ void
|
||||
NamePrefixList::print()
|
||||
{
|
||||
int i = 1;
|
||||
for (std::list<string>::iterator it = m_nameList.begin();
|
||||
for (std::list<ndn::Name>::iterator it = m_nameList.begin();
|
||||
it != m_nameList.end();
|
||||
it++)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/name.hpp>
|
||||
|
||||
|
||||
namespace nlsr {
|
||||
@@ -16,21 +17,21 @@ public:
|
||||
~NamePrefixList();
|
||||
|
||||
int32_t
|
||||
insert(const std::string& name);
|
||||
insert(const ndn::Name& name);
|
||||
|
||||
int32_t
|
||||
remove(const std::string& name);
|
||||
remove(const ndn::Name& name);
|
||||
|
||||
void
|
||||
sort();
|
||||
|
||||
int32_t
|
||||
size_t
|
||||
getSize()
|
||||
{
|
||||
return m_nameList.size();
|
||||
}
|
||||
|
||||
std::list<std::string>&
|
||||
std::list<ndn::Name>&
|
||||
getNameList()
|
||||
{
|
||||
return m_nameList;
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
print();
|
||||
|
||||
private:
|
||||
std::list<std::string> m_nameList;
|
||||
std::list<ndn::Name> m_nameList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
+25
-17
@@ -20,11 +20,25 @@ Nlsr::registrationFailed(const ndn::Name& name)
|
||||
|
||||
|
||||
void
|
||||
Nlsr::setInterestFilter(const string& name)
|
||||
Nlsr::setInfoInterestFilter()
|
||||
{
|
||||
ndn::Name name(m_confParam.getRouterPrefix());
|
||||
getNlsrFace().setInterestFilter(name,
|
||||
ndn::bind(&InterestManager::processInterest,
|
||||
&m_interestManager, _1, _2),
|
||||
ndn::bind(&HelloProtocol::processInterest,
|
||||
&m_helloProtocol, _1, _2),
|
||||
ndn::bind(&Nlsr::registrationFailed, this, _1));
|
||||
}
|
||||
|
||||
void
|
||||
Nlsr::setLsaInterestFilter()
|
||||
{
|
||||
// ndn::Name name(m_confParam.getChronosyncLsaPrefix() +
|
||||
// m_confParam.getRouterPrefix());
|
||||
ndn::Name name = m_confParam.getChronosyncLsaPrefix();
|
||||
name.append(m_confParam.getRouterPrefix());
|
||||
getNlsrFace().setInterestFilter(name,
|
||||
ndn::bind(&Lsdb::processInterest,
|
||||
&m_nlsrLsdb, _1, _2),
|
||||
ndn::bind(&Nlsr::registrationFailed, this, _1));
|
||||
}
|
||||
|
||||
@@ -33,12 +47,8 @@ Nlsr::initialize()
|
||||
{
|
||||
m_confParam.buildRouterPrefix();
|
||||
m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
|
||||
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix());
|
||||
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
|
||||
m_fib.setEntryRefreshTime(2 * m_confParam.getLsaRefreshTime());
|
||||
// if (!m_km.initialize(m_confParam))
|
||||
// {
|
||||
// std::cerr << "Can not initiate/load certificate" << endl;
|
||||
// }
|
||||
m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
|
||||
m_sequencingManager.initiateSeqNoFromFile();
|
||||
/* debugging purpose start */
|
||||
@@ -46,16 +56,14 @@ Nlsr::initialize()
|
||||
m_adjacencyList.print();
|
||||
m_namePrefixList.print();
|
||||
/* debugging purpose end */
|
||||
m_nlsrLsdb.buildAndInstallOwnNameLsa(boost::ref(*this));
|
||||
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa(boost::ref(*this));
|
||||
setInterestFilter(m_confParam.getRouterPrefix());
|
||||
setInterestFilter(m_confParam.getChronosyncLsaPrefix() +
|
||||
m_confParam.getRouterPrefix());
|
||||
setInterestFilter(m_confParam.getRootKeyPrefix());
|
||||
m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix());
|
||||
m_nlsrLsdb.buildAndInstallOwnNameLsa();
|
||||
m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
|
||||
setInfoInterestFilter();
|
||||
setLsaInterestFilter();
|
||||
m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncSyncPrefix().toUri());
|
||||
m_syncLogicHandler.createSyncSocket(boost::ref(*this));
|
||||
// m_slh.publishKeyUpdate(m_km);
|
||||
m_interestManager.scheduleInfoInterest(10);
|
||||
//m_interestManager.scheduleInfoInterest(10);
|
||||
m_helloProtocol.scheduleInterest(10);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+11
-33
@@ -11,15 +11,13 @@
|
||||
#include "conf-parameter.hpp"
|
||||
#include "adjacency-list.hpp"
|
||||
#include "name-prefix-list.hpp"
|
||||
#include "communication/interest-manager.hpp"
|
||||
#include "communication/data-manager.hpp"
|
||||
#include "lsdb.hpp"
|
||||
#include "sequencing-manager.hpp"
|
||||
#include "route/routing-table.hpp"
|
||||
#include "route/name-prefix-table.hpp"
|
||||
#include "route/fib.hpp"
|
||||
// #include "security/key-manager.hpp"
|
||||
#include "communication/sync-logic-handler.hpp"
|
||||
#include "hello-protocol.hpp"
|
||||
|
||||
|
||||
namespace nlsr {
|
||||
@@ -42,28 +40,29 @@ public:
|
||||
, m_confParam()
|
||||
, m_adjacencyList()
|
||||
, m_namePrefixList()
|
||||
, m_interestManager(*this)
|
||||
, m_dataManager(*this)
|
||||
, m_sequencingManager()
|
||||
// , m_km()
|
||||
, m_isDaemonProcess(false)
|
||||
, m_configFileName("nlsr.conf")
|
||||
, m_nlsrLsdb()
|
||||
, m_nlsrLsdb(*this)
|
||||
, m_adjBuildCount(0)
|
||||
, m_isBuildAdjLsaSheduled(false)
|
||||
, m_isRouteCalculationScheduled(false)
|
||||
, m_isRoutingTableCalculating(false)
|
||||
, m_routingTable()
|
||||
, m_namePrefixTable()
|
||||
, m_fib(m_nlsrFace)
|
||||
, m_fib(*this, m_nlsrFace)
|
||||
, m_namePrefixTable(*this)
|
||||
, m_syncLogicHandler(m_nlsrFace.getIoService())
|
||||
, m_helloProtocol(*this)
|
||||
{}
|
||||
|
||||
void
|
||||
registrationFailed(const ndn::Name& name);
|
||||
|
||||
void
|
||||
setInterestFilter(const std::string& name);
|
||||
setInfoInterestFilter();
|
||||
|
||||
void
|
||||
setLsaInterestFilter();
|
||||
|
||||
void
|
||||
startEventLoop();
|
||||
@@ -125,25 +124,6 @@ public:
|
||||
return m_nlsrFace;
|
||||
}
|
||||
|
||||
// KeyManager&
|
||||
// getKeyManager()
|
||||
// {
|
||||
// return m_km;
|
||||
// }
|
||||
|
||||
|
||||
InterestManager&
|
||||
getInterestManager()
|
||||
{
|
||||
return m_interestManager;
|
||||
}
|
||||
|
||||
DataManager&
|
||||
getDataManager()
|
||||
{
|
||||
return m_dataManager;
|
||||
}
|
||||
|
||||
SequencingManager&
|
||||
getSequencingManager()
|
||||
{
|
||||
@@ -256,10 +236,7 @@ private:
|
||||
ConfParameter m_confParam;
|
||||
AdjacencyList m_adjacencyList;
|
||||
NamePrefixList m_namePrefixList;
|
||||
InterestManager m_interestManager;
|
||||
DataManager m_dataManager;
|
||||
SequencingManager m_sequencingManager;
|
||||
// KeyManager m_km;
|
||||
bool m_isDaemonProcess;
|
||||
std::string m_configFileName;
|
||||
Lsdb m_nlsrLsdb;
|
||||
@@ -268,10 +245,11 @@ private:
|
||||
bool m_isRouteCalculationScheduled;
|
||||
bool m_isRoutingTableCalculating;
|
||||
RoutingTable m_routingTable;
|
||||
NamePrefixTable m_namePrefixTable;
|
||||
Fib m_fib;
|
||||
NamePrefixTable m_namePrefixTable;
|
||||
SyncLogicHandler m_syncLogicHandler;
|
||||
int32_t m_apiPort;
|
||||
HelloProtocol m_helloProtocol;
|
||||
};
|
||||
|
||||
} //namespace nlsr
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
FibEntry(const std::string& name)
|
||||
FibEntry(const ndn::Name& name)
|
||||
: m_timeToRefresh(0)
|
||||
, m_seqNo(0)
|
||||
, m_nexthopList()
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getName() const
|
||||
{
|
||||
return m_name;
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
isEqualNextHops(NexthopList& nhlOther);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
ndn::Name m_name;
|
||||
int32_t m_timeToRefresh;
|
||||
ndn::EventId m_expiringEventId;
|
||||
int32_t m_seqNo;
|
||||
|
||||
+62
-61
@@ -14,32 +14,31 @@ using namespace std;
|
||||
using namespace ndn;
|
||||
|
||||
static bool
|
||||
fibEntryNameCompare(const FibEntry& fibEntry, const string& name)
|
||||
fibEntryNameCompare(const FibEntry& fibEntry, const ndn::Name& name)
|
||||
{
|
||||
return fibEntry.getName() == name ;
|
||||
}
|
||||
|
||||
void
|
||||
Fib::cancelScheduledExpiringEvent(Nlsr& pnlsr, EventId eid)
|
||||
Fib::cancelScheduledExpiringEvent(EventId eid)
|
||||
{
|
||||
pnlsr.getScheduler().cancelEvent(eid);
|
||||
m_nlsr.getScheduler().cancelEvent(eid);
|
||||
}
|
||||
|
||||
|
||||
ndn::EventId
|
||||
Fib::scheduleEntryRefreshing(Nlsr& pnlsr, const string& name, int32_t feSeqNum,
|
||||
Fib::scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
|
||||
int32_t refreshTime)
|
||||
{
|
||||
std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl;
|
||||
std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
|
||||
return pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
|
||||
ndn::bind(&Fib::refreshEntry, this,
|
||||
boost::ref(pnlsr),
|
||||
name, feSeqNum));
|
||||
return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
|
||||
ndn::bind(&Fib::refreshEntry, this,
|
||||
name, feSeqNum));
|
||||
}
|
||||
|
||||
void
|
||||
Fib::refreshEntry(Nlsr& nlsr, const string& name, int32_t feSeqNum)
|
||||
Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum)
|
||||
{
|
||||
std::cout << "Fib::refreshEntry Called" << std::endl;
|
||||
std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
|
||||
@@ -53,26 +52,24 @@ Fib::refreshEntry(Nlsr& nlsr, const string& name, int32_t feSeqNum)
|
||||
{
|
||||
std::cout << "Refreshing the FIB entry" << std::endl;
|
||||
for (std::list<NextHop>::iterator nhit =
|
||||
(*it).getNexthopList().getNextHops().begin();
|
||||
nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
|
||||
(*it).getNexthopList().getNextHops().begin();
|
||||
nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
|
||||
{
|
||||
// add entry to NDN-FIB
|
||||
registerPrefixInNfd(it->getName(), nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
|
||||
registerPrefixInNfd(it->getName(), nhit->getConnectingFace(),
|
||||
std::ceil(nhit->getRouteCost()));
|
||||
}
|
||||
|
||||
// increase sequence number and schedule refresh again
|
||||
it->setSeqNo(feSeqNum + 1);
|
||||
it->setExpiringEventId(scheduleEntryRefreshing(nlsr,
|
||||
it->getName() ,
|
||||
it->getSeqNo(),
|
||||
it->setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
|
||||
it->getSeqNo(),
|
||||
m_refreshTime));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Fib::remove(Nlsr& pnlsr, const std::string& name)
|
||||
Fib::remove(const ndn::Name& name)
|
||||
{
|
||||
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
m_table.end(),
|
||||
@@ -84,14 +81,14 @@ Fib::remove(Nlsr& pnlsr, const std::string& name)
|
||||
nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
|
||||
{
|
||||
//remove entry from NDN-FIB
|
||||
if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
|
||||
if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName()))
|
||||
{
|
||||
unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
|
||||
nhit->getConnectingFace())
|
||||
if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
|
||||
nhit->getConnectingFace())
|
||||
{
|
||||
unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
|
||||
}
|
||||
@@ -99,19 +96,19 @@ Fib::remove(Nlsr& pnlsr, const std::string& name)
|
||||
}
|
||||
std::cout << "Cancellling Scheduled event" << std::endl;
|
||||
std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
|
||||
cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
|
||||
cancelScheduledExpiringEvent((*it).getExpiringEventId());
|
||||
m_table.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
|
||||
Fib::update(const ndn::Name& name, NexthopList& nextHopList)
|
||||
{
|
||||
std::cout << "Fib::updateFib Called" << std::endl;
|
||||
int startFace = 0;
|
||||
int endFace = getNumberOfFacesForName(nextHopList,
|
||||
pnlsr.getConfParameter().getMaxFacesPerPrefix());
|
||||
m_nlsr.getConfParameter().getMaxFacesPerPrefix());
|
||||
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
m_table.end(),
|
||||
bind(&fibEntryNameCompare, _1, name));
|
||||
@@ -127,13 +124,13 @@ Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
|
||||
{
|
||||
newEntry.getNexthopList().addNextHop((*nhit));
|
||||
//Add entry to NDN-FIB
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(),
|
||||
std::ceil(nhit->getRouteCost()));
|
||||
}
|
||||
newEntry.getNexthopList().sort();
|
||||
newEntry.setTimeToRefresh(m_refreshTime);
|
||||
newEntry.setSeqNo(1);
|
||||
newEntry.setExpiringEventId(scheduleEntryRefreshing(pnlsr,
|
||||
name , 1, m_refreshTime));
|
||||
newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1, m_refreshTime));
|
||||
m_table.push_back(newEntry);
|
||||
}
|
||||
}
|
||||
@@ -148,8 +145,9 @@ Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
|
||||
std::list<NextHop> nhl = nextHopList.getNextHops();
|
||||
std::list<NextHop>::iterator nhit = nhl.begin();
|
||||
// Add first Entry to NDN-FIB
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
|
||||
removeHop(pnlsr, it->getNexthopList(), nhit->getConnectingFace(), name);
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(),
|
||||
std::ceil(nhit->getRouteCost()));
|
||||
removeHop(it->getNexthopList(), nhit->getConnectingFace(), name);
|
||||
it->getNexthopList().reset();
|
||||
it->getNexthopList().addNextHop((*nhit));
|
||||
++startFace;
|
||||
@@ -158,21 +156,21 @@ Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
|
||||
{
|
||||
it->getNexthopList().addNextHop((*nhit));
|
||||
//Add Entry to NDN_FIB
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(), std::ceil(nhit->getRouteCost()));
|
||||
registerPrefixInNfd(name, nhit->getConnectingFace(),
|
||||
std::ceil(nhit->getRouteCost()));
|
||||
}
|
||||
}
|
||||
it->setTimeToRefresh(m_refreshTime);
|
||||
std::cout << "Cancellling Scheduled event" << std::endl;
|
||||
std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
|
||||
cancelScheduledExpiringEvent(pnlsr, it->getExpiringEventId());
|
||||
cancelScheduledExpiringEvent(it->getExpiringEventId());
|
||||
it->setSeqNo(it->getSeqNo() + 1);
|
||||
(*it).setExpiringEventId(scheduleEntryRefreshing(pnlsr,
|
||||
it->getName() ,
|
||||
(*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
|
||||
it->getSeqNo(), m_refreshTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
remove(pnlsr, name);
|
||||
remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,27 +178,28 @@ Fib::update(Nlsr& pnlsr, const string& name, NexthopList& nextHopList)
|
||||
|
||||
|
||||
void
|
||||
Fib::clean(Nlsr& pnlsr)
|
||||
Fib::clean()
|
||||
{
|
||||
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
|
||||
++it)
|
||||
{
|
||||
std::cout << "Cancellling Scheduled event" << std::endl;
|
||||
std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() << std::endl;
|
||||
cancelScheduledExpiringEvent(pnlsr, (*it).getExpiringEventId());
|
||||
std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() <<
|
||||
std::endl;
|
||||
cancelScheduledExpiringEvent((*it).getExpiringEventId());
|
||||
for (std::list<NextHop>::iterator nhit =
|
||||
(*it).getNexthopList().getNextHops().begin();
|
||||
nhit != (*it).getNexthopList().getNextHops().end(); nhit++)
|
||||
{
|
||||
//Remove entry from NDN-FIB
|
||||
if (!pnlsr.getAdjacencyList().isNeighbor(it->getName()))
|
||||
if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName()))
|
||||
{
|
||||
unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pnlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
|
||||
nhit->getConnectingFace())
|
||||
if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFace() !=
|
||||
nhit->getConnectingFace())
|
||||
{
|
||||
unregisterPrefixFromNfd(it->getName(), nhit->getConnectingFace());
|
||||
}
|
||||
@@ -214,7 +213,8 @@ Fib::clean(Nlsr& pnlsr)
|
||||
}
|
||||
|
||||
int
|
||||
Fib::getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix)
|
||||
Fib::getNumberOfFacesForName(NexthopList& nextHopList,
|
||||
uint32_t maxFacesPerPrefix)
|
||||
{
|
||||
int endFace = 0;
|
||||
if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix))
|
||||
@@ -229,8 +229,8 @@ Fib::getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefi
|
||||
}
|
||||
|
||||
void
|
||||
Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
const std::string& name)
|
||||
Fib::removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
const ndn::Name& name)
|
||||
{
|
||||
for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
|
||||
it != nl.getNextHops().end(); ++it)
|
||||
@@ -238,14 +238,14 @@ Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
if (it->getConnectingFace() != doNotRemoveHopFaceId)
|
||||
{
|
||||
//Remove FIB Entry from NDN-FIB
|
||||
if (!pnlsr.getAdjacencyList().isNeighbor(name))
|
||||
if (!m_nlsr.getAdjacencyList().isNeighbor(name))
|
||||
{
|
||||
unregisterPrefixFromNfd(name, it->getConnectingFace());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pnlsr.getAdjacencyList().getAdjacent(name).getConnectingFace() !=
|
||||
it->getConnectingFace())
|
||||
if (m_nlsr.getAdjacencyList().getAdjacent(name).getConnectingFace() !=
|
||||
it->getConnectingFace())
|
||||
{
|
||||
unregisterPrefixFromNfd(name, it->getConnectingFace());
|
||||
}
|
||||
@@ -255,32 +255,31 @@ Fib::removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
}
|
||||
|
||||
void
|
||||
Fib::registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost)
|
||||
Fib::registerPrefixInNfd(const ndn::Name& namePrefix, uint64_t faceId,
|
||||
uint64_t faceCost)
|
||||
{
|
||||
ndn::nfd::ControlParameters controlParameters;
|
||||
controlParameters
|
||||
.setName(namePrefix)
|
||||
.setCost(faceCost)
|
||||
.setFaceId(faceId)
|
||||
.setExpirationPeriod(ndn::time::milliseconds(m_refreshTime*1000))
|
||||
.setOrigin(128);
|
||||
|
||||
.setName(namePrefix)
|
||||
.setCost(faceCost)
|
||||
.setFaceId(faceId)
|
||||
.setExpirationPeriod(ndn::time::milliseconds(m_refreshTime * 1000))
|
||||
.setOrigin(128);
|
||||
m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
|
||||
ndn::bind(&Fib::onSuccess, this, _1,
|
||||
"Successful in name registration"),
|
||||
ndn::bind(&Fib::onFailure, this, _1, _2,
|
||||
"Failed in name registration"));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Fib::unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId)
|
||||
Fib::unregisterPrefixFromNfd(const ndn::Name& namePrefix, uint64_t faceId)
|
||||
{
|
||||
ndn::nfd::ControlParameters controlParameters;
|
||||
controlParameters
|
||||
.setName(namePrefix)
|
||||
.setFaceId(faceId)
|
||||
.setOrigin(128);
|
||||
|
||||
.setName(namePrefix)
|
||||
.setFaceId(faceId)
|
||||
.setOrigin(128);
|
||||
m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
|
||||
ndn::bind(&Fib::onSuccess, this, _1,
|
||||
"Successful in unregistering name"),
|
||||
@@ -289,13 +288,15 @@ Fib::unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId)
|
||||
}
|
||||
|
||||
void
|
||||
Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message)
|
||||
Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
|
||||
const std::string& message)
|
||||
{
|
||||
std::cout << message << ": " << commandSuccessResult << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
Fib::onFailure(uint32_t code, const std::string& error, const std::string& message)
|
||||
Fib::onFailure(uint32_t code, const std::string& error,
|
||||
const std::string& message)
|
||||
{
|
||||
std::cout << message << ": " << error << " (code: " << code << ")";
|
||||
}
|
||||
|
||||
+18
-14
@@ -16,8 +16,9 @@ class Nlsr;
|
||||
class Fib
|
||||
{
|
||||
public:
|
||||
Fib(ndn::Face& face)
|
||||
: m_table()
|
||||
Fib(Nlsr& nlsr, ndn::Face& face)
|
||||
: m_nlsr(nlsr)
|
||||
, m_table()
|
||||
, m_refreshTime(0)
|
||||
, m_controller(face)
|
||||
{
|
||||
@@ -27,13 +28,13 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
remove(Nlsr& pnlsr, const std::string& name);
|
||||
remove(const ndn::Name& name);
|
||||
|
||||
void
|
||||
update(Nlsr& pnlsr, const std::string& name, NexthopList& nextHopList);
|
||||
update(const ndn::Name& name, NexthopList& nextHopList);
|
||||
|
||||
void
|
||||
clean(Nlsr& pnlsr);
|
||||
clean();
|
||||
|
||||
void
|
||||
setEntryRefreshTime(int32_t fert)
|
||||
@@ -46,35 +47,38 @@ public:
|
||||
|
||||
private:
|
||||
void
|
||||
removeHop(Nlsr& pnlsr, NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
const std::string& name);
|
||||
removeHop(NexthopList& nl, uint32_t doNotRemoveHopFaceId,
|
||||
const ndn::Name& name);
|
||||
|
||||
int
|
||||
getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
|
||||
|
||||
ndn::EventId
|
||||
scheduleEntryRefreshing(Nlsr& pnlsr, const std::string& name, int32_t feSeqNum,
|
||||
scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
|
||||
int32_t refreshTime);
|
||||
|
||||
void
|
||||
cancelScheduledExpiringEvent(Nlsr& pnlsr, ndn::EventId eid);
|
||||
cancelScheduledExpiringEvent(ndn::EventId eid);
|
||||
|
||||
void
|
||||
refreshEntry(Nlsr& nlsr, const std::string& name, int32_t feSeqNum);
|
||||
refreshEntry(const ndn::Name& name, int32_t feSeqNum);
|
||||
|
||||
void
|
||||
registerPrefixInNfd(const std::string& namePrefix, uint64_t faceId, uint64_t faceCost);
|
||||
registerPrefixInNfd(const ndn::Name& namePrefix, uint64_t faceId,
|
||||
uint64_t faceCost);
|
||||
|
||||
void
|
||||
unregisterPrefixFromNfd(const std::string& namePrefix, uint64_t faceId);
|
||||
|
||||
unregisterPrefixFromNfd(const ndn::Name& namePrefix, uint64_t faceId);
|
||||
|
||||
void
|
||||
onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message);
|
||||
onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
|
||||
const std::string& message);
|
||||
|
||||
void
|
||||
onFailure(uint32_t code, const std::string& error, const std::string& message);
|
||||
|
||||
private:
|
||||
Nlsr& m_nlsr;
|
||||
std::list<FibEntry> m_table;
|
||||
int32_t m_refreshTime;
|
||||
ndn::nfd::Controller m_controller;
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#define NLSR_MAP_ENTRY_HPP
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/name.hpp>
|
||||
|
||||
namespace nlsr{
|
||||
namespace nlsr {
|
||||
|
||||
class MapEntry
|
||||
{
|
||||
@@ -18,13 +19,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
MapEntry(const std::string& rtr, int32_t mn)
|
||||
MapEntry(const ndn::Name& rtr, int32_t mn)
|
||||
{
|
||||
m_router = rtr;
|
||||
m_mappingNumber = mn;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getRouter() const
|
||||
{
|
||||
return m_router;
|
||||
@@ -37,7 +38,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_router;
|
||||
ndn::Name m_router;
|
||||
int32_t m_mappingNumber;
|
||||
};
|
||||
|
||||
|
||||
+9
-9
@@ -12,7 +12,7 @@ namespace nlsr {
|
||||
using namespace std;
|
||||
|
||||
static bool
|
||||
mapEntryCompareByRouter(MapEntry& mpe1, const string& rtrName)
|
||||
mapEntryCompareByRouter(MapEntry& mpe1, const ndn::Name& rtrName)
|
||||
{
|
||||
return mpe1.getRouter() == rtrName;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ mapEntryCompareByMappingNo(MapEntry& mpe1, int32_t mappingNo)
|
||||
}
|
||||
|
||||
void
|
||||
Map::addEntry(const string& rtrName)
|
||||
Map::addEntry(const ndn::Name& rtrName)
|
||||
{
|
||||
MapEntry me(rtrName, m_mappingIndex);
|
||||
if (addEntry(me))
|
||||
@@ -48,7 +48,7 @@ Map::addEntry(MapEntry& mpe)
|
||||
return false;
|
||||
}
|
||||
|
||||
string
|
||||
const ndn::Name
|
||||
Map::getRouterNameByMappingNo(int32_t mn)
|
||||
{
|
||||
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
@@ -59,11 +59,11 @@ Map::getRouterNameByMappingNo(int32_t mn)
|
||||
{
|
||||
return (*it).getRouter();
|
||||
}
|
||||
return "";
|
||||
return ndn::Name();
|
||||
}
|
||||
|
||||
int32_t
|
||||
Map::getMappingNoByRouterName(string& rName)
|
||||
Map::getMappingNoByRouterName(const ndn::Name& rName)
|
||||
{
|
||||
std::list<MapEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
m_table.end(),
|
||||
@@ -83,14 +83,14 @@ Map::createFromAdjLsdb(Nlsr& pnlsr)
|
||||
for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
|
||||
it != adjLsdb.end() ; it++)
|
||||
{
|
||||
string linkStartRouter = (*it).getOrigRouter();
|
||||
addEntry(linkStartRouter);
|
||||
//ndn::Name& linkStartRouter = (*it).getOrigRouter();
|
||||
addEntry((*it).getOrigRouter());
|
||||
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
|
||||
for (std::list<Adjacent>::iterator itAdl = adl.begin();
|
||||
itAdl != adl.end() ; itAdl++)
|
||||
{
|
||||
string linkEndRouter = (*itAdl).getName();
|
||||
addEntry(linkEndRouter);
|
||||
//ndn::Name& linkEndRouter = (*itAdl).getName();
|
||||
addEntry((*itAdl).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -23,16 +23,16 @@ public:
|
||||
|
||||
|
||||
void
|
||||
addEntry(const std::string& rtrName);
|
||||
addEntry(const ndn::Name& rtrName);
|
||||
|
||||
void
|
||||
createFromAdjLsdb(Nlsr& pnlsr);
|
||||
|
||||
std::string
|
||||
const ndn::Name
|
||||
getRouterNameByMappingNo(int32_t mn);
|
||||
|
||||
int32_t
|
||||
getMappingNoByRouterName(std::string& rName);
|
||||
getMappingNoByRouterName(const ndn::Name& rName);
|
||||
|
||||
void
|
||||
reset();
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
return m_table;
|
||||
}
|
||||
|
||||
int
|
||||
size_t
|
||||
getMapSize() const
|
||||
{
|
||||
return m_table.size();
|
||||
|
||||
@@ -27,7 +27,7 @@ NamePrefixTableEntry::generateNhlfromRteList()
|
||||
|
||||
|
||||
static bool
|
||||
rteCompare(RoutingTableEntry& rte, string& destRouter)
|
||||
rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
|
||||
{
|
||||
return rte.getDestination() == destRouter;
|
||||
}
|
||||
@@ -57,7 +57,8 @@ NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
|
||||
else
|
||||
{
|
||||
(*it).getNexthopList().reset(); // reseting existing routing table's next hop
|
||||
for (std::list<NextHop>::iterator nhit = rte.getNexthopList().getNextHops().begin();
|
||||
for (std::list<NextHop>::iterator nhit =
|
||||
rte.getNexthopList().getNextHops().begin();
|
||||
nhit != rte.getNexthopList().getNextHops().end(); ++nhit)
|
||||
{
|
||||
(*it).getNexthopList().addNextHop((*nhit));
|
||||
|
||||
@@ -16,13 +16,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
NamePrefixTableEntry(const std::string& namePrefix)
|
||||
: m_nexthopList()
|
||||
NamePrefixTableEntry(const ndn::Name& namePrefix)
|
||||
: m_namePrefix(namePrefix)
|
||||
, m_nexthopList()
|
||||
{
|
||||
m_namePrefix = namePrefix;
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const ndn::Name&
|
||||
getNamePrefix() const
|
||||
{
|
||||
return m_namePrefix;
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
addRoutingTableEntry(RoutingTableEntry& rte);
|
||||
|
||||
private:
|
||||
std::string m_namePrefix;
|
||||
ndn::Name m_namePrefix;
|
||||
std::list<RoutingTableEntry> m_rteList;
|
||||
NexthopList m_nexthopList;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "nlsr.hpp"
|
||||
#include "name-prefix-table.hpp"
|
||||
#include "name-prefix-table-entry.hpp"
|
||||
#include "routing-table.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace nlsr {
|
||||
using namespace std;
|
||||
|
||||
static bool
|
||||
npteCompare(NamePrefixTableEntry& npte, const string& name)
|
||||
npteCompare(NamePrefixTableEntry& npte, const ndn::Name& name)
|
||||
{
|
||||
return npte.getNamePrefix() == name;
|
||||
}
|
||||
@@ -21,7 +22,7 @@ npteCompare(NamePrefixTableEntry& npte, const string& name)
|
||||
|
||||
|
||||
void
|
||||
NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
|
||||
NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte)
|
||||
{
|
||||
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
m_table.end(), bind(&npteCompare, _1, name));
|
||||
@@ -34,7 +35,7 @@ NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnls
|
||||
m_table.push_back(newEntry);
|
||||
if (rte.getNexthopList().getSize() > 0)
|
||||
{
|
||||
pnlsr.getFib().update(pnlsr, name, newEntry.getNexthopList());
|
||||
m_nlsr.getFib().update(name, newEntry.getNexthopList());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -44,77 +45,82 @@ NamePrefixTable::addEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnls
|
||||
(*it).addRoutingTableEntry(rte);
|
||||
(*it).generateNhlfromRteList();
|
||||
(*it).getNexthopList().sort();
|
||||
pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
|
||||
m_nlsr.getFib().update(name, (*it).getNexthopList());
|
||||
}
|
||||
else
|
||||
{
|
||||
(*it).resetRteListNextHop();
|
||||
(*it).getNexthopList().reset();
|
||||
pnlsr.getFib().remove(pnlsr, name);
|
||||
m_nlsr.getFib().remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NamePrefixTable::removeEntry(const string& name, RoutingTableEntry& rte, Nlsr& pnlsr)
|
||||
NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte)
|
||||
{
|
||||
std::list<NamePrefixTableEntry>::iterator it = std::find_if(m_table.begin(),
|
||||
m_table.end(), bind(&npteCompare, _1, name));
|
||||
if (it != m_table.end())
|
||||
{
|
||||
string destRouter = rte.getDestination();
|
||||
ndn::Name destRouter = rte.getDestination();
|
||||
(*it).removeRoutingTableEntry(rte);
|
||||
if (((*it).getRteListSize() == 0) &&
|
||||
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/1", 1)) &&
|
||||
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/2", 2)) &&
|
||||
(!pnlsr.getLsdb().doesLsaExist(destRouter + "/3", 3)))
|
||||
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/name"),
|
||||
std::string("name"))) &&
|
||||
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/adjacency"),
|
||||
std::string("adjacency"))) &&
|
||||
(!m_nlsr.getLsdb().doesLsaExist(destRouter.append("/coordinate"),
|
||||
std::string("coordinate"))))
|
||||
{
|
||||
m_table.erase(it);
|
||||
pnlsr.getFib().remove(pnlsr, name);
|
||||
m_nlsr.getFib().remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
(*it).generateNhlfromRteList();
|
||||
pnlsr.getFib().update(pnlsr, name, (*it).getNexthopList());
|
||||
m_nlsr.getFib().update(name, (*it).getNexthopList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NamePrefixTable::addEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
|
||||
NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter)
|
||||
{
|
||||
//
|
||||
RoutingTableEntry* rteCheck =
|
||||
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
|
||||
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
|
||||
if (rteCheck != 0)
|
||||
{
|
||||
addEntry(name, *(rteCheck) , pnlsr);
|
||||
addEntry(name, *(rteCheck));
|
||||
}
|
||||
else
|
||||
{
|
||||
RoutingTableEntry rte(destRouter);
|
||||
addEntry(name, rte, pnlsr);
|
||||
addEntry(name, rte);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NamePrefixTable::removeEntry(const string& name, const string& destRouter, Nlsr& pnlsr)
|
||||
NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter)
|
||||
{
|
||||
//
|
||||
RoutingTableEntry* rteCheck =
|
||||
pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
|
||||
m_nlsr.getRoutingTable().findRoutingTableEntry(destRouter);
|
||||
if (rteCheck != 0)
|
||||
{
|
||||
removeEntry(name, *(rteCheck), pnlsr);
|
||||
removeEntry(name, *(rteCheck));
|
||||
}
|
||||
else
|
||||
{
|
||||
RoutingTableEntry rte(destRouter);
|
||||
removeEntry(name, rte, pnlsr);
|
||||
removeEntry(name, rte);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NamePrefixTable::updateWithNewRoute(Nlsr& pnlsr)
|
||||
NamePrefixTable::updateWithNewRoute()
|
||||
{
|
||||
for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
|
||||
it != m_table.end(); ++it)
|
||||
@@ -124,15 +130,15 @@ NamePrefixTable::updateWithNewRoute(Nlsr& pnlsr)
|
||||
rteit != rteList.end(); ++rteit)
|
||||
{
|
||||
RoutingTableEntry* rteCheck =
|
||||
pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
|
||||
m_nlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
|
||||
if (rteCheck != 0)
|
||||
{
|
||||
addEntry((*it).getNamePrefix(), *(rteCheck), pnlsr);
|
||||
addEntry((*it).getNamePrefix(), *(rteCheck));
|
||||
}
|
||||
else
|
||||
{
|
||||
RoutingTableEntry rte((*rteit).getDestination());
|
||||
addEntry((*it).getNamePrefix(), rte, pnlsr);
|
||||
addEntry((*it).getNamePrefix(), rte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,30 +13,32 @@ class Nlsr;
|
||||
class NamePrefixTable
|
||||
{
|
||||
public:
|
||||
NamePrefixTable()
|
||||
NamePrefixTable(Nlsr& nlsr)
|
||||
: m_nlsr(nlsr)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
addEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
|
||||
addEntry(const ndn::Name& name, const ndn::Name& destRouter);
|
||||
|
||||
void
|
||||
removeEntry(const std::string& name, const std::string& destRouter, Nlsr& pnlsr);
|
||||
removeEntry(const ndn::Name& name, const ndn::Name& destRouter);
|
||||
|
||||
void
|
||||
updateWithNewRoute(Nlsr& pnlsr);
|
||||
updateWithNewRoute();
|
||||
|
||||
void
|
||||
print();
|
||||
|
||||
private:
|
||||
void
|
||||
addEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
|
||||
addEntry(const ndn::Name& name, RoutingTableEntry& rte);
|
||||
|
||||
void
|
||||
removeEntry(const std::string& name, RoutingTableEntry& rte, Nlsr& pnlsr);
|
||||
removeEntry(const ndn::Name& name, RoutingTableEntry& rte);
|
||||
|
||||
private:
|
||||
Nlsr& m_nlsr;
|
||||
std::list<NamePrefixTableEntry> m_table;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,14 +38,12 @@ RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
|
||||
for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
|
||||
it != adjLsdb.end() ; it++)
|
||||
{
|
||||
string linkStartRouter = (*it).getOrigRouter();
|
||||
int row = pMap.getMappingNoByRouterName(linkStartRouter);
|
||||
int row = pMap.getMappingNoByRouterName((*it).getOrigRouter());
|
||||
std::list<Adjacent> adl = (*it).getAdl().getAdjList();
|
||||
for (std::list<Adjacent>::iterator itAdl = adl.begin();
|
||||
itAdl != adl.end() ; itAdl++)
|
||||
{
|
||||
string linkEndRouter = (*itAdl).getName();
|
||||
int col = pMap.getMappingNoByRouterName(linkEndRouter);
|
||||
int col = pMap.getMappingNoByRouterName((*itAdl).getName());
|
||||
double cost = (*itAdl).getLinkCost();
|
||||
if ((row >= 0 && row < numOfRouter) && (col >= 0 && col < numOfRouter))
|
||||
{
|
||||
@@ -158,8 +156,7 @@ LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
|
||||
makeAdjMatrix(pnlsr, pMap);
|
||||
std::cout << pMap;
|
||||
printAdjMatrix();
|
||||
string routerName = pnlsr.getConfParameter().getRouterPrefix();
|
||||
int sourceRouter = pMap.getMappingNoByRouterName(routerName);
|
||||
int sourceRouter = pMap.getMappingNoByRouterName(pnlsr.getConfParameter().getRouterPrefix());
|
||||
//int noLink=getNumOfLinkfromAdjMatrix(sourceRouter);
|
||||
allocateParent();
|
||||
allocateDistance();
|
||||
@@ -259,8 +256,7 @@ LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(Nlsr& pnlsr,
|
||||
if (nextHopRouter != NO_NEXT_HOP)
|
||||
{
|
||||
double routeCost = m_distance[i];
|
||||
string nextHopRouterName =
|
||||
pMap.getRouterNameByMappingNo(nextHopRouter);
|
||||
ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(nextHopRouter);
|
||||
int nxtHopFace =
|
||||
pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFace();
|
||||
std::cout << "Dest Router: " << pMap.getRouterNameByMappingNo(i) << std::endl;
|
||||
@@ -382,7 +378,7 @@ HypRoutingTableCalculator::calculatePath(Map& pMap,
|
||||
RoutingTable& rt, Nlsr& pnlsr)
|
||||
{
|
||||
makeAdjMatrix(pnlsr, pMap);
|
||||
string routerName = pnlsr.getConfParameter().getRouterPrefix();
|
||||
ndn::Name routerName = pnlsr.getConfParameter().getRouterPrefix();
|
||||
int sourceRouter = pMap.getMappingNoByRouterName(routerName);
|
||||
int noLink = getNumOfLinkfromAdjMatrix(sourceRouter);
|
||||
setNoLink(noLink);
|
||||
@@ -399,7 +395,7 @@ HypRoutingTableCalculator::calculatePath(Map& pMap,
|
||||
allocateDistFromNbrToDest();
|
||||
for (int j = 0; j < vNoLink; j++)
|
||||
{
|
||||
string nextHopRouterName = pMap.getRouterNameByMappingNo(links[j]);
|
||||
ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(links[j]);
|
||||
int nextHopFace =
|
||||
pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFace();
|
||||
double distToNbr = getHyperbolicDistance(pnlsr, pMap,
|
||||
@@ -431,7 +427,7 @@ HypRoutingTableCalculator::addHypNextHopsToRoutingTable(Nlsr& pnlsr, Map& pMap,
|
||||
{
|
||||
for (int i = 0 ; i < noFaces ; ++i)
|
||||
{
|
||||
string destRouter = pMap.getRouterNameByMappingNo(dest);
|
||||
ndn::Name destRouter = pMap.getRouterNameByMappingNo(dest);
|
||||
NextHop nh(m_linkFaces[i], m_distFromNbrToDest[i]);
|
||||
rt.addNextHop(destRouter, nh);
|
||||
if (m_isDryRun)
|
||||
@@ -446,8 +442,10 @@ HypRoutingTableCalculator::getHyperbolicDistance(Nlsr& pnlsr,
|
||||
Map& pMap, int src, int dest)
|
||||
{
|
||||
double distance = 0.0;
|
||||
string srcRouterKey = pMap.getRouterNameByMappingNo(src) + "/3";
|
||||
string destRouterKey = pMap.getRouterNameByMappingNo(dest) + "/3";
|
||||
ndn::Name srcRouterKey = pMap.getRouterNameByMappingNo(src);
|
||||
srcRouterKey.append("coordinate");
|
||||
ndn::Name destRouterKey = pMap.getRouterNameByMappingNo(dest);
|
||||
destRouterKey.append("coordinate");
|
||||
double srcRadius = (pnlsr.getLsdb().findCoordinateLsa(
|
||||
srcRouterKey))->getCorRadius();
|
||||
double srcTheta = (pnlsr.getLsdb().findCoordinateLsa(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define NLSR_ROUTING_TABLE_ENTRY_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <ndn-cxx/name.hpp>
|
||||
#include "nexthop-list.hpp"
|
||||
|
||||
namespace nlsr {
|
||||
@@ -18,13 +18,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
RoutingTableEntry(const std::string& dest)
|
||||
RoutingTableEntry(const ndn::Name& dest)
|
||||
{
|
||||
m_destination = dest;
|
||||
}
|
||||
|
||||
std::string
|
||||
getDestination()
|
||||
const ndn::Name&
|
||||
getDestination() const
|
||||
{
|
||||
return m_destination;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_destination;
|
||||
ndn::Name m_destination;
|
||||
NexthopList m_nexthopList;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ void
|
||||
RoutingTable::calculate(Nlsr& pnlsr)
|
||||
{
|
||||
//debugging purpose
|
||||
std::cout << pnlsr.getConfParameter() << std::endl;
|
||||
pnlsr.getNamePrefixTable().print();
|
||||
pnlsr.getLsdb().printAdjLsdb();
|
||||
pnlsr.getLsdb().printCorLsdb();
|
||||
@@ -26,7 +25,8 @@ RoutingTable::calculate(Nlsr& pnlsr)
|
||||
{
|
||||
pnlsr.setIsRoutingTableCalculating(1); //setting routing table calculation
|
||||
if (pnlsr.getLsdb().doesLsaExist(
|
||||
pnlsr.getConfParameter().getRouterPrefix() + "/" + "2", 2))
|
||||
pnlsr.getConfParameter().getRouterPrefix().toUri() + "/" + "adjacency",
|
||||
std::string("adjacency")))
|
||||
{
|
||||
if (pnlsr.getIsBuildAdjLsaSheduled() != 1)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ RoutingTable::calculate(Nlsr& pnlsr)
|
||||
calculateHypDryRoutingTable(pnlsr);
|
||||
}
|
||||
//need to update NPT here
|
||||
pnlsr.getNamePrefixTable().updateWithNewRoute(pnlsr);
|
||||
pnlsr.getNamePrefixTable().updateWithNewRoute();
|
||||
//debugging purpose
|
||||
printRoutingTable();
|
||||
pnlsr.getNamePrefixTable().print();
|
||||
@@ -71,7 +71,7 @@ RoutingTable::calculate(Nlsr& pnlsr)
|
||||
clearDryRoutingTable(); // for dry run options
|
||||
// need to update NPT here
|
||||
std::cout << "Calling Update NPT With new Route" << std::endl;
|
||||
pnlsr.getNamePrefixTable().updateWithNewRoute(pnlsr);
|
||||
pnlsr.getNamePrefixTable().updateWithNewRoute();
|
||||
//debugging purpose
|
||||
printRoutingTable();
|
||||
pnlsr.getNamePrefixTable().print();
|
||||
@@ -131,14 +131,14 @@ RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
|
||||
}
|
||||
|
||||
static bool
|
||||
routingTableEntryCompare(RoutingTableEntry& rte, string& destRouter)
|
||||
routingTableEntryCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
|
||||
{
|
||||
return rte.getDestination() == destRouter;
|
||||
}
|
||||
|
||||
// function related to manipulation of routing table
|
||||
void
|
||||
RoutingTable::addNextHop(string destRouter, NextHop& nh)
|
||||
RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh)
|
||||
{
|
||||
RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter);
|
||||
if (rteChk == 0)
|
||||
@@ -154,7 +154,7 @@ RoutingTable::addNextHop(string destRouter, NextHop& nh)
|
||||
}
|
||||
|
||||
RoutingTableEntry*
|
||||
RoutingTable::findRoutingTableEntry(const string destRouter)
|
||||
RoutingTable::findRoutingTableEntry(const ndn::Name& destRouter)
|
||||
{
|
||||
std::list<RoutingTableEntry>::iterator it = std::find_if(m_rTable.begin(),
|
||||
m_rTable.end(),
|
||||
@@ -180,7 +180,7 @@ RoutingTable::printRoutingTable()
|
||||
|
||||
//function related to manipulation of dry routing table
|
||||
void
|
||||
RoutingTable::addNextHopToDryTable(string destRouter, NextHop& nh)
|
||||
RoutingTable::addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh)
|
||||
{
|
||||
std::list<RoutingTableEntry>::iterator it = std::find_if(m_dryTable.begin(),
|
||||
m_dryTable.end(),
|
||||
|
||||
@@ -24,19 +24,19 @@ public:
|
||||
calculate(Nlsr& pnlsr);
|
||||
|
||||
void
|
||||
addNextHop(std::string destRouter, NextHop& nh);
|
||||
addNextHop(const ndn::Name& destRouter, NextHop& nh);
|
||||
|
||||
void
|
||||
printRoutingTable();
|
||||
|
||||
void
|
||||
addNextHopToDryTable(std::string destRouter, NextHop& nh);
|
||||
addNextHopToDryTable(const ndn::Name& destRouter, NextHop& nh);
|
||||
|
||||
void
|
||||
printDryRoutingTable();
|
||||
|
||||
RoutingTableEntry*
|
||||
findRoutingTableEntry(const std::string destRouter);
|
||||
findRoutingTableEntry(const ndn::Name& destRouter);
|
||||
|
||||
void
|
||||
scheduleRoutingTableCalculation(Nlsr& pnlsr);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef NLSR_NAME_HELPER_HPP
|
||||
#define NLSR_NAME_HELPER_HPP
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <ndn-cxx/name-component.hpp>
|
||||
#include <ndn-cxx/name.hpp>
|
||||
|
||||
namespace nlsr {
|
||||
namespace util {
|
||||
/**
|
||||
* @brief search a name component in ndn::Name and return the position of the component
|
||||
* @param name where to search the searchString
|
||||
* @param searchString, the string to search in name
|
||||
* @retrun int32_t -1 if searchString not found else return the position
|
||||
* starting from 0
|
||||
*/
|
||||
|
||||
inline static int32_t
|
||||
getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
|
||||
{
|
||||
ndn::name::Component component(searchString);
|
||||
size_t nameSize = name.size();
|
||||
for (uint32_t i = 0; i < nameSize; i++)
|
||||
{
|
||||
if (component == name[i])
|
||||
{
|
||||
return (int32_t)i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
} //namespace util
|
||||
|
||||
} // namespace nlsr
|
||||
|
||||
#endif //NLSR_NAME_HELPER_HPP
|
||||
+8
-8
@@ -24,10 +24,10 @@ BOOST_AUTO_TEST_CASE(NameLsaBasic)
|
||||
|
||||
//lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12.
|
||||
//1800 is default lsa refresh time.
|
||||
NameLsa nlsa1("router1", 1, 12, 1800, npl1);
|
||||
NameLsa nlsa2("router2", 1, 12, 1500, npl1);
|
||||
NameLsa nlsa1("router1", std::string("name"), 12, 1800, npl1);
|
||||
NameLsa nlsa2("router2", std::string("name"), 12, 1500, npl1);
|
||||
|
||||
BOOST_CHECK_EQUAL(nlsa1.getLsType(), (uint8_t)1);
|
||||
BOOST_CHECK_EQUAL(nlsa1.getLsType(), "name");
|
||||
|
||||
BOOST_CHECK(nlsa1.getLifeTime() != nlsa2.getLifeTime());
|
||||
|
||||
@@ -44,10 +44,10 @@ BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
|
||||
|
||||
//For AdjLsa, lsType is 2.
|
||||
//1 is the number of adjacent in adjacent list.
|
||||
AdjLsa alsa1("router1", 2, 12, 1800, 1, adjList);
|
||||
AdjLsa alsa2("router1", 2, 12, 1800, 1, adjList);
|
||||
AdjLsa alsa1("router1", std::string("adjacency"), 12, 1800, 1, adjList);
|
||||
AdjLsa alsa2("router1", std::string("adjacency"), 12, 1800, 1, adjList);
|
||||
|
||||
BOOST_CHECK_EQUAL(alsa1.getLsType(), (uint8_t)2);
|
||||
BOOST_CHECK_EQUAL(alsa1.getLsType(), "adjacency");
|
||||
BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12);
|
||||
BOOST_CHECK_EQUAL(alsa1.getLifeTime(), (uint32_t)1800);
|
||||
BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1);
|
||||
@@ -63,8 +63,8 @@ BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
|
||||
BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
|
||||
{
|
||||
//For CoordinateLsa, lsType is 3.
|
||||
CoordinateLsa clsa1("router1", 3, 12, 1800, 2.5, 30.0);
|
||||
CoordinateLsa clsa2("router1", 3, 12, 1800, 2.5, 30.0);
|
||||
CoordinateLsa clsa1("router1", std::string("coordinate"), 12, 1800, 2.5, 30.0);
|
||||
CoordinateLsa clsa2("router1", std::string("coordinate"), 12, 1800, 2.5, 30.0);
|
||||
|
||||
BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
|
||||
BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
|
||||
|
||||
+6
-6
@@ -31,17 +31,17 @@ BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
|
||||
//For NameLsa lsType is 1.
|
||||
//12 is seqNo, randomly generated.
|
||||
//1800 is the default life time.
|
||||
NameLsa nlsa1("router1", 1, 12, 1800, npl1);
|
||||
NameLsa nlsa1("router1", std::string("name"), 12, 1800, npl1);
|
||||
|
||||
Lsdb lsdb1;
|
||||
Lsdb lsdb1(nlsr1);
|
||||
|
||||
lsdb1.installNameLsa(nlsr1, nlsa1);
|
||||
lsdb1.installNameLsa(nlsa1);
|
||||
|
||||
BOOST_CHECK(lsdb1.doesLsaExist("router1/1", 1));
|
||||
BOOST_CHECK(lsdb1.doesLsaExist("router1/1", std::string("name")));
|
||||
|
||||
lsdb1.removeNameLsa(nlsr1, router1);
|
||||
lsdb1.removeNameLsa(router1);
|
||||
|
||||
BOOST_CHECK_EQUAL(lsdb1.doesLsaExist("router1/1", 1), false);
|
||||
BOOST_CHECK_EQUAL(lsdb1.doesLsaExist("router1/1", std::string("name")), false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in new issue
Block a user