Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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" |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 31 | #include "rib-status-publisher.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 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 35 | #include <ndn-cxx/security/validator-config.hpp> |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/management/nfd-face-monitor.hpp> |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 37 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 38 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 39 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 40 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 41 | |
| 42 | namespace nfd { |
| 43 | namespace rib { |
| 44 | |
| 45 | using ndn::nfd::ControlCommand; |
| 46 | using ndn::nfd::ControlResponse; |
| 47 | using ndn::nfd::ControlParameters; |
| 48 | |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 49 | using ndn::nfd::FaceEventNotification; |
| 50 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 51 | class RibManager : noncopyable |
| 52 | { |
| 53 | public: |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 54 | class Error : public std::runtime_error |
| 55 | { |
| 56 | public: |
| 57 | explicit |
| 58 | Error(const std::string& what) |
| 59 | : std::runtime_error(what) |
| 60 | { |
| 61 | } |
| 62 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 63 | |
Vince Lehman | c1dfdb4 | 2015-07-16 12:17:36 -0500 | [diff] [blame] | 64 | RibManager(ndn::Face& face, ndn::KeyChain& keyChain); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 65 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 66 | ~RibManager(); |
| 67 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 68 | void |
| 69 | registerWithNfd(); |
| 70 | |
| 71 | void |
| 72 | enableLocalControlHeader(); |
| 73 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 74 | void |
| 75 | setConfigFile(ConfigFile& configFile); |
| 76 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 77 | void |
| 78 | onRibUpdateSuccess(const RibUpdate& update); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 79 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 80 | void |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 81 | onRibUpdateFailure(const RibUpdate& update, uint32_t code, const std::string& error); |
| 82 | |
| 83 | private: |
| 84 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 85 | onConfig(const ConfigSection& configSection, |
| 86 | bool isDryRun, |
| 87 | const std::string& filename); |
| 88 | |
| 89 | void |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame] | 90 | startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest); |
| 91 | |
| 92 | void |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 93 | onLocalhopRequest(const Interest& request); |
| 94 | |
| 95 | void |
| 96 | onLocalhostRequest(const Interest& request); |
| 97 | |
| 98 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 99 | sendResponse(const Name& name, |
| 100 | const ControlResponse& response); |
| 101 | |
| 102 | void |
| 103 | sendResponse(const Name& name, |
| 104 | uint32_t code, |
| 105 | const std::string& text); |
| 106 | |
| 107 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 108 | sendSuccessResponse(const shared_ptr<const Interest>& request, |
| 109 | const ControlParameters& parameters); |
| 110 | |
| 111 | void |
| 112 | sendErrorResponse(uint32_t code, const std::string& error, |
| 113 | const shared_ptr<const Interest>& request); |
| 114 | |
| 115 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 116 | registerEntry(const shared_ptr<const Interest>& request, |
| 117 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 118 | |
| 119 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 120 | unregisterEntry(const shared_ptr<const Interest>& request, |
| 121 | ControlParameters& parameters); |
| 122 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 123 | private: |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 124 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 125 | onCommandValidated(const shared_ptr<const Interest>& request); |
| 126 | |
| 127 | void |
| 128 | onCommandValidationFailed(const shared_ptr<const Interest>& request, |
| 129 | const std::string& failureInfo); |
| 130 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 131 | |
| 132 | void |
| 133 | onCommandError(uint32_t code, const std::string& error, |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 134 | const shared_ptr<const Interest>& request, |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 135 | const Route& route); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 136 | |
| 137 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 138 | onRegSuccess(const shared_ptr<const Interest>& request, |
| 139 | const ControlParameters& parameters, |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 140 | const Route& route); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 141 | |
| 142 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 143 | onUnRegSuccess(const shared_ptr<const Interest>& request, |
| 144 | const ControlParameters& parameters, |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 145 | const Route& route); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 146 | |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 147 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 148 | void |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 149 | onNrdCommandPrefixAddNextHopSuccess(const Name& prefix, |
| 150 | const ndn::nfd::ControlParameters& result); |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 151 | |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 152 | private: |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 153 | void |
| 154 | onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg); |
| 155 | |
| 156 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 157 | onControlHeaderSuccess(); |
| 158 | |
| 159 | void |
| 160 | onControlHeaderError(uint32_t code, const std::string& reason); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 161 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 162 | static bool |
| 163 | extractParameters(const Name::Component& parameterComponent, |
| 164 | ControlParameters& extractedParameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 165 | |
| 166 | bool |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 167 | validateParameters(const ControlCommand& command, |
| 168 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 169 | |
| 170 | void |
| 171 | onNotification(const FaceEventNotification& notification); |
| 172 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 173 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 174 | void |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 175 | onFaceDestroyedEvent(uint64_t faceId); |
Alexander Afanasyev | 63108c4 | 2014-07-07 19:10:47 -0700 | [diff] [blame] | 176 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 177 | private: |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 178 | void |
| 179 | listEntries(const Interest& request); |
| 180 | |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 181 | void |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 182 | scheduleActiveFaceFetch(const time::seconds& timeToWait); |
| 183 | |
| 184 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 185 | fetchActiveFaces(); |
| 186 | |
| 187 | void |
| 188 | fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer); |
| 189 | |
| 190 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 191 | onFetchFaceStatusTimeout(); |
| 192 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 193 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 194 | /** \param buffer Face dataset contents |
| 195 | */ |
| 196 | void |
| 197 | removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer); |
| 198 | |
| 199 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 200 | Rib m_managedRib; |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 201 | |
| 202 | private: |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 203 | ndn::Face& m_face; |
Vince Lehman | c1dfdb4 | 2015-07-16 12:17:36 -0500 | [diff] [blame] | 204 | ndn::KeyChain& m_keyChain; |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 205 | ndn::nfd::Controller m_nfdController; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 206 | ndn::ValidatorConfig m_localhostValidator; |
| 207 | ndn::ValidatorConfig m_localhopValidator; |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 208 | ndn::nfd::FaceMonitor m_faceMonitor; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 209 | bool m_isLocalhopEnabled; |
Yanbiao Li | d7c9636 | 2015-01-30 23:58:24 -0800 | [diff] [blame] | 210 | AutoPrefixPropagator m_prefixPropagator; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 211 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 212 | RibStatusPublisher m_ribStatusPublisher; |
| 213 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 214 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 215 | FibUpdater m_fibUpdater; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 216 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 217 | private: |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 218 | typedef function<void(RibManager*, |
| 219 | const shared_ptr<const Interest>& request, |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 220 | ControlParameters& parameters)> SignedVerbProcessor; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 221 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 222 | typedef std::map<name::Component, SignedVerbProcessor> SignedVerbDispatchTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 223 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 224 | typedef std::pair<name::Component, SignedVerbProcessor> SignedVerbAndProcessor; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 225 | |
| 226 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 227 | const SignedVerbDispatchTable m_signedVerbDispatch; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 228 | |
| 229 | static const Name COMMAND_PREFIX; // /localhost/nrd |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 230 | |
| 231 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 232 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
| 233 | |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 234 | private: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 235 | // number of components in an invalid, but not malformed, unsigned command. |
| 236 | // (/localhost/nrd + verb + options) = 4 |
| 237 | static const size_t COMMAND_UNSIGNED_NCOMPS; |
| 238 | |
| 239 | // number of components in a valid signed Interest. |
| 240 | // 8 with signed Interest support. |
| 241 | static const size_t COMMAND_SIGNED_NCOMPS; |
| 242 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 243 | static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[]; |
| 244 | |
| 245 | typedef function<void(RibManager*, const Interest&)> UnsignedVerbProcessor; |
| 246 | typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable; |
| 247 | typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor; |
| 248 | |
| 249 | const UnsignedVerbDispatchTable m_unsignedVerbDispatch; |
| 250 | static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[]; |
| 251 | |
| 252 | static const Name LIST_COMMAND_PREFIX; |
| 253 | static const size_t LIST_COMMAND_NCOMPS; |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 254 | |
| 255 | static const Name FACES_LIST_DATASET_PREFIX; |
| 256 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 257 | static const time::seconds ACTIVE_FACE_FETCH_INTERVAL; |
Junxiao Shi | 1e46be3 | 2015-01-08 20:18:05 -0700 | [diff] [blame] | 258 | scheduler::EventId m_activeFaceFetchEvent; |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 259 | |
| 260 | typedef std::set<uint64_t> FaceIdSet; |
| 261 | /** \brief contains FaceIds with one or more Routes in the RIB |
| 262 | */ |
| 263 | FaceIdSet m_registeredFaces; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | } // namespace rib |
| 267 | } // namespace nfd |
| 268 | |
| 269 | #endif // NFD_RIB_RIB_MANAGER_HPP |