blob: 22de10034bfad30cf60928cb5eb5f05159357e19 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry84d3adc2017-08-09 23:31:40 -04002/*
Eric Newberryde332452018-01-30 11:45:32 -07003 * Copyright (c) 2014-2018, 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"
Eric Newberryde332452018-01-30 11:45:32 -070045 " congestion={base-marking-interval=12345ms default-threshold=54321B}"
Junxiao Shi36e54292017-02-17 18:43:16 +000046 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
47 " flags={non-local permanent multi-access}\n"
48 "faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
Eric Newberryde332452018-01-30 11:45:32 -070049 " congestion={base-marking-interval=100ms default-threshold=65536B}"
Junxiao Shi36e54292017-02-17 18:43:16 +000050 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Eric Newberryde332452018-01-30 11:45:32 -070051 " flags={local on-demand point-to-point local-fields lp-reliability congestion-marking}\n";
Junxiao Shi36e54292017-02-17 18:43:16 +000052
53BOOST_AUTO_TEST_CASE(NormalNonQuery)
54{
55 this->processInterest = [this] (const Interest& interest) {
56 FaceStatus payload1;
57 payload1.setFaceId(134)
58 .setRemoteUri("udp4://233.252.0.4:6363")
59 .setLocalUri("udp4://192.0.2.1:6363")
60 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
61 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
62 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
Eric Newberryde332452018-01-30 11:45:32 -070063 .setBaseCongestionMarkingInterval(12345_ms)
64 .setDefaultCongestionThreshold(54321)
Junxiao Shi36e54292017-02-17 18:43:16 +000065 .setNInInterests(22562)
Junxiao Shif03d4792017-04-06 16:41:22 +000066 .setNInData(22031)
Junxiao Shi36e54292017-02-17 18:43:16 +000067 .setNInNacks(63)
68 .setNOutInterests(30121)
Junxiao Shif03d4792017-04-06 16:41:22 +000069 .setNOutData(20940)
Junxiao Shi36e54292017-02-17 18:43:16 +000070 .setNOutNacks(1218)
71 .setNInBytes(2522915)
72 .setNOutBytes(1353592);
73 FaceStatus payload2;
74 payload2.setFaceId(745)
75 .setRemoteUri("fd://75")
76 .setLocalUri("unix:///var/run/nfd.sock")
77 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
78 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
79 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -070080 .setBaseCongestionMarkingInterval(100_ms)
81 .setDefaultCongestionThreshold(65536)
Junxiao Shi36e54292017-02-17 18:43:16 +000082 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Eric Newberry84d3adc2017-08-09 23:31:40 -040083 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true)
Eric Newberryde332452018-01-30 11:45:32 -070084 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true)
Junxiao Shi36e54292017-02-17 18:43:16 +000085 .setNInInterests(18998)
Junxiao Shif03d4792017-04-06 16:41:22 +000086 .setNInData(26701)
Junxiao Shi36e54292017-02-17 18:43:16 +000087 .setNInNacks(147)
88 .setNOutInterests(34779)
Junxiao Shif03d4792017-04-06 16:41:22 +000089 .setNOutData(17028)
Junxiao Shi36e54292017-02-17 18:43:16 +000090 .setNOutNacks(1176)
91 .setNInBytes(4672308)
92 .setNOutBytes(8957187);
93 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
94 };
95
96 this->execute("face list");
97 BOOST_CHECK_EQUAL(exitCode, 0);
98 BOOST_CHECK(out.is_equal(NONQUERY_OUTPUT));
99 BOOST_CHECK(err.is_empty());
100}
101
102const std::string QUERY_OUTPUT =
103 "faceid=177 remote=tcp4://53.239.9.114:6363 local=tcp4://164.0.31.106:20396"
Eric Newberryde332452018-01-30 11:45:32 -0700104 " congestion={base-marking-interval=555ms default-threshold=10000B}"
Junxiao Shi36e54292017-02-17 18:43:16 +0000105 " counters={in={2325i 1110d 79n 4716834B} out={2278i 485d 841n 308108B}}"
106 " flags={non-local persistent point-to-point}\n";
107
108BOOST_AUTO_TEST_CASE(NormalQuery)
109{
110 this->processInterest = [this] (const Interest& interest) {
111 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
112 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
113 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
114 FaceQueryFilter expectedFilter;
115 expectedFilter.setRemoteUri("tcp4://53.239.9.114:6363")
116 .setLocalUri("tcp4://164.0.31.106:20396")
117 .setUriScheme("tcp4");
118 BOOST_CHECK_EQUAL(filter, expectedFilter);
119
120 FaceStatus payload;
121 payload.setFaceId(177)
122 .setRemoteUri("tcp4://53.239.9.114:6363")
123 .setLocalUri("tcp4://164.0.31.106:20396")
124 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
125 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
126 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -0700127 .setBaseCongestionMarkingInterval(555_ms)
128 .setDefaultCongestionThreshold(10000)
Junxiao Shi36e54292017-02-17 18:43:16 +0000129 .setNInInterests(2325)
Junxiao Shif03d4792017-04-06 16:41:22 +0000130 .setNInData(1110)
Junxiao Shi36e54292017-02-17 18:43:16 +0000131 .setNInNacks(79)
132 .setNOutInterests(2278)
Junxiao Shif03d4792017-04-06 16:41:22 +0000133 .setNOutData(485)
Junxiao Shi36e54292017-02-17 18:43:16 +0000134 .setNOutNacks(841)
135 .setNInBytes(4716834)
136 .setNOutBytes(308108);
137 this->sendDataset(interest.getName(), payload);
138 };
139
140 this->execute("face list tcp://53.239.9.114 scheme tcp4 local tcp://164.0.31.106:20396");
141 BOOST_CHECK_EQUAL(exitCode, 0);
142 BOOST_CHECK(out.is_equal(QUERY_OUTPUT));
143 BOOST_CHECK(err.is_empty());
144}
145
146BOOST_AUTO_TEST_CASE(NotFound)
147{
148 this->processInterest = [this] (const Interest& interest) {
149 this->sendEmptyDataset(interest.getName());
150 };
151
152 this->execute("face list scheme udp6");
153 BOOST_CHECK_EQUAL(exitCode, 3);
154 BOOST_CHECK(out.is_empty());
155 BOOST_CHECK(err.is_equal("Face not found\n"));
156}
157
158BOOST_AUTO_TEST_CASE(Error)
159{
160 this->processInterest = nullptr; // no response
161
162 this->execute("face list local udp4://31.67.17.2:6363");
163 BOOST_CHECK_EQUAL(exitCode, 1);
164 BOOST_CHECK(out.is_empty());
165 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
166}
167
168BOOST_AUTO_TEST_SUITE_END() // ListCommand
169
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000170BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
171
Eric Newberryde332452018-01-30 11:45:32 -0700172const std::string NORMAL_ALL_CONGESTION_OUTPUT = std::string(R"TEXT(
173 faceid=256
174 remote=udp4://84.67.35.111:6363
175 local=udp4://79.91.49.215:6363
176congestion={base-marking-interval=123ms default-threshold=10000B}
177 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
178 flags={non-local on-demand point-to-point}
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000179)TEXT").substr(1);
180
Eric Newberryde332452018-01-30 11:45:32 -0700181BOOST_AUTO_TEST_CASE(NormalAllCongestionParams)
182{
183 this->processInterest = [this] (const Interest& interest) {
184 BOOST_CHECK(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().setFaceId(256));
188
189 FaceStatus payload;
190 payload.setFaceId(256)
191 .setRemoteUri("udp4://84.67.35.111:6363")
192 .setLocalUri("udp4://79.91.49.215:6363")
193 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
194 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
195 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
196 .setBaseCongestionMarkingInterval(123_ms)
197 .setDefaultCongestionThreshold(10000)
198 .setNInInterests(28975)
199 .setNInData(28232)
200 .setNInNacks(212)
201 .setNOutInterests(19525)
202 .setNOutData(30993)
203 .setNOutNacks(1038)
204 .setNInBytes(13307258)
205 .setNOutBytes(6231946);
206
207 this->sendDataset(interest.getName(), payload);
208 };
209
210 this->execute("face show 256");
211 BOOST_CHECK_EQUAL(exitCode, 0);
212 BOOST_CHECK(out.is_equal(NORMAL_ALL_CONGESTION_OUTPUT));
213 BOOST_CHECK(err.is_empty());
214}
215
216const std::string NORMAL_INTERVAL_CONGESTION_OUTPUT = std::string(R"TEXT(
217 faceid=256
218 remote=udp4://84.67.35.111:6363
219 local=udp4://79.91.49.215:6363
220congestion={base-marking-interval=123ms}
221 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
222 flags={non-local on-demand point-to-point}
223)TEXT").substr(1);
224
225BOOST_AUTO_TEST_CASE(NormalIntervalCongestionParams)
226{
227 this->processInterest = [this] (const Interest& interest) {
228 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
229 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
230 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
231 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
232
233 FaceStatus payload;
234 payload.setFaceId(256)
235 .setRemoteUri("udp4://84.67.35.111:6363")
236 .setLocalUri("udp4://79.91.49.215:6363")
237 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
238 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
239 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
240 .setBaseCongestionMarkingInterval(123_ms)
241 .setNInInterests(28975)
242 .setNInData(28232)
243 .setNInNacks(212)
244 .setNOutInterests(19525)
245 .setNOutData(30993)
246 .setNOutNacks(1038)
247 .setNInBytes(13307258)
248 .setNOutBytes(6231946);
249
250 this->sendDataset(interest.getName(), payload);
251 };
252
253 this->execute("face show 256");
254 BOOST_CHECK_EQUAL(exitCode, 0);
255 BOOST_CHECK(out.is_equal(NORMAL_INTERVAL_CONGESTION_OUTPUT));
256 BOOST_CHECK(err.is_empty());
257}
258
259const std::string NORMAL_THRESHOLD_CONGESTION_OUTPUT = std::string(R"TEXT(
260 faceid=256
261 remote=udp4://84.67.35.111:6363
262 local=udp4://79.91.49.215:6363
263congestion={default-threshold=10000B}
264 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
265 flags={non-local on-demand point-to-point}
266)TEXT").substr(1);
267
268BOOST_AUTO_TEST_CASE(NormalThresholdCongestionParams)
269{
270 this->processInterest = [this] (const Interest& interest) {
271 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
272 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
273 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
274 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
275
276 FaceStatus payload;
277 payload.setFaceId(256)
278 .setRemoteUri("udp4://84.67.35.111:6363")
279 .setLocalUri("udp4://79.91.49.215:6363")
280 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
281 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
282 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
283 .setDefaultCongestionThreshold(10000)
284 .setNInInterests(28975)
285 .setNInData(28232)
286 .setNInNacks(212)
287 .setNOutInterests(19525)
288 .setNOutData(30993)
289 .setNOutNacks(1038)
290 .setNInBytes(13307258)
291 .setNOutBytes(6231946);
292
293 this->sendDataset(interest.getName(), payload);
294 };
295
296 this->execute("face show 256");
297 BOOST_CHECK_EQUAL(exitCode, 0);
298 BOOST_CHECK(out.is_equal(NORMAL_THRESHOLD_CONGESTION_OUTPUT));
299 BOOST_CHECK(err.is_empty());
300}
301
302const std::string NORMAL_NO_CONGESTION_OUTPUT = std::string(R"TEXT(
303 faceid=256
304 remote=udp4://84.67.35.111:6363
305 local=udp4://79.91.49.215:6363
306 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
307 flags={non-local on-demand point-to-point}
308)TEXT").substr(1);
309
310BOOST_AUTO_TEST_CASE(NormalNoCongestionParams)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000311{
312 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi36e54292017-02-17 18:43:16 +0000313 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
Junxiao Shi8f803f22017-02-10 03:04:28 +0000314 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
315 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
316 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000317
318 FaceStatus payload;
319 payload.setFaceId(256)
320 .setRemoteUri("udp4://84.67.35.111:6363")
321 .setLocalUri("udp4://79.91.49.215:6363")
322 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
323 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
324 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
325 .setNInInterests(28975)
Junxiao Shif03d4792017-04-06 16:41:22 +0000326 .setNInData(28232)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000327 .setNInNacks(212)
328 .setNOutInterests(19525)
Junxiao Shif03d4792017-04-06 16:41:22 +0000329 .setNOutData(30993)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000330 .setNOutNacks(1038)
331 .setNInBytes(13307258)
332 .setNOutBytes(6231946);
333
Junxiao Shi8f803f22017-02-10 03:04:28 +0000334 this->sendDataset(interest.getName(), payload);
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000335 };
336
337 this->execute("face show 256");
338 BOOST_CHECK_EQUAL(exitCode, 0);
Eric Newberryde332452018-01-30 11:45:32 -0700339 BOOST_CHECK(out.is_equal(NORMAL_NO_CONGESTION_OUTPUT));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000340 BOOST_CHECK(err.is_empty());
341}
342
343BOOST_AUTO_TEST_CASE(NotFound)
344{
345 this->processInterest = [this] (const Interest& interest) {
346 this->sendEmptyDataset(interest.getName());
347 };
348
349 this->execute("face show 256");
350 BOOST_CHECK_EQUAL(exitCode, 3);
351 BOOST_CHECK(out.is_empty());
Junxiao Shi8f803f22017-02-10 03:04:28 +0000352 BOOST_CHECK(err.is_equal("Face not found\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000353}
354
355BOOST_AUTO_TEST_CASE(Error)
356{
357 this->processInterest = nullptr; // no response
358
359 this->execute("face show 256");
360 BOOST_CHECK_EQUAL(exitCode, 1);
361 BOOST_CHECK(out.is_empty());
Junxiao Shi8f803f22017-02-10 03:04:28 +0000362 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000363}
364
365BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000366
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000367class ExecuteFaceCreateCommandFixture : public ExecuteCommandFixture
368{
369protected:
370 void
Eric Newberryde332452018-01-30 11:45:32 -0700371 respond409(const Interest& interest, FacePersistency persistency,
372 bool enableLpReliability = false,
373 bool enableCongestionMarking = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000374 {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000375 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000376 ControlParameters body;
377 body.setFaceId(1172)
378 .setUri("udp4://100.77.30.65:6363")
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000379 .setLocalUri("udp4://68.62.26.57:24087")
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000380 .setFacePersistency(persistency)
381 .setFlags(0);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400382 if (enableLpReliability) {
383 body.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false);
384 }
Eric Newberryde332452018-01-30 11:45:32 -0700385 if (enableCongestionMarking) {
386 body.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
387 }
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000388 this->failCommand(interest, 409, "conflict-409", body);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000389 }
390};
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000391
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000392BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteFaceCreateCommandFixture)
393
394BOOST_AUTO_TEST_CASE(Creating)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000395{
396 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000397 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000398 BOOST_REQUIRE(req.hasUri());
399 BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363");
Junxiao Shi0d976922017-04-01 14:35:21 +0000400 BOOST_CHECK(!req.hasLocalUri());
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000401 BOOST_REQUIRE(req.hasFacePersistency());
402 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
403
404 ControlParameters resp;
405 resp.setFaceId(2130)
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000406 .setUri("udp4://159.242.33.78:6363")
407 .setLocalUri("udp4://179.63.153.45:28835")
Junxiao Shi5c1bb362017-05-11 16:03:38 +0000408 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
409 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000410 this->succeedCommand(interest, resp);
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000411 };
412
413 this->execute("face create udp://159.242.33.78");
414 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000415 BOOST_CHECK(out.is_equal("face-created id=2130 local=udp4://179.63.153.45:28835 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400416 "remote=udp4://159.242.33.78:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700417 "reliability=off congestion-marking=off\n"));
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000418 BOOST_CHECK(err.is_empty());
419}
420
Eric Newberry84d3adc2017-08-09 23:31:40 -0400421BOOST_AUTO_TEST_CASE(CreatingWithParams)
Junxiao Shi0d976922017-04-01 14:35:21 +0000422{
423 this->processInterest = [this] (const Interest& interest) {
424 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
425 BOOST_REQUIRE(req.hasUri());
426 BOOST_CHECK_EQUAL(req.getUri(), "udp4://22.91.89.51:19903");
427 BOOST_REQUIRE(req.hasLocalUri());
428 BOOST_CHECK_EQUAL(req.getLocalUri(), "udp4://98.68.23.71:6363");
429 BOOST_REQUIRE(req.hasFacePersistency());
430 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERMANENT);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400431 BOOST_CHECK(req.hasFlags());
432 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Junxiao Shi0d976922017-04-01 14:35:21 +0000433
434 ControlParameters resp;
435 resp.setFaceId(301)
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000436 .setUri("udp4://22.91.89.51:19903")
437 .setLocalUri("udp4://98.68.23.71:6363")
Junxiao Shi5c1bb362017-05-11 16:03:38 +0000438 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT)
Eric Newberryde332452018-01-30 11:45:32 -0700439 .setBaseCongestionMarkingInterval(100_ms)
440 .setDefaultCongestionThreshold(65536)
441 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false)
442 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
Junxiao Shi0d976922017-04-01 14:35:21 +0000443 this->succeedCommand(interest, resp);
444 };
445
Eric Newberryde332452018-01-30 11:45:32 -0700446 this->execute("face create udp://22.91.89.51:19903 permanent local udp://98.68.23.71 reliability on "
447 "congestion-marking on congestion-marking-interval 100 "
448 "default-congestion-threshold 65536");
Junxiao Shi0d976922017-04-01 14:35:21 +0000449 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000450 BOOST_CHECK(out.is_equal("face-created id=301 local=udp4://98.68.23.71:6363 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400451 "remote=udp4://22.91.89.51:19903 persistency=permanent "
Eric Newberryde332452018-01-30 11:45:32 -0700452 "reliability=on congestion-marking=on "
453 "congestion-marking-interval=100ms default-congestion-threshold=65536B\n"));
Junxiao Shi0d976922017-04-01 14:35:21 +0000454 BOOST_CHECK(err.is_empty());
455}
456
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000457BOOST_AUTO_TEST_CASE(UpgradingPersistency)
458{
459 bool hasUpdateCommand = false;
460 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000461 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
462 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000463 return;
464 }
465
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000466 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000467 hasUpdateCommand = true;
468 BOOST_REQUIRE(req.hasFaceId());
469 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
470 BOOST_REQUIRE(req.hasFacePersistency());
471 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
472 BOOST_CHECK(!req.hasFlags());
473
474 ControlParameters resp;
475 resp.setFaceId(1172)
476 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
477 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000478 this->succeedCommand(interest, resp);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000479 };
480
481 this->execute("face create udp://100.77.30.65");
482 BOOST_CHECK(hasUpdateCommand);
483 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000484 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400485 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700486 "reliability=off congestion-marking=off\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000487 BOOST_CHECK(err.is_empty());
488}
489
490BOOST_AUTO_TEST_CASE(NotDowngradingPersistency)
491{
492 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000493 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERMANENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000494 // no command other than faces/create is expected
495 };
496
497 this->execute("face create udp://100.77.30.65");
498 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000499 BOOST_CHECK(out.is_equal("face-exists id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400500 "remote=udp4://100.77.30.65:6363 persistency=permanent "
Eric Newberryde332452018-01-30 11:45:32 -0700501 "reliability=off congestion-marking=off\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000502 BOOST_CHECK(err.is_empty());
503}
504
505BOOST_AUTO_TEST_CASE(SamePersistency)
506{
507 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000508 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000509 // no command other than faces/create is expected
510 };
511
512 this->execute("face create udp://100.77.30.65");
513 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000514 BOOST_CHECK(out.is_equal("face-exists id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400515 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700516 "reliability=off congestion-marking=off\n"));
Eric Newberry84d3adc2017-08-09 23:31:40 -0400517 BOOST_CHECK(err.is_empty());
518}
519
520BOOST_AUTO_TEST_CASE(EnablingReliability)
521{
522 bool hasUpdateCommand = false;
523 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
524 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
525 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
526 return;
527 }
528
529 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
530 hasUpdateCommand = true;
531 BOOST_REQUIRE(req.hasFaceId());
532 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
533 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
534 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
535
536 ControlParameters resp;
537 resp.setFaceId(1172)
538 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
539 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false);
540 this->succeedCommand(interest, resp);
541 };
542
543 this->execute("face create udp://100.77.30.65 reliability on");
544 BOOST_CHECK_EQUAL(exitCode, 0);
545 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
546 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700547 "reliability=on congestion-marking=off\n"));
Eric Newberry84d3adc2017-08-09 23:31:40 -0400548 BOOST_CHECK(err.is_empty());
549}
550
551BOOST_AUTO_TEST_CASE(DisablingReliability)
552{
553 bool hasUpdateCommand = false;
554 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
555 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
556 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT, true);
557 return;
558 }
559
560 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
561 hasUpdateCommand = true;
562 BOOST_REQUIRE(req.hasFaceId());
563 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
564 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
565 BOOST_CHECK(!req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
566
567 ControlParameters resp;
568 resp.setFaceId(1172)
569 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
570 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false, false);
571 this->succeedCommand(interest, resp);
572 };
573
574 this->execute("face create udp://100.77.30.65 reliability off");
575 BOOST_CHECK_EQUAL(exitCode, 0);
576 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
577 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700578 "reliability=off congestion-marking=off\n"));
579 BOOST_CHECK(err.is_empty());
580}
581
582BOOST_AUTO_TEST_CASE(EnablingCongestionMarking)
583{
584 bool hasUpdateCommand = false;
585 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
586 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
587 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
588 return;
589 }
590
591 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
592 hasUpdateCommand = true;
593 BOOST_REQUIRE(req.hasFaceId());
594 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
595 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
596 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
597 BOOST_CHECK(!req.hasBaseCongestionMarkingInterval());
598 BOOST_CHECK(!req.hasDefaultCongestionThreshold());
599
600 ControlParameters resp;
601 resp.setFaceId(1172)
602 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
603 .setBaseCongestionMarkingInterval(100_ms)
604 .setDefaultCongestionThreshold(65536)
605 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
606 this->succeedCommand(interest, resp);
607 };
608
609 this->execute("face create udp://100.77.30.65 congestion-marking on");
610 BOOST_CHECK_EQUAL(exitCode, 0);
611 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
612 "remote=udp4://100.77.30.65:6363 persistency=persistent "
613 "reliability=off congestion-marking=on "
614 "congestion-marking-interval=100ms default-congestion-threshold=65536B\n"));
615 BOOST_CHECK(err.is_empty());
616}
617
618BOOST_AUTO_TEST_CASE(DisablingCongestionMarking)
619{
620 bool hasUpdateCommand = false;
621 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
622 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
623 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT, false, true);
624 return;
625 }
626
627 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
628 hasUpdateCommand = true;
629 BOOST_REQUIRE(req.hasFaceId());
630 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
631 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
632 BOOST_CHECK(!req.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
633 BOOST_CHECK(!req.hasBaseCongestionMarkingInterval());
634 BOOST_CHECK(!req.hasDefaultCongestionThreshold());
635
636 ControlParameters resp;
637 resp.setFaceId(1172)
638 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
639 .setBaseCongestionMarkingInterval(100_ms)
640 .setDefaultCongestionThreshold(65536)
641 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false, false);
642 this->succeedCommand(interest, resp);
643 };
644
645 this->execute("face create udp://100.77.30.65 congestion-marking off");
646 BOOST_CHECK_EQUAL(exitCode, 0);
647 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
648 "remote=udp4://100.77.30.65:6363 persistency=persistent "
649 "reliability=off congestion-marking=off "
650 "congestion-marking-interval=100ms default-congestion-threshold=65536B\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000651 BOOST_CHECK(err.is_empty());
652}
653
Junxiao Shi0d976922017-04-01 14:35:21 +0000654BOOST_AUTO_TEST_CASE(ErrorCanonizeRemote)
655{
656 this->execute("face create invalid://");
657 BOOST_CHECK_EQUAL(exitCode, 4);
658 BOOST_CHECK(out.is_empty());
659 BOOST_CHECK(err.is_equal("Error when canonizing 'invalid://': scheme not supported\n"));
660}
661
662BOOST_AUTO_TEST_CASE(ErrorCanonizeLocal)
663{
664 this->execute("face create udp4://24.37.20.47:6363 local invalid://");
665 BOOST_CHECK_EQUAL(exitCode, 4);
666 BOOST_CHECK(out.is_empty());
667 BOOST_CHECK(err.is_equal("Error when canonizing 'invalid://': scheme not supported\n"));
668}
669
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000670BOOST_AUTO_TEST_CASE(ErrorCreate)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000671{
672 this->processInterest = nullptr; // no response
673
674 this->execute("face create udp://159.242.33.78");
675 BOOST_CHECK_EQUAL(exitCode, 1);
676 BOOST_CHECK(out.is_empty());
677 BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n"));
678}
679
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000680BOOST_AUTO_TEST_CASE(ErrorConflict)
681{
682 // Current NFD will not report a 409-conflict with a different remote FaceUri, but this is
683 // allowed by FaceMgmt protocol and nfdc should not attempt to upgrade persistency in this case.
684
685 this->processInterest = [this] (const Interest& interest) {
686 // conflict with udp4://100.77.30.65:6363
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000687 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000688 };
689
690 this->execute("face create udp://20.53.73.45");
691 BOOST_CHECK_EQUAL(exitCode, 1);
692 BOOST_CHECK(out.is_empty());
693 BOOST_CHECK(err.is_equal("Error 409 when creating face: conflict-409\n"));
694}
695
696BOOST_AUTO_TEST_CASE(ErrorUpdate)
697{
698 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000699 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
700 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000701 return;
702 }
703
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000704 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000705 // no response to faces/update
706 };
707
708 this->execute("face create udp://100.77.30.65");
709 BOOST_CHECK_EQUAL(exitCode, 1);
710 BOOST_CHECK(out.is_empty());
711 BOOST_CHECK(err.is_equal("Error 10060 when upgrading face persistency: request timed out\n"));
712}
713
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000714BOOST_AUTO_TEST_SUITE_END() // CreateCommand
715
Junxiao Shi05dd4442017-02-06 22:50:07 +0000716BOOST_FIXTURE_TEST_SUITE(DestroyCommand, ExecuteCommandFixture)
717
718BOOST_AUTO_TEST_CASE(NormalByFaceId)
719{
720 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000721 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000722 return;
723 }
724
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000725 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000726 BOOST_REQUIRE(req.hasFaceId());
727 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
728
729 ControlParameters resp;
730 resp.setFaceId(10156);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000731 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000732 };
733
734 this->execute("face destroy 10156");
735 BOOST_CHECK_EQUAL(exitCode, 0);
736 BOOST_CHECK(out.is_equal("face-destroyed id=10156 local=tcp4://151.26.163.27:22967 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400737 "remote=tcp4://198.57.27.40:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700738 "reliability=off congestion-marking=off\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000739 BOOST_CHECK(err.is_empty());
740}
741
742BOOST_AUTO_TEST_CASE(NormalByFaceUri)
743{
744 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000745 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000746 return;
747 }
748
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000749 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000750 BOOST_REQUIRE(req.hasFaceId());
751 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
752
753 ControlParameters resp;
754 resp.setFaceId(2249);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000755 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000756 };
757
758 this->execute("face destroy tcp://32.121.182.82");
759 BOOST_CHECK_EQUAL(exitCode, 0);
760 BOOST_CHECK(out.is_equal("face-destroyed id=2249 local=tcp4://30.99.87.98:31414 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400761 "remote=tcp4://32.121.182.82:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700762 "reliability=off congestion-marking=off\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000763 BOOST_CHECK(err.is_empty());
764}
765
766BOOST_AUTO_TEST_CASE(FaceNotExist)
767{
768 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000769 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000770 };
771
772 this->execute("face destroy 23728");
773 BOOST_CHECK_EQUAL(exitCode, 3);
774 BOOST_CHECK(out.is_empty());
775 BOOST_CHECK(err.is_equal("Face not found\n"));
776}
777
778BOOST_AUTO_TEST_CASE(Ambiguous)
779{
780 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000781 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000782 };
783
784 this->execute("face destroy udp4://225.131.75.231:56363");
785 BOOST_CHECK_EQUAL(exitCode, 5);
786 BOOST_CHECK(out.is_empty());
787 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
788 "Re-run the command with a FaceId: "
789 "6720 (local=udp4://202.83.168.28:56363), "
790 "31066 (local=udp4://25.90.26.32:56363)\n"));
791}
792
793BOOST_AUTO_TEST_CASE(ErrorCanonization)
794{
795 this->execute("face destroy udp6://32.38.164.64:10445");
796 BOOST_CHECK_EQUAL(exitCode, 4);
797 BOOST_CHECK(out.is_empty());
798 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
Eric Newberry7d8695d2017-05-29 15:49:10 -0700799 "IPv4/v6 mismatch\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000800}
801
802BOOST_AUTO_TEST_CASE(ErrorDataset)
803{
804 this->processInterest = nullptr; // no response to dataset or command
805
806 this->execute("face destroy udp://159.242.33.78");
807 BOOST_CHECK_EQUAL(exitCode, 1);
808 BOOST_CHECK(out.is_empty());
809 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n"));
810}
811
812BOOST_AUTO_TEST_CASE(ErrorCommand)
813{
814 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000815 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000816 return;
817 }
818
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000819 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000820 // no response to command
821 };
822
Junxiao Shi918e5d42017-02-25 03:58:21 +0000823 this->execute("face destroy 10156");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000824 BOOST_CHECK_EQUAL(exitCode, 1);
825 BOOST_CHECK(out.is_empty());
826 BOOST_CHECK(err.is_equal("Error 10060 when destroying face: request timed out\n"));
827}
828
829BOOST_AUTO_TEST_SUITE_END() // DestroyCommand
830
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000831const std::string STATUS_XML = stripXmlSpaces(R"XML(
832 <faces>
833 <face>
834 <faceId>134</faceId>
835 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
836 <localUri>udp4://192.0.2.1:6363</localUri>
837 <faceScope>non-local</faceScope>
838 <facePersistency>permanent</facePersistency>
839 <linkType>multi-access</linkType>
Eric Newberryde332452018-01-30 11:45:32 -0700840 <congestion/>
Eric Newberry6d932e82016-11-24 05:05:43 +0000841 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000842 <packetCounters>
843 <incomingPackets>
844 <nInterests>22562</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000845 <nData>22031</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000846 <nNacks>63</nNacks>
847 </incomingPackets>
848 <outgoingPackets>
849 <nInterests>30121</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000850 <nData>20940</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000851 <nNacks>1218</nNacks>
852 </outgoingPackets>
853 </packetCounters>
854 <byteCounters>
855 <incomingBytes>2522915</incomingBytes>
856 <outgoingBytes>1353592</outgoingBytes>
857 </byteCounters>
858 </face>
859 <face>
860 <faceId>745</faceId>
861 <remoteUri>fd://75</remoteUri>
862 <localUri>unix:///var/run/nfd.sock</localUri>
863 <faceScope>local</faceScope>
864 <facePersistency>on-demand</facePersistency>
865 <linkType>point-to-point</linkType>
Eric Newberryde332452018-01-30 11:45:32 -0700866 <congestion>
867 <baseMarkingInterval>PT0.100S</baseMarkingInterval>
868 <defaultThreshold>65536</defaultThreshold>
869 </congestion>
Eric Newberry6d932e82016-11-24 05:05:43 +0000870 <flags>
871 <localFieldsEnabled/>
Eric Newberry84d3adc2017-08-09 23:31:40 -0400872 <lpReliabilityEnabled/>
Eric Newberryde332452018-01-30 11:45:32 -0700873 <congestionMarkingEnabled/>
Eric Newberry6d932e82016-11-24 05:05:43 +0000874 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000875 <packetCounters>
876 <incomingPackets>
877 <nInterests>18998</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000878 <nData>26701</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000879 <nNacks>147</nNacks>
880 </incomingPackets>
881 <outgoingPackets>
882 <nInterests>34779</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000883 <nData>17028</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000884 <nNacks>1176</nNacks>
885 </outgoingPackets>
886 </packetCounters>
887 <byteCounters>
888 <incomingBytes>4672308</incomingBytes>
889 <outgoingBytes>8957187</outgoingBytes>
890 </byteCounters>
891 </face>
892 </faces>
893)XML");
894
895const std::string STATUS_TEXT =
896 "Faces:\n"
897 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
898 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000899 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000900 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
Eric Newberryde332452018-01-30 11:45:32 -0700901 " congestion={base-marking-interval=100ms default-threshold=65536B}"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000902 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Eric Newberryde332452018-01-30 11:45:32 -0700903 " flags={local on-demand point-to-point local-fields lp-reliability congestion-marking}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000904
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000905BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000906{
907 this->fetchStatus();
908 FaceStatus payload1;
909 payload1.setFaceId(134)
910 .setRemoteUri("udp4://233.252.0.4:6363")
911 .setLocalUri("udp4://192.0.2.1:6363")
912 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
913 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
914 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
915 .setNInInterests(22562)
Junxiao Shif03d4792017-04-06 16:41:22 +0000916 .setNInData(22031)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000917 .setNInNacks(63)
918 .setNOutInterests(30121)
Junxiao Shif03d4792017-04-06 16:41:22 +0000919 .setNOutData(20940)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000920 .setNOutNacks(1218)
921 .setNInBytes(2522915)
922 .setNOutBytes(1353592);
923 FaceStatus payload2;
924 payload2.setFaceId(745)
925 .setRemoteUri("fd://75")
926 .setLocalUri("unix:///var/run/nfd.sock")
927 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
928 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
929 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -0700930 .setBaseCongestionMarkingInterval(100_ms)
931 .setDefaultCongestionThreshold(65536)
Eric Newberry6d932e82016-11-24 05:05:43 +0000932 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Eric Newberry84d3adc2017-08-09 23:31:40 -0400933 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true)
Eric Newberryde332452018-01-30 11:45:32 -0700934 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000935 .setNInInterests(18998)
Junxiao Shif03d4792017-04-06 16:41:22 +0000936 .setNInData(26701)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000937 .setNInNacks(147)
938 .setNOutInterests(34779)
Junxiao Shif03d4792017-04-06 16:41:22 +0000939 .setNOutData(17028)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000940 .setNOutNacks(1176)
941 .setNInBytes(4672308)
942 .setNOutBytes(8957187);
943 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
944 this->prepareStatusOutput();
945
946 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
947 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
948}
949
950BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000951BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000952
953} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000954} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000955} // namespace tools
956} // namespace nfd