blob: e3750b1d995bc583e01a2961bcc07f6cbd27c8ea [file] [log] [blame]
/* -*- 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 <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);
private:
typedef uint32_t TransactionId;
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);
void
expireEntry(const shared_ptr<const Interest>& request, ControlParameters& params);
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 FaceEntry& faceEntry);
void
onRegSuccess(const shared_ptr<const Interest>& request,
const ControlParameters& parameters,
const FaceEntry& faceEntry);
void
onUnRegSuccess(const shared_ptr<const Interest>& request,
const ControlParameters& parameters,
const FaceEntry& faceEntry);
void
onNrdCommandPrefixAddNextHopSuccess(const Name& prefix);
void
onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
void
onAddNextHopSuccess(const shared_ptr<const Interest>& request,
const ControlParameters& parameters,
const TransactionId transactionId,
const bool shouldSendResponse);
void
onAddNextHopError(uint32_t code, const std::string& error,
const shared_ptr<const Interest>& request,
const TransactionId transactionId, const bool shouldSendResponse);
void
onRemoveNextHopSuccess(const shared_ptr<const Interest>& request,
const ControlParameters& parameters,
const TransactionId transactionId,
const bool shouldSendResponse);
void
onRemoveNextHopError(uint32_t code, const std::string& error,
const shared_ptr<const Interest>& request,
const TransactionId transactionId, const bool shouldSendResponse);
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);
void
processErasureAfterNotification(uint64_t faceId);
void
sendUpdatesToFib(const shared_ptr<const Interest>& request,
const ControlParameters& parameters);
void
sendUpdatesToFibAfterFaceDestroyEvent();
/** \brief Checks if the transaction has received all of the expected responses
* from the FIB.
* \return{ True if the transaction with the passed transactionId has applied
* all of its FIB updates successfully; otherwise, false }
*/
bool
isTransactionComplete(const TransactionId transactionId);
void
invalidateTransaction(const TransactionId transactionId);
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;
/** \brief The last transaction ID for FIB update response messages.
* Each group of FIB updates applied to the FIB is assigned an incrementing
* ID that is used to track the number of successfully applied updates.
*/
TransactionId m_lastTransactionId;
/// table of FIB update transactions => count of pending FIB updates
typedef std::map<TransactionId, int> FibTransactionTable;
/** \brief Table used to track the number of FIB updates that have not yet received
* a response from the FIB.
* The table maps a transaction ID to the number of updates remaining for that
* specific transaction.
*/
FibTransactionTable m_pendingFibTransactions;
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
static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
// 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