blob: bce68b7889b0ecf4ff6b2bc39c40712c3ae9023c [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/face-module.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi1f481fa2017-01-26 15:14:43 +000028#include "execute-command-fixture.hpp"
29#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 Shi1d7fef52017-02-02 05:33:14 +000036using ndn::nfd::FaceQueryFilter;
37
Junxiao Shi331ade72016-08-19 14:07:19 +000038BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000039BOOST_AUTO_TEST_SUITE(TestFaceModule)
40
Junxiao Shi36e54292017-02-17 18:43:16 +000041BOOST_FIXTURE_TEST_SUITE(ListCommand, ExecuteCommandFixture)
42
43const std::string NONQUERY_OUTPUT =
44 "faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
45 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
46 " flags={non-local permanent multi-access}\n"
47 "faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
48 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
49 " flags={local on-demand point-to-point local-fields}\n";
50
51BOOST_AUTO_TEST_CASE(NormalNonQuery)
52{
53 this->processInterest = [this] (const Interest& interest) {
54 FaceStatus payload1;
55 payload1.setFaceId(134)
56 .setRemoteUri("udp4://233.252.0.4:6363")
57 .setLocalUri("udp4://192.0.2.1:6363")
58 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
59 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
60 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
61 .setNInInterests(22562)
62 .setNInDatas(22031)
63 .setNInNacks(63)
64 .setNOutInterests(30121)
65 .setNOutDatas(20940)
66 .setNOutNacks(1218)
67 .setNInBytes(2522915)
68 .setNOutBytes(1353592);
69 FaceStatus payload2;
70 payload2.setFaceId(745)
71 .setRemoteUri("fd://75")
72 .setLocalUri("unix:///var/run/nfd.sock")
73 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
74 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
75 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
76 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
77 .setNInInterests(18998)
78 .setNInDatas(26701)
79 .setNInNacks(147)
80 .setNOutInterests(34779)
81 .setNOutDatas(17028)
82 .setNOutNacks(1176)
83 .setNInBytes(4672308)
84 .setNOutBytes(8957187);
85 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
86 };
87
88 this->execute("face list");
89 BOOST_CHECK_EQUAL(exitCode, 0);
90 BOOST_CHECK(out.is_equal(NONQUERY_OUTPUT));
91 BOOST_CHECK(err.is_empty());
92}
93
94const std::string QUERY_OUTPUT =
95 "faceid=177 remote=tcp4://53.239.9.114:6363 local=tcp4://164.0.31.106:20396"
96 " counters={in={2325i 1110d 79n 4716834B} out={2278i 485d 841n 308108B}}"
97 " flags={non-local persistent point-to-point}\n";
98
99BOOST_AUTO_TEST_CASE(NormalQuery)
100{
101 this->processInterest = [this] (const Interest& interest) {
102 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
103 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
104 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
105 FaceQueryFilter expectedFilter;
106 expectedFilter.setRemoteUri("tcp4://53.239.9.114:6363")
107 .setLocalUri("tcp4://164.0.31.106:20396")
108 .setUriScheme("tcp4");
109 BOOST_CHECK_EQUAL(filter, expectedFilter);
110
111 FaceStatus payload;
112 payload.setFaceId(177)
113 .setRemoteUri("tcp4://53.239.9.114:6363")
114 .setLocalUri("tcp4://164.0.31.106:20396")
115 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
116 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
117 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
118 .setNInInterests(2325)
119 .setNInDatas(1110)
120 .setNInNacks(79)
121 .setNOutInterests(2278)
122 .setNOutDatas(485)
123 .setNOutNacks(841)
124 .setNInBytes(4716834)
125 .setNOutBytes(308108);
126 this->sendDataset(interest.getName(), payload);
127 };
128
129 this->execute("face list tcp://53.239.9.114 scheme tcp4 local tcp://164.0.31.106:20396");
130 BOOST_CHECK_EQUAL(exitCode, 0);
131 BOOST_CHECK(out.is_equal(QUERY_OUTPUT));
132 BOOST_CHECK(err.is_empty());
133}
134
135BOOST_AUTO_TEST_CASE(NotFound)
136{
137 this->processInterest = [this] (const Interest& interest) {
138 this->sendEmptyDataset(interest.getName());
139 };
140
141 this->execute("face list scheme udp6");
142 BOOST_CHECK_EQUAL(exitCode, 3);
143 BOOST_CHECK(out.is_empty());
144 BOOST_CHECK(err.is_equal("Face not found\n"));
145}
146
147BOOST_AUTO_TEST_CASE(Error)
148{
149 this->processInterest = nullptr; // no response
150
151 this->execute("face list local udp4://31.67.17.2:6363");
152 BOOST_CHECK_EQUAL(exitCode, 1);
153 BOOST_CHECK(out.is_empty());
154 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
155}
156
157BOOST_AUTO_TEST_SUITE_END() // ListCommand
158
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000159BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
160
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000161const std::string NORMAL_OUTPUT = std::string(R"TEXT(
162 faceid=256
163 remote=udp4://84.67.35.111:6363
164 local=udp4://79.91.49.215:6363
165counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
166 flags={non-local on-demand point-to-point}
167)TEXT").substr(1);
168
169BOOST_AUTO_TEST_CASE(Normal)
170{
171 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi36e54292017-02-17 18:43:16 +0000172 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
Junxiao Shi8f803f22017-02-10 03:04:28 +0000173 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
174 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
175 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000176
177 FaceStatus payload;
178 payload.setFaceId(256)
179 .setRemoteUri("udp4://84.67.35.111:6363")
180 .setLocalUri("udp4://79.91.49.215:6363")
181 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
182 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
183 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
184 .setNInInterests(28975)
185 .setNInDatas(28232)
186 .setNInNacks(212)
187 .setNOutInterests(19525)
188 .setNOutDatas(30993)
189 .setNOutNacks(1038)
190 .setNInBytes(13307258)
191 .setNOutBytes(6231946);
192
Junxiao Shi8f803f22017-02-10 03:04:28 +0000193 this->sendDataset(interest.getName(), payload);
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000194 };
195
196 this->execute("face show 256");
197 BOOST_CHECK_EQUAL(exitCode, 0);
198 BOOST_CHECK(out.is_equal(NORMAL_OUTPUT));
199 BOOST_CHECK(err.is_empty());
200}
201
202BOOST_AUTO_TEST_CASE(NotFound)
203{
204 this->processInterest = [this] (const Interest& interest) {
205 this->sendEmptyDataset(interest.getName());
206 };
207
208 this->execute("face show 256");
209 BOOST_CHECK_EQUAL(exitCode, 3);
210 BOOST_CHECK(out.is_empty());
Junxiao Shi8f803f22017-02-10 03:04:28 +0000211 BOOST_CHECK(err.is_equal("Face not found\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000212}
213
214BOOST_AUTO_TEST_CASE(Error)
215{
216 this->processInterest = nullptr; // no response
217
218 this->execute("face show 256");
219 BOOST_CHECK_EQUAL(exitCode, 1);
220 BOOST_CHECK(out.is_empty());
Junxiao Shi8f803f22017-02-10 03:04:28 +0000221 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000222}
223
224BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000225
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000226class ExecuteFaceCreateCommandFixture : public ExecuteCommandFixture
227{
228protected:
229 void
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000230 respond409(const Interest& interest, FacePersistency persistency)
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000231 {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000232 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000233 ControlParameters body;
234 body.setFaceId(1172)
235 .setUri("udp4://100.77.30.65:6363")
236 .setFacePersistency(persistency)
237 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000238 this->failCommand(interest, 409, "conflict-409", body);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000239 }
240};
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000241
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000242BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteFaceCreateCommandFixture)
243
244BOOST_AUTO_TEST_CASE(Creating)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000245{
246 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000247 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000248 BOOST_REQUIRE(req.hasUri());
249 BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363");
250 BOOST_REQUIRE(req.hasFacePersistency());
251 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
252
253 ControlParameters resp;
254 resp.setFaceId(2130)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000255 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000256 this->succeedCommand(interest, resp);
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000257 };
258
259 this->execute("face create udp://159.242.33.78");
260 BOOST_CHECK_EQUAL(exitCode, 0);
261 BOOST_CHECK(out.is_equal("face-created id=2130 remote=udp4://159.242.33.78:6363 persistency=persistent\n"));
262 BOOST_CHECK(err.is_empty());
263}
264
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000265BOOST_AUTO_TEST_CASE(UpgradingPersistency)
266{
267 bool hasUpdateCommand = false;
268 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000269 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
270 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000271 return;
272 }
273
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000274 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000275 hasUpdateCommand = true;
276 BOOST_REQUIRE(req.hasFaceId());
277 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
278 BOOST_REQUIRE(req.hasFacePersistency());
279 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
280 BOOST_CHECK(!req.hasFlags());
281
282 ControlParameters resp;
283 resp.setFaceId(1172)
284 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
285 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000286 this->succeedCommand(interest, resp);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000287 };
288
289 this->execute("face create udp://100.77.30.65");
290 BOOST_CHECK(hasUpdateCommand);
291 BOOST_CHECK_EQUAL(exitCode, 0);
292 BOOST_CHECK(out.is_equal("face-updated id=1172 remote=udp4://100.77.30.65:6363 persistency=persistent\n"));
293 BOOST_CHECK(err.is_empty());
294}
295
296BOOST_AUTO_TEST_CASE(NotDowngradingPersistency)
297{
298 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000299 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERMANENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000300 // no command other than faces/create is expected
301 };
302
303 this->execute("face create udp://100.77.30.65");
304 BOOST_CHECK_EQUAL(exitCode, 0);
305 BOOST_CHECK(out.is_equal("face-exists id=1172 remote=udp4://100.77.30.65:6363 persistency=permanent\n"));
306 BOOST_CHECK(err.is_empty());
307}
308
309BOOST_AUTO_TEST_CASE(SamePersistency)
310{
311 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000312 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000313 // no command other than faces/create is expected
314 };
315
316 this->execute("face create udp://100.77.30.65");
317 BOOST_CHECK_EQUAL(exitCode, 0);
318 BOOST_CHECK(out.is_equal("face-exists id=1172 remote=udp4://100.77.30.65:6363 persistency=persistent\n"));
319 BOOST_CHECK(err.is_empty());
320}
321
322BOOST_AUTO_TEST_CASE(ErrorCreate)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000323{
324 this->processInterest = nullptr; // no response
325
326 this->execute("face create udp://159.242.33.78");
327 BOOST_CHECK_EQUAL(exitCode, 1);
328 BOOST_CHECK(out.is_empty());
329 BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n"));
330}
331
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000332BOOST_AUTO_TEST_CASE(ErrorConflict)
333{
334 // Current NFD will not report a 409-conflict with a different remote FaceUri, but this is
335 // allowed by FaceMgmt protocol and nfdc should not attempt to upgrade persistency in this case.
336
337 this->processInterest = [this] (const Interest& interest) {
338 // conflict with udp4://100.77.30.65:6363
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000339 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000340 };
341
342 this->execute("face create udp://20.53.73.45");
343 BOOST_CHECK_EQUAL(exitCode, 1);
344 BOOST_CHECK(out.is_empty());
345 BOOST_CHECK(err.is_equal("Error 409 when creating face: conflict-409\n"));
346}
347
348BOOST_AUTO_TEST_CASE(ErrorUpdate)
349{
350 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000351 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
352 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000353 return;
354 }
355
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000356 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000357 // no response to faces/update
358 };
359
360 this->execute("face create udp://100.77.30.65");
361 BOOST_CHECK_EQUAL(exitCode, 1);
362 BOOST_CHECK(out.is_empty());
363 BOOST_CHECK(err.is_equal("Error 10060 when upgrading face persistency: request timed out\n"));
364}
365
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000366BOOST_AUTO_TEST_SUITE_END() // CreateCommand
367
Junxiao Shi05dd4442017-02-06 22:50:07 +0000368BOOST_FIXTURE_TEST_SUITE(DestroyCommand, ExecuteCommandFixture)
369
370BOOST_AUTO_TEST_CASE(NormalByFaceId)
371{
372 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000373 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000374 return;
375 }
376
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000377 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000378 BOOST_REQUIRE(req.hasFaceId());
379 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
380
381 ControlParameters resp;
382 resp.setFaceId(10156);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000383 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000384 };
385
386 this->execute("face destroy 10156");
387 BOOST_CHECK_EQUAL(exitCode, 0);
388 BOOST_CHECK(out.is_equal("face-destroyed id=10156 local=tcp4://151.26.163.27:22967 "
389 "remote=tcp4://198.57.27.40:6363 persistency=persistent\n"));
390 BOOST_CHECK(err.is_empty());
391}
392
393BOOST_AUTO_TEST_CASE(NormalByFaceUri)
394{
395 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000396 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000397 return;
398 }
399
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000400 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000401 BOOST_REQUIRE(req.hasFaceId());
402 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
403
404 ControlParameters resp;
405 resp.setFaceId(2249);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000406 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000407 };
408
409 this->execute("face destroy tcp://32.121.182.82");
410 BOOST_CHECK_EQUAL(exitCode, 0);
411 BOOST_CHECK(out.is_equal("face-destroyed id=2249 local=tcp4://30.99.87.98:31414 "
412 "remote=tcp4://32.121.182.82:6363 persistency=persistent\n"));
413 BOOST_CHECK(err.is_empty());
414}
415
416BOOST_AUTO_TEST_CASE(FaceNotExist)
417{
418 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000419 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000420 };
421
422 this->execute("face destroy 23728");
423 BOOST_CHECK_EQUAL(exitCode, 3);
424 BOOST_CHECK(out.is_empty());
425 BOOST_CHECK(err.is_equal("Face not found\n"));
426}
427
428BOOST_AUTO_TEST_CASE(Ambiguous)
429{
430 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000431 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000432 };
433
434 this->execute("face destroy udp4://225.131.75.231:56363");
435 BOOST_CHECK_EQUAL(exitCode, 5);
436 BOOST_CHECK(out.is_empty());
437 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
438 "Re-run the command with a FaceId: "
439 "6720 (local=udp4://202.83.168.28:56363), "
440 "31066 (local=udp4://25.90.26.32:56363)\n"));
441}
442
443BOOST_AUTO_TEST_CASE(ErrorCanonization)
444{
445 this->execute("face destroy udp6://32.38.164.64:10445");
446 BOOST_CHECK_EQUAL(exitCode, 4);
447 BOOST_CHECK(out.is_empty());
448 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
449 "No endpoints match the specified address selector\n"));
450}
451
452BOOST_AUTO_TEST_CASE(ErrorDataset)
453{
454 this->processInterest = nullptr; // no response to dataset or command
455
456 this->execute("face destroy udp://159.242.33.78");
457 BOOST_CHECK_EQUAL(exitCode, 1);
458 BOOST_CHECK(out.is_empty());
459 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
460}
461
462BOOST_AUTO_TEST_CASE(ErrorCommand)
463{
464 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000465 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000466 return;
467 }
468
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000469 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000470 // no response to command
471 };
472
Junxiao Shi918e5d42017-02-25 03:58:21 +0000473 this->execute("face destroy 10156");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000474 BOOST_CHECK_EQUAL(exitCode, 1);
475 BOOST_CHECK(out.is_empty());
476 BOOST_CHECK(err.is_equal("Error 10060 when destroying face: request timed out\n"));
477}
478
479BOOST_AUTO_TEST_SUITE_END() // DestroyCommand
480
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000481const std::string STATUS_XML = stripXmlSpaces(R"XML(
482 <faces>
483 <face>
484 <faceId>134</faceId>
485 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
486 <localUri>udp4://192.0.2.1:6363</localUri>
487 <faceScope>non-local</faceScope>
488 <facePersistency>permanent</facePersistency>
489 <linkType>multi-access</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000490 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000491 <packetCounters>
492 <incomingPackets>
493 <nInterests>22562</nInterests>
494 <nDatas>22031</nDatas>
495 <nNacks>63</nNacks>
496 </incomingPackets>
497 <outgoingPackets>
498 <nInterests>30121</nInterests>
499 <nDatas>20940</nDatas>
500 <nNacks>1218</nNacks>
501 </outgoingPackets>
502 </packetCounters>
503 <byteCounters>
504 <incomingBytes>2522915</incomingBytes>
505 <outgoingBytes>1353592</outgoingBytes>
506 </byteCounters>
507 </face>
508 <face>
509 <faceId>745</faceId>
510 <remoteUri>fd://75</remoteUri>
511 <localUri>unix:///var/run/nfd.sock</localUri>
512 <faceScope>local</faceScope>
513 <facePersistency>on-demand</facePersistency>
514 <linkType>point-to-point</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000515 <flags>
516 <localFieldsEnabled/>
517 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000518 <packetCounters>
519 <incomingPackets>
520 <nInterests>18998</nInterests>
521 <nDatas>26701</nDatas>
522 <nNacks>147</nNacks>
523 </incomingPackets>
524 <outgoingPackets>
525 <nInterests>34779</nInterests>
526 <nDatas>17028</nDatas>
527 <nNacks>1176</nNacks>
528 </outgoingPackets>
529 </packetCounters>
530 <byteCounters>
531 <incomingBytes>4672308</incomingBytes>
532 <outgoingBytes>8957187</outgoingBytes>
533 </byteCounters>
534 </face>
535 </faces>
536)XML");
537
538const std::string STATUS_TEXT =
539 "Faces:\n"
540 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
541 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000542 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000543 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
544 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000545 " flags={local on-demand point-to-point local-fields}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000546
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000547BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000548{
549 this->fetchStatus();
550 FaceStatus payload1;
551 payload1.setFaceId(134)
552 .setRemoteUri("udp4://233.252.0.4:6363")
553 .setLocalUri("udp4://192.0.2.1:6363")
554 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
555 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
556 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
557 .setNInInterests(22562)
558 .setNInDatas(22031)
559 .setNInNacks(63)
560 .setNOutInterests(30121)
561 .setNOutDatas(20940)
562 .setNOutNacks(1218)
563 .setNInBytes(2522915)
564 .setNOutBytes(1353592);
565 FaceStatus payload2;
566 payload2.setFaceId(745)
567 .setRemoteUri("fd://75")
568 .setLocalUri("unix:///var/run/nfd.sock")
569 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
570 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
571 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberry6d932e82016-11-24 05:05:43 +0000572 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000573 .setNInInterests(18998)
574 .setNInDatas(26701)
575 .setNInNacks(147)
576 .setNOutInterests(34779)
577 .setNOutDatas(17028)
578 .setNOutNacks(1176)
579 .setNInBytes(4672308)
580 .setNOutBytes(8957187);
581 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
582 this->prepareStatusOutput();
583
584 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
585 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
586}
587
588BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000589BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000590
591} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000592} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000593} // namespace tools
594} // namespace nfd