blob: a0ea8c19642f600b661f7c80b2bf394616528811 [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/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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 {
28
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070029BOOST_AUTO_TEST_SUITE(ManagementTestNfdControlCommand)
Junxiao Shi5ec80222014-03-25 20:08:05 -070030
31BOOST_AUTO_TEST_CASE(FaceCreate)
32{
33 FaceCreateCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070034
35 ControlParameters p1;
36 p1.setUri("tcp4://192.0.2.1")
37 .setFaceId(4);
38 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
39 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
40
41 ControlParameters p2;
42 p2.setName("ndn:/example");
43 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
44 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
45
46 ControlParameters p3;
47 p3.setUri("tcp4://192.0.2.1")
48 .setFaceId(0);
49 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -070050
51 ControlParameters p4;
52 p4.setUri("tcp4://192.0.2.1:6363");
53 Name n4;
54 BOOST_CHECK_NO_THROW(n4 = command.getRequestName("/PREFIX", p4));
55 BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n4));
Junxiao Shi5ec80222014-03-25 20:08:05 -070056}
57
58BOOST_AUTO_TEST_CASE(FaceDestroy)
59{
60 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070061
62 ControlParameters p1;
63 p1.setUri("tcp4://192.0.2.1")
64 .setFaceId(4);
65 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
66 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
67
68 ControlParameters p2;
69 p2.setFaceId(0);
70 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
71 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
72
73 ControlParameters p3;
74 p3.setFaceId(6);
75 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
76 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -070077 Name n3;
78 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
79 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -070080}
81
82BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
83{
84 FaceEnableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070085
86 ControlParameters p1;
87 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
88 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
89 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -070090 Name n1;
91 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
92 BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -070093
94 ControlParameters p2;
95 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
96 .setFaceId(9);
97 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
98 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -070099
100 ControlParameters p3;
101 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
102 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
103 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700104}
105
106BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
107{
108 FaceDisableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700109
110 ControlParameters p1;
111 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
112 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
113 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700114 Name n1;
115 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
116 BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700117
118 ControlParameters p2;
119 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
120 .setFaceId(9);
121 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
122 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700123
124 ControlParameters p3;
125 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
126 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
127 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700128}
129
130BOOST_AUTO_TEST_CASE(FibAddNextHop)
131{
132 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700133
134 ControlParameters p1;
135 p1.setName("ndn:/")
136 .setFaceId(22);
137 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
138 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700139 Name n1;
140 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
141 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700142
143 ControlParameters p2;
144 p2.setName("ndn:/example")
145 .setFaceId(0)
146 .setCost(6);
147 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
148 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
149
150 command.applyDefaultsToRequest(p1);
151 BOOST_REQUIRE(p1.hasCost());
152 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700153
154 p1.unsetFaceId();
155 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
156 command.applyDefaultsToRequest(p1);
157 BOOST_REQUIRE(p1.hasFaceId());
158 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700159}
160
161BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
162{
163 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700164
165 ControlParameters p1;
166 p1.setName("ndn:/")
167 .setFaceId(22);
168 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
169 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700170 Name n1;
171 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
172 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700173
174 ControlParameters p2;
175 p2.setName("ndn:/example")
176 .setFaceId(0);
177 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
178 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700179
180 p1.unsetFaceId();
181 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
182 command.applyDefaultsToRequest(p1);
183 BOOST_REQUIRE(p1.hasFaceId());
184 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700185}
186
187BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
188{
189 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700190
191 ControlParameters p1;
192 p1.setName("ndn:/")
193 .setStrategy("ndn:/strategy/P");
194 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
195 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700196 Name n1;
197 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
198 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700199
200 ControlParameters p2;
201 p2.setName("ndn:/example");
202 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
203 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
204}
205
206BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
207{
208 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700209
210 ControlParameters p1;
211 p1.setName("ndn:/example");
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/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700217
218 ControlParameters p2;
219 p2.setName("ndn:/example")
220 .setStrategy("ndn:/strategy/P");
221 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
222 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
223
224 ControlParameters p3;
225 p3.setName("ndn:/");
226 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
227 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
228}
229
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700230BOOST_AUTO_TEST_CASE(RibRegister)
231{
232 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700233
234 ControlParameters p1;
235 p1.setName("ndn:/");
236 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
237 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700238 Name n1;
239 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
240 BOOST_CHECK(Name("ndn:/PREFIX/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700241
242 command.applyDefaultsToRequest(p1);
243 BOOST_REQUIRE(p1.hasOrigin());
244 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
245 BOOST_REQUIRE(p1.hasCost());
246 BOOST_CHECK_EQUAL(p1.getCost(), 0);
247 BOOST_REQUIRE(p1.hasFlags());
248 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700249 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700250
251 ControlParameters p2;
252 p2.setName("ndn:/example")
253 .setFaceId(2)
254 .setCost(6);
255 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
256 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700257 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700258 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
259}
260
261BOOST_AUTO_TEST_CASE(RibUnregister)
262{
263 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700264
265 ControlParameters p1;
266 p1.setName("ndn:/")
267 .setFaceId(22)
268 .setOrigin(ROUTE_ORIGIN_STATIC);
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/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700274
275 ControlParameters p2;
276 p2.setName("ndn:/example")
277 .setFaceId(0)
278 .setOrigin(ROUTE_ORIGIN_APP);
279 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
280 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
281
282 p2.unsetFaceId();
283 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
284 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
285}
286
Junxiao Shi5ec80222014-03-25 20:08:05 -0700287BOOST_AUTO_TEST_SUITE_END()
288
289} // namespace nfd
290} // namespace ndn