blob: 4db3752464ce0498d6a86cecb3e0b29bd5d40ea0 [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/*
3 * Copyright (c) 2013-2018 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
Junxiao Shi7357ef22016-09-07 02:39:37 +000022#include "mgmt/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
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
69 ControlParameters p6(p1);
70 p6.setMask(0x1);
71 BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError);
72}
73
74BOOST_AUTO_TEST_CASE(FaceCreateResponse)
75{
76 FaceCreateCommand command;
77
78 // good
79 ControlParameters p1;
80 p1.setFaceId(3208)
Junxiao Shi144c7e32017-04-20 01:04:06 +000081 .setUri("tcp4://192.0.2.1:6363")
82 .setLocalUri("tcp4://192.0.2.2:32114")
83 .setFacePersistency(FACE_PERSISTENCY_PERMANENT)
Eric Newberry07d05c92018-01-22 16:08:01 -070084 .setBaseCongestionMarkingInterval(500_ns)
85 .setDefaultCongestionThreshold(12345)
Eric Newberry3c9bc042018-06-02 17:58:10 -070086 .setMtu(2048)
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000087 .setFlags(0x3);
88 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Eric Newberryda916d62016-08-11 23:04:34 -070089
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000090 // Name is forbidden
91 ControlParameters p2(p1);
92 p2.setName("/example");
93 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Yukai Tud93c5fc2015-08-25 11:37:16 +080094
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000095 // Mask is forbidden
96 ControlParameters p3(p1);
97 p3.setMask(0x1);
98 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -070099
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +0000100 // FaceId must be valid
101 ControlParameters p4(p1);
102 p4.setFaceId(INVALID_FACE_ID);
103 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -0700104
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +0000105 // LocalUri is required
106 ControlParameters p5(p1);
107 p5.unsetLocalUri();
108 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700109}
110
Yanbiao Licbdacb22016-08-02 16:02:35 +0800111BOOST_AUTO_TEST_CASE(FaceUpdate)
112{
113 FaceUpdateCommand command;
114
115 ControlParameters p1;
116 p1.setFaceId(0);
Eric Newberryda916d62016-08-11 23:04:34 -0700117 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500118 p1.setFaceId(INVALID_FACE_ID);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700119 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800120
121 p1.setFaceId(1);
122 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Eric Newberry138ef2c2016-08-15 20:29:03 -0700123 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
124 command.applyDefaultsToRequest(p1);
125 BOOST_CHECK_EQUAL(p1.getFaceId(), 1);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800126
127 ControlParameters p2;
128 p2.setFaceId(1)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700129 .setFacePersistency(FACE_PERSISTENCY_PERSISTENT)
Eric Newberry07d05c92018-01-22 16:08:01 -0700130 .setBaseCongestionMarkingInterval(765_ns)
131 .setDefaultCongestionThreshold(54321)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700132 .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800133 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberry138ef2c2016-08-15 20:29:03 -0700134 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); // Mask forbidden but present
Yanbiao Licbdacb22016-08-02 16:02:35 +0800135
Eric Newberry138ef2c2016-08-15 20:29:03 -0700136 // Flags without Mask
Eric Newberryda916d62016-08-11 23:04:34 -0700137 p2.unsetMask();
138 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700139 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
140
141 p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
142 p2.unsetFaceId();
143 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberryda916d62016-08-11 23:04:34 -0700144
Yanbiao Licbdacb22016-08-02 16:02:35 +0800145 ControlParameters p3;
Eric Newberryda916d62016-08-11 23:04:34 -0700146 p3.setFaceId(1)
147 .setName("/ndn/name");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800148 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
149 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
150
151 ControlParameters p4;
152 p4.setFaceId(1)
Eric Newberryda916d62016-08-11 23:04:34 -0700153 .setUri("tcp4://192.0.2.1");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800154 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
155 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
156
157 ControlParameters p5;
Eric Newberry138ef2c2016-08-15 20:29:03 -0700158 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
159 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
160 BOOST_CHECK(!p5.hasFaceId());
161 command.applyDefaultsToRequest(p5);
162 BOOST_REQUIRE(p5.hasFaceId());
163 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
164 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
165 BOOST_CHECK_EQUAL(p5.getFaceId(), 0);
Eric Newberry3c9bc042018-06-02 17:58:10 -0700166
167 ControlParameters p6;
168 p6.setFaceId(1)
169 .setMtu(1024);
170 BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError);
171 BOOST_CHECK_THROW(command.validateResponse(p6), ControlCommand::ArgumentError);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800172}
173
Junxiao Shi5ec80222014-03-25 20:08:05 -0700174BOOST_AUTO_TEST_CASE(FaceDestroy)
175{
176 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700177
178 ControlParameters p1;
179 p1.setUri("tcp4://192.0.2.1")
180 .setFaceId(4);
181 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
182 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
183
184 ControlParameters p2;
Davide Pesaventof8503d22017-02-17 01:19:10 -0500185 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700186 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
187 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
188
189 ControlParameters p3;
190 p3.setFaceId(6);
191 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
192 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700193 Name n3;
194 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
195 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700196}
197
Junxiao Shi5ec80222014-03-25 20:08:05 -0700198BOOST_AUTO_TEST_CASE(FibAddNextHop)
199{
200 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700201
202 ControlParameters p1;
203 p1.setName("ndn:/")
204 .setFaceId(22);
205 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
206 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700207 Name n1;
208 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
209 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700210
211 ControlParameters p2;
212 p2.setName("ndn:/example")
213 .setFaceId(0)
214 .setCost(6);
215 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500216 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700217 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
218
219 command.applyDefaultsToRequest(p1);
220 BOOST_REQUIRE(p1.hasCost());
221 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700222
223 p1.unsetFaceId();
224 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
225 command.applyDefaultsToRequest(p1);
226 BOOST_REQUIRE(p1.hasFaceId());
227 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700228}
229
230BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
231{
232 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700233
234 ControlParameters p1;
235 p1.setName("ndn:/")
236 .setFaceId(22);
237 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
238 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700239 Name n1;
240 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
241 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700242
243 ControlParameters p2;
244 p2.setName("ndn:/example")
245 .setFaceId(0);
246 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500247 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700248 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700249
250 p1.unsetFaceId();
251 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
252 command.applyDefaultsToRequest(p1);
253 BOOST_REQUIRE(p1.hasFaceId());
254 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700255}
256
Junxiao Shi22f85682018-01-22 19:23:22 +0000257BOOST_AUTO_TEST_CASE(CsConfigRequest)
258{
259 CsConfigCommand command;
260
261 // good empty request
262 ControlParameters p1;
263 command.validateRequest(p1);
264 BOOST_CHECK(Name("/PREFIX/cs/config").isPrefixOf(command.getRequestName("/PREFIX", p1)));
265
266 // good full request
267 ControlParameters p2;
268 p2.setCapacity(1574);
269 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
270 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
271 command.validateRequest(p2);
272
273 // bad request: Flags but no Mask
274 ControlParameters p3(p2);
275 p3.unsetMask();
276 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
277
278 // bad request: Mask but no Flags
279 ControlParameters p4(p2);
280 p4.unsetFlags();
281 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
282
283 // bad request: forbidden field
284 ControlParameters p5(p2);
285 p5.setName("/example");
286 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
287}
288
289BOOST_AUTO_TEST_CASE(CsConfigResponse)
290{
291 CsConfigCommand command;
292
293 // bad empty response
294 ControlParameters p1;
295 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
296
297 // bad response: Mask not allowed
298 ControlParameters p2;
299 p2.setCapacity(1574);
300 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
301 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
302 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
303
304 // good response
305 ControlParameters p3(p2);
306 p3.unsetMask();
307 command.validateResponse(p3);
308}
309
Junxiao Shidf505382018-03-04 13:40:44 +0000310BOOST_AUTO_TEST_CASE(CsEraseRequest)
311{
312 CsEraseCommand command;
313
314 // good no-limit request
315 ControlParameters p1;
316 p1.setName("/u4LYPNU8Q");
317 command.validateRequest(p1);
318 BOOST_CHECK(Name("/PREFIX/cs/erase").isPrefixOf(command.getRequestName("/PREFIX", p1)));
319
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500320 // good limited request
Junxiao Shidf505382018-03-04 13:40:44 +0000321 ControlParameters p2;
322 p2.setName("/IMw1RaLF");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500323 p2.setCount(177);
Junxiao Shidf505382018-03-04 13:40:44 +0000324 command.validateRequest(p2);
325
326 // bad request: zero entry
327 ControlParameters p3;
328 p3.setName("/ahMID1jcib");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500329 p3.setCount(0);
Junxiao Shidf505382018-03-04 13:40:44 +0000330 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
331
332 // bad request: forbidden field
333 ControlParameters p4(p2);
334 p4.setCapacity(278);
335 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
336}
337
338BOOST_AUTO_TEST_CASE(CsEraseResponse)
339{
340 CsEraseCommand command;
341
342 // good normal response
343 ControlParameters p1;
344 p1.setName("/TwiIwCdR");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500345 p1.setCount(1);
Junxiao Shidf505382018-03-04 13:40:44 +0000346 command.validateResponse(p1);
347
348 // good limit exceeded request
349 ControlParameters p2;
350 p2.setName("/NMsiy44pr");
351 p2.setCapacity(360);
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500352 p2.setCount(360);
Junxiao Shidf505382018-03-04 13:40:44 +0000353 command.validateResponse(p2);
354
355 // good zero-entry response
356 ControlParameters p3;
357 p3.setName("/5f1LRPh1L");
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500358 p3.setCount(0);
Junxiao Shidf505382018-03-04 13:40:44 +0000359 command.validateResponse(p3);
360
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500361 // bad request: missing Count
Junxiao Shidf505382018-03-04 13:40:44 +0000362 ControlParameters p4(p1);
Davide Pesavento5e2ccca2018-03-06 19:00:15 -0500363 p4.unsetCount();
Junxiao Shidf505382018-03-04 13:40:44 +0000364 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
365
366 // bad request: zero capacity
367 ControlParameters p5(p1);
368 p5.setCapacity(0);
369 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
Junxiao Shidf505382018-03-04 13:40:44 +0000370}
371
Junxiao Shi5ec80222014-03-25 20:08:05 -0700372BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
373{
374 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700375
376 ControlParameters p1;
377 p1.setName("ndn:/")
378 .setStrategy("ndn:/strategy/P");
379 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
380 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700381 Name n1;
382 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
383 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700384
385 ControlParameters p2;
386 p2.setName("ndn:/example");
387 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
388 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
389}
390
391BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
392{
393 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700394
395 ControlParameters p1;
396 p1.setName("ndn:/example");
397 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
398 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700399 Name n1;
400 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
401 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700402
403 ControlParameters p2;
404 p2.setName("ndn:/example")
405 .setStrategy("ndn:/strategy/P");
406 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
407 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
408
409 ControlParameters p3;
410 p3.setName("ndn:/");
411 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
412 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
413}
414
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700415BOOST_AUTO_TEST_CASE(RibRegister)
416{
417 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700418
419 ControlParameters p1;
420 p1.setName("ndn:/");
421 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
422 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700423 Name n1;
424 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
425 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700426
427 command.applyDefaultsToRequest(p1);
428 BOOST_REQUIRE(p1.hasOrigin());
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400429 BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700430 BOOST_REQUIRE(p1.hasCost());
431 BOOST_CHECK_EQUAL(p1.getCost(), 0);
432 BOOST_REQUIRE(p1.hasFlags());
433 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700434 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700435
436 ControlParameters p2;
437 p2.setName("ndn:/example")
438 .setFaceId(2)
439 .setCost(6);
440 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
441 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700442 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700443 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
444}
445
446BOOST_AUTO_TEST_CASE(RibUnregister)
447{
448 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700449
450 ControlParameters p1;
451 p1.setName("ndn:/")
452 .setFaceId(22)
453 .setOrigin(ROUTE_ORIGIN_STATIC);
454 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
455 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700456 Name n1;
457 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
458 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700459
460 ControlParameters p2;
461 p2.setName("ndn:/example")
462 .setFaceId(0)
463 .setOrigin(ROUTE_ORIGIN_APP);
464 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500465 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700466 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
467
468 p2.unsetFaceId();
469 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
470 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
471}
472
Junxiao Shi7357ef22016-09-07 02:39:37 +0000473BOOST_AUTO_TEST_SUITE_END() // TestControlCommand
474BOOST_AUTO_TEST_SUITE_END() // Nfd
475BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi5ec80222014-03-25 20:08:05 -0700476
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800477} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700478} // namespace nfd
479} // namespace ndn