src: Changing prefix registration's flag and FaceMonitor
Refs: #1841 #1843
Change-Id: I7ab74d529cf6f9f54ec1db1415f54f36f2229723
diff --git a/src/face-monitor.cpp b/src/face-monitor.cpp
deleted file mode 100644
index 7685471..0000000
--- a/src/face-monitor.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- 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
diff --git a/src/face-monitor.hpp b/src/face-monitor.hpp
deleted file mode 100644
index 1344f60..0000000
--- a/src/face-monitor.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- 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
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 7bcf3bb..98ab9cd 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -217,7 +217,8 @@
HelloProtocol::registerPrefixes(const ndn::Name& adjName, const std::string& faceUri,
double linkCost, const ndn::time::milliseconds& timeout)
{
- m_nlsr.getFib().registerPrefix(adjName, faceUri, linkCost, timeout, 0,
+ m_nlsr.getFib().registerPrefix(adjName, faceUri, linkCost, timeout,
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0,
ndn::bind(&HelloProtocol::onRegistrationSuccess,
this, _1, adjName,timeout),
ndn::bind(&HelloProtocol::onRegistrationFailure,
@@ -236,11 +237,14 @@
std::string faceUri = adjacent->getConnectingFaceUri();
double linkCost = adjacent->getLinkCost();
m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(),
- faceUri, linkCost, timeout, 0);
+ faceUri, linkCost, timeout,
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getLsaPrefix(),
- faceUri, linkCost, timeout, 0);
+ faceUri, linkCost, timeout,
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
m_nlsr.getFib().registerPrefix(broadcastKeyPrefix,
- faceUri, linkCost, timeout, 0);
+ faceUri, linkCost, timeout,
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
m_nlsr.setStrategies();
/* interest name: /<neighbor>/NLSR/INFO/<router> */
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index b9f9cb2..3ee4ccd 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -59,7 +59,9 @@
ndn::bind(&HelloProtocol::processInterest,
&m_helloProtocol, _1, _2),
ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
- ndn::bind(&Nlsr::registrationFailed, this, _1));
+ ndn::bind(&Nlsr::registrationFailed, this, _1),
+ m_defaultIdentity,
+ ndn::nfd::ROUTE_FLAG_CAPTURE);
}
void
@@ -73,7 +75,9 @@
ndn::bind(&Lsdb::processInterest,
&m_nlsrLsdb, _1, _2),
ndn::bind(&Nlsr::onRegistrationSuccess, this, _1),
- ndn::bind(&Nlsr::registrationFailed, this, _1));
+ ndn::bind(&Nlsr::registrationFailed, this, _1),
+ m_defaultIdentity,
+ ndn::nfd::ROUTE_FLAG_CAPTURE);
}
void
@@ -131,6 +135,7 @@
/* Logging end */
initializeKey();
setStrategies();
+ _LOG_DEBUG("Default NLSR identity: " << m_defaultIdentity);
setInfoInterestFilter();
setLsaInterestFilter();
m_nlsrLsdb.buildAndInstallOwnNameLsa();
@@ -138,8 +143,6 @@
m_syncLogicHandler.createSyncSocket(boost::ref(*this));
registerKeyPrefix();
m_helloProtocol.scheduleInterest(10);
-
- m_faceMonitor.startNotification();
}
void
@@ -187,7 +190,9 @@
ndn::bind(&Nlsr::onKeyInterest,
this, _1, _2),
ndn::bind(&Nlsr::onKeyPrefixRegSuccess, this, _1),
- ndn::bind(&Nlsr::registrationFailed, this, _1));
+ ndn::bind(&Nlsr::registrationFailed, this, _1),
+ m_defaultIdentity,
+ ndn::nfd::ROUTE_FLAG_CAPTURE);
}
@@ -254,11 +259,13 @@
Nlsr::onFaceEventNotification(const ndn::nfd::FaceEventNotification& faceEventNotification)
{
ndn::nfd::FaceEventKind kind = faceEventNotification.getKind();
+ _LOG_DEBUG("Nlsr::onFaceEventNotification called");
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");
+ _LOG_DEBUG("Face to " << adjacent->getName() << " with face id: "
+ << faceId << " deleted");
adjacent->setFaceId(0);
}
}
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index bcfe95b..dd3c99b 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -31,6 +31,7 @@
#include <ndn-cxx/security/certificate-cache-ttl.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/management/nfd-face-event-notification.hpp>
+#include <ndn-cxx/management/nfd-face-monitor.hpp>
#include "conf-parameter.hpp"
#include "adjacency-list.hpp"
@@ -42,7 +43,6 @@
#include "route/fib.hpp"
#include "communication/sync-logic-handler.hpp"
#include "hello-protocol.hpp"
-#include "face-monitor.hpp"
#include "validator.hpp"
@@ -86,9 +86,11 @@
, m_certificateCache(new ndn::CertificateCacheTtl(m_nlsrFace.getIoService()))
, m_validator(m_nlsrFace, DEFAULT_BROADCAST_PREFIX, m_certificateCache)
- , m_faceMonitor(m_nlsrFace.getIoService(),
- ndn::bind(&Nlsr::onFaceEventNotification, this, _1))
- {}
+ , m_faceMonitor(m_nlsrFace)
+ {
+ m_faceMonitor.onNotification += ndn::bind(&Nlsr::onFaceEventNotification, this, _1);
+ m_faceMonitor.start();
+ }
void
registrationFailed(const ndn::Name& name);
@@ -380,7 +382,7 @@
ndn::Name m_defaultIdentity;
ndn::Name m_defaultCertName;
- FaceMonitor m_faceMonitor;
+ ndn::nfd::FaceMonitor m_faceMonitor;
};
} //namespace nlsr
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index b99d7a2..7a8e98b 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -82,7 +82,8 @@
if (isPrefixUpdatable(it->getName())) {
registerPrefix(it->getName(), nhit->getConnectingFaceUri(),
std::ceil(nhit->getRouteCost()),
- ndn::time::seconds(m_refreshTime + GRACE_PERIOD), 0);
+ ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}
// increase sequence number and schedule refresh again
@@ -138,7 +139,8 @@
if (isPrefixUpdatable(name)) {
registerPrefix(name, nhit->getConnectingFaceUri(),
std::ceil(nhit->getRouteCost()),
- ndn::time::seconds(m_refreshTime + GRACE_PERIOD), 0);
+ ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}
newEntry.getNexthopList().sort();
@@ -162,7 +164,8 @@
if (isPrefixUpdatable(name)) {
registerPrefix(name, nhit->getConnectingFaceUri(),
std::ceil(nhit->getRouteCost()),
- ndn::time::seconds(m_refreshTime + GRACE_PERIOD), 0);
+ ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
removeHop(it->getNexthopList(), nhit->getConnectingFaceUri(), name);
it->getNexthopList().reset();
@@ -175,7 +178,8 @@
if (isPrefixUpdatable(name)) {
registerPrefix(name, nhit->getConnectingFaceUri(),
std::ceil(nhit->getRouteCost()),
- ndn::time::seconds(m_refreshTime + GRACE_PERIOD), 0);
+ ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
+ ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
}
}
}
@@ -292,14 +296,22 @@
void
Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
uint64_t faceCost, const ndn::time::milliseconds& timeout,
- uint8_t times)
+ uint64_t flags, uint8_t times)
{
uint64_t faceId = m_nlsr.getAdjacencyList().getFaceId(faceUri);
if (faceId != 0) {
+ ndn::nfd::ControlParameters faceParameters;
+ faceParameters
+ .setName(namePrefix)
+ .setFaceId(faceId)
+ .setFlags(flags)
+ .setCost(faceCost)
+ .setExpirationPeriod(timeout)
+ .setOrigin(128);
+
_LOG_DEBUG("Registering prefix: " << namePrefix << " Face Uri: " << faceUri
<< " Face Id: " << faceId);
- registerPrefixInNfd(namePrefix, faceId,
- faceCost, timeout, faceUri, times);
+ registerPrefixInNfd(faceParameters, faceUri, times);
}
else {
_LOG_DEBUG("Error: No Face Id for face uri: " << faceUri);
@@ -311,58 +323,56 @@
const std::string& faceUri,
uint64_t faceCost,
const ndn::time::milliseconds& timeout,
+ uint64_t flags,
uint8_t times,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
- createFace(faceUri,
- ndn::bind(&Fib::registerPrefixInNfd, this,_1,
- namePrefix, faceCost,
- timeout, times, onSuccess, onFailure),
- onFailure);
-}
-
-void
-Fib::registerPrefixInNfd(const ndn::Name& namePrefix,
- uint64_t faceId,
- uint64_t faceCost,
- const ndn::time::milliseconds& timeout,
- const std::string& faceUri,
- uint8_t times)
-{
- ndn::nfd::ControlParameters controlParameters;
- controlParameters
+ ndn::nfd::ControlParameters parameters;
+ parameters
.setName(namePrefix)
- .setFaceId(faceId)
+ .setFlags(flags)
.setCost(faceCost)
.setExpirationPeriod(timeout)
.setOrigin(128);
- m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
+ createFace(faceUri,
+ ndn::bind(&Fib::registerPrefixInNfd, this,_1,
+ parameters,
+ times, onSuccess, onFailure),
+ onFailure);
+}
+
+void
+Fib::registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
+ const std::string& faceUri,
+ uint8_t times)
+{
+ m_controller.start<ndn::nfd::RibRegisterCommand>(parameters,
ndn::bind(&Fib::onRegistration, this, _1,
"Successful in name registration",
faceUri),
ndn::bind(&Fib::onRegistrationFailure,
this, _1, _2,
"Failed in name registration",
- namePrefix, faceUri, faceCost,
- timeout, times));
+ parameters,
+ faceUri, times));
}
void
Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
- const ndn::Name& namePrefix, uint64_t faceCost,
- const ndn::time::milliseconds& timeout,
+ const ndn::nfd::ControlParameters& parameters,
uint8_t times,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
{
ndn::nfd::ControlParameters controlParameters;
controlParameters
- .setName(namePrefix)
+ .setName(parameters.getName())
.setFaceId(faceCreateResult.getFaceId())
- .setCost(faceCost)
- .setExpirationPeriod(timeout)
+ .setCost(parameters.getCost())
+ .setFlags(parameters.getFlags())
+ .setExpirationPeriod(parameters.getExpirationPeriod())
.setOrigin(128);
m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
onSuccess,
@@ -416,7 +426,6 @@
m_faceMap.writeLog();
}
-
void
Fib::onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
const std::string& message)
@@ -428,15 +437,18 @@
void
Fib::onRegistrationFailure(uint32_t code, const std::string& error,
const std::string& message,
- const ndn::Name& namePrefix, const std::string& faceUri,
- uint64_t faceCost, const ndn::time::milliseconds& timeout,
+ const ndn::nfd::ControlParameters& parameters,
+ const std::string& faceUri,
uint8_t times)
{
_LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
- _LOG_DEBUG("Prefix: " << namePrefix << " failed for: " << times);
+ _LOG_DEBUG("Prefix: " << parameters.getName() << " failed for: " << times);
if (times < 3) {
_LOG_DEBUG("Trying to register again...");
- registerPrefix(namePrefix, faceUri, faceCost, timeout, times+1);
+ registerPrefix(parameters.getName(), faceUri,
+ parameters.getCost(),
+ parameters.getExpirationPeriod(),
+ parameters.getFlags(), times+1);
}
else {
_LOG_DEBUG("Registration trial given up");
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 4c54a79..2522928 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -94,17 +94,19 @@
void
registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
uint64_t faceCost,
- const ndn::time::milliseconds& timeout, uint8_t times);
+ const ndn::time::milliseconds& timeout,
+ uint64_t flags, uint8_t times);
void
registerPrefix(const ndn::Name& namePrefix,
const std::string& faceUri,
uint64_t faceCost,
const ndn::time::milliseconds& timeout,
+ uint64_t flags,
uint8_t times,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
-
+
void
setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
@@ -123,17 +125,13 @@
const CommandFailCallback& onFailure);
void
- registerPrefixInNfd(const ndn::Name& namePrefix,
- uint64_t faceId,
- uint64_t faceCost,
- const ndn::time::milliseconds& timeout,
+ registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
const std::string& faceUri,
uint8_t times);
void
registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
- const ndn::Name& namePrefix, uint64_t faceCost,
- const ndn::time::milliseconds& timeout,
+ const ndn::nfd::ControlParameters& parameters,
uint8_t times,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
@@ -157,8 +155,8 @@
void
onRegistrationFailure(uint32_t code, const std::string& error,
const std::string& message,
- const ndn::Name& namePrefix, const std::string& faceUri,
- uint64_t faceCost, const ndn::time::milliseconds& timeout,
+ const ndn::nfd::ControlParameters& parameters,
+ const std::string& faceUri,
uint8_t times);
void