rib: a few cleanups and simplifications in RibManager
Change-Id: I77699525ab372c4f4f3bbcae74e65bec24a86b4c Refs: #3903
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -30,13 +30,14 @@ namespace nfd {
|
||||
using ndn::mgmt::ValidateParameters;
|
||||
using ndn::mgmt::Authorization;
|
||||
|
||||
ManagerBase::ManagerBase(Dispatcher& dispatcher,
|
||||
const std::string& module)
|
||||
ManagerBase::ManagerBase(Dispatcher& dispatcher, const std::string& module)
|
||||
: m_dispatcher(dispatcher)
|
||||
, m_module(module)
|
||||
{
|
||||
}
|
||||
|
||||
ManagerBase::~ManagerBase() = default;
|
||||
|
||||
void
|
||||
ManagerBase::registerStatusDatasetHandler(const std::string& verb,
|
||||
const ndn::mgmt::StatusDatasetHandler& handler)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -59,8 +59,10 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
ManagerBase(Dispatcher& dispatcher,
|
||||
const std::string& module);
|
||||
ManagerBase(Dispatcher& dispatcher, const std::string& module);
|
||||
|
||||
virtual
|
||||
~ManagerBase();
|
||||
|
||||
const std::string&
|
||||
getModule() const
|
||||
@@ -69,7 +71,6 @@ public:
|
||||
}
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
|
||||
|
||||
// difference from mgmt::ControlCommand: accepts nfd::ControlParameters
|
||||
typedef function<void(const ControlCommand& command,
|
||||
const Name& prefix, const Interest& interest,
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014-2016, Regents of the University of California,
|
||||
* Copyright (c) 2014-2017, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
bool
|
||||
hasFaceId(const uint64_t faceId) const;
|
||||
|
||||
RouteList&
|
||||
getRoutes();
|
||||
const RouteList&
|
||||
getRoutes() const;
|
||||
|
||||
size_t
|
||||
getNRoutes() const;
|
||||
@@ -219,14 +219,14 @@ RibEntry::getParent() const
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
inline const std::list<shared_ptr<RibEntry> >&
|
||||
inline const std::list<shared_ptr<RibEntry>>&
|
||||
RibEntry::getChildren() const
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
inline RibEntry::RouteList&
|
||||
RibEntry::getRoutes()
|
||||
inline const RibEntry::RouteList&
|
||||
RibEntry::getRoutes() const
|
||||
{
|
||||
return m_routes;
|
||||
}
|
||||
|
||||
+27
-42
@@ -28,7 +28,6 @@
|
||||
#include "readvertise/client-to-nlsr-readvertise-policy.hpp"
|
||||
#include "readvertise/nfd-rib-readvertise-destination.hpp"
|
||||
|
||||
#include "core/global-io.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include "core/scheduler.hpp"
|
||||
|
||||
@@ -39,14 +38,11 @@
|
||||
#include <ndn-cxx/mgmt/nfd/face-status.hpp>
|
||||
#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace rib {
|
||||
|
||||
using ndn::nfd::ControlCommand;
|
||||
using ndn::nfd::ControlResponse;
|
||||
using ndn::nfd::ControlParameters;
|
||||
using ndn::nfd::FaceEventNotification;
|
||||
|
||||
NFD_LOG_INIT("RibManager");
|
||||
|
||||
const Name RibManager::LOCAL_HOST_TOP_PREFIX = "/localhost/nfd";
|
||||
@@ -81,10 +77,7 @@ RibManager::RibManager(Dispatcher& dispatcher,
|
||||
registerStatusDatasetHandler("list", bind(&RibManager::listEntries, this, _1, _2, _3));
|
||||
}
|
||||
|
||||
RibManager::~RibManager()
|
||||
{
|
||||
scheduler::cancel(m_activeFaceFetchEvent);
|
||||
}
|
||||
RibManager::~RibManager() = default;
|
||||
|
||||
void
|
||||
RibManager::registerWithNfd()
|
||||
@@ -283,29 +276,26 @@ void
|
||||
RibManager::listEntries(const Name& topPrefix, const Interest& interest,
|
||||
ndn::mgmt::StatusDatasetContext& context)
|
||||
{
|
||||
for (auto&& ribTableEntry : m_rib) {
|
||||
for (const auto& ribTableEntry : m_rib) {
|
||||
const auto& ribEntry = *ribTableEntry.second;
|
||||
ndn::nfd::RibEntry record;
|
||||
|
||||
for (auto&& route : ribEntry) {
|
||||
ndn::nfd::Route routeElement;
|
||||
routeElement.setFaceId(route.faceId)
|
||||
.setOrigin(route.origin)
|
||||
.setCost(route.cost)
|
||||
.setFlags(route.flags);
|
||||
|
||||
if (route.expires < time::steady_clock::TimePoint::max()) {
|
||||
routeElement.setExpirationPeriod(time::duration_cast<time::milliseconds>(
|
||||
route.expires - time::steady_clock::now()));
|
||||
}
|
||||
|
||||
record.addRoute(routeElement);
|
||||
}
|
||||
|
||||
record.setName(ribEntry.getName());
|
||||
context.append(record.wireEncode());
|
||||
const auto& routes = ribEntry.getRoutes() |
|
||||
boost::adaptors::transformed([] (const Route& route) {
|
||||
auto r = ndn::nfd::Route()
|
||||
.setFaceId(route.faceId)
|
||||
.setOrigin(route.origin)
|
||||
.setCost(route.cost)
|
||||
.setFlags(route.flags);
|
||||
if (route.expires < time::steady_clock::TimePoint::max()) {
|
||||
r.setExpirationPeriod(time::duration_cast<time::milliseconds>(
|
||||
route.expires - time::steady_clock::now()));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
context.append(ndn::nfd::RibEntry()
|
||||
.setName(ribEntry.getName())
|
||||
.setRoutes(std::begin(routes), std::end(routes))
|
||||
.wireEncode());
|
||||
}
|
||||
|
||||
context.end();
|
||||
}
|
||||
|
||||
@@ -370,10 +360,7 @@ RibManager::onFaceDestroyedEvent(uint64_t faceId)
|
||||
void
|
||||
RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
|
||||
{
|
||||
scheduler::cancel(m_activeFaceFetchEvent);
|
||||
|
||||
m_activeFaceFetchEvent = scheduler::schedule(timeToWait,
|
||||
bind(&RibManager::fetchActiveFaces, this));
|
||||
m_activeFaceFetchEvent = scheduler::schedule(timeToWait, [this] { this->fetchActiveFaces(); });
|
||||
}
|
||||
|
||||
void
|
||||
@@ -382,18 +369,16 @@ RibManager::removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFa
|
||||
NFD_LOG_DEBUG("Checking for invalid face registrations");
|
||||
|
||||
FaceIdSet activeFaceIds;
|
||||
for (const ndn::nfd::FaceStatus& item : activeFaces) {
|
||||
activeFaceIds.insert(item.getFaceId());
|
||||
for (const auto& faceStatus : activeFaces) {
|
||||
activeFaceIds.insert(faceStatus.getFaceId());
|
||||
}
|
||||
|
||||
// Look for face IDs that were registered but not active to find missed
|
||||
// face destroyed events
|
||||
for (auto&& faceId : m_registeredFaces) {
|
||||
for (auto faceId : m_registeredFaces) {
|
||||
if (activeFaceIds.count(faceId) == 0) {
|
||||
NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
|
||||
|
||||
scheduler::schedule(time::seconds(0),
|
||||
bind(&RibManager::onFaceDestroyedEvent, this, faceId));
|
||||
scheduler::schedule(time::seconds(0), [this, faceId] { this->onFaceDestroyedEvent(faceId); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +387,7 @@ RibManager::removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFa
|
||||
}
|
||||
|
||||
void
|
||||
RibManager::onNotification(const FaceEventNotification& notification)
|
||||
RibManager::onNotification(const ndn::nfd::FaceEventNotification& notification)
|
||||
{
|
||||
NFD_LOG_TRACE("onNotification: " << notification);
|
||||
|
||||
|
||||
+6
-7
@@ -33,11 +33,11 @@
|
||||
#include "core/config-file.hpp"
|
||||
#include "core/manager-base.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/buffer-stream.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/util/scheduler-scoped-event-id.hpp>
|
||||
|
||||
namespace nfd {
|
||||
namespace rib {
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
public:
|
||||
RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
|
||||
|
||||
~RibManager();
|
||||
~RibManager() override;
|
||||
|
||||
void
|
||||
registerWithNfd();
|
||||
@@ -138,17 +138,16 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
|
||||
private:
|
||||
void
|
||||
onCommandPrefixAddNextHopSuccess(const Name& prefix,
|
||||
const ndn::nfd::ControlParameters& result);
|
||||
onCommandPrefixAddNextHopSuccess(const Name& prefix, const ControlParameters& result);
|
||||
|
||||
void
|
||||
onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
|
||||
onCommandPrefixAddNextHopError(const Name& name, const ControlResponse& response);
|
||||
|
||||
void
|
||||
onEnableLocalFieldsSuccess();
|
||||
|
||||
void
|
||||
onEnableLocalFieldsError(const ndn::nfd::ControlResponse& response);
|
||||
onEnableLocalFieldsError(const ControlResponse& response);
|
||||
|
||||
private:
|
||||
ndn::Face& m_face;
|
||||
@@ -171,7 +170,7 @@ private:
|
||||
static const std::string MGMT_MODULE_NAME;
|
||||
static const Name FACES_LIST_DATASET_PREFIX;
|
||||
static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
|
||||
scheduler::EventId m_activeFaceFetchEvent;
|
||||
scheduler::ScopedEventId m_activeFaceFetchEvent;
|
||||
static const Name READVERTISE_NLSR_PREFIX;
|
||||
|
||||
typedef std::set<uint64_t> FaceIdSet;
|
||||
|
||||
Reference in New Issue
Block a user