blob: c45aededcf2f91a32ebe174c4b0542f9dd375555 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi75306352018-02-01 21:59:44 +00002/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
Junxiao Shi1e46be32015-01-08 20:18:05 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince12e49462014-06-09 13:29:32 -050024 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070025
26#include "rib-manager.hpp"
Nick Gordon9fcf1232017-03-10 22:30:20 +000027
Junxiao Shi75306352018-02-01 21:59:44 +000028#include "core/fib-max-depth.hpp"
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070029#include "core/logger.hpp"
Alexander Afanasyev63108c42014-07-07 19:10:47 -070030#include "core/scheduler.hpp"
Nick Gordon9fcf1232017-03-10 22:30:20 +000031
Junxiao Shicbc8e942016-09-06 03:17:45 +000032#include <ndn-cxx/lp/tags.hpp>
Nick Gordon9fcf1232017-03-10 22:30:20 +000033#include <ndn-cxx/mgmt/nfd/control-command.hpp>
Nick Gordon9fcf1232017-03-10 22:30:20 +000034#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
Junxiao Shi3f21e582017-05-29 15:26:32 +000035#include <ndn-cxx/mgmt/nfd/control-response.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000036#include <ndn-cxx/mgmt/nfd/face-status.hpp>
37#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070038
39namespace nfd {
40namespace rib {
41
Davide Pesaventoa3148082018-04-12 18:21:54 -040042NFD_LOG_INIT(RibManager);
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070043
Yanbiao Licf0db022016-01-29 00:54:25 -080044const Name RibManager::LOCAL_HOST_TOP_PREFIX = "/localhost/nfd";
45const Name RibManager::LOCAL_HOP_TOP_PREFIX = "/localhop/nfd";
Junxiao Shifde3f542016-07-10 19:54:53 +000046const std::string RibManager::MGMT_MODULE_NAME = "rib";
Vince Lehmancd613c52014-07-30 14:34:49 -050047const Name RibManager::FACES_LIST_DATASET_PREFIX = "/localhost/nfd/faces/list";
Vince Lehman26b215c2014-08-17 15:00:41 -050048const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
49
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000050RibManager::RibManager(Rib& rib,
51 Dispatcher& dispatcher,
Yanbiao Licf0db022016-01-29 00:54:25 -080052 ndn::Face& face,
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000053 ndn::nfd::Controller& controller,
54 AutoPrefixPropagator& propagator)
Junxiao Shifde3f542016-07-10 19:54:53 +000055 : ManagerBase(dispatcher, MGMT_MODULE_NAME)
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000056 , m_rib(rib)
57 , m_nfdController(controller)
58 , m_faceMonitor(face)
59 , m_localhostValidator(face)
60 , m_localhopValidator(face)
61 , m_prefixPropagator(propagator)
Yanbiao Licf0db022016-01-29 00:54:25 -080062 , m_addTopPrefix([&dispatcher] (const Name& topPrefix) {
63 dispatcher.addTopPrefix(topPrefix, false);
64 })
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070065{
Yanbiao Licf0db022016-01-29 00:54:25 -080066 registerCommandHandler<ndn::nfd::RibRegisterCommand>("register",
67 bind(&RibManager::registerEntry, this, _2, _3, _4, _5));
68 registerCommandHandler<ndn::nfd::RibUnregisterCommand>("unregister",
69 bind(&RibManager::unregisterEntry, this, _2, _3, _4, _5));
70
71 registerStatusDatasetHandler("list", bind(&RibManager::listEntries, this, _1, _2, _3));
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070072}
73
Davide Pesaventod396b612017-02-20 22:11:50 -050074RibManager::~RibManager() = default;
Vince Lehman26b215c2014-08-17 15:00:41 -050075
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070076void
77RibManager::registerWithNfd()
78{
Yanbiao Licf0db022016-01-29 00:54:25 -080079 registerTopPrefix(LOCAL_HOST_TOP_PREFIX);
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070080
Junxiao Shia3295742014-05-16 22:40:10 -070081 if (m_isLocalhopEnabled) {
Yanbiao Licf0db022016-01-29 00:54:25 -080082 registerTopPrefix(LOCAL_HOP_TOP_PREFIX);
Junxiao Shia3295742014-05-16 22:40:10 -070083 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070084
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070085 NFD_LOG_INFO("Start monitoring face create/destroy events");
Junxiao Shifbf78342015-01-23 14:46:41 -070086 m_faceMonitor.onNotification.connect(bind(&RibManager::onNotification, this, _1));
Junxiao Shi15b12e72014-08-09 19:56:24 -070087 m_faceMonitor.start();
Vince Lehmancd613c52014-07-30 14:34:49 -050088
Vince Lehman26b215c2014-08-17 15:00:41 -050089 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070090}
91
92void
Eric Newberryecc45cb2016-11-08 19:57:12 +000093RibManager::enableLocalFields()
Yanbiao Licf0db022016-01-29 00:54:25 -080094{
Eric Newberryecc45cb2016-11-08 19:57:12 +000095 m_nfdController.start<ndn::nfd::FaceUpdateCommand>(
Yanbiao Licf0db022016-01-29 00:54:25 -080096 ControlParameters()
Eric Newberryecc45cb2016-11-08 19:57:12 +000097 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true),
98 bind(&RibManager::onEnableLocalFieldsSuccess, this),
99 bind(&RibManager::onEnableLocalFieldsError, this, _1));
Yanbiao Licf0db022016-01-29 00:54:25 -0800100}
101
102void
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700103RibManager::setConfigFile(ConfigFile& configFile)
104{
Yingdi Yue5224e92014-04-29 18:04:02 -0700105 configFile.addSectionHandler("rib",
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700106 bind(&RibManager::onConfig, this, _1, _2, _3));
107}
108
109void
Yanbiao Licf0db022016-01-29 00:54:25 -0800110RibManager::onRibUpdateSuccess(const RibUpdate& update)
111{
112 NFD_LOG_DEBUG("RIB update succeeded for " << update);
113}
114
115void
116RibManager::onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error)
117{
118 NFD_LOG_DEBUG("RIB update failed for " << update << " (code: " << code
119 << ", error: " << error << ")");
120
121 // Since the FIB rejected the update, clean up invalid routes
122 scheduleActiveFaceFetch(time::seconds(1));
123}
124
125void
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000126RibManager::onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700127{
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000128 wantAutoPrefixPropagator = false;
129 wantReadvertiseToNlsr = false;
Yanbiao Lib9d439d2014-12-11 16:12:32 -0800130
Vince Lehman76c751c2014-11-18 17:36:38 -0600131 for (const auto& item : configSection) {
132 if (item.first == "localhost_security") {
133 m_localhostValidator.load(item.second, filename);
Yingdi Yue5224e92014-04-29 18:04:02 -0700134 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600135 else if (item.first == "localhop_security") {
136 m_localhopValidator.load(item.second, filename);
137 m_isLocalhopEnabled = true;
Yanbiao Lib9d439d2014-12-11 16:12:32 -0800138 }
Yanbiao Lid7c96362015-01-30 23:58:24 -0800139 else if (item.first == "auto_prefix_propagate") {
140 m_prefixPropagator.loadConfig(item.second);
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000141 wantAutoPrefixPropagator = true;
Vince Lehman76c751c2014-11-18 17:36:38 -0600142 }
Nick Gordon9fcf1232017-03-10 22:30:20 +0000143 else if (item.first == "readvertise_nlsr") {
144 wantReadvertiseToNlsr = ConfigFile::parseYesNo(item, "rib.readvertise_nlsr");
145 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600146 else {
Spyridon Mastorakis149e02c2015-07-27 13:22:22 -0700147 BOOST_THROW_EXCEPTION(Error("Unrecognized rib property: " + item.first));
Vince Lehman76c751c2014-11-18 17:36:38 -0600148 }
149 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700150}
151
152void
Yanbiao Licf0db022016-01-29 00:54:25 -0800153RibManager::registerTopPrefix(const Name& topPrefix)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700154{
Yanbiao Licf0db022016-01-29 00:54:25 -0800155 // register entry to the FIB
156 m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400157 ControlParameters()
158 .setName(Name(topPrefix).append(MGMT_MODULE_NAME))
159 .setFaceId(0),
160 [=] (const auto& res) { this->onCommandPrefixAddNextHopSuccess(topPrefix, res); },
161 [=] (const auto& res) { this->onCommandPrefixAddNextHopError(topPrefix, res); });
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700162
Yanbiao Licf0db022016-01-29 00:54:25 -0800163 // add top prefix to the dispatcher
164 m_addTopPrefix(topPrefix);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700165}
166
167void
Yanbiao Licf0db022016-01-29 00:54:25 -0800168RibManager::registerEntry(const Name& topPrefix, const Interest& interest,
169 ControlParameters parameters,
170 const ndn::mgmt::CommandContinuation& done)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700171{
Junxiao Shi75306352018-02-01 21:59:44 +0000172 if (parameters.getName().size() > FIB_MAX_DEPTH) {
173 done(ControlResponse(414, "Route prefix cannot exceed " + ndn::to_string(FIB_MAX_DEPTH) +
174 " components"));
175 return;
176 }
177
Yanbiao Licf0db022016-01-29 00:54:25 -0800178 setFaceForSelfRegistration(interest, parameters);
Vince Lehman76c751c2014-11-18 17:36:38 -0600179
180 // Respond since command is valid and authorized
Yanbiao Licf0db022016-01-29 00:54:25 -0800181 done(ControlResponse(200, "Success").setBody(parameters.wireEncode()));
Alexander Afanasyevfb1c8082014-07-17 15:16:15 -0700182
Vince Lehman218be0a2015-01-15 17:25:20 -0600183 Route route;
184 route.faceId = parameters.getFaceId();
185 route.origin = parameters.getOrigin();
186 route.cost = parameters.getCost();
187 route.flags = parameters.getFlags();
Syed Obaid3313a372014-07-01 01:31:33 -0500188
Alexander Afanasyevf67cf082014-07-18 16:47:29 -0700189 if (parameters.hasExpirationPeriod() &&
Nick Gordon9fcf1232017-03-10 22:30:20 +0000190 parameters.getExpirationPeriod() != time::milliseconds::max()) {
Vince Lehman76c751c2014-11-18 17:36:38 -0600191 route.expires = time::steady_clock::now() + parameters.getExpirationPeriod();
Syed Obaid3313a372014-07-01 01:31:33 -0500192
Vince Lehman76c751c2014-11-18 17:36:38 -0600193 // Schedule a new event, the old one will be cancelled during rib insertion.
194 scheduler::EventId eventId = scheduler::schedule(parameters.getExpirationPeriod(),
Yanbiao Licf0db022016-01-29 00:54:25 -0800195 bind(&Rib::onRouteExpiration, &m_rib, parameters.getName(), route));
Syed Obaid3313a372014-07-01 01:31:33 -0500196
Junxiao Shi3f21e582017-05-29 15:26:32 +0000197 NFD_LOG_TRACE("Scheduled unregistration at: " << *route.expires <<
Vince Lehman76c751c2014-11-18 17:36:38 -0600198 " with EventId: " << eventId);
199
200 // Set the NewEventId of this entry
201 route.setExpirationEvent(eventId);
202 }
203 else {
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400204 route.expires = nullopt;
Vince Lehman76c751c2014-11-18 17:36:38 -0600205 }
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700206
Vince Lehmanff8b3972015-02-20 16:51:21 -0600207 NFD_LOG_INFO("Adding route " << parameters.getName() << " nexthop=" << route.faceId
208 << " origin=" << route.origin
209 << " cost=" << route.cost);
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700210
Vince Lehman76c751c2014-11-18 17:36:38 -0600211 RibUpdate update;
212 update.setAction(RibUpdate::REGISTER)
213 .setName(parameters.getName())
214 .setRoute(route);
215
Yanbiao Licf0db022016-01-29 00:54:25 -0800216 m_rib.beginApplyUpdate(update,
Junxiao Shib2600172016-07-11 08:53:53 +0000217 bind(&RibManager::onRibUpdateSuccess, this, update),
218 bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
Vince Lehman76c751c2014-11-18 17:36:38 -0600219
Vince Lehman218be0a2015-01-15 17:25:20 -0600220 m_registeredFaces.insert(route.faceId);
Vince Lehman281ded72014-08-21 12:17:08 -0500221}
222
223void
Yanbiao Licf0db022016-01-29 00:54:25 -0800224RibManager::unregisterEntry(const Name& topPrefix, const Interest& interest,
225 ControlParameters parameters,
226 const ndn::mgmt::CommandContinuation& done)
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700227{
Yanbiao Licf0db022016-01-29 00:54:25 -0800228 setFaceForSelfRegistration(interest, parameters);
Vince Lehman76c751c2014-11-18 17:36:38 -0600229
230 // Respond since command is valid and authorized
Yanbiao Licf0db022016-01-29 00:54:25 -0800231 done(ControlResponse(200, "Success").setBody(parameters.wireEncode()));
Alexander Afanasyevfb1c8082014-07-17 15:16:15 -0700232
Vince Lehman218be0a2015-01-15 17:25:20 -0600233 Route route;
234 route.faceId = parameters.getFaceId();
235 route.origin = parameters.getOrigin();
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700236
Vince Lehmanff8b3972015-02-20 16:51:21 -0600237 NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId
238 << " origin=" << route.origin);
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700239
Vince Lehman76c751c2014-11-18 17:36:38 -0600240 RibUpdate update;
241 update.setAction(RibUpdate::UNREGISTER)
242 .setName(parameters.getName())
243 .setRoute(route);
Vince Lehman4387e782014-06-19 16:57:45 -0500244
Yanbiao Licf0db022016-01-29 00:54:25 -0800245 m_rib.beginApplyUpdate(update,
Junxiao Shib2600172016-07-11 08:53:53 +0000246 bind(&RibManager::onRibUpdateSuccess, this, update),
247 bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700248}
249
250void
Yanbiao Licf0db022016-01-29 00:54:25 -0800251RibManager::listEntries(const Name& topPrefix, const Interest& interest,
252 ndn::mgmt::StatusDatasetContext& context)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700253{
Junxiao Shi3f21e582017-05-29 15:26:32 +0000254 auto now = time::steady_clock::now();
255 for (const auto& kv : m_rib) {
256 const RibEntry& entry = *kv.second;
257 ndn::nfd::RibEntry item;
258 item.setName(entry.getName());
259 for (const Route& route : entry.getRoutes()) {
260 ndn::nfd::Route r;
261 r.setFaceId(route.faceId);
262 r.setOrigin(route.origin);
263 r.setCost(route.cost);
264 r.setFlags(route.flags);
265 if (route.expires) {
266 r.setExpirationPeriod(time::duration_cast<time::milliseconds>(*route.expires - now));
267 }
268 item.addRoute(r);
269 }
270 context.append(item.wireEncode());
Vince Lehman76c751c2014-11-18 17:36:38 -0600271 }
Yanbiao Licf0db022016-01-29 00:54:25 -0800272 context.end();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700273}
274
275void
Yanbiao Licf0db022016-01-29 00:54:25 -0800276RibManager::setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700277{
Yanbiao Licf0db022016-01-29 00:54:25 -0800278 bool isSelfRegistration = (parameters.getFaceId() == 0);
279 if (isSelfRegistration) {
280 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
281 // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field",
282 // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD
283 // and is initialized synchronously with IncomingFaceId field enabled.
284 BOOST_ASSERT(incomingFaceIdTag != nullptr);
285 parameters.setFaceId(*incomingFaceIdTag);
Vince Lehman76c751c2014-11-18 17:36:38 -0600286 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700287}
288
Junxiao Shi21738402016-08-19 19:48:00 +0000289ndn::mgmt::Authorization
290RibManager::makeAuthorization(const std::string& verb)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700291{
Junxiao Shi21738402016-08-19 19:48:00 +0000292 return [this] (const Name& prefix, const Interest& interest,
293 const ndn::mgmt::ControlParameters* params,
294 const ndn::mgmt::AcceptContinuation& accept,
295 const ndn::mgmt::RejectContinuation& reject) {
296 BOOST_ASSERT(params != nullptr);
297 BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
298 BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700299
Junxiao Shi21738402016-08-19 19:48:00 +0000300 ndn::ValidatorConfig& validator = prefix == LOCAL_HOST_TOP_PREFIX ?
301 m_localhostValidator : m_localhopValidator;
302 validator.validate(interest,
303 bind([&interest, this, accept] { extractRequester(interest, accept); }),
304 bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
305 };
Vince Lehman26b215c2014-08-17 15:00:41 -0500306}
307
308void
Vince Lehmancd613c52014-07-30 14:34:49 -0500309RibManager::fetchActiveFaces()
310{
311 NFD_LOG_DEBUG("Fetching active faces");
312
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700313 m_nfdController.fetch<ndn::nfd::FaceDataset>(
314 bind(&RibManager::removeInvalidFaces, this, _1),
315 bind(&RibManager::onFetchActiveFacesFailure, this, _1, _2),
316 ndn::nfd::CommandOptions());
Vince Lehmancd613c52014-07-30 14:34:49 -0500317}
318
319void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700320RibManager::onFetchActiveFacesFailure(uint32_t code, const std::string& reason)
Vince Lehmancd613c52014-07-30 14:34:49 -0500321{
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700322 NFD_LOG_DEBUG("Face Status Dataset request failure " << code << " " << reason);
Yanbiao Licf0db022016-01-29 00:54:25 -0800323 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
324}
325
326void
327RibManager::onFaceDestroyedEvent(uint64_t faceId)
328{
329 m_rib.beginRemoveFace(faceId);
330 m_registeredFaces.erase(faceId);
331}
332
333void
334RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
335{
Davide Pesaventod396b612017-02-20 22:11:50 -0500336 m_activeFaceFetchEvent = scheduler::schedule(timeToWait, [this] { this->fetchActiveFaces(); });
Yanbiao Licf0db022016-01-29 00:54:25 -0800337}
338
339void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700340RibManager::removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces)
Vince Lehmancd613c52014-07-30 14:34:49 -0500341{
Vince Lehman26b215c2014-08-17 15:00:41 -0500342 NFD_LOG_DEBUG("Checking for invalid face registrations");
Vince Lehmancd613c52014-07-30 14:34:49 -0500343
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700344 FaceIdSet activeFaceIds;
Davide Pesaventod396b612017-02-20 22:11:50 -0500345 for (const auto& faceStatus : activeFaces) {
346 activeFaceIds.insert(faceStatus.getFaceId());
Junxiao Shi78926c92015-02-28 22:56:06 -0700347 }
348
Vince Lehman26b215c2014-08-17 15:00:41 -0500349 // Look for face IDs that were registered but not active to find missed
350 // face destroyed events
Davide Pesaventod396b612017-02-20 22:11:50 -0500351 for (auto faceId : m_registeredFaces) {
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700352 if (activeFaceIds.count(faceId) == 0) {
Vince Lehman76c751c2014-11-18 17:36:38 -0600353 NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
Davide Pesaventod396b612017-02-20 22:11:50 -0500354 scheduler::schedule(time::seconds(0), [this, faceId] { this->onFaceDestroyedEvent(faceId); });
Vince Lehman26b215c2014-08-17 15:00:41 -0500355 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600356 }
Vince Lehman26b215c2014-08-17 15:00:41 -0500357
358 // Reschedule the check for future clean up
359 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
Vince Lehmancd613c52014-07-30 14:34:49 -0500360}
361
362void
Davide Pesaventod396b612017-02-20 22:11:50 -0500363RibManager::onNotification(const ndn::nfd::FaceEventNotification& notification)
Vince Lehmancd613c52014-07-30 14:34:49 -0500364{
Yanbiao Licf0db022016-01-29 00:54:25 -0800365 NFD_LOG_TRACE("onNotification: " << notification);
366
367 if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) {
368 NFD_LOG_DEBUG("Received notification for destroyed faceId: " << notification.getFaceId());
369
370 scheduler::schedule(time::seconds(0),
371 bind(&RibManager::onFaceDestroyedEvent, this, notification.getFaceId()));
372 }
373}
374
375void
Junxiao Shib2600172016-07-11 08:53:53 +0000376RibManager::onCommandPrefixAddNextHopSuccess(const Name& prefix,
377 const ndn::nfd::ControlParameters& result)
Yanbiao Licf0db022016-01-29 00:54:25 -0800378{
379 NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
380
381 // Routes must be inserted into the RIB so route flags can be applied
382 Route route;
383 route.faceId = result.getFaceId();
384 route.origin = ndn::nfd::ROUTE_ORIGIN_APP;
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400385 route.expires = nullopt;
Yanbiao Licf0db022016-01-29 00:54:25 -0800386 route.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
387
388 m_rib.insert(prefix, route);
389
390 m_registeredFaces.insert(route.faceId);
391}
392
393void
Junxiao Shi29b41282016-08-22 03:47:02 +0000394RibManager::onCommandPrefixAddNextHopError(const Name& name,
395 const ndn::nfd::ControlResponse& response)
Yanbiao Licf0db022016-01-29 00:54:25 -0800396{
Junxiao Shi29b41282016-08-22 03:47:02 +0000397 BOOST_THROW_EXCEPTION(Error("Error in setting interest filter (" + name.toUri() +
398 "): " + response.getText()));
Yanbiao Licf0db022016-01-29 00:54:25 -0800399}
400
401void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000402RibManager::onEnableLocalFieldsSuccess()
Yanbiao Licf0db022016-01-29 00:54:25 -0800403{
Eric Newberryecc45cb2016-11-08 19:57:12 +0000404 NFD_LOG_DEBUG("Local fields enabled");
Yanbiao Licf0db022016-01-29 00:54:25 -0800405}
406
407void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000408RibManager::onEnableLocalFieldsError(const ndn::nfd::ControlResponse& response)
Yanbiao Licf0db022016-01-29 00:54:25 -0800409{
Eric Newberryecc45cb2016-11-08 19:57:12 +0000410 BOOST_THROW_EXCEPTION(Error("Couldn't enable local fields (code: " +
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400411 to_string(response.getCode()) + ", info: " + response.getText() + ")"));
Vince Lehmancd613c52014-07-30 14:34:49 -0500412}
413
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700414} // namespace rib
415} // namespace nfd