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