Browse Source

src: Recreating face in case of face deletion by NFD

Change-Id: Idd1d0b7f521e574ace38d6f671a682622d98209d
pull/1/head
akmhoque 11 years ago
parent
commit
c04e7270d2
  1. 28
      src/adjacency-list.cpp
  2. 6
      src/adjacency-list.hpp
  3. 26
      src/adjacent.cpp
  4. 28
      src/adjacent.hpp
  5. 2
      src/conf-file-processor.cpp
  6. 83
      src/face-monitor.cpp
  7. 65
      src/face-monitor.hpp
  8. 86
      src/hello-protocol.cpp
  9. 10
      src/hello-protocol.hpp
  10. 2
      src/lsa.cpp
  11. 104
      src/nlsr.cpp
  12. 34
      src/nlsr.hpp
  13. 79
      src/route/fib.cpp
  14. 35
      src/route/fib.hpp

28
src/adjacency-list.cpp

@ -233,6 +233,34 @@ AdjacencyList::find(const ndn::Name& adjName)
return it;
}
Adjacent *
AdjacencyList::findAdjacent(const ndn::Name& adjName)
{
std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
m_adjList.end(),
ndn::bind(&Adjacent::compare,
_1, ndn::cref(adjName)));
if (it != m_adjList.end()) {
return &(*it);
}
return 0;
}
Adjacent *
AdjacencyList::findAdjacent(uint64_t faceId)
{
std::list<Adjacent>::iterator it = std::find_if(m_adjList.begin(),
m_adjList.end(),
ndn::bind(&Adjacent::compareFaceId,
_1, faceId));
if (it != m_adjList.end()) {
return &(*it);
}
return 0;
}
void
AdjacencyList::writeLog()
{

6
src/adjacency-list.hpp

@ -98,6 +98,12 @@ public:
}
}
Adjacent*
findAdjacent(const ndn::Name& adjName);
Adjacent*
findAdjacent(uint64_t faceId);
void
writeLog();

26
src/adjacent.cpp

@ -43,6 +43,7 @@ Adjacent::Adjacent()
, m_linkCost(DEFAULT_LINK_COST)
, m_status(ADJACENT_STATUS_INACTIVE)
, m_interestTimedOutNo(0)
, m_faceId(0)
{
}
@ -52,18 +53,21 @@ Adjacent::Adjacent(const ndn::Name& an)
, m_linkCost(DEFAULT_LINK_COST)
, m_status(ADJACENT_STATUS_INACTIVE)
, m_interestTimedOutNo(0)
, m_faceId(0)
{
}
Adjacent::Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
uint32_t s, uint32_t iton)
{
m_name = an;
m_connectingFaceUri = cfu;
m_linkCost = lc;
m_status = s;
m_interestTimedOutNo = iton;
}
uint32_t s, uint32_t iton, uint64_t faceId)
: m_name(an)
, m_connectingFaceUri(cfu)
, m_linkCost(lc)
, m_status(s)
, m_interestTimedOutNo(iton)
, m_faceId(faceId)
{
}
bool
Adjacent::operator==(const Adjacent& adjacent) const
@ -74,12 +78,6 @@ Adjacent::operator==(const Adjacent& adjacent) const
std::numeric_limits<double>::epsilon()) ;
}
bool
Adjacent::compare(const ndn::Name& adjacencyName)
{
return m_name == adjacencyName;
}
void
Adjacent::writeLog()
{

28
src/adjacent.hpp

@ -43,7 +43,7 @@ public:
Adjacent(const ndn::Name& an);
Adjacent(const ndn::Name& an, const std::string& cfu, double lc,
uint32_t s, uint32_t iton);
uint32_t s, uint32_t iton, uint64_t faceId);
const ndn::Name&
getName() const
@ -105,11 +105,32 @@ public:
m_interestTimedOutNo = iton;
}
void
setFaceId(uint64_t faceId)
{
m_faceId = faceId;
}
uint64_t
getFaceId()
{
return m_faceId;
}
bool
operator==(const Adjacent& adjacent) const;
bool
compare(const ndn::Name& adjacencyName);
inline bool
compare(const ndn::Name& adjacencyName)
{
return m_name == adjacencyName;
}
inline bool
compareFaceId(uint64_t faceId)
{
return m_faceId == faceId;
}
void
writeLog();
@ -123,6 +144,7 @@ private:
double m_linkCost;
uint32_t m_status;
uint32_t m_interestTimedOutNo;
uint64_t m_faceId;
};
} // namespace nlsr

2
src/conf-file-processor.cpp

@ -324,7 +324,7 @@ ConfFileProcessor::processConfSectionNeighbors(boost::property_tree::ptree
Adjacent::DEFAULT_LINK_COST);
ndn::Name neighborName(name);
if (!neighborName.empty()) {
Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0);
Adjacent adj(name, faceUri, linkCost, ADJACENT_STATUS_INACTIVE, 0, 0);
m_nlsr.getAdjacencyList().insert(adj);
}
else {

83
src/face-monitor.cpp

@ -0,0 +1,83 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#include "face-monitor.hpp"
#include "logger.hpp"
namespace nlsr {
INIT_LOGGER("FaceMonitor");
void
FaceMonitor::startNotification()
{
ndn::Interest interest("/localhost/nfd/faces/events");
interest
.setMustBeFresh(true)
.setChildSelector(1)
.setInterestLifetime(ndn::time::seconds(60));
_LOG_DEBUG("FaceMonitor::startNotification sending interest: " << interest);
m_face.expressInterest(interest,
ndn::bind(&nlsr::FaceMonitor::onData, this, _2),
ndn::bind(&nlsr::FaceMonitor::onTimeout, this));
}
void
FaceMonitor::onTimeout()
{
ndn::Interest interest("/localhost/nfd/faces/events");
interest
.setMustBeFresh(true)
.setChildSelector(1)
.setInterestLifetime(ndn::time::seconds(60));
_LOG_DEBUG("FaceMonitor::onTimeout sending interest: " << interest);
m_face.expressInterest(interest,
ndn::bind(&nlsr::FaceMonitor::onData, this, _2),
ndn::bind(&nlsr::FaceMonitor::onTimeout, this));
}
void
FaceMonitor::onData(const ndn::Data& data)
{
m_lastSequence = data.getName().get(-1).toSegment();
ndn::nfd::FaceEventNotification notification(data.getContent().blockFromValue());
m_notificationCallBack(notification);
ndn::Name nextNotification("/localhost/nfd/faces/events");
nextNotification.appendSegment(m_lastSequence + 1);
ndn::Interest interest(nextNotification);
interest.setInterestLifetime(ndn::time::seconds(60));
_LOG_DEBUG("FaceMonitor::onData Interest sent: " << interest);
m_face.expressInterest(interest,
ndn::bind(&nlsr::FaceMonitor::onData, this, _2),
ndn::bind(&nlsr::FaceMonitor::onTimeout, this));
}
} // namespace nlsr

65
src/face-monitor.hpp

@ -0,0 +1,65 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014 University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
*
**/
#ifndef FACE_MONITOR_HPP
#define FACE_MONITOR_HPP
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/management/nfd-face-event-notification.hpp>
namespace nlsr {
class FaceMonitor
{
public:
typedef ndn::function<void(const ndn::nfd::FaceEventNotification&)> NotificationCallback;
typedef ndn::function<void()> TimeoutCallback;
FaceMonitor(boost::asio::io_service& ioService, const NotificationCallback& notificationCallBack)
: m_face(ioService)
, m_notificationCallBack(notificationCallBack)
{
}
~FaceMonitor()
{
}
void
startNotification();
private:
void
onTimeout();
void
onData(const ndn::Data& data);
private:
ndn::Face m_face;
NotificationCallback m_notificationCallBack;
uint64_t m_lastSequence;
};
} // namespace nlsr
#endif //FACE_MONITOR_HPP

86
src/hello-protocol.cpp

@ -54,13 +54,19 @@ 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) {
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName = (*it).getName() ;
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
if((*it).getFaceId() != 0) {
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName = (*it).getName() ;
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
else {
registerPrefixes((*it).getName(), (*it).getConnectingFaceUri(),
(*it).getLinkCost(), 31536000);
}
}
scheduleInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
}
@ -94,15 +100,21 @@ HelloProtocol::processInterest(const ndn::Name& name,
m_nlsr.getKeyChain().sign(data, m_nlsr.getDefaultCertName());
_LOG_DEBUG("Sending out data for name: " << data.getName());
m_nlsr.getNlsrFace().put(data);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
if (status == 0) {
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName(neighbor);
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
if (adjacent->getStatus() == 0) {
if(adjacent->getFaceId() != 0){
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName(neighbor);
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
else {
registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(),
adjacent->getLinkCost(), 31536000);
}
}
}
}
@ -194,4 +206,46 @@ HelloProtocol::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>&
_LOG_DEBUG("Validation Error: " << msg);
}
void
HelloProtocol::registerPrefixes(const ndn::Name adjName, const std::string& faceUri,
double linkCost, uint64_t timeout)
{
ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX;
broadcastKeyPrefix.append("KEYS");
m_nlsr.getFib().registerPrefix(adjName, faceUri, linkCost, timeout,
ndn::bind(&HelloProtocol::onRegistrationSuccess,
this, _1, ndn::cref(adjName)),
ndn::bind(&HelloProtocol::onRegistrationFailure,
this, _1, _2));
m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(),
faceUri, linkCost, timeout);
m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getLsaPrefix(),
faceUri, linkCost, timeout);
m_nlsr.getFib().registerPrefix(broadcastKeyPrefix,
faceUri, linkCost, timeout);
}
void
HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const ndn::Name neighbor)
{
Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
if (adjacent != 0) {
adjacent->setFaceId(commandSuccessResult.getFaceId());
/* interest name: /<neighbor>/NLSR/INFO/<router> */
ndn::Name interestName(neighbor);
interestName.append(NLSR_COMPONENT);
interestName.append(INFO_COMPONENT);
interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
expressInterest(interestName,
m_nlsr.getConfParameter().getInterestResendTime());
}
}
void
HelloProtocol::onRegistrationFailure(uint32_t code, const std::string& error)
{
_LOG_DEBUG(error << " (code: " << code << ")");
}
} //namespace nlsr

10
src/hello-protocol.hpp

@ -67,6 +67,16 @@ private:
onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
const std::string& msg);
void
onRegistrationFailure(uint32_t code, const std::string& error);
void
onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
const ndn::Name neighbor);
void
registerPrefixes(const ndn::Name adjName, const std::string& faceUri,
double linkCost, uint64_t timeout);
private:
Nlsr& m_nlsr;
static const std::string INFO_COMPONENT;

2
src/lsa.cpp

@ -286,7 +286,7 @@ AdjLsa::initializeFromContent(const std::string& content)
ndn::Name adjName(*tok_iter++);
std::string connectingFaceUri(*tok_iter++);
double linkCost = boost::lexical_cast<double>(*tok_iter++);
Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0);
Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0, 0);
addAdjacent(adjacent);
}
catch (std::exception& e) {

104
src/nlsr.cpp

@ -76,7 +76,7 @@ Nlsr::setLsaInterestFilter()
}
void
Nlsr::registerPrefixes()
Nlsr::setStrategies()
{
std::string strategy("ndn:/localhost/nfd/strategy/broadcast");
ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX;
@ -84,14 +84,6 @@ Nlsr::registerPrefixes()
std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
for (std::list<Adjacent>::iterator it = adjacents.begin();
it != adjacents.end(); it++) {
m_fib.registerPrefix((*it).getName(), (*it).getConnectingFaceUri(),
(*it).getLinkCost(), 31536000); /* One Year in seconds */
m_fib.registerPrefix(m_confParam.getChronosyncPrefix(),
(*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
m_fib.registerPrefix(m_confParam.getLsaPrefix(),
(*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
m_fib.registerPrefix(broadcastKeyPrefix,
(*it).getConnectingFaceUri(), (*it).getLinkCost(), 31536000);
m_fib.setStrategy((*it).getName(), strategy);
}
@ -111,20 +103,13 @@ Nlsr::initialize()
m_sequencingManager.setSeqFileName(m_confParam.getSeqFileDir());
m_sequencingManager.initiateSeqNoFromFile();
m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncPrefix().toUri());
intializeKey();
/* Logging start */
m_confParam.writeLog();
m_adjacencyList.writeLog();
m_namePrefixList.writeLog();
/* Logging end */
createFaces();
}
void
Nlsr::start()
{
registerPrefixes();
intializeKey();
setStrategies();
setInfoInterestFilter();
setLsaInterestFilter();
m_nlsrLsdb.buildAndInstallOwnNameLsa();
@ -195,55 +180,9 @@ Nlsr::onKeyPrefixRegSuccess(const ndn::Name& name)
{
}
void
Nlsr::createFace(const std::string& faceUri,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setUri(faceUri);
m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
onSuccess,
onFailure);
}
void
Nlsr::onCreateFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult)
{
m_nFacesCreated++;
if (m_nFacesToCreate == m_nFacesCreated)
{
start();
}
}
void
Nlsr::onCreateFaceFailure(int32_t code, const std::string& error)
{
_LOG_DEBUG(error << " (code: " << code << ")");
destroyFaces();
throw Error("Error: Face creation failed");
}
void
Nlsr::createFaces()
{
std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
for (std::list<Adjacent>::iterator it = adjacents.begin();
it != adjacents.end(); it++) {
createFace((*it).getConnectingFaceUri(),
ndn::bind(&Nlsr::onCreateFaceSuccess, this, _1),
ndn::bind(&Nlsr::onCreateFaceFailure, this, _1, _2));
m_nFacesToCreate++;
}
}
void
Nlsr::onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult)
{
}
void
@ -259,34 +198,27 @@ Nlsr::destroyFaces()
std::list<Adjacent>& adjacents = m_adjacencyList.getAdjList();
for (std::list<Adjacent>::iterator it = adjacents.begin();
it != adjacents.end(); it++) {
destroyFace((*it).getConnectingFaceUri());
m_fib.destroyFace((*it).getConnectingFaceUri(),
ndn::bind(&Nlsr::onDestroyFaceSuccess, this, _1),
ndn::bind(&Nlsr::onDestroyFaceFailure, this, _1, _2));
}
}
void
Nlsr::destroyFace(const std::string& faceUri)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setUri(faceUri);
m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
ndn::bind(&Nlsr::destroyFaceInNfd,
this, _1),
ndn::bind(&Nlsr::onDestroyFaceFailure,
this, _1, _2));
}
void
Nlsr::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult)
Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setFaceId(faceDestroyResult.getFaceId());
m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
ndn::bind(&Nlsr::onDestroyFaceSuccess,
this, _1),
ndn::bind(&Nlsr::onDestroyFaceFailure,
this, _1, _2));
ndn::nfd::FaceEventKind kind = faceEventNotification.getKind();
if (kind == ndn::nfd::FACE_EVENT_DESTROYED) {
uint64_t faceId = faceEventNotification.getFaceId();
Adjacent *adjacent = m_adjacencyList.findAdjacent(faceId);
if (adjacent != 0) {
_LOG_DEBUG("Face to " << adjacent->getName() << "deleted");
adjacent->setFaceId(0);
}
}
}

34
src/nlsr.hpp

@ -30,6 +30,7 @@
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/certificate-cache-ttl.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/management/nfd-face-event-notification.hpp>
#include "conf-parameter.hpp"
#include "adjacency-list.hpp"
@ -41,6 +42,7 @@
#include "route/fib.hpp"
#include "communication/sync-logic-handler.hpp"
#include "hello-protocol.hpp"
#include "face-monitor.hpp"
#include "validator.hpp"
@ -62,10 +64,6 @@ class Nlsr
};
public:
typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
Nlsr()
: m_scheduler(m_nlsrFace.getIoService())
, m_confParam()
@ -88,9 +86,8 @@ public:
, m_certificateCache(new ndn::CertificateCacheTtl(m_nlsrFace.getIoService()))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
, m_controller(m_nlsrFace)
, m_nFacesToCreate(0)
, m_nFacesCreated(0)
, m_faceMonitor(m_nlsrFace.getIoService(),
ndn::bind(&Nlsr::onFaceEventNotification, this, _1))
{}
void
@ -271,9 +268,6 @@ public:
void
initialize();
void
start();
void
intializeKey();
@ -333,7 +327,7 @@ public:
private:
void
registerPrefixes();
setStrategies();
void
registerKeyPrefix();
@ -344,15 +338,6 @@ private:
void
onKeyPrefixRegSuccess(const ndn::Name& name);
void
onCreateFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
void
onCreateFaceFailure(int32_t code, const std::string& error);
void
createFaces();
void
onDestroyFaceSuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
@ -360,10 +345,7 @@ private:
onDestroyFaceFailure(int32_t code, const std::string& error);
void
destroyFace(const std::string& faceUri);
void
destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult);
onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification);
private:
typedef std::map<ndn::Name, ndn::shared_ptr<ndn::IdentityCertificate> > CertMap;
@ -395,9 +377,7 @@ private:
ndn::Name m_defaultIdentity;
ndn::Name m_defaultCertName;
ndn::nfd::Controller m_controller;
int32_t m_nFacesToCreate;
int32_t m_nFacesCreated;
FaceMonitor m_faceMonitor;
};
} //namespace nlsr

79
src/route/fib.cpp

@ -256,19 +256,62 @@ Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
}
void
Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
uint64_t faceCost, uint64_t timeout)
Fib::createFace(const std::string& faceUri,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setUri(faceUri);
.setUri(faceUri);
m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
ndn::bind(&Fib::registerPrefixInNfd, this,_1,
namePrefix, faceCost, timeout),
ndn::bind(&Fib::onFailure, this, _1, _2,
"Failed in name registration"));
onSuccess,
onFailure);
}
void
Fib::destroyFace(const std::string& faceUri,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
createFace(faceUri,
ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
onFailure);
}
void
Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters faceParameters;
faceParameters
.setFaceId(faceDestroyResult.getFaceId());
m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
onSuccess,
onFailure);
}
void
Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
uint64_t faceCost, uint64_t timeout)
{
createFace(faceUri,
ndn::bind(&Fib::registerPrefixInNfd, this,_1, namePrefix, faceCost, timeout),
ndn::bind(&Fib::onFailure, this, _1, _2,"Failed in name registration"));
}
void
Fib::registerPrefix(const ndn::Name& namePrefix,
const std::string& faceUri,
uint64_t faceCost, uint64_t timeout,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
createFace(faceUri,
ndn::bind(&Fib::registerPrefixInNfd, this,_1,
namePrefix, faceCost, timeout, onSuccess, onFailure),
onFailure);
}
void
@ -290,6 +333,24 @@ Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
"Failed in name registration"));
}
void
Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters controlParameters;
controlParameters
.setName(namePrefix)
.setFaceId(faceCreateResult.getFaceId())
.setCost(faceCost)
.setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
.setOrigin(128);
m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
onSuccess,
onFailure);
}
void
Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
{

35
src/route/fib.hpp

@ -33,6 +33,9 @@
namespace nlsr {
typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
class Nlsr;
@ -90,8 +93,11 @@ public:
uint64_t faceCost, uint64_t timeout);
void
registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
registerPrefix(const ndn::Name& namePrefix,
const std::string& faceUri,
uint64_t faceCost, uint64_t timeout,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
void
setStrategy(const ndn::Name& name, const std::string& strategy);
@ -99,7 +105,32 @@ public:
void
writeLog();
void
destroyFace(const std::string& faceUri,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
private:
void
createFace(const std::string& faceUri,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
void
registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
void
registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
void
destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
void
unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);

Loading…
Cancel
Save