blob: d76b67c6ce91d9fc69655f428d93fcaa0ed39ccd [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 Newberryda916d62016-08-11 23:04:34 -070050 .setFlags(0x3)
51 .setMask(0x1);
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000052 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Yukai Tud93c5fc2015-08-25 11:37:16 +080053
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000054 // Uri is required
55 ControlParameters p3;
56 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
57
58 // Name is forbidden
59 ControlParameters p4(p1);
60 p4.setName("/example");
61 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
62
63 // Flags and Mask must be specified together
64 ControlParameters p5(p1);
65 p5.setFlags(0x3);
66 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
67
68 ControlParameters p6(p1);
69 p6.setMask(0x1);
70 BOOST_CHECK_THROW(command.validateRequest(p6), ControlCommand::ArgumentError);
71}
72
73BOOST_AUTO_TEST_CASE(FaceCreateResponse)
74{
75 FaceCreateCommand command;
76
77 // good
78 ControlParameters p1;
79 p1.setFaceId(3208)
Junxiao Shi144c7e32017-04-20 01:04:06 +000080 .setUri("tcp4://192.0.2.1:6363")
81 .setLocalUri("tcp4://192.0.2.2:32114")
82 .setFacePersistency(FACE_PERSISTENCY_PERMANENT)
Eric Newberry07d05c92018-01-22 16:08:01 -070083 .setBaseCongestionMarkingInterval(500_ns)
84 .setDefaultCongestionThreshold(12345)
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000085 .setFlags(0x3);
86 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Eric Newberryda916d62016-08-11 23:04:34 -070087
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000088 // Name is forbidden
89 ControlParameters p2(p1);
90 p2.setName("/example");
91 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Yukai Tud93c5fc2015-08-25 11:37:16 +080092
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000093 // Mask is forbidden
94 ControlParameters p3(p1);
95 p3.setMask(0x1);
96 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -070097
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +000098 // FaceId must be valid
99 ControlParameters p4(p1);
100 p4.setFaceId(INVALID_FACE_ID);
101 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
Eric Newberryda916d62016-08-11 23:04:34 -0700102
Junxiao Shi8c2ab2e2017-05-05 20:26:34 +0000103 // LocalUri is required
104 ControlParameters p5(p1);
105 p5.unsetLocalUri();
106 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700107}
108
Yanbiao Licbdacb22016-08-02 16:02:35 +0800109BOOST_AUTO_TEST_CASE(FaceUpdate)
110{
111 FaceUpdateCommand command;
112
113 ControlParameters p1;
114 p1.setFaceId(0);
Eric Newberryda916d62016-08-11 23:04:34 -0700115 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500116 p1.setFaceId(INVALID_FACE_ID);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700117 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800118
119 p1.setFaceId(1);
120 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
Eric Newberry138ef2c2016-08-15 20:29:03 -0700121 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
122 command.applyDefaultsToRequest(p1);
123 BOOST_CHECK_EQUAL(p1.getFaceId(), 1);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800124
125 ControlParameters p2;
126 p2.setFaceId(1)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700127 .setFacePersistency(FACE_PERSISTENCY_PERSISTENT)
Eric Newberry07d05c92018-01-22 16:08:01 -0700128 .setBaseCongestionMarkingInterval(765_ns)
129 .setDefaultCongestionThreshold(54321)
Eric Newberry138ef2c2016-08-15 20:29:03 -0700130 .setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800131 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberry138ef2c2016-08-15 20:29:03 -0700132 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError); // Mask forbidden but present
Yanbiao Licbdacb22016-08-02 16:02:35 +0800133
Eric Newberry138ef2c2016-08-15 20:29:03 -0700134 // Flags without Mask
Eric Newberryda916d62016-08-11 23:04:34 -0700135 p2.unsetMask();
136 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
Eric Newberry138ef2c2016-08-15 20:29:03 -0700137 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
138
139 p2.setFlagBit(BIT_LOCAL_FIELDS_ENABLED, false);
140 p2.unsetFaceId();
141 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Eric Newberryda916d62016-08-11 23:04:34 -0700142
Yanbiao Licbdacb22016-08-02 16:02:35 +0800143 ControlParameters p3;
Eric Newberryda916d62016-08-11 23:04:34 -0700144 p3.setFaceId(1)
145 .setName("/ndn/name");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800146 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
147 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
148
149 ControlParameters p4;
150 p4.setFaceId(1)
Eric Newberryda916d62016-08-11 23:04:34 -0700151 .setUri("tcp4://192.0.2.1");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800152 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
153 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
154
155 ControlParameters p5;
Eric Newberry138ef2c2016-08-15 20:29:03 -0700156 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
157 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
158 BOOST_CHECK(!p5.hasFaceId());
159 command.applyDefaultsToRequest(p5);
160 BOOST_REQUIRE(p5.hasFaceId());
161 BOOST_CHECK_NO_THROW(command.validateRequest(p5));
162 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
163 BOOST_CHECK_EQUAL(p5.getFaceId(), 0);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800164}
165
Junxiao Shi5ec80222014-03-25 20:08:05 -0700166BOOST_AUTO_TEST_CASE(FaceDestroy)
167{
168 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700169
170 ControlParameters p1;
171 p1.setUri("tcp4://192.0.2.1")
172 .setFaceId(4);
173 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
174 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
175
176 ControlParameters p2;
Davide Pesaventof8503d22017-02-17 01:19:10 -0500177 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700178 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
179 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
180
181 ControlParameters p3;
182 p3.setFaceId(6);
183 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
184 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700185 Name n3;
186 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
187 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700188}
189
Junxiao Shi5ec80222014-03-25 20:08:05 -0700190BOOST_AUTO_TEST_CASE(FibAddNextHop)
191{
192 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700193
194 ControlParameters p1;
195 p1.setName("ndn:/")
196 .setFaceId(22);
197 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
198 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700199 Name n1;
200 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
201 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700202
203 ControlParameters p2;
204 p2.setName("ndn:/example")
205 .setFaceId(0)
206 .setCost(6);
207 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500208 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700209 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
210
211 command.applyDefaultsToRequest(p1);
212 BOOST_REQUIRE(p1.hasCost());
213 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700214
215 p1.unsetFaceId();
216 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
217 command.applyDefaultsToRequest(p1);
218 BOOST_REQUIRE(p1.hasFaceId());
219 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700220}
221
222BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
223{
224 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700225
226 ControlParameters p1;
227 p1.setName("ndn:/")
228 .setFaceId(22);
229 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
230 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700231 Name n1;
232 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
233 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700234
235 ControlParameters p2;
236 p2.setName("ndn:/example")
237 .setFaceId(0);
238 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500239 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700240 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700241
242 p1.unsetFaceId();
243 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
244 command.applyDefaultsToRequest(p1);
245 BOOST_REQUIRE(p1.hasFaceId());
246 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700247}
248
Junxiao Shi22f85682018-01-22 19:23:22 +0000249BOOST_AUTO_TEST_CASE(CsConfigRequest)
250{
251 CsConfigCommand command;
252
253 // good empty request
254 ControlParameters p1;
255 command.validateRequest(p1);
256 BOOST_CHECK(Name("/PREFIX/cs/config").isPrefixOf(command.getRequestName("/PREFIX", p1)));
257
258 // good full request
259 ControlParameters p2;
260 p2.setCapacity(1574);
261 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
262 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
263 command.validateRequest(p2);
264
265 // bad request: Flags but no Mask
266 ControlParameters p3(p2);
267 p3.unsetMask();
268 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
269
270 // bad request: Mask but no Flags
271 ControlParameters p4(p2);
272 p4.unsetFlags();
273 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
274
275 // bad request: forbidden field
276 ControlParameters p5(p2);
277 p5.setName("/example");
278 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
279}
280
281BOOST_AUTO_TEST_CASE(CsConfigResponse)
282{
283 CsConfigCommand command;
284
285 // bad empty response
286 ControlParameters p1;
287 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
288
289 // bad response: Mask not allowed
290 ControlParameters p2;
291 p2.setCapacity(1574);
292 p2.setFlagBit(BIT_CS_ENABLE_ADMIT, true);
293 p2.setFlagBit(BIT_CS_ENABLE_SERVE, true);
294 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
295
296 // good response
297 ControlParameters p3(p2);
298 p3.unsetMask();
299 command.validateResponse(p3);
300}
301
Junxiao Shidf505382018-03-04 13:40:44 +0000302BOOST_AUTO_TEST_CASE(CsEraseRequest)
303{
304 CsEraseCommand command;
305
306 // good no-limit request
307 ControlParameters p1;
308 p1.setName("/u4LYPNU8Q");
309 command.validateRequest(p1);
310 BOOST_CHECK(Name("/PREFIX/cs/erase").isPrefixOf(command.getRequestName("/PREFIX", p1)));
311
312 // good limit-entries request
313 ControlParameters p2;
314 p2.setName("/IMw1RaLF");
315 p2.setNCsEntries(177);
316 command.validateRequest(p2);
317
318 // bad request: zero entry
319 ControlParameters p3;
320 p3.setName("/ahMID1jcib");
321 p3.setNCsEntries(0);
322 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
323
324 // bad request: forbidden field
325 ControlParameters p4(p2);
326 p4.setCapacity(278);
327 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
328}
329
330BOOST_AUTO_TEST_CASE(CsEraseResponse)
331{
332 CsEraseCommand command;
333
334 // good normal response
335 ControlParameters p1;
336 p1.setName("/TwiIwCdR");
337 p1.setNCsEntries(1);
338 command.validateResponse(p1);
339
340 // good limit exceeded request
341 ControlParameters p2;
342 p2.setName("/NMsiy44pr");
343 p2.setCapacity(360);
344 p2.setNCsEntries(360);
345 command.validateResponse(p2);
346
347 // good zero-entry response
348 ControlParameters p3;
349 p3.setName("/5f1LRPh1L");
350 p3.setNCsEntries(0);
351 command.validateResponse(p3);
352
353 // bad request: missing NCsEntries
354 ControlParameters p4(p1);
355 p4.unsetNCsEntries();
356 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
357
358 // bad request: zero capacity
359 ControlParameters p5(p1);
360 p5.setCapacity(0);
361 BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
362
363}
364
Junxiao Shi5ec80222014-03-25 20:08:05 -0700365BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
366{
367 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700368
369 ControlParameters p1;
370 p1.setName("ndn:/")
371 .setStrategy("ndn:/strategy/P");
372 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
373 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700374 Name n1;
375 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
376 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700377
378 ControlParameters p2;
379 p2.setName("ndn:/example");
380 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
381 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
382}
383
384BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
385{
386 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700387
388 ControlParameters p1;
389 p1.setName("ndn:/example");
390 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
391 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700392 Name n1;
393 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
394 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700395
396 ControlParameters p2;
397 p2.setName("ndn:/example")
398 .setStrategy("ndn:/strategy/P");
399 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
400 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
401
402 ControlParameters p3;
403 p3.setName("ndn:/");
404 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
405 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
406}
407
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700408BOOST_AUTO_TEST_CASE(RibRegister)
409{
410 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700411
412 ControlParameters p1;
413 p1.setName("ndn:/");
414 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
415 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700416 Name n1;
417 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
418 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700419
420 command.applyDefaultsToRequest(p1);
421 BOOST_REQUIRE(p1.hasOrigin());
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400422 BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700423 BOOST_REQUIRE(p1.hasCost());
424 BOOST_CHECK_EQUAL(p1.getCost(), 0);
425 BOOST_REQUIRE(p1.hasFlags());
426 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700427 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700428
429 ControlParameters p2;
430 p2.setName("ndn:/example")
431 .setFaceId(2)
432 .setCost(6);
433 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
434 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700435 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700436 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
437}
438
439BOOST_AUTO_TEST_CASE(RibUnregister)
440{
441 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700442
443 ControlParameters p1;
444 p1.setName("ndn:/")
445 .setFaceId(22)
446 .setOrigin(ROUTE_ORIGIN_STATIC);
447 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
448 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700449 Name n1;
450 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
451 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700452
453 ControlParameters p2;
454 p2.setName("ndn:/example")
455 .setFaceId(0)
456 .setOrigin(ROUTE_ORIGIN_APP);
457 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
Davide Pesaventof8503d22017-02-17 01:19:10 -0500458 p2.setFaceId(INVALID_FACE_ID);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700459 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
460
461 p2.unsetFaceId();
462 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
463 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
464}
465
Junxiao Shi7357ef22016-09-07 02:39:37 +0000466BOOST_AUTO_TEST_SUITE_END() // TestControlCommand
467BOOST_AUTO_TEST_SUITE_END() // Nfd
468BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi5ec80222014-03-25 20:08:05 -0700469
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800470} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700471} // namespace nfd
472} // namespace ndn