hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -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 | 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/>. |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -0500 | [diff] [blame] | 24 | */ |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 25 | |
| 26 | #ifndef NFD_TOOLS_NFDC_HPP |
| 27 | #define NFD_TOOLS_NFDC_HPP |
| 28 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/face.hpp> |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame^] | 30 | #include <ndn-cxx/security/key-chain.hpp> |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -0500 | [diff] [blame] | 31 | #include <ndn-cxx/util/time.hpp> |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 32 | #include <ndn-cxx/management/nfd-controller.hpp> |
Chengyu Fan | dae2530 | 2014-10-16 11:40:11 -0600 | [diff] [blame] | 33 | #include <ndn-cxx/util/face-uri.hpp> |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 34 | |
| 35 | namespace nfdc { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 36 | |
| 37 | using namespace ndn::nfd; |
| 38 | |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 39 | class Nfdc : boost::noncopyable |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 40 | { |
| 41 | public: |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -0500 | [diff] [blame] | 42 | |
| 43 | static const ndn::time::milliseconds DEFAULT_EXPIRATION_PERIOD; |
| 44 | static const uint64_t DEFAULT_COST; |
| 45 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 46 | class Error : public std::runtime_error |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 47 | { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 48 | public: |
| 49 | explicit |
| 50 | Error(const std::string& what) |
| 51 | : std::runtime_error(what) |
| 52 | { |
| 53 | } |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 54 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 55 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 56 | explicit |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 57 | Nfdc(ndn::Face& face); |
| 58 | |
| 59 | ~Nfdc(); |
| 60 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 61 | bool |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 62 | dispatch(const std::string& cmd); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 63 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 64 | /** |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 65 | * \brief Adds a nexthop to a FIB entry |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 66 | * |
| 67 | * If the FIB entry does not exist, it is inserted automatically |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 68 | * |
| 69 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 70 | * [-c cost] name faceId|faceUri |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 71 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 72 | */ |
| 73 | void |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 74 | fibAddNextHop(); |
| 75 | |
| 76 | /** |
| 77 | * \brief Adds a nexthop to a FIB entry using faceId provided in the faceCreateResult |
| 78 | * |
| 79 | */ |
| 80 | void |
| 81 | fibAddNextHop(const ControlParameters& faceCreateResult); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 82 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 83 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 84 | * \brief Removes a nexthop from an existing FIB entry |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 85 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 86 | * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 87 | * |
| 88 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 89 | * name faceId |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 90 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 91 | */ |
| 92 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 93 | fibRemoveNextHop(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 94 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 95 | /** |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 96 | * \brief Registers name to the given faceId or faceUri |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 97 | * |
| 98 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 99 | * [-I] [-C] [-c cost] name faceId|faceUri |
| 100 | */ |
| 101 | void |
| 102 | ribRegisterPrefix(); |
| 103 | |
| 104 | /** |
| 105 | * \brief Registers name to the faceId provided in faceCreateResult |
| 106 | * |
| 107 | */ |
| 108 | void |
| 109 | ribRegisterPrefix(const ControlParameters& faceCreateResult); |
| 110 | |
| 111 | /** |
| 112 | * \brief Unregisters name from the given faceId |
| 113 | * |
| 114 | * cmd format: |
| 115 | * name faceId |
| 116 | */ |
| 117 | void |
| 118 | ribUnregisterPrefix(); |
| 119 | |
| 120 | /** |
| 121 | * \brief Creates new face |
| 122 | * |
| 123 | * This command allows creation of UDP unicast and TCP faces only |
| 124 | * |
| 125 | * cmd format: |
| 126 | * uri |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 127 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 128 | */ |
| 129 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 130 | faceCreate(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 131 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 132 | /** |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 133 | * \brief Destroys face |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 134 | * |
| 135 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 136 | * faceId|faceUri |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 137 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 138 | */ |
| 139 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 140 | faceDestroy(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 141 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 142 | /** |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 143 | * \brief Destroys face based on faceId provided in faceCreateResult |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 144 | * |
| 145 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 146 | * faceId|faceUri |
| 147 | * |
| 148 | */ |
| 149 | void |
| 150 | faceDestroy(const ControlParameters& faceCreateResult); |
| 151 | |
| 152 | /** |
| 153 | * \brief Sets the strategy for a namespace |
| 154 | * |
| 155 | * cmd format: |
| 156 | * name strategy |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 157 | * |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 158 | */ |
| 159 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 160 | strategyChoiceSet(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 161 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 162 | /** |
| 163 | * \brief Unset the strategy for a namespace |
| 164 | * |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 165 | * cmd format: |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 166 | * name strategy |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 167 | * |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 168 | */ |
| 169 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 170 | strategyChoiceUnset(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 171 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 172 | private: |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 173 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 174 | void |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 175 | onSuccess(const ControlParameters& commandSuccessResult, |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 176 | const std::string& message); |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 177 | |
| 178 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 179 | onError(uint32_t code, const std::string& error, const std::string& message); |
| 180 | |
Chengyu Fan | dae2530 | 2014-10-16 11:40:11 -0600 | [diff] [blame] | 181 | void |
| 182 | onCanonizeFailure(const std::string& reason); |
| 183 | |
| 184 | void |
| 185 | startFaceCreate(const ndn::util::FaceUri& canonicalUri); |
| 186 | |
| 187 | void |
| 188 | startFaceDestroy(const ndn::util::FaceUri& canonicalUri); |
| 189 | |
| 190 | void |
| 191 | startFibAddNextHop(const ndn::util::FaceUri& canonicalUri); |
| 192 | |
| 193 | void |
| 194 | startRibRegisterPrefix(const ndn::util::FaceUri& canonicalUri); |
| 195 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 196 | public: |
| 197 | const char* m_programName; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 198 | |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 199 | // command parameters without leading 'cmd' component |
Junxiao Shi | 2229503 | 2014-04-29 22:57:40 -0700 | [diff] [blame] | 200 | const char* const* m_commandLineArguments; |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 201 | int m_nOptions; |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 202 | uint64_t m_flags; |
| 203 | uint64_t m_cost; |
| 204 | uint64_t m_faceId; |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -0500 | [diff] [blame] | 205 | uint64_t m_origin; |
| 206 | ndn::time::milliseconds m_expires; |
Obaid | dca5079 | 2014-04-24 18:38:40 -0500 | [diff] [blame] | 207 | std::string m_name; |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 208 | |
Syed Obaid | 4ae0ce3 | 2014-06-17 13:59:20 -0500 | [diff] [blame] | 209 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 210 | private: |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame^] | 211 | ndn::KeyChain m_keyChain; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 212 | Controller m_controller; |
Chengyu Fan | dae2530 | 2014-10-16 11:40:11 -0600 | [diff] [blame] | 213 | boost::asio::io_service& m_ioService; |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 214 | }; |
| 215 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 216 | } // namespace nfdc |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 217 | |
| 218 | #endif // NFD_TOOLS_NFDC_HPP |