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 | |
| 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 | /** |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 58 | * \brief Adds a name to a FIB entry after creating the attaced face. |
| 59 | * |
| 60 | * Create a new face for the given faceUri and use it when adding the given name to the fib |
| 61 | * |
| 62 | * |
| 63 | * cmd format: |
| 64 | * add name faceUri [cost] |
| 65 | * |
| 66 | */ |
| 67 | void |
| 68 | addName(); |
| 69 | /** |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 70 | * \brief Adds a nexthop to a FIB entry. |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 71 | * |
| 72 | * If the FIB entry does not exist, it is inserted automatically |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 73 | * |
| 74 | * cmd format: |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 75 | * name faceId [cost] |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 76 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 77 | */ |
| 78 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 79 | fibAddNextHop(bool hasCost); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 80 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 81 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 82 | * \brief Removes a nexthop from an existing FIB entry |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 83 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 84 | * 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] | 85 | * |
| 86 | * cmd format: |
| 87 | * name faceId |
| 88 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 89 | */ |
| 90 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 91 | fibRemoveNextHop(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 92 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 93 | /** |
| 94 | * \brief create new face |
| 95 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 96 | * This command allows creation of UDP unicast and TCP faces only. |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 97 | * |
| 98 | * cmd format: |
| 99 | * uri |
| 100 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 101 | */ |
| 102 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 103 | faceCreate(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 104 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 105 | /** |
| 106 | * \brief destroy a face |
| 107 | * |
| 108 | * cmd format: |
| 109 | * faceId |
| 110 | * |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 111 | */ |
| 112 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 113 | faceDestroy(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 114 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 115 | /** |
| 116 | * \brief Set the strategy for a namespace |
| 117 | * |
| 118 | * |
| 119 | * cmd format: |
| 120 | * name strategy |
| 121 | * |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 122 | */ |
| 123 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 124 | strategyChoiceSet(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 125 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 126 | /** |
| 127 | * \brief Unset the strategy for a namespace |
| 128 | * |
| 129 | * |
| 130 | * cmd format: |
| 131 | * name strategy |
| 132 | * |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 133 | */ |
| 134 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 135 | strategyChoiceUnset(); |
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: |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 138 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 139 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 140 | onSuccess(const ControlParameters& parameters, |
| 141 | const std::string& message); |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 142 | |
| 143 | void |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 144 | onAddSuccess(const ControlParameters& parameters, |
| 145 | const std::string& message); |
| 146 | |
| 147 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 148 | onError(uint32_t code, const std::string& error, const std::string& message); |
| 149 | |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 150 | void |
| 151 | fibAddNextHop(const std::string& name, const uint64_t faceId, bool hasCost); |
| 152 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 153 | public: |
| 154 | const char* m_programName; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 155 | |
hilata | 54e4eaf | 2014-04-10 23:38:33 -0500 | [diff] [blame] | 156 | // command parameters without leading 'cmd' component |
| 157 | const char** m_commandLineArguments; |
| 158 | int m_nOptions; |
| 159 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 160 | private: |
| 161 | Controller m_controller; |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 162 | }; |
| 163 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 164 | } // namespace nfdc |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 165 | |
| 166 | #endif // NFD_TOOLS_NFDC_HPP |