Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 4 | * 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 Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 10 | * |
| 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/>. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 25 | |
| 26 | #ifndef NFD_RIB_RIB_MANAGER_HPP |
| 27 | #define NFD_RIB_RIB_MANAGER_HPP |
| 28 | |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 29 | #include "auto-prefix-propagator.hpp" |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 30 | #include "fib-updater.hpp" |
Nick Gordon | 9fcf123 | 2017-03-10 22:30:20 +0000 | [diff] [blame] | 31 | #include "rib.hpp" |
| 32 | |
| 33 | #include "core/config-file.hpp" |
| 34 | #include "core/manager-base.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/security/validator-config.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 37 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Nick Gordon | 9fcf123 | 2017-03-10 22:30:20 +0000 | [diff] [blame] | 38 | #include <ndn-cxx/mgmt/nfd/face-event-notification.hpp> |
| 39 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
Davide Pesavento | d396b61 | 2017-02-20 22:11:50 -0500 | [diff] [blame] | 40 | #include <ndn-cxx/util/scheduler-scoped-event-id.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 41 | |
| 42 | namespace nfd { |
| 43 | namespace rib { |
| 44 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 45 | /** |
| 46 | * @brief Serve commands and datasets in NFD RIB management protocol. |
| 47 | */ |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 48 | class RibManager : public nfd::ManagerBase |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 51 | class Error : public std::runtime_error |
| 52 | { |
| 53 | public: |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 54 | using std::runtime_error::runtime_error; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 55 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 57 | RibManager(Rib& rib, ndn::Face& face, ndn::nfd::Controller& nfdController, Dispatcher& dispatcher); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 59 | /** |
| 60 | * @brief Apply localhost_security configuration. |
| 61 | */ |
| 62 | void |
| 63 | applyLocalhostConfig(const ConfigSection& section, const std::string& filename); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 64 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 65 | /** |
| 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 Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 81 | void |
| 82 | registerWithNfd(); |
| 83 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 84 | /** |
| 85 | * @brief Enable NDNLP IncomingFaceId field in order to support self-registration commands. |
| 86 | */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 87 | void |
Eric Newberry | ecc45cb | 2016-11-08 19:57:12 +0000 | [diff] [blame] | 88 | enableLocalFields(); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 90 | private: // RIB and FibUpdater actions |
| 91 | enum class RibUpdateResult |
| 92 | { |
| 93 | OK, |
| 94 | ERROR, |
| 95 | EXPIRED, |
| 96 | }; |
| 97 | |
| 98 | /** \brief Start adding a route to RIB and FIB. |
| 99 | * \param name route name |
| 100 | * \param route route parameters; may contain absolute expiration time |
| 101 | * \param expires relative expiration time; if specified, overwrites \c route.expires |
| 102 | * \param done completion callback |
| 103 | */ |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 104 | void |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 105 | beginAddRoute(const Name& name, Route route, optional<time::nanoseconds> expires, |
| 106 | const std::function<void(RibUpdateResult)>& done); |
| 107 | |
| 108 | /** \brief Start removing a route from RIB and FIB. |
| 109 | * \param name route name |
| 110 | * \param route route parameters |
| 111 | * \param done completion callback |
| 112 | */ |
| 113 | void |
| 114 | beginRemoveRoute(const Name& name, const Route& route, |
| 115 | const std::function<void(RibUpdateResult)>& done); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 116 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 117 | void |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 118 | beginRibUpdate(const RibUpdate& update, const std::function<void(RibUpdateResult)>& done); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 119 | |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 120 | private: // management Dispatcher related |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 121 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 122 | registerTopPrefix(const Name& topPrefix); |
| 123 | |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 124 | /** \brief Serve rib/register command. |
| 125 | */ |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 126 | void |
| 127 | registerEntry(const Name& topPrefix, const Interest& interest, |
| 128 | ControlParameters parameters, |
| 129 | const ndn::mgmt::CommandContinuation& done); |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame] | 130 | |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 131 | /** \brief Serve rib/unregister command. |
| 132 | */ |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame] | 133 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 134 | unregisterEntry(const Name& topPrefix, const Interest& interest, |
| 135 | ControlParameters parameters, |
| 136 | const ndn::mgmt::CommandContinuation& done); |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 137 | |
Junxiao Shi | 5200904 | 2018-09-10 12:33:56 +0000 | [diff] [blame] | 138 | /** \brief Serve rib/list dataset. |
| 139 | */ |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 140 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 141 | listEntries(const Name& topPrefix, const Interest& interest, |
| 142 | ndn::mgmt::StatusDatasetContext& context); |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 143 | |
| 144 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 145 | setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 146 | |
Nick Gordon | 9fcf123 | 2017-03-10 22:30:20 +0000 | [diff] [blame] | 147 | ndn::mgmt::Authorization |
Junxiao Shi | 2173840 | 2016-08-19 19:48:00 +0000 | [diff] [blame] | 148 | makeAuthorization(const std::string& verb) override; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 149 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 150 | private: // Face monitor |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 151 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 152 | fetchActiveFaces(); |
| 153 | |
| 154 | void |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 155 | onFetchActiveFacesFailure(uint32_t code, const std::string& reason); |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 156 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 157 | void |
| 158 | onFaceDestroyedEvent(uint64_t faceId); |
| 159 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 160 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 161 | void |
| 162 | scheduleActiveFaceFetch(const time::seconds& timeToWait); |
| 163 | |
| 164 | /** |
| 165 | * @brief remove invalid faces |
| 166 | * |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 167 | * @param status Face dataset |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 168 | */ |
| 169 | void |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 170 | removeInvalidFaces(const std::vector<ndn::nfd::FaceStatus>& activeFaces); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 171 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 172 | /** |
| 173 | * @brief response to face events |
| 174 | * |
| 175 | * @param notification |
| 176 | */ |
| 177 | void |
Nick Gordon | 9fcf123 | 2017-03-10 22:30:20 +0000 | [diff] [blame] | 178 | onNotification(const ndn::nfd::FaceEventNotification& notification); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 179 | |
| 180 | private: |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 181 | Rib& m_rib; |
| 182 | ndn::nfd::Controller& m_nfdController; |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 183 | Dispatcher& m_dispatcher; |
| 184 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 185 | ndn::nfd::FaceMonitor m_faceMonitor; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 186 | ndn::ValidatorConfig m_localhostValidator; |
| 187 | ndn::ValidatorConfig m_localhopValidator; |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 188 | bool m_isLocalhopEnabled; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 189 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 190 | private: |
Davide Pesavento | d396b61 | 2017-02-20 22:11:50 -0500 | [diff] [blame] | 191 | scheduler::ScopedEventId m_activeFaceFetchEvent; |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 192 | |
| 193 | typedef std::set<uint64_t> FaceIdSet; |
| 194 | /** \brief contains FaceIds with one or more Routes in the RIB |
| 195 | */ |
| 196 | FaceIdSet m_registeredFaces; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | } // namespace rib |
| 200 | } // namespace nfd |
| 201 | |
| 202 | #endif // NFD_RIB_RIB_MANAGER_HPP |