Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 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. |
| 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 | */ |
| 25 | |
| 26 | #ifndef NFD_TOOLS_NFDC_LEGACY_NFDC_HPP |
| 27 | #define NFD_TOOLS_NFDC_LEGACY_NFDC_HPP |
| 28 | |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 29 | #include "execute-command.hpp" |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 30 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tools { |
| 34 | namespace nfdc { |
| 35 | |
| 36 | class LegacyNfdc : noncopyable |
| 37 | { |
| 38 | public: |
| 39 | static const time::milliseconds DEFAULT_EXPIRATION_PERIOD; |
| 40 | static const uint64_t DEFAULT_COST; |
| 41 | |
| 42 | class Error : public std::runtime_error |
| 43 | { |
| 44 | public: |
| 45 | explicit |
| 46 | Error(const std::string& what) |
| 47 | : std::runtime_error(what) |
| 48 | { |
| 49 | } |
| 50 | }; |
| 51 | |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 52 | LegacyNfdc(Face& face, KeyChain& keyChain); |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 53 | |
| 54 | bool |
| 55 | dispatch(const std::string& cmd); |
| 56 | |
| 57 | /** |
| 58 | * \brief Adds a nexthop to a FIB entry |
| 59 | * |
| 60 | * If the FIB entry does not exist, it is inserted automatically |
| 61 | * |
| 62 | * cmd format: |
| 63 | * [-c cost] name faceId|faceUri |
| 64 | * |
| 65 | */ |
| 66 | void |
| 67 | fibAddNextHop(); |
| 68 | |
| 69 | /** |
| 70 | * \brief Removes a nexthop from an existing FIB entry |
| 71 | * |
| 72 | * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted |
| 73 | * |
| 74 | * cmd format: |
| 75 | * name faceId |
| 76 | * |
| 77 | */ |
| 78 | void |
| 79 | fibRemoveNextHop(); |
| 80 | |
| 81 | /** |
| 82 | * \brief Registers name to the given faceId or faceUri |
| 83 | * |
| 84 | * cmd format: |
| 85 | * [-I] [-C] [-c cost] name faceId|faceUri |
| 86 | */ |
| 87 | void |
| 88 | ribRegisterPrefix(); |
| 89 | |
| 90 | /** |
| 91 | * \brief Unregisters name from the given faceId/faceUri |
| 92 | * |
| 93 | * cmd format: |
| 94 | * name faceId/faceUri |
| 95 | */ |
| 96 | void |
| 97 | ribUnregisterPrefix(); |
| 98 | |
| 99 | /** |
| 100 | * \brief Creates new face |
| 101 | * |
| 102 | * This command allows creation of UDP unicast and TCP faces only |
| 103 | * |
| 104 | * cmd format: |
| 105 | * uri |
| 106 | * |
| 107 | */ |
| 108 | void |
| 109 | faceCreate(); |
| 110 | |
| 111 | /** |
| 112 | * \brief Destroys face |
| 113 | * |
| 114 | * cmd format: |
| 115 | * faceId|faceUri |
| 116 | * |
| 117 | */ |
| 118 | void |
| 119 | faceDestroy(); |
| 120 | |
| 121 | /** |
| 122 | * \brief Sets the strategy for a namespace |
| 123 | * |
| 124 | * cmd format: |
| 125 | * name strategy |
| 126 | * |
| 127 | */ |
| 128 | void |
| 129 | strategyChoiceSet(); |
| 130 | |
| 131 | /** |
| 132 | * \brief Unset the strategy for a namespace |
| 133 | * |
| 134 | * cmd format: |
| 135 | * name strategy |
| 136 | * |
| 137 | */ |
| 138 | void |
| 139 | strategyChoiceUnset(); |
| 140 | |
| 141 | private: |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 142 | void |
| 143 | onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 144 | const std::string& message); |
| 145 | |
| 146 | void |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 147 | onError(const ndn::nfd::ControlResponse& response, const std::string& message); |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 148 | |
| 149 | void |
| 150 | onCanonizeFailure(const std::string& reason); |
| 151 | |
| 152 | void |
| 153 | startFaceCreate(const ndn::util::FaceUri& canonicalUri); |
| 154 | |
| 155 | void |
| 156 | onObtainFaceIdFailure(const std::string& message); |
| 157 | |
| 158 | public: |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 159 | std::vector<std::string> m_commandLineArguments; // positional arguments |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 160 | uint64_t m_flags; |
| 161 | uint64_t m_cost; |
| 162 | uint64_t m_faceId; |
| 163 | uint64_t m_origin; |
| 164 | time::milliseconds m_expires; |
| 165 | std::string m_name; |
| 166 | ndn::nfd::FacePersistency m_facePersistency; |
| 167 | |
| 168 | private: |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 169 | Face& m_face; |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 170 | ndn::nfd::Controller m_controller; |
| 171 | }; |
| 172 | |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 173 | void |
| 174 | legacyNfdcUsage(); |
| 175 | |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 176 | void |
Junxiao Shi | d695801 | 2017-02-20 03:34:48 +0000 | [diff] [blame] | 177 | legacyNfdcMain(ExecuteContext& ctx, const std::string& replacementCommand); |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 178 | |
Junxiao Shi | d243d71 | 2016-08-19 06:45:31 +0000 | [diff] [blame] | 179 | } // namespace nfdc |
| 180 | } // namespace tools |
| 181 | } // namespace nfd |
| 182 | |
| 183 | #endif // NFD_TOOLS_NFDC_LEGACY_NFDC_HPP |