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