blob: 968c276b8f735e5e14daae36fb398fc63f4d1321 [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
Alexander Afanasyev4a771362014-04-24 21:29:33 -070028#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/management/controller.hpp>
30#include <ndn-cxx/management/nfd-controller.hpp>
hilata198cadb2014-02-15 23:46:19 -060031
32namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070033
34using namespace ndn::nfd;
35
hilata54e4eaf2014-04-10 23:38:33 -050036class Nfdc : boost::noncopyable
hilata198cadb2014-02-15 23:46:19 -060037{
38public:
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070039 class Error : public std::runtime_error
hilata198cadb2014-02-15 23:46:19 -060040 {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070041 public:
42 explicit
43 Error(const std::string& what)
44 : std::runtime_error(what)
45 {
46 }
hilata198cadb2014-02-15 23:46:19 -060047 };
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070048
hilata198cadb2014-02-15 23:46:19 -060049 explicit
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070050 Nfdc(ndn::Face& face);
51
52 ~Nfdc();
53
hilata198cadb2014-02-15 23:46:19 -060054 bool
hilata54e4eaf2014-04-10 23:38:33 -050055 dispatch(const std::string& cmd);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070056
hilata198cadb2014-02-15 23:46:19 -060057 /**
hilata54e4eaf2014-04-10 23:38:33 -050058 * \brief Adds a name to a FIB entry after creating the attaced face.
59 *
60 * Create a new face for the given faceUri and use it when adding the given name to the fib
61 *
62 *
63 * cmd format:
64 * add name faceUri [cost]
65 *
66 */
67 void
68 addName();
69 /**
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070070 * \brief Adds a nexthop to a FIB entry.
hilatadc947ec2014-03-10 12:48:31 -050071 *
72 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060073 *
74 * cmd format:
hilata54e4eaf2014-04-10 23:38:33 -050075 * name faceId [cost]
hilata198cadb2014-02-15 23:46:19 -060076 *
hilata198cadb2014-02-15 23:46:19 -060077 */
78 void
hilata54e4eaf2014-04-10 23:38:33 -050079 fibAddNextHop(bool hasCost);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070080
hilata198cadb2014-02-15 23:46:19 -060081 /**
hilatadc947ec2014-03-10 12:48:31 -050082 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060083 *
hilatadc947ec2014-03-10 12:48:31 -050084 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060085 *
86 * cmd format:
87 * name faceId
88 *
hilata198cadb2014-02-15 23:46:19 -060089 */
90 void
hilata54e4eaf2014-04-10 23:38:33 -050091 fibRemoveNextHop();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070092
hilata198cadb2014-02-15 23:46:19 -060093 /**
94 * \brief create new face
95 *
hilatadc947ec2014-03-10 12:48:31 -050096 * This command allows creation of UDP unicast and TCP faces only.
hilata198cadb2014-02-15 23:46:19 -060097 *
98 * cmd format:
99 * uri
100 *
hilata198cadb2014-02-15 23:46:19 -0600101 */
102 void
hilata54e4eaf2014-04-10 23:38:33 -0500103 faceCreate();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700104
hilata198cadb2014-02-15 23:46:19 -0600105 /**
106 * \brief destroy a face
107 *
108 * cmd format:
109 * faceId
110 *
hilata198cadb2014-02-15 23:46:19 -0600111 */
112 void
hilata54e4eaf2014-04-10 23:38:33 -0500113 faceDestroy();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700114
hilata141eaae2014-03-13 19:54:47 -0500115 /**
116 * \brief Set the strategy for a namespace
117 *
118 *
119 * cmd format:
120 * name strategy
121 *
hilata141eaae2014-03-13 19:54:47 -0500122 */
123 void
hilata54e4eaf2014-04-10 23:38:33 -0500124 strategyChoiceSet();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700125
hilata141eaae2014-03-13 19:54:47 -0500126 /**
127 * \brief Unset the strategy for a namespace
128 *
129 *
130 * cmd format:
131 * name strategy
132 *
hilata141eaae2014-03-13 19:54:47 -0500133 */
134 void
hilata54e4eaf2014-04-10 23:38:33 -0500135 strategyChoiceUnset();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700136
hilata198cadb2014-02-15 23:46:19 -0600137private:
hilata54e4eaf2014-04-10 23:38:33 -0500138
hilata198cadb2014-02-15 23:46:19 -0600139 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700140 onSuccess(const ControlParameters& parameters,
141 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600142
143 void
hilata54e4eaf2014-04-10 23:38:33 -0500144 onAddSuccess(const ControlParameters& parameters,
145 const std::string& message);
146
147 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700148 onError(uint32_t code, const std::string& error, const std::string& message);
149
hilata54e4eaf2014-04-10 23:38:33 -0500150 void
151 fibAddNextHop(const std::string& name, const uint64_t faceId, bool hasCost);
152
hilata198cadb2014-02-15 23:46:19 -0600153public:
154 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700155
hilata54e4eaf2014-04-10 23:38:33 -0500156 // command parameters without leading 'cmd' component
157 const char** m_commandLineArguments;
158 int m_nOptions;
159
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700160private:
161 Controller m_controller;
hilata198cadb2014-02-15 23:46:19 -0600162};
163
hilata141eaae2014-03-13 19:54:47 -0500164} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600165
166#endif // NFD_TOOLS_NFDC_HPP