blob: 8734e426bf5ec3be958c6773aadaac80bc6759de [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
Obaiddca50792014-04-24 18:38:40 -05009 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 **/
hilata198cadb2014-02-15 23:46:19 -060025
26#ifndef NFD_TOOLS_NFDC_HPP
27#define NFD_TOOLS_NFDC_HPP
28
Alexander Afanasyev4a771362014-04-24 21:29:33 -070029#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/management/controller.hpp>
31#include <ndn-cxx/management/nfd-controller.hpp>
hilata198cadb2014-02-15 23:46:19 -060032
33namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070034
35using namespace ndn::nfd;
36
hilata54e4eaf2014-04-10 23:38:33 -050037class Nfdc : boost::noncopyable
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
hilata54e4eaf2014-04-10 23:38:33 -050056 dispatch(const std::string& cmd);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070057
hilata198cadb2014-02-15 23:46:19 -060058 /**
Obaiddca50792014-04-24 18:38:40 -050059 * \brief Adds a nexthop to a FIB entry
hilatadc947ec2014-03-10 12:48:31 -050060 *
61 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060062 *
63 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050064 * [-c cost] name faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -060065 *
hilata198cadb2014-02-15 23:46:19 -060066 */
67 void
Obaiddca50792014-04-24 18:38:40 -050068 fibAddNextHop();
69
70 /**
71 * \brief Adds a nexthop to a FIB entry using faceId provided in the faceCreateResult
72 *
73 */
74 void
75 fibAddNextHop(const ControlParameters& faceCreateResult);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070076
hilata198cadb2014-02-15 23:46:19 -060077 /**
hilatadc947ec2014-03-10 12:48:31 -050078 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060079 *
hilatadc947ec2014-03-10 12:48:31 -050080 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060081 *
82 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050083 * name faceId
hilata198cadb2014-02-15 23:46:19 -060084 *
hilata198cadb2014-02-15 23:46:19 -060085 */
86 void
hilata54e4eaf2014-04-10 23:38:33 -050087 fibRemoveNextHop();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070088
hilata198cadb2014-02-15 23:46:19 -060089 /**
Obaiddca50792014-04-24 18:38:40 -050090 * \brief Registers name to the given faceId or faceUri
hilata198cadb2014-02-15 23:46:19 -060091 *
92 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050093 * [-I] [-C] [-c cost] name faceId|faceUri
94 */
95 void
96 ribRegisterPrefix();
97
98 /**
99 * \brief Registers name to the faceId provided in faceCreateResult
100 *
101 */
102 void
103 ribRegisterPrefix(const ControlParameters& faceCreateResult);
104
105 /**
106 * \brief Unregisters name from the given faceId
107 *
108 * cmd format:
109 * name faceId
110 */
111 void
112 ribUnregisterPrefix();
113
114 /**
115 * \brief Creates new face
116 *
117 * This command allows creation of UDP unicast and TCP faces only
118 *
119 * cmd format:
120 * uri
hilata198cadb2014-02-15 23:46:19 -0600121 *
hilata198cadb2014-02-15 23:46:19 -0600122 */
123 void
hilata54e4eaf2014-04-10 23:38:33 -0500124 faceCreate();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700125
hilata198cadb2014-02-15 23:46:19 -0600126 /**
Obaiddca50792014-04-24 18:38:40 -0500127 * \brief Destroys face
hilata198cadb2014-02-15 23:46:19 -0600128 *
129 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500130 * faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -0600131 *
hilata198cadb2014-02-15 23:46:19 -0600132 */
133 void
hilata54e4eaf2014-04-10 23:38:33 -0500134 faceDestroy();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700135
hilata141eaae2014-03-13 19:54:47 -0500136 /**
Obaiddca50792014-04-24 18:38:40 -0500137 * \brief Destroys face based on faceId provided in faceCreateResult
hilata141eaae2014-03-13 19:54:47 -0500138 *
139 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500140 * faceId|faceUri
141 *
142 */
143 void
144 faceDestroy(const ControlParameters& faceCreateResult);
145
146 /**
147 * \brief Sets the strategy for a namespace
148 *
149 * cmd format:
150 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500151 *
hilata141eaae2014-03-13 19:54:47 -0500152 */
153 void
hilata54e4eaf2014-04-10 23:38:33 -0500154 strategyChoiceSet();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700155
hilata141eaae2014-03-13 19:54:47 -0500156 /**
157 * \brief Unset the strategy for a namespace
158 *
hilata141eaae2014-03-13 19:54:47 -0500159 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500160 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500161 *
hilata141eaae2014-03-13 19:54:47 -0500162 */
163 void
hilata54e4eaf2014-04-10 23:38:33 -0500164 strategyChoiceUnset();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700165
hilata198cadb2014-02-15 23:46:19 -0600166private:
hilata54e4eaf2014-04-10 23:38:33 -0500167
hilata198cadb2014-02-15 23:46:19 -0600168 void
Obaiddca50792014-04-24 18:38:40 -0500169 onSuccess(const ControlParameters& commandSuccessResult,
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700170 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600171
172 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700173 onError(uint32_t code, const std::string& error, const std::string& message);
174
hilata198cadb2014-02-15 23:46:19 -0600175public:
176 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700177
hilata54e4eaf2014-04-10 23:38:33 -0500178 // command parameters without leading 'cmd' component
179 const char** m_commandLineArguments;
180 int m_nOptions;
Obaiddca50792014-04-24 18:38:40 -0500181 uint64_t m_flags;
182 uint64_t m_cost;
183 uint64_t m_faceId;
184 std::string m_name;
hilata54e4eaf2014-04-10 23:38:33 -0500185
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700186private:
187 Controller m_controller;
hilata198cadb2014-02-15 23:46:19 -0600188};
189
hilata141eaae2014-03-13 19:54:47 -0500190} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600191
192#endif // NFD_TOOLS_NFDC_HPP