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 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 29 | #include "ethernet-fixture.hpp" |
| 30 | #include "face-system-fixture.hpp" |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame] | 31 | #include "factory-test-common.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 32 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 33 | #include <boost/algorithm/string/replace.hpp> |
| 34 | #include <boost/range/algorithm/count_if.hpp> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 37 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 38 | namespace tests { |
| 39 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 40 | class EthernetFactoryFixture : public EthernetFixture |
| 41 | , public FaceSystemFactoryFixture<EthernetFactory> |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 42 | { |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 43 | protected: |
Junxiao Shi | 79a9208 | 2017-08-08 02:40:59 +0000 | [diff] [blame] | 44 | EthernetFactoryFixture() |
| 45 | { |
| 46 | this->copyRealNetifsToNetmon(); |
| 47 | } |
| 48 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 49 | std::set<std::string> |
| 50 | listUrisOfAvailableNetifs() const |
| 51 | { |
| 52 | std::set<std::string> uris; |
| 53 | std::transform(netifs.begin(), netifs.end(), std::inserter(uris, uris.end()), |
| 54 | [] (const shared_ptr<const ndn::net::NetworkInterface>& ni) { |
| 55 | return FaceUri::fromDev(ni->getName()).toString(); |
| 56 | }); |
| 57 | return uris; |
| 58 | } |
| 59 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 60 | std::vector<const Face*> |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 61 | listEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 62 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 63 | return this->listFacesByScheme("ether", linkType); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | size_t |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 67 | countEtherMcastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 68 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 69 | return this->listEtherMcastFaces(linkType).size(); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 70 | } |
| 71 | }; |
| 72 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 73 | BOOST_AUTO_TEST_SUITE(Face) |
| 74 | BOOST_FIXTURE_TEST_SUITE(TestEthernetFactory, EthernetFactoryFixture) |
| 75 | |
| 76 | using nfd::Face; |
| 77 | |
| 78 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 79 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 80 | BOOST_AUTO_TEST_CASE(ListeningChannels) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 81 | { |
| 82 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 83 | |
| 84 | const std::string CONFIG = R"CONFIG( |
| 85 | face_system |
| 86 | { |
| 87 | ether |
| 88 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 89 | listen yes |
| 90 | idle_timeout 60 |
| 91 | mcast no |
| 92 | } |
| 93 | } |
| 94 | )CONFIG"; |
| 95 | |
| 96 | parseConfig(CONFIG, true); |
| 97 | parseConfig(CONFIG, false); |
| 98 | |
| 99 | auto& factory = this->getFactoryById<EthernetFactory>("ether"); |
| 100 | checkChannelListEqual(factory, this->listUrisOfAvailableNetifs()); |
| 101 | for (const auto& channel : factory.getChannels()) { |
| 102 | BOOST_CHECK_EQUAL(channel->isListening(), true); |
| 103 | } |
| 104 | |
| 105 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
| 106 | } |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(NonListeningChannels) |
| 109 | { |
| 110 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 111 | |
| 112 | const std::string CONFIG = R"CONFIG( |
| 113 | face_system |
| 114 | { |
| 115 | ether |
| 116 | { |
| 117 | listen no |
| 118 | idle_timeout 60 |
| 119 | mcast no |
| 120 | } |
| 121 | } |
| 122 | )CONFIG"; |
| 123 | |
| 124 | parseConfig(CONFIG, true); |
| 125 | parseConfig(CONFIG, false); |
| 126 | |
| 127 | auto& factory = this->getFactoryById<EthernetFactory>("ether"); |
| 128 | checkChannelListEqual(factory, this->listUrisOfAvailableNetifs()); |
| 129 | for (const auto& channel : factory.getChannels()) { |
| 130 | BOOST_CHECK_EQUAL(channel->isListening(), false); |
| 131 | } |
| 132 | |
| 133 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
| 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(BadListen) |
| 137 | { |
| 138 | const std::string CONFIG = R"CONFIG( |
| 139 | face_system |
| 140 | { |
| 141 | ether |
| 142 | { |
| 143 | listen hello |
| 144 | } |
| 145 | } |
| 146 | )CONFIG"; |
| 147 | |
| 148 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 149 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(McastNormal) |
| 153 | { |
| 154 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 155 | |
| 156 | const std::string CONFIG = R"CONFIG( |
| 157 | face_system |
| 158 | { |
| 159 | ether |
| 160 | { |
| 161 | listen no |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 162 | mcast yes |
| 163 | mcast_group 01:00:5E:00:17:AA |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 164 | mcast_ad_hoc no |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 165 | whitelist |
| 166 | { |
| 167 | * |
| 168 | } |
| 169 | blacklist |
| 170 | { |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | )CONFIG"; |
| 175 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 176 | parseConfig(CONFIG, true); |
| 177 | parseConfig(CONFIG, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 178 | |
| 179 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size()); |
| 180 | } |
| 181 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 182 | BOOST_AUTO_TEST_CASE(EnableDisableMcast) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 183 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 184 | const std::string CONFIG_WITH_MCAST = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 185 | face_system |
| 186 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 187 | ether |
| 188 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 189 | listen no |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 190 | mcast yes |
| 191 | } |
| 192 | } |
| 193 | )CONFIG"; |
| 194 | const std::string CONFIG_WITHOUT_MCAST = R"CONFIG( |
| 195 | face_system |
| 196 | { |
| 197 | ether |
| 198 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 199 | listen no |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 200 | mcast no |
| 201 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 202 | } |
| 203 | )CONFIG"; |
| 204 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 205 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 207 | |
| 208 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 209 | |
| 210 | parseConfig(CONFIG_WITH_MCAST, false); |
| 211 | g_io.poll(); |
| 212 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size()); |
| 213 | |
| 214 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
| 215 | g_io.poll(); |
| 216 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
| 217 | } |
| 218 | |
| 219 | BOOST_AUTO_TEST_CASE(McastAdHoc) |
| 220 | { |
| 221 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 222 | |
| 223 | const std::string CONFIG = R"CONFIG( |
| 224 | face_system |
| 225 | { |
| 226 | ether |
| 227 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 228 | listen no |
| 229 | mcast yes |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 230 | mcast_ad_hoc yes |
| 231 | } |
| 232 | } |
| 233 | )CONFIG"; |
| 234 | |
| 235 | parseConfig(CONFIG, false); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_MULTI_ACCESS), 0); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_AD_HOC), netifs.size()); |
| 238 | } |
| 239 | |
| 240 | BOOST_AUTO_TEST_CASE(ChangeMcastGroup) |
| 241 | { |
| 242 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 243 | |
| 244 | const std::string CONFIG1 = R"CONFIG( |
| 245 | face_system |
| 246 | { |
| 247 | ether |
| 248 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 249 | mcast_group 01:00:5e:90:10:01 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | )CONFIG"; |
| 253 | const std::string CONFIG2 = R"CONFIG( |
| 254 | face_system |
| 255 | { |
| 256 | ether |
| 257 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 258 | mcast_group 01:00:5e:90:10:02 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | )CONFIG"; |
| 262 | |
| 263 | parseConfig(CONFIG1, false); |
| 264 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 265 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 266 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 267 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x01})); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 268 | |
| 269 | parseConfig(CONFIG2, false); |
| 270 | g_io.poll(); |
| 271 | etherMcastFaces = this->listEtherMcastFaces(); |
| 272 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 273 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 274 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x02})); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(Whitelist) |
| 278 | { |
| 279 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 280 | |
| 281 | std::string CONFIG = R"CONFIG( |
| 282 | face_system |
| 283 | { |
| 284 | ether |
| 285 | { |
| 286 | whitelist |
| 287 | { |
| 288 | ifname %ifname |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | )CONFIG"; |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 293 | auto ifname = netifs.front()->getName(); |
| 294 | boost::replace_first(CONFIG, "%ifname", ifname); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 295 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 296 | parseConfig(CONFIG, false); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 297 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 298 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 299 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), 1); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 300 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getLocalUri(), FaceUri::fromDev(ifname)); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | BOOST_AUTO_TEST_CASE(Blacklist) |
| 304 | { |
| 305 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 306 | |
| 307 | std::string CONFIG = R"CONFIG( |
| 308 | face_system |
| 309 | { |
| 310 | ether |
| 311 | { |
| 312 | blacklist |
| 313 | { |
| 314 | ifname %ifname |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | )CONFIG"; |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 319 | auto ifname = netifs.front()->getName(); |
| 320 | boost::replace_first(CONFIG, "%ifname", ifname); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 321 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 322 | parseConfig(CONFIG, false); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 323 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 324 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 325 | BOOST_CHECK_EQUAL(etherMcastFaces.size(), netifs.size() - 1); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(boost::count_if(etherMcastFaces, [ifname] (const Face* face) { |
| 327 | return face->getLocalUri() == FaceUri::fromDev(ifname); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 328 | }), 0); |
| 329 | } |
| 330 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 331 | BOOST_AUTO_TEST_CASE(Omitted) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 332 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 333 | const std::string CONFIG = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 334 | face_system |
| 335 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 336 | } |
| 337 | )CONFIG"; |
| 338 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 339 | parseConfig(CONFIG, true); |
| 340 | parseConfig(CONFIG, false); |
| 341 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 346 | { |
| 347 | const std::string CONFIG = R"CONFIG( |
| 348 | face_system |
| 349 | { |
| 350 | ether |
| 351 | { |
| 352 | mcast hello |
| 353 | } |
| 354 | } |
| 355 | )CONFIG"; |
| 356 | |
| 357 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 358 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 359 | } |
| 360 | |
| 361 | BOOST_AUTO_TEST_CASE(BadMcastGroup) |
| 362 | { |
| 363 | const std::string CONFIG = R"CONFIG( |
| 364 | face_system |
| 365 | { |
| 366 | ether |
| 367 | { |
| 368 | mcast yes |
| 369 | mcast_group hello |
| 370 | } |
| 371 | } |
| 372 | )CONFIG"; |
| 373 | |
| 374 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 375 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 376 | } |
| 377 | |
| 378 | BOOST_AUTO_TEST_CASE(UnicastMcastGroup) |
| 379 | { |
| 380 | const std::string CONFIG = R"CONFIG( |
| 381 | face_system |
| 382 | { |
| 383 | ether |
| 384 | { |
| 385 | mcast yes |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 386 | mcast_group 00:00:5e:00:53:5e |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | )CONFIG"; |
| 390 | |
| 391 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 392 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 393 | } |
| 394 | |
| 395 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 396 | { |
| 397 | const std::string CONFIG = R"CONFIG( |
| 398 | face_system |
| 399 | { |
| 400 | ether |
| 401 | { |
| 402 | hello |
| 403 | } |
| 404 | } |
| 405 | )CONFIG"; |
| 406 | |
| 407 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 408 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 409 | } |
| 410 | |
| 411 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 412 | |
| 413 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 414 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
| 416 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 417 | |
| 418 | factory.createChannel(netifs.front(), time::minutes(1)); |
| 419 | checkChannelListEqual(factory, {FaceUri::fromDev(netifs.front()->getName()).toString()}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 422 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 423 | { |
| 424 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 425 | |
| 426 | auto channel1 = factory.createChannel(netifs.front(), time::minutes(1)); |
| 427 | auto channel1a = factory.createChannel(netifs.front(), time::minutes(5)); |
| 428 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 429 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "dev://" + netifs.front()->getName()); |
| 430 | |
| 431 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(2); |
| 432 | |
| 433 | auto channel2 = factory.createChannel(netifs.back(), time::minutes(1)); |
| 434 | BOOST_CHECK_NE(channel1, channel2); |
| 435 | } |
| 436 | |
| 437 | BOOST_AUTO_TEST_CASE(CreateFace) |
| 438 | { |
| 439 | createFace(factory, |
| 440 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 441 | FaceUri("dev://eth0"), |
| 442 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 443 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 444 | false, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 445 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
| 446 | |
| 447 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 448 | auto localUri = factory.createChannel(netifs.front(), time::minutes(1))->getUri(); |
| 449 | |
| 450 | createFace(factory, |
| 451 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 452 | localUri, |
| 453 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 454 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 455 | false, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 456 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 457 | |
| 458 | createFace(factory, |
| 459 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 460 | localUri, |
| 461 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 462 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 463 | false, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 464 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 465 | |
| 466 | createFace(factory, |
| 467 | FaceUri("ether://[00:00:5e:00:53:53]"), |
| 468 | localUri, |
| 469 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 470 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 471 | false, |
| 472 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 473 | |
| 474 | createFace(factory, |
| 475 | FaceUri("ether://[00:00:5e:00:53:57]"), |
| 476 | localUri, |
| 477 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 478 | false, |
| 479 | true, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 480 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 481 | } |
| 482 | |
| 483 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 484 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 485 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 486 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 487 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 488 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 489 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 490 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 491 | {CreateFaceExpectedResult::FAILURE, 406, |
| 492 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 493 | |
| 494 | createFace(factory, |
| 495 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 496 | FaceUri("udp4://127.0.0.1:20071"), |
| 497 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 498 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 499 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 500 | {CreateFaceExpectedResult::FAILURE, 406, |
| 501 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 502 | |
| 503 | createFace(factory, |
| 504 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 505 | FaceUri("dev://eth0"), |
| 506 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
| 507 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 508 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 509 | {CreateFaceExpectedResult::FAILURE, 406, |
| 510 | "Outgoing Ethernet faces do not support on-demand persistency"}); |
| 511 | |
| 512 | createFace(factory, |
| 513 | FaceUri("ether://[01:00:5e:90:10:5e]"), |
| 514 | FaceUri("dev://eth0"), |
| 515 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 516 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 517 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 518 | {CreateFaceExpectedResult::FAILURE, 406, |
| 519 | "Cannot create multicast Ethernet faces"}); |
| 520 | |
| 521 | createFace(factory, |
| 522 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 523 | FaceUri("dev://eth0"), |
| 524 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 525 | true, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 526 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 527 | {CreateFaceExpectedResult::FAILURE, 406, |
| 528 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory |
| 532 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 533 | |
| 534 | } // namespace tests |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 535 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 536 | } // namespace nfd |