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