blob: a82c8b9fa9df57fc92427f616c3c1af74f04d834 [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);
40 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
41
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;
53 p4.setUri("tcp4://192.0.2.1:6363");
54 Name n4;
55 BOOST_CHECK_NO_THROW(n4 = command.getRequestName("/PREFIX", p4));
56 BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n4));
Junxiao Shi5ec80222014-03-25 20:08:05 -070057}
58
59BOOST_AUTO_TEST_CASE(FaceDestroy)
60{
61 FaceDestroyCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070062
63 ControlParameters p1;
64 p1.setUri("tcp4://192.0.2.1")
65 .setFaceId(4);
66 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
67 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
68
69 ControlParameters p2;
70 p2.setFaceId(0);
71 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
72 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
73
74 ControlParameters p3;
75 p3.setFaceId(6);
76 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
77 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
Junxiao Shi5de006b2014-10-26 20:20:52 -070078 Name n3;
79 BOOST_CHECK_NO_THROW(n3 = command.getRequestName("/PREFIX", p3));
80 BOOST_CHECK(Name("ndn:/PREFIX/faces/destroy").isPrefixOf(n3));
Junxiao Shi5ec80222014-03-25 20:08:05 -070081}
82
83BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
84{
85 FaceEnableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -070086
87 ControlParameters p1;
88 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
89 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
90 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -070091 Name n1;
92 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
93 BOOST_CHECK(Name("ndn:/PREFIX/faces/enable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -070094
95 ControlParameters p2;
96 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
97 .setFaceId(9);
98 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
99 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700100
101 ControlParameters p3;
102 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
103 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
104 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700105}
106
107BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
108{
109 FaceDisableLocalControlCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700110
111 ControlParameters p1;
112 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
113 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
114 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700115 Name n1;
116 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
117 BOOST_CHECK(Name("ndn:/PREFIX/faces/disable-local-control").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700118
119 ControlParameters p2;
120 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
121 .setFaceId(9);
122 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
123 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700124
125 ControlParameters p3;
126 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
127 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
128 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700129}
130
131BOOST_AUTO_TEST_CASE(FibAddNextHop)
132{
133 FibAddNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700134
135 ControlParameters p1;
136 p1.setName("ndn:/")
137 .setFaceId(22);
138 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
139 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
Junxiao Shi5de006b2014-10-26 20:20:52 -0700140 Name n1;
141 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
142 BOOST_CHECK(Name("ndn:/PREFIX/fib/add-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700143
144 ControlParameters p2;
145 p2.setName("ndn:/example")
146 .setFaceId(0)
147 .setCost(6);
148 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
149 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
150
151 command.applyDefaultsToRequest(p1);
152 BOOST_REQUIRE(p1.hasCost());
153 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700154
155 p1.unsetFaceId();
156 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
157 command.applyDefaultsToRequest(p1);
158 BOOST_REQUIRE(p1.hasFaceId());
159 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700160}
161
162BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
163{
164 FibRemoveNextHopCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700165
166 ControlParameters p1;
167 p1.setName("ndn:/")
168 .setFaceId(22);
169 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
170 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700171 Name n1;
172 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
173 BOOST_CHECK(Name("ndn:/PREFIX/fib/remove-nexthop").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700174
175 ControlParameters p2;
176 p2.setName("ndn:/example")
177 .setFaceId(0);
178 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
179 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700180
181 p1.unsetFaceId();
182 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
183 command.applyDefaultsToRequest(p1);
184 BOOST_REQUIRE(p1.hasFaceId());
185 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700186}
187
188BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
189{
190 StrategyChoiceSetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700191
192 ControlParameters p1;
193 p1.setName("ndn:/")
194 .setStrategy("ndn:/strategy/P");
195 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
196 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700197 Name n1;
198 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
199 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/set").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700200
201 ControlParameters p2;
202 p2.setName("ndn:/example");
203 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
204 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
205}
206
207BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
208{
209 StrategyChoiceUnsetCommand command;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700210
211 ControlParameters p1;
212 p1.setName("ndn:/example");
213 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
214 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700215 Name n1;
216 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
217 BOOST_CHECK(Name("ndn:/PREFIX/strategy-choice/unset").isPrefixOf(n1));
Junxiao Shi5ec80222014-03-25 20:08:05 -0700218
219 ControlParameters p2;
220 p2.setName("ndn:/example")
221 .setStrategy("ndn:/strategy/P");
222 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
223 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
224
225 ControlParameters p3;
226 p3.setName("ndn:/");
227 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
228 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
229}
230
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700231BOOST_AUTO_TEST_CASE(RibRegister)
232{
233 RibRegisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700234
235 ControlParameters p1;
236 p1.setName("ndn:/");
237 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
238 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
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/rib/register").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700242
243 command.applyDefaultsToRequest(p1);
244 BOOST_REQUIRE(p1.hasOrigin());
245 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
246 BOOST_REQUIRE(p1.hasCost());
247 BOOST_CHECK_EQUAL(p1.getCost(), 0);
248 BOOST_REQUIRE(p1.hasFlags());
249 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700250 BOOST_CHECK_EQUAL(p1.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700251
252 ControlParameters p2;
253 p2.setName("ndn:/example")
254 .setFaceId(2)
255 .setCost(6);
256 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
257 command.applyDefaultsToRequest(p2);
Alexander Afanasyev21f13b02014-07-17 16:17:34 -0700258 BOOST_CHECK_EQUAL(p2.hasExpirationPeriod(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700259 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
260}
261
262BOOST_AUTO_TEST_CASE(RibUnregister)
263{
264 RibUnregisterCommand command;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700265
266 ControlParameters p1;
267 p1.setName("ndn:/")
268 .setFaceId(22)
269 .setOrigin(ROUTE_ORIGIN_STATIC);
270 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
271 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
Junxiao Shi5de006b2014-10-26 20:20:52 -0700272 Name n1;
273 BOOST_CHECK_NO_THROW(n1 = command.getRequestName("/PREFIX", p1));
274 BOOST_CHECK(Name("ndn:/PREFIX/rib/unregister").isPrefixOf(n1));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700275
276 ControlParameters p2;
277 p2.setName("ndn:/example")
278 .setFaceId(0)
279 .setOrigin(ROUTE_ORIGIN_APP);
280 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
281 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
282
283 p2.unsetFaceId();
284 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
285 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
286}
287
Junxiao Shi5ec80222014-03-25 20:08:05 -0700288BOOST_AUTO_TEST_SUITE_END()
289
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800290} // namespace tests
Junxiao Shi5ec80222014-03-25 20:08:05 -0700291} // namespace nfd
292} // namespace ndn