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