blob: 6ef6d6b20f4401a7d3e21a384e9f192d7261be49 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento9f8b10e2018-08-22 08:45:37 +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#ifndef NFD_RIB_RIB_MANAGER_HPP
27#define NFD_RIB_RIB_MANAGER_HPP
28
Yanbiao Lid7c96362015-01-30 23:58:24 -080029#include "auto-prefix-propagator.hpp"
Vince Lehman76c751c2014-11-18 17:36:38 -060030#include "fib-updater.hpp"
Nick Gordon9fcf1232017-03-10 22:30:20 +000031#include "rib.hpp"
32
33#include "core/config-file.hpp"
34#include "core/manager-base.hpp"
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070035
Alexander Afanasyev4a771362014-04-24 21:29:33 -070036#include <ndn-cxx/security/validator-config.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000037#include <ndn-cxx/mgmt/nfd/controller.hpp>
Nick Gordon9fcf1232017-03-10 22:30:20 +000038#include <ndn-cxx/mgmt/nfd/face-event-notification.hpp>
39#include <ndn-cxx/mgmt/nfd/face-monitor.hpp>
Davide Pesaventod396b612017-02-20 22:11:50 -050040#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070041
42namespace nfd {
43namespace rib {
44
Junxiao Shif4cfed12018-08-22 23:26:29 +000045/**
46 * @brief Serve commands and datasets in NFD RIB management protocol.
47 */
Yanbiao Licf0db022016-01-29 00:54:25 -080048class RibManager : public nfd::ManagerBase
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070049{
50public:
Yingdi Yue5224e92014-04-29 18:04:02 -070051 class Error : public std::runtime_error
52 {
53 public:
Junxiao Shif4cfed12018-08-22 23:26:29 +000054 using std::runtime_error::runtime_error;
Yingdi Yue5224e92014-04-29 18:04:02 -070055 };
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070056
Junxiao Shif4cfed12018-08-22 23:26:29 +000057 RibManager(Rib& rib, ndn::Face& face, ndn::nfd::Controller& nfdController, Dispatcher& dispatcher);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070058
Junxiao Shif4cfed12018-08-22 23:26:29 +000059 /**
60 * @brief Apply localhost_security configuration.
61 */
62 void
63 applyLocalhostConfig(const ConfigSection& section, const std::string& filename);
Vince Lehman26b215c2014-08-17 15:00:41 -050064
Junxiao Shif4cfed12018-08-22 23:26:29 +000065 /**
66 * @brief Apply localhop_security configuration and allow accepting commands on
67 * /localhop/nfd/rib prefix.
68 */
69 void
70 enableLocalhop(const ConfigSection& section, const std::string& filename);
71
72 /**
73 * @brief Disallow accepting commands on /localhop/nfd/rib prefix.
74 */
75 void
76 disableLocalhop();
77
78 /**
79 * @brief Start accepting commands and dataset requests.
80 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070081 void
82 registerWithNfd();
83
Junxiao Shif4cfed12018-08-22 23:26:29 +000084 /**
85 * @brief Enable NDNLP IncomingFaceId field in order to support self-registration commands.
86 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070087 void
Eric Newberryecc45cb2016-11-08 19:57:12 +000088 enableLocalFields();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070089
Junxiao Shif4cfed12018-08-22 23:26:29 +000090PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Vince Lehman76c751c2014-11-18 17:36:38 -060091 void
92 onRibUpdateSuccess(const RibUpdate& update);
Vince Lehman4387e782014-06-19 16:57:45 -050093
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070094 void
Vince Lehman76c751c2014-11-18 17:36:38 -060095 onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
96
Yanbiao Licf0db022016-01-29 00:54:25 -080097private: // initialization helpers
Vince Lehman76c751c2014-11-18 17:36:38 -060098 void
Yanbiao Licf0db022016-01-29 00:54:25 -080099 registerTopPrefix(const Name& topPrefix);
100
101private: // ControlCommand and StatusDataset
102 void
103 registerEntry(const Name& topPrefix, const Interest& interest,
104 ControlParameters parameters,
105 const ndn::mgmt::CommandContinuation& done);
Junxiao Shia3295742014-05-16 22:40:10 -0700106
107 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800108 unregisterEntry(const Name& topPrefix, const Interest& interest,
109 ControlParameters parameters,
110 const ndn::mgmt::CommandContinuation& done);
Yingdi Yue5224e92014-04-29 18:04:02 -0700111
112 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800113 listEntries(const Name& topPrefix, const Interest& interest,
114 ndn::mgmt::StatusDatasetContext& context);
Yingdi Yue5224e92014-04-29 18:04:02 -0700115
116 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800117 setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700118
Nick Gordon9fcf1232017-03-10 22:30:20 +0000119 ndn::mgmt::Authorization
Junxiao Shi21738402016-08-19 19:48:00 +0000120 makeAuthorization(const std::string& verb) override;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700121
Yanbiao Licf0db022016-01-29 00:54:25 -0800122private: // Face monitor
Vince Lehman26b215c2014-08-17 15:00:41 -0500123 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500124 fetchActiveFaces();
125
126 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700127 onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
Vince Lehmancd613c52014-07-30 14:34:49 -0500128
Yanbiao Licf0db022016-01-29 00:54:25 -0800129 void
130 onFaceDestroyedEvent(uint64_t faceId);
131
Vince Lehman281ded72014-08-21 12:17:08 -0500132PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800133 void
134 scheduleActiveFaceFetch(const time::seconds& timeToWait);
135
136 /**
137 * @brief remove invalid faces
138 *
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700139 * @param status Face dataset
Vince Lehman26b215c2014-08-17 15:00:41 -0500140 */
141 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700142 removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
Vince Lehman26b215c2014-08-17 15:00:41 -0500143
Yanbiao Licf0db022016-01-29 00:54:25 -0800144 /**
145 * @brief response to face events
146 *
147 * @param notification
148 */
149 void
Nick Gordon9fcf1232017-03-10 22:30:20 +0000150 onNotification(const ndn::nfd::FaceEventNotification& notification);
Yanbiao Licf0db022016-01-29 00:54:25 -0800151
152private:
153 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500154 onCommandPrefixAddNextHopSuccess(const Name& prefix, const ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800155
156 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500157 onCommandPrefixAddNextHopError(const Name& name, const ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800158
159 void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000160 onEnableLocalFieldsSuccess();
Yanbiao Licf0db022016-01-29 00:54:25 -0800161
162 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500163 onEnableLocalFieldsError(const ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500164
165private:
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000166 Rib& m_rib;
167 ndn::nfd::Controller& m_nfdController;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000168 Dispatcher& m_dispatcher;
169
Yanbiao Licf0db022016-01-29 00:54:25 -0800170 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700171 ndn::ValidatorConfig m_localhostValidator;
172 ndn::ValidatorConfig m_localhopValidator;
Junxiao Shif4cfed12018-08-22 23:26:29 +0000173 bool m_isLocalhopEnabled;
Vince Lehman4387e782014-06-19 16:57:45 -0500174
Vince Lehman76c751c2014-11-18 17:36:38 -0600175private:
Davide Pesaventod396b612017-02-20 22:11:50 -0500176 scheduler::ScopedEventId m_activeFaceFetchEvent;
Vince Lehman26b215c2014-08-17 15:00:41 -0500177
178 typedef std::set<uint64_t> FaceIdSet;
179 /** \brief contains FaceIds with one or more Routes in the RIB
180 */
181 FaceIdSet m_registeredFaces;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700182};
183
184} // namespace rib
185} // namespace nfd
186
187#endif // NFD_RIB_RIB_MANAGER_HPP