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 . - * - * \author A K M Mahmudul Hoque - * - **/ -#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 . - * - * \author A K M Mahmudul Hoque - * - **/ -#ifndef FACE_MONITOR_HPP -#define FACE_MONITOR_HPP - -#include -#include - -namespace nlsr { - -class FaceMonitor -{ -public: - typedef ndn::function NotificationCallback; - typedef ndn::function 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 @@ void 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 @@ HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandS 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: //NLSR/INFO/ */ 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 @@ Nlsr::setInfoInterestFilter() 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 @@ Nlsr::setLsaInterestFilter() 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 @@ Nlsr::initialize() /* Logging end */ initializeKey(); setStrategies(); + _LOG_DEBUG("Default NLSR identity: " << m_defaultIdentity); setInfoInterestFilter(); setLsaInterestFilter(); m_nlsrLsdb.buildAndInstallOwnNameLsa(); @@ -138,8 +143,6 @@ Nlsr::initialize() m_syncLogicHandler.createSyncSocket(boost::ref(*this)); registerKeyPrefix(); m_helloProtocol.scheduleInterest(10); - - m_faceMonitor.startNotification(); } void @@ -187,7 +190,9 @@ Nlsr::registerKeyPrefix() 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 @@ void 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 #include #include +#include #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 @@ public: , 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 @@ private: 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 @@ Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum) 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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList) 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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList) 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 @@ Fib::update(const ndn::Name& name, NexthopList& nextHopList) 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 @@ Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult, 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 @@ Fib::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) { - 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(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(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(controlParameters, onSuccess, @@ -416,7 +426,6 @@ Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult, m_faceMap.writeLog(); } - void Fib::onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult, const std::string& message) @@ -428,15 +437,18 @@ Fib::onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult, 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 @@ public: 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 @@ private: 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 @@ private: 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