blob: 95857d46d1186376e85859002617106e1b1a66b7 [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")
Eric Newberryda916d62016-08-11 23:04:34 -070054 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT)
55 .setFlags(0x3)
56 .setMask(0x1);
Yukai Tud93c5fc2015-08-25 11:37:16 +080057 BOOST_CHECK_NO_THROW(command.validateRequest(p4));
58
Eric Newberryda916d62016-08-11 23:04:34 -070059 ControlParameters p5;
60 p5.setUri("tcp4://192.0.2.1")
61 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT)
62 .setFlags(0x1);
63 BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
64
Yukai Tud93c5fc2015-08-25 11:37:16 +080065 p4.unsetFacePersistency();
66 BOOST_CHECK_NO_THROW(command.validateRequest(p4));
67 command.applyDefaultsToRequest(p4);
68 BOOST_REQUIRE(p4.hasFacePersistency());
69 BOOST_CHECK_EQUAL(p4.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
70
Yukai Tud93c5fc2015-08-25 11:37:16 +080071 ControlParameters p6;
Eric Newberryda916d62016-08-11 23:04:34 -070072 p6.setFaceId(4)
73 .setUri("tcp4://192.0.2.1")
74 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
75 BOOST_CHECK_NO_THROW(command.validateResponse(p6));
76
77 ControlParameters p7;
78 p7.setUri("tcp4://192.0.2.1:6363");
79 Name n7;
80 BOOST_CHECK_NO_THROW(n7 = command.getRequestName("/PREFIX", p7));
81 BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n7));
82
83 ControlParameters p8;
84 p8.setFaceId(5)
85 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERMANENT)
86 .setFlags(0x2);
87 BOOST_CHECK_NO_THROW(command.validateResponse(p8));
Junxiao Shi5ec80222014-03-25 20:08:05 -070088}
89
Yanbiao Licbdacb22016-08-02 16:02:35 +080090BOOST_AUTO_TEST_CASE(FaceUpdate)
91{
92 FaceUpdateCommand command;
93
94 ControlParameters p1;
95 p1.setFaceId(0);
Eric Newberryda916d62016-08-11 23:04:34 -070096 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
97 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Yanbiao Licbdacb22016-08-02 16:02:35 +080098
99 p1.setFaceId(1);
100 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
101 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
102
103 ControlParameters p2;
104 p2.setFaceId(1)
Eric Newberryda916d62016-08-11 23:04:34 -0700105 .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT)
106 .setFlags(0x0)
107 .setMask(0x1);
Yanbiao Licbdacb22016-08-02 16:02:35 +0800108 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
109 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
110
Eric Newberryda916d62016-08-11 23:04:34 -0700111 p2.unsetFaceId();
112 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
113
114 p2.unsetMask();
115 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
116
Yanbiao Licbdacb22016-08-02 16:02:35 +0800117 ControlParameters p3;
Eric Newberryda916d62016-08-11 23:04:34 -0700118 p3.setFaceId(1)
119 .setName("/ndn/name");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800120 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
121 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
122
123 ControlParameters p4;
124 p4.setFaceId(1)
Eric Newberryda916d62016-08-11 23:04:34 -0700125 .setUri("tcp4://192.0.2.1");
Yanbiao Licbdacb22016-08-02 16:02:35 +0800126 BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
127 BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
128
129 ControlParameters p5;
Eric Newberryda916d62016-08-11 23:04:34 -0700130 BOOST_CHECK_NO_THROW(command.validateResponse(p5));
Yanbiao Licbdacb22016-08-02 16:02:35 +0800131}
132
Junxiao Shi5ec80222014-03-25 20:08:05 -0700133BOOST_AUTO_TEST_CASE(FaceDestroy)
134{
135 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700136
137 ControlParameters p1;
138 p1.setUri("tcp4://192.0.2.1")
139 .setFaceId(4);
140 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
141 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
142
143 ControlParameters p2;
144 p2.setFaceId(0);
145 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
146 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
147
148 ControlParameters p3;
149 p3.setFaceId(6);
150 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
151 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700152 Name n3;
153 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
154 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700155}
156
157BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
158{
159 FaceEnableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700160
161 ControlParameters p1;
162 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
163 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
164 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700165 Name n1;
166 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
167 BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700168
169 ControlParameters p2;
170 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
171 .setFaceId(9);
172 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
173 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700174
175 ControlParameters p3;
176 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
177 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
178 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700179}
180
181BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
182{
183 FaceDisableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700184
185 ControlParameters p1;
186 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
187 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
188 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700189 Name n1;
190 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
191 BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700192
193 ControlParameters p2;
194 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
195 .setFaceId(9);
196 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
197 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700198
199 ControlParameters p3;
200 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
201 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
202 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700203}
204
205BOOST_AUTO_TEST_CASE(FibAddNextHop)
206{
207 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700208
209 ControlParameters p1;
210 p1.setName("ndn:/")
211 .setFaceId(22);
212 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
213 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700214 Name n1;
215 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
216 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700217
218 ControlParameters p2;
219 p2.setName("ndn:/example")
220 .setFaceId(0)
221 .setCost(6);
222 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
223 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
224
225 command.applyDefaultsToRequest(p1);
226 BOOST_REQUIRE(p1.hasCost());
227 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700228
229 p1.unsetFaceId();
230 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
231 command.applyDefaultsToRequest(p1);
232 BOOST_REQUIRE(p1.hasFaceId());
233 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700234}
235
236BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
237{
238 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700239
240 ControlParameters p1;
241 p1.setName("ndn:/")
242 .setFaceId(22);
243 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
244 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700245 Name n1;
246 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
247 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700248
249 ControlParameters p2;
250 p2.setName("ndn:/example")
251 .setFaceId(0);
252 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
253 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700254
255 p1.unsetFaceId();
256 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
257 command.applyDefaultsToRequest(p1);
258 BOOST_REQUIRE(p1.hasFaceId());
259 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700260}
261
262BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
263{
264 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700265
266 ControlParameters p1;
267 p1.setName("ndn:/")
268 .setStrategy("ndn:/strategy/P");
269 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
270 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700271 Name n1;
272 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
273 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700274
275 ControlParameters p2;
276 p2.setName("ndn:/example");
277 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
278 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
279}
280
281BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
282{
283 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700284
285 ControlParameters p1;
286 p1.setName("ndn:/example");
287 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
288 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700289 Name n1;
290 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
291 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700292
293 ControlParameters p2;
294 p2.setName("ndn:/example")
295 .setStrategy("ndn:/strategy/P");
296 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
297 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
298
299 ControlParameters p3;
300 p3.setName("ndn:/");
301 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
302 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
303}
304
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700305BOOST_AUTO_TEST_CASE(RibRegister)
306{
307 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700308
309 ControlParameters p1;
310 p1.setName("ndn:/");
311 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
312 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700313 Name n1;
314 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
315 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700316
317 command.applyDefaultsToRequest(p1);
318 BOOST_REQUIRE(p1.hasOrigin());
319 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
320 BOOST_REQUIRE(p1.hasCost());
321 BOOST_CHECK_EQUAL(p1.getCost(), 0);
322 BOOST_REQUIRE(p1.hasFlags());
323 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700324 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700325
326 ControlParameters p2;
327 p2.setName("ndn:/example")
328 .setFaceId(2)
329 .setCost(6);
330 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
331 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700332 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700333 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
334}
335
336BOOST_AUTO_TEST_CASE(RibUnregister)
337{
338 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700339
340 ControlParameters p1;
341 p1.setName("ndn:/")
342 .setFaceId(22)
343 .setOrigin(ROUTE_ORIGIN_STATIC);
344 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
345 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700346 Name n1;
347 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
348 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700349
350 ControlParameters p2;
351 p2.setName("ndn:/example")
352 .setFaceId(0)
353 .setOrigin(ROUTE_ORIGIN_APP);
354 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
355 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
356
357 p2.unsetFaceId();
358 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
359 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
360}
361
Junxiao Shi5ec80222014-03-25 20:08:05 -0700362BOOST_AUTO_TEST_SUITE_END()
363
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800364} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700365} // namespace nfd
366} // namespace ndn