blob: 537667e818cbb0c58d3304269d4f7b65fd00a21b [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>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070030#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 /**
Obaiddca50792014-04-24 18:38:40 -050058 * \brief Adds a nexthop to a FIB entry
hilatadc947ec2014-03-10 12:48:31 -050059 *
60 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060061 *
62 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050063 * [-c cost] name faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -060064 *
hilata198cadb2014-02-15 23:46:19 -060065 */
66 void
Obaiddca50792014-04-24 18:38:40 -050067 fibAddNextHop();
68
69 /**
70 * \brief Adds a nexthop to a FIB entry using faceId provided in the faceCreateResult
71 *
72 */
73 void
74 fibAddNextHop(const ControlParameters& faceCreateResult);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070075
hilata198cadb2014-02-15 23:46:19 -060076 /**
hilatadc947ec2014-03-10 12:48:31 -050077 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060078 *
hilatadc947ec2014-03-10 12:48:31 -050079 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060080 *
81 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050082 * name faceId
hilata198cadb2014-02-15 23:46:19 -060083 *
hilata198cadb2014-02-15 23:46:19 -060084 */
85 void
hilata54e4eaf2014-04-10 23:38:33 -050086 fibRemoveNextHop();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070087
hilata198cadb2014-02-15 23:46:19 -060088 /**
Obaiddca50792014-04-24 18:38:40 -050089 * \brief Registers name to the given faceId or faceUri
hilata198cadb2014-02-15 23:46:19 -060090 *
91 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050092 * [-I] [-C] [-c cost] name faceId|faceUri
93 */
94 void
95 ribRegisterPrefix();
96
97 /**
98 * \brief Registers name to the faceId provided in faceCreateResult
99 *
100 */
101 void
102 ribRegisterPrefix(const ControlParameters& faceCreateResult);
103
104 /**
105 * \brief Unregisters name from the given faceId
106 *
107 * cmd format:
108 * name faceId
109 */
110 void
111 ribUnregisterPrefix();
112
113 /**
114 * \brief Creates new face
115 *
116 * This command allows creation of UDP unicast and TCP faces only
117 *
118 * cmd format:
119 * uri
hilata198cadb2014-02-15 23:46:19 -0600120 *
hilata198cadb2014-02-15 23:46:19 -0600121 */
122 void
hilata54e4eaf2014-04-10 23:38:33 -0500123 faceCreate();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700124
hilata198cadb2014-02-15 23:46:19 -0600125 /**
Obaiddca50792014-04-24 18:38:40 -0500126 * \brief Destroys face
hilata198cadb2014-02-15 23:46:19 -0600127 *
128 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500129 * faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -0600130 *
hilata198cadb2014-02-15 23:46:19 -0600131 */
132 void
hilata54e4eaf2014-04-10 23:38:33 -0500133 faceDestroy();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700134
hilata141eaae2014-03-13 19:54:47 -0500135 /**
Obaiddca50792014-04-24 18:38:40 -0500136 * \brief Destroys face based on faceId provided in faceCreateResult
hilata141eaae2014-03-13 19:54:47 -0500137 *
138 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500139 * faceId|faceUri
140 *
141 */
142 void
143 faceDestroy(const ControlParameters& faceCreateResult);
144
145 /**
146 * \brief Sets the strategy for a namespace
147 *
148 * cmd format:
149 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500150 *
hilata141eaae2014-03-13 19:54:47 -0500151 */
152 void
hilata54e4eaf2014-04-10 23:38:33 -0500153 strategyChoiceSet();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700154
hilata141eaae2014-03-13 19:54:47 -0500155 /**
156 * \brief Unset the strategy for a namespace
157 *
hilata141eaae2014-03-13 19:54:47 -0500158 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500159 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500160 *
hilata141eaae2014-03-13 19:54:47 -0500161 */
162 void
hilata54e4eaf2014-04-10 23:38:33 -0500163 strategyChoiceUnset();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700164
hilata198cadb2014-02-15 23:46:19 -0600165private:
hilata54e4eaf2014-04-10 23:38:33 -0500166
hilata198cadb2014-02-15 23:46:19 -0600167 void
Obaiddca50792014-04-24 18:38:40 -0500168 onSuccess(const ControlParameters& commandSuccessResult,
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700169 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600170
171 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700172 onError(uint32_t code, const std::string& error, const std::string& message);
173
hilata198cadb2014-02-15 23:46:19 -0600174public:
175 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700176
hilata54e4eaf2014-04-10 23:38:33 -0500177 // command parameters without leading 'cmd' component
Junxiao Shi22295032014-04-29 22:57:40 -0700178 const char* const* m_commandLineArguments;
hilata54e4eaf2014-04-10 23:38:33 -0500179 int m_nOptions;
Obaiddca50792014-04-24 18:38:40 -0500180 uint64_t m_flags;
181 uint64_t m_cost;
182 uint64_t m_faceId;
183 std::string m_name;
hilata54e4eaf2014-04-10 23:38:33 -0500184
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700185private:
186 Controller m_controller;
hilata198cadb2014-02-15 23:46:19 -0600187};
188
hilata141eaae2014-03-13 19:54:47 -0500189} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600190
191#endif // NFD_TOOLS_NFDC_HPP