blob: 8d465e2c1441e4961fbc8647ecef5e5a9cd99d0a [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 Shi1d7fef52017-02-02 05:33:14 +000027#include <ndn-cxx/mgmt/nfd/face-query-filter.hpp>
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "execute-command-fixture.hpp"
30#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000031
32namespace nfd {
33namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000034namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035namespace tests {
36
Junxiao Shi1d7fef52017-02-02 05:33:14 +000037using ndn::nfd::FaceQueryFilter;
38
Junxiao Shi331ade72016-08-19 14:07:19 +000039BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000040BOOST_AUTO_TEST_SUITE(TestFaceModule)
41
42BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
43
Junxiao Shi1f481fa2017-01-26 15:14:43 +000044const std::string NORMAL_OUTPUT = std::string(R"TEXT(
45 faceid=256
46 remote=udp4://84.67.35.111:6363
47 local=udp4://79.91.49.215:6363
48counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
49 flags={non-local on-demand point-to-point}
50)TEXT").substr(1);
51
52BOOST_AUTO_TEST_CASE(Normal)
53{
54 this->processInterest = [this] (const Interest& interest) {
55 Name datasetName("/localhost/nfd/faces/query");
56 FaceQueryFilter filter;
57 filter.setFaceId(256);
58 datasetName.append(filter.wireEncode());
59
60 FaceStatus payload;
61 payload.setFaceId(256)
62 .setRemoteUri("udp4://84.67.35.111:6363")
63 .setLocalUri("udp4://79.91.49.215:6363")
64 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
65 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
66 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
67 .setNInInterests(28975)
68 .setNInDatas(28232)
69 .setNInNacks(212)
70 .setNOutInterests(19525)
71 .setNOutDatas(30993)
72 .setNOutNacks(1038)
73 .setNInBytes(13307258)
74 .setNOutBytes(6231946);
75
76 this->sendDataset(datasetName, payload);
77 };
78
79 this->execute("face show 256");
80 BOOST_CHECK_EQUAL(exitCode, 0);
81 BOOST_CHECK(out.is_equal(NORMAL_OUTPUT));
82 BOOST_CHECK(err.is_empty());
83}
84
85BOOST_AUTO_TEST_CASE(NotFound)
86{
87 this->processInterest = [this] (const Interest& interest) {
88 this->sendEmptyDataset(interest.getName());
89 };
90
91 this->execute("face show 256");
92 BOOST_CHECK_EQUAL(exitCode, 3);
93 BOOST_CHECK(out.is_empty());
94 BOOST_CHECK(err.is_equal("Face 256 not found.\n"));
95}
96
97BOOST_AUTO_TEST_CASE(Error)
98{
99 this->processInterest = nullptr; // no response
100
101 this->execute("face show 256");
102 BOOST_CHECK_EQUAL(exitCode, 1);
103 BOOST_CHECK(out.is_empty());
104 BOOST_CHECK(err.is_equal("Error 10060 when fetching face information: Timeout\n"));
105}
106
107BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000108
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000109BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteCommandFixture)
110
111BOOST_AUTO_TEST_CASE(Normal)
112{
113 this->processInterest = [this] (const Interest& interest) {
114 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/create");
115 BOOST_REQUIRE(req.hasUri());
116 BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363");
117 BOOST_REQUIRE(req.hasFacePersistency());
118 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
119
120 ControlParameters resp;
121 resp.setFaceId(2130)
122 .setUri("udp4://159.242.33.78:6363")
123 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
124 this->succeedCommand(resp);
125 };
126
127 this->execute("face create udp://159.242.33.78");
128 BOOST_CHECK_EQUAL(exitCode, 0);
129 BOOST_CHECK(out.is_equal("face-created id=2130 remote=udp4://159.242.33.78:6363 persistency=persistent\n"));
130 BOOST_CHECK(err.is_empty());
131}
132
133BOOST_AUTO_TEST_CASE(Error)
134{
135 this->processInterest = nullptr; // no response
136
137 this->execute("face create udp://159.242.33.78");
138 BOOST_CHECK_EQUAL(exitCode, 1);
139 BOOST_CHECK(out.is_empty());
140 BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n"));
141}
142
143BOOST_AUTO_TEST_SUITE_END() // CreateCommand
144
Junxiao Shi05dd4442017-02-06 22:50:07 +0000145BOOST_FIXTURE_TEST_SUITE(DestroyCommand, ExecuteCommandFixture)
146
147BOOST_AUTO_TEST_CASE(NormalByFaceId)
148{
149 this->processInterest = [this] (const Interest& interest) {
150 if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
151 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
152 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
153 // BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(10156));
154 BOOST_CHECK_EQUAL(filter.getFaceId(), 10156);
155
156 FaceStatus faceStatus;
157 faceStatus.setFaceId(10156)
158 .setLocalUri("tcp4://151.26.163.27:22967")
159 .setRemoteUri("tcp4://198.57.27.40:6363")
160 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
161 this->sendDataset(interest.getName(), faceStatus);
162 return;
163 }
164
165 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy");
166 BOOST_REQUIRE(req.hasFaceId());
167 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
168
169 ControlParameters resp;
170 resp.setFaceId(10156);
171 this->succeedCommand(resp);
172 };
173
174 this->execute("face destroy 10156");
175 BOOST_CHECK_EQUAL(exitCode, 0);
176 BOOST_CHECK(out.is_equal("face-destroyed id=10156 local=tcp4://151.26.163.27:22967 "
177 "remote=tcp4://198.57.27.40:6363 persistency=persistent\n"));
178 BOOST_CHECK(err.is_empty());
179}
180
181BOOST_AUTO_TEST_CASE(NormalByFaceUri)
182{
183 this->processInterest = [this] (const Interest& interest) {
184 if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
185 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
186 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
187 // BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363"));
188 BOOST_CHECK_EQUAL(filter.getRemoteUri(), "tcp4://32.121.182.82:6363");
189
190 FaceStatus faceStatus;
191 faceStatus.setFaceId(2249)
192 .setLocalUri("tcp4://30.99.87.98:31414")
193 .setRemoteUri("tcp4://32.121.182.82:6363")
194 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
195 this->sendDataset(interest.getName(), faceStatus);
196 return;
197 }
198
199 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy");
200 BOOST_REQUIRE(req.hasFaceId());
201 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
202
203 ControlParameters resp;
204 resp.setFaceId(2249);
205 this->succeedCommand(resp);
206 };
207
208 this->execute("face destroy tcp://32.121.182.82");
209 BOOST_CHECK_EQUAL(exitCode, 0);
210 BOOST_CHECK(out.is_equal("face-destroyed id=2249 local=tcp4://30.99.87.98:31414 "
211 "remote=tcp4://32.121.182.82:6363 persistency=persistent\n"));
212 BOOST_CHECK(err.is_empty());
213}
214
215BOOST_AUTO_TEST_CASE(FaceNotExist)
216{
217 this->processInterest = [this] (const Interest& interest) {
218 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
219 this->sendEmptyDataset(interest.getName());
220 };
221
222 this->execute("face destroy 23728");
223 BOOST_CHECK_EQUAL(exitCode, 3);
224 BOOST_CHECK(out.is_empty());
225 BOOST_CHECK(err.is_equal("Face not found\n"));
226}
227
228BOOST_AUTO_TEST_CASE(Ambiguous)
229{
230 this->processInterest = [this] (const Interest& interest) {
231 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
232
233 FaceStatus faceStatus1, faceStatus2;
234 faceStatus1.setFaceId(6720)
235 .setLocalUri("udp4://202.83.168.28:56363")
236 .setRemoteUri("udp4://225.131.75.231:56363")
237 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT);
238 faceStatus2.setFaceId(31066)
239 .setLocalUri("udp4://25.90.26.32:56363")
240 .setRemoteUri("udp4://225.131.75.231:56363")
241 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT);
242 this->sendDataset(interest.getName(), faceStatus1, faceStatus2);
243 };
244
245 this->execute("face destroy udp4://225.131.75.231:56363");
246 BOOST_CHECK_EQUAL(exitCode, 5);
247 BOOST_CHECK(out.is_empty());
248 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
249 "Re-run the command with a FaceId: "
250 "6720 (local=udp4://202.83.168.28:56363), "
251 "31066 (local=udp4://25.90.26.32:56363)\n"));
252}
253
254BOOST_AUTO_TEST_CASE(ErrorCanonization)
255{
256 this->execute("face destroy udp6://32.38.164.64:10445");
257 BOOST_CHECK_EQUAL(exitCode, 4);
258 BOOST_CHECK(out.is_empty());
259 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
260 "No endpoints match the specified address selector\n"));
261}
262
263BOOST_AUTO_TEST_CASE(ErrorDataset)
264{
265 this->processInterest = nullptr; // no response to dataset or command
266
267 this->execute("face destroy udp://159.242.33.78");
268 BOOST_CHECK_EQUAL(exitCode, 1);
269 BOOST_CHECK(out.is_empty());
270 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
271}
272
273BOOST_AUTO_TEST_CASE(ErrorCommand)
274{
275 this->processInterest = [this] (const Interest& interest) {
276 if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
277 FaceStatus faceStatus;
278 faceStatus.setFaceId(17757)
279 .setLocalUri("tcp4://27.65.24.30:19187")
280 .setRemoteUri("tcp4://70.47.27.77:6363")
281 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
282 this->sendDataset(interest.getName(), faceStatus);
283 return;
284 }
285
286 MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy");
287 // no response to command
288 };
289
290 this->execute("face destroy 17757");
291 BOOST_CHECK_EQUAL(exitCode, 1);
292 BOOST_CHECK(out.is_empty());
293 BOOST_CHECK(err.is_equal("Error 10060 when destroying face: request timed out\n"));
294}
295
296BOOST_AUTO_TEST_SUITE_END() // DestroyCommand
297
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000298const std::string STATUS_XML = stripXmlSpaces(R"XML(
299 <faces>
300 <face>
301 <faceId>134</faceId>
302 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
303 <localUri>udp4://192.0.2.1:6363</localUri>
304 <faceScope>non-local</faceScope>
305 <facePersistency>permanent</facePersistency>
306 <linkType>multi-access</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000307 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000308 <packetCounters>
309 <incomingPackets>
310 <nInterests>22562</nInterests>
311 <nDatas>22031</nDatas>
312 <nNacks>63</nNacks>
313 </incomingPackets>
314 <outgoingPackets>
315 <nInterests>30121</nInterests>
316 <nDatas>20940</nDatas>
317 <nNacks>1218</nNacks>
318 </outgoingPackets>
319 </packetCounters>
320 <byteCounters>
321 <incomingBytes>2522915</incomingBytes>
322 <outgoingBytes>1353592</outgoingBytes>
323 </byteCounters>
324 </face>
325 <face>
326 <faceId>745</faceId>
327 <remoteUri>fd://75</remoteUri>
328 <localUri>unix:///var/run/nfd.sock</localUri>
329 <faceScope>local</faceScope>
330 <facePersistency>on-demand</facePersistency>
331 <linkType>point-to-point</linkType>
Eric Newberry6d932e82016-11-24 05:05:43 +0000332 <flags>
333 <localFieldsEnabled/>
334 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000335 <packetCounters>
336 <incomingPackets>
337 <nInterests>18998</nInterests>
338 <nDatas>26701</nDatas>
339 <nNacks>147</nNacks>
340 </incomingPackets>
341 <outgoingPackets>
342 <nInterests>34779</nInterests>
343 <nDatas>17028</nDatas>
344 <nNacks>1176</nNacks>
345 </outgoingPackets>
346 </packetCounters>
347 <byteCounters>
348 <incomingBytes>4672308</incomingBytes>
349 <outgoingBytes>8957187</outgoingBytes>
350 </byteCounters>
351 </face>
352 </faces>
353)XML");
354
355const std::string STATUS_TEXT =
356 "Faces:\n"
357 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
358 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000359 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000360 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
361 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000362 " flags={local on-demand point-to-point local-fields}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000363
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000364BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000365{
366 this->fetchStatus();
367 FaceStatus payload1;
368 payload1.setFaceId(134)
369 .setRemoteUri("udp4://233.252.0.4:6363")
370 .setLocalUri("udp4://192.0.2.1:6363")
371 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
372 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
373 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
374 .setNInInterests(22562)
375 .setNInDatas(22031)
376 .setNInNacks(63)
377 .setNOutInterests(30121)
378 .setNOutDatas(20940)
379 .setNOutNacks(1218)
380 .setNInBytes(2522915)
381 .setNOutBytes(1353592);
382 FaceStatus payload2;
383 payload2.setFaceId(745)
384 .setRemoteUri("fd://75")
385 .setLocalUri("unix:///var/run/nfd.sock")
386 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
387 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
388 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberry6d932e82016-11-24 05:05:43 +0000389 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000390 .setNInInterests(18998)
391 .setNInDatas(26701)
392 .setNInNacks(147)
393 .setNOutInterests(34779)
394 .setNOutDatas(17028)
395 .setNOutNacks(1176)
396 .setNInBytes(4672308)
397 .setNOutBytes(8957187);
398 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
399 this->prepareStatusOutput();
400
401 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
402 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
403}
404
405BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000406BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000407
408} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000409} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000410} // namespace tools
411} // namespace nfd