36 const uint64_t Fib::GRACE_PERIOD = 10;
42 std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
43 if (it != m_table.end()) {
44 for (std::set<NextHop, NextHopComparator>::iterator nhit =
45 (it->second).getNexthopList().getNextHops().begin();
46 nhit != (it->second).getNexthopList().getNextHops().end(); nhit++) {
49 if (isPrefixUpdatable((it->second).getName())) {
50 unregisterPrefix((it->second).getName(), nhit->getConnectingFaceUri());
53 cancelEntryRefresh(it->second);
61 const ndn::Name& name = entry.
getName();
68 if (isPrefixUpdatable(name)) {
71 it->getRouteCostAsAdjustedInteger(),
72 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
73 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
85 unsigned int maxFaces = getNumberOfFacesForName(allHops);
88 unsigned int nFaces = 0;
96 std::map<ndn::Name, FibEntry>::iterator entryIt = m_table.find(name);
99 if (entryIt == m_table.end() && hopsToAdd.
size() != 0) {
104 addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
106 m_table.emplace(name, entry);
108 entryIt = m_table.find(name);
116 if (hopsToAdd.
size() == 0) {
121 FibEntry& entry = (entryIt->second);
122 addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
124 std::set<NextHop, NextHopComparator> hopsToRemove;
129 bool isUpdatable = isPrefixUpdatable(entry.
getName());
131 for (
const auto& hop: hopsToRemove){
133 unregisterPrefix(entry.
getName(), hop.getConnectingFaceUri());
142 entryIt = m_table.find(name);
145 if (entryIt != m_table.end() && !entryIt->second.getRefreshEventId()) {
146 scheduleEntryRefresh(entryIt->second,
157 for (std::map<ndn::Name, FibEntry>::iterator it = m_table.begin();
160 NLSR_LOG_DEBUG(
"Cancelling Scheduled event. Name: " << it->second.getName());
161 cancelEntryRefresh(it->second);
162 for (std::set<NextHop, NextHopComparator>::iterator nhit =
163 (it->second).getNexthopList().getNextHops().begin();
164 nhit != (it->second).getNexthopList().getNextHops().end(); nhit++) {
166 unregisterPrefix((it->second).getName(), nhit->getConnectingFaceUri());
169 if (m_table.size() > 0) {
175 Fib::getNumberOfFacesForName(
NexthopList& nextHopList)
177 uint32_t nNextHops =
static_cast<uint32_t
>(nextHopList.
getNextHops().size());
181 if (nMaxFaces == 0) {
185 return std::min(nNextHops, nMaxFaces);
190 Fib::isPrefixUpdatable(
const ndn::Name& name) {
201 const ndn::time::milliseconds& timeout,
202 uint64_t flags, uint8_t times)
204 uint64_t faceId = m_adjacencyList.
getFaceId(ndn::FaceUri(faceUri));
207 ndn::nfd::ControlParameters faceParameters;
213 .setExpirationPeriod(timeout)
214 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
216 NLSR_LOG_DEBUG(
"Registering prefix: " << faceParameters.getName() <<
" faceUri: " << faceUri);
217 m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
218 std::bind(&Fib::onRegistrationSuccess,
this, _1,
219 "Successful in name registration",
221 std::bind(&Fib::onRegistrationFailure,
223 "Failed in name registration",
228 NLSR_LOG_WARN(
"Error: No Face Id for face uri: " << faceUri);
233 Fib::onRegistrationSuccess(
const ndn::nfd::ControlParameters& commandSuccessResult,
234 const std::string& message,
const ndn::FaceUri& faceUri)
236 NLSR_LOG_DEBUG(message <<
": " << commandSuccessResult.getName() <<
237 " Face Uri: " << faceUri <<
" faceId: " << commandSuccessResult.getFaceId());
240 if (adjacent != m_adjacencyList.
end()) {
241 adjacent->setFaceId(commandSuccessResult.getFaceId());
245 m_faceMap.
update(faceUri.toString(), commandSuccessResult.getFaceId());
250 Fib::onRegistrationFailure(
const ndn::nfd::ControlResponse& response,
251 const std::string& message,
252 const ndn::nfd::ControlParameters& parameters,
253 const ndn::FaceUri& faceUri,
256 NLSR_LOG_DEBUG(message <<
": " << response.getText() <<
" (code: " << response.getCode() <<
")");
257 NLSR_LOG_DEBUG(
"Prefix: " << parameters.getName() <<
" failed for: " << times);
261 parameters.getCost(),
262 parameters.getExpirationPeriod(),
263 parameters.getFlags(), times+1);
271 Fib::unregisterPrefix(
const ndn::Name& namePrefix,
const std::string& faceUri)
273 uint32_t faceId = m_faceMap.
getFaceId(faceUri);
274 NLSR_LOG_DEBUG(
"Unregister prefix: " << namePrefix <<
" Face Uri: " << faceUri);
276 ndn::nfd::ControlParameters controlParameters;
280 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
281 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
282 std::bind(&Fib::onUnregistrationSuccess,
this, _1,
283 "Successful in unregistering name"),
284 std::bind(&Fib::onUnregistrationFailure,
286 "Failed in unregistering name"));
291 Fib::onUnregistrationSuccess(
const ndn::nfd::ControlParameters& commandSuccessResult,
292 const std::string& message)
294 NLSR_LOG_DEBUG(
"Unregister successful Prefix: " << commandSuccessResult.getName() <<
295 " Face Id: " << commandSuccessResult.getFaceId());
299 Fib::onUnregistrationFailure(
const ndn::nfd::ControlResponse& response,
300 const std::string& message)
302 NLSR_LOG_DEBUG(message <<
": " << response.getText() <<
" (code: " << response.getCode() <<
")");
308 ndn::nfd::ControlParameters parameters;
311 .setStrategy(strategy);
313 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
314 std::bind(&Fib::onSetStrategySuccess,
this, _1,
315 "Successfully set strategy choice"),
316 std::bind(&Fib::onSetStrategyFailure,
this, _1,
319 "Failed to set strategy choice"));
323 Fib::onSetStrategySuccess(
const ndn::nfd::ControlParameters& commandSuccessResult,
324 const std::string& message)
326 NLSR_LOG_DEBUG(message <<
": " << commandSuccessResult.getStrategy() <<
" " 327 <<
"for name: " << commandSuccessResult.getName());
331 Fib::onSetStrategyFailure(
const ndn::nfd::ControlResponse& response,
332 const ndn::nfd::ControlParameters& parameters,
334 const std::string& message)
337 <<
"for name: " << parameters.getName());
339 setStrategy(parameters.getName(), parameters.getStrategy().toUri(),count+1);
348 <<
" in " << m_refreshTime <<
" seconds");
350 entry.
setRefreshEventId(m_scheduler.scheduleEvent(ndn::time::seconds(m_refreshTime),
351 std::bind(&Fib::refreshEntry,
this,
352 entry.
getName(), refreshCallback)));
358 scheduleEntryRefresh(entry,
359 std::bind(&Fib::scheduleLoop,
this, _1));
363 Fib::cancelEntryRefresh(
const FibEntry& entry)
374 std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
376 if (it == m_table.end()) {
386 for (
const NextHop& hop : entry) {
388 ndn::FaceUri(hop.getConnectingFaceUri()),
389 hop.getRouteCostAsAdjustedInteger(),
390 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
391 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
400 NLSR_LOG_DEBUG(
"-------------------FIB-----------------------------");
401 for (std::map<ndn::Name, FibEntry>::iterator it = m_table.begin();
const std::set< NextHop, NextHopComparator > & getNextHops() const
bool isNeighbor(const ndn::Name &adjName) const
#define NLSR_LOG_DEBUG(x)
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
uint32_t getMaxFacesPerPrefix() const
ndn::EventId getRefreshEventId() const
NexthopList & getNexthopList()
void setSeqNo(int32_t fsn)
void setRefreshEventId(ndn::EventId id)
void clean()
Remove all entries from the FIB.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const ndn::Name & getName() const
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
void update(const ndn::Name &name, NexthopList &allHops)
Set the nexthop list of a name.
std::set< NextHop, NextHopComparator >::iterator iterator
std::list< Adjacent >::iterator iterator
uint64_t getFaceId(const ndn::FaceUri &faceUri)
void removeNextHop(const NextHop &nh)
Remove a next hop from the Next Hop list.
void update(const std::string &faceUri, uint32_t faceId)
std::function< void(FibEntry &)> afterRefreshCallback
const_iterator end() const
uint32_t getFaceId(const std::string &faceUri)
void registerPrefix(const ndn::Name &namePrefix, const ndn::FaceUri &faceUri, uint64_t faceCost, const ndn::time::milliseconds &timeout, uint64_t flags, uint8_t times)
Inform NFD of a next-hop.