blob: 67696b21181592de3d6364f0d2848e50df493680 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi5ec80222014-03-25 20:08:05 -07002/**
Yanbiao Licbdacb22016-08-02 16:02:35 +08003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Junxiao Shi5ec80222014-03-25 20:08:05 -070020 */
21
22#include "management/nfd-control-command.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070023
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070025
26namespace ndn {
27namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Junxiao Shi5ec80222014-03-25 20:08:05 -070029
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030BOOST_AUTO_TEST_SUITE(ManagementNfdControlCommand)
Junxiao Shi5ec80222014-03-25 20:08:05 -070031
32BOOST_AUTO_TEST_CASE(FaceCreate)
33{
34 FaceCreateCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070035
36 ControlParameters p1;
37 p1.setUri("tcp4://192.0.2.1")
38 .setFaceId(4);
39 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
Yukai Tud93c5fc2015-08-25 11:37:16 +080040 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -070041
42 ControlParameters p2;
43 p2.setName("ndn:/example");
44 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
45 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
46
47 ControlParameters p3;
48 p3.setUri("tcp4://192.0.2.1")
49 .setFaceId(0);
50 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -070051
52 ControlParameters p4;
Yukai Tud93c5fc2015-08-25 11:37:16 +080053 p4.setUri("tcp4://192.0.2.1")
54 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
55 BOOST_CHECK_NO_THROW(command.validateRequest(p4));
56
57 p4.unsetFacePersistency();
58 BOOST_CHECK_NO_THROW(command.validateRequest(p4));
59 command.applyDefaultsToRequest(p4);
60 BOOST_REQUIRE(p4.hasFacePersistency());
61 BOOST_CHECK_EQUAL(p4.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
62
63 ControlParameters p5;
64 p5.setUri("tcp4://192.0.2.1")
65 .setFaceId(4)
66 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
67 BOOST_CHECK_NO_THROW(command.validateResponse(p5));
68
69 ControlParameters p6;
70 p6.setUri("tcp4://192.0.2.1:6363");
71 Name n6;
72 BOOST_CHECK_NO_THROW(n6 = command.getRequestName("/PREFIX", p6));
73 BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n6));
Junxiao Shi5ec80222014-03-25 20:08:05 -070074}
75
Yanbiao Licbdacb22016-08-02 16:02:35 +080076BOOST_AUTO_TEST_CASE(FaceUpdate)
77{
78 FaceUpdateCommand command;
79
80 ControlParameters p1;
81 p1.setFaceId(0);
82 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
83 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
84
85 p1.setFaceId(1);
86 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
87 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
88
89 ControlParameters p2;
90 p2.setFaceId(1)
91 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
92 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
93 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
94
95 ControlParameters p3;
96 p3.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
97 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
98 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
99
100 ControlParameters p4;
101 p4.setFaceId(1)
102 .setName("/ndn/name");
103 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
104 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
105
106 ControlParameters p5;
107 p5.setFaceId(1)
108 .setUri("tcp4://192.0.2.1");
109 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
110 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
111}
112
Junxiao Shi5ec80222014-03-25 20:08:05 -0700113BOOST_AUTO_TEST_CASE(FaceDestroy)
114{
115 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700116
117 ControlParameters p1;
118 p1.setUri("tcp4://192.0.2.1")
119 .setFaceId(4);
120 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
121 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
122
123 ControlParameters p2;
124 p2.setFaceId(0);
125 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
126 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
127
128 ControlParameters p3;
129 p3.setFaceId(6);
130 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
131 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700132 Name n3;
133 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
134 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700135}
136
137BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
138{
139 FaceEnableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700140
141 ControlParameters p1;
142 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
143 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
144 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700145 Name n1;
146 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
147 BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700148
149 ControlParameters p2;
150 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
151 .setFaceId(9);
152 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
153 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700154
155 ControlParameters p3;
156 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
157 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
158 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700159}
160
161BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
162{
163 FaceDisableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700164
165 ControlParameters p1;
166 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
167 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
168 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700169 Name n1;
170 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
171 BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700172
173 ControlParameters p2;
174 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
175 .setFaceId(9);
176 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
177 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700178
179 ControlParameters p3;
180 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
181 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
182 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700183}
184
185BOOST_AUTO_TEST_CASE(FibAddNextHop)
186{
187 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700188
189 ControlParameters p1;
190 p1.setName("ndn:/")
191 .setFaceId(22);
192 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
193 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700194 Name n1;
195 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
196 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700197
198 ControlParameters p2;
199 p2.setName("ndn:/example")
200 .setFaceId(0)
201 .setCost(6);
202 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
203 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
204
205 command.applyDefaultsToRequest(p1);
206 BOOST_REQUIRE(p1.hasCost());
207 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700208
209 p1.unsetFaceId();
210 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
211 command.applyDefaultsToRequest(p1);
212 BOOST_REQUIRE(p1.hasFaceId());
213 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700214}
215
216BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
217{
218 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700219
220 ControlParameters p1;
221 p1.setName("ndn:/")
222 .setFaceId(22);
223 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
224 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700225 Name n1;
226 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
227 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700228
229 ControlParameters p2;
230 p2.setName("ndn:/example")
231 .setFaceId(0);
232 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
233 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700234
235 p1.unsetFaceId();
236 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
237 command.applyDefaultsToRequest(p1);
238 BOOST_REQUIRE(p1.hasFaceId());
239 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700240}
241
242BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
243{
244 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700245
246 ControlParameters p1;
247 p1.setName("ndn:/")
248 .setStrategy("ndn:/strategy/P");
249 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
250 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700251 Name n1;
252 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
253 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700254
255 ControlParameters p2;
256 p2.setName("ndn:/example");
257 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
258 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
259}
260
261BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
262{
263 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700264
265 ControlParameters p1;
266 p1.setName("ndn:/example");
267 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
268 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700269 Name n1;
270 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
271 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700272
273 ControlParameters p2;
274 p2.setName("ndn:/example")
275 .setStrategy("ndn:/strategy/P");
276 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
277 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
278
279 ControlParameters p3;
280 p3.setName("ndn:/");
281 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
282 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
283}
284
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700285BOOST_AUTO_TEST_CASE(RibRegister)
286{
287 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700288
289 ControlParameters p1;
290 p1.setName("ndn:/");
291 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
292 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700293 Name n1;
294 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
295 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700296
297 command.applyDefaultsToRequest(p1);
298 BOOST_REQUIRE(p1.hasOrigin());
299 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
300 BOOST_REQUIRE(p1.hasCost());
301 BOOST_CHECK_EQUAL(p1.getCost(), 0);
302 BOOST_REQUIRE(p1.hasFlags());
303 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700304 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700305
306 ControlParameters p2;
307 p2.setName("ndn:/example")
308 .setFaceId(2)
309 .setCost(6);
310 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
311 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700312 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700313 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
314}
315
316BOOST_AUTO_TEST_CASE(RibUnregister)
317{
318 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700319
320 ControlParameters p1;
321 p1.setName("ndn:/")
322 .setFaceId(22)
323 .setOrigin(ROUTE_ORIGIN_STATIC);
324 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
325 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700326 Name n1;
327 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
328 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700329
330 ControlParameters p2;
331 p2.setName("ndn:/example")
332 .setFaceId(0)
333 .setOrigin(ROUTE_ORIGIN_APP);
334 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
335 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
336
337 p2.unsetFaceId();
338 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
339 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
340}
341
Junxiao Shi5ec80222014-03-25 20:08:05 -0700342BOOST_AUTO_TEST_SUITE_END()
343
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800344} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700345} // namespace nfd
346} // namespace ndn