blob: 6ae9abefee8c5eb52d0988a8344f516ccbe1bce4 [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi88a062d2017-01-26 03:10:05 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shid243d712016-08-19 06:45:31 +00004 * 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.
10 *
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 */
25
26#ifndef NFD_TOOLS_NFDC_LEGACY_NFDC_HPP
27#define NFD_TOOLS_NFDC_LEGACY_NFDC_HPP
28
Junxiao Shi737c43c2016-09-14 02:51:44 +000029#include "execute-command.hpp"
Junxiao Shi25c6ce42016-09-09 13:49:59 +000030#include <ndn-cxx/mgmt/nfd/controller.hpp>
Junxiao Shid243d712016-08-19 06:45:31 +000031
32namespace nfd {
33namespace tools {
34namespace nfdc {
35
36class LegacyNfdc : noncopyable
37{
38public:
39 static const time::milliseconds DEFAULT_EXPIRATION_PERIOD;
40 static const uint64_t DEFAULT_COST;
41
42 class Error : public std::runtime_error
43 {
44 public:
45 explicit
46 Error(const std::string& what)
47 : std::runtime_error(what)
48 {
49 }
50 };
51
Junxiao Shi737c43c2016-09-14 02:51:44 +000052 LegacyNfdc(Face& face, KeyChain& keyChain);
Junxiao Shid243d712016-08-19 06:45:31 +000053
54 bool
55 dispatch(const std::string& cmd);
56
57 /**
58 * \brief Adds a nexthop to a FIB entry
59 *
60 * If the FIB entry does not exist, it is inserted automatically
61 *
62 * cmd format:
63 * [-c cost] name faceId|faceUri
64 *
65 */
66 void
67 fibAddNextHop();
68
69 /**
70 * \brief Removes a nexthop from an existing FIB entry
71 *
72 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
73 *
74 * cmd format:
75 * name faceId
76 *
77 */
78 void
79 fibRemoveNextHop();
80
81 /**
82 * \brief Registers name to the given faceId or faceUri
83 *
84 * cmd format:
85 * [-I] [-C] [-c cost] name faceId|faceUri
86 */
87 void
88 ribRegisterPrefix();
89
90 /**
91 * \brief Unregisters name from the given faceId/faceUri
92 *
93 * cmd format:
94 * name faceId/faceUri
95 */
96 void
97 ribUnregisterPrefix();
98
99 /**
100 * \brief Creates new face
101 *
102 * This command allows creation of UDP unicast and TCP faces only
103 *
104 * cmd format:
105 * uri
106 *
107 */
108 void
109 faceCreate();
110
111 /**
112 * \brief Destroys face
113 *
114 * cmd format:
115 * faceId|faceUri
116 *
117 */
118 void
119 faceDestroy();
120
121 /**
122 * \brief Sets the strategy for a namespace
123 *
124 * cmd format:
125 * name strategy
126 *
127 */
128 void
129 strategyChoiceSet();
130
131 /**
132 * \brief Unset the strategy for a namespace
133 *
134 * cmd format:
135 * name strategy
136 *
137 */
138 void
139 strategyChoiceUnset();
140
141private:
Junxiao Shid243d712016-08-19 06:45:31 +0000142 void
143 onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
144 const std::string& message);
145
146 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000147 onError(const ndn::nfd::ControlResponse& response, const std::string& message);
Junxiao Shid243d712016-08-19 06:45:31 +0000148
149 void
150 onCanonizeFailure(const std::string& reason);
151
152 void
153 startFaceCreate(const ndn::util::FaceUri& canonicalUri);
154
155 void
156 onObtainFaceIdFailure(const std::string& message);
157
158public:
Junxiao Shi2f741322016-08-29 00:53:18 +0000159 std::vector<std::string> m_commandLineArguments; // positional arguments
Junxiao Shid243d712016-08-19 06:45:31 +0000160 uint64_t m_flags;
161 uint64_t m_cost;
162 uint64_t m_faceId;
163 uint64_t m_origin;
164 time::milliseconds m_expires;
165 std::string m_name;
166 ndn::nfd::FacePersistency m_facePersistency;
167
168private:
Junxiao Shi737c43c2016-09-14 02:51:44 +0000169 Face& m_face;
Junxiao Shid243d712016-08-19 06:45:31 +0000170 ndn::nfd::Controller m_controller;
171};
172
Junxiao Shi2f741322016-08-29 00:53:18 +0000173void
174legacyNfdcUsage();
175
Junxiao Shi88a062d2017-01-26 03:10:05 +0000176void
Junxiao Shid6958012017-02-20 03:34:48 +0000177legacyNfdcMain(ExecuteContext& ctx, const std::string& replacementCommand);
Junxiao Shi2f741322016-08-29 00:53:18 +0000178
Junxiao Shid243d712016-08-19 06:45:31 +0000179} // namespace nfdc
180} // namespace tools
181} // namespace nfd
182
183#endif // NFD_TOOLS_NFDC_LEGACY_NFDC_HPP