blob: 159d358f650681d222d6f83c49d5b815927d9d86 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoaf7a2112019-03-19 14:55:20 -04002/*
Davide Pesaventod2610dc2025-01-03 13:20:06 -05003 * Copyright (c) 2014-2025, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040019 */
Nick Gordonb7168472016-09-21 13:57:17 -050020
akmhoquefdbddb12014-05-02 18:35:19 -050021#include "fib.hpp"
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050022#include "adjacency-list.hpp"
23#include "conf-parameter.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050024#include "logger.hpp"
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050025#include "nexthop-list.hpp"
26
Davide Pesaventod2610dc2025-01-03 13:20:06 -050027#include <ndn-cxx/mgmt/nfd/control-command.hpp>
28
laqinfancd7ca052017-06-02 04:57:18 -050029#include <algorithm>
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040030#include <cmath>
31#include <map>
akmhoquec8a10f72014-04-25 18:42:55 -050032
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
34
dmcoomescf8d0ed2017-02-21 11:39:01 -060035INIT_LOGGER(route.Fib);
akmhoque674b0b12014-05-20 14:33:28 -050036
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060037Fib::Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList,
Alexander Afanasyev0ad01f32020-06-03 14:12:58 -040038 ConfParameter& conf, ndn::security::KeyChain& keyChain)
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060039 : m_scheduler(scheduler)
Ashlesh Gawande85998a12017-12-07 22:22:13 -060040 , m_refreshTime(2 * conf.getLsaRefreshTime())
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060041 , m_controller(face, keyChain)
42 , m_adjacencyList(adjacencyList)
43 , m_confParameter(conf)
44{
45}
46
akmhoque53353462014-04-22 08:43:45 -050047void
akmhoque31d1d4b2014-05-05 22:08:14 -050048Fib::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050049{
dmcoomes5bcb39e2017-10-31 15:07:55 -050050 NLSR_LOG_DEBUG("Fib::remove called");
Davide Pesaventoaf7a2112019-03-19 14:55:20 -040051 auto it = m_table.find(name);
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060052
53 // Only unregister the prefix if it ISN'T a neighbor.
Ashlesh Gawande7a231c02020-06-12 20:06:44 -070054 if (it != m_table.end() && isNotNeighbor((it->second).name)) {
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -070055 for (const auto& nexthop : (it->second).nexthopSet) {
Ashlesh Gawande7a231c02020-06-12 20:06:44 -070056 unregisterPrefix((it->second).name, nexthop.getConnectingFaceUri());
akmhoque53353462014-04-22 08:43:45 -050057 }
akmhoque53353462014-04-22 08:43:45 -050058 m_table.erase(it);
59 }
60}
61
Vince Lehman18841082014-08-19 17:15:24 -050062void
awlanefc0b45a2025-05-07 15:51:02 -050063Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd, uint64_t routeFlags)
Vince Lehman18841082014-08-19 17:15:24 -050064{
Ashlesh Gawande7a231c02020-06-12 20:06:44 -070065 const ndn::Name& name = entry.name;
Vince Lehman18841082014-08-19 17:15:24 -050066
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060067 bool shouldRegister = isNotNeighbor(name);
68
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -070069 for (const auto& hop : hopsToAdd)
Vince Lehman18841082014-08-19 17:15:24 -050070 {
71 // Add nexthop to FIB entry
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -070072 NLSR_LOG_DEBUG("Adding " << hop.getConnectingFaceUri() << " to " << entry.name);
73 entry.nexthopSet.addNextHop(hop);
Vince Lehman18841082014-08-19 17:15:24 -050074
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060075 if (shouldRegister) {
Vince Lehman18841082014-08-19 17:15:24 -050076 // Add nexthop to NDN-FIB
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060077 registerPrefix(name, ndn::FaceUri(hop.getConnectingFaceUri()),
78 hop.getRouteCostAsAdjustedInteger(),
Vince Lehman18841082014-08-19 17:15:24 -050079 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
awlanefc0b45a2025-05-07 15:51:02 -050080 routeFlags, 0);
Vince Lehman18841082014-08-19 17:15:24 -050081 }
82 }
Vince Lehman942eb7b2014-10-02 10:09:27 -050083}
84
85void
awlanefc0b45a2025-05-07 15:51:02 -050086Fib::update(const ndn::Name& name, const NexthopList& allHops, uint64_t routeFlags)
Vince Lehman18841082014-08-19 17:15:24 -050087{
dmcoomes5bcb39e2017-10-31 15:07:55 -050088 NLSR_LOG_DEBUG("Fib::update called");
Vince Lehman18841082014-08-19 17:15:24 -050089
Ashlesh Gawandee5002b32018-12-20 21:07:31 -060090 // Get the max possible faces which is the minimum of the configuration setting and
Vince Lehman942eb7b2014-10-02 10:09:27 -050091 // the length of the list of all next hops.
92 unsigned int maxFaces = getNumberOfFacesForName(allHops);
Vince Lehman18841082014-08-19 17:15:24 -050093
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -070094 NextHopsUriSortedSet hopsToAdd;
Vince Lehman942eb7b2014-10-02 10:09:27 -050095 unsigned int nFaces = 0;
Vince Lehman18841082014-08-19 17:15:24 -050096
Vince Lehman942eb7b2014-10-02 10:09:27 -050097 // Create a list of next hops to be installed with length == maxFaces
Davide Pesaventoaf7a2112019-03-19 14:55:20 -040098 for (auto it = allHops.cbegin(); it != allHops.cend() && nFaces < maxFaces; ++it, ++nFaces) {
Vince Lehman942eb7b2014-10-02 10:09:27 -050099 hopsToAdd.addNextHop(*it);
100 }
Vince Lehman18841082014-08-19 17:15:24 -0500101
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400102 auto entryIt = m_table.find(name);
Vince Lehman942eb7b2014-10-02 10:09:27 -0500103
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500104 // New FIB entry that has nextHops
Nick Gordonff9a6272017-10-12 13:38:29 -0500105 if (entryIt == m_table.end() && hopsToAdd.size() != 0) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500106 NLSR_LOG_DEBUG("New FIB Entry");
Vince Lehman18841082014-08-19 17:15:24 -0500107
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700108 FibEntry entry;
109 entry.name = name;
awlanefc0b45a2025-05-07 15:51:02 -0500110 addNextHopsToFibEntryAndNfd(entry, hopsToAdd, routeFlags);
Vince Lehman18841082014-08-19 17:15:24 -0500111
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400112 entryIt = m_table.try_emplace(name, std::move(entry)).first;
akmhoque53353462014-04-22 08:43:45 -0500113 }
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500114 // Existing FIB entry that may or may not have nextHops
akmhoque157b0a42014-05-13 00:26:37 -0500115 else {
Vince Lehman18841082014-08-19 17:15:24 -0500116 // Existing FIB entry
dmcoomes5bcb39e2017-10-31 15:07:55 -0500117 NLSR_LOG_DEBUG("Existing FIB Entry");
Vince Lehman18841082014-08-19 17:15:24 -0500118
119 // Remove empty FIB entry
Nick Gordonff9a6272017-10-12 13:38:29 -0500120 if (hopsToAdd.size() == 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500121 remove(name);
Nick Gordon5867b522017-09-06 17:41:37 -0500122 return;
akmhoque53353462014-04-22 08:43:45 -0500123 }
Vince Lehman18841082014-08-19 17:15:24 -0500124
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400125 FibEntry& entry = entryIt->second;
awlanefc0b45a2025-05-07 15:51:02 -0500126 addNextHopsToFibEntryAndNfd(entry, hopsToAdd, routeFlags);
Vince Lehman18841082014-08-19 17:15:24 -0500127
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700128 std::set<NextHop, NextHopUriSortedComparator> hopsToRemove;
129 std::set_difference(entry.nexthopSet.begin(), entry.nexthopSet.end(),
laqinfancd7ca052017-06-02 04:57:18 -0500130 hopsToAdd.begin(), hopsToAdd.end(),
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700131 std::inserter(hopsToRemove, hopsToRemove.begin()),
132 NextHopUriSortedComparator());
laqinfancd7ca052017-06-02 04:57:18 -0500133
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700134 bool isUpdatable = isNotNeighbor(entry.name);
laqinfancd7ca052017-06-02 04:57:18 -0500135 // Remove the uninstalled next hops from NFD and FIB entry
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600136 for (const auto& hop : hopsToRemove){
laqinfancd7ca052017-06-02 04:57:18 -0500137 if (isUpdatable) {
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700138 unregisterPrefix(entry.name, hop.getConnectingFaceUri());
laqinfancd7ca052017-06-02 04:57:18 -0500139 }
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700140 NLSR_LOG_DEBUG("Removing " << hop.getConnectingFaceUri() << " from " << entry.name);
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700141 entry.nexthopSet.removeNextHop(hop);
laqinfancd7ca052017-06-02 04:57:18 -0500142 }
Vince Lehman18841082014-08-19 17:15:24 -0500143
Vince Lehman18841082014-08-19 17:15:24 -0500144 // Increment sequence number
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700145 entry.seqNo += 1;
Nick Gordon5867b522017-09-06 17:41:37 -0500146 entryIt = m_table.find(name);
Nick Gordon5867b522017-09-06 17:41:37 -0500147 }
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700148
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600149 if (entryIt != m_table.end() &&
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700150 !entryIt->second.refreshEventId &&
151 isNotNeighbor(entryIt->second.name)) {
awlanefc0b45a2025-05-07 15:51:02 -0500152 scheduleEntryRefresh(entryIt->second, routeFlags,
153 [this] (FibEntry& entry, uint64_t routeFlags) { scheduleLoop(entry, routeFlags); });
akmhoque53353462014-04-22 08:43:45 -0500154 }
155}
156
Vince Lehman942eb7b2014-10-02 10:09:27 -0500157unsigned int
Ashlesh Gawandee8d8bd52018-08-09 17:18:51 -0500158Fib::getNumberOfFacesForName(const NexthopList& nextHopList)
akmhoque53353462014-04-22 08:43:45 -0500159{
Vince Lehman942eb7b2014-10-02 10:09:27 -0500160 uint32_t nNextHops = static_cast<uint32_t>(nextHopList.getNextHops().size());
161 uint32_t nMaxFaces = m_confParameter.getMaxFacesPerPrefix();
162
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700163 // 0 == all faces
164 return nMaxFaces == 0 ? nNextHops : std::min(nNextHops, nMaxFaces);
akmhoque53353462014-04-22 08:43:45 -0500165}
166
akmhoque393d4ff2014-07-16 14:27:03 -0500167bool
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600168Fib::isNotNeighbor(const ndn::Name& name)
169{
170 return !m_adjacencyList.isNeighbor(name);
akmhoque393d4ff2014-07-16 14:27:03 -0500171}
172
akmhoque53353462014-04-22 08:43:45 -0500173void
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500174Fib::registerPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri,
Ashlesh Gawande41878572019-09-29 00:16:02 -0500175 uint64_t faceCost, const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500176 uint64_t flags, uint8_t times)
akmhoquec04e7272014-07-02 11:00:14 -0500177{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500178 uint64_t faceId = m_adjacencyList.getFaceId(faceUri);
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500179
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500180 if (faceId > 0) {
akmhoque060d3022014-08-12 13:35:06 -0500181 ndn::nfd::ControlParameters faceParameters;
182 faceParameters
183 .setName(namePrefix)
184 .setFaceId(faceId)
185 .setFlags(flags)
186 .setCost(faceCost)
187 .setExpirationPeriod(timeout)
Davide Pesavento87911da2017-02-21 22:10:55 -0500188 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
akmhoque060d3022014-08-12 13:35:06 -0500189
dmcoomes5bcb39e2017-10-31 15:07:55 -0500190 NLSR_LOG_DEBUG("Registering prefix: " << faceParameters.getName() << " faceUri: " << faceUri);
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500191 m_controller.start<ndn::nfd::RibRegisterCommand>(faceParameters,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500192 std::bind(&Fib::onRegistrationSuccess, this, _1, faceUri),
Davide Pesaventod2610dc2025-01-03 13:20:06 -0500193 std::bind(&Fib::onRegistrationFailure, this, _1, faceParameters, faceUri, times));
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500194 }
195 else {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500196 NLSR_LOG_WARN("Error: No Face Id for face uri: " << faceUri);
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500197 }
198}
199
200void
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500201Fib::onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
202 const ndn::FaceUri& faceUri)
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500203{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500204 NLSR_LOG_DEBUG("Successful in name registration: " << param.getName() <<
205 " Face Uri: " << faceUri << " faceId: " << param.getFaceId());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500206
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400207 auto adjacent = m_adjacencyList.findAdjacent(faceUri);
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500208 if (adjacent != m_adjacencyList.end()) {
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500209 adjacent->setFaceId(param.getFaceId());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500210 }
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500211 onPrefixRegistrationSuccess(param.getName());
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500212}
213
214void
215Fib::onRegistrationFailure(const ndn::nfd::ControlResponse& response,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500216 const ndn::nfd::ControlParameters& parameters,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500217 const ndn::FaceUri& faceUri,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500218 uint8_t times)
219{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500220 NLSR_LOG_DEBUG("Failed in name registration: " << response.getText() <<
221 " (code: " << response.getCode() << ")");
222 NLSR_LOG_DEBUG("Prefix: " << parameters.getName() << " failed for: " << +times);
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500223 if (times < 3) {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500224 NLSR_LOG_DEBUG("Trying to register again...");
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500225 registerPrefix(parameters.getName(), faceUri,
226 parameters.getCost(),
227 parameters.getExpirationPeriod(),
228 parameters.getFlags(), times+1);
229 }
230 else {
dmcoomes5bcb39e2017-10-31 15:07:55 -0500231 NLSR_LOG_DEBUG("Registration trial given up");
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500232 }
akmhoquefdbddb12014-05-02 18:35:19 -0500233}
akmhoque31d1d4b2014-05-05 22:08:14 -0500234
akmhoquefdbddb12014-05-02 18:35:19 -0500235void
Junxiao Shi6593a432023-08-21 10:50:28 +0000236Fib::unregisterPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri)
akmhoquefdbddb12014-05-02 18:35:19 -0500237{
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500238 uint64_t faceId = 0;
Junxiao Shi6593a432023-08-21 10:50:28 +0000239 auto adjacent = m_adjacencyList.findAdjacent(faceUri);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500240 if (adjacent != m_adjacencyList.end()) {
241 faceId = adjacent->getFaceId();
242 }
243
dmcoomes5bcb39e2017-10-31 15:07:55 -0500244 NLSR_LOG_DEBUG("Unregister prefix: " << namePrefix << " Face Uri: " << faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500245 if (faceId > 0) {
246 ndn::nfd::ControlParameters controlParameters;
247 controlParameters
248 .setName(namePrefix)
249 .setFaceId(faceId)
Davide Pesavento87911da2017-02-21 22:10:55 -0500250 .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR);
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500251
akmhoque157b0a42014-05-13 00:26:37 -0500252 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500253 [] (const ndn::nfd::ControlParameters& commandSuccessResult) {
254 NLSR_LOG_DEBUG("Unregister successful Prefix: " << commandSuccessResult.getName() <<
255 " Face Id: " << commandSuccessResult.getFaceId());
256 },
257 [] (const ndn::nfd::ControlResponse& response) {
Davide Pesaventod2610dc2025-01-03 13:20:06 -0500258 NLSR_LOG_DEBUG("Failed in unregistering name: " << response.getText() <<
259 " (code " << response.getCode() << ")");
Ashlesh Gawande6b388fc2019-09-30 10:14:41 -0500260 });
akmhoque157b0a42014-05-13 00:26:37 -0500261 }
akmhoquefdbddb12014-05-02 18:35:19 -0500262}
263
264void
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400265Fib::setStrategy(const ndn::Name& name, const ndn::Name& strategy, uint32_t count)
akmhoque157b0a42014-05-13 00:26:37 -0500266{
267 ndn::nfd::ControlParameters parameters;
268 parameters
269 .setName(name)
270 .setStrategy(strategy);
271
272 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
Davide Pesaventod2610dc2025-01-03 13:20:06 -0500273 std::bind(&Fib::onSetStrategySuccess, this, _1),
274 std::bind(&Fib::onSetStrategyFailure, this, _1, parameters, count));
akmhoque157b0a42014-05-13 00:26:37 -0500275}
276
277void
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400278Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult)
akmhoque393d4ff2014-07-16 14:27:03 -0500279{
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400280 NLSR_LOG_DEBUG("Successfully set strategy choice: " << commandSuccessResult.getStrategy() <<
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600281 " for name: " << commandSuccessResult.getName());
akmhoque393d4ff2014-07-16 14:27:03 -0500282}
283
284void
Davide Pesaventod2610dc2025-01-03 13:20:06 -0500285Fib::onSetStrategyFailure(const ndn::nfd::ControlResponse&,
Junxiao Shi63bd0342016-08-17 16:57:14 +0000286 const ndn::nfd::ControlParameters& parameters,
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400287 uint32_t count)
akmhoque393d4ff2014-07-16 14:27:03 -0500288{
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400289 NLSR_LOG_DEBUG("Failed to set strategy choice: " << parameters.getStrategy() <<
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600290 " for name: " << parameters.getName());
akmhoque393d4ff2014-07-16 14:27:03 -0500291 if (count < 3) {
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600292 setStrategy(parameters.getName(), parameters.getStrategy().toUri(), count + 1);
akmhoque393d4ff2014-07-16 14:27:03 -0500293 }
294}
295
296void
awlanefc0b45a2025-05-07 15:51:02 -0500297Fib::scheduleEntryRefresh(FibEntry& entry, uint64_t routeFlags, const AfterRefreshCallback& refreshCallback)
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500298{
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700299 NLSR_LOG_DEBUG("Scheduling refresh for " << entry.name <<
300 " Seq Num: " << entry.seqNo <<
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600301 " in " << m_refreshTime << " seconds");
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500302
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700303 entry.refreshEventId = m_scheduler.schedule(ndn::time::seconds(m_refreshTime),
304 std::bind(&Fib::refreshEntry, this,
awlanefc0b45a2025-05-07 15:51:02 -0500305 entry.name, routeFlags, refreshCallback));
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500306}
307
308void
awlanefc0b45a2025-05-07 15:51:02 -0500309Fib::scheduleLoop(FibEntry& entry, uint64_t routeFlags)
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500310{
awlanefc0b45a2025-05-07 15:51:02 -0500311 scheduleEntryRefresh(entry, routeFlags, std::bind(&Fib::scheduleLoop, this, _1, _2));
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500312}
313
314void
awlanefc0b45a2025-05-07 15:51:02 -0500315Fib::refreshEntry(const ndn::Name& name, uint64_t routeFlags, AfterRefreshCallback refreshCb)
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500316{
Davide Pesaventoaf7a2112019-03-19 14:55:20 -0400317 auto it = m_table.find(name);
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500318 if (it == m_table.end()) {
319 return;
320 }
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500321 FibEntry& entry = it->second;
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700322 NLSR_LOG_DEBUG("Refreshing " << entry.name << " Seq Num: " << entry.seqNo);
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500323
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700324 entry.seqNo += 1;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500325
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700326 for (const NextHop& hop : entry.nexthopSet) {
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700327 registerPrefix(entry.name,
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -0500328 ndn::FaceUri(hop.getConnectingFaceUri()),
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500329 hop.getRouteCostAsAdjustedInteger(),
330 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
awlanefc0b45a2025-05-07 15:51:02 -0500331 routeFlags, 0);
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500332 }
333
awlanefc0b45a2025-05-07 15:51:02 -0500334 refreshCb(entry, routeFlags);
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500335}
336
337void
akmhoque674b0b12014-05-20 14:33:28 -0500338Fib::writeLog()
339{
dmcoomes5bcb39e2017-10-31 15:07:55 -0500340 NLSR_LOG_DEBUG("-------------------FIB-----------------------------");
Ashlesh Gawandee5002b32018-12-20 21:07:31 -0600341 for (const auto& entry : m_table) {
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700342 NLSR_LOG_DEBUG("Name prefix: " << entry.first);
Ashlesh Gawande7a231c02020-06-12 20:06:44 -0700343 NLSR_LOG_DEBUG("Seq No: " << entry.second.seqNo);
Ashlesh Gawande6f0f35d2021-08-21 23:52:14 -0700344 NLSR_LOG_DEBUG("Nexthop List: \n" << entry.second.nexthopSet);
akmhoque674b0b12014-05-20 14:33:28 -0500345 }
346}
akmhoquefdbddb12014-05-02 18:35:19 -0500347
Nick Gordonfad8e252016-08-11 14:21:38 -0500348} // namespace nlsr