Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [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/>. |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
| 27 | #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 28 | |
| 29 | #include "common.hpp" |
| 30 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 31 | #include "mgmt/command-validator.hpp" |
| 32 | #include "mgmt/internal-face.hpp" |
| 33 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 35 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 36 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 37 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 38 | namespace nfd { |
| 39 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 40 | using ndn::nfd::ControlCommand; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 41 | using ndn::nfd::ControlResponse; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 42 | using ndn::nfd::ControlParameters; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 43 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 44 | class InternalFace; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 45 | |
| 46 | class ManagerBase |
| 47 | { |
| 48 | public: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 50 | struct Error : public std::runtime_error |
| 51 | { |
| 52 | Error(const std::string& what) : std::runtime_error(what) {} |
| 53 | }; |
| 54 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 55 | ManagerBase(shared_ptr<InternalFace> face, |
| 56 | const std::string& privilege, |
| 57 | ndn::KeyChain& keyChain); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 58 | |
| 59 | virtual |
| 60 | ~ManagerBase(); |
| 61 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 62 | void |
| 63 | onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 64 | const std::string& error); |
| 65 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 66 | protected: |
| 67 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 68 | static bool |
| 69 | extractParameters(const Name::Component& parameterComponent, |
| 70 | ControlParameters& extractedParameters); |
| 71 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 72 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 73 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 74 | uint32_t code, |
| 75 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 76 | void |
| 77 | setResponse(ControlResponse& response, |
| 78 | uint32_t code, |
| 79 | const std::string& text, |
| 80 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 81 | |
| 82 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 83 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 84 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 85 | |
| 86 | void |
| 87 | sendResponse(const Name& name, |
| 88 | uint32_t code, |
| 89 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 90 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 91 | void |
| 92 | sendResponse(const Name& name, |
| 93 | uint32_t code, |
| 94 | const std::string& text, |
| 95 | const Block& body); |
| 96 | |
Chengyu Fan | ab205c2 | 2014-11-18 10:58:41 -0700 | [diff] [blame] | 97 | void |
| 98 | sendNack(const Name& name); |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 99 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 100 | virtual bool |
| 101 | validateParameters(const ControlCommand& command, |
| 102 | ControlParameters& parameters); |
| 103 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 104 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 105 | void |
| 106 | addInterestRule(const std::string& regex, |
| 107 | const ndn::IdentityCertificate& certificate); |
| 108 | |
| 109 | void |
| 110 | addInterestRule(const std::string& regex, |
| 111 | const Name& keyName, |
| 112 | const ndn::PublicKey& publicKey); |
| 113 | |
| 114 | void |
| 115 | validate(const Interest& interest, |
| 116 | const ndn::OnInterestValidated& onValidated, |
| 117 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 118 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 119 | protected: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 120 | shared_ptr<InternalFace> m_face; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 121 | ndn::KeyChain& m_keyChain; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 124 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 125 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 126 | uint32_t code, |
| 127 | const std::string& text) |
| 128 | { |
| 129 | response.setCode(code); |
| 130 | response.setText(text); |
| 131 | } |
| 132 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 133 | inline void |
| 134 | ManagerBase::setResponse(ControlResponse& response, |
| 135 | uint32_t code, |
| 136 | const std::string& text, |
| 137 | const Block& body) |
| 138 | { |
| 139 | setResponse(response, code, text); |
| 140 | response.setBody(body); |
| 141 | } |
| 142 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 143 | inline void |
| 144 | ManagerBase::addInterestRule(const std::string& regex, |
| 145 | const ndn::IdentityCertificate& certificate) |
| 146 | { |
| 147 | m_face->getValidator().addInterestRule(regex, certificate); |
| 148 | } |
| 149 | |
| 150 | inline void |
| 151 | ManagerBase::addInterestRule(const std::string& regex, |
| 152 | const Name& keyName, |
| 153 | const ndn::PublicKey& publicKey) |
| 154 | { |
| 155 | m_face->getValidator().addInterestRule(regex, keyName, publicKey); |
| 156 | } |
| 157 | |
| 158 | inline void |
| 159 | ManagerBase::validate(const Interest& interest, |
| 160 | const ndn::OnInterestValidated& onValidated, |
| 161 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 162 | { |
| 163 | m_face->getValidator().validate(interest, onValidated, onValidationFailed); |
| 164 | } |
| 165 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 166 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 167 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 169 | #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP |