blob: 78b287785ab43b8961e35e9233c5e48bb4c72ea3 [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;
34 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create");
35
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);
51}
52
53BOOST_AUTO_TEST_CASE(FaceDestroy)
54{
55 FaceDestroyCommand command;
56 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy");
57
58 ControlParameters p1;
59 p1.setUri("tcp4://192.0.2.1")
60 .setFaceId(4);
61 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
62 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
63
64 ControlParameters p2;
65 p2.setFaceId(0);
66 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
67 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
68
69 ControlParameters p3;
70 p3.setFaceId(6);
71 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
72 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
73}
74
75BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
76{
77 FaceEnableLocalControlCommand command;
78 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control");
79
80 ControlParameters p1;
81 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
82 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
83 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
84
85 ControlParameters p2;
86 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
87 .setFaceId(9);
88 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
89 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -070090
91 ControlParameters p3;
92 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
93 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
94 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -070095}
96
97BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
98{
99 FaceDisableLocalControlCommand command;
100 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control");
101
102 ControlParameters p1;
103 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
104 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
105 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
106
107 ControlParameters p2;
108 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
109 .setFaceId(9);
110 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
111 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700112
113 ControlParameters p3;
114 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
115 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
116 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700117}
118
119BOOST_AUTO_TEST_CASE(FibAddNextHop)
120{
121 FibAddNextHopCommand command;
122 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop");
123
124 ControlParameters p1;
125 p1.setName("ndn:/")
126 .setFaceId(22);
127 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
128 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
129
130 ControlParameters p2;
131 p2.setName("ndn:/example")
132 .setFaceId(0)
133 .setCost(6);
134 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
135 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
136
137 command.applyDefaultsToRequest(p1);
138 BOOST_REQUIRE(p1.hasCost());
139 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700140
141 p1.unsetFaceId();
142 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
143 command.applyDefaultsToRequest(p1);
144 BOOST_REQUIRE(p1.hasFaceId());
145 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700146}
147
148BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
149{
150 FibRemoveNextHopCommand command;
151 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop");
152
153 ControlParameters p1;
154 p1.setName("ndn:/")
155 .setFaceId(22);
156 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
157 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
158
159 ControlParameters p2;
160 p2.setName("ndn:/example")
161 .setFaceId(0);
162 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
163 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700164
165 p1.unsetFaceId();
166 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
167 command.applyDefaultsToRequest(p1);
168 BOOST_REQUIRE(p1.hasFaceId());
169 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700170}
171
172BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
173{
174 StrategyChoiceSetCommand command;
175 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set");
176
177 ControlParameters p1;
178 p1.setName("ndn:/")
179 .setStrategy("ndn:/strategy/P");
180 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
181 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
182
183 ControlParameters p2;
184 p2.setName("ndn:/example");
185 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
186 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
187}
188
189BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
190{
191 StrategyChoiceUnsetCommand command;
192 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset");
193
194 ControlParameters p1;
195 p1.setName("ndn:/example");
196 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
197 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
198
199 ControlParameters p2;
200 p2.setName("ndn:/example")
201 .setStrategy("ndn:/strategy/P");
202 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
203 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
204
205 ControlParameters p3;
206 p3.setName("ndn:/");
207 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
208 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
209}
210
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700211BOOST_AUTO_TEST_CASE(RibRegister)
212{
213 RibRegisterCommand command;
214 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/register");
215
216 ControlParameters p1;
217 p1.setName("ndn:/");
218 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
219 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
220
221 command.applyDefaultsToRequest(p1);
222 BOOST_REQUIRE(p1.hasOrigin());
223 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
224 BOOST_REQUIRE(p1.hasCost());
225 BOOST_CHECK_EQUAL(p1.getCost(), 0);
226 BOOST_REQUIRE(p1.hasFlags());
227 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
228 BOOST_REQUIRE(p1.hasExpirationPeriod());
229 BOOST_CHECK_GT(p1.getExpirationPeriod(), time::hours(240));
230
231 ControlParameters p2;
232 p2.setName("ndn:/example")
233 .setFaceId(2)
234 .setCost(6);
235 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
236 command.applyDefaultsToRequest(p2);
237 BOOST_CHECK_EQUAL(p2.getExpirationPeriod(), time::hours(1));
238 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
239}
240
241BOOST_AUTO_TEST_CASE(RibUnregister)
242{
243 RibUnregisterCommand command;
244 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/unregister");
245
246 ControlParameters p1;
247 p1.setName("ndn:/")
248 .setFaceId(22)
249 .setOrigin(ROUTE_ORIGIN_STATIC);
250 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
251 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
252
253 ControlParameters p2;
254 p2.setName("ndn:/example")
255 .setFaceId(0)
256 .setOrigin(ROUTE_ORIGIN_APP);
257 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
258 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
259
260 p2.unsetFaceId();
261 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
262 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
263}
264
Junxiao Shi5ec80222014-03-25 20:08:05 -0700265BOOST_AUTO_TEST_SUITE_END()
266
267} // namespace nfd
268} // namespace ndn