blob: e6f4d3ba0fb61cc26fb4d407639ee3b85f9c1d8c [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/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 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
76BOOST_AUTO_TEST_CASE(FaceDestroy)
77{
78 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070079
80 ControlParameters p1;
81 p1.setUri("tcp4://192.0.2.1")
82 .setFaceId(4);
83 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
84 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
85
86 ControlParameters p2;
87 p2.setFaceId(0);
88 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
89 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
90
91 ControlParameters p3;
92 p3.setFaceId(6);
93 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
94 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -070095 Name n3;
96 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
97 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -070098}
99
100BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
101{
102 FaceEnableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700103
104 ControlParameters p1;
105 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
106 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
107 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700108 Name n1;
109 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
110 BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700111
112 ControlParameters p2;
113 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
114 .setFaceId(9);
115 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
116 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700117
118 ControlParameters p3;
119 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
120 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
121 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700122}
123
124BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
125{
126 FaceDisableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700127
128 ControlParameters p1;
129 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
130 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
131 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700132 Name n1;
133 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
134 BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700135
136 ControlParameters p2;
137 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
138 .setFaceId(9);
139 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
140 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700141
142 ControlParameters p3;
143 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
144 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
145 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700146}
147
148BOOST_AUTO_TEST_CASE(FibAddNextHop)
149{
150 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700151
152 ControlParameters p1;
153 p1.setName("ndn:/")
154 .setFaceId(22);
155 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
156 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700157 Name n1;
158 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
159 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700160
161 ControlParameters p2;
162 p2.setName("ndn:/example")
163 .setFaceId(0)
164 .setCost(6);
165 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
166 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
167
168 command.applyDefaultsToRequest(p1);
169 BOOST_REQUIRE(p1.hasCost());
170 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700171
172 p1.unsetFaceId();
173 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
174 command.applyDefaultsToRequest(p1);
175 BOOST_REQUIRE(p1.hasFaceId());
176 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700177}
178
179BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
180{
181 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700182
183 ControlParameters p1;
184 p1.setName("ndn:/")
185 .setFaceId(22);
186 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
187 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700188 Name n1;
189 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
190 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700191
192 ControlParameters p2;
193 p2.setName("ndn:/example")
194 .setFaceId(0);
195 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
196 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700197
198 p1.unsetFaceId();
199 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
200 command.applyDefaultsToRequest(p1);
201 BOOST_REQUIRE(p1.hasFaceId());
202 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700203}
204
205BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
206{
207 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700208
209 ControlParameters p1;
210 p1.setName("ndn:/")
211 .setStrategy("ndn:/strategy/P");
212 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
213 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
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/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700217
218 ControlParameters p2;
219 p2.setName("ndn:/example");
220 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
221 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
222}
223
224BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
225{
226 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700227
228 ControlParameters p1;
229 p1.setName("ndn:/example");
230 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
231 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700232 Name n1;
233 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
234 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700235
236 ControlParameters p2;
237 p2.setName("ndn:/example")
238 .setStrategy("ndn:/strategy/P");
239 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
240 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
241
242 ControlParameters p3;
243 p3.setName("ndn:/");
244 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
245 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
246}
247
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700248BOOST_AUTO_TEST_CASE(RibRegister)
249{
250 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700251
252 ControlParameters p1;
253 p1.setName("ndn:/");
254 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
255 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700256 Name n1;
257 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
258 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700259
260 command.applyDefaultsToRequest(p1);
261 BOOST_REQUIRE(p1.hasOrigin());
262 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
263 BOOST_REQUIRE(p1.hasCost());
264 BOOST_CHECK_EQUAL(p1.getCost(), 0);
265 BOOST_REQUIRE(p1.hasFlags());
266 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700267 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700268
269 ControlParameters p2;
270 p2.setName("ndn:/example")
271 .setFaceId(2)
272 .setCost(6);
273 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
274 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700275 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700276 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
277}
278
279BOOST_AUTO_TEST_CASE(RibUnregister)
280{
281 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700282
283 ControlParameters p1;
284 p1.setName("ndn:/")
285 .setFaceId(22)
286 .setOrigin(ROUTE_ORIGIN_STATIC);
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/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700292
293 ControlParameters p2;
294 p2.setName("ndn:/example")
295 .setFaceId(0)
296 .setOrigin(ROUTE_ORIGIN_APP);
297 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
298 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
299
300 p2.unsetFaceId();
301 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
302 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
303}
304
Junxiao Shi5ec80222014-03-25 20:08:05 -0700305BOOST_AUTO_TEST_SUITE_END()
306
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800307} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700308} // namespace nfd
309} // namespace ndn