32 #include <ndn-cxx/lp/tags.hpp> 33 #include <ndn-cxx/mgmt/nfd/fib-entry.hpp> 35 #include <boost/range/adaptor/transformed.hpp> 45 , m_faceTable(faceTable)
47 registerCommandHandler<ndn::nfd::FibAddNextHopCommand>(
"add-nexthop",
48 bind(&FibManager::addNextHop,
this, _2, _3, _4, _5));
49 registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>(
"remove-nexthop",
50 bind(&FibManager::removeNextHop,
this, _2, _3, _4, _5));
56 FibManager::addNextHop(
const Name& topPrefix,
const Interest& interest,
57 ControlParameters parameters,
58 const ndn::mgmt::CommandContinuation& done)
60 setFaceForSelfRegistration(interest, parameters);
61 const Name& prefix = parameters.getName();
62 FaceId faceId = parameters.getFaceId();
63 uint64_t cost = parameters.getCost();
66 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
67 "): FAIL prefix-too-long");
68 return done(ControlResponse(414,
"FIB entry prefix cannot exceed " +
72 Face* face = m_faceTable.
get(faceId);
73 if (face ==
nullptr) {
74 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
75 "): FAIL unknown-faceid");
76 return done(ControlResponse(410,
"Face not found"));
82 NFD_LOG_TRACE(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
"): OK");
83 return done(ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
87 FibManager::removeNextHop(
const Name& topPrefix,
const Interest& interest,
88 ControlParameters parameters,
89 const ndn::mgmt::CommandContinuation& done)
91 setFaceForSelfRegistration(interest, parameters);
92 const Name& prefix = parameters.getName();
93 FaceId faceId = parameters.getFaceId();
95 done(ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
97 Face* face = m_faceTable.
get(faceId);
98 if (face ==
nullptr) {
99 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-face");
104 if (entry ==
nullptr) {
105 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-entry");
112 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-nexthop");
115 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK entry-erased");
118 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK nexthop-removed");
124 FibManager::listEntries(
const Name& topPrefix,
const Interest& interest,
125 ndn::mgmt::StatusDatasetContext& context)
127 for (
const auto& entry : m_fib) {
128 const auto& nexthops = entry.getNextHops() |
129 boost::adaptors::transformed([] (
const fib::NextHop& nh) {
130 return ndn::nfd::NextHopRecord()
134 context.append(ndn::nfd::FibEntry()
135 .setPrefix(entry.getPrefix())
136 .setNextHopRecords(std::begin(nexthops), std::end(nexthops))
143 FibManager::setFaceForSelfRegistration(
const Interest& request, ControlParameters& parameters)
145 bool isSelfRegistration = (parameters.getFaceId() == 0);
146 if (isSelfRegistration) {
147 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
151 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
152 parameters.setFaceId(*incomingFaceIdTag);
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
Entry * findExactMatch(const Name &prefix)
Performs an exact match lookup.
std::pair< Entry *, bool > insert(const Name &prefix)
Find or insert a FIB entry.
Face * get(FaceId id) const
get face by FaceId
Represents the Forwarding Information Base (FIB)
Provides ControlCommand authorization according to NFD configuration file.
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
the nexthop is removed and the fib entry is removed
generalization of a network interface
FibManager(fib::Fib &fib, const FaceTable &faceTable, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
static constexpr size_t getMaxDepth()
Maximum number of components in a FIB entry prefix.
void addOrUpdateNextHop(Entry &entry, Face &face, uint64_t cost)
Add a NextHop record.
#define NFD_LOG_INIT(name)
RemoveNextHopResult removeNextHop(Entry &entry, const Face &face)
Remove the NextHop record for face from entry.
Represents a nexthop record in a FIB entry.
uint64_t FaceId
Identifies a face.
the nexthop is removed and the fib entry stays