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> |
| 13 | #include <ndn-cpp-dev/management/nfd-fib-management-options.hpp> |
| 14 | #include <ndn-cpp-dev/management/nfd-face-management-options.hpp> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace nfdc { |
| 18 | |
| 19 | class Controller : public ndn::nfd::Controller |
| 20 | { |
| 21 | public: |
| 22 | struct Error : public std::runtime_error |
| 23 | { |
| 24 | Error(const std::string& what) : std::runtime_error(what) {} |
| 25 | }; |
| 26 | |
| 27 | explicit |
| 28 | Controller(ndn::Face& face); |
| 29 | |
| 30 | ~Controller(); |
| 31 | |
| 32 | bool |
| 33 | dispatch(const std::string& cmd, |
| 34 | const char* cmdOptions[], |
| 35 | int nOptions); |
| 36 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 37 | * \brief Adds a nexthop to a FIB entry. |
| 38 | * |
| 39 | * If the FIB entry does not exist, it is inserted automatically |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 40 | * |
| 41 | * cmd format: |
| 42 | * name |
| 43 | * |
| 44 | * @param cmdOptions add command without leading 'insert' component |
| 45 | */ |
| 46 | void |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 47 | fibAddNextHop(const char* cmdOptions[], bool hasCost); |
| 48 | /** |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 49 | * \brief Removes a nexthop from an existing FIB entry |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 50 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 51 | * 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] | 52 | * |
| 53 | * cmd format: |
| 54 | * name faceId |
| 55 | * |
| 56 | * @param cmdOptions delNext command without leading 'remove-nexthop' component |
| 57 | */ |
| 58 | void |
| 59 | fibRemoveNextHop(const char* cmdOptions[]); |
| 60 | /** |
| 61 | * \brief Sets a forwarding strategy for a namespace |
| 62 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 63 | * This command sets a forwarding strategy for a namespace. |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 64 | * |
| 65 | * cmd format: |
| 66 | * name strategy |
| 67 | * |
| 68 | * @param cmdOptions setStrategy command without leading 'setStrategy' component |
| 69 | */ |
| 70 | void |
| 71 | fibSetStrategy(const char* cmdOptions[]); |
| 72 | |
| 73 | /** |
| 74 | * \brief create new face |
| 75 | * |
hilata | dc947ec | 2014-03-10 12:48:31 -0500 | [diff] [blame] | 76 | * This command allows creation of UDP unicast and TCP faces only. |
hilata | 198cadb | 2014-02-15 23:46:19 -0600 | [diff] [blame] | 77 | * |
| 78 | * cmd format: |
| 79 | * uri |
| 80 | * |
| 81 | * @param cmdOptions create command without leading 'create' component |
| 82 | */ |
| 83 | void |
| 84 | faceCreate(const char* cmdOptions[]); |
| 85 | /** |
| 86 | * \brief destroy a face |
| 87 | * |
| 88 | * cmd format: |
| 89 | * faceId |
| 90 | * |
| 91 | * @param cmdOptions destroy command without leading 'destroy' component |
| 92 | */ |
| 93 | void |
| 94 | faceDestroy(const char* cmdOptions[]); |
| 95 | |
| 96 | private: |
| 97 | void |
| 98 | onFibSuccess(const ndn::nfd::FibManagementOptions& fibOptions, const std::string& message); |
| 99 | |
| 100 | void |
| 101 | onFaceSuccess(const ndn::nfd::FaceManagementOptions& faceOptions, const std::string& message); |
| 102 | |
| 103 | void |
| 104 | onError(const std::string& error, const std::string& message); |
| 105 | |
| 106 | public: |
| 107 | const char* m_programName; |
| 108 | }; |
| 109 | |
| 110 | }// namespace nfdc |
| 111 | |
| 112 | #endif // NFD_TOOLS_NFDC_HPP |
| 113 | |