blob: df0a696636caeb10afd0ceda7e42b6787de16983 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi1f481fa2017-01-26 15:14:43 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Junxiao Shi331ade72016-08-19 14:07:19 +000026#include "nfdc/rib-module.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi918e5d42017-02-25 03:58:21 +000028#include "execute-command-fixture.hpp"
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030
31namespace nfd {
32namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000033namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000034namespace tests {
35
Junxiao Shi331ade72016-08-19 14:07:19 +000036BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000037BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000038
Junxiao Shi918e5d42017-02-25 03:58:21 +000039BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture)
40
41BOOST_AUTO_TEST_CASE(NormalByFaceId)
42{
43 this->processInterest = [this] (const Interest& interest) {
44 if (this->respondFaceQuery(interest)) {
45 return;
46 }
47
48 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
49 ndn::nfd::RibRegisterCommand cmd;
50 cmd.validateRequest(req);
51 cmd.applyDefaultsToRequest(req);
52 BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB");
53 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
54 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
55 BOOST_CHECK_EQUAL(req.getCost(), 0);
56 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAGS_NONE);
57 BOOST_CHECK_EQUAL(req.hasExpirationPeriod(), false);
58
59 this->succeedCommand(req);
60 };
61
62 this->execute("route add /vxXoEaWeDB 10156 no-inherit");
63 BOOST_CHECK_EQUAL(exitCode, 0);
64 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=255 "
65 "cost=0 flags=none expires=never\n"));
66 BOOST_CHECK(err.is_empty());
67}
68
69BOOST_AUTO_TEST_CASE(NormalByFaceUri)
70{
71 this->processInterest = [this] (const Interest& interest) {
72 if (this->respondFaceQuery(interest)) {
73 return;
74 }
75
76 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
77 ndn::nfd::RibRegisterCommand cmd;
78 cmd.validateRequest(req);
79 cmd.applyDefaultsToRequest(req);
80 BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf");
81 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
82 BOOST_CHECK_EQUAL(req.getOrigin(), 17591);
83 BOOST_CHECK_EQUAL(req.getCost(), 702);
84 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
85 ndn::nfd::ROUTE_FLAG_CAPTURE);
86 BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true);
87 BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), time::milliseconds(727411987));
88
89 ControlParameters resp = req;
90 resp.setExpirationPeriod(time::milliseconds(727411154)); // server side may change expiration
91 this->succeedCommand(resp);
92 };
93
94 this->execute("route add /FLQAsaYnYf tcp4://32.121.182.82:6363 "
95 "origin 17591 cost 702 capture expires 727411987");
96 BOOST_CHECK_EQUAL(exitCode, 0);
97 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/FLQAsaYnYf nexthop=2249 origin=17591 "
98 "cost=702 flags=child-inherit|capture expires=727411154ms\n"));
99 BOOST_CHECK(err.is_empty());
100}
101
102BOOST_AUTO_TEST_CASE(FaceNotExist)
103{
104 this->processInterest = [this] (const Interest& interest) {
105 BOOST_CHECK(this->respondFaceQuery(interest));
106 };
107
108 this->execute("route add /GJiKDus5i 23728");
109 BOOST_CHECK_EQUAL(exitCode, 3);
110 BOOST_CHECK(out.is_empty());
111 BOOST_CHECK(err.is_equal("Face not found\n"));
112}
113
114BOOST_AUTO_TEST_CASE(Ambiguous)
115{
116 this->processInterest = [this] (const Interest& interest) {
117 BOOST_CHECK(this->respondFaceQuery(interest));
118 };
119
120 this->execute("route add /BQqjjnVsz udp4://225.131.75.231:56363");
121 BOOST_CHECK_EQUAL(exitCode, 5);
122 BOOST_CHECK(out.is_empty());
123 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
124 "Re-run the command with a FaceId: "
125 "6720 (local=udp4://202.83.168.28:56363), "
126 "31066 (local=udp4://25.90.26.32:56363)\n"));
127}
128
129BOOST_AUTO_TEST_CASE(ErrorCanonization)
130{
131 this->execute("route add /bxJfGsVtDt udp6://32.38.164.64:10445");
132 BOOST_CHECK_EQUAL(exitCode, 4);
133 BOOST_CHECK(out.is_empty());
134 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
135 "No endpoints match the specified address selector\n"));
136}
137
138BOOST_AUTO_TEST_CASE(ErrorDataset)
139{
140 this->processInterest = nullptr; // no response to dataset or command
141
142 this->execute("route add /q1Qf7go7 udp://159.242.33.78");
143 BOOST_CHECK_EQUAL(exitCode, 1);
144 BOOST_CHECK(out.is_empty());
145 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
146}
147
148BOOST_AUTO_TEST_CASE(ErrorCommand)
149{
150 this->processInterest = [this] (const Interest& interest) {
151 if (this->respondFaceQuery(interest)) {
152 return;
153 }
154
155 MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/rib/register");
156 // no response to command
157 };
158
159 this->execute("route add /bYiMbEuE 10156");
160 BOOST_CHECK_EQUAL(exitCode, 1);
161 BOOST_CHECK(out.is_empty());
162 BOOST_CHECK(err.is_equal("Error 10060 when adding route: request timed out\n"));
163}
164
165BOOST_AUTO_TEST_SUITE_END() // AddCommand
166
Junxiao Shi084b7952017-02-26 22:00:53 +0000167BOOST_FIXTURE_TEST_SUITE(RemoveCommand, ExecuteCommandFixture)
168
169BOOST_AUTO_TEST_CASE(NormalByFaceId)
170{
171 this->processInterest = [this] (const Interest& interest) {
172 if (this->respondFaceQuery(interest)) {
173 return;
174 }
175
176 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
177 ndn::nfd::RibUnregisterCommand cmd;
178 cmd.validateRequest(req);
179 cmd.applyDefaultsToRequest(req);
180 BOOST_CHECK_EQUAL(req.getName(), "/2B5NUGjpt");
181 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
182 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
183
184 this->succeedCommand(interest, req);
185 };
186
187 this->execute("route remove /2B5NUGjpt 10156");
188 BOOST_CHECK_EQUAL(exitCode, 0);
189 BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=255\n"));
190 BOOST_CHECK(err.is_empty());
191}
192
193BOOST_AUTO_TEST_CASE(NormalByFaceUri)
194{
195 this->processInterest = [this] (const Interest& interest) {
196 if (this->respondFaceQuery(interest)) {
197 return;
198 }
199
200 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
201 ndn::nfd::RibUnregisterCommand cmd;
202 cmd.validateRequest(req);
203 cmd.applyDefaultsToRequest(req);
204 BOOST_CHECK_EQUAL(req.getName(), "/wHdNn0BtUF");
205 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
206 BOOST_CHECK_EQUAL(req.getOrigin(), 15246);
207
208 this->succeedCommand(interest, req);
209 };
210
211 this->execute("route remove /wHdNn0BtUF tcp4://32.121.182.82:6363 origin 15246");
212 BOOST_CHECK_EQUAL(exitCode, 0);
213 BOOST_CHECK(out.is_equal("route-removed prefix=/wHdNn0BtUF nexthop=2249 origin=15246\n"));
214 BOOST_CHECK(err.is_empty());
215}
216
217BOOST_AUTO_TEST_CASE(MultipleFaces)
218{
219 std::set<uint64_t> faceIds{6720, 31066};
220 this->processInterest = [this, &faceIds] (const Interest& interest) {
221 if (this->respondFaceQuery(interest)) {
222 return;
223 }
224
225 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
226 ndn::nfd::RibUnregisterCommand cmd;
227 cmd.validateRequest(req);
228 cmd.applyDefaultsToRequest(req);
229 BOOST_CHECK_EQUAL(req.getName(), "/nm5y8X8b2");
230 BOOST_CHECK_MESSAGE(faceIds.erase(req.getFaceId()), "expected face " + std::to_string(req.getFaceId()));
231 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
232
233 this->succeedCommand(interest, req);
234 };
235
236 this->execute("route remove /nm5y8X8b2 udp4://225.131.75.231:56363");
237 BOOST_CHECK(faceIds.empty());
238 BOOST_CHECK_EQUAL(exitCode, 0);
239 BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=255\n"
240 "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=255\n"));
241 BOOST_CHECK(err.is_empty());
242}
243
244BOOST_AUTO_TEST_CASE(FaceNotExist)
245{
246 this->processInterest = [this] (const Interest& interest) {
247 BOOST_CHECK(this->respondFaceQuery(interest));
248 };
249
250 this->execute("route remove /HeGRjzwFM 23728");
251 BOOST_CHECK_EQUAL(exitCode, 3);
252 BOOST_CHECK(out.is_empty());
253 BOOST_CHECK(err.is_equal("Face not found\n"));
254}
255
256BOOST_AUTO_TEST_CASE(ErrorDataset)
257{
258 this->processInterest = nullptr; // no response to dataset or command
259
260 this->execute("route remove /YX4xQQN3v5 udp://26.97.248.3");
261 BOOST_CHECK_EQUAL(exitCode, 1);
262 BOOST_CHECK(out.is_empty());
263 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
264}
265
266BOOST_AUTO_TEST_CASE(ErrorCommand)
267{
268 this->processInterest = [this] (const Interest& interest) {
269 if (this->respondFaceQuery(interest)) {
270 return;
271 }
272
273 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
274 // no response to command
275 };
276
277 this->execute("route remove /mvGRoxD2 10156");
278 BOOST_CHECK_EQUAL(exitCode, 1);
279 BOOST_CHECK(out.is_empty());
280 BOOST_CHECK(err.is_equal("Error 10060 when removing route: request timed out\n"));
281}
282
283BOOST_AUTO_TEST_SUITE_END() // RemoveCommand
284
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000285const std::string STATUS_XML = stripXmlSpaces(R"XML(
286 <rib>
287 <ribEntry>
288 <prefix>/</prefix>
289 <routes>
290 <route>
291 <faceId>262</faceId>
292 <origin>255</origin>
293 <cost>9</cost>
294 <flags>
295 <ribCapture/>
296 </flags>
297 </route>
298 <route>
299 <faceId>272</faceId>
300 <origin>255</origin>
301 <cost>50</cost>
302 <flags/>
303 </route>
304 <route>
305 <faceId>274</faceId>
306 <origin>255</origin>
307 <cost>78</cost>
308 <flags>
309 <childInherit/>
310 <ribCapture/>
311 </flags>
312 </route>
313 <route>
314 <faceId>276</faceId>
315 <origin>255</origin>
316 <cost>79</cost>
317 <flags>
318 <childInherit/>
319 </flags>
320 <expirationPeriod>PT47S</expirationPeriod>
321 </route>
322 </routes>
323 </ribEntry>
324 <ribEntry>
325 <prefix>/localhost/nfd</prefix>
326 <routes>
327 <route>
328 <faceId>258</faceId>
329 <origin>0</origin>
330 <cost>0</cost>
331 <flags>
332 <childInherit/>
333 </flags>
334 </route>
335 </routes>
336 </ribEntry>
337 </rib>
338)XML");
339
340const std::string STATUS_TEXT =
341 "RIB:\n"
342 " / route={faceid=262 (origin=255 cost=9 RibCapture), faceid=272 (origin=255 cost=50), "
343 "faceid=274 (origin=255 cost=78 ChildInherit RibCapture), "
344 "faceid=276 (origin=255 cost=79 expires=47s ChildInherit)}\n"
345 " /localhost/nfd route={faceid=258 (origin=0 cost=0 ChildInherit)}\n";
346
347BOOST_AUTO_TEST_CASE(Status)
348{
349 this->fetchStatus();
350 RibEntry payload1;
351 payload1.setName("/")
352 .addRoute(Route().setFaceId(262)
353 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
354 .setCost(9)
355 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE))
356 .addRoute(Route().setFaceId(272)
357 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
358 .setCost(50)
359 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE))
360 .addRoute(Route().setFaceId(274)
361 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
362 .setCost(78)
363 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE))
364 .addRoute(Route().setFaceId(276)
365 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
366 .setCost(79)
367 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
368 .setExpirationPeriod(time::milliseconds(47292)));
369 RibEntry payload2;
370 payload2.setName("/localhost/nfd")
371 .addRoute(Route().setFaceId(258)
372 .setOrigin(ndn::nfd::ROUTE_ORIGIN_APP)
373 .setCost(0)
374 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
375 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
376 this->prepareStatusOutput();
377
378 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
379 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
380}
381
382BOOST_AUTO_TEST_SUITE_END() // TestRibModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000383BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000384
385} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000386} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000387} // namespace tools
388} // namespace nfd