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