76c751ce80
refs: #1941 Change-Id: I1457f71ddd1c120daae48308d5cc02a7c0ecf93d
271 lines
7.5 KiB
C++
271 lines
7.5 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (c) 2014-2015, Regents of the University of California,
|
|
* Arizona Board of Regents,
|
|
* Colorado State University,
|
|
* University Pierre & Marie Curie, Sorbonne University,
|
|
* Washington University in St. Louis,
|
|
* Beijing Institute of Technology,
|
|
* The University of Memphis.
|
|
*
|
|
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
|
* See AUTHORS.md for complete list of NFD authors and contributors.
|
|
*
|
|
* NFD 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.
|
|
*
|
|
* NFD 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
|
|
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef NFD_RIB_RIB_MANAGER_HPP
|
|
#define NFD_RIB_RIB_MANAGER_HPP
|
|
|
|
#include "rib.hpp"
|
|
#include "core/config-file.hpp"
|
|
#include "rib-status-publisher.hpp"
|
|
#include "remote-registrator.hpp"
|
|
#include "fib-updater.hpp"
|
|
|
|
#include <ndn-cxx/security/validator-config.hpp>
|
|
#include <ndn-cxx/management/nfd-face-monitor.hpp>
|
|
#include <ndn-cxx/management/nfd-controller.hpp>
|
|
#include <ndn-cxx/management/nfd-control-command.hpp>
|
|
#include <ndn-cxx/management/nfd-control-response.hpp>
|
|
#include <ndn-cxx/management/nfd-control-parameters.hpp>
|
|
|
|
namespace nfd {
|
|
namespace rib {
|
|
|
|
using ndn::nfd::ControlCommand;
|
|
using ndn::nfd::ControlResponse;
|
|
using ndn::nfd::ControlParameters;
|
|
|
|
using ndn::nfd::FaceEventNotification;
|
|
|
|
class RibManager : noncopyable
|
|
{
|
|
public:
|
|
class Error : public std::runtime_error
|
|
{
|
|
public:
|
|
explicit
|
|
Error(const std::string& what)
|
|
: std::runtime_error(what)
|
|
{
|
|
}
|
|
};
|
|
|
|
explicit
|
|
RibManager(ndn::Face& face);
|
|
|
|
~RibManager();
|
|
|
|
void
|
|
registerWithNfd();
|
|
|
|
void
|
|
enableLocalControlHeader();
|
|
|
|
void
|
|
setConfigFile(ConfigFile& configFile);
|
|
|
|
void
|
|
onRibUpdateSuccess(const RibUpdate& update);
|
|
|
|
void
|
|
onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
|
|
|
|
private:
|
|
void
|
|
onConfig(const ConfigSection& configSection,
|
|
bool isDryRun,
|
|
const std::string& filename);
|
|
|
|
void
|
|
startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest);
|
|
|
|
void
|
|
onLocalhopRequest(const Interest& request);
|
|
|
|
void
|
|
onLocalhostRequest(const Interest& request);
|
|
|
|
void
|
|
sendResponse(const Name& name,
|
|
const ControlResponse& response);
|
|
|
|
void
|
|
sendResponse(const Name& name,
|
|
uint32_t code,
|
|
const std::string& text);
|
|
|
|
void
|
|
sendSuccessResponse(const shared_ptr<const Interest>& request,
|
|
const ControlParameters& parameters);
|
|
|
|
void
|
|
sendErrorResponse(uint32_t code, const std::string& error,
|
|
const shared_ptr<const Interest>& request);
|
|
|
|
void
|
|
registerEntry(const shared_ptr<const Interest>& request,
|
|
ControlParameters& parameters);
|
|
|
|
void
|
|
unregisterEntry(const shared_ptr<const Interest>& request,
|
|
ControlParameters& parameters);
|
|
|
|
private:
|
|
void
|
|
onCommandValidated(const shared_ptr<const Interest>& request);
|
|
|
|
void
|
|
onCommandValidationFailed(const shared_ptr<const Interest>& request,
|
|
const std::string& failureInfo);
|
|
|
|
|
|
void
|
|
onCommandError(uint32_t code, const std::string& error,
|
|
const shared_ptr<const Interest>& request,
|
|
const Route& route);
|
|
|
|
void
|
|
onRegSuccess(const shared_ptr<const Interest>& request,
|
|
const ControlParameters& parameters,
|
|
const Route& route);
|
|
|
|
void
|
|
onUnRegSuccess(const shared_ptr<const Interest>& request,
|
|
const ControlParameters& parameters,
|
|
const Route& route);
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
void
|
|
onNrdCommandPrefixAddNextHopSuccess(const Name& prefix,
|
|
const ndn::nfd::ControlParameters& result);
|
|
|
|
private:
|
|
void
|
|
onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
|
|
|
|
void
|
|
onControlHeaderSuccess();
|
|
|
|
void
|
|
onControlHeaderError(uint32_t code, const std::string& reason);
|
|
|
|
static bool
|
|
extractParameters(const Name::Component& parameterComponent,
|
|
ControlParameters& extractedParameters);
|
|
|
|
bool
|
|
validateParameters(const ControlCommand& command,
|
|
ControlParameters& parameters);
|
|
|
|
void
|
|
onNotification(const FaceEventNotification& notification);
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
void
|
|
onFaceDestroyedEvent(uint64_t faceId);
|
|
|
|
private:
|
|
void
|
|
listEntries(const Interest& request);
|
|
|
|
void
|
|
scheduleActiveFaceFetch(const time::seconds& timeToWait);
|
|
|
|
void
|
|
fetchActiveFaces();
|
|
|
|
void
|
|
fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer);
|
|
|
|
void
|
|
onFetchFaceStatusTimeout();
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
/** \param buffer Face dataset contents
|
|
*/
|
|
void
|
|
removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer);
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
Rib m_managedRib;
|
|
|
|
private:
|
|
ndn::Face& m_face;
|
|
ndn::nfd::Controller m_nfdController;
|
|
ndn::KeyChain m_keyChain;
|
|
ndn::ValidatorConfig m_localhostValidator;
|
|
ndn::ValidatorConfig m_localhopValidator;
|
|
ndn::nfd::FaceMonitor m_faceMonitor;
|
|
bool m_isLocalhopEnabled;
|
|
RemoteRegistrator m_remoteRegistrator;
|
|
|
|
RibStatusPublisher m_ribStatusPublisher;
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
FibUpdater m_fibUpdater;
|
|
|
|
private:
|
|
typedef function<void(RibManager*,
|
|
const shared_ptr<const Interest>& request,
|
|
ControlParameters& parameters)> SignedVerbProcessor;
|
|
|
|
typedef std::map<name::Component, SignedVerbProcessor> SignedVerbDispatchTable;
|
|
|
|
typedef std::pair<name::Component, SignedVerbProcessor> SignedVerbAndProcessor;
|
|
|
|
|
|
const SignedVerbDispatchTable m_signedVerbDispatch;
|
|
|
|
static const Name COMMAND_PREFIX; // /localhost/nrd
|
|
|
|
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
|
static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
|
|
|
|
private:
|
|
// number of components in an invalid, but not malformed, unsigned command.
|
|
// (/localhost/nrd + verb + options) = 4
|
|
static const size_t COMMAND_UNSIGNED_NCOMPS;
|
|
|
|
// number of components in a valid signed Interest.
|
|
// 8 with signed Interest support.
|
|
static const size_t COMMAND_SIGNED_NCOMPS;
|
|
|
|
static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[];
|
|
|
|
typedef function<void(RibManager*, const Interest&)> UnsignedVerbProcessor;
|
|
typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable;
|
|
typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor;
|
|
|
|
const UnsignedVerbDispatchTable m_unsignedVerbDispatch;
|
|
static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[];
|
|
|
|
static const Name LIST_COMMAND_PREFIX;
|
|
static const size_t LIST_COMMAND_NCOMPS;
|
|
|
|
static const Name FACES_LIST_DATASET_PREFIX;
|
|
|
|
static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
|
|
scheduler::EventId m_activeFaceFetchEvent;
|
|
|
|
typedef std::set<uint64_t> FaceIdSet;
|
|
/** \brief contains FaceIds with one or more Routes in the RIB
|
|
*/
|
|
FaceIdSet m_registeredFaces;
|
|
};
|
|
|
|
} // namespace rib
|
|
} // namespace nfd
|
|
|
|
#endif // NFD_RIB_RIB_MANAGER_HPP
|