Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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 | |
| 29 | #include "rib.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 30 | #include "core/config-file.hpp" |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 31 | #include "core/manager-base.hpp" |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 32 | #include "auto-prefix-propagator.hpp" |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 33 | #include "fib-updater.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 06d6ba6 | 2016-08-22 15:59:03 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/security/validator-config.hpp> |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 37 | #include <ndn-cxx/management/nfd-face-monitor.hpp> |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 38 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 39 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 40 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 41 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 42 | |
| 43 | namespace nfd { |
| 44 | namespace rib { |
| 45 | |
| 46 | using ndn::nfd::ControlCommand; |
| 47 | using ndn::nfd::ControlResponse; |
| 48 | using ndn::nfd::ControlParameters; |
| 49 | |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 50 | using ndn::nfd::FaceEventNotification; |
| 51 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 52 | class RibManager : public nfd::ManagerBase |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 53 | { |
| 54 | public: |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 55 | class Error : public std::runtime_error |
| 56 | { |
| 57 | public: |
| 58 | explicit |
| 59 | Error(const std::string& what) |
| 60 | : std::runtime_error(what) |
| 61 | { |
| 62 | } |
| 63 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 64 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 65 | public: |
| 66 | RibManager(Dispatcher& dispatcher, ndn::Face& face, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 67 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 68 | ~RibManager(); |
| 69 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 70 | void |
| 71 | registerWithNfd(); |
| 72 | |
| 73 | void |
| 74 | enableLocalControlHeader(); |
| 75 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 76 | void |
| 77 | setConfigFile(ConfigFile& configFile); |
| 78 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 79 | void |
| 80 | onRibUpdateSuccess(const RibUpdate& update); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 81 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 82 | void |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 83 | onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error); |
| 84 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 85 | private: // initialization helpers |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 86 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 87 | onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 88 | |
| 89 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 90 | registerTopPrefix(const Name& topPrefix); |
| 91 | |
| 92 | private: // ControlCommand and StatusDataset |
| 93 | void |
| 94 | registerEntry(const Name& topPrefix, const Interest& interest, |
| 95 | ControlParameters parameters, |
| 96 | const ndn::mgmt::CommandContinuation& done); |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame] | 97 | |
| 98 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 99 | unregisterEntry(const Name& topPrefix, const Interest& interest, |
| 100 | ControlParameters parameters, |
| 101 | const ndn::mgmt::CommandContinuation& done); |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 102 | |
| 103 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 104 | listEntries(const Name& topPrefix, const Interest& interest, |
| 105 | ndn::mgmt::StatusDatasetContext& context); |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 106 | |
| 107 | void |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 108 | setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 109 | |
Junxiao Shi | 2173840 | 2016-08-19 19:48:00 +0000 | [diff] [blame] | 110 | virtual ndn::mgmt::Authorization |
| 111 | makeAuthorization(const std::string& verb) override; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 112 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 113 | private: // Face monitor |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 114 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 115 | fetchActiveFaces(); |
| 116 | |
| 117 | void |
| 118 | fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer); |
| 119 | |
| 120 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 121 | onFetchFaceStatusTimeout(); |
| 122 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 123 | void |
| 124 | onFaceDestroyedEvent(uint64_t faceId); |
| 125 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 126 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 127 | void |
| 128 | scheduleActiveFaceFetch(const time::seconds& timeToWait); |
| 129 | |
| 130 | /** |
| 131 | * @brief remove invalid faces |
| 132 | * |
| 133 | * @param buffer Face dataset contents |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 134 | */ |
| 135 | void |
| 136 | removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer); |
| 137 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 138 | /** |
| 139 | * @brief response to face events |
| 140 | * |
| 141 | * @param notification |
| 142 | */ |
| 143 | void |
| 144 | onNotification(const FaceEventNotification& notification); |
| 145 | |
| 146 | private: |
| 147 | void |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 148 | onCommandPrefixAddNextHopSuccess(const Name& prefix, |
| 149 | const ndn::nfd::ControlParameters& result); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 150 | |
| 151 | void |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 152 | onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 153 | |
| 154 | void |
| 155 | onControlHeaderSuccess(); |
| 156 | |
| 157 | void |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 158 | onControlHeaderError(const ndn::nfd::ControlResponse& response); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 159 | |
| 160 | private: |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 161 | ndn::Face& m_face; |
Vince Lehman | c1dfdb4 | 2015-07-16 12:17:36 -0500 | [diff] [blame] | 162 | ndn::KeyChain& m_keyChain; |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 163 | ndn::nfd::Controller m_nfdController; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 164 | ndn::nfd::FaceMonitor m_faceMonitor; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 165 | ndn::ValidatorConfig m_localhostValidator; |
| 166 | ndn::ValidatorConfig m_localhopValidator; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 167 | bool m_isLocalhopEnabled; |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 168 | AutoPrefixPropagator m_prefixPropagator; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 169 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 170 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 171 | Rib m_rib; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 172 | FibUpdater m_fibUpdater; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 173 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 174 | private: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 175 | static const Name LOCAL_HOST_TOP_PREFIX; |
| 176 | static const Name LOCAL_HOP_TOP_PREFIX; |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 177 | static const std::string MGMT_MODULE_NAME; |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 178 | static const Name FACES_LIST_DATASET_PREFIX; |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 179 | static const time::seconds ACTIVE_FACE_FETCH_INTERVAL; |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 180 | scheduler::EventId m_activeFaceFetchEvent; |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 181 | |
| 182 | typedef std::set<uint64_t> FaceIdSet; |
| 183 | /** \brief contains FaceIds with one or more Routes in the RIB |
| 184 | */ |
| 185 | FaceIdSet m_registeredFaces; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 186 | |
| 187 | std::function<void(const Name& topPrefix)> m_addTopPrefix; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | } // namespace rib |
| 191 | } // namespace nfd |
| 192 | |
| 193 | #endif // NFD_RIB_RIB_MANAGER_HPP |