blob: eb7bc51f1e2971467f25a44719289a7e90da3c00 [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>
Junxiao Shi8e273ca2014-11-12 00:42:29 -070030#include <ndn-cxx/security/key-chain.hpp>
Syed Obaid4ae0ce32014-06-17 13:59:20 -050031#include <ndn-cxx/util/time.hpp>
Alexander Afanasyev4a771362014-04-24 21:29:33 -070032#include <ndn-cxx/management/nfd-controller.hpp>
Chengyu Fandae25302014-10-16 11:40:11 -060033#include <ndn-cxx/util/face-uri.hpp>
hilata198cadb2014-02-15 23:46:19 -060034
35namespace nfdc {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070036
37using namespace ndn::nfd;
38
hilata54e4eaf2014-04-10 23:38:33 -050039class Nfdc : boost::noncopyable
hilata198cadb2014-02-15 23:46:19 -060040{
41public:
Syed Obaid4ae0ce32014-06-17 13:59:20 -050042
43 static const ndn::time::milliseconds DEFAULT_EXPIRATION_PERIOD;
44 static const uint64_t DEFAULT_COST;
45
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070046 class Error : public std::runtime_error
hilata198cadb2014-02-15 23:46:19 -060047 {
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070048 public:
49 explicit
50 Error(const std::string& what)
51 : std::runtime_error(what)
52 {
53 }
hilata198cadb2014-02-15 23:46:19 -060054 };
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070055
hilata198cadb2014-02-15 23:46:19 -060056 explicit
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070057 Nfdc(ndn::Face& face);
58
59 ~Nfdc();
60
hilata198cadb2014-02-15 23:46:19 -060061 bool
hilata54e4eaf2014-04-10 23:38:33 -050062 dispatch(const std::string& cmd);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070063
hilata198cadb2014-02-15 23:46:19 -060064 /**
Obaiddca50792014-04-24 18:38:40 -050065 * \brief Adds a nexthop to a FIB entry
hilatadc947ec2014-03-10 12:48:31 -050066 *
67 * If the FIB entry does not exist, it is inserted automatically
hilata198cadb2014-02-15 23:46:19 -060068 *
69 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050070 * [-c cost] name faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -060071 *
hilata198cadb2014-02-15 23:46:19 -060072 */
73 void
Obaiddca50792014-04-24 18:38:40 -050074 fibAddNextHop();
75
76 /**
77 * \brief Adds a nexthop to a FIB entry using faceId provided in the faceCreateResult
78 *
79 */
80 void
81 fibAddNextHop(const ControlParameters& faceCreateResult);
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070082
hilata198cadb2014-02-15 23:46:19 -060083 /**
hilatadc947ec2014-03-10 12:48:31 -050084 * \brief Removes a nexthop from an existing FIB entry
hilata198cadb2014-02-15 23:46:19 -060085 *
hilatadc947ec2014-03-10 12:48:31 -050086 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
hilata198cadb2014-02-15 23:46:19 -060087 *
88 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050089 * name faceId
hilata198cadb2014-02-15 23:46:19 -060090 *
hilata198cadb2014-02-15 23:46:19 -060091 */
92 void
hilata54e4eaf2014-04-10 23:38:33 -050093 fibRemoveNextHop();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -070094
hilata198cadb2014-02-15 23:46:19 -060095 /**
Obaiddca50792014-04-24 18:38:40 -050096 * \brief Registers name to the given faceId or faceUri
hilata198cadb2014-02-15 23:46:19 -060097 *
98 * cmd format:
Obaiddca50792014-04-24 18:38:40 -050099 * [-I] [-C] [-c cost] name faceId|faceUri
100 */
101 void
102 ribRegisterPrefix();
103
104 /**
105 * \brief Registers name to the faceId provided in faceCreateResult
106 *
107 */
108 void
109 ribRegisterPrefix(const ControlParameters& faceCreateResult);
110
111 /**
112 * \brief Unregisters name from the given faceId
113 *
114 * cmd format:
115 * name faceId
116 */
117 void
118 ribUnregisterPrefix();
119
120 /**
121 * \brief Creates new face
122 *
123 * This command allows creation of UDP unicast and TCP faces only
124 *
125 * cmd format:
126 * uri
hilata198cadb2014-02-15 23:46:19 -0600127 *
hilata198cadb2014-02-15 23:46:19 -0600128 */
129 void
hilata54e4eaf2014-04-10 23:38:33 -0500130 faceCreate();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700131
hilata198cadb2014-02-15 23:46:19 -0600132 /**
Obaiddca50792014-04-24 18:38:40 -0500133 * \brief Destroys face
hilata198cadb2014-02-15 23:46:19 -0600134 *
135 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500136 * faceId|faceUri
hilata198cadb2014-02-15 23:46:19 -0600137 *
hilata198cadb2014-02-15 23:46:19 -0600138 */
139 void
hilata54e4eaf2014-04-10 23:38:33 -0500140 faceDestroy();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700141
hilata141eaae2014-03-13 19:54:47 -0500142 /**
Obaiddca50792014-04-24 18:38:40 -0500143 * \brief Destroys face based on faceId provided in faceCreateResult
hilata141eaae2014-03-13 19:54:47 -0500144 *
145 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500146 * faceId|faceUri
147 *
148 */
149 void
150 faceDestroy(const ControlParameters& faceCreateResult);
151
152 /**
153 * \brief Sets the strategy for a namespace
154 *
155 * cmd format:
156 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500157 *
hilata141eaae2014-03-13 19:54:47 -0500158 */
159 void
hilata54e4eaf2014-04-10 23:38:33 -0500160 strategyChoiceSet();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700161
hilata141eaae2014-03-13 19:54:47 -0500162 /**
163 * \brief Unset the strategy for a namespace
164 *
hilata141eaae2014-03-13 19:54:47 -0500165 * cmd format:
Obaiddca50792014-04-24 18:38:40 -0500166 * name strategy
hilata141eaae2014-03-13 19:54:47 -0500167 *
hilata141eaae2014-03-13 19:54:47 -0500168 */
169 void
hilata54e4eaf2014-04-10 23:38:33 -0500170 strategyChoiceUnset();
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700171
hilata198cadb2014-02-15 23:46:19 -0600172private:
hilata54e4eaf2014-04-10 23:38:33 -0500173
hilata198cadb2014-02-15 23:46:19 -0600174 void
Obaiddca50792014-04-24 18:38:40 -0500175 onSuccess(const ControlParameters& commandSuccessResult,
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700176 const std::string& message);
hilata198cadb2014-02-15 23:46:19 -0600177
178 void
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700179 onError(uint32_t code, const std::string& error, const std::string& message);
180
Chengyu Fandae25302014-10-16 11:40:11 -0600181 void
182 onCanonizeFailure(const std::string& reason);
183
184 void
185 startFaceCreate(const ndn::util::FaceUri& canonicalUri);
186
187 void
188 startFaceDestroy(const ndn::util::FaceUri& canonicalUri);
189
190 void
191 startFibAddNextHop(const ndn::util::FaceUri& canonicalUri);
192
193 void
194 startRibRegisterPrefix(const ndn::util::FaceUri& canonicalUri);
195
hilata198cadb2014-02-15 23:46:19 -0600196public:
197 const char* m_programName;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700198
hilata54e4eaf2014-04-10 23:38:33 -0500199 // command parameters without leading 'cmd' component
Junxiao Shi22295032014-04-29 22:57:40 -0700200 const char* const* m_commandLineArguments;
hilata54e4eaf2014-04-10 23:38:33 -0500201 int m_nOptions;
Obaiddca50792014-04-24 18:38:40 -0500202 uint64_t m_flags;
203 uint64_t m_cost;
204 uint64_t m_faceId;
Syed Obaid4ae0ce32014-06-17 13:59:20 -0500205 uint64_t m_origin;
206 ndn::time::milliseconds m_expires;
Obaiddca50792014-04-24 18:38:40 -0500207 std::string m_name;
hilata54e4eaf2014-04-10 23:38:33 -0500208
Syed Obaid4ae0ce32014-06-17 13:59:20 -0500209
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700210private:
Junxiao Shi8e273ca2014-11-12 00:42:29 -0700211 ndn::KeyChain m_keyChain;
Alexander Afanasyev352e14e2014-03-27 16:02:12 -0700212 Controller m_controller;
Chengyu Fandae25302014-10-16 11:40:11 -0600213 boost::asio::io_service& m_ioService;
hilata198cadb2014-02-15 23:46:19 -0600214};
215
hilata141eaae2014-03-13 19:54:47 -0500216} // namespace nfdc
hilata198cadb2014-02-15 23:46:19 -0600217
218#endif // NFD_TOOLS_NFDC_HPP