29 #include <ndn-cxx/lp/tags.hpp> 30 #include <ndn-cxx/mgmt/nfd/fib-entry.hpp> 32 #include <boost/range/adaptor/transformed.hpp> 44 , m_faceTable(faceTable)
46 registerCommandHandler<ndn::nfd::FibAddNextHopCommand>(
"add-nexthop",
47 bind(&FibManager::addNextHop,
this, _2, _3, _4, _5));
48 registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>(
"remove-nexthop",
49 bind(&FibManager::removeNextHop,
this, _2, _3, _4, _5));
55 FibManager::addNextHop(
const Name& topPrefix,
const Interest& interest,
59 setFaceForSelfRegistration(interest, parameters);
62 uint64_t cost = parameters.
getCost();
65 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
66 "): FAIL prefix-too-long");
72 if (
face ==
nullptr) {
73 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
74 "): FAIL unknown-faceid");
78 fib::Entry* entry = m_fib.
insert(prefix).first;
79 entry->addNextHop(*
face, cost);
81 NFD_LOG_TRACE(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
"): OK");
86 FibManager::removeNextHop(
const Name& topPrefix,
const Interest& interest,
90 setFaceForSelfRegistration(interest, parameters);
91 const Name& prefix = parameters.getName();
92 FaceId faceId = parameters.getFaceId();
97 if (
face ==
nullptr) {
98 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-face");
103 if (entry ==
nullptr) {
104 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-entry");
108 entry->removeNextHop(*
face);
109 if (!entry->hasNextHops()) {
111 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK entry-erased");
114 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK nexthop-removed");
119 FibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
122 for (
const auto& entry : m_fib) {
123 const auto& nexthops = entry.getNextHops() |
124 boost::adaptors::transformed([] (
const fib::NextHop& nh) {
126 .setFaceId(nh.getFace().getId())
127 .setCost(nh.getCost());
130 .setPrefix(entry.getPrefix())
131 .setNextHopRecords(std::begin(nexthops), std::end(nexthops))
140 bool isSelfRegistration = (parameters.getFaceId() == 0);
141 if (isSelfRegistration) {
146 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
147 parameters.setFaceId(*incomingFaceIdTag);
std::pair< Entry *, bool > insert(const Name &prefix)
find or insert a FIB entry
Entry * findExactMatch(const Name &prefix)
performs an exact match lookup
void erase(const Name &prefix)
represents parameters in a ControlCommand request or response
represents a dispatcher on server side of NFD Management protocol
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Represents an Interest packet.
#define NFD_LOG_DEBUG(expression)
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
Face * get(FaceId id) const
get face by FaceId
provides a tag type for simple types
#define NFD_LOG_TRACE(expression)
const Name & getName() const
FibManager(Fib &fib, const FaceTable &faceTable, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
mgmt::ControlResponse ControlResponse
Copyright (c) 2011-2015 Regents of the University of California.
void end()
end the response successfully after appending zero or more blocks
represents the Forwarding Information Base (FIB)
Represents an absolute name.
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
uint64_t getFaceId() const
size_t size() const
Get number of components.
provides ControlCommand authorization according to NFD configuration file
void append(const Block &block)
append a Block to the response
std::string to_string(const V &v)
provides a context for generating response to a StatusDataset request
uint64_t FaceId
identifies a face
a collection of common functions shared by all NFD managers, such as communicating with the dispatche...
#define NFD_LOG_INIT(name)
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)