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 | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, 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 | |
| 34 | namespace nfd { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 35 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 36 | namespace tests { |
| 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()); |
| 154 | } |
| 155 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 156 | BOOST_AUTO_TEST_CASE(EnableDisableMcast) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 157 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 158 | const std::string CONFIG_WITH_MCAST = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 159 | face_system |
| 160 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 161 | ether |
| 162 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 163 | listen no |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 164 | mcast yes |
| 165 | } |
| 166 | } |
| 167 | )CONFIG"; |
| 168 | const std::string CONFIG_WITHOUT_MCAST = R"CONFIG( |
| 169 | face_system |
| 170 | { |
| 171 | ether |
| 172 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 173 | listen no |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 174 | mcast no |
| 175 | } |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 176 | } |
| 177 | )CONFIG"; |
| 178 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 179 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 180 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 181 | |
| 182 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 183 | |
| 184 | parseConfig(CONFIG_WITH_MCAST, false); |
| 185 | g_io.poll(); |
| 186 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), netifs.size()); |
| 187 | |
| 188 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
| 189 | g_io.poll(); |
| 190 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
| 191 | } |
| 192 | |
| 193 | BOOST_AUTO_TEST_CASE(McastAdHoc) |
| 194 | { |
| 195 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 196 | |
| 197 | const std::string CONFIG = R"CONFIG( |
| 198 | face_system |
| 199 | { |
| 200 | ether |
| 201 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 202 | listen no |
| 203 | mcast yes |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 204 | mcast_ad_hoc yes |
| 205 | } |
| 206 | } |
| 207 | )CONFIG"; |
| 208 | |
| 209 | parseConfig(CONFIG, false); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 210 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_MULTI_ACCESS), 0); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(ndn::nfd::LINK_TYPE_AD_HOC), netifs.size()); |
| 212 | } |
| 213 | |
| 214 | BOOST_AUTO_TEST_CASE(ChangeMcastGroup) |
| 215 | { |
| 216 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 217 | |
| 218 | const std::string CONFIG1 = R"CONFIG( |
| 219 | face_system |
| 220 | { |
| 221 | ether |
| 222 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 223 | mcast_group 01:00:5e:90:10:01 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | )CONFIG"; |
| 227 | const std::string CONFIG2 = R"CONFIG( |
| 228 | face_system |
| 229 | { |
| 230 | ether |
| 231 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 232 | mcast_group 01:00:5e:90:10:02 |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | )CONFIG"; |
| 236 | |
| 237 | parseConfig(CONFIG1, false); |
| 238 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 239 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 240 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 241 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x01})); |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 242 | |
| 243 | parseConfig(CONFIG2, false); |
| 244 | g_io.poll(); |
| 245 | etherMcastFaces = this->listEtherMcastFaces(); |
| 246 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), netifs.size()); |
| 247 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getRemoteUri(), |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 248 | FaceUri(ethernet::Address{0x01, 0x00, 0x5e, 0x90, 0x10, 0x02})); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | BOOST_AUTO_TEST_CASE(Whitelist) |
| 252 | { |
| 253 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 254 | |
| 255 | std::string CONFIG = R"CONFIG( |
| 256 | face_system |
| 257 | { |
| 258 | ether |
| 259 | { |
| 260 | whitelist |
| 261 | { |
| 262 | ifname %ifname |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | )CONFIG"; |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 267 | auto ifname = netifs.front()->getName(); |
| 268 | boost::replace_first(CONFIG, "%ifname", ifname); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 269 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 270 | parseConfig(CONFIG, false); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 271 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 272 | auto etherMcastFaces = this->listEtherMcastFaces(); |
| 273 | BOOST_REQUIRE_EQUAL(etherMcastFaces.size(), 1); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(etherMcastFaces.front()->getLocalUri(), FaceUri::fromDev(ifname)); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(Blacklist) |
| 278 | { |
| 279 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 280 | |
| 281 | std::string CONFIG = R"CONFIG( |
| 282 | face_system |
| 283 | { |
| 284 | ether |
| 285 | { |
| 286 | blacklist |
| 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_CHECK_EQUAL(etherMcastFaces.size(), netifs.size() - 1); |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 300 | BOOST_CHECK(std::none_of(etherMcastFaces.begin(), etherMcastFaces.end(), |
| 301 | [ifname] (const nfd::Face* face) { |
| 302 | return face->getLocalUri() == FaceUri::fromDev(ifname); |
| 303 | } |
| 304 | )); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 307 | BOOST_AUTO_TEST_CASE(Omitted) |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 308 | { |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 309 | const std::string CONFIG = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 310 | face_system |
| 311 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 312 | } |
| 313 | )CONFIG"; |
| 314 | |
Teng Liang | bfea575 | 2017-03-29 04:51:10 +0000 | [diff] [blame] | 315 | parseConfig(CONFIG, true); |
| 316 | parseConfig(CONFIG, false); |
| 317 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 318 | BOOST_CHECK_EQUAL(this->countEtherMcastFaces(), 0); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 321 | BOOST_AUTO_TEST_CASE(BadListen) |
| 322 | { |
| 323 | const std::string CONFIG = R"CONFIG( |
| 324 | face_system |
| 325 | { |
| 326 | ether |
| 327 | { |
| 328 | listen hello |
| 329 | } |
| 330 | } |
| 331 | )CONFIG"; |
| 332 | |
| 333 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 334 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 335 | } |
| 336 | |
| 337 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BadIdleTimeout, 2) // Bug #4489 |
| 338 | BOOST_AUTO_TEST_CASE(BadIdleTimeout) |
| 339 | { |
| 340 | // not a number |
| 341 | const std::string CONFIG1 = R"CONFIG( |
| 342 | face_system |
| 343 | { |
| 344 | ether |
| 345 | { |
| 346 | idle_timeout hello |
| 347 | } |
| 348 | } |
| 349 | )CONFIG"; |
| 350 | |
| 351 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 352 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 353 | |
| 354 | // negative number |
| 355 | const std::string CONFIG2 = R"CONFIG( |
| 356 | face_system |
| 357 | { |
| 358 | ether |
| 359 | { |
| 360 | idle_timeout -15 |
| 361 | } |
| 362 | } |
| 363 | )CONFIG"; |
| 364 | |
| 365 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 366 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 367 | } |
| 368 | |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 369 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 370 | { |
| 371 | const std::string CONFIG = R"CONFIG( |
| 372 | face_system |
| 373 | { |
| 374 | ether |
| 375 | { |
| 376 | mcast hello |
| 377 | } |
| 378 | } |
| 379 | )CONFIG"; |
| 380 | |
| 381 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 382 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 383 | } |
| 384 | |
| 385 | BOOST_AUTO_TEST_CASE(BadMcastGroup) |
| 386 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 387 | // not an address |
| 388 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 389 | face_system |
| 390 | { |
| 391 | ether |
| 392 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 393 | mcast_group hello |
| 394 | } |
| 395 | } |
| 396 | )CONFIG"; |
| 397 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 398 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 399 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 400 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 401 | // non-multicast address |
| 402 | const std::string CONFIG2 = R"CONFIG( |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 403 | face_system |
| 404 | { |
| 405 | ether |
| 406 | { |
Davide Pesavento | 43ff2a9 | 2017-05-18 19:50:57 -0400 | [diff] [blame] | 407 | mcast_group 00:00:5e:00:53:5e |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | )CONFIG"; |
| 411 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 412 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 413 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 417 | { |
| 418 | const std::string CONFIG = R"CONFIG( |
| 419 | face_system |
| 420 | { |
| 421 | ether |
| 422 | { |
| 423 | hello |
| 424 | } |
| 425 | } |
| 426 | )CONFIG"; |
| 427 | |
| 428 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 429 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 430 | } |
| 431 | |
| 432 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 433 | |
| 434 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 435 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
| 437 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 438 | |
| 439 | factory.createChannel(netifs.front(), time::minutes(1)); |
| 440 | checkChannelListEqual(factory, {FaceUri::fromDev(netifs.front()->getName()).toString()}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 443 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 444 | { |
| 445 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 446 | |
| 447 | auto channel1 = factory.createChannel(netifs.front(), time::minutes(1)); |
| 448 | auto channel1a = factory.createChannel(netifs.front(), time::minutes(5)); |
| 449 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 450 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "dev://" + netifs.front()->getName()); |
| 451 | |
| 452 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(2); |
| 453 | |
| 454 | auto channel2 = factory.createChannel(netifs.back(), time::minutes(1)); |
| 455 | BOOST_CHECK_NE(channel1, channel2); |
| 456 | } |
| 457 | |
| 458 | BOOST_AUTO_TEST_CASE(CreateFace) |
| 459 | { |
| 460 | createFace(factory, |
| 461 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 462 | FaceUri("dev://eth0"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 463 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 464 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
| 465 | |
| 466 | SKIP_IF_ETHERNET_NETIF_COUNT_LT(1); |
| 467 | auto localUri = factory.createChannel(netifs.front(), time::minutes(1))->getUri(); |
| 468 | |
| 469 | createFace(factory, |
| 470 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 471 | localUri, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 472 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 473 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 474 | |
| 475 | createFace(factory, |
| 476 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 477 | localUri, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 478 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 479 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 480 | |
| 481 | createFace(factory, |
| 482 | FaceUri("ether://[00:00:5e:00:53:53]"), |
| 483 | localUri, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 484 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 485 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 486 | |
| 487 | createFace(factory, |
| 488 | FaceUri("ether://[00:00:5e:00:53:57]"), |
| 489 | localUri, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 490 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, true, false}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 491 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 492 | |
| 493 | createFace(factory, |
| 494 | FaceUri("ether://[00:00:5e:00:53:5b]"), |
| 495 | localUri, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 496 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, true}, |
| 497 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 498 | |
| 499 | createFace(factory, |
| 500 | FaceUri("ether://[00:00:5e:00:53:5c]"), |
| 501 | localUri, |
| 502 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, 1000, false, false, false}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 503 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 504 | } |
| 505 | |
| 506 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 507 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 508 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 509 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 510 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 511 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 512 | {CreateFaceExpectedResult::FAILURE, 406, |
| 513 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 514 | |
| 515 | createFace(factory, |
| 516 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 517 | FaceUri("udp4://127.0.0.1:20071"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 518 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 519 | {CreateFaceExpectedResult::FAILURE, 406, |
| 520 | "Creation of unicast Ethernet faces requires a LocalUri with dev:// scheme"}); |
| 521 | |
| 522 | createFace(factory, |
| 523 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 524 | FaceUri("dev://eth0"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 525 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 526 | {CreateFaceExpectedResult::FAILURE, 406, |
| 527 | "Outgoing Ethernet faces do not support on-demand persistency"}); |
| 528 | |
| 529 | createFace(factory, |
| 530 | FaceUri("ether://[01:00:5e:90:10:5e]"), |
| 531 | FaceUri("dev://eth0"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 532 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 533 | {CreateFaceExpectedResult::FAILURE, 406, |
| 534 | "Cannot create multicast Ethernet faces"}); |
| 535 | |
| 536 | createFace(factory, |
| 537 | FaceUri("ether://[00:00:5e:00:53:5e]"), |
| 538 | FaceUri("dev://eth0"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 539 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 540 | {CreateFaceExpectedResult::FAILURE, 406, |
| 541 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | BOOST_AUTO_TEST_SUITE_END() // TestEthernetFactory |
| 545 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 546 | |
| 547 | } // namespace tests |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame] | 548 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 549 | } // namespace nfd |