Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [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 | 9bcbc7c | 2014-04-06 19:37:37 -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/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_MGMT_FACE_MANAGER_HPP |
| 27 | #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 28 | |
| 29 | #include "common.hpp" |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 30 | #include "face/local-face.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 31 | #include "mgmt/manager-base.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 32 | #include "mgmt/face-status-publisher.hpp" |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 33 | #include "mgmt/channel-status-publisher.hpp" |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 34 | #include "mgmt/notification-stream.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 36 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
| 37 | #include <ndn-cxx/management/nfd-control-response.hpp> |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 38 | |
| 39 | namespace nfd { |
| 40 | |
| 41 | const std::string FACE_MANAGER_PRIVILEGE = "faces"; |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 42 | |
Davide Pesavento | 52a18f9 | 2014-04-10 00:55:01 +0200 | [diff] [blame] | 43 | class ConfigFile; |
| 44 | class Face; |
| 45 | class FaceTable; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 46 | class LocalFace; |
Davide Pesavento | 52a18f9 | 2014-04-10 00:55:01 +0200 | [diff] [blame] | 47 | class NetworkInterfaceInfo; |
| 48 | class ProtocolFactory; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 49 | |
| 50 | class FaceManager : public ManagerBase |
| 51 | { |
| 52 | public: |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 53 | class Error : public ManagerBase::Error |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 54 | { |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 55 | public: |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 56 | Error(const std::string& what) : ManagerBase::Error(what) {} |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * \throws FaceManager::Error if localPort is an invalid port number |
| 61 | */ |
| 62 | |
| 63 | FaceManager(FaceTable& faceTable, |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 64 | shared_ptr<InternalFace> face, |
| 65 | ndn::KeyChain& keyChain); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 66 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 67 | virtual |
| 68 | ~FaceManager(); |
| 69 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 70 | /** \brief Subscribe to a face management section(s) for the config file |
| 71 | */ |
| 72 | void |
| 73 | setConfigFile(ConfigFile& configFile); |
| 74 | |
| 75 | void |
| 76 | onFaceRequest(const Interest& request); |
| 77 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 78 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 79 | void |
| 80 | listFaces(const Interest& request); |
| 81 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 82 | void |
| 83 | listChannels(const Interest& request); |
| 84 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 85 | shared_ptr<ProtocolFactory> |
| 86 | findFactory(const std::string& protocol); |
| 87 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 88 | PROTECTED_WITH_TESTS_ELSE_PRIVATE: |
| 89 | |
| 90 | void |
| 91 | onValidatedFaceRequest(const shared_ptr<const Interest>& request); |
| 92 | |
| 93 | VIRTUAL_WITH_TESTS void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 94 | createFace(const Interest& request, |
| 95 | ControlParameters& parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 96 | |
| 97 | VIRTUAL_WITH_TESTS void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 98 | destroyFace(const Interest& request, |
| 99 | ControlParameters& parameters); |
| 100 | |
| 101 | VIRTUAL_WITH_TESTS bool |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 102 | extractLocalControlParameters(const Interest& request, |
| 103 | ControlParameters& parameters, |
| 104 | ControlCommand& command, |
| 105 | shared_ptr<LocalFace>& outFace, |
| 106 | LocalControlFeature& outFeature); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 107 | |
| 108 | VIRTUAL_WITH_TESTS void |
| 109 | enableLocalControl(const Interest& request, |
| 110 | ControlParameters& parambeters); |
| 111 | |
| 112 | VIRTUAL_WITH_TESTS void |
| 113 | disableLocalControl(const Interest& request, |
| 114 | ControlParameters& parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 115 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 116 | void |
| 117 | ignoreUnsignedVerb(const Interest& request); |
| 118 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 119 | void |
Alexander Afanasyev | bbe3f0c | 2014-03-23 11:44:01 -0700 | [diff] [blame] | 120 | addCreatedFaceToForwarder(const shared_ptr<Face>& newFace); |
| 121 | |
| 122 | void |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 123 | onCreated(const Name& requestName, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 124 | ControlParameters& parameters, |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 125 | const shared_ptr<Face>& newFace); |
| 126 | |
| 127 | void |
| 128 | onConnectFailed(const Name& requestName, const std::string& reason); |
| 129 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 130 | void |
| 131 | onAddFace(shared_ptr<Face> face); |
| 132 | |
| 133 | void |
| 134 | onRemoveFace(shared_ptr<Face> face); |
| 135 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 136 | private: |
| 137 | void |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame] | 138 | onConfig(const ConfigSection& configSection, bool isDryRun, const std::string& filename); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 139 | |
| 140 | void |
| 141 | processSectionUnix(const ConfigSection& configSection, bool isDryRun); |
| 142 | |
| 143 | void |
| 144 | processSectionTcp(const ConfigSection& configSection, bool isDryRun); |
| 145 | |
| 146 | void |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 147 | processSectionUdp(const ConfigSection& configSection, |
| 148 | bool isDryRun, |
| 149 | const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 150 | |
| 151 | void |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 152 | processSectionEther(const ConfigSection& configSection, |
| 153 | bool isDryRun, |
| 154 | const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 155 | |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 156 | void |
| 157 | processSectionWebSocket(const ConfigSection& configSection, bool isDryRun); |
| 158 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 159 | /** \brief parse a config option that can be either "yes" or "no" |
| 160 | * \throw ConfigFile::Error value is neither "yes" nor "no" |
| 161 | * \return true if "yes", false if "no" |
| 162 | */ |
| 163 | bool |
| 164 | parseYesNo(const ConfigSection::const_iterator& i, |
| 165 | const std::string& optionName, |
| 166 | const std::string& sectionName); |
| 167 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 168 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 169 | typedef std::map< std::string/*protocol*/, shared_ptr<ProtocolFactory> > FactoryMap; |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 170 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 171 | FactoryMap m_factories; |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 172 | |
| 173 | private: |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 174 | FaceTable& m_faceTable; |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 175 | FaceStatusPublisher m_faceStatusPublisher; |
| 176 | ChannelStatusPublisher m_channelStatusPublisher; |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 177 | NotificationStream m_notificationStream; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 178 | |
| 179 | typedef function<void(FaceManager*, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 180 | const Interest&, |
| 181 | ControlParameters&)> SignedVerbProcessor; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 182 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 183 | typedef std::map<Name::Component, SignedVerbProcessor> SignedVerbDispatchTable; |
| 184 | typedef std::pair<Name::Component, SignedVerbProcessor> SignedVerbAndProcessor; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 185 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 186 | typedef function<void(FaceManager*, const Interest&)> UnsignedVerbProcessor; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 187 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 188 | typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable; |
| 189 | typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 190 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 191 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 192 | const SignedVerbDispatchTable m_signedVerbDispatch; |
| 193 | const UnsignedVerbDispatchTable m_unsignedVerbDispatch; |
| 194 | |
| 195 | static const Name COMMAND_PREFIX; // /localhost/nfd/faces |
| 196 | |
| 197 | // number of components in an invalid signed command (i.e. should be signed, but isn't) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 198 | // (/localhost/nfd/faces + verb + parameters) = 5 |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 199 | static const size_t COMMAND_UNSIGNED_NCOMPS; |
| 200 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 201 | // number of components in a valid signed command. |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 202 | // (see UNSIGNED_NCOMPS), 9 with signed Interest support. |
| 203 | static const size_t COMMAND_SIGNED_NCOMPS; |
| 204 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 205 | static const SignedVerbAndProcessor SIGNED_COMMAND_VERBS[]; |
| 206 | static const UnsignedVerbAndProcessor UNSIGNED_COMMAND_VERBS[]; |
| 207 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 208 | static const Name FACES_LIST_DATASET_PREFIX; |
| 209 | static const size_t FACES_LIST_DATASET_NCOMPS; |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 210 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 211 | static const Name CHANNELS_LIST_DATASET_PREFIX; |
| 212 | static const size_t CHANNELS_LIST_DATASET_NCOMPS; |
| 213 | |
| 214 | static const Name FACE_EVENTS_PREFIX; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | inline bool |
| 218 | FaceManager::parseYesNo(const ConfigSection::const_iterator& i, |
| 219 | const std::string& optionName, |
| 220 | const std::string& sectionName) |
| 221 | { |
| 222 | const std::string value = i->second.get_value<std::string>(); |
| 223 | if (value == "yes") |
| 224 | { |
| 225 | return true; |
| 226 | } |
| 227 | else if (value == "no") |
| 228 | { |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | throw ConfigFile::Error("Invalid value for option \"" + |
| 233 | optionName + "\" in \"" + |
| 234 | sectionName + "\" section"); |
| 235 | |
| 236 | } |
| 237 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 238 | inline void |
| 239 | FaceManager::ignoreUnsignedVerb(const Interest& request) |
| 240 | { |
| 241 | // do nothing |
| 242 | } |
| 243 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 244 | } // namespace nfd |
| 245 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 246 | #endif // NFD_DAEMON_MGMT_FACE_MANAGER_HPP |