hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TOOLS_NFDC_HPP |
| 8 | #define NFD_TOOLS_NFDC_HPP |
| 9 | |
| 10 | #include <ndn-cpp-dev/face.hpp> |
| 11 | #include <ndn-cpp-dev/management/controller.hpp> |
| 12 | #include <ndn-cpp-dev/management/nfd-controller.hpp> |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
| 15 | namespace nfdc { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 16 | |
| 17 | using namespace ndn::nfd; |
| 18 | |
| 19 | class Nfdc |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 20 | { |
| 21 | public: |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 22 | class Error : public std::runtime_error |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 23 | { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 24 | public: |
| 25 | explicit |
| 26 | Error(const std::string& what) |
| 27 | : std::runtime_error(what) |
| 28 | { |
| 29 | } |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 30 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 31 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 32 | explicit |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 33 | Nfdc(ndn::Face& face); |
| 34 | |
| 35 | ~Nfdc(); |
| 36 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 37 | bool |
| 38 | dispatch(const std::string& cmd, |
| 39 | const char* cmdOptions[], |
| 40 | int nOptions); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 41 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 42 | /** |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 43 | * \brief Adds a nexthop to a FIB entry. |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 44 | * |
| 45 | * If the FIB entry does not exist, it is inserted automatically |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 46 | * |
| 47 | * cmd format: |
| 48 | * name |
| 49 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 50 | * \param cmdOptions Add next hop command parameters without leading 'add-nexthop' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 51 | */ |
| 52 | void |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 53 | fibAddNextHop(const char* cmdOptions[], bool hasCost); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 54 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 55 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 56 | * \brief Removes a nexthop from an existing FIB entry |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 57 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 58 | * 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] | 59 | * |
| 60 | * cmd format: |
| 61 | * name faceId |
| 62 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 63 | * \param cmdOptions Remove next hop command parameters without leading |
| 64 | * 'remove-nexthop' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 65 | */ |
| 66 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 67 | fibRemoveNextHop(const char* cmdOptions[]); |
| 68 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 69 | /** |
| 70 | * \brief create new face |
| 71 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 72 | * This command allows creation of UDP unicast and TCP faces only. |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 73 | * |
| 74 | * cmd format: |
| 75 | * uri |
| 76 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 77 | * \param cmdOptions Create face command parameters without leading 'create' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 78 | */ |
| 79 | void |
| 80 | faceCreate(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 81 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 82 | /** |
| 83 | * \brief destroy a face |
| 84 | * |
| 85 | * cmd format: |
| 86 | * faceId |
| 87 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 88 | * \param cmdOptions Destroy face command parameters without leading 'destroy' component |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 89 | */ |
| 90 | void |
| 91 | faceDestroy(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 92 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 93 | /** |
| 94 | * \brief Set the strategy for a namespace |
| 95 | * |
| 96 | * |
| 97 | * cmd format: |
| 98 | * name strategy |
| 99 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 100 | * \param cmdOptions Set strategy choice command parameters without leading |
| 101 | * 'set-strategy' component |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 102 | */ |
| 103 | void |
| 104 | strategyChoiceSet(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 105 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 106 | /** |
| 107 | * \brief Unset the strategy for a namespace |
| 108 | * |
| 109 | * |
| 110 | * cmd format: |
| 111 | * name strategy |
| 112 | * |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 113 | * \param cmdOptions Unset strategy choice command parameters without leading |
| 114 | * 'unset-strategy' component |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 115 | */ |
| 116 | void |
| 117 | strategyChoiceUnset(const char* cmdOptions[]); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 118 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 119 | private: |
| 120 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 121 | onSuccess(const ControlParameters& parameters, |
| 122 | const std::string& message); |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 123 | |
| 124 | void |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 125 | onError(uint32_t code, const std::string& error, const std::string& message); |
| 126 | |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 127 | public: |
| 128 | const char* m_programName; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 129 | |
| 130 | private: |
| 131 | Controller m_controller; |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 132 | }; |
| 133 | |
hilata | 141eaae | 2014-03-13 19:54:47 -0500 | [diff] [blame] | 134 | } // namespace nfdc |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 135 | |
| 136 | #endif // NFD_TOOLS_NFDC_HPP |