blob: 25371fd3a02ae059f85403e83e5395b49b9fb6c0 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi22f85682018-01-22 19:23:22 +00002/*
Eric Newberryce9c1952020-02-15 15:10:59 -08003 * Copyright (c) 2013-2020 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
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/mgmt/nfd/control-command.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/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
Junxiao Shi7357ef22016-09-07 02:39:37 +000030BOOST_AUTO_TEST_SUITE(Mgmt)
31BOOST_AUTO_TEST_SUITE(Nfd)
32BOOST_AUTO_TEST_SUITE(TestControlCommand)
Junxiao Shi5ec80222014-03-25 20:08:05 -070033
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000034BOOST_AUTO_TEST_CASE(FaceCreateRequest)
Junxiao Shi5ec80222014-03-25 20:08:05 -070035{
36 FaceCreateCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070037
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000038 // good with required fields only
Junxiao Shi5ec80222014-03-25 20:08:05 -070039 ControlParameters p1;
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000040 p1.setUri("tcp4://192.0.2.1:6363");
41 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
42 BOOST_CHECK(Name("/PREFIX/faces/create").isPrefixOf(command.getRequestName("/PREFIX", p1)));
Junxiao Shi5ec80222014-03-25 20:08:05 -070043
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000044 // good with optional fields
45 ControlParameters p2(p1);
46 p2.setLocalUri("tcp4://192.0.2.2:32114")
47 .setFacePersistency(FACE_PERSISTENCY_PERMANENT)
Eric Newberry07d05c92018-01-22 16:08:01 -070048 .setBaseCongestionMarkingInterval(100_ms)
49 .setDefaultCongestionThreshold(10000)
Eric Newberry3c9bc042018-06-02 17:58:10 -070050 .setMtu(8192)
Eric Newberryda916d62016-08-11 23:04:34 -070051 .setFlags(0x3)
52 .setMask(0x1);
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000053 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Yukai Tud93c5fc2015-08-25 11:37:16 +080054
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000055 // Uri is required
56 ControlParameters p3;
57 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
58
59 // Name is forbidden
60 ControlParameters p4(p1);
61 p4.setName("/example");
62 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
63
64 // Flags and Mask must be specified together
65 ControlParameters p5(p1);
66 p5.setFlags(0x3);
67 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
68
Eric Newberryce9c1952020-02-15 15:10:59 -080069 // Flags and Mask must be specified together
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000070 ControlParameters p6(p1);
71 p6.setMask(0x1);
72 BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError);
73}
74
75BOOST_AUTO_TEST_CASE(FaceCreateResponse)
76{
77 FaceCreateCommand command;
78
79 // good
80 ControlParameters p1;
81 p1.setFaceId(3208)
Junxiao Shi144c7e32017-04-20 01:04:06 +000082 .setUri("tcp4://192.0.2.1:6363")
83 .setLocalUri("tcp4://192.0.2.2:32114")
84 .setFacePersistency(FACE_PERSISTENCY_PERMANENT)
Eric Newberry07d05c92018-01-22 16:08:01 -070085 .setBaseCongestionMarkingInterval(500_ns)
86 .setDefaultCongestionThreshold(12345)
Eric Newberry3c9bc042018-06-02 17:58:10 -070087 .setMtu(2048)
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000088 .setFlags(0x3);
89 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Eric Newberryda916d62016-08-11 23:04:34 -070090
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000091 // Name is forbidden
92 ControlParameters p2(p1);
93 p2.setName("/example");
94 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Yukai Tud93c5fc2015-08-25 11:37:16 +080095
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000096 // Mask is forbidden
97 ControlParameters p3(p1);
98 p3.setMask(0x1);
99 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -0700100
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +0000101 // FaceId must be valid
102 ControlParameters p4(p1);
103 p4.setFaceId(INVALID_FACE_ID);
104 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -0700105
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +0000106 // LocalUri is required
107 ControlParameters p5(p1);
108 p5.unsetLocalUri();
109 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700110}
111
Yanbiao Licbdacb22016-08-02 16:02:35 +0800112BOOST_AUTO_TEST_CASE(FaceUpdate)
113{
114 FaceUpdateCommand command;
115
Eric Newberryce9c1952020-02-15 15:10:59 -0800116 // FaceId must be valid
Yanbiao Licbdacb22016-08-02 16:02:35 +0800117 ControlParameters p1;
118 p1.setFaceId(0);
Eric Newberryda916d62016-08-11 23:04:34 -0700119 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500120 p1.setFaceId(INVALID_FACE_ID);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700121 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800122
Eric Newberryce9c1952020-02-15 15:10:59 -0800123 // Persistency and Flags are required in response
Yanbiao Licbdacb22016-08-02 16:02:35 +0800124 p1.setFaceId(1);
125 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Eric Newberry138ef2c2016-08-15 20:29:03 -0700126 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
127 command.applyDefaultsToRequest(p1);
128 BOOST_CHECK_EQUAL(p1.getFaceId(), 1);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800129
Eric Newberryce9c1952020-02-15 15:10:59 -0800130 // Good request, bad response (Mask is forbidden but present)
Yanbiao Licbdacb22016-08-02 16:02:35 +0800131 ControlParameters p2;
132 p2.setFaceId(1)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700133 .setFacePersistency(FACE_PERSISTENCY_PERSISTENT)
Eric Newberry07d05c92018-01-22 16:08:01 -0700134 .setBaseCongestionMarkingInterval(765_ns)
135 .setDefaultCongestionThreshold(54321)
Eric Newberryce9c1952020-02-15 15:10:59 -0800136 .setMtu(8192)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700137 .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800138 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberryce9c1952020-02-15 15:10:59 -0800139 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800140
Eric Newberryce9c1952020-02-15 15:10:59 -0800141 // Flags without Mask (good response, bad request)
Eric Newberryda916d62016-08-11 23:04:34 -0700142 p2.unsetMask();
143 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700144 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
145
Eric Newberryce9c1952020-02-15 15:10:59 -0800146 // FaceId is optional in request
Eric Newberry138ef2c2016-08-15 20:29:03 -0700147 p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
148 p2.unsetFaceId();
149 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberryda916d62016-08-11 23:04:34 -0700150
Eric Newberryce9c1952020-02-15 15:10:59 -0800151 // Name is forbidden
Yanbiao Licbdacb22016-08-02 16:02:35 +0800152 ControlParameters p3;
Eric Newberryda916d62016-08-11 23:04:34 -0700153 p3.setFaceId(1)
154 .setName("/ndn/name");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800155 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
156 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
157
Eric Newberryce9c1952020-02-15 15:10:59 -0800158 // Uri is forbidden
Yanbiao Licbdacb22016-08-02 16:02:35 +0800159 ControlParameters p4;
160 p4.setFaceId(1)
Eric Newberryda916d62016-08-11 23:04:34 -0700161 .setUri("tcp4://192.0.2.1");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800162 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
163 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
164
Eric Newberryce9c1952020-02-15 15:10:59 -0800165 // Empty request is valid, empty response is invalid
Yanbiao Licbdacb22016-08-02 16:02:35 +0800166 ControlParameters p5;
Eric Newberry138ef2c2016-08-15 20:29:03 -0700167 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
168 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
169 BOOST_CHECK(!p5.hasFaceId());
Eric Newberryce9c1952020-02-15 15:10:59 -0800170
171 // Default request, not valid response due to missing FacePersistency and Flags
Eric Newberry138ef2c2016-08-15 20:29:03 -0700172 command.applyDefaultsToRequest(p5);
173 BOOST_REQUIRE(p5.hasFaceId());
174 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
175 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
176 BOOST_CHECK_EQUAL(p5.getFaceId(), 0);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800177}
178
Junxiao Shi5ec80222014-03-25 20:08:05 -0700179BOOST_AUTO_TEST_CASE(FaceDestroy)
180{
181 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700182
Eric Newberryce9c1952020-02-15 15:10:59 -0800183 // Uri is forbidden
Junxiao Shi5ec80222014-03-25 20:08:05 -0700184 ControlParameters p1;
185 p1.setUri("tcp4://192.0.2.1")
186 .setFaceId(4);
187 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
188 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
189
Eric Newberryce9c1952020-02-15 15:10:59 -0800190 // FaceId must be valid
Junxiao Shi5ec80222014-03-25 20:08:05 -0700191 ControlParameters p2;
Davide Pesaventof8503d22017-02-17 01:19:10 -0500192 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700193 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
194 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
195
Eric Newberryce9c1952020-02-15 15:10:59 -0800196 // Good request, good response
Junxiao Shi5ec80222014-03-25 20:08:05 -0700197 ControlParameters p3;
198 p3.setFaceId(6);
199 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
200 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700201 Name n3;
202 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
203 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700204}
205
Junxiao Shi5ec80222014-03-25 20:08:05 -0700206BOOST_AUTO_TEST_CASE(FibAddNextHop)
207{
208 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700209
Eric Newberryce9c1952020-02-15 15:10:59 -0800210 // Cost required in response
Junxiao Shi5ec80222014-03-25 20:08:05 -0700211 ControlParameters p1;
212 p1.setName("ndn:/")
213 .setFaceId(22);
214 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
215 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700216 Name n1;
217 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
218 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700219
Eric Newberryce9c1952020-02-15 15:10:59 -0800220 // Good request, bad response (FaceId must be valid)
Junxiao Shi5ec80222014-03-25 20:08:05 -0700221 ControlParameters p2;
222 p2.setName("ndn:/example")
223 .setFaceId(0)
224 .setCost(6);
225 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500226 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700227 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
228
Eric Newberryce9c1952020-02-15 15:10:59 -0800229 // Default request
Junxiao Shi5ec80222014-03-25 20:08:05 -0700230 command.applyDefaultsToRequest(p1);
231 BOOST_REQUIRE(p1.hasCost());
232 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700233
Eric Newberryce9c1952020-02-15 15:10:59 -0800234 // FaceId optional in request
Junxiao Shicaac54e2014-05-20 15:27:01 -0700235 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(FibRemoveNextHop)
243{
244 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700245
Eric Newberryce9c1952020-02-15 15:10:59 -0800246 // Good request, good response
Junxiao Shi5ec80222014-03-25 20:08:05 -0700247 ControlParameters p1;
248 p1.setName("ndn:/")
249 .setFaceId(22);
250 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
251 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700252 Name n1;
253 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
254 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700255
Eric Newberryce9c1952020-02-15 15:10:59 -0800256 // Good request, bad response (FaceId must be valid)
Junxiao Shi5ec80222014-03-25 20:08:05 -0700257 ControlParameters p2;
258 p2.setName("ndn:/example")
259 .setFaceId(0);
260 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500261 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700262 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700263
Eric Newberryce9c1952020-02-15 15:10:59 -0800264 // FaceId is optional in request
Junxiao Shicaac54e2014-05-20 15:27:01 -0700265 p1.unsetFaceId();
266 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
267 command.applyDefaultsToRequest(p1);
268 BOOST_REQUIRE(p1.hasFaceId());
269 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700270}
271
Junxiao Shi22f85682018-01-22 19:23:22 +0000272BOOST_AUTO_TEST_CASE(CsConfigRequest)
273{
274 CsConfigCommand command;
275
276 // good empty request
277 ControlParameters p1;
278 command.validateRequest(p1);
279 BOOST_CHECK(Name("/PREFIX/cs/config").isPrefixOf(command.getRequestName("/PREFIX", p1)));
280
281 // good full request
282 ControlParameters p2;
283 p2.setCapacity(1574);
284 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
285 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
286 command.validateRequest(p2);
287
288 // bad request: Flags but no Mask
289 ControlParameters p3(p2);
290 p3.unsetMask();
291 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
292
293 // bad request: Mask but no Flags
294 ControlParameters p4(p2);
295 p4.unsetFlags();
296 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
297
298 // bad request: forbidden field
299 ControlParameters p5(p2);
300 p5.setName("/example");
301 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
302}
303
304BOOST_AUTO_TEST_CASE(CsConfigResponse)
305{
306 CsConfigCommand command;
307
308 // bad empty response
309 ControlParameters p1;
310 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
311
312 // bad response: Mask not allowed
313 ControlParameters p2;
314 p2.setCapacity(1574);
315 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
316 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
317 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
318
319 // good response
320 ControlParameters p3(p2);
321 p3.unsetMask();
322 command.validateResponse(p3);
323}
324
Junxiao Shidf505382018-03-04 13:40:44 +0000325BOOST_AUTO_TEST_CASE(CsEraseRequest)
326{
327 CsEraseCommand command;
328
329 // good no-limit request
330 ControlParameters p1;
331 p1.setName("/u4LYPNU8Q");
332 command.validateRequest(p1);
333 BOOST_CHECK(Name("/PREFIX/cs/erase").isPrefixOf(command.getRequestName("/PREFIX", p1)));
334
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500335 // good limited request
Junxiao Shidf505382018-03-04 13:40:44 +0000336 ControlParameters p2;
337 p2.setName("/IMw1RaLF");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500338 p2.setCount(177);
Junxiao Shidf505382018-03-04 13:40:44 +0000339 command.validateRequest(p2);
340
341 // bad request: zero entry
342 ControlParameters p3;
343 p3.setName("/ahMID1jcib");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500344 p3.setCount(0);
Junxiao Shidf505382018-03-04 13:40:44 +0000345 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
346
347 // bad request: forbidden field
348 ControlParameters p4(p2);
349 p4.setCapacity(278);
350 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
351}
352
353BOOST_AUTO_TEST_CASE(CsEraseResponse)
354{
355 CsEraseCommand command;
356
357 // good normal response
358 ControlParameters p1;
359 p1.setName("/TwiIwCdR");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500360 p1.setCount(1);
Junxiao Shidf505382018-03-04 13:40:44 +0000361 command.validateResponse(p1);
362
363 // good limit exceeded request
364 ControlParameters p2;
365 p2.setName("/NMsiy44pr");
366 p2.setCapacity(360);
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500367 p2.setCount(360);
Junxiao Shidf505382018-03-04 13:40:44 +0000368 command.validateResponse(p2);
369
370 // good zero-entry response
371 ControlParameters p3;
372 p3.setName("/5f1LRPh1L");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500373 p3.setCount(0);
Junxiao Shidf505382018-03-04 13:40:44 +0000374 command.validateResponse(p3);
375
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500376 // bad request: missing Count
Junxiao Shidf505382018-03-04 13:40:44 +0000377 ControlParameters p4(p1);
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500378 p4.unsetCount();
Junxiao Shidf505382018-03-04 13:40:44 +0000379 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
380
381 // bad request: zero capacity
382 ControlParameters p5(p1);
383 p5.setCapacity(0);
384 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
Junxiao Shidf505382018-03-04 13:40:44 +0000385}
386
Junxiao Shi5ec80222014-03-25 20:08:05 -0700387BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
388{
389 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700390
Eric Newberryce9c1952020-02-15 15:10:59 -0800391 // Good request, good response
Junxiao Shi5ec80222014-03-25 20:08:05 -0700392 ControlParameters p1;
393 p1.setName("ndn:/")
394 .setStrategy("ndn:/strategy/P");
395 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
396 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700397 Name n1;
398 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
399 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700400
Eric Newberryce9c1952020-02-15 15:10:59 -0800401 // Strategy is required in both requests and responses
Junxiao Shi5ec80222014-03-25 20:08:05 -0700402 ControlParameters p2;
403 p2.setName("ndn:/example");
404 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
405 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
406}
407
408BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
409{
410 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700411
Eric Newberryce9c1952020-02-15 15:10:59 -0800412 // Good request, good response
Junxiao Shi5ec80222014-03-25 20:08:05 -0700413 ControlParameters p1;
414 p1.setName("ndn:/example");
415 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
416 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700417 Name n1;
418 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
419 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700420
Eric Newberryce9c1952020-02-15 15:10:59 -0800421 // Strategy is forbidden
Junxiao Shi5ec80222014-03-25 20:08:05 -0700422 ControlParameters p2;
423 p2.setName("ndn:/example")
424 .setStrategy("ndn:/strategy/P");
425 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
426 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
427
Eric Newberryce9c1952020-02-15 15:10:59 -0800428 // Name must have at least one component
Junxiao Shi5ec80222014-03-25 20:08:05 -0700429 ControlParameters p3;
430 p3.setName("ndn:/");
431 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
432 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
433}
434
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700435BOOST_AUTO_TEST_CASE(RibRegister)
436{
437 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700438
Eric Newberryce9c1952020-02-15 15:10:59 -0800439 // Good request, response missing many fields
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700440 ControlParameters p1;
441 p1.setName("ndn:/");
442 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
443 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700444 Name n1;
445 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
446 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700447
Eric Newberryce9c1952020-02-15 15:10:59 -0800448 // Default request
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700449 command.applyDefaultsToRequest(p1);
450 BOOST_REQUIRE(p1.hasOrigin());
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400451 BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700452 BOOST_REQUIRE(p1.hasCost());
453 BOOST_CHECK_EQUAL(p1.getCost(), 0);
454 BOOST_REQUIRE(p1.hasFlags());
455 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700456 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700457
Eric Newberryce9c1952020-02-15 15:10:59 -0800458 // Good request, good response
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700459 ControlParameters p2;
460 p2.setName("ndn:/example")
461 .setFaceId(2)
462 .setCost(6);
463 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
464 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700465 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700466 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
467}
468
469BOOST_AUTO_TEST_CASE(RibUnregister)
470{
471 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700472
Eric Newberryce9c1952020-02-15 15:10:59 -0800473 // Good request, good response
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700474 ControlParameters p1;
475 p1.setName("ndn:/")
476 .setFaceId(22)
477 .setOrigin(ROUTE_ORIGIN_STATIC);
478 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
479 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700480 Name n1;
481 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
482 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700483
Eric Newberryce9c1952020-02-15 15:10:59 -0800484 // Good request, bad response (FaceId must be valid)
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700485 ControlParameters p2;
486 p2.setName("ndn:/example")
487 .setFaceId(0)
488 .setOrigin(ROUTE_ORIGIN_APP);
489 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500490 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700491 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
492
Eric Newberryce9c1952020-02-15 15:10:59 -0800493 // FaceId is optional in request, required in response
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700494 p2.unsetFaceId();
495 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
496 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
497}
498
Junxiao Shi7357ef22016-09-07 02:39:37 +0000499BOOST_AUTO_TEST_SUITE_END() // TestControlCommand
500BOOST_AUTO_TEST_SUITE_END() // Nfd
501BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi5ec80222014-03-25 20:08:05 -0700502
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800503} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700504} // namespace nfd
505} // namespace ndn