blob: b8b07d189d11af68d7f87447ece923429ba5209c [file] [log] [blame]
Junxiao Shicde37ad2015-12-24 01:02:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi7003c602017-01-10 13:35:28 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -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
26#include "face/ethernet-factory.hpp"
Junxiao Shi7003c602017-01-10 13:35:28 +000027#include "face/face.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070028
Eric Newberry42602412016-08-27 09:33:18 -070029#include "factory-test-common.hpp"
Junxiao Shi7003c602017-01-10 13:35:28 +000030#include "ethernet-fixture.hpp"
31#include "face-system-fixture.hpp"
32#include <boost/algorithm/string/replace.hpp>
33#include <boost/range/algorithm/count_if.hpp>
Junxiao Shicde37ad2015-12-24 01:02:05 -070034
35namespace nfd {
Junxiao Shi7003c602017-01-10 13:35:28 +000036namespace face {
Junxiao Shicde37ad2015-12-24 01:02:05 -070037namespace tests {
38
Junxiao Shi7003c602017-01-10 13:35:28 +000039using namespace nfd::tests;
Junxiao Shicde37ad2015-12-24 01:02:05 -070040
41BOOST_AUTO_TEST_SUITE(Face)
Junxiao Shi7003c602017-01-10 13:35:28 +000042BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, EthernetFixture)
43
44using face::Face;
45
46class EthernetConfigFixture : public EthernetFixture
47 , public FaceSystemFixture
48{
49public:
50 std::vector<const Face*>
Teng Liangbfea5752017-03-29 04:51:10 +000051 listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
Junxiao Shi7003c602017-01-10 13:35:28 +000052 {
Teng Liangbfea5752017-03-29 04:51:10 +000053 return this->listFacesByScheme("ether", linkType);
Junxiao Shi7003c602017-01-10 13:35:28 +000054 }
55
56 size_t
Teng Liangbfea5752017-03-29 04:51:10 +000057 countEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
Junxiao Shi7003c602017-01-10 13:35:28 +000058 {
Teng Liangbfea5752017-03-29 04:51:10 +000059 return this->listEtherMcastFaces(linkType).size();
Junxiao Shi7003c602017-01-10 13:35:28 +000060 }
61};
62
63BOOST_FIXTURE_TEST_SUITE(ProcessConfig, EthernetConfigFixture)
64
65BOOST_AUTO_TEST_CASE(Normal)
66{
67 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
68
69 const std::string CONFIG = R"CONFIG(
70 face_system
71 {
72 ether
73 {
74 mcast yes
75 mcast_group 01:00:5E:00:17:AA
Teng Liangbfea5752017-03-29 04:51:10 +000076 mcast_ad_hoc no
Junxiao Shi7003c602017-01-10 13:35:28 +000077 whitelist
78 {
79 *
80 }
81 blacklist
82 {
83 }
84 }
85 }
86 )CONFIG";
87
Junxiao Shi1b65ca12017-01-21 23:04:41 +000088 parseConfig(CONFIG, true);
89 parseConfig(CONFIG, false);
Junxiao Shi7003c602017-01-10 13:35:28 +000090
91 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
92}
93
Teng Liangbfea5752017-03-29 04:51:10 +000094BOOST_AUTO_TEST_CASE(EnableDisableMcast)
Junxiao Shi7003c602017-01-10 13:35:28 +000095{
Teng Liangbfea5752017-03-29 04:51:10 +000096 const std::string CONFIG_WITH_MCAST = R"CONFIG(
Junxiao Shi7003c602017-01-10 13:35:28 +000097 face_system
98 {
Teng Liangbfea5752017-03-29 04:51:10 +000099 ether
100 {
101 mcast yes
102 }
103 }
104 )CONFIG";
105 const std::string CONFIG_WITHOUT_MCAST = R"CONFIG(
106 face_system
107 {
108 ether
109 {
110 mcast no
111 }
Junxiao Shi7003c602017-01-10 13:35:28 +0000112 }
113 )CONFIG";
114
Teng Liangbfea5752017-03-29 04:51:10 +0000115 parseConfig(CONFIG_WITHOUT_MCAST, false);
Junxiao Shi7003c602017-01-10 13:35:28 +0000116 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
Teng Liangbfea5752017-03-29 04:51:10 +0000117
118 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
119
120 parseConfig(CONFIG_WITH_MCAST, false);
121 g_io.poll();
122 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size());
123
124 parseConfig(CONFIG_WITHOUT_MCAST, false);
125 g_io.poll();
126 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
127}
128
129BOOST_AUTO_TEST_CASE(McastAdHoc)
130{
131 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
132
133 const std::string CONFIG = R"CONFIG(
134 face_system
135 {
136 ether
137 {
138 mcast_ad_hoc yes
139 }
140 }
141 )CONFIG";
142
143 parseConfig(CONFIG, false);
144 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_AD_HOC), netifs.size());
145}
146
147BOOST_AUTO_TEST_CASE(ChangeMcastGroup)
148{
149 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
150
151 const std::string CONFIG1 = R"CONFIG(
152 face_system
153 {
154 ether
155 {
156 mcast_group 01:00:00:00:00:01
157 }
158 }
159 )CONFIG";
160 const std::string CONFIG2 = R"CONFIG(
161 face_system
162 {
163 ether
164 {
165 mcast_group 01:00:00:00:00:02
166 }
167 }
168 )CONFIG";
169
170 parseConfig(CONFIG1, false);
171 auto etherMcastFaces = this->listEtherMcastFaces();
172 BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
173 BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
174 FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x01)));
175
176 parseConfig(CONFIG2, false);
177 g_io.poll();
178 etherMcastFaces = this->listEtherMcastFaces();
179 BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size());
180 BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(),
181 FaceUri(ethernet::Address(0x01, 0x00, 0x00, 0x00, 0x00, 0x02)));
Junxiao Shi7003c602017-01-10 13:35:28 +0000182}
183
184BOOST_AUTO_TEST_CASE(Whitelist)
185{
186 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
187
188 std::string CONFIG = R"CONFIG(
189 face_system
190 {
191 ether
192 {
193 whitelist
194 {
195 ifname %ifname
196 }
197 }
198 }
199 )CONFIG";
200 boost::replace_first(CONFIG, "%ifname", netifs.front().name);
201
Junxiao Shi1b65ca12017-01-21 23:04:41 +0000202 parseConfig(CONFIG, false);
Junxiao Shi7003c602017-01-10 13:35:28 +0000203 auto etherMcastFaces = this->listEtherMcastFaces();
204 BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), 1);
205 BOOST_CHECK_EQUAL(etherMcastFaces.front()->getLocalUri().getHost(), netifs.front().name);
206}
207
208BOOST_AUTO_TEST_CASE(Blacklist)
209{
210 SKIP_IF_ETHERNET_NETIF_COUNT_LT(1);
211
212 std::string CONFIG = R"CONFIG(
213 face_system
214 {
215 ether
216 {
217 blacklist
218 {
219 ifname %ifname
220 }
221 }
222 }
223 )CONFIG";
224 boost::replace_first(CONFIG, "%ifname", netifs.front().name);
225
Junxiao Shi1b65ca12017-01-21 23:04:41 +0000226 parseConfig(CONFIG, false);
Junxiao Shi7003c602017-01-10 13:35:28 +0000227 auto etherMcastFaces = this->listEtherMcastFaces();
228 BOOST_CHECK_EQUAL(etherMcastFaces.size(), netifs.size() - 1);
229 BOOST_CHECK_EQUAL(boost::count_if(etherMcastFaces, [=] (const Face* face) {
230 return face->getLocalUri().getHost() == netifs.front().name;
231 }), 0);
232}
233
Teng Liangbfea5752017-03-29 04:51:10 +0000234BOOST_AUTO_TEST_CASE(Omitted)
Junxiao Shi7003c602017-01-10 13:35:28 +0000235{
Teng Liangbfea5752017-03-29 04:51:10 +0000236 const std::string CONFIG = R"CONFIG(
Junxiao Shi7003c602017-01-10 13:35:28 +0000237 face_system
238 {
Junxiao Shi7003c602017-01-10 13:35:28 +0000239 }
240 )CONFIG";
241
Teng Liangbfea5752017-03-29 04:51:10 +0000242 parseConfig(CONFIG, true);
243 parseConfig(CONFIG, false);
244
Junxiao Shi7003c602017-01-10 13:35:28 +0000245 BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0);
Junxiao Shi7003c602017-01-10 13:35:28 +0000246}
247
248BOOST_AUTO_TEST_CASE(BadMcast)
249{
250 const std::string CONFIG = R"CONFIG(
251 face_system
252 {
253 ether
254 {
255 mcast hello
256 }
257 }
258 )CONFIG";
259
260 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
261 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
262}
263
264BOOST_AUTO_TEST_CASE(BadMcastGroup)
265{
266 const std::string CONFIG = R"CONFIG(
267 face_system
268 {
269 ether
270 {
271 mcast yes
272 mcast_group hello
273 }
274 }
275 )CONFIG";
276
277 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
278 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
279}
280
281BOOST_AUTO_TEST_CASE(UnicastMcastGroup)
282{
283 const std::string CONFIG = R"CONFIG(
284 face_system
285 {
286 ether
287 {
288 mcast yes
289 mcast_group 02:00:00:00:00:01
290 }
291 }
292 )CONFIG";
293
294 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
295 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
296}
297
298BOOST_AUTO_TEST_CASE(UnknownOption)
299{
300 const std::string CONFIG = R"CONFIG(
301 face_system
302 {
303 ether
304 {
305 hello
306 }
307 }
308 )CONFIG";
309
310 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
311 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
312}
313
314BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
Junxiao Shicde37ad2015-12-24 01:02:05 -0700315
316BOOST_AUTO_TEST_CASE(GetChannels)
317{
318 EthernetFactory factory;
319
320 auto channels = factory.getChannels();
321 BOOST_CHECK_EQUAL(channels.empty(), true);
322}
323
Junxiao Shicde37ad2015-12-24 01:02:05 -0700324BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
325{
326 EthernetFactory factory;
327
Eric Newberry42602412016-08-27 09:33:18 -0700328 createFace(factory,
329 FaceUri("ether://[08:00:27:01:01:01]"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000330 {},
Eric Newberry42602412016-08-27 09:33:18 -0700331 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700332 false,
Eric Newberry42602412016-08-27 09:33:18 -0700333 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700334
Eric Newberry42602412016-08-27 09:33:18 -0700335 createFace(factory,
336 FaceUri("ether://[08:00:27:01:01:01]"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000337 {},
Eric Newberry42602412016-08-27 09:33:18 -0700338 ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
Eric Newberryf40551a2016-09-05 15:41:16 -0700339 false,
Eric Newberry42602412016-08-27 09:33:18 -0700340 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700341
Eric Newberry42602412016-08-27 09:33:18 -0700342 createFace(factory,
343 FaceUri("ether://[08:00:27:01:01:01]"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000344 {},
Eric Newberry42602412016-08-27 09:33:18 -0700345 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700346 false,
Eric Newberry42602412016-08-27 09:33:18 -0700347 {CreateFaceExpectedResult::FAILURE, 406, "Unsupported protocol"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700348}
349
350BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory
351BOOST_AUTO_TEST_SUITE_END() // Face
352
353} // namespace tests
Junxiao Shi7003c602017-01-10 13:35:28 +0000354} // namespace face
Junxiao Shicde37ad2015-12-24 01:02:05 -0700355} // namespace nfd