blob: 653ad289c5c234bac0f2e7fd7e6c549523a6d763 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Licf0db022016-01-29 00:54:25 -08003 * Copyright (c) 2014-2016, 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"
Alexander Afanasyev03ea3eb2014-04-17 18:19:06 -070027#include "core/global-io.hpp"
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070028#include "core/logger.hpp"
Alexander Afanasyev63108c42014-07-07 19:10:47 -070029#include "core/scheduler.hpp"
Junxiao Shicbc8e942016-09-06 03:17:45 +000030#include <ndn-cxx/lp/tags.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000031#include <ndn-cxx/mgmt/nfd/face-status.hpp>
32#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070033
34namespace nfd {
35namespace rib {
36
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070037NFD_LOG_INIT("RibManager");
38
Yanbiao Licf0db022016-01-29 00:54:25 -080039const Name RibManager::LOCAL_HOST_TOP_PREFIX = "/localhost/nfd";
40const Name RibManager::LOCAL_HOP_TOP_PREFIX = "/localhop/nfd";
Junxiao Shifde3f542016-07-10 19:54:53 +000041const std::string RibManager::MGMT_MODULE_NAME = "rib";
Vince Lehmancd613c52014-07-30 14:34:49 -050042const Name RibManager::FACES_LIST_DATASET_PREFIX = "/localhost/nfd/faces/list";
Vince Lehman26b215c2014-08-17 15:00:41 -050043const time::seconds RibManager::ACTIVE_FACE_FETCH_INTERVAL = time::seconds(300);
44
Yanbiao Licf0db022016-01-29 00:54:25 -080045RibManager::RibManager(Dispatcher& dispatcher,
46 ndn::Face& face,
47 ndn::KeyChain& keyChain)
Junxiao Shifde3f542016-07-10 19:54:53 +000048 : ManagerBase(dispatcher, MGMT_MODULE_NAME)
Yanbiao Licf0db022016-01-29 00:54:25 -080049 , m_face(face)
Vince Lehmanc1dfdb42015-07-16 12:17:36 -050050 , m_keyChain(keyChain)
Junxiao Shi8e273ca2014-11-12 00:42:29 -070051 , m_nfdController(m_face, m_keyChain)
Yanbiao Licf0db022016-01-29 00:54:25 -080052 , m_faceMonitor(m_face)
Yingdi Yue5224e92014-04-29 18:04:02 -070053 , m_localhostValidator(m_face)
54 , m_localhopValidator(m_face)
Yingdi Yue5224e92014-04-29 18:04:02 -070055 , m_isLocalhopEnabled(false)
Yanbiao Licf0db022016-01-29 00:54:25 -080056 , m_prefixPropagator(m_nfdController, m_keyChain, m_rib)
57 , m_fibUpdater(m_rib, m_nfdController)
58 , m_addTopPrefix([&dispatcher] (const Name& topPrefix) {
59 dispatcher.addTopPrefix(topPrefix, false);
60 })
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070061{
Yanbiao Licf0db022016-01-29 00:54:25 -080062 registerCommandHandler<ndn::nfd::RibRegisterCommand>("register",
63 bind(&RibManager::registerEntry, this, _2, _3, _4, _5));
64 registerCommandHandler<ndn::nfd::RibUnregisterCommand>("unregister",
65 bind(&RibManager::unregisterEntry, this, _2, _3, _4, _5));
66
67 registerStatusDatasetHandler("list", bind(&RibManager::listEntries, this, _1, _2, _3));
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070068}
69
Vince Lehman26b215c2014-08-17 15:00:41 -050070RibManager::~RibManager()
71{
72 scheduler::cancel(m_activeFaceFetchEvent);
73}
74
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070075void
76RibManager::registerWithNfd()
77{
Yanbiao Licf0db022016-01-29 00:54:25 -080078 registerTopPrefix(LOCAL_HOST_TOP_PREFIX);
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070079
Junxiao Shia3295742014-05-16 22:40:10 -070080 if (m_isLocalhopEnabled) {
Yanbiao Licf0db022016-01-29 00:54:25 -080081 registerTopPrefix(LOCAL_HOP_TOP_PREFIX);
Junxiao Shia3295742014-05-16 22:40:10 -070082 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070083
Alexander Afanasyev89cf5e02014-04-17 12:08:57 -070084 NFD_LOG_INFO("Start monitoring face create/destroy events");
Junxiao Shifbf78342015-01-23 14:46:41 -070085 m_faceMonitor.onNotification.connect(bind(&RibManager::onNotification, this, _1));
Junxiao Shi15b12e72014-08-09 19:56:24 -070086 m_faceMonitor.start();
Vince Lehmancd613c52014-07-30 14:34:49 -050087
Vince Lehman26b215c2014-08-17 15:00:41 -050088 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070089}
90
91void
Eric Newberryecc45cb2016-11-08 19:57:12 +000092RibManager::enableLocalFields()
Yanbiao Licf0db022016-01-29 00:54:25 -080093{
Eric Newberryecc45cb2016-11-08 19:57:12 +000094 m_nfdController.start<ndn::nfd::FaceUpdateCommand>(
Yanbiao Licf0db022016-01-29 00:54:25 -080095 ControlParameters()
Eric Newberryecc45cb2016-11-08 19:57:12 +000096 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true),
97 bind(&RibManager::onEnableLocalFieldsSuccess, this),
98 bind(&RibManager::onEnableLocalFieldsError, this, _1));
Yanbiao Licf0db022016-01-29 00:54:25 -080099}
100
101void
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700102RibManager::setConfigFile(ConfigFile& configFile)
103{
Yingdi Yue5224e92014-04-29 18:04:02 -0700104 configFile.addSectionHandler("rib",
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700105 bind(&RibManager::onConfig, this, _1, _2, _3));
106}
107
108void
Yanbiao Licf0db022016-01-29 00:54:25 -0800109RibManager::onRibUpdateSuccess(const RibUpdate& update)
110{
111 NFD_LOG_DEBUG("RIB update succeeded for " << update);
112}
113
114void
115RibManager::onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error)
116{
117 NFD_LOG_DEBUG("RIB update failed for " << update << " (code: " << code
118 << ", error: " << error << ")");
119
120 // Since the FIB rejected the update, clean up invalid routes
121 scheduleActiveFaceFetch(time::seconds(1));
122}
123
124void
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700125RibManager::onConfig(const ConfigSection& configSection,
Yingdi Yuf4db0b52014-04-17 13:17:39 -0700126 bool isDryRun,
127 const std::string& filename)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700128{
Yanbiao Lid7c96362015-01-30 23:58:24 -0800129 bool isAutoPrefixPropagatorEnabled = 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);
141 isAutoPrefixPropagatorEnabled = true;
Vince Lehman76c751c2014-11-18 17:36:38 -0600142
143 // Avoid other actions when isDryRun == true
144 if (isDryRun) {
145 continue;
146 }
147
Yanbiao Lid7c96362015-01-30 23:58:24 -0800148 m_prefixPropagator.enable();
Vince Lehman76c751c2014-11-18 17:36:38 -0600149 }
150 else {
Spyridon Mastorakis149e02c2015-07-27 13:22:22 -0700151 BOOST_THROW_EXCEPTION(Error("Unrecognized rib property: " + item.first));
Vince Lehman76c751c2014-11-18 17:36:38 -0600152 }
153 }
154
Yanbiao Lid7c96362015-01-30 23:58:24 -0800155 if (!isAutoPrefixPropagatorEnabled) {
156 m_prefixPropagator.disable();
Vince Lehman76c751c2014-11-18 17:36:38 -0600157 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700158}
159
160void
Yanbiao Licf0db022016-01-29 00:54:25 -0800161RibManager::registerTopPrefix(const Name& topPrefix)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700162{
Yanbiao Licf0db022016-01-29 00:54:25 -0800163 // register entry to the FIB
164 m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
165 ControlParameters()
Junxiao Shifde3f542016-07-10 19:54:53 +0000166 .setName(Name(topPrefix).append(MGMT_MODULE_NAME))
Yanbiao Licf0db022016-01-29 00:54:25 -0800167 .setFaceId(0),
Junxiao Shib2600172016-07-11 08:53:53 +0000168 bind(&RibManager::onCommandPrefixAddNextHopSuccess, this, cref(topPrefix), _1),
Junxiao Shi29b41282016-08-22 03:47:02 +0000169 bind(&RibManager::onCommandPrefixAddNextHopError, this, cref(topPrefix), _1));
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700170
Yanbiao Licf0db022016-01-29 00:54:25 -0800171 // add top prefix to the dispatcher
172 m_addTopPrefix(topPrefix);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700173}
174
175void
Yanbiao Licf0db022016-01-29 00:54:25 -0800176RibManager::registerEntry(const Name& topPrefix, const Interest& interest,
177 ControlParameters parameters,
178 const ndn::mgmt::CommandContinuation& done)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700179{
Yanbiao Licf0db022016-01-29 00:54:25 -0800180 setFaceForSelfRegistration(interest, parameters);
Vince Lehman76c751c2014-11-18 17:36:38 -0600181
182 // Respond since command is valid and authorized
Yanbiao Licf0db022016-01-29 00:54:25 -0800183 done(ControlResponse(200, "Success").setBody(parameters.wireEncode()));
Alexander Afanasyevfb1c8082014-07-17 15:16:15 -0700184
Vince Lehman218be0a2015-01-15 17:25:20 -0600185 Route route;
186 route.faceId = parameters.getFaceId();
187 route.origin = parameters.getOrigin();
188 route.cost = parameters.getCost();
189 route.flags = parameters.getFlags();
Syed Obaid3313a372014-07-01 01:31:33 -0500190
Alexander Afanasyevf67cf082014-07-18 16:47:29 -0700191 if (parameters.hasExpirationPeriod() &&
192 parameters.getExpirationPeriod() != time::milliseconds::max())
Vince Lehman76c751c2014-11-18 17:36:38 -0600193 {
194 route.expires = time::steady_clock::now() + parameters.getExpirationPeriod();
Syed Obaid3313a372014-07-01 01:31:33 -0500195
Vince Lehman76c751c2014-11-18 17:36:38 -0600196 // Schedule a new event, the old one will be cancelled during rib insertion.
197 scheduler::EventId eventId = scheduler::schedule(parameters.getExpirationPeriod(),
Yanbiao Licf0db022016-01-29 00:54:25 -0800198 bind(&Rib::onRouteExpiration, &m_rib, parameters.getName(), route));
Syed Obaid3313a372014-07-01 01:31:33 -0500199
Vince Lehman76c751c2014-11-18 17:36:38 -0600200 NFD_LOG_TRACE("Scheduled unregistration at: " << route.expires <<
201 " with EventId: " << eventId);
202
203 // Set the NewEventId of this entry
204 route.setExpirationEvent(eventId);
205 }
206 else {
207 route.expires = time::steady_clock::TimePoint::max();
208 }
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700209
Vince Lehmanff8b3972015-02-20 16:51:21 -0600210 NFD_LOG_INFO("Adding route " << parameters.getName() << " nexthop=" << route.faceId
211 << " origin=" << route.origin
212 << " cost=" << route.cost);
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700213
Vince Lehman76c751c2014-11-18 17:36:38 -0600214 RibUpdate update;
215 update.setAction(RibUpdate::REGISTER)
216 .setName(parameters.getName())
217 .setRoute(route);
218
Yanbiao Licf0db022016-01-29 00:54:25 -0800219 m_rib.beginApplyUpdate(update,
Junxiao Shib2600172016-07-11 08:53:53 +0000220 bind(&RibManager::onRibUpdateSuccess, this, update),
221 bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
Vince Lehman76c751c2014-11-18 17:36:38 -0600222
Vince Lehman218be0a2015-01-15 17:25:20 -0600223 m_registeredFaces.insert(route.faceId);
Vince Lehman281ded72014-08-21 12:17:08 -0500224}
225
226void
Yanbiao Licf0db022016-01-29 00:54:25 -0800227RibManager::unregisterEntry(const Name& topPrefix, const Interest& interest,
228 ControlParameters parameters,
229 const ndn::mgmt::CommandContinuation& done)
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700230{
Yanbiao Licf0db022016-01-29 00:54:25 -0800231 setFaceForSelfRegistration(interest, parameters);
Vince Lehman76c751c2014-11-18 17:36:38 -0600232
233 // Respond since command is valid and authorized
Yanbiao Licf0db022016-01-29 00:54:25 -0800234 done(ControlResponse(200, "Success").setBody(parameters.wireEncode()));
Alexander Afanasyevfb1c8082014-07-17 15:16:15 -0700235
Vince Lehman218be0a2015-01-15 17:25:20 -0600236 Route route;
237 route.faceId = parameters.getFaceId();
238 route.origin = parameters.getOrigin();
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700239
Vince Lehmanff8b3972015-02-20 16:51:21 -0600240 NFD_LOG_INFO("Removing route " << parameters.getName() << " nexthop=" << route.faceId
241 << " origin=" << route.origin);
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700242
Vince Lehman76c751c2014-11-18 17:36:38 -0600243 RibUpdate update;
244 update.setAction(RibUpdate::UNREGISTER)
245 .setName(parameters.getName())
246 .setRoute(route);
Vince Lehman4387e782014-06-19 16:57:45 -0500247
Yanbiao Licf0db022016-01-29 00:54:25 -0800248 m_rib.beginApplyUpdate(update,
Junxiao Shib2600172016-07-11 08:53:53 +0000249 bind(&RibManager::onRibUpdateSuccess, this, update),
250 bind(&RibManager::onRibUpdateFailure, this, update, _1, _2));
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700251}
252
253void
Yanbiao Licf0db022016-01-29 00:54:25 -0800254RibManager::listEntries(const Name& topPrefix, const Interest& interest,
255 ndn::mgmt::StatusDatasetContext& context)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700256{
Yanbiao Licf0db022016-01-29 00:54:25 -0800257 for (auto&& ribTableEntry : m_rib) {
258 const auto& ribEntry = *ribTableEntry.second;
259 ndn::nfd::RibEntry record;
Vince Lehman76c751c2014-11-18 17:36:38 -0600260
Yanbiao Licf0db022016-01-29 00:54:25 -0800261 for (auto&& route : ribEntry) {
262 ndn::nfd::Route routeElement;
263 routeElement.setFaceId(route.faceId)
264 .setOrigin(route.origin)
265 .setCost(route.cost)
266 .setFlags(route.flags);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700267
Yanbiao Licf0db022016-01-29 00:54:25 -0800268 if (route.expires < time::steady_clock::TimePoint::max()) {
269 routeElement.setExpirationPeriod(time::duration_cast<time::milliseconds>(
270 route.expires - time::steady_clock::now()));
271 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700272
Yanbiao Licf0db022016-01-29 00:54:25 -0800273 record.addRoute(routeElement);
274 }
275
276 record.setName(ribEntry.getName());
277 context.append(record.wireEncode());
Vince Lehman76c751c2014-11-18 17:36:38 -0600278 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700279
Yanbiao Licf0db022016-01-29 00:54:25 -0800280 context.end();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700281}
282
283void
Yanbiao Licf0db022016-01-29 00:54:25 -0800284RibManager::setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700285{
Yanbiao Licf0db022016-01-29 00:54:25 -0800286 bool isSelfRegistration = (parameters.getFaceId() == 0);
287 if (isSelfRegistration) {
288 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
289 // NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field",
290 // but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD
291 // and is initialized synchronously with IncomingFaceId field enabled.
292 BOOST_ASSERT(incomingFaceIdTag != nullptr);
293 parameters.setFaceId(*incomingFaceIdTag);
Vince Lehman76c751c2014-11-18 17:36:38 -0600294 }
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700295}
296
Junxiao Shi21738402016-08-19 19:48:00 +0000297ndn::mgmt::Authorization
298RibManager::makeAuthorization(const std::string& verb)
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700299{
Junxiao Shi21738402016-08-19 19:48:00 +0000300 return [this] (const Name& prefix, const Interest& interest,
301 const ndn::mgmt::ControlParameters* params,
302 const ndn::mgmt::AcceptContinuation& accept,
303 const ndn::mgmt::RejectContinuation& reject) {
304 BOOST_ASSERT(params != nullptr);
305 BOOST_ASSERT(typeid(*params) == typeid(ndn::nfd::ControlParameters));
306 BOOST_ASSERT(prefix == LOCAL_HOST_TOP_PREFIX || prefix == LOCAL_HOP_TOP_PREFIX);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700307
Junxiao Shi21738402016-08-19 19:48:00 +0000308 ndn::ValidatorConfig& validator = prefix == LOCAL_HOST_TOP_PREFIX ?
309 m_localhostValidator : m_localhopValidator;
310 validator.validate(interest,
311 bind([&interest, this, accept] { extractRequester(interest, accept); }),
312 bind([reject] { reject(ndn::mgmt::RejectReply::STATUS403); }));
313 };
Vince Lehman26b215c2014-08-17 15:00:41 -0500314}
315
316void
Vince Lehmancd613c52014-07-30 14:34:49 -0500317RibManager::fetchActiveFaces()
318{
319 NFD_LOG_DEBUG("Fetching active faces");
320
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700321 m_nfdController.fetch<ndn::nfd::FaceDataset>(
322 bind(&RibManager::removeInvalidFaces, this, _1),
323 bind(&RibManager::onFetchActiveFacesFailure, this, _1, _2),
324 ndn::nfd::CommandOptions());
Vince Lehmancd613c52014-07-30 14:34:49 -0500325}
326
327void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700328RibManager::onFetchActiveFacesFailure(uint32_t code, const std::string& reason)
Vince Lehmancd613c52014-07-30 14:34:49 -0500329{
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700330 NFD_LOG_DEBUG("Face Status Dataset request failure " << code << " " << reason);
Yanbiao Licf0db022016-01-29 00:54:25 -0800331 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
332}
333
334void
335RibManager::onFaceDestroyedEvent(uint64_t faceId)
336{
337 m_rib.beginRemoveFace(faceId);
338 m_registeredFaces.erase(faceId);
339}
340
341void
342RibManager::scheduleActiveFaceFetch(const time::seconds& timeToWait)
343{
344 scheduler::cancel(m_activeFaceFetchEvent);
345
346 m_activeFaceFetchEvent = scheduler::schedule(timeToWait,
347 bind(&RibManager::fetchActiveFaces, this));
348}
349
350void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700351RibManager::removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces)
Vince Lehmancd613c52014-07-30 14:34:49 -0500352{
Vince Lehman26b215c2014-08-17 15:00:41 -0500353 NFD_LOG_DEBUG("Checking for invalid face registrations");
Vince Lehmancd613c52014-07-30 14:34:49 -0500354
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700355 FaceIdSet activeFaceIds;
356 for (const ndn::nfd::FaceStatus& item : activeFaces) {
357 activeFaceIds.insert(item.getFaceId());
Junxiao Shi78926c92015-02-28 22:56:06 -0700358 }
359
Vince Lehman26b215c2014-08-17 15:00:41 -0500360 // Look for face IDs that were registered but not active to find missed
361 // face destroyed events
Yanbiao Licf0db022016-01-29 00:54:25 -0800362 for (auto&& faceId : m_registeredFaces) {
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700363 if (activeFaceIds.count(faceId) == 0) {
Vince Lehman76c751c2014-11-18 17:36:38 -0600364 NFD_LOG_DEBUG("Removing invalid face ID: " << faceId);
365
366 scheduler::schedule(time::seconds(0),
367 bind(&RibManager::onFaceDestroyedEvent, this, faceId));
Vince Lehman26b215c2014-08-17 15:00:41 -0500368 }
Vince Lehman76c751c2014-11-18 17:36:38 -0600369 }
Vince Lehman26b215c2014-08-17 15:00:41 -0500370
371 // Reschedule the check for future clean up
372 scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL);
Vince Lehmancd613c52014-07-30 14:34:49 -0500373}
374
375void
Yanbiao Licf0db022016-01-29 00:54:25 -0800376RibManager::onNotification(const FaceEventNotification& notification)
Vince Lehmancd613c52014-07-30 14:34:49 -0500377{
Yanbiao Licf0db022016-01-29 00:54:25 -0800378 NFD_LOG_TRACE("onNotification: " << notification);
379
380 if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) {
381 NFD_LOG_DEBUG("Received notification for destroyed faceId: " << notification.getFaceId());
382
383 scheduler::schedule(time::seconds(0),
384 bind(&RibManager::onFaceDestroyedEvent, this, notification.getFaceId()));
385 }
386}
387
388void
Junxiao Shib2600172016-07-11 08:53:53 +0000389RibManager::onCommandPrefixAddNextHopSuccess(const Name& prefix,
390 const ndn::nfd::ControlParameters& result)
Yanbiao Licf0db022016-01-29 00:54:25 -0800391{
392 NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
393
394 // Routes must be inserted into the RIB so route flags can be applied
395 Route route;
396 route.faceId = result.getFaceId();
397 route.origin = ndn::nfd::ROUTE_ORIGIN_APP;
398 route.expires = time::steady_clock::TimePoint::max();
399 route.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
400
401 m_rib.insert(prefix, route);
402
403 m_registeredFaces.insert(route.faceId);
404}
405
406void
Junxiao Shi29b41282016-08-22 03:47:02 +0000407RibManager::onCommandPrefixAddNextHopError(const Name& name,
408 const ndn::nfd::ControlResponse& response)
Yanbiao Licf0db022016-01-29 00:54:25 -0800409{
Junxiao Shi29b41282016-08-22 03:47:02 +0000410 BOOST_THROW_EXCEPTION(Error("Error in setting interest filter (" + name.toUri() +
411 "): " + response.getText()));
Yanbiao Licf0db022016-01-29 00:54:25 -0800412}
413
414void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000415RibManager::onEnableLocalFieldsSuccess()
Yanbiao Licf0db022016-01-29 00:54:25 -0800416{
Eric Newberryecc45cb2016-11-08 19:57:12 +0000417 NFD_LOG_DEBUG("Local fields enabled");
Yanbiao Licf0db022016-01-29 00:54:25 -0800418}
419
420void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000421RibManager::onEnableLocalFieldsError(const ndn::nfd::ControlResponse& response)
Yanbiao Licf0db022016-01-29 00:54:25 -0800422{
Eric Newberryecc45cb2016-11-08 19:57:12 +0000423 BOOST_THROW_EXCEPTION(Error("Couldn't enable local fields (code: " +
424 to_string(response.getCode()) + ", info: " + response.getText() +
425 ")"));
Vince Lehmancd613c52014-07-30 14:34:49 -0500426}
427
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700428} // namespace rib
429} // namespace nfd