Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014, 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" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/security/validator-config.hpp> |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/management/nfd-face-monitor.hpp> |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 35 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 36 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 37 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 38 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 39 | |
| 40 | namespace nfd { |
| 41 | namespace rib { |
| 42 | |
| 43 | using ndn::nfd::ControlCommand; |
| 44 | using ndn::nfd::ControlResponse; |
| 45 | using ndn::nfd::ControlParameters; |
| 46 | |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 47 | using ndn::nfd::FaceEventNotification; |
| 48 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 49 | class RibManager : noncopyable |
| 50 | { |
| 51 | public: |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 52 | class Error : public std::runtime_error |
| 53 | { |
| 54 | public: |
| 55 | explicit |
| 56 | Error(const std::string& what) |
| 57 | : std::runtime_error(what) |
| 58 | { |
| 59 | } |
| 60 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 61 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 62 | explicit |
| 63 | RibManager(ndn::Face& face); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 64 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame^] | 65 | ~RibManager(); |
| 66 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 67 | void |
| 68 | registerWithNfd(); |
| 69 | |
| 70 | void |
| 71 | enableLocalControlHeader(); |
| 72 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 73 | void |
| 74 | setConfigFile(ConfigFile& configFile); |
| 75 | |
| 76 | private: |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 77 | typedef uint32_t TransactionId; |
| 78 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 79 | void |
| 80 | onConfig(const ConfigSection& configSection, |
| 81 | bool isDryRun, |
| 82 | const std::string& filename); |
| 83 | |
| 84 | void |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame] | 85 | startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest); |
| 86 | |
| 87 | void |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 88 | onLocalhopRequest(const Interest& request); |
| 89 | |
| 90 | void |
| 91 | onLocalhostRequest(const Interest& request); |
| 92 | |
| 93 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 94 | sendResponse(const Name& name, |
| 95 | const ControlResponse& response); |
| 96 | |
| 97 | void |
| 98 | sendResponse(const Name& name, |
| 99 | uint32_t code, |
| 100 | const std::string& text); |
| 101 | |
| 102 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 103 | sendSuccessResponse(const shared_ptr<const Interest>& request, |
| 104 | const ControlParameters& parameters); |
| 105 | |
| 106 | void |
| 107 | sendErrorResponse(uint32_t code, const std::string& error, |
| 108 | const shared_ptr<const Interest>& request); |
| 109 | |
| 110 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 111 | registerEntry(const shared_ptr<const Interest>& request, |
| 112 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 113 | |
| 114 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 115 | unregisterEntry(const shared_ptr<const Interest>& request, |
| 116 | ControlParameters& parameters); |
| 117 | |
| 118 | void |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 119 | expireEntry(const shared_ptr<const Interest>& request, ControlParameters& params); |
| 120 | |
| 121 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 122 | onCommandValidated(const shared_ptr<const Interest>& request); |
| 123 | |
| 124 | void |
| 125 | onCommandValidationFailed(const shared_ptr<const Interest>& request, |
| 126 | const std::string& failureInfo); |
| 127 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 128 | |
| 129 | void |
| 130 | onCommandError(uint32_t code, const std::string& error, |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 131 | const shared_ptr<const Interest>& request, |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 132 | const FaceEntry& faceEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 133 | |
| 134 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 135 | onRegSuccess(const shared_ptr<const Interest>& request, |
| 136 | const ControlParameters& parameters, |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 137 | const FaceEntry& faceEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 138 | |
| 139 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 140 | onUnRegSuccess(const shared_ptr<const Interest>& request, |
| 141 | const ControlParameters& parameters, |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 142 | const FaceEntry& faceEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 143 | |
| 144 | void |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 145 | onNrdCommandPrefixAddNextHopSuccess(const Name& prefix); |
| 146 | |
| 147 | void |
| 148 | onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg); |
| 149 | |
| 150 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 151 | onAddNextHopSuccess(const shared_ptr<const Interest>& request, |
| 152 | const ControlParameters& parameters, |
| 153 | const TransactionId transactionId, |
| 154 | const bool shouldSendResponse); |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 155 | |
| 156 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 157 | onAddNextHopError(uint32_t code, const std::string& error, |
| 158 | const shared_ptr<const Interest>& request, |
| 159 | const TransactionId transactionId, const bool shouldSendResponse); |
| 160 | |
| 161 | void |
| 162 | onRemoveNextHopSuccess(const shared_ptr<const Interest>& request, |
| 163 | const ControlParameters& parameters, |
| 164 | const TransactionId transactionId, |
| 165 | const bool shouldSendResponse); |
| 166 | |
| 167 | void |
| 168 | onRemoveNextHopError(uint32_t code, const std::string& error, |
| 169 | const shared_ptr<const Interest>& request, |
| 170 | const TransactionId transactionId, const bool shouldSendResponse); |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 171 | |
| 172 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 173 | onControlHeaderSuccess(); |
| 174 | |
| 175 | void |
| 176 | onControlHeaderError(uint32_t code, const std::string& reason); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 177 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 178 | static bool |
| 179 | extractParameters(const Name::Component& parameterComponent, |
| 180 | ControlParameters& extractedParameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 181 | |
| 182 | bool |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 183 | validateParameters(const ControlCommand& command, |
| 184 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 185 | |
| 186 | void |
| 187 | onNotification(const FaceEventNotification& notification); |
| 188 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 189 | void |
Alexander Afanasyev | 63108c4 | 2014-07-07 19:10:47 -0700 | [diff] [blame] | 190 | processErasureAfterNotification(uint64_t faceId); |
| 191 | |
| 192 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 193 | sendUpdatesToFib(const shared_ptr<const Interest>& request, |
| 194 | const ControlParameters& parameters); |
| 195 | |
| 196 | void |
| 197 | sendUpdatesToFibAfterFaceDestroyEvent(); |
| 198 | |
| 199 | /** \brief Checks if the transaction has received all of the expected responses |
| 200 | * from the FIB. |
| 201 | * \return{ True if the transaction with the passed transactionId has applied |
| 202 | * all of its FIB updates successfully; otherwise, false } |
| 203 | */ |
| 204 | bool |
| 205 | isTransactionComplete(const TransactionId transactionId); |
| 206 | |
| 207 | void |
| 208 | invalidateTransaction(const TransactionId transactionId); |
| 209 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 210 | void |
| 211 | listEntries(const Interest& request); |
| 212 | |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 213 | void |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame^] | 214 | scheduleActiveFaceFetch(const time::seconds& timeToWait); |
| 215 | |
| 216 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 217 | fetchActiveFaces(); |
| 218 | |
| 219 | void |
| 220 | fetchSegments(const Data& data, shared_ptr<ndn::OBufferStream> buffer); |
| 221 | |
| 222 | void |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 223 | onFetchFaceStatusTimeout(); |
| 224 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 225 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame^] | 226 | /** \param buffer Face dataset contents |
| 227 | */ |
| 228 | void |
| 229 | removeInvalidFaces(shared_ptr<ndn::OBufferStream> buffer); |
| 230 | |
| 231 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 232 | Rib m_managedRib; |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 233 | |
| 234 | private: |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 235 | ndn::Face& m_face; |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 236 | ndn::nfd::Controller m_nfdController; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 237 | ndn::KeyChain m_keyChain; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 238 | ndn::ValidatorConfig m_localhostValidator; |
| 239 | ndn::ValidatorConfig m_localhopValidator; |
Alexander Afanasyev | 585e5a6 | 2014-08-12 11:49:31 -0700 | [diff] [blame] | 240 | ndn::nfd::FaceMonitor m_faceMonitor; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 241 | bool m_isLocalhopEnabled; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 242 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 243 | RibStatusPublisher m_ribStatusPublisher; |
| 244 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 245 | /** \brief The last transaction ID for FIB update response messages. |
| 246 | * Each group of FIB updates applied to the FIB is assigned an incrementing |
| 247 | * ID that is used to track the number of successfully applied updates. |
| 248 | */ |
| 249 | TransactionId m_lastTransactionId; |
| 250 | |
| 251 | /// table of FIB update transactions => count of pending FIB updates |
| 252 | typedef std::map<TransactionId, int> FibTransactionTable; |
| 253 | |
| 254 | /** \brief Table used to track the number of FIB updates that have not yet received |
| 255 | * a response from the FIB. |
| 256 | * The table maps a transaction ID to the number of updates remaining for that |
| 257 | * specific transaction. |
| 258 | */ |
| 259 | FibTransactionTable m_pendingFibTransactions; |
| 260 | |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 261 | typedef function<void(RibManager*, |
| 262 | const shared_ptr<const Interest>& request, |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 263 | ControlParameters& parameters)> SignedVerbProcessor; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 264 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 265 | typedef std::map<name::Component, SignedVerbProcessor> SignedVerbDispatchTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 266 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 267 | typedef std::pair<name::Component, SignedVerbProcessor> SignedVerbAndProcessor; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 268 | |
| 269 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 270 | const SignedVerbDispatchTable m_signedVerbDispatch; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 271 | |
| 272 | static const Name COMMAND_PREFIX; // /localhost/nrd |
| 273 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
| 274 | |
| 275 | // number of components in an invalid, but not malformed, unsigned command. |
| 276 | // (/localhost/nrd + verb + options) = 4 |
| 277 | static const size_t COMMAND_UNSIGNED_NCOMPS; |
| 278 | |
| 279 | // number of components in a valid signed Interest. |
| 280 | // 8 with signed Interest support. |
| 281 | static const size_t COMMAND_SIGNED_NCOMPS; |
| 282 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 283 | static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[]; |
| 284 | |
| 285 | typedef function<void(RibManager*, const Interest&)> UnsignedVerbProcessor; |
| 286 | typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable; |
| 287 | typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor; |
| 288 | |
| 289 | const UnsignedVerbDispatchTable m_unsignedVerbDispatch; |
| 290 | static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[]; |
| 291 | |
| 292 | static const Name LIST_COMMAND_PREFIX; |
| 293 | static const size_t LIST_COMMAND_NCOMPS; |
Vince Lehman | cd613c5 | 2014-07-30 14:34:49 -0500 | [diff] [blame] | 294 | |
| 295 | static const Name FACES_LIST_DATASET_PREFIX; |
| 296 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame^] | 297 | static const time::seconds ACTIVE_FACE_FETCH_INTERVAL; |
| 298 | EventId m_activeFaceFetchEvent; |
| 299 | |
| 300 | typedef std::set<uint64_t> FaceIdSet; |
| 301 | /** \brief contains FaceIds with one or more Routes in the RIB |
| 302 | */ |
| 303 | FaceIdSet m_registeredFaces; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | } // namespace rib |
| 307 | } // namespace nfd |
| 308 | |
| 309 | #endif // NFD_RIB_RIB_MANAGER_HPP |