blob: 6da3ef4a8724aa6da394e22fcc044e06d023874a [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordon9fcf1232017-03-10 22:30:20 +00003 * Copyright (c) 2014-2017, 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:
62 RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070063
Davide Pesaventod396b612017-02-20 22:11:50 -050064 ~RibManager() override;
Vince Lehman26b215c2014-08-17 15:00:41 -050065
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070066 void
67 registerWithNfd();
68
69 void
Eric Newberryecc45cb2016-11-08 19:57:12 +000070 enableLocalFields();
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070071
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070072 void
73 setConfigFile(ConfigFile& configFile);
74
Vince Lehman76c751c2014-11-18 17:36:38 -060075 void
76 onRibUpdateSuccess(const RibUpdate& update);
Vince Lehman4387e782014-06-19 16:57:45 -050077
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070078 void
Vince Lehman76c751c2014-11-18 17:36:38 -060079 onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error);
80
Yanbiao Licf0db022016-01-29 00:54:25 -080081private: // initialization helpers
Vince Lehman76c751c2014-11-18 17:36:38 -060082 void
Yanbiao Licf0db022016-01-29 00:54:25 -080083 onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070084
85 void
Yanbiao Licf0db022016-01-29 00:54:25 -080086 registerTopPrefix(const Name& topPrefix);
87
88private: // ControlCommand and StatusDataset
89 void
90 registerEntry(const Name& topPrefix, const Interest& interest,
91 ControlParameters parameters,
92 const ndn::mgmt::CommandContinuation& done);
Junxiao Shia3295742014-05-16 22:40:10 -070093
94 void
Yanbiao Licf0db022016-01-29 00:54:25 -080095 unregisterEntry(const Name& topPrefix, const Interest& interest,
96 ControlParameters parameters,
97 const ndn::mgmt::CommandContinuation& done);
Yingdi Yue5224e92014-04-29 18:04:02 -070098
99 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800100 listEntries(const Name& topPrefix, const Interest& interest,
101 ndn::mgmt::StatusDatasetContext& context);
Yingdi Yue5224e92014-04-29 18:04:02 -0700102
103 void
Yanbiao Licf0db022016-01-29 00:54:25 -0800104 setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700105
Nick Gordon9fcf1232017-03-10 22:30:20 +0000106 ndn::mgmt::Authorization
Junxiao Shi21738402016-08-19 19:48:00 +0000107 makeAuthorization(const std::string& verb) override;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700108
Yanbiao Licf0db022016-01-29 00:54:25 -0800109private: // Face monitor
Vince Lehman26b215c2014-08-17 15:00:41 -0500110 void
Vince Lehmancd613c52014-07-30 14:34:49 -0500111 fetchActiveFaces();
112
113 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700114 onFetchActiveFacesFailure(uint32_t code, const std::string& reason);
Vince Lehmancd613c52014-07-30 14:34:49 -0500115
Yanbiao Licf0db022016-01-29 00:54:25 -0800116 void
117 onFaceDestroyedEvent(uint64_t faceId);
118
Vince Lehman281ded72014-08-21 12:17:08 -0500119PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800120 void
121 scheduleActiveFaceFetch(const time::seconds& timeToWait);
122
123 /**
124 * @brief remove invalid faces
125 *
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700126 * @param status Face dataset
Vince Lehman26b215c2014-08-17 15:00:41 -0500127 */
128 void
Weiwei Liu6e21cdb2016-09-29 15:16:23 -0700129 removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces);
Vince Lehman26b215c2014-08-17 15:00:41 -0500130
Yanbiao Licf0db022016-01-29 00:54:25 -0800131 /**
132 * @brief response to face events
133 *
134 * @param notification
135 */
136 void
Nick Gordon9fcf1232017-03-10 22:30:20 +0000137 onNotification(const ndn::nfd::FaceEventNotification& notification);
Yanbiao Licf0db022016-01-29 00:54:25 -0800138
139private:
140 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500141 onCommandPrefixAddNextHopSuccess(const Name& prefix, const ControlParameters& result);
Yanbiao Licf0db022016-01-29 00:54:25 -0800142
143 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500144 onCommandPrefixAddNextHopError(const Name& name, const ControlResponse& response);
Yanbiao Licf0db022016-01-29 00:54:25 -0800145
146 void
Eric Newberryecc45cb2016-11-08 19:57:12 +0000147 onEnableLocalFieldsSuccess();
Yanbiao Licf0db022016-01-29 00:54:25 -0800148
149 void
Davide Pesaventod396b612017-02-20 22:11:50 -0500150 onEnableLocalFieldsError(const ControlResponse& response);
Vince Lehman281ded72014-08-21 12:17:08 -0500151
152private:
Vince Lehman72446ec2014-07-09 10:50:02 -0500153 ndn::Face& m_face;
Vince Lehmanc1dfdb42015-07-16 12:17:36 -0500154 ndn::KeyChain& m_keyChain;
Alexander Afanasyevb3893c92014-05-15 01:49:54 -0700155 ndn::nfd::Controller m_nfdController;
Yanbiao Licf0db022016-01-29 00:54:25 -0800156 ndn::nfd::FaceMonitor m_faceMonitor;
Yingdi Yue5224e92014-04-29 18:04:02 -0700157 ndn::ValidatorConfig m_localhostValidator;
158 ndn::ValidatorConfig m_localhopValidator;
Yingdi Yue5224e92014-04-29 18:04:02 -0700159 bool m_isLocalhopEnabled;
Yanbiao Lid7c96362015-01-30 23:58:24 -0800160 AutoPrefixPropagator m_prefixPropagator;
Nick Gordon9fcf1232017-03-10 22:30:20 +0000161 unique_ptr<Readvertise> m_readvertiseNlsr;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700162
Vince Lehman76c751c2014-11-18 17:36:38 -0600163PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yanbiao Licf0db022016-01-29 00:54:25 -0800164 Rib m_rib;
Vince Lehman76c751c2014-11-18 17:36:38 -0600165 FibUpdater m_fibUpdater;
Vince Lehman4387e782014-06-19 16:57:45 -0500166
Vince Lehman76c751c2014-11-18 17:36:38 -0600167private:
Yanbiao Licf0db022016-01-29 00:54:25 -0800168 static const Name LOCAL_HOST_TOP_PREFIX;
169 static const Name LOCAL_HOP_TOP_PREFIX;
Junxiao Shifde3f542016-07-10 19:54:53 +0000170 static const std::string MGMT_MODULE_NAME;
Vince Lehmancd613c52014-07-30 14:34:49 -0500171 static const Name FACES_LIST_DATASET_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500172 static const time::seconds ACTIVE_FACE_FETCH_INTERVAL;
Davide Pesaventod396b612017-02-20 22:11:50 -0500173 scheduler::ScopedEventId m_activeFaceFetchEvent;
Nick Gordon9fcf1232017-03-10 22:30:20 +0000174 static const Name READVERTISE_NLSR_PREFIX;
Vince Lehman26b215c2014-08-17 15:00:41 -0500175
176 typedef std::set<uint64_t> FaceIdSet;
177 /** \brief contains FaceIds with one or more Routes in the RIB
178 */
179 FaceIdSet m_registeredFaces;
Yanbiao Licf0db022016-01-29 00:54:25 -0800180
181 std::function<void(const Name& topPrefix)> m_addTopPrefix;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700182};
183
184} // namespace rib
185} // namespace nfd
186
187#endif // NFD_RIB_RIB_MANAGER_HPP