rib: move RibManager to mgmt

Refs: #4528
Change-Id: Idff4ce8fe28b48163794cd12f0d185f8ca4233e3
This commit is contained in:
Davide Pesavento
2019-02-28 02:26:19 -05:00
parent 1b077f6028
commit 8a05c7fd2a
7 changed files with 69 additions and 68 deletions
+2 -2
View File
@@ -227,7 +227,7 @@ SelfLearningStrategy::addRoute(const shared_ptr<pit::Entry>& pitEntry, const Fac
{
runOnRibIoService([pitEntryWeak = weak_ptr<pit::Entry>{pitEntry}, inFaceId = inFace.getId(), data, pa] {
rib::Service::get().getRibManager().slAnnounce(pa, inFaceId, ROUTE_RENEW_LIFETIME,
[] (rib::RibManager::SlAnnounceResult res) {
[] (RibManager::SlAnnounceResult res) {
NFD_LOG_DEBUG("Add route via PrefixAnnouncement with result=" << res);
});
});
@@ -239,7 +239,7 @@ SelfLearningStrategy::renewRoute(const Name& name, FaceId inFaceId, time::millis
// renew route with PA or ignore PA (if route has no PA)
runOnRibIoService([name, inFaceId, maxLifetime] {
rib::Service::get().getRibManager().slRenew(name, inFaceId, maxLifetime,
[] (rib::RibManager::SlAnnounceResult res) {
[] (RibManager::SlAnnounceResult res) {
NFD_LOG_DEBUG("Renew route with result=" << res);
});
});
@@ -36,7 +36,9 @@
#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
namespace nfd {
namespace rib {
using rib::RibUpdate;
using rib::Route;
NFD_LOG_INIT(RibManager);
@@ -46,7 +48,7 @@ static const time::seconds ACTIVE_FACE_FETCH_INTERVAL = 5_min;
const Name RibManager::LOCALHOP_TOP_PREFIX = "/localhop/nfd";
RibManager::RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
RibManager::RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
ndn::util::Scheduler& scheduler)
: ManagerBase(dispatcher, MGMT_MODULE_NAME)
@@ -267,7 +269,7 @@ RibManager::listEntries(const Name& topPrefix, const Interest& interest,
{
auto now = time::steady_clock::now();
for (const auto& kv : m_rib) {
const RibEntry& entry = *kv.second;
const rib::RibEntry& entry = *kv.second;
ndn::nfd::RibEntry item;
item.setName(entry.getName());
for (const Route& route : entry.getRoutes()) {
@@ -414,7 +416,7 @@ RibManager::slRenew(const Name& name, uint64_t faceId, time::milliseconds maxLif
void
RibManager::slFindAnn(const Name& name, const SlFindAnnCallback& cb) const
{
shared_ptr<RibEntry> entry;
shared_ptr<rib::RibEntry> entry;
auto exactMatch = m_rib.find(name);
if (exactMatch != m_rib.end()) {
entry = exactMatch->second;
@@ -496,5 +498,4 @@ RibManager::onNotification(const ndn::nfd::FaceEventNotification& notification)
}
}
} // namespace rib
} // namespace nfd
@@ -23,28 +23,26 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_DAEMON_RIB_RIB_MANAGER_HPP
#define NFD_DAEMON_RIB_RIB_MANAGER_HPP
#include "fib-updater.hpp"
#include "rib.hpp"
#ifndef NFD_DAEMON_MGMT_RIB_MANAGER_HPP
#define NFD_DAEMON_MGMT_RIB_MANAGER_HPP
#include "core/config-file.hpp"
#include "core/manager-base.hpp"
#include "rib/rib.hpp"
#include <ndn-cxx/security/validator-config.hpp>
#include <ndn-cxx/mgmt/nfd/controller.hpp>
#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
#include <ndn-cxx/security/validator-config.hpp>
#include <ndn-cxx/util/scheduler.hpp>
namespace nfd {
namespace rib {
/**
* @brief Serve commands and datasets in NFD RIB management protocol.
* @brief Serve commands and datasets of NFD RIB management protocol.
* @sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt
*/
class RibManager : public nfd::ManagerBase
class RibManager : public ManagerBase
{
public:
class Error : public std::runtime_error
@@ -53,8 +51,9 @@ public:
using std::runtime_error::runtime_error;
};
RibManager(Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain, ndn::nfd::Controller& nfdController,
Dispatcher& dispatcher, ndn::util::Scheduler& scheduler);
RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher,
ndn::util::Scheduler& scheduler);
/**
* @brief Apply localhost_security configuration.
@@ -174,7 +173,7 @@ private: // RIB and FibUpdater actions
* \param done completion callback
*/
void
beginAddRoute(const Name& name, Route route, optional<time::nanoseconds> expires,
beginAddRoute(const Name& name, rib::Route route, optional<time::nanoseconds> expires,
const std::function<void(RibUpdateResult)>& done);
/** \brief Start removing a route from RIB and FIB.
@@ -183,11 +182,12 @@ private: // RIB and FibUpdater actions
* \param done completion callback
*/
void
beginRemoveRoute(const Name& name, const Route& route,
beginRemoveRoute(const Name& name, const rib::Route& route,
const std::function<void(RibUpdateResult)>& done);
void
beginRibUpdate(const RibUpdate& update, const std::function<void(RibUpdateResult)>& done);
beginRibUpdate(const rib::RibUpdate& update,
const std::function<void(RibUpdateResult)>& done);
private: // management Dispatcher related
void
@@ -243,7 +243,7 @@ public:
static const Name LOCALHOP_TOP_PREFIX;
private:
Rib& m_rib;
rib::Rib& m_rib;
ndn::KeyChain& m_keyChain;
ndn::nfd::Controller& m_nfdController;
Dispatcher& m_dispatcher;
@@ -262,7 +262,6 @@ private:
std::ostream&
operator<<(std::ostream& os, RibManager::SlAnnounceResult res);
} // namespace rib
} // namespace nfd
#endif // NFD_DAEMON_RIB_RIB_MANAGER_HPP
#endif // NFD_DAEMON_MGMT_RIB_MANAGER_HPP
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -25,7 +25,7 @@
#include "host-to-gateway-readvertise-policy.hpp"
#include "core/scope-prefix.hpp"
#include "rib/rib-manager.hpp"
#include "mgmt/rib-manager.hpp"
#include <ndn-cxx/security/pib/identity.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
+3 -2
View File
@@ -26,9 +26,10 @@
#ifndef NFD_DAEMON_RIB_SERVICE_HPP
#define NFD_DAEMON_RIB_SERVICE_HPP
#include "rib-manager.hpp"
#include "core/config-file.hpp"
#include "mgmt/rib-manager.hpp"
#include "rib/fib-updater.hpp"
#include "rib/rib.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/mgmt/dispatcher.hpp>
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,17 +23,17 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rib/rib-manager.hpp"
#include "mgmt/rib-manager.hpp"
#include "rib/fib-updater.hpp"
#include "tests/identity-management-fixture.hpp"
#include <ndn-cxx/util/dummy-client-face.hpp>
namespace nfd {
namespace rib {
namespace tests {
using namespace nfd::tests;
using rib::Route;
class RibManagerSlAnnounceFixture : public IdentityManagementTimeFixture
{
@@ -49,7 +49,7 @@ public:
, m_trustedSigner(m_keyChain.createIdentity("/trusted", ndn::RsaKeyParams()))
, m_untrustedSigner(m_keyChain.createIdentity("/untrusted", ndn::RsaKeyParams()))
{
rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
rib.mockFibResponse = [] (const auto&) { return true; };
rib.wantMockFibResponseOnce = false;
// Face, Controller, Dispatcher are irrelevant to SlAnnounce functions but required by
@@ -62,16 +62,16 @@ public:
template<typename ...T>
ndn::PrefixAnnouncement
makeTrustedAnn(const T&... args)
makeTrustedAnn(T&&... args)
{
return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_trustedSigner);
return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_trustedSigner);
}
template<typename ...T>
ndn::PrefixAnnouncement
makeUntrustedAnn(const T&... args)
makeUntrustedAnn(T&&... args)
{
return signPrefixAnn(makePrefixAnn(args...), m_keyChain, m_untrustedSigner);
return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_untrustedSigner);
}
/** \brief Invoke manager->slAnnounce and wait for result.
@@ -158,7 +158,7 @@ private:
}
public:
Rib rib;
rib::Rib rib;
unique_ptr<RibManager> manager;
private:
@@ -166,13 +166,15 @@ private:
ndn::util::Scheduler m_scheduler;
ndn::nfd::Controller m_nfdController;
ndn::mgmt::Dispatcher m_dispatcher;
FibUpdater m_fibUpdater;
rib::FibUpdater m_fibUpdater;
ndn::security::SigningInfo m_trustedSigner;
ndn::security::SigningInfo m_untrustedSigner;
};
BOOST_FIXTURE_TEST_SUITE(TestSlAnnounce, RibManagerSlAnnounceFixture)
BOOST_AUTO_TEST_SUITE(Mgmt)
BOOST_AUTO_TEST_SUITE(TestRibManager)
BOOST_FIXTURE_TEST_SUITE(SlAnnounce, RibManagerSlAnnounceFixture)
BOOST_AUTO_TEST_CASE(AnnounceUnconfigured)
{
@@ -327,8 +329,9 @@ BOOST_AUTO_TEST_CASE(FindNone)
BOOST_CHECK(!pa);
}
BOOST_AUTO_TEST_SUITE_END() // TestSlAnnounce
BOOST_AUTO_TEST_SUITE_END() // SlAnnounce
BOOST_AUTO_TEST_SUITE_END() // TestRibManager
BOOST_AUTO_TEST_SUITE_END() // Mgmt
} // namespace tests
} // namespace rib
} // namespace nfd
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2018, Regents of the University of California,
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,22 +23,19 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#include "rib/rib-manager.hpp"
#include "mgmt/rib-manager.hpp"
#include "core/fib-max-depth.hpp"
#include "rib/fib-updater.hpp"
#include "tests/manager-common-fixture.hpp"
#include <ndn-cxx/lp/tags.hpp>
#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
#include <ndn-cxx/mgmt/nfd/face-status.hpp>
#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
namespace nfd {
namespace rib {
namespace tests {
using namespace nfd::tests;
struct ConfigurationStatus
{
bool isLocalhostConfigured;
@@ -65,7 +62,7 @@ public:
, m_fibUpdater(m_rib, m_nfdController)
, m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler)
{
m_rib.mockFibResponse = [] (const RibUpdateBatch& batch) {
m_rib.mockFibResponse = [] (const rib::RibUpdateBatch& batch) {
BOOST_CHECK(batch.begin() != batch.end());
return true;
};
@@ -93,7 +90,7 @@ private:
registerWithNfd()
{
m_manager.registerWithNfd();
advanceClocks(time::milliseconds(1));
advanceClocks(1_ms);
auto replyFibAddCommand = [this] (const Interest& interest) {
nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
@@ -114,7 +111,7 @@ private:
for (const auto& command : m_commands) {
if (commandPrefix.isPrefixOf(command.getName())) {
replyFibAddCommand(command);
advanceClocks(time::milliseconds(1));
advanceClocks(1_ms);
}
}
@@ -210,8 +207,8 @@ protected:
ndn::util::Scheduler m_scheduler;
ndn::nfd::Controller m_nfdController;
Rib m_rib;
FibUpdater m_fibUpdater;
rib::Rib m_rib;
rib::FibUpdater m_fibUpdater;
RibManager m_manager;
};
@@ -240,6 +237,7 @@ operator<<(std::ostream& os, RibManagerFixture::CheckCommandResult result)
return os << static_cast<int>(result);
}
BOOST_AUTO_TEST_SUITE(Mgmt)
BOOST_AUTO_TEST_SUITE(TestRibManager)
class AddTopPrefixFixture : public RibManagerFixture
@@ -389,20 +387,20 @@ BOOST_AUTO_TEST_CASE(SelfOperation)
BOOST_AUTO_TEST_CASE(Expiration)
{
auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, time::milliseconds(50));
auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms);
auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527);
receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
advanceClocks(time::milliseconds(55));
advanceClocks(55_ms);
BOOST_REQUIRE_EQUAL(m_commands.size(), 2); // the registered route has expired
BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
BOOST_CHECK_EQUAL(checkCommand(1, "remove-nexthop", paramsUnregister), CheckCommandResult::OK);
m_commands.clear();
paramsRegister.setExpirationPeriod(time::milliseconds(100));
paramsRegister.setExpirationPeriod(100_ms);
receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister));
advanceClocks(time::milliseconds(55));
advanceClocks(55_ms);
BOOST_REQUIRE_EQUAL(m_commands.size(), 1); // the registered route is still active
BOOST_CHECK_EQUAL(checkCommand(0, "add-nexthop", paramsRegister), CheckCommandResult::OK);
}
@@ -431,8 +429,8 @@ BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister
BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture)
{
uint64_t faceId = 0;
auto generateRoute = [&faceId] () -> Route {
Route route;
auto generateRoute = [&faceId] () -> rib::Route {
rib::Route route;
route.faceId = ++faceId;
route.cost = route.faceId * 10;
route.expires = nullopt;
@@ -491,7 +489,7 @@ BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent)
{
BOOST_CHECK_EQUAL(m_commands.size(), 0);
advanceClocks(time::seconds(301)); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s
advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s
BOOST_REQUIRE_EQUAL(m_commands.size(), 2);
BOOST_CHECK_EQUAL(m_commands[0].getName(), "/localhost/nfd/faces/events");
BOOST_CHECK_EQUAL(m_commands[1].getName(), "/localhost/nfd/faces/list");
@@ -512,7 +510,7 @@ BOOST_AUTO_TEST_CASE(RemoveInvalidFaces)
activeFaces.push_back(status);
m_manager.removeInvalidFaces(activeFaces);
advanceClocks(time::milliseconds(100));
advanceClocks(100_ms);
BOOST_REQUIRE_EQUAL(m_rib.size(), 1);
auto it1 = m_rib.find("/test-remove-invalid-faces-1");
@@ -531,24 +529,23 @@ BOOST_AUTO_TEST_CASE(OnNotification)
receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2));
BOOST_REQUIRE_EQUAL(m_rib.size(), 2);
auto makeNotification = [] (ndn::nfd::FaceEventKind eventKind, uint64_t faceId) -> ndn::nfd::FaceEventNotification {
ndn::nfd::FaceEventNotification notification;
notification.setKind(eventKind).setFaceId(faceId);
return notification;
auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) {
return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId);
};
m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1));
advanceClocks(time::milliseconds(100));
advanceClocks(100_ms);
BOOST_CHECK_EQUAL(m_rib.size(), 0);
m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2));
advanceClocks(time::milliseconds(100));
advanceClocks(100_ms);
BOOST_CHECK_EQUAL(m_rib.size(), 0);
}
BOOST_AUTO_TEST_SUITE_END() // FaceMonitor
BOOST_AUTO_TEST_SUITE_END() // TestRibManager
BOOST_AUTO_TEST_SUITE_END() // Mgmt
} // namespace tests
} // namespace rib
} // namespace nfd