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