blob: ada0a7d9be3a98b0e3c86a7ea37d79930103c0d0 [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"
Davide Pesavento22db5392017-04-14 00:56:43 -040030
31#include <ndn-cxx/encoding/nfd-constants.hpp>
Junxiao Shi25c6ce42016-09-09 13:49:59 +000032#include <ndn-cxx/mgmt/nfd/controller.hpp>
Junxiao Shid243d712016-08-19 06:45:31 +000033
34namespace nfd {
35namespace tools {
36namespace nfdc {
37
38class LegacyNfdc : noncopyable
39{
40public:
41 static const time::milliseconds DEFAULT_EXPIRATION_PERIOD;
42 static const uint64_t DEFAULT_COST;
43
44 class Error : public std::runtime_error
45 {
46 public:
47 explicit
48 Error(const std::string& what)
49 : std::runtime_error(what)
50 {
51 }
52 };
53
Junxiao Shi737c43c2016-09-14 02:51:44 +000054 LegacyNfdc(Face& face, KeyChain& keyChain);
Junxiao Shid243d712016-08-19 06:45:31 +000055
56 bool
57 dispatch(const std::string& cmd);
58
59 /**
60 * \brief Adds a nexthop to a FIB entry
61 *
62 * If the FIB entry does not exist, it is inserted automatically
63 *
64 * cmd format:
65 * [-c cost] name faceId|faceUri
66 *
67 */
68 void
69 fibAddNextHop();
70
71 /**
72 * \brief Removes a nexthop from an existing FIB entry
73 *
74 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
75 *
76 * cmd format:
77 * name faceId
78 *
79 */
80 void
81 fibRemoveNextHop();
82
83 /**
84 * \brief Registers name to the given faceId or faceUri
85 *
86 * cmd format:
87 * [-I] [-C] [-c cost] name faceId|faceUri
88 */
89 void
90 ribRegisterPrefix();
91
92 /**
93 * \brief Unregisters name from the given faceId/faceUri
94 *
95 * cmd format:
96 * name faceId/faceUri
97 */
98 void
99 ribUnregisterPrefix();
100
101 /**
102 * \brief Creates new face
103 *
104 * This command allows creation of UDP unicast and TCP faces only
105 *
106 * cmd format:
107 * uri
108 *
109 */
110 void
111 faceCreate();
112
113 /**
114 * \brief Destroys face
115 *
116 * cmd format:
117 * faceId|faceUri
118 *
119 */
120 void
121 faceDestroy();
122
123 /**
124 * \brief Sets the strategy for a namespace
125 *
126 * cmd format:
127 * name strategy
128 *
129 */
130 void
131 strategyChoiceSet();
132
133 /**
134 * \brief Unset the strategy for a namespace
135 *
136 * cmd format:
137 * name strategy
138 *
139 */
140 void
141 strategyChoiceUnset();
142
143private:
Junxiao Shid243d712016-08-19 06:45:31 +0000144 void
145 onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
146 const std::string& message);
147
148 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000149 onError(const ndn::nfd::ControlResponse& response, const std::string& message);
Junxiao Shid243d712016-08-19 06:45:31 +0000150
151 void
152 onCanonizeFailure(const std::string& reason);
153
154 void
155 startFaceCreate(const ndn::util::FaceUri& canonicalUri);
156
157 void
158 onObtainFaceIdFailure(const std::string& message);
159
160public:
Junxiao Shi2f741322016-08-29 00:53:18 +0000161 std::vector<std::string> m_commandLineArguments; // positional arguments
Junxiao Shid243d712016-08-19 06:45:31 +0000162 uint64_t m_flags;
163 uint64_t m_cost;
164 uint64_t m_faceId;
Davide Pesavento22db5392017-04-14 00:56:43 -0400165 ndn::nfd::RouteOrigin m_origin;
Junxiao Shid243d712016-08-19 06:45:31 +0000166 time::milliseconds m_expires;
167 std::string m_name;
168 ndn::nfd::FacePersistency m_facePersistency;
169
170private:
Junxiao Shi737c43c2016-09-14 02:51:44 +0000171 Face& m_face;
Junxiao Shid243d712016-08-19 06:45:31 +0000172 ndn::nfd::Controller m_controller;
173};
174
Junxiao Shi2f741322016-08-29 00:53:18 +0000175void
176legacyNfdcUsage();
177
Junxiao Shi88a062d2017-01-26 03:10:05 +0000178void
Junxiao Shid6958012017-02-20 03:34:48 +0000179legacyNfdcMain(ExecuteContext& ctx, const std::string& replacementCommand);
Junxiao Shi2f741322016-08-29 00:53:18 +0000180
Junxiao Shid243d712016-08-19 06:45:31 +0000181} // namespace nfdc
182} // namespace tools
183} // namespace nfd
184
185#endif // NFD_TOOLS_NFDC_LEGACY_NFDC_HPP