41 : m_scheduler(scheduler)
42 , m_refreshTime(2 * conf.getLsaRefreshTime())
43 , m_controller(face, keyChain)
44 , m_adjacencyList(adjacencyList)
45 , m_confParameter(conf)
53 auto it = m_table.find(name);
56 if (it != m_table.end() && isNotNeighbor((it->second).name)) {
57 for (
const auto& nexthop : (it->second).nexthopList.getNextHops()) {
58 unregisterPrefix((it->second).name, nexthop.getConnectingFaceUri());
67 const ndn::Name& name = entry.
name;
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;
99 for (
auto it = allHops.
cbegin(); it != allHops.
cend() && nFaces < maxFaces; ++it, ++nFaces) {
103 auto entryIt = m_table.find(name);
106 if (entryIt == m_table.end() && hopsToAdd.
size() != 0) {
112 addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
114 m_table.emplace(name, std::move(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.
name);
139 for (
const auto& hop : hopsToRemove){
141 unregisterPrefix(entry.
name, hop.getConnectingFaceUri());
149 entryIt = m_table.find(name);
152 if (entryIt != m_table.end() &&
153 !entryIt->second.refreshEventId &&
154 isNotNeighbor(entryIt->second.name)) {
155 scheduleEntryRefresh(entryIt->second, [
this] (
FibEntry& entry) { scheduleLoop(entry); });
163 for (
const auto& it : m_table) {
164 for (
const auto& hop : it.second.nexthopList.getNextHops()) {
165 unregisterPrefix(it.second.name, hop.getConnectingFaceUri());
171 Fib::getNumberOfFacesForName(
const NexthopList& nextHopList)
173 uint32_t nNextHops =
static_cast<uint32_t
>(nextHopList.
getNextHops().size());
177 return nMaxFaces == 0 ? nNextHops : std::min(nNextHops, nMaxFaces);
181 Fib::isNotNeighbor(
const ndn::Name& name)
188 uint64_t faceCost,
const ndn::time::milliseconds& timeout,
189 uint64_t flags, uint8_t times)
191 uint64_t faceId = m_adjacencyList.
getFaceId(faceUri);
194 ndn::nfd::ControlParameters faceParameters;
200 .setExpirationPeriod(timeout)
201 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
203 NLSR_LOG_DEBUG(
"Registering prefix: " << faceParameters.getName() <<
" faceUri: " << faceUri);
204 m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
205 std::bind(&Fib::onRegistrationSuccess,
this, _1, faceUri),
206 std::bind(&Fib::onRegistrationFailure,
this, _1,
207 faceParameters, faceUri, times));
210 NLSR_LOG_WARN(
"Error: No Face Id for face uri: " << faceUri);
215 Fib::onRegistrationSuccess(
const ndn::nfd::ControlParameters& param,
216 const ndn::FaceUri& faceUri)
218 NLSR_LOG_DEBUG(
"Successful in name registration: " << param.getName() <<
219 " Face Uri: " << faceUri <<
" faceId: " << param.getFaceId());
222 if (adjacent != m_adjacencyList.
end()) {
223 adjacent->setFaceId(param.getFaceId());
229 Fib::onRegistrationFailure(
const ndn::nfd::ControlResponse& response,
230 const ndn::nfd::ControlParameters& parameters,
231 const ndn::FaceUri& faceUri,
234 NLSR_LOG_DEBUG(
"Failed in name registration: " << response.getText() <<
235 " (code: " << response.getCode() <<
")");
236 NLSR_LOG_DEBUG(
"Prefix: " << parameters.getName() <<
" failed for: " << +times);
240 parameters.getCost(),
241 parameters.getExpirationPeriod(),
242 parameters.getFlags(), times+1);
250 Fib::unregisterPrefix(
const ndn::Name& namePrefix,
const std::string& faceUri)
253 auto adjacent = m_adjacencyList.
findAdjacent(ndn::FaceUri(faceUri));
254 if (adjacent != m_adjacencyList.
end()) {
255 faceId = adjacent->getFaceId();
258 NLSR_LOG_DEBUG(
"Unregister prefix: " << namePrefix <<
" Face Uri: " << faceUri);
260 ndn::nfd::ControlParameters controlParameters;
264 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
266 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
267 [] (
const ndn::nfd::ControlParameters& commandSuccessResult) {
268 NLSR_LOG_DEBUG(
"Unregister successful Prefix: " << commandSuccessResult.getName() <<
269 " Face Id: " << commandSuccessResult.getFaceId());
271 [] (
const ndn::nfd::ControlResponse& response) {
272 NLSR_LOG_DEBUG(
"Failed in unregistering name" <<
": " << response.getText() <<
273 " (code: " << response.getCode() <<
")");
281 ndn::nfd::ControlParameters parameters;
284 .setStrategy(strategy);
286 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
287 std::bind(&Fib::onSetStrategySuccess,
this, _1),
288 std::bind(&Fib::onSetStrategyFailure,
this, _1,
293 Fib::onSetStrategySuccess(
const ndn::nfd::ControlParameters& commandSuccessResult)
295 NLSR_LOG_DEBUG(
"Successfully set strategy choice: " << commandSuccessResult.getStrategy() <<
296 " for name: " << commandSuccessResult.getName());
300 Fib::onSetStrategyFailure(
const ndn::nfd::ControlResponse& response,
301 const ndn::nfd::ControlParameters& parameters,
304 NLSR_LOG_DEBUG(
"Failed to set strategy choice: " << parameters.getStrategy() <<
305 " for name: " << parameters.getName());
307 setStrategy(parameters.getName(), parameters.getStrategy().toUri(), count + 1);
315 " Seq Num: " << entry.seqNo <<
316 " in " << m_refreshTime <<
" seconds");
318 entry.refreshEventId = m_scheduler.schedule(ndn::time::seconds(m_refreshTime),
319 std::bind(&Fib::refreshEntry,
this,
320 entry.name, refreshCallback));
324 Fib::scheduleLoop(FibEntry& entry)
326 scheduleEntryRefresh(entry, std::bind(&Fib::scheduleLoop,
this, _1));
332 auto it = m_table.find(name);
333 if (it == m_table.end()) {
337 FibEntry& entry = it->second;
338 NLSR_LOG_DEBUG(
"Refreshing " << entry.name <<
" Seq Num: " << entry.seqNo);
342 for (
const NextHop& hop : entry.nexthopList) {
344 ndn::FaceUri(hop.getConnectingFaceUri()),
345 hop.getRouteCostAsAdjustedInteger(),
346 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
347 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
356 NLSR_LOG_DEBUG(
"-------------------FIB-----------------------------");
357 for (
const auto& entry : m_table) {
uint64_t getFaceId(const ndn::FaceUri &faceUri)
const_iterator end() const
bool isNeighbor(const ndn::Name &adjName) const
AdjacencyList::iterator findAdjacent(const ndn::Name &adjName)
A class to house all the configuration parameters for NLSR.
uint32_t getMaxFacesPerPrefix() const
static const std::string MULTICAST_STRATEGY
void clean()
Remove all entries from the FIB.
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::KeyChain &keyChain)
static const std::string BEST_ROUTE_V2_STRATEGY
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
ndn::util::Signal< Fib, const ndn::Name & > onPrefixRegistrationSuccess
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.
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
const_iterator cend() const
const_iterator cbegin() const
void removeNextHop(const NextHop &nh)
Remove a next hop from the Next Hop list.
const std::set< NextHop, NextHopComparator > & getNextHops() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...
std::function< void(FibEntry &)> afterRefreshCallback