Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * 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 Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 27 | #include "face/face.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 28 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 30 | #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 Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 36 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | namespace tests { |
| 38 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 39 | class EthernetFactoryFixture : public EthernetFixture |
| 40 | , public FaceSystemFactoryFixture<EthernetFactory> |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 41 | { |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 42 | protected: |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 43 | std::vector<const Face*> |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 44 | listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 45 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 46 | return this->listFacesByScheme("ether", linkType); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | size_t |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 50 | countEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 51 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 52 | return this->listEtherMcastFaces(linkType).size(); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame^] | 56 | BOOST_AUTO_TEST_SUITE(Face) |
| 57 | BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, EthernetFactoryFixture) |
| 58 | |
| 59 | using nfd::Face; |
| 60 | |
| 61 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 62 | |
| 63 | BOOST_AUTO_TEST_CASE(Normal) |
| 64 | { |
| 65 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 66 | |
| 67 | const std::string CONFIG = R"CONFIG( |
| 68 | face_system |
| 69 | { |
| 70 | ether |
| 71 | { |
| 72 | mcast yes |
| 73 | mcast_group 01:00:5E:00:17:AA |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 74 | mcast_ad_hoc no |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 75 | whitelist |
| 76 | { |
| 77 | * |
| 78 | } |
| 79 | blacklist |
| 80 | { |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | )CONFIG"; |
| 85 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 86 | parseConfig(CONFIG, true); |
| 87 | parseConfig(CONFIG, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 88 | |
| 89 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size()); |
| 90 | } |
| 91 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(EnableDisableMcast) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 93 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 94 | const std::string CONFIG_WITH_MCAST = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 95 | face_system |
| 96 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 97 | ether |
| 98 | { |
| 99 | mcast yes |
| 100 | } |
| 101 | } |
| 102 | )CONFIG"; |
| 103 | const std::string CONFIG_WITHOUT_MCAST = R"CONFIG( |
| 104 | face_system |
| 105 | { |
| 106 | ether |
| 107 | { |
| 108 | mcast no |
| 109 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 110 | } |
| 111 | )CONFIG"; |
| 112 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 113 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 114 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 115 | |
| 116 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 117 | |
| 118 | parseConfig(CONFIG_WITH_MCAST, false); |
| 119 | g_io.poll(); |
| 120 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size()); |
| 121 | |
| 122 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
| 123 | g_io.poll(); |
| 124 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
| 125 | } |
| 126 | |
| 127 | BOOST_AUTO_TEST_CASE(McastAdHoc) |
| 128 | { |
| 129 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 130 | |
| 131 | const std::string CONFIG = R"CONFIG( |
| 132 | face_system |
| 133 | { |
| 134 | ether |
| 135 | { |
| 136 | mcast_ad_hoc yes |
| 137 | } |
| 138 | } |
| 139 | )CONFIG"; |
| 140 | |
| 141 | parseConfig(CONFIG, false); |
| 142 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_AD_HOC), netifs.size()); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(ChangeMcastGroup) |
| 146 | { |
| 147 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 148 | |
| 149 | const std::string CONFIG1 = R"CONFIG( |
| 150 | face_system |
| 151 | { |
| 152 | ether |
| 153 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 154 | mcast_group 01:00:5e:90:10:01 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | )CONFIG"; |
| 158 | const std::string CONFIG2 = R"CONFIG( |
| 159 | face_system |
| 160 | { |
| 161 | ether |
| 162 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 163 | mcast_group 01:00:5e:90:10:02 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | )CONFIG"; |
| 167 | |
| 168 | parseConfig(CONFIG1, false); |
| 169 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 170 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 171 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 172 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x01})); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 173 | |
| 174 | parseConfig(CONFIG2, false); |
| 175 | g_io.poll(); |
| 176 | etherMcastFaces = this->listEtherMcastFaces(); |
| 177 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 178 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 179 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x02})); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | BOOST_AUTO_TEST_CASE(Whitelist) |
| 183 | { |
| 184 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 185 | |
| 186 | std::string CONFIG = R"CONFIG( |
| 187 | face_system |
| 188 | { |
| 189 | ether |
| 190 | { |
| 191 | whitelist |
| 192 | { |
| 193 | ifname %ifname |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 198 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 199 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 200 | parseConfig(CONFIG, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 201 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 202 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), 1); |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getLocalUri().getHost(), netifs.front()->getName()); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | BOOST_AUTO_TEST_CASE(Blacklist) |
| 207 | { |
| 208 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 209 | |
| 210 | std::string CONFIG = R"CONFIG( |
| 211 | face_system |
| 212 | { |
| 213 | ether |
| 214 | { |
| 215 | blacklist |
| 216 | { |
| 217 | ifname %ifname |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 222 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 223 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 224 | parseConfig(CONFIG, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 225 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 226 | BOOST_CHECK_EQUAL(etherMcastFaces.size(), netifs.size() - 1); |
| 227 | BOOST_CHECK_EQUAL(boost::count_if(etherMcastFaces, [=] (const Face* face) { |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 228 | return face->getLocalUri().getHost() == netifs.front()->getName(); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 229 | }), 0); |
| 230 | } |
| 231 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 232 | BOOST_AUTO_TEST_CASE(Omitted) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 233 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 234 | const std::string CONFIG = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 235 | face_system |
| 236 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 237 | } |
| 238 | )CONFIG"; |
| 239 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 240 | parseConfig(CONFIG, true); |
| 241 | parseConfig(CONFIG, false); |
| 242 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 247 | { |
| 248 | const std::string CONFIG = R"CONFIG( |
| 249 | face_system |
| 250 | { |
| 251 | ether |
| 252 | { |
| 253 | mcast hello |
| 254 | } |
| 255 | } |
| 256 | )CONFIG"; |
| 257 | |
| 258 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 259 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 260 | } |
| 261 | |
| 262 | BOOST_AUTO_TEST_CASE(BadMcastGroup) |
| 263 | { |
| 264 | const std::string CONFIG = R"CONFIG( |
| 265 | face_system |
| 266 | { |
| 267 | ether |
| 268 | { |
| 269 | mcast yes |
| 270 | mcast_group hello |
| 271 | } |
| 272 | } |
| 273 | )CONFIG"; |
| 274 | |
| 275 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 276 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 277 | } |
| 278 | |
| 279 | BOOST_AUTO_TEST_CASE(UnicastMcastGroup) |
| 280 | { |
| 281 | const std::string CONFIG = R"CONFIG( |
| 282 | face_system |
| 283 | { |
| 284 | ether |
| 285 | { |
| 286 | mcast yes |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 287 | mcast_group 00:00:5e:00:53:5e |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | )CONFIG"; |
| 291 | |
| 292 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 293 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 294 | } |
| 295 | |
| 296 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 297 | { |
| 298 | const std::string CONFIG = R"CONFIG( |
| 299 | face_system |
| 300 | { |
| 301 | ether |
| 302 | { |
| 303 | hello |
| 304 | } |
| 305 | } |
| 306 | )CONFIG"; |
| 307 | |
| 308 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 309 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 310 | } |
| 311 | |
| 312 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 313 | |
| 314 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 315 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 316 | auto channels = factory.getChannels(); |
| 317 | BOOST_CHECK_EQUAL(channels.empty(), true); |
| 318 | } |
| 319 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 320 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
| 321 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 322 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 323 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 324 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 325 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 326 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 327 | {CreateFaceExpectedResult::FAILURE, 406, |
| 328 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 329 | |
| 330 | createFace(factory, |
| 331 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 332 | FaceUri("udp4://127.0.0.1:20071"), |
| 333 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 334 | false, |
| 335 | {CreateFaceExpectedResult::FAILURE, 406, |
| 336 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 337 | |
| 338 | createFace(factory, |
| 339 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 340 | FaceUri("dev://eth0"), |
| 341 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
| 342 | false, |
| 343 | {CreateFaceExpectedResult::FAILURE, 406, |
| 344 | "Outgoing Ethernet faces do not support on-demand persistency"}); |
| 345 | |
| 346 | createFace(factory, |
| 347 | FaceUri("ether://[01:00:5e:90:10:5e]"), |
| 348 | FaceUri("dev://eth0"), |
| 349 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 350 | false, |
| 351 | {CreateFaceExpectedResult::FAILURE, 406, |
| 352 | "Cannot create multicast Ethernet faces"}); |
| 353 | |
| 354 | createFace(factory, |
| 355 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 356 | FaceUri("dev://eth0"), |
| 357 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 358 | true, |
| 359 | {CreateFaceExpectedResult::FAILURE, 406, |
| 360 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory |
| 364 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 365 | |
| 366 | } // namespace tests |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 367 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 368 | } // namespace nfd |