36 const uint64_t Fib::GRACE_PERIOD = 10;
40 : m_scheduler(scheduler)
41 , m_refreshTime(2 * conf.getLsaRefreshTime())
42 , m_controller(face, keyChain)
43 , m_adjacencyList(adjacencyList)
44 , m_confParameter(conf)
52 std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
55 if (it != m_table.end() && isNotNeighbor((it->second).getName())) {
56 for (
const auto& nexthop : (it->second).getNexthopList().getNextHops()) {
57 unregisterPrefix((it->second).getName(), nexthop.getConnectingFaceUri());
59 cancelEntryRefresh(it->second);
67 const ndn::Name& name = entry.
getName();
69 bool shouldRegister = isNotNeighbor(name);
79 hop.getRouteCostAsAdjustedInteger(),
80 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
81 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
93 unsigned int maxFaces = getNumberOfFacesForName(allHops);
96 unsigned int nFaces = 0;
104 std::map<ndn::Name, FibEntry>::iterator entryIt = m_table.find(name);
107 if (entryIt == m_table.end() && hopsToAdd.
size() != 0) {
112 addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
114 m_table.emplace(name, entry);
116 entryIt = m_table.find(name);
124 if (hopsToAdd.
size() == 0) {
129 FibEntry& entry = (entryIt->second);
130 addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
132 std::set<NextHop, NextHopComparator> hopsToRemove;
137 bool isUpdatable = isNotNeighbor(entry.
getName());
139 for (
const auto& hop : hopsToRemove){
141 unregisterPrefix(entry.
getName(), hop.getConnectingFaceUri());
150 entryIt = m_table.find(name);
153 if (entryIt != m_table.end() &&
154 !entryIt->second.getRefreshEventId() &&
155 isNotNeighbor(entryIt->second.getName())) {
156 scheduleEntryRefresh(entryIt->second,
168 for (
auto&& it : m_table) {
169 NLSR_LOG_DEBUG(
"Canceling Scheduled event. Name: " << it.second.getName());
170 cancelEntryRefresh(it.second);
172 for (
const auto& hop : it.second.getNexthopList().getNextHops()) {
173 unregisterPrefix(it.second.getName(), hop.getConnectingFaceUri());
179 Fib::getNumberOfFacesForName(
const NexthopList& nextHopList)
181 uint32_t nNextHops =
static_cast<uint32_t
>(nextHopList.
getNextHops().size());
185 if (nMaxFaces == 0) {
189 return std::min(nNextHops, nMaxFaces);
194 Fib::isNotNeighbor(
const ndn::Name& name)
202 const ndn::time::milliseconds& timeout,
203 uint64_t flags, uint8_t times)
205 uint64_t faceId = m_adjacencyList.
getFaceId(ndn::FaceUri(faceUri));
208 ndn::nfd::ControlParameters faceParameters;
214 .setExpirationPeriod(timeout)
215 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
217 NLSR_LOG_DEBUG(
"Registering prefix: " << faceParameters.getName() <<
" faceUri: " << faceUri);
218 m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
219 std::bind(&Fib::onRegistrationSuccess,
this, _1,
220 "Successful in name registration",
222 std::bind(&Fib::onRegistrationFailure,
this, _1,
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, std::bind(&Fib::scheduleLoop,
this, _1));
362 Fib::cancelEntryRefresh(
const FibEntry& entry)
373 std::map<ndn::Name, FibEntry>::iterator it = m_table.find(name);
375 if (it == m_table.end()) {
385 for (
const NextHop& hop : entry) {
387 ndn::FaceUri(hop.getConnectingFaceUri()),
388 hop.getRouteCostAsAdjustedInteger(),
389 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
390 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
399 NLSR_LOG_DEBUG(
"-------------------FIB-----------------------------");
400 for (
const auto& entry : m_table) {
A class to house all the configuration parameters for NLSR.
const std::set< NextHop, NextHopComparator > & getNextHops() const
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
const_iterator cend() 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)
const_iterator cbegin() const
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.
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::v2::KeyChain &keyChain)
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.
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.