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