blob: 84a7fc83f785410e9725616d3d028346c33caa76 [file] [log] [blame]
hilata198cadb2014-02-15 23:46:19 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Syed Obaid4ae0ce32014-06-17 13:59:20 -05003 * 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 * 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/>.
Syed Obaid4ae0ce32014-06-17 13:59:20 -050024 */
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>
Syed Obaid4ae0ce32014-06-17 13:59:20 -050030#include <ndn-cxx/util/time.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070031#include <ndn-cxx/management/nfd-controller.hpp>
Chengyu Fandae25302014-10-16 11:40:11 -060032#include <ndn-cxx/util/face-uri.hpp>
hilata198cadb2014-02-15 23:46:19 -060033
34namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070035
36using namespace ndn::nfd;
37
hilata54e4eaf2014-04-10 23:38:33 -050038class Nfdc : boost::noncopyable
hilata198cadb2014-02-15 23:46:19 -060039{
40public:
Syed Obaid4ae0ce32014-06-17 13:59:20 -050041
42 static const ndn::time::milliseconds DEFAULT_EXPIRATION_PERIOD;
43 static const uint64_t DEFAULT_COST;
44
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070045 class Error : public std::runtime_error
hilata198cadb2014-02-15 23:46:19 -060046 {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070047 public:
48 explicit
49 Error(const std::string& what)
50 : std::runtime_error(what)
51 {
52 }
hilata198cadb2014-02-15 23:46:19 -060053 };
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070054
hilata198cadb2014-02-15 23:46:19 -060055 explicit
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070056 Nfdc(ndn::Face& face);
57
58 ~Nfdc();
59
hilata198cadb2014-02-15 23:46:19 -060060 bool
hilata54e4eaf2014-04-10 23:38:33 -050061 dispatch(const std::string& cmd);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070062
hilata198cadb2014-02-15 23:46:19 -060063 /**
Obaiddca50792014-04-24 18:38:40 -050064 * \brief Adds a nexthop to a FIB entry
hilatadc947ec2014-03-10 12:48:31 -050065 *
66 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060067 *
68 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050069 * [-c cost] name faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -060070 *
hilata198cadb2014-02-15 23:46:19 -060071 */
72 void
Obaiddca50792014-04-24 18:38:40 -050073 fibAddNextHop();
74
75 /**
76 * \brief Adds a nexthop to a FIB entry using faceId provided in the faceCreateResult
77 *
78 */
79 void
80 fibAddNextHop(const ControlParameters& faceCreateResult);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070081
hilata198cadb2014-02-15 23:46:19 -060082 /**
hilatadc947ec2014-03-10 12:48:31 -050083 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060084 *
hilatadc947ec2014-03-10 12:48:31 -050085 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060086 *
87 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050088 * name faceId
hilata198cadb2014-02-15 23:46:19 -060089 *
hilata198cadb2014-02-15 23:46:19 -060090 */
91 void
hilata54e4eaf2014-04-10 23:38:33 -050092 fibRemoveNextHop();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070093
hilata198cadb2014-02-15 23:46:19 -060094 /**
Obaiddca50792014-04-24 18:38:40 -050095 * \brief Registers name to the given faceId or faceUri
hilata198cadb2014-02-15 23:46:19 -060096 *
97 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050098 * [-I] [-C] [-c cost] name faceId|faceUri
99 */
100 void
101 ribRegisterPrefix();
102
103 /**
104 * \brief Registers name to the faceId provided in faceCreateResult
105 *
106 */
107 void
108 ribRegisterPrefix(const ControlParameters& faceCreateResult);
109
110 /**
111 * \brief Unregisters name from the given faceId
112 *
113 * cmd format:
114 * name faceId
115 */
116 void
117 ribUnregisterPrefix();
118
119 /**
120 * \brief Creates new face
121 *
122 * This command allows creation of UDP unicast and TCP faces only
123 *
124 * cmd format:
125 * uri
hilata198cadb2014-02-15 23:46:19 -0600126 *
hilata198cadb2014-02-15 23:46:19 -0600127 */
128 void
hilata54e4eaf2014-04-10 23:38:33 -0500129 faceCreate();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700130
hilata198cadb2014-02-15 23:46:19 -0600131 /**
Obaiddca50792014-04-24 18:38:40 -0500132 * \brief Destroys face
hilata198cadb2014-02-15 23:46:19 -0600133 *
134 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500135 * faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -0600136 *
hilata198cadb2014-02-15 23:46:19 -0600137 */
138 void
hilata54e4eaf2014-04-10 23:38:33 -0500139 faceDestroy();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700140
hilata141eaae2014-03-13 19:54:47 -0500141 /**
Obaiddca50792014-04-24 18:38:40 -0500142 * \brief Destroys face based on faceId provided in faceCreateResult
hilata141eaae2014-03-13 19:54:47 -0500143 *
144 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500145 * faceId|faceUri
146 *
147 */
148 void
149 faceDestroy(const ControlParameters& faceCreateResult);
150
151 /**
152 * \brief Sets the strategy for a namespace
153 *
154 * cmd format:
155 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500156 *
hilata141eaae2014-03-13 19:54:47 -0500157 */
158 void
hilata54e4eaf2014-04-10 23:38:33 -0500159 strategyChoiceSet();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700160
hilata141eaae2014-03-13 19:54:47 -0500161 /**
162 * \brief Unset the strategy for a namespace
163 *
hilata141eaae2014-03-13 19:54:47 -0500164 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500165 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500166 *
hilata141eaae2014-03-13 19:54:47 -0500167 */
168 void
hilata54e4eaf2014-04-10 23:38:33 -0500169 strategyChoiceUnset();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700170
hilata198cadb2014-02-15 23:46:19 -0600171private:
hilata54e4eaf2014-04-10 23:38:33 -0500172
hilata198cadb2014-02-15 23:46:19 -0600173 void
Obaiddca50792014-04-24 18:38:40 -0500174 onSuccess(const ControlParameters& commandSuccessResult,
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700175 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600176
177 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700178 onError(uint32_t code, const std::string& error, const std::string& message);
179
Chengyu Fandae25302014-10-16 11:40:11 -0600180 void
181 onCanonizeFailure(const std::string& reason);
182
183 void
184 startFaceCreate(const ndn::util::FaceUri& canonicalUri);
185
186 void
187 startFaceDestroy(const ndn::util::FaceUri& canonicalUri);
188
189 void
190 startFibAddNextHop(const ndn::util::FaceUri& canonicalUri);
191
192 void
193 startRibRegisterPrefix(const ndn::util::FaceUri& canonicalUri);
194
hilata198cadb2014-02-15 23:46:19 -0600195public:
196 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700197
hilata54e4eaf2014-04-10 23:38:33 -0500198 // command parameters without leading 'cmd' component
Junxiao Shi22295032014-04-29 22:57:40 -0700199 const char* const* m_commandLineArguments;
hilata54e4eaf2014-04-10 23:38:33 -0500200 int m_nOptions;
Obaiddca50792014-04-24 18:38:40 -0500201 uint64_t m_flags;
202 uint64_t m_cost;
203 uint64_t m_faceId;
Syed Obaid4ae0ce32014-06-17 13:59:20 -0500204 uint64_t m_origin;
205 ndn::time::milliseconds m_expires;
Obaiddca50792014-04-24 18:38:40 -0500206 std::string m_name;
hilata54e4eaf2014-04-10 23:38:33 -0500207
Syed Obaid4ae0ce32014-06-17 13:59:20 -0500208
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700209private:
210 Controller m_controller;
Chengyu Fandae25302014-10-16 11:40:11 -0600211 boost::asio::io_service& m_ioService;
hilata198cadb2014-02-15 23:46:19 -0600212};
213
hilata141eaae2014-03-13 19:54:47 -0500214} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600215
216#endif // NFD_TOOLS_NFDC_HPP