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 [
this] (
auto&&,
auto&&,
auto&&... args) { addNextHop(std::forward<decltype(args)>(args)...); });
49 registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>(
"remove-nexthop",
50 [
this] (
auto&&,
auto&&,
auto&&... args) { removeNextHop(std::forward<decltype(args)>(args)...); });
52 [
this] (
auto&&,
auto&&,
auto&&... args) { listEntries(std::forward<decltype(args)>(args)...); });
56 FibManager::addNextHop(
const Interest& interest, ControlParameters parameters,
57 const ndn::mgmt::CommandContinuation& done)
59 setFaceForSelfRegistration(interest, parameters);
60 const Name& prefix = parameters.getName();
61 FaceId faceId = parameters.getFaceId();
62 uint64_t cost = parameters.getCost();
65 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
66 "): FAIL prefix-too-long");
67 return done(ControlResponse(414,
"FIB entry prefix cannot exceed " +
71 Face* face = m_faceTable.
get(faceId);
72 if (face ==
nullptr) {
73 NFD_LOG_DEBUG(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
74 "): FAIL unknown-faceid");
75 return done(ControlResponse(410,
"Face not found"));
78 fib::Entry* entry = m_fib.
insert(prefix).first;
81 NFD_LOG_TRACE(
"fib/add-nexthop(" << prefix <<
',' << faceId <<
',' << cost <<
"): OK");
82 return done(ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
86 FibManager::removeNextHop(
const Interest& interest, ControlParameters parameters,
87 const ndn::mgmt::CommandContinuation& done)
89 setFaceForSelfRegistration(interest, parameters);
90 const Name& prefix = parameters.getName();
91 FaceId faceId = parameters.getFaceId();
93 done(ControlResponse(200,
"Success").setBody(parameters.wireEncode()));
95 Face* face = m_faceTable.
get(faceId);
96 if (face ==
nullptr) {
97 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-face");
102 if (entry ==
nullptr) {
103 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-entry");
110 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK no-nexthop");
113 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK entry-erased");
116 NFD_LOG_TRACE(
"fib/remove-nexthop(" << prefix <<
',' << faceId <<
"): OK nexthop-removed");
122 FibManager::listEntries(ndn::mgmt::StatusDatasetContext& context)
124 for (
const auto& entry : m_fib) {
125 const auto& nexthops = entry.getNextHops() |
126 boost::adaptors::transformed([] (
const fib::NextHop& nh) {
127 return ndn::nfd::NextHopRecord()
128 .setFaceId(nh.getFace().getId())
129 .setCost(nh.getCost());
131 context.append(ndn::nfd::FibEntry()
132 .setPrefix(entry.getPrefix())
133 .setNextHopRecords(std::begin(nexthops), std::end(nexthops))
140 FibManager::setFaceForSelfRegistration(
const Interest& request, ControlParameters& parameters)
143 if (isSelfRegistration) {
144 auto incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
148 BOOST_ASSERT(incomingFaceIdTag !=
nullptr);
149 parameters.setFaceId(*incomingFaceIdTag);
Provides ControlCommand authorization according to NFD's configuration file.
Face * get(FaceId id) const noexcept
Get face by FaceId.
FibManager(fib::Fib &fib, const FaceTable &faceTable, Dispatcher &dispatcher, CommandAuthenticator &authenticator)
A collection of common functions shared by all NFD managers, such as communicating with the dispatche...
void registerStatusDatasetHandler(const std::string &verb, const ndn::mgmt::StatusDatasetHandler &handler)
Represents the Forwarding Information Base (FIB).
@ NEXTHOP_REMOVED
the nexthop is removed and the fib entry stays
@ FIB_ENTRY_REMOVED
the nexthop is removed and the fib entry is removed
@ NO_SUCH_NEXTHOP
the nexthop is not found
std::pair< Entry *, bool > insert(const Name &prefix)
Find or insert a FIB entry.
Entry * findExactMatch(const Name &prefix)
Performs an exact match lookup.
RemoveNextHopResult removeNextHop(Entry &entry, const Face &face)
Remove the NextHop record for face from entry.
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)
constexpr FaceId INVALID_FACEID
Indicates an invalid FaceId.
uint64_t FaceId
Identifies a face.