34 #include <boost/range/adaptor/transformed.hpp> 46 , m_faceTable(faceTable)
48 registerCommandHandler<ndn::nfd::FibAddNextHopCommand>(
"add-nexthop",
49 bind(&FibManager::addNextHop,
this, _2, _3, _4, _5));
50 registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>(
"remove-nexthop",
51 bind(&FibManager::removeNextHop,
this, _2, _3, _4, _5));
57 FibManager::addNextHop(
const Name& topPrefix,
const Interest& interest,
61 setFaceForSelfRegistration(interest, parameters);
64 uint64_t cost = parameters.
getCost();
67 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
68 "): FAIL prefix-too-long");
73 Face* face = m_faceTable.
get(faceId);
74 if (face ==
nullptr) {
75 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
76 "): FAIL unknown-faceid");
80 fib::Entry* entry = m_fib.
insert(prefix).first;
81 entry->addOrUpdateNextHop(*face, 0, cost);
83 NFD_LOG_TRACE(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
"): OK");
88 FibManager::removeNextHop(
const Name& topPrefix,
const Interest& interest,
92 setFaceForSelfRegistration(interest, parameters);
93 const Name& prefix = parameters.getName();
94 FaceId faceId = parameters.getFaceId();
98 Face* face = m_faceTable.
get(faceId);
99 if (face ==
nullptr) {
100 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-face");
105 if (entry ==
nullptr) {
106 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-entry");
110 entry->removeNextHop(*face, 0);
111 if (!entry->hasNextHops()) {
113 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK entry-erased");
116 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK nexthop-removed");
121 FibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
124 for (
const auto& entry : m_fib) {
125 const auto& nexthops = entry.getNextHops() |
126 boost::adaptors::transformed([] (
const fib::NextHop& nh) {
128 .setFaceId(nh.getFace().getId())
129 .setCost(nh.getCost());
132 .setPrefix(entry.getPrefix())
133 .setNextHopRecords(std::begin(nexthops), std::end(nexthops))
142 bool isSelfRegistration = (parameters.getFaceId() == 0);
143 if (isSelfRegistration) {
148 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
149 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.
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
const Name & getName() const
FibManager(Fib &fib, const FaceTable &faceTable, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
mgmt::ControlResponse ControlResponse
implement the FIB Management of NFD Management Protocol.
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)