blob: ab74e108bb981a105159816d465ad2321297502f [file] [log] [blame]
hilata198cadb2014-02-15 23:46:19 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
hilata198cadb2014-02-15 23:46:19 -060024
25#ifndef NFD_TOOLS_NFDC_HPP
26#define NFD_TOOLS_NFDC_HPP
27
28#include <ndn-cpp-dev/face.hpp>
29#include <ndn-cpp-dev/management/controller.hpp>
30#include <ndn-cpp-dev/management/nfd-controller.hpp>
hilata198cadb2014-02-15 23:46:19 -060031#include <vector>
32
33namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070034
35using namespace ndn::nfd;
36
37class Nfdc
hilata198cadb2014-02-15 23:46:19 -060038{
39public:
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070040 class Error : public std::runtime_error
hilata198cadb2014-02-15 23:46:19 -060041 {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070042 public:
43 explicit
44 Error(const std::string& what)
45 : std::runtime_error(what)
46 {
47 }
hilata198cadb2014-02-15 23:46:19 -060048 };
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070049
hilata198cadb2014-02-15 23:46:19 -060050 explicit
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070051 Nfdc(ndn::Face& face);
52
53 ~Nfdc();
54
hilata198cadb2014-02-15 23:46:19 -060055 bool
56 dispatch(const std::string& cmd,
57 const char* cmdOptions[],
58 int nOptions);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070059
hilata198cadb2014-02-15 23:46:19 -060060 /**
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070061 * \brief Adds a nexthop to a FIB entry.
hilatadc947ec2014-03-10 12:48:31 -050062 *
63 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060064 *
65 * cmd format:
66 * name
67 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070068 * \param cmdOptions Add next hop command parameters without leading 'add-nexthop' component
hilata198cadb2014-02-15 23:46:19 -060069 */
70 void
hilata198cadb2014-02-15 23:46:19 -060071 fibAddNextHop(const char* cmdOptions[], bool hasCost);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070072
hilata198cadb2014-02-15 23:46:19 -060073 /**
hilatadc947ec2014-03-10 12:48:31 -050074 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060075 *
hilatadc947ec2014-03-10 12:48:31 -050076 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060077 *
78 * cmd format:
79 * name faceId
80 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070081 * \param cmdOptions Remove next hop command parameters without leading
82 * 'remove-nexthop' component
hilata198cadb2014-02-15 23:46:19 -060083 */
84 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070085 fibRemoveNextHop(const char* cmdOptions[]);
86
hilata198cadb2014-02-15 23:46:19 -060087 /**
88 * \brief create new face
89 *
hilatadc947ec2014-03-10 12:48:31 -050090 * This command allows creation of UDP unicast and TCP faces only.
hilata198cadb2014-02-15 23:46:19 -060091 *
92 * cmd format:
93 * uri
94 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070095 * \param cmdOptions Create face command parameters without leading 'create' component
hilata198cadb2014-02-15 23:46:19 -060096 */
97 void
98 faceCreate(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070099
hilata198cadb2014-02-15 23:46:19 -0600100 /**
101 * \brief destroy a face
102 *
103 * cmd format:
104 * faceId
105 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700106 * \param cmdOptions Destroy face command parameters without leading 'destroy' component
hilata198cadb2014-02-15 23:46:19 -0600107 */
108 void
109 faceDestroy(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700110
hilata141eaae2014-03-13 19:54:47 -0500111 /**
112 * \brief Set the strategy for a namespace
113 *
114 *
115 * cmd format:
116 * name strategy
117 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700118 * \param cmdOptions Set strategy choice command parameters without leading
119 * 'set-strategy' component
hilata141eaae2014-03-13 19:54:47 -0500120 */
121 void
122 strategyChoiceSet(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700123
hilata141eaae2014-03-13 19:54:47 -0500124 /**
125 * \brief Unset the strategy for a namespace
126 *
127 *
128 * cmd format:
129 * name strategy
130 *
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700131 * \param cmdOptions Unset strategy choice command parameters without leading
132 * 'unset-strategy' component
hilata141eaae2014-03-13 19:54:47 -0500133 */
134 void
135 strategyChoiceUnset(const char* cmdOptions[]);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700136
hilata198cadb2014-02-15 23:46:19 -0600137private:
138 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700139 onSuccess(const ControlParameters& parameters,
140 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600141
142 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700143 onError(uint32_t code, const std::string& error, const std::string& message);
144
hilata198cadb2014-02-15 23:46:19 -0600145public:
146 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700147
148private:
149 Controller m_controller;
hilata198cadb2014-02-15 23:46:19 -0600150};
151
hilata141eaae2014-03-13 19:54:47 -0500152} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600153
154#endif // NFD_TOOLS_NFDC_HPP