blob: 5a804a17f483fe0a5111db7ca086ddc9dbea0b3a [file] [log] [blame]
Junxiao Shid243d712016-08-19 06:45:31 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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.
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
29#include "core/common.hpp"
30#include <ndn-cxx/face.hpp>
31#include <ndn-cxx/security/key-chain.hpp>
32#include <ndn-cxx/management/nfd-controller.hpp>
33
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
54 explicit
55 LegacyNfdc(ndn::Face& face);
56
57 bool
58 dispatch(const std::string& cmd);
59
60 /**
61 * \brief Adds a nexthop to a FIB entry
62 *
63 * If the FIB entry does not exist, it is inserted automatically
64 *
65 * cmd format:
66 * [-c cost] name faceId|faceUri
67 *
68 */
69 void
70 fibAddNextHop();
71
72 /**
73 * \brief Removes a nexthop from an existing FIB entry
74 *
75 * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
76 *
77 * cmd format:
78 * name faceId
79 *
80 */
81 void
82 fibRemoveNextHop();
83
84 /**
85 * \brief Registers name to the given faceId or faceUri
86 *
87 * cmd format:
88 * [-I] [-C] [-c cost] name faceId|faceUri
89 */
90 void
91 ribRegisterPrefix();
92
93 /**
94 * \brief Unregisters name from the given faceId/faceUri
95 *
96 * cmd format:
97 * name faceId/faceUri
98 */
99 void
100 ribUnregisterPrefix();
101
102 /**
103 * \brief Creates new face
104 *
105 * This command allows creation of UDP unicast and TCP faces only
106 *
107 * cmd format:
108 * uri
109 *
110 */
111 void
112 faceCreate();
113
114 /**
115 * \brief Destroys face
116 *
117 * cmd format:
118 * faceId|faceUri
119 *
120 */
121 void
122 faceDestroy();
123
124 /**
125 * \brief Sets the strategy for a namespace
126 *
127 * cmd format:
128 * name strategy
129 *
130 */
131 void
132 strategyChoiceSet();
133
134 /**
135 * \brief Unset the strategy for a namespace
136 *
137 * cmd format:
138 * name strategy
139 *
140 */
141 void
142 strategyChoiceUnset();
143
144private:
Junxiao Shid243d712016-08-19 06:45:31 +0000145 void
146 onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
147 const std::string& message);
148
149 void
Junxiao Shi29b41282016-08-22 03:47:02 +0000150 onError(const ndn::nfd::ControlResponse& response, const std::string& message);
Junxiao Shid243d712016-08-19 06:45:31 +0000151
152 void
153 onCanonizeFailure(const std::string& reason);
154
155 void
156 startFaceCreate(const ndn::util::FaceUri& canonicalUri);
157
158 void
159 onObtainFaceIdFailure(const std::string& message);
160
161public:
162 const char* m_programName;
163
164 // command parameters without leading 'cmd' component
165 const char* const* m_commandLineArguments;
166 int m_nOptions;
167 uint64_t m_flags;
168 uint64_t m_cost;
169 uint64_t m_faceId;
170 uint64_t m_origin;
171 time::milliseconds m_expires;
172 std::string m_name;
173 ndn::nfd::FacePersistency m_facePersistency;
174
175private:
176 ndn::KeyChain m_keyChain;
177 ndn::Face& m_face;
178 ndn::nfd::Controller m_controller;
179};
180
181} // namespace nfdc
182} // namespace tools
183} // namespace nfd
184
185#endif // NFD_TOOLS_NFDC_LEGACY_NFDC_HPP