blob: 7b92657ca79c227d65cffe4c51990180c3209a44 [file] [log] [blame]
Junxiao Shi5ec80222014-03-25 20:08:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Junxiao Shi5ec80222014-03-25 20:08:05 -070011 */
12
13#include "management/nfd-control-command.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070014
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070015#include "boost-test.hpp"
Junxiao Shi5ec80222014-03-25 20:08:05 -070016
17namespace ndn {
18namespace nfd {
19
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070020BOOST_AUTO_TEST_SUITE(ManagementTestNfdControlCommand)
Junxiao Shi5ec80222014-03-25 20:08:05 -070021
22BOOST_AUTO_TEST_CASE(FaceCreate)
23{
24 FaceCreateCommand command;
25 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create");
26
27 ControlParameters p1;
28 p1.setUri("tcp4://192.0.2.1")
29 .setFaceId(4);
30 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
31 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
32
33 ControlParameters p2;
34 p2.setName("ndn:/example");
35 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
36 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
37
38 ControlParameters p3;
39 p3.setUri("tcp4://192.0.2.1")
40 .setFaceId(0);
41 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
42}
43
44BOOST_AUTO_TEST_CASE(FaceDestroy)
45{
46 FaceDestroyCommand command;
47 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy");
48
49 ControlParameters p1;
50 p1.setUri("tcp4://192.0.2.1")
51 .setFaceId(4);
52 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
53 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
54
55 ControlParameters p2;
56 p2.setFaceId(0);
57 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
58 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
59
60 ControlParameters p3;
61 p3.setFaceId(6);
62 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
63 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
64}
65
66BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
67{
68 FaceEnableLocalControlCommand command;
69 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control");
70
71 ControlParameters p1;
72 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
73 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
74 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
75
76 ControlParameters p2;
77 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
78 .setFaceId(9);
79 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
80 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -070081
82 ControlParameters p3;
83 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
84 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
85 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -070086}
87
88BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
89{
90 FaceDisableLocalControlCommand command;
91 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control");
92
93 ControlParameters p1;
94 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
95 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
96 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
97
98 ControlParameters p2;
99 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
100 .setFaceId(9);
101 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
102 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -0700103
104 ControlParameters p3;
105 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
106 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
107 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700108}
109
110BOOST_AUTO_TEST_CASE(FibAddNextHop)
111{
112 FibAddNextHopCommand command;
113 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop");
114
115 ControlParameters p1;
116 p1.setName("ndn:/")
117 .setFaceId(22);
118 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
119 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
120
121 ControlParameters p2;
122 p2.setName("ndn:/example")
123 .setFaceId(0)
124 .setCost(6);
125 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
126 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
127
128 command.applyDefaultsToRequest(p1);
129 BOOST_REQUIRE(p1.hasCost());
130 BOOST_CHECK_EQUAL(p1.getCost(), 0);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700131
132 p1.unsetFaceId();
133 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
134 command.applyDefaultsToRequest(p1);
135 BOOST_REQUIRE(p1.hasFaceId());
136 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700137}
138
139BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
140{
141 FibRemoveNextHopCommand command;
142 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop");
143
144 ControlParameters p1;
145 p1.setName("ndn:/")
146 .setFaceId(22);
147 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
148 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
149
150 ControlParameters p2;
151 p2.setName("ndn:/example")
152 .setFaceId(0);
153 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
154 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shicaac54e2014-05-20 15:27:01 -0700155
156 p1.unsetFaceId();
157 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
158 command.applyDefaultsToRequest(p1);
159 BOOST_REQUIRE(p1.hasFaceId());
160 BOOST_CHECK_EQUAL(p1.getFaceId(), 0);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700161}
162
163BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
164{
165 StrategyChoiceSetCommand command;
166 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set");
167
168 ControlParameters p1;
169 p1.setName("ndn:/")
170 .setStrategy("ndn:/strategy/P");
171 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
172 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
173
174 ControlParameters p2;
175 p2.setName("ndn:/example");
176 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
177 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
178}
179
180BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
181{
182 StrategyChoiceUnsetCommand command;
183 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset");
184
185 ControlParameters p1;
186 p1.setName("ndn:/example");
187 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
188 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
189
190 ControlParameters p2;
191 p2.setName("ndn:/example")
192 .setStrategy("ndn:/strategy/P");
193 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
194 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
195
196 ControlParameters p3;
197 p3.setName("ndn:/");
198 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
199 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
200}
201
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700202BOOST_AUTO_TEST_CASE(RibRegister)
203{
204 RibRegisterCommand command;
205 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/register");
206
207 ControlParameters p1;
208 p1.setName("ndn:/");
209 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
210 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
211
212 command.applyDefaultsToRequest(p1);
213 BOOST_REQUIRE(p1.hasOrigin());
214 BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
215 BOOST_REQUIRE(p1.hasCost());
216 BOOST_CHECK_EQUAL(p1.getCost(), 0);
217 BOOST_REQUIRE(p1.hasFlags());
218 BOOST_CHECK_EQUAL(p1.getFlags(), static_cast<uint64_t>(ROUTE_FLAG_CHILD_INHERIT));
219 BOOST_REQUIRE(p1.hasExpirationPeriod());
220 BOOST_CHECK_GT(p1.getExpirationPeriod(), time::hours(240));
221
222 ControlParameters p2;
223 p2.setName("ndn:/example")
224 .setFaceId(2)
225 .setCost(6);
226 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
227 command.applyDefaultsToRequest(p2);
228 BOOST_CHECK_EQUAL(p2.getExpirationPeriod(), time::hours(1));
229 BOOST_CHECK_NO_THROW(command.validateResponse(p2));
230}
231
232BOOST_AUTO_TEST_CASE(RibUnregister)
233{
234 RibUnregisterCommand command;
235 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/rib/unregister");
236
237 ControlParameters p1;
238 p1.setName("ndn:/")
239 .setFaceId(22)
240 .setOrigin(ROUTE_ORIGIN_STATIC);
241 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
242 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
243
244 ControlParameters p2;
245 p2.setName("ndn:/example")
246 .setFaceId(0)
247 .setOrigin(ROUTE_ORIGIN_APP);
248 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
249 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
250
251 p2.unsetFaceId();
252 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
253 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
254}
255
Junxiao Shi5ec80222014-03-25 20:08:05 -0700256BOOST_AUTO_TEST_SUITE_END()
257
258} // namespace nfd
259} // namespace ndn