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