Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 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 |
| 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/>. |
| 24 | **/ |
| 25 | |
| 26 | #ifndef NFD_RIB_RIB_MANAGER_HPP |
| 27 | #define NFD_RIB_RIB_MANAGER_HPP |
| 28 | |
| 29 | #include "rib.hpp" |
| 30 | #include "face-monitor.hpp" |
| 31 | #include "core/config-file.hpp" |
| 32 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/security/validator-config.hpp> |
| 34 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 35 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 36 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 37 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 38 | |
| 39 | namespace nfd { |
| 40 | namespace rib { |
| 41 | |
| 42 | using ndn::nfd::ControlCommand; |
| 43 | using ndn::nfd::ControlResponse; |
| 44 | using ndn::nfd::ControlParameters; |
| 45 | |
| 46 | class RibManager : noncopyable |
| 47 | { |
| 48 | public: |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 49 | class Error : public std::runtime_error |
| 50 | { |
| 51 | public: |
| 52 | explicit |
| 53 | Error(const std::string& what) |
| 54 | : std::runtime_error(what) |
| 55 | { |
| 56 | } |
| 57 | }; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 58 | |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 59 | RibManager(); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 60 | |
| 61 | void |
| 62 | registerWithNfd(); |
| 63 | |
| 64 | void |
| 65 | enableLocalControlHeader(); |
| 66 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 67 | void |
| 68 | setConfigFile(ConfigFile& configFile); |
| 69 | |
| 70 | private: |
| 71 | void |
| 72 | onConfig(const ConfigSection& configSection, |
| 73 | bool isDryRun, |
| 74 | const std::string& filename); |
| 75 | |
| 76 | void |
Junxiao Shi | a329574 | 2014-05-16 22:40:10 -0700 | [diff] [blame^] | 77 | startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest); |
| 78 | |
| 79 | void |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 80 | onLocalhopRequest(const Interest& request); |
| 81 | |
| 82 | void |
| 83 | onLocalhostRequest(const Interest& request); |
| 84 | |
| 85 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 86 | sendResponse(const Name& name, |
| 87 | const ControlResponse& response); |
| 88 | |
| 89 | void |
| 90 | sendResponse(const Name& name, |
| 91 | uint32_t code, |
| 92 | const std::string& text); |
| 93 | |
| 94 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 95 | registerEntry(const shared_ptr<const Interest>& request, |
| 96 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 97 | |
| 98 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 99 | unregisterEntry(const shared_ptr<const Interest>& request, |
| 100 | ControlParameters& parameters); |
| 101 | |
| 102 | void |
| 103 | onCommandValidated(const shared_ptr<const Interest>& request); |
| 104 | |
| 105 | void |
| 106 | onCommandValidationFailed(const shared_ptr<const Interest>& request, |
| 107 | const std::string& failureInfo); |
| 108 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 109 | |
| 110 | void |
| 111 | onCommandError(uint32_t code, const std::string& error, |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 112 | const shared_ptr<const Interest>& request, |
| 113 | const RibEntry& ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 114 | |
| 115 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 116 | onRegSuccess(const shared_ptr<const Interest>& request, |
| 117 | const ControlParameters& parameters, |
| 118 | const RibEntry& ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 119 | |
| 120 | void |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 121 | onUnRegSuccess(const shared_ptr<const Interest>& request, |
| 122 | const ControlParameters& parameters, |
| 123 | const RibEntry& ribEntry); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 124 | |
| 125 | void |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 126 | onNrdCommandPrefixAddNextHopSuccess(const Name& prefix); |
| 127 | |
| 128 | void |
| 129 | onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg); |
| 130 | |
| 131 | void |
| 132 | onAddNextHopSuccess(const Name& prefix); |
| 133 | |
| 134 | void |
| 135 | onAddNextHopError(const Name& name, const std::string& msg); |
| 136 | |
| 137 | void |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 138 | onControlHeaderSuccess(); |
| 139 | |
| 140 | void |
| 141 | onControlHeaderError(uint32_t code, const std::string& reason); |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 142 | static bool |
| 143 | extractParameters(const Name::Component& parameterComponent, |
| 144 | ControlParameters& extractedParameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 145 | |
| 146 | bool |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 147 | validateParameters(const ControlCommand& command, |
| 148 | ControlParameters& parameters); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 149 | |
| 150 | void |
| 151 | onNotification(const FaceEventNotification& notification); |
| 152 | |
| 153 | private: |
| 154 | Rib m_managedRib; |
Yingdi Yu | f4db0b5 | 2014-04-17 13:17:39 -0700 | [diff] [blame] | 155 | ndn::Face m_face; |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 156 | ndn::nfd::Controller m_nfdController; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 157 | ndn::KeyChain m_keyChain; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 158 | ndn::ValidatorConfig m_localhostValidator; |
| 159 | ndn::ValidatorConfig m_localhopValidator; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 160 | FaceMonitor m_faceMonitor; |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 161 | bool m_isLocalhopEnabled; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 162 | |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 163 | typedef function<void(RibManager*, |
| 164 | const shared_ptr<const Interest>& request, |
| 165 | ControlParameters& parameters)> VerbProcessor; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 166 | |
| 167 | typedef std::map<name::Component, VerbProcessor> VerbDispatchTable; |
| 168 | |
| 169 | typedef std::pair<name::Component, VerbProcessor> VerbAndProcessor; |
| 170 | |
| 171 | |
| 172 | const VerbDispatchTable m_verbDispatch; |
| 173 | |
| 174 | static const Name COMMAND_PREFIX; // /localhost/nrd |
| 175 | static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd |
| 176 | |
| 177 | // number of components in an invalid, but not malformed, unsigned command. |
| 178 | // (/localhost/nrd + verb + options) = 4 |
| 179 | static const size_t COMMAND_UNSIGNED_NCOMPS; |
| 180 | |
| 181 | // number of components in a valid signed Interest. |
| 182 | // 8 with signed Interest support. |
| 183 | static const size_t COMMAND_SIGNED_NCOMPS; |
| 184 | |
| 185 | static const VerbAndProcessor COMMAND_VERBS[]; |
| 186 | }; |
| 187 | |
| 188 | } // namespace rib |
| 189 | } // namespace nfd |
| 190 | |
| 191 | #endif // NFD_RIB_RIB_MANAGER_HPP |