blob: be13c44a9a2aba628bb44cea1772d7976d3d9a56 [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
Nick Gordon9fcf1232017-03-10 22:30:20 +000045class AutoPrefixPropagator;
46class Readvertise;
Alexander Afanasyev585e5a62014-08-12 11:49:31 -070047
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:
54 explicit
55 Error(const std::string& what)
56 : std::runtime_error(what)
57 {
58 }
59 };
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060
Yanbiao Licf0db022016-01-29 00:54:25 -080061public:
Davide Pesavento9f8b10e2018-08-22 08:45:37 +000062 RibManager(Rib& rib, Dispatcher& dispatcher, ndn::Face& face,
63 ndn::nfd::Controller& controller, AutoPrefixPropagator& propagator);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070064
Davide Pesaventod396b612017-02-20 22:11:50 -050065 ~RibManager() override;
Vince Lehman26b215c2014-08-17 15:00:41 -050066
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070067 void
68 registerWithNfd();
69
70 void
Eric Newberryecc45cb2016-11-08 19:57:12 +000071 enableLocalFields();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070072
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070073 void
74 setConfigFile(ConfigFile& configFile);
75
Vince Lehman76c751c2014-11-18 17:36:38 -060076 void
77 onRibUpdateSuccess(const RibUpdate& update);
Vince Lehman4387e782014-06-19 16:57:45 -050078
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070079 void
Vince Lehman76c751c2014-11-18 17:36:38 -060080 onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
81
Yanbiao Licf0db022016-01-29 00:54:25 -080082private: // initialization helpers
Vince Lehman76c751c2014-11-18 17:36:38 -060083 void
Yanbiao Licf0db022016-01-29 00:54:25 -080084 onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070085
86 void
Yanbiao Licf0db022016-01-29 00:54:25 -080087 registerTopPrefix(const Name& topPrefix);
88
89private: // ControlCommand and StatusDataset
90 void
91 registerEntry(const Name& topPrefix, const Interest& interest,
92 ControlParameters parameters,
93 const ndn::mgmt::CommandContinuation& done);
Junxiao Shia3295742014-05-16 22:40:10 -070094
95 void
Yanbiao Licf0db022016-01-29 00:54:25 -080096 unregisterEntry(const Name& topPrefix, const Interest& interest,
97 ControlParameters parameters,
98 const ndn::mgmt::CommandContinuation& done);
Yingdi Yue5224e92014-04-29 18:04:02 -070099
100 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800101 listEntries(const Name& topPrefix, const Interest& interest,
102 ndn::mgmt::StatusDatasetContext& context);
Yingdi Yue5224e92014-04-29 18:04:02 -0700103
104 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800105 setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700106
Nick Gordon9fcf1232017-03-10 22:30:20 +0000107 ndn::mgmt::Authorization
Junxiao Shi21738402016-08-19 19:48:00 +0000108 makeAuthorization(const std::string& verb) override;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700109
Yanbiao Licf0db022016-01-29 00:54:25 -0800110private: // Face monitor
Vince Lehman26b215c2014-08-17 15:00:41 -0500111 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500112 fetchActiveFaces();
113
114 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700115 onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
Vince Lehmancd613c52014-07-30 14:34:49 -0500116
Yanbiao Licf0db022016-01-29 00:54:25 -0800117 void
118 onFaceDestroyedEvent(uint64_t faceId);
119
Vince Lehman281ded72014-08-21 12:17:08 -0500120PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800121 void
122 scheduleActiveFaceFetch(const time::seconds& timeToWait);
123
124 /**
125 * @brief remove invalid faces
126 *
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700127 * @param status Face dataset
Vince Lehman26b215c2014-08-17 15:00:41 -0500128 */
129 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700130 removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
Vince Lehman26b215c2014-08-17 15:00:41 -0500131
Yanbiao Licf0db022016-01-29 00:54:25 -0800132 /**
133 * @brief response to face events
134 *
135 * @param notification
136 */
137 void
Nick Gordon9fcf1232017-03-10 22:30:20 +0000138 onNotification(const ndn::nfd::FaceEventNotification& notification);
Yanbiao Licf0db022016-01-29 00:54:25 -0800139
140private:
141 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500142 onCommandPrefixAddNextHopSuccess(const Name& prefix, const ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800143
144 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500145 onCommandPrefixAddNextHopError(const Name& name, const ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800146
147 void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000148 onEnableLocalFieldsSuccess();
Yanbiao Licf0db022016-01-29 00:54:25 -0800149
150 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500151 onEnableLocalFieldsError(const ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500152
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000153public:
154 bool wantAutoPrefixPropagator = false;
155 bool wantReadvertiseToNlsr = false;
156
Vince Lehman281ded72014-08-21 12:17:08 -0500157private:
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000158 Rib& m_rib;
159 ndn::nfd::Controller& m_nfdController;
Yanbiao Licf0db022016-01-29 00:54:25 -0800160 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700161 ndn::ValidatorConfig m_localhostValidator;
162 ndn::ValidatorConfig m_localhopValidator;
Davide Pesavento9f8b10e2018-08-22 08:45:37 +0000163 bool m_isLocalhopEnabled = false;
164 AutoPrefixPropagator& m_prefixPropagator;
Vince Lehman4387e782014-06-19 16:57:45 -0500165
Vince Lehman76c751c2014-11-18 17:36:38 -0600166private:
Yanbiao Licf0db022016-01-29 00:54:25 -0800167 static const Name LOCAL_HOST_TOP_PREFIX;
168 static const Name LOCAL_HOP_TOP_PREFIX;
Junxiao Shifde3f542016-07-10 19:54:53 +0000169 static const std::string MGMT_MODULE_NAME;
Vince Lehmancd613c52014-07-30 14:34:49 -0500170 static const Name FACES_LIST_DATASET_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500171 static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
Davide Pesaventod396b612017-02-20 22:11:50 -0500172 scheduler::ScopedEventId m_activeFaceFetchEvent;
Vince Lehman26b215c2014-08-17 15:00:41 -0500173
174 typedef std::set<uint64_t> FaceIdSet;
175 /** \brief contains FaceIds with one or more Routes in the RIB
176 */
177 FaceIdSet m_registeredFaces;
Yanbiao Licf0db022016-01-29 00:54:25 -0800178
179 std::function<void(const Name& topPrefix)> m_addTopPrefix;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700180};
181
182} // namespace rib
183} // namespace nfd
184
185#endif // NFD_RIB_RIB_MANAGER_HPP