blob: 994c0b257bbf84481bc93f76857e0130e00b6df3 [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 Newberry4f8dd962018-06-17 21:32:07 -070045 " congestion={base-marking-interval=12345ms default-threshold=54321B} mtu=1024"
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 Newberry4f8dd962018-06-17 21:32:07 -070049 " congestion={base-marking-interval=100ms default-threshold=65536B} mtu=8800"
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)
Eric Newberry4f8dd962018-06-17 21:32:07 -070065 .setMtu(1024)
Junxiao Shi36e54292017-02-17 18:43:16 +000066 .setNInInterests(22562)
Junxiao Shif03d4792017-04-06 16:41:22 +000067 .setNInData(22031)
Junxiao Shi36e54292017-02-17 18:43:16 +000068 .setNInNacks(63)
69 .setNOutInterests(30121)
Junxiao Shif03d4792017-04-06 16:41:22 +000070 .setNOutData(20940)
Junxiao Shi36e54292017-02-17 18:43:16 +000071 .setNOutNacks(1218)
72 .setNInBytes(2522915)
73 .setNOutBytes(1353592);
74 FaceStatus payload2;
75 payload2.setFaceId(745)
76 .setRemoteUri("fd://75")
77 .setLocalUri("unix:///var/run/nfd.sock")
78 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
79 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
80 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -070081 .setBaseCongestionMarkingInterval(100_ms)
82 .setDefaultCongestionThreshold(65536)
Eric Newberry4f8dd962018-06-17 21:32:07 -070083 .setMtu(8800)
Junxiao Shi36e54292017-02-17 18:43:16 +000084 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Eric Newberry84d3adc2017-08-09 23:31:40 -040085 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true)
Eric Newberryde332452018-01-30 11:45:32 -070086 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true)
Junxiao Shi36e54292017-02-17 18:43:16 +000087 .setNInInterests(18998)
Junxiao Shif03d4792017-04-06 16:41:22 +000088 .setNInData(26701)
Junxiao Shi36e54292017-02-17 18:43:16 +000089 .setNInNacks(147)
90 .setNOutInterests(34779)
Junxiao Shif03d4792017-04-06 16:41:22 +000091 .setNOutData(17028)
Junxiao Shi36e54292017-02-17 18:43:16 +000092 .setNOutNacks(1176)
93 .setNInBytes(4672308)
94 .setNOutBytes(8957187);
95 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
96 };
97
98 this->execute("face list");
99 BOOST_CHECK_EQUAL(exitCode, 0);
100 BOOST_CHECK(out.is_equal(NONQUERY_OUTPUT));
101 BOOST_CHECK(err.is_empty());
102}
103
104const std::string QUERY_OUTPUT =
105 "faceid=177 remote=tcp4://53.239.9.114:6363 local=tcp4://164.0.31.106:20396"
Eric Newberry4f8dd962018-06-17 21:32:07 -0700106 " congestion={base-marking-interval=555ms default-threshold=10000B} mtu=2000"
Junxiao Shi36e54292017-02-17 18:43:16 +0000107 " counters={in={2325i 1110d 79n 4716834B} out={2278i 485d 841n 308108B}}"
108 " flags={non-local persistent point-to-point}\n";
109
110BOOST_AUTO_TEST_CASE(NormalQuery)
111{
112 this->processInterest = [this] (const Interest& interest) {
113 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
114 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
115 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
116 FaceQueryFilter expectedFilter;
117 expectedFilter.setRemoteUri("tcp4://53.239.9.114:6363")
118 .setLocalUri("tcp4://164.0.31.106:20396")
119 .setUriScheme("tcp4");
120 BOOST_CHECK_EQUAL(filter, expectedFilter);
121
122 FaceStatus payload;
123 payload.setFaceId(177)
124 .setRemoteUri("tcp4://53.239.9.114:6363")
125 .setLocalUri("tcp4://164.0.31.106:20396")
126 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
127 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
128 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -0700129 .setBaseCongestionMarkingInterval(555_ms)
130 .setDefaultCongestionThreshold(10000)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700131 .setMtu(2000)
Junxiao Shi36e54292017-02-17 18:43:16 +0000132 .setNInInterests(2325)
Junxiao Shif03d4792017-04-06 16:41:22 +0000133 .setNInData(1110)
Junxiao Shi36e54292017-02-17 18:43:16 +0000134 .setNInNacks(79)
135 .setNOutInterests(2278)
Junxiao Shif03d4792017-04-06 16:41:22 +0000136 .setNOutData(485)
Junxiao Shi36e54292017-02-17 18:43:16 +0000137 .setNOutNacks(841)
138 .setNInBytes(4716834)
139 .setNOutBytes(308108);
140 this->sendDataset(interest.getName(), payload);
141 };
142
143 this->execute("face list tcp://53.239.9.114 scheme tcp4 local tcp://164.0.31.106:20396");
144 BOOST_CHECK_EQUAL(exitCode, 0);
145 BOOST_CHECK(out.is_equal(QUERY_OUTPUT));
146 BOOST_CHECK(err.is_empty());
147}
148
149BOOST_AUTO_TEST_CASE(NotFound)
150{
151 this->processInterest = [this] (const Interest& interest) {
152 this->sendEmptyDataset(interest.getName());
153 };
154
155 this->execute("face list scheme udp6");
156 BOOST_CHECK_EQUAL(exitCode, 3);
157 BOOST_CHECK(out.is_empty());
158 BOOST_CHECK(err.is_equal("Face not found\n"));
159}
160
161BOOST_AUTO_TEST_CASE(Error)
162{
163 this->processInterest = nullptr; // no response
164
165 this->execute("face list local udp4://31.67.17.2:6363");
166 BOOST_CHECK_EQUAL(exitCode, 1);
167 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700168 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi36e54292017-02-17 18:43:16 +0000169}
170
171BOOST_AUTO_TEST_SUITE_END() // ListCommand
172
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000173BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture)
174
Eric Newberryde332452018-01-30 11:45:32 -0700175const std::string NORMAL_ALL_CONGESTION_OUTPUT = std::string(R"TEXT(
176 faceid=256
177 remote=udp4://84.67.35.111:6363
178 local=udp4://79.91.49.215:6363
179congestion={base-marking-interval=123ms default-threshold=10000B}
Eric Newberry4f8dd962018-06-17 21:32:07 -0700180 mtu=4000
Eric Newberryde332452018-01-30 11:45:32 -0700181 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
182 flags={non-local on-demand point-to-point}
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000183)TEXT").substr(1);
184
Eric Newberryde332452018-01-30 11:45:32 -0700185BOOST_AUTO_TEST_CASE(NormalAllCongestionParams)
186{
187 this->processInterest = [this] (const Interest& interest) {
188 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
189 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
190 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
191 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
192
193 FaceStatus payload;
194 payload.setFaceId(256)
195 .setRemoteUri("udp4://84.67.35.111:6363")
196 .setLocalUri("udp4://79.91.49.215:6363")
197 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
198 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700199 .setMtu(4000)
Eric Newberryde332452018-01-30 11:45:32 -0700200 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
201 .setBaseCongestionMarkingInterval(123_ms)
202 .setDefaultCongestionThreshold(10000)
203 .setNInInterests(28975)
204 .setNInData(28232)
205 .setNInNacks(212)
206 .setNOutInterests(19525)
207 .setNOutData(30993)
208 .setNOutNacks(1038)
209 .setNInBytes(13307258)
210 .setNOutBytes(6231946);
211
212 this->sendDataset(interest.getName(), payload);
213 };
214
215 this->execute("face show 256");
216 BOOST_CHECK_EQUAL(exitCode, 0);
217 BOOST_CHECK(out.is_equal(NORMAL_ALL_CONGESTION_OUTPUT));
218 BOOST_CHECK(err.is_empty());
219}
220
221const std::string NORMAL_INTERVAL_CONGESTION_OUTPUT = std::string(R"TEXT(
222 faceid=256
223 remote=udp4://84.67.35.111:6363
224 local=udp4://79.91.49.215:6363
225congestion={base-marking-interval=123ms}
Eric Newberry4f8dd962018-06-17 21:32:07 -0700226 mtu=3000
Eric Newberryde332452018-01-30 11:45:32 -0700227 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
228 flags={non-local on-demand point-to-point}
229)TEXT").substr(1);
230
231BOOST_AUTO_TEST_CASE(NormalIntervalCongestionParams)
232{
233 this->processInterest = [this] (const Interest& interest) {
234 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
235 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
236 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
237 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
238
239 FaceStatus payload;
240 payload.setFaceId(256)
241 .setRemoteUri("udp4://84.67.35.111:6363")
242 .setLocalUri("udp4://79.91.49.215:6363")
243 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
244 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
245 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
246 .setBaseCongestionMarkingInterval(123_ms)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700247 .setMtu(3000)
Eric Newberryde332452018-01-30 11:45:32 -0700248 .setNInInterests(28975)
249 .setNInData(28232)
250 .setNInNacks(212)
251 .setNOutInterests(19525)
252 .setNOutData(30993)
253 .setNOutNacks(1038)
254 .setNInBytes(13307258)
255 .setNOutBytes(6231946);
256
257 this->sendDataset(interest.getName(), payload);
258 };
259
260 this->execute("face show 256");
261 BOOST_CHECK_EQUAL(exitCode, 0);
262 BOOST_CHECK(out.is_equal(NORMAL_INTERVAL_CONGESTION_OUTPUT));
263 BOOST_CHECK(err.is_empty());
264}
265
266const std::string NORMAL_THRESHOLD_CONGESTION_OUTPUT = std::string(R"TEXT(
267 faceid=256
268 remote=udp4://84.67.35.111:6363
269 local=udp4://79.91.49.215:6363
270congestion={default-threshold=10000B}
Eric Newberry4f8dd962018-06-17 21:32:07 -0700271 mtu=5000
Eric Newberryde332452018-01-30 11:45:32 -0700272 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
273 flags={non-local on-demand point-to-point}
274)TEXT").substr(1);
275
276BOOST_AUTO_TEST_CASE(NormalThresholdCongestionParams)
277{
278 this->processInterest = [this] (const Interest& interest) {
279 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
280 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
281 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
282 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
283
284 FaceStatus payload;
285 payload.setFaceId(256)
286 .setRemoteUri("udp4://84.67.35.111:6363")
287 .setLocalUri("udp4://79.91.49.215:6363")
288 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
289 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700290 .setMtu(5000)
Eric Newberryde332452018-01-30 11:45:32 -0700291 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
292 .setDefaultCongestionThreshold(10000)
293 .setNInInterests(28975)
294 .setNInData(28232)
295 .setNInNacks(212)
296 .setNOutInterests(19525)
297 .setNOutData(30993)
298 .setNOutNacks(1038)
299 .setNInBytes(13307258)
300 .setNOutBytes(6231946);
301
302 this->sendDataset(interest.getName(), payload);
303 };
304
305 this->execute("face show 256");
306 BOOST_CHECK_EQUAL(exitCode, 0);
307 BOOST_CHECK(out.is_equal(NORMAL_THRESHOLD_CONGESTION_OUTPUT));
308 BOOST_CHECK(err.is_empty());
309}
310
311const std::string NORMAL_NO_CONGESTION_OUTPUT = std::string(R"TEXT(
312 faceid=256
313 remote=udp4://84.67.35.111:6363
314 local=udp4://79.91.49.215:6363
Eric Newberry4f8dd962018-06-17 21:32:07 -0700315 mtu=6000
Eric Newberryde332452018-01-30 11:45:32 -0700316 counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}}
317 flags={non-local on-demand point-to-point}
318)TEXT").substr(1);
319
320BOOST_AUTO_TEST_CASE(NormalNoCongestionParams)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000321{
322 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi36e54292017-02-17 18:43:16 +0000323 BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName()));
Junxiao Shi8f803f22017-02-10 03:04:28 +0000324 BOOST_CHECK_EQUAL(interest.getName().size(), 5);
325 FaceQueryFilter filter(interest.getName().at(4).blockFromValue());
326 BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000327
328 FaceStatus payload;
329 payload.setFaceId(256)
330 .setRemoteUri("udp4://84.67.35.111:6363")
331 .setLocalUri("udp4://79.91.49.215:6363")
332 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
333 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700334 .setMtu(6000)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000335 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
336 .setNInInterests(28975)
Junxiao Shif03d4792017-04-06 16:41:22 +0000337 .setNInData(28232)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000338 .setNInNacks(212)
339 .setNOutInterests(19525)
Junxiao Shif03d4792017-04-06 16:41:22 +0000340 .setNOutData(30993)
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000341 .setNOutNacks(1038)
342 .setNInBytes(13307258)
343 .setNOutBytes(6231946);
344
Junxiao Shi8f803f22017-02-10 03:04:28 +0000345 this->sendDataset(interest.getName(), payload);
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000346 };
347
348 this->execute("face show 256");
349 BOOST_CHECK_EQUAL(exitCode, 0);
Eric Newberryde332452018-01-30 11:45:32 -0700350 BOOST_CHECK(out.is_equal(NORMAL_NO_CONGESTION_OUTPUT));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000351 BOOST_CHECK(err.is_empty());
352}
353
354BOOST_AUTO_TEST_CASE(NotFound)
355{
356 this->processInterest = [this] (const Interest& interest) {
357 this->sendEmptyDataset(interest.getName());
358 };
359
360 this->execute("face show 256");
361 BOOST_CHECK_EQUAL(exitCode, 3);
362 BOOST_CHECK(out.is_empty());
Junxiao Shi8f803f22017-02-10 03:04:28 +0000363 BOOST_CHECK(err.is_equal("Face not found\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000364}
365
366BOOST_AUTO_TEST_CASE(Error)
367{
368 this->processInterest = nullptr; // no response
369
370 this->execute("face show 256");
371 BOOST_CHECK_EQUAL(exitCode, 1);
372 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700373 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000374}
375
376BOOST_AUTO_TEST_SUITE_END() // ShowCommand
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000377
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000378class ExecuteFaceCreateCommandFixture : public ExecuteCommandFixture
379{
380protected:
381 void
Eric Newberry4f8dd962018-06-17 21:32:07 -0700382 respond409(const Interest& interest, FacePersistency persistency, optional<uint64_t> mtu = {},
Eric Newberryde332452018-01-30 11:45:32 -0700383 bool enableLpReliability = false,
384 bool enableCongestionMarking = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000385 {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000386 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000387 ControlParameters body;
388 body.setFaceId(1172)
389 .setUri("udp4://100.77.30.65:6363")
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000390 .setLocalUri("udp4://68.62.26.57:24087")
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000391 .setFacePersistency(persistency)
392 .setFlags(0);
Eric Newberry4f8dd962018-06-17 21:32:07 -0700393 if (mtu) {
394 body.setMtu(*mtu);
395 }
Eric Newberry84d3adc2017-08-09 23:31:40 -0400396 if (enableLpReliability) {
397 body.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false);
398 }
Eric Newberryde332452018-01-30 11:45:32 -0700399 if (enableCongestionMarking) {
400 body.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
401 }
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000402 this->failCommand(interest, 409, "conflict-409", body);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000403 }
404};
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000405
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000406BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteFaceCreateCommandFixture)
407
408BOOST_AUTO_TEST_CASE(Creating)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000409{
410 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000411 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000412 BOOST_REQUIRE(req.hasUri());
413 BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363");
Junxiao Shi0d976922017-04-01 14:35:21 +0000414 BOOST_CHECK(!req.hasLocalUri());
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000415 BOOST_REQUIRE(req.hasFacePersistency());
416 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
417
418 ControlParameters resp;
419 resp.setFaceId(2130)
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000420 .setUri("udp4://159.242.33.78:6363")
421 .setLocalUri("udp4://179.63.153.45:28835")
Junxiao Shi5c1bb362017-05-11 16:03:38 +0000422 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
423 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000424 this->succeedCommand(interest, resp);
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000425 };
426
427 this->execute("face create udp://159.242.33.78");
428 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000429 BOOST_CHECK(out.is_equal("face-created id=2130 local=udp4://179.63.153.45:28835 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400430 "remote=udp4://159.242.33.78:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700431 "reliability=off congestion-marking=off\n"));
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000432 BOOST_CHECK(err.is_empty());
433}
434
Eric Newberry84d3adc2017-08-09 23:31:40 -0400435BOOST_AUTO_TEST_CASE(CreatingWithParams)
Junxiao Shi0d976922017-04-01 14:35:21 +0000436{
437 this->processInterest = [this] (const Interest& interest) {
438 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
439 BOOST_REQUIRE(req.hasUri());
440 BOOST_CHECK_EQUAL(req.getUri(), "udp4://22.91.89.51:19903");
441 BOOST_REQUIRE(req.hasLocalUri());
442 BOOST_CHECK_EQUAL(req.getLocalUri(), "udp4://98.68.23.71:6363");
443 BOOST_REQUIRE(req.hasFacePersistency());
444 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERMANENT);
Eric Newberry4f8dd962018-06-17 21:32:07 -0700445 BOOST_REQUIRE(req.hasBaseCongestionMarkingInterval());
446 BOOST_CHECK_EQUAL(req.getBaseCongestionMarkingInterval(), 100_ms);
447 BOOST_REQUIRE(req.hasDefaultCongestionThreshold());
448 BOOST_CHECK_EQUAL(req.getDefaultCongestionThreshold(), 65536);
449 BOOST_REQUIRE(req.hasMtu());
450 BOOST_CHECK_EQUAL(req.getMtu(), 10000);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400451 BOOST_CHECK(req.hasFlags());
452 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Junxiao Shi0d976922017-04-01 14:35:21 +0000453
454 ControlParameters resp;
455 resp.setFaceId(301)
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000456 .setUri("udp4://22.91.89.51:19903")
457 .setLocalUri("udp4://98.68.23.71:6363")
Junxiao Shi5c1bb362017-05-11 16:03:38 +0000458 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT)
Eric Newberryde332452018-01-30 11:45:32 -0700459 .setBaseCongestionMarkingInterval(100_ms)
460 .setDefaultCongestionThreshold(65536)
Eric Newberry4f8dd962018-06-17 21:32:07 -0700461 .setMtu(8800)
Eric Newberryde332452018-01-30 11:45:32 -0700462 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false)
463 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
Junxiao Shi0d976922017-04-01 14:35:21 +0000464 this->succeedCommand(interest, resp);
465 };
466
Eric Newberryde332452018-01-30 11:45:32 -0700467 this->execute("face create udp://22.91.89.51:19903 permanent local udp://98.68.23.71 reliability on "
468 "congestion-marking on congestion-marking-interval 100 "
Eric Newberry4f8dd962018-06-17 21:32:07 -0700469 "default-congestion-threshold 65536 mtu 10000");
Junxiao Shi0d976922017-04-01 14:35:21 +0000470 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000471 BOOST_CHECK(out.is_equal("face-created id=301 local=udp4://98.68.23.71:6363 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400472 "remote=udp4://22.91.89.51:19903 persistency=permanent "
Eric Newberryde332452018-01-30 11:45:32 -0700473 "reliability=on congestion-marking=on "
Eric Newberry4f8dd962018-06-17 21:32:07 -0700474 "congestion-marking-interval=100ms default-congestion-threshold=65536B "
475 "mtu=8800\n"));
Junxiao Shi0d976922017-04-01 14:35:21 +0000476 BOOST_CHECK(err.is_empty());
477}
478
Eric Newberry4f8dd962018-06-17 21:32:07 -0700479BOOST_AUTO_TEST_CASE(MtuExistingFace)
480{
481 bool hasUpdateCommand = false;
482 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
483 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND, 4000);
484 // no command other than faces/create is expected
485 };
486
487 this->execute("face create udp://100.77.30.65 mtu 5000");
488 BOOST_CHECK_EQUAL(exitCode, 1);
489 BOOST_CHECK(out.is_empty());
490 BOOST_CHECK(err.is_equal("Error 409 when creating face: conflict-409\n"));
491}
492
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000493BOOST_AUTO_TEST_CASE(UpgradingPersistency)
494{
495 bool hasUpdateCommand = false;
496 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000497 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
498 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000499 return;
500 }
501
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000502 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000503 hasUpdateCommand = true;
504 BOOST_REQUIRE(req.hasFaceId());
505 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
506 BOOST_REQUIRE(req.hasFacePersistency());
507 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
508 BOOST_CHECK(!req.hasFlags());
509
510 ControlParameters resp;
511 resp.setFaceId(1172)
512 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
513 .setFlags(0);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000514 this->succeedCommand(interest, resp);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000515 };
516
517 this->execute("face create udp://100.77.30.65");
518 BOOST_CHECK(hasUpdateCommand);
519 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000520 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400521 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700522 "reliability=off congestion-marking=off\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000523 BOOST_CHECK(err.is_empty());
524}
525
Eric Newberry4f8dd962018-06-17 21:32:07 -0700526BOOST_AUTO_TEST_CASE(UpgradingPersistencySameMtu)
527{
528 bool hasUpdateCommand = false;
529 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
530 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
531 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND, 8800);
532 return;
533 }
534
535 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
536 hasUpdateCommand = true;
537 BOOST_REQUIRE(req.hasFaceId());
538 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
539 BOOST_REQUIRE(req.hasFacePersistency());
540 BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT);
541 BOOST_CHECK(!req.hasFlags());
542
543 ControlParameters resp;
544 resp.setFaceId(1172)
545 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
546 .setFlags(0);
547 this->succeedCommand(interest, resp);
548 };
549
550 this->execute("face create udp://100.77.30.65 mtu 8800");
551 BOOST_CHECK(hasUpdateCommand);
552 BOOST_CHECK_EQUAL(exitCode, 0);
553 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
554 "remote=udp4://100.77.30.65:6363 persistency=persistent "
555 "reliability=off congestion-marking=off\n"));
556 BOOST_CHECK(err.is_empty());
557}
558
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000559BOOST_AUTO_TEST_CASE(NotDowngradingPersistency)
560{
561 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000562 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERMANENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000563 // no command other than faces/create is expected
564 };
565
566 this->execute("face create udp://100.77.30.65");
567 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000568 BOOST_CHECK(out.is_equal("face-exists id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400569 "remote=udp4://100.77.30.65:6363 persistency=permanent "
Eric Newberryde332452018-01-30 11:45:32 -0700570 "reliability=off congestion-marking=off\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000571 BOOST_CHECK(err.is_empty());
572}
573
574BOOST_AUTO_TEST_CASE(SamePersistency)
575{
576 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000577 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000578 // no command other than faces/create is expected
579 };
580
581 this->execute("face create udp://100.77.30.65");
582 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi1cce2a32017-05-02 02:39:55 +0000583 BOOST_CHECK(out.is_equal("face-exists id=1172 local=udp4://68.62.26.57:24087 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400584 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700585 "reliability=off congestion-marking=off\n"));
Eric Newberry84d3adc2017-08-09 23:31:40 -0400586 BOOST_CHECK(err.is_empty());
587}
588
589BOOST_AUTO_TEST_CASE(EnablingReliability)
590{
591 bool hasUpdateCommand = false;
592 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
593 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
594 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
595 return;
596 }
597
598 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
599 hasUpdateCommand = true;
600 BOOST_REQUIRE(req.hasFaceId());
601 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
602 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
603 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
604
605 ControlParameters resp;
606 resp.setFaceId(1172)
607 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
608 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true, false);
609 this->succeedCommand(interest, resp);
610 };
611
612 this->execute("face create udp://100.77.30.65 reliability on");
613 BOOST_CHECK_EQUAL(exitCode, 0);
614 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
615 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700616 "reliability=on congestion-marking=off\n"));
Eric Newberry84d3adc2017-08-09 23:31:40 -0400617 BOOST_CHECK(err.is_empty());
618}
619
620BOOST_AUTO_TEST_CASE(DisablingReliability)
621{
622 bool hasUpdateCommand = false;
623 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
624 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
Eric Newberry4f8dd962018-06-17 21:32:07 -0700625 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT, {}, true);
Eric Newberry84d3adc2017-08-09 23:31:40 -0400626 return;
627 }
628
629 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
630 hasUpdateCommand = true;
631 BOOST_REQUIRE(req.hasFaceId());
632 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
633 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
634 BOOST_CHECK(!req.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
635
636 ControlParameters resp;
637 resp.setFaceId(1172)
638 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
639 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false, false);
640 this->succeedCommand(interest, resp);
641 };
642
643 this->execute("face create udp://100.77.30.65 reliability off");
644 BOOST_CHECK_EQUAL(exitCode, 0);
645 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
646 "remote=udp4://100.77.30.65:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700647 "reliability=off congestion-marking=off\n"));
648 BOOST_CHECK(err.is_empty());
649}
650
651BOOST_AUTO_TEST_CASE(EnablingCongestionMarking)
652{
653 bool hasUpdateCommand = false;
654 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
655 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
656 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT);
657 return;
658 }
659
660 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
661 hasUpdateCommand = true;
662 BOOST_REQUIRE(req.hasFaceId());
663 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
664 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
665 BOOST_CHECK(req.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
666 BOOST_CHECK(!req.hasBaseCongestionMarkingInterval());
667 BOOST_CHECK(!req.hasDefaultCongestionThreshold());
668
669 ControlParameters resp;
670 resp.setFaceId(1172)
671 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
672 .setBaseCongestionMarkingInterval(100_ms)
673 .setDefaultCongestionThreshold(65536)
674 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true, false);
675 this->succeedCommand(interest, resp);
676 };
677
678 this->execute("face create udp://100.77.30.65 congestion-marking on");
679 BOOST_CHECK_EQUAL(exitCode, 0);
680 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
681 "remote=udp4://100.77.30.65:6363 persistency=persistent "
682 "reliability=off congestion-marking=on "
683 "congestion-marking-interval=100ms default-congestion-threshold=65536B\n"));
684 BOOST_CHECK(err.is_empty());
685}
686
687BOOST_AUTO_TEST_CASE(DisablingCongestionMarking)
688{
689 bool hasUpdateCommand = false;
690 this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) {
691 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
Eric Newberry4f8dd962018-06-17 21:32:07 -0700692 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_PERSISTENT, {}, false, true);
Eric Newberryde332452018-01-30 11:45:32 -0700693 return;
694 }
695
696 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
697 hasUpdateCommand = true;
698 BOOST_REQUIRE(req.hasFaceId());
699 BOOST_CHECK_EQUAL(req.getFaceId(), 1172);
700 BOOST_CHECK(req.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
701 BOOST_CHECK(!req.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
702 BOOST_CHECK(!req.hasBaseCongestionMarkingInterval());
703 BOOST_CHECK(!req.hasDefaultCongestionThreshold());
704
705 ControlParameters resp;
706 resp.setFaceId(1172)
707 .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT)
708 .setBaseCongestionMarkingInterval(100_ms)
709 .setDefaultCongestionThreshold(65536)
710 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false, false);
711 this->succeedCommand(interest, resp);
712 };
713
714 this->execute("face create udp://100.77.30.65 congestion-marking off");
715 BOOST_CHECK_EQUAL(exitCode, 0);
716 BOOST_CHECK(out.is_equal("face-updated id=1172 local=udp4://68.62.26.57:24087 "
717 "remote=udp4://100.77.30.65:6363 persistency=persistent "
718 "reliability=off congestion-marking=off "
719 "congestion-marking-interval=100ms default-congestion-threshold=65536B\n"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000720 BOOST_CHECK(err.is_empty());
721}
722
Junxiao Shi0d976922017-04-01 14:35:21 +0000723BOOST_AUTO_TEST_CASE(ErrorCanonizeRemote)
724{
725 this->execute("face create invalid://");
726 BOOST_CHECK_EQUAL(exitCode, 4);
727 BOOST_CHECK(out.is_empty());
728 BOOST_CHECK(err.is_equal("Error when canonizing 'invalid://': scheme not supported\n"));
729}
730
731BOOST_AUTO_TEST_CASE(ErrorCanonizeLocal)
732{
733 this->execute("face create udp4://24.37.20.47:6363 local invalid://");
734 BOOST_CHECK_EQUAL(exitCode, 4);
735 BOOST_CHECK(out.is_empty());
736 BOOST_CHECK(err.is_equal("Error when canonizing 'invalid://': scheme not supported\n"));
737}
738
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000739BOOST_AUTO_TEST_CASE(ErrorCreate)
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000740{
741 this->processInterest = nullptr; // no response
742
743 this->execute("face create udp://159.242.33.78");
744 BOOST_CHECK_EQUAL(exitCode, 1);
745 BOOST_CHECK(out.is_empty());
746 BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n"));
747}
748
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000749BOOST_AUTO_TEST_CASE(ErrorConflict)
750{
751 // Current NFD will not report a 409-conflict with a different remote FaceUri, but this is
752 // allowed by FaceMgmt protocol and nfdc should not attempt to upgrade persistency in this case.
753
754 this->processInterest = [this] (const Interest& interest) {
755 // conflict with udp4://100.77.30.65:6363
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000756 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000757 };
758
759 this->execute("face create udp://20.53.73.45");
760 BOOST_CHECK_EQUAL(exitCode, 1);
761 BOOST_CHECK(out.is_empty());
762 BOOST_CHECK(err.is_equal("Error 409 when creating face: conflict-409\n"));
763}
764
765BOOST_AUTO_TEST_CASE(ErrorUpdate)
766{
767 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000768 if (parseCommand(interest, "/localhost/nfd/faces/create")) {
769 this->respond409(interest, FacePersistency::FACE_PERSISTENCY_ON_DEMAND);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000770 return;
771 }
772
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000773 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/update");
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000774 // no response to faces/update
775 };
776
777 this->execute("face create udp://100.77.30.65");
778 BOOST_CHECK_EQUAL(exitCode, 1);
779 BOOST_CHECK(out.is_empty());
780 BOOST_CHECK(err.is_equal("Error 10060 when upgrading face persistency: request timed out\n"));
781}
782
Junxiao Shi1d7fef52017-02-02 05:33:14 +0000783BOOST_AUTO_TEST_SUITE_END() // CreateCommand
784
Junxiao Shi05dd4442017-02-06 22:50:07 +0000785BOOST_FIXTURE_TEST_SUITE(DestroyCommand, ExecuteCommandFixture)
786
787BOOST_AUTO_TEST_CASE(NormalByFaceId)
788{
789 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000790 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000791 return;
792 }
793
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000794 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000795 BOOST_REQUIRE(req.hasFaceId());
796 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
797
798 ControlParameters resp;
799 resp.setFaceId(10156);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000800 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000801 };
802
803 this->execute("face destroy 10156");
804 BOOST_CHECK_EQUAL(exitCode, 0);
805 BOOST_CHECK(out.is_equal("face-destroyed id=10156 local=tcp4://151.26.163.27:22967 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400806 "remote=tcp4://198.57.27.40:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700807 "reliability=off congestion-marking=off\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000808 BOOST_CHECK(err.is_empty());
809}
810
811BOOST_AUTO_TEST_CASE(NormalByFaceUri)
812{
813 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000814 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000815 return;
816 }
817
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000818 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000819 BOOST_REQUIRE(req.hasFaceId());
820 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
821
822 ControlParameters resp;
823 resp.setFaceId(2249);
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000824 this->succeedCommand(interest, resp);
Junxiao Shi05dd4442017-02-06 22:50:07 +0000825 };
826
827 this->execute("face destroy tcp://32.121.182.82");
828 BOOST_CHECK_EQUAL(exitCode, 0);
829 BOOST_CHECK(out.is_equal("face-destroyed id=2249 local=tcp4://30.99.87.98:31414 "
Eric Newberry84d3adc2017-08-09 23:31:40 -0400830 "remote=tcp4://32.121.182.82:6363 persistency=persistent "
Eric Newberryde332452018-01-30 11:45:32 -0700831 "reliability=off congestion-marking=off\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000832 BOOST_CHECK(err.is_empty());
833}
834
835BOOST_AUTO_TEST_CASE(FaceNotExist)
836{
837 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000838 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000839 };
840
841 this->execute("face destroy 23728");
842 BOOST_CHECK_EQUAL(exitCode, 3);
843 BOOST_CHECK(out.is_empty());
844 BOOST_CHECK(err.is_equal("Face not found\n"));
845}
846
847BOOST_AUTO_TEST_CASE(Ambiguous)
848{
849 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000850 BOOST_CHECK(this->respondFaceQuery(interest));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000851 };
852
853 this->execute("face destroy udp4://225.131.75.231:56363");
854 BOOST_CHECK_EQUAL(exitCode, 5);
855 BOOST_CHECK(out.is_empty());
856 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
857 "Re-run the command with a FaceId: "
858 "6720 (local=udp4://202.83.168.28:56363), "
859 "31066 (local=udp4://25.90.26.32:56363)\n"));
860}
861
862BOOST_AUTO_TEST_CASE(ErrorCanonization)
863{
864 this->execute("face destroy udp6://32.38.164.64:10445");
865 BOOST_CHECK_EQUAL(exitCode, 4);
866 BOOST_CHECK(out.is_empty());
867 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
Eric Newberry7d8695d2017-05-29 15:49:10 -0700868 "IPv4/v6 mismatch\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000869}
870
871BOOST_AUTO_TEST_CASE(ErrorDataset)
872{
873 this->processInterest = nullptr; // no response to dataset or command
874
875 this->execute("face destroy udp://159.242.33.78");
876 BOOST_CHECK_EQUAL(exitCode, 1);
877 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700878 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi05dd4442017-02-06 22:50:07 +0000879}
880
881BOOST_AUTO_TEST_CASE(ErrorCommand)
882{
883 this->processInterest = [this] (const Interest& interest) {
Junxiao Shi918e5d42017-02-25 03:58:21 +0000884 if (this->respondFaceQuery(interest)) {
Junxiao Shi05dd4442017-02-06 22:50:07 +0000885 return;
886 }
887
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000888 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/destroy");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000889 // no response to command
890 };
891
Junxiao Shi918e5d42017-02-25 03:58:21 +0000892 this->execute("face destroy 10156");
Junxiao Shi05dd4442017-02-06 22:50:07 +0000893 BOOST_CHECK_EQUAL(exitCode, 1);
894 BOOST_CHECK(out.is_empty());
895 BOOST_CHECK(err.is_equal("Error 10060 when destroying face: request timed out\n"));
896}
897
898BOOST_AUTO_TEST_SUITE_END() // DestroyCommand
899
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000900const std::string STATUS_XML = stripXmlSpaces(R"XML(
901 <faces>
902 <face>
903 <faceId>134</faceId>
904 <remoteUri>udp4://233.252.0.4:6363</remoteUri>
905 <localUri>udp4://192.0.2.1:6363</localUri>
906 <faceScope>non-local</faceScope>
907 <facePersistency>permanent</facePersistency>
908 <linkType>multi-access</linkType>
Eric Newberryde332452018-01-30 11:45:32 -0700909 <congestion/>
Eric Newberry6d932e82016-11-24 05:05:43 +0000910 <flags/>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000911 <packetCounters>
912 <incomingPackets>
913 <nInterests>22562</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000914 <nData>22031</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000915 <nNacks>63</nNacks>
916 </incomingPackets>
917 <outgoingPackets>
918 <nInterests>30121</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000919 <nData>20940</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000920 <nNacks>1218</nNacks>
921 </outgoingPackets>
922 </packetCounters>
923 <byteCounters>
924 <incomingBytes>2522915</incomingBytes>
925 <outgoingBytes>1353592</outgoingBytes>
926 </byteCounters>
927 </face>
928 <face>
929 <faceId>745</faceId>
930 <remoteUri>fd://75</remoteUri>
931 <localUri>unix:///var/run/nfd.sock</localUri>
932 <faceScope>local</faceScope>
933 <facePersistency>on-demand</facePersistency>
934 <linkType>point-to-point</linkType>
Eric Newberryde332452018-01-30 11:45:32 -0700935 <congestion>
936 <baseMarkingInterval>PT0.100S</baseMarkingInterval>
937 <defaultThreshold>65536</defaultThreshold>
938 </congestion>
Eric Newberry4f8dd962018-06-17 21:32:07 -0700939 <mtu>8800</mtu>
Eric Newberry6d932e82016-11-24 05:05:43 +0000940 <flags>
941 <localFieldsEnabled/>
Eric Newberry84d3adc2017-08-09 23:31:40 -0400942 <lpReliabilityEnabled/>
Eric Newberryde332452018-01-30 11:45:32 -0700943 <congestionMarkingEnabled/>
Eric Newberry6d932e82016-11-24 05:05:43 +0000944 </flags>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000945 <packetCounters>
946 <incomingPackets>
947 <nInterests>18998</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000948 <nData>26701</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000949 <nNacks>147</nNacks>
950 </incomingPackets>
951 <outgoingPackets>
952 <nInterests>34779</nInterests>
Junxiao Shif03d4792017-04-06 16:41:22 +0000953 <nData>17028</nData>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000954 <nNacks>1176</nNacks>
955 </outgoingPackets>
956 </packetCounters>
957 <byteCounters>
958 <incomingBytes>4672308</incomingBytes>
959 <outgoingBytes>8957187</outgoingBytes>
960 </byteCounters>
961 </face>
962 </faces>
963)XML");
964
965const std::string STATUS_TEXT =
966 "Faces:\n"
967 " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363"
968 " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}"
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000969 " flags={non-local permanent multi-access}\n"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000970 " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock"
Eric Newberry4f8dd962018-06-17 21:32:07 -0700971 " congestion={base-marking-interval=100ms default-threshold=65536B} mtu=8800"
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000972 " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}"
Eric Newberryde332452018-01-30 11:45:32 -0700973 " flags={local on-demand point-to-point local-fields lp-reliability congestion-marking}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000974
Junxiao Shi1f481fa2017-01-26 15:14:43 +0000975BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000976{
977 this->fetchStatus();
978 FaceStatus payload1;
979 payload1.setFaceId(134)
980 .setRemoteUri("udp4://233.252.0.4:6363")
981 .setLocalUri("udp4://192.0.2.1:6363")
982 .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL)
983 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT)
984 .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS)
985 .setNInInterests(22562)
Junxiao Shif03d4792017-04-06 16:41:22 +0000986 .setNInData(22031)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000987 .setNInNacks(63)
988 .setNOutInterests(30121)
Junxiao Shif03d4792017-04-06 16:41:22 +0000989 .setNOutData(20940)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000990 .setNOutNacks(1218)
991 .setNInBytes(2522915)
992 .setNOutBytes(1353592);
993 FaceStatus payload2;
994 payload2.setFaceId(745)
995 .setRemoteUri("fd://75")
996 .setLocalUri("unix:///var/run/nfd.sock")
997 .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL)
998 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND)
999 .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT)
Eric Newberryde332452018-01-30 11:45:32 -07001000 .setBaseCongestionMarkingInterval(100_ms)
1001 .setDefaultCongestionThreshold(65536)
Eric Newberry4f8dd962018-06-17 21:32:07 -07001002 .setMtu(8800)
Eric Newberry6d932e82016-11-24 05:05:43 +00001003 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true)
Eric Newberry84d3adc2017-08-09 23:31:40 -04001004 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true)
Eric Newberryde332452018-01-30 11:45:32 -07001005 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true)
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001006 .setNInInterests(18998)
Junxiao Shif03d4792017-04-06 16:41:22 +00001007 .setNInData(26701)
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001008 .setNInNacks(147)
1009 .setNOutInterests(34779)
Junxiao Shif03d4792017-04-06 16:41:22 +00001010 .setNOutData(17028)
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001011 .setNOutNacks(1176)
1012 .setNInBytes(4672308)
1013 .setNOutBytes(8957187);
1014 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
1015 this->prepareStatusOutput();
1016
1017 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
1018 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
1019}
1020
1021BOOST_AUTO_TEST_SUITE_END() // TestFaceModule
Junxiao Shi331ade72016-08-19 14:07:19 +00001022BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001023
1024} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +00001025} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001026} // namespace tools
1027} // namespace nfd