34 #include <ndn-cxx/encoding/tlv.hpp> 40 const Name FibManager::COMMAND_PREFIX =
"/localhost/nfd/fib";
42 const size_t FibManager::COMMAND_UNSIGNED_NCOMPS =
43 FibManager::COMMAND_PREFIX.
size() +
47 const size_t FibManager::COMMAND_SIGNED_NCOMPS =
48 FibManager::COMMAND_UNSIGNED_NCOMPS +
51 const FibManager::SignedVerbAndProcessor FibManager::SIGNED_COMMAND_VERBS[] =
54 SignedVerbAndProcessor(
56 &FibManager::addNextHop
59 SignedVerbAndProcessor(
61 &FibManager::removeNextHop
66 const FibManager::UnsignedVerbAndProcessor FibManager::UNSIGNED_COMMAND_VERBS[] =
68 UnsignedVerbAndProcessor(
70 &FibManager::listEntries
74 const Name FibManager::LIST_COMMAND_PREFIX(
"/localhost/nfd/fib/list");
75 const size_t FibManager::LIST_COMMAND_NCOMPS = LIST_COMMAND_PREFIX.size();
79 function<shared_ptr<Face>(
FaceId)> getFace,
80 shared_ptr<InternalFace> face,
81 ndn::KeyChain& keyChain)
85 , m_fibEnumerationPublisher(fib, *face, LIST_COMMAND_PREFIX, keyChain)
86 , m_signedVerbDispatch(SIGNED_COMMAND_VERBS,
87 SIGNED_COMMAND_VERBS +
88 (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor)))
89 , m_unsignedVerbDispatch(UNSIGNED_COMMAND_VERBS,
90 UNSIGNED_COMMAND_VERBS +
91 (sizeof(UNSIGNED_COMMAND_VERBS) / sizeof(UnsignedVerbAndProcessor)))
93 face->setInterestFilter(
"/localhost/nfd/fib",
106 const size_t commandNComps = command.
size();
108 if (commandNComps <= COMMAND_PREFIX.
size())
118 const auto unsignedVerbProcessor = m_unsignedVerbDispatch.find(verb);
119 if (unsignedVerbProcessor != m_unsignedVerbDispatch.end())
122 (unsignedVerbProcessor->second)(
this, request);
124 else if (COMMAND_UNSIGNED_NCOMPS <= commandNComps &&
125 commandNComps < COMMAND_SIGNED_NCOMPS)
130 else if (commandNComps < COMMAND_SIGNED_NCOMPS ||
139 bind(&FibManager::onValidatedFibRequest,
this, _1),
145 FibManager::onValidatedFibRequest(
const shared_ptr<const Interest>& request)
147 const Name& command = request->getName();
151 SignedVerbDispatchTable::const_iterator verbProcessor = m_signedVerbDispatch.find(verb);
152 if (verbProcessor != m_signedVerbDispatch.end())
163 if (isSelfRegistration)
165 parameters.
setFaceId(request->getIncomingFaceId());
170 (verbProcessor->second)(
this, parameters, response);
195 uint64_t cost = parameters.
getCost();
198 <<
" faceid: " << faceId
199 <<
" cost: " << cost);
201 shared_ptr<Face> nextHopFace = m_getFace(faceId);
202 if (static_cast<bool>(nextHopFace))
204 shared_ptr<fib::Entry> entry = m_managedFib.
insert(prefix).first;
206 entry->addNextHop(nextHopFace, cost);
209 <<
" prefix:" << prefix
210 <<
" faceid: " << faceId
211 <<
" cost: " << cost);
217 NFD_LOG_DEBUG(
"add-nexthop result: FAIL reason: unknown-faceid: " << faceId);
229 NFD_LOG_DEBUG(
"remove-nexthop result: FAIL reason: malformed");
235 <<
" faceid: " << parameters.
getFaceId());
237 shared_ptr<Face> faceToRemove = m_getFace(parameters.
getFaceId());
238 if (static_cast<bool>(faceToRemove))
241 if (static_cast<bool>(entry))
243 entry->removeNextHop(faceToRemove);
245 <<
" faceid: " << parameters.
getFaceId());
247 if (!entry->hasNextHops())
249 m_managedFib.
erase(*entry);
254 NFD_LOG_DEBUG(
"remove-nexthop result: OK, but entry for face id " 255 << parameters.
getFaceId() <<
" not found");
261 << parameters.
getFaceId() <<
" not found");
268 FibManager::listEntries(
const Interest& request)
271 const size_t commandNComps = command.
size();
273 if (commandNComps < LIST_COMMAND_NCOMPS ||
281 m_fibEnumerationPublisher.
publish();
ControlParameters & setFaceId(uint64_t faceId)
const Name & getName() const
#define NFD_LOG_DEBUG(expression)
represents a fib/add-nexthop command
represents parameters in a ControlCommand request or response
std::pair< shared_ptr< fib::Entry >, bool > insert(const Name &prefix)
inserts a FIB entry for prefix If an entry for exact same prefix exists, that entry is returned...
void sendResponse(const Name &name, const ControlResponse &response)
represents an Interest packet
FibManager(Fib &fib, function< shared_ptr< Face >(FaceId)> getFace, shared_ptr< InternalFace > face, ndn::KeyChain &keyChain)
represents a fib/remove-nexthop command
size_t wireEncode(EncodingImpl< TAG > &encoder) const
static bool extractParameters(const Name::Component ¶meterComponent, ControlParameters &extractedParameters)
const std::string FIB_PRIVILEGE
ndn::mgmt::ControlResponse ControlResponse
void erase(const Name &prefix)
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< fib::Entry > findExactMatch(const Name &prefix) const
const Name & getName() const
void onCommandValidationFailed(const shared_ptr< const Interest > &command, const std::string &error)
size_t size() const
Get the number of components.
Name abstraction to represent an absolute name.
uint64_t getFaceId() const
Component holds a read-only name component value.
void onFibRequest(const Interest &request)
#define NFD_LOG_INIT(name)
#define NFD_LOG_TRACE(expression)
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
void setResponse(ControlResponse &response, uint32_t code, const std::string &text)
virtual bool validateParameters(const ControlCommand &command, ControlParameters ¶meters)
void validate(const Interest &interest, const ndn::OnInterestValidated &onValidated, const ndn::OnInterestValidationFailed &onValidationFailed)
const Component & at(ssize_t i) const
Get component at the specified index.