blob: 4274efa1d6a0d67d02a1e3ae975ce24935cb3e51 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi60286192017-07-26 01:07:48 +00002/*
Yanbiao Li58ba3f92017-02-15 14:27:18 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -07004 * 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
Yanbiao Li58ba3f92017-02-15 14:27:18 +000026#include "mgmt/face-manager.hpp"
Eric Newberry42602412016-08-27 09:33:18 -070027#include "face-manager-command-fixture.hpp"
28#include "nfd-manager-common-fixture.hpp"
Junxiao Shib84e6742016-07-19 13:16:22 +000029
Yanbiao Li73860e32015-08-19 16:30:16 -070030namespace nfd {
31namespace tests {
32
Yanbiao Li73860e32015-08-19 16:30:16 -070033BOOST_AUTO_TEST_SUITE(Mgmt)
34BOOST_AUTO_TEST_SUITE(TestFaceManager)
35
36BOOST_FIXTURE_TEST_SUITE(CreateFace, BaseFixture)
37
Yanbiao Li73860e32015-08-19 16:30:16 -070038class TcpFaceOnDemand
39{
40public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040041 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070042 getParameters()
43 {
44 return ControlParameters()
45 .setUri("tcp4://127.0.0.1:26363")
46 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
47 }
48};
49
50class TcpFacePersistent
51{
52public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040053 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070054 getParameters()
55 {
56 return ControlParameters()
57 .setUri("tcp4://127.0.0.1:26363")
58 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
59 }
60};
61
62class TcpFacePermanent
63{
64public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040065 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070066 getParameters()
67 {
68 return ControlParameters()
69 .setUri("tcp4://127.0.0.1:26363")
70 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
71 }
72};
73
74class UdpFaceOnDemand
75{
76public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040077 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070078 getParameters()
79 {
80 return ControlParameters()
81 .setUri("udp4://127.0.0.1:26363")
82 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
83 }
84};
85
Yanbiao Li73860e32015-08-19 16:30:16 -070086class UdpFacePersistent
87{
88public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040089 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070090 getParameters()
91 {
92 return ControlParameters()
93 .setUri("udp4://127.0.0.1:26363")
94 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
95 }
96};
97
98class UdpFacePermanent
99{
100public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400101 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -0700102 getParameters()
103 {
104 return ControlParameters()
105 .setUri("udp4://127.0.0.1:26363")
106 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
107 }
108};
109
Eric Newberryf40551a2016-09-05 15:41:16 -0700110class LocalTcpFaceLocalFieldsEnabled
111{
112public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400113 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700114 getParameters()
115 {
116 return ControlParameters()
117 .setUri("tcp4://127.0.0.1:26363")
118 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
119 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
120 }
121};
122
123class LocalTcpFaceLocalFieldsDisabled
124{
125public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400126 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700127 getParameters()
128 {
129 return ControlParameters()
130 .setUri("tcp4://127.0.0.1:26363")
131 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
132 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
133 }
134};
135
136class NonLocalUdpFaceLocalFieldsEnabled // won't work because non-local scope
137{
138public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400139 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700140 getParameters()
141 {
142 return ControlParameters()
143 .setUri("udp4://127.0.0.1:26363")
144 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
145 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
146 }
147};
148
149class NonLocalUdpFaceLocalFieldsDisabled
150{
151public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400152 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700153 getParameters()
154 {
155 return ControlParameters()
156 .setUri("udp4://127.0.0.1:26363")
157 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
158 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
159 }
160};
161
Eric Newberry2642cd22017-07-13 21:34:53 -0400162class TcpFaceLpReliabilityEnabled
163{
164public:
165 static ControlParameters
166 getParameters()
167 {
168 return ControlParameters()
169 .setUri("tcp4://127.0.0.1:26363")
170 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
171 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
172 }
173};
174
175class TcpFaceLpReliabilityDisabled
176{
177public:
178 static ControlParameters
179 getParameters()
180 {
181 return ControlParameters()
182 .setUri("tcp4://127.0.0.1:26363")
183 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
184 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
185 }
186};
187
188class UdpFaceLpReliabilityEnabled
189{
190public:
191 static ControlParameters
192 getParameters()
193 {
194 return ControlParameters()
195 .setUri("tcp4://127.0.0.1:26363")
196 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
197 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
198 }
199};
200
201class UdpFaceLpReliabilityDisabled
202{
203public:
204 static ControlParameters
205 getParameters()
206 {
207 return ControlParameters()
208 .setUri("tcp4://127.0.0.1:26363")
209 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
210 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
211 }
212};
213
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000214class FaceUriMalformed
215{
216public:
217 static ControlParameters
218 getParameters()
219 {
220 return ControlParameters()
221 .setUri("tcp4://127.0.0.1:not-a-port");
222 }
223};
224
225class FaceUriNonCanonical
226{
227public:
228 static ControlParameters
229 getParameters()
230 {
231 return ControlParameters()
232 .setUri("udp://localhost");
233 }
234};
235
236class FaceUriUnsupportedScheme
237{
238public:
239 static ControlParameters
240 getParameters()
241 {
242 return ControlParameters()
243 .setUri("dev://eth0");
244 }
245};
246
Yanbiao Li73860e32015-08-19 16:30:16 -0700247namespace mpl = boost::mpl;
248
Eric Newberry42602412016-08-27 09:33:18 -0700249// pairs of CreateCommand and Success/Failure status
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400250using TestCases = mpl::vector<
251 mpl::pair<TcpFaceOnDemand, CommandFailure<406>>,
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700252 mpl::pair<TcpFacePersistent, CommandSuccess>,
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400253 mpl::pair<TcpFacePermanent, CommandSuccess>,
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700254 mpl::pair<UdpFaceOnDemand, CommandFailure<406>>,
255 mpl::pair<UdpFacePersistent, CommandSuccess>,
256 mpl::pair<UdpFacePermanent, CommandSuccess>,
Eric Newberryf40551a2016-09-05 15:41:16 -0700257 mpl::pair<LocalTcpFaceLocalFieldsEnabled, CommandSuccess>,
258 mpl::pair<LocalTcpFaceLocalFieldsDisabled, CommandSuccess>,
259 mpl::pair<NonLocalUdpFaceLocalFieldsEnabled, CommandFailure<406>>,
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000260 mpl::pair<NonLocalUdpFaceLocalFieldsDisabled, CommandSuccess>,
Eric Newberry2642cd22017-07-13 21:34:53 -0400261 mpl::pair<TcpFaceLpReliabilityEnabled, CommandSuccess>,
262 mpl::pair<TcpFaceLpReliabilityDisabled, CommandSuccess>,
263 mpl::pair<UdpFaceLpReliabilityEnabled, CommandSuccess>,
264 mpl::pair<UdpFaceLpReliabilityDisabled, CommandSuccess>,
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000265 mpl::pair<FaceUriMalformed, CommandFailure<400>>,
266 mpl::pair<FaceUriNonCanonical, CommandFailure<400>>,
267 mpl::pair<FaceUriUnsupportedScheme, CommandFailure<406>>>;
Yanbiao Li73860e32015-08-19 16:30:16 -0700268
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400269BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700270{
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400271 using FaceType = typename T::first;
272 using CreateResult = typename T::second;
Yanbiao Li73860e32015-08-19 16:30:16 -0700273
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000274 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
Yanbiao Li73860e32015-08-19 16:30:16 -0700275
276 bool hasCallbackFired = false;
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000277 this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) {
278 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberry42602412016-08-27 09:33:18 -0700279 return;
280 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700281
Eric Newberry42602412016-08-27 09:33:18 -0700282 ControlResponse actual(response.getContent().blockFromValue());
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400283 ControlResponse expected(CreateResult::getExpected());
Eric Newberry42602412016-08-27 09:33:18 -0700284 BOOST_TEST_MESSAGE(actual.getText());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000285 BOOST_CHECK_EQUAL(expected.getCode(), actual.getCode());
Yanbiao Li73860e32015-08-19 16:30:16 -0700286
Eric Newberry42602412016-08-27 09:33:18 -0700287 if (actual.getBody().hasWire()) {
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400288 ControlParameters expectedParams(FaceType::getParameters());
Eric Newberry42602412016-08-27 09:33:18 -0700289 ControlParameters actualParams(actual.getBody());
Yanbiao Li73860e32015-08-19 16:30:16 -0700290
Eric Newberry42602412016-08-27 09:33:18 -0700291 BOOST_CHECK(actualParams.hasFaceId());
292 BOOST_CHECK_EQUAL(expectedParams.getFacePersistency(), actualParams.getFacePersistency());
293
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700294 if (actual.getCode() == 200) {
295 if (expectedParams.hasFlags()) {
Eric Newberryf40551a2016-09-05 15:41:16 -0700296 BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
297 actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
Eric Newberry2642cd22017-07-13 21:34:53 -0400298 BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED),
299 actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700300 }
301 else {
Eric Newberryf40551a2016-09-05 15:41:16 -0700302 // local fields are disabled by default
303 BOOST_CHECK_EQUAL(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED), false);
Eric Newberry2642cd22017-07-13 21:34:53 -0400304 BOOST_CHECK_EQUAL(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED), false);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700305 }
306 }
307 else {
Yanbiao Li73860e32015-08-19 16:30:16 -0700308 BOOST_CHECK_EQUAL(expectedParams.getUri(), actualParams.getUri());
Yanbiao Li73860e32015-08-19 16:30:16 -0700309 }
Eric Newberry42602412016-08-27 09:33:18 -0700310 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700311
312 if (actual.getCode() != 200) {
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000313 FaceUri uri;
314 if (uri.parse(FaceType::getParameters().getUri())) {
315 // ensure face not created
Davide Pesaventob5eee202017-09-21 23:59:22 -0400316 const auto& faceTable = this->node1.faceTable;
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000317 BOOST_CHECK(std::none_of(faceTable.begin(), faceTable.end(), [uri] (Face& face) {
318 return face.getRemoteUri() == uri;
319 }));
320 }
321 else {
322 // do not check malformed FaceUri
323 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700324 }
325
Eric Newberry42602412016-08-27 09:33:18 -0700326 hasCallbackFired = true;
327 });
Yanbiao Li73860e32015-08-19 16:30:16 -0700328
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000329 this->node1.face.receive(req);
Junxiao Shib84e6742016-07-19 13:16:22 +0000330 this->advanceClocks(time::milliseconds(1), 5);
Yanbiao Li73860e32015-08-19 16:30:16 -0700331
332 BOOST_CHECK(hasCallbackFired);
333}
334
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000335BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700336{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000337 using FaceType = UdpFacePersistent;
Yanbiao Li73860e32015-08-19 16:30:16 -0700338
339 {
340 // create face
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000341 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
342 this->node1.face.receive(req);
Junxiao Shib84e6742016-07-19 13:16:22 +0000343 this->advanceClocks(time::milliseconds(1), 5);
Yanbiao Li73860e32015-08-19 16:30:16 -0700344 }
345
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000346 // find the created face
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400347 auto foundFace = this->node1.findFaceByUri(FaceType::getParameters().getUri());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000348 BOOST_REQUIRE(foundFace != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700349
350 {
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000351 // re-create face
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000352 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
Yanbiao Li73860e32015-08-19 16:30:16 -0700353
354 bool hasCallbackFired = false;
Junxiao Shib84e6742016-07-19 13:16:22 +0000355 this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400356 [req, foundFace, &hasCallbackFired] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000357 if (!req.getName().isPrefixOf(response.getName())) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700358 return;
359 }
360
361 ControlResponse actual(response.getContent().blockFromValue());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000362 BOOST_REQUIRE_EQUAL(actual.getCode(), 409);
Yanbiao Li73860e32015-08-19 16:30:16 -0700363
Yanbiao Li73860e32015-08-19 16:30:16 -0700364 ControlParameters actualParams(actual.getBody());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000365 BOOST_CHECK_EQUAL(foundFace->getId(), actualParams.getFaceId());
366 BOOST_CHECK_EQUAL(foundFace->getRemoteUri().toString(), actualParams.getUri());
367 BOOST_CHECK_EQUAL(foundFace->getPersistency(), actualParams.getFacePersistency());
Yanbiao Li73860e32015-08-19 16:30:16 -0700368
369 hasCallbackFired = true;
370 });
371
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000372 this->node1.face.receive(req);
Junxiao Shib84e6742016-07-19 13:16:22 +0000373 this->advanceClocks(time::milliseconds(1), 5);
Yanbiao Li73860e32015-08-19 16:30:16 -0700374
375 BOOST_CHECK(hasCallbackFired);
376 }
377}
378
379BOOST_AUTO_TEST_SUITE_END() // CreateFace
380BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
381BOOST_AUTO_TEST_SUITE_END() // Mgmt
382
Weiwei Liuf5aee942016-03-19 07:00:42 +0000383} // namespace tests
384} // namespace nfd