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 |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_TOOLS_NFDC_HPP |
| 26 | #define NFD_TOOLS_NFDC_HPP |
| 27 | |
| 28 | #include <ndn-cpp-dev/face.hpp> |
| 29 | #include <ndn-cpp-dev/management/controller.hpp> |
| 30 | #include <ndn-cpp-dev/management/nfd-controller.hpp> |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 31 | #include <vector> |
| 32 | |
| 33 | namespace nfdc { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 34 | |
| 35 | using namespace ndn::nfd; |
| 36 | |
| 37 | class Nfdc |
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 |
| 56 | dispatch(const std::string& cmd, |
| 57 | const char* cmdOptions[], |
| 58 | int nOptions); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 59 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 60 | /** |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 61 | * \brief Adds a nexthop to a FIB entry. |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 62 | * |
| 63 | * If the FIB entry does not exist, it is inserted automatically |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 64 | * |
| 65 | * cmd format: |
| 66 | * name |
| 67 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 68 | * \param cmdOptions Add next hop command parameters without leading 'add-nexthop' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 69 | */ |
| 70 | void |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 71 | fibAddNextHop(const char* cmdOptions[], bool hasCost); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 72 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 73 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 74 | * \brief Removes a nexthop from an existing FIB entry |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 75 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 76 | * 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] | 77 | * |
| 78 | * cmd format: |
| 79 | * name faceId |
| 80 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 81 | * \param cmdOptions Remove next hop command parameters without leading |
| 82 | * 'remove-nexthop' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 83 | */ |
| 84 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 85 | fibRemoveNextHop(const char* cmdOptions[]); |
| 86 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 87 | /** |
| 88 | * \brief create new face |
| 89 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 90 | * This command allows creation of UDP unicast and TCP faces only. |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 91 | * |
| 92 | * cmd format: |
| 93 | * uri |
| 94 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 95 | * \param cmdOptions Create face command parameters without leading 'create' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 96 | */ |
| 97 | void |
| 98 | faceCreate(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 99 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 100 | /** |
| 101 | * \brief destroy a face |
| 102 | * |
| 103 | * cmd format: |
| 104 | * faceId |
| 105 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 106 | * \param cmdOptions Destroy face command parameters without leading 'destroy' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 107 | */ |
| 108 | void |
| 109 | faceDestroy(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 110 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 111 | /** |
| 112 | * \brief Set the strategy for a namespace |
| 113 | * |
| 114 | * |
| 115 | * cmd format: |
| 116 | * name strategy |
| 117 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 118 | * \param cmdOptions Set strategy choice command parameters without leading |
| 119 | * 'set-strategy' component |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 120 | */ |
| 121 | void |
| 122 | strategyChoiceSet(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 123 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 124 | /** |
| 125 | * \brief Unset the strategy for a namespace |
| 126 | * |
| 127 | * |
| 128 | * cmd format: |
| 129 | * name strategy |
| 130 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 131 | * \param cmdOptions Unset strategy choice command parameters without leading |
| 132 | * 'unset-strategy' component |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 133 | */ |
| 134 | void |
| 135 | strategyChoiceUnset(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 136 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 137 | private: |
| 138 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 139 | onSuccess(const ControlParameters& parameters, |
| 140 | const std::string& message); |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 141 | |
| 142 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 143 | onError(uint32_t code, const std::string& error, const std::string& message); |
| 144 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 145 | public: |
| 146 | const char* m_programName; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 147 | |
| 148 | private: |
| 149 | Controller m_controller; |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 150 | }; |
| 151 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 152 | } // namespace nfdc |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 153 | |
| 154 | #endif // NFD_TOOLS_NFDC_HPP |