susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 2 | /* |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [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 "core/network-interface-predicate.hpp" |
| 27 | #include "core/network-interface.hpp" |
| 28 | |
| 29 | #include "tests/test-common.hpp" |
| 30 | |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 31 | #include <ndn-cxx/net/network-monitor-stub.hpp> |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 32 | #include <boost/property_tree/info_parser.hpp> |
| 33 | #include <sstream> |
| 34 | |
| 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | class NetworkInterfacePredicateFixture : public BaseFixture |
| 39 | { |
| 40 | protected: |
| 41 | NetworkInterfacePredicateFixture() |
| 42 | { |
| 43 | using namespace boost::asio::ip; |
| 44 | interfaces.push_back( |
| 45 | NetworkInterfaceInfo{0, "eth0", |
| 46 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 47 | {address_v4::from_string("129.82.100.1")}, |
| 48 | {}, |
| 49 | address_v4::from_string("129.82.255.255"), |
| 50 | IFF_UP}); |
| 51 | interfaces.push_back( |
| 52 | NetworkInterfaceInfo{1, "eth1", |
| 53 | ethernet::Address::fromString("3e:15:c2:8b:65:01"), |
| 54 | {address_v4::from_string("192.168.2.1")}, |
| 55 | {}, |
| 56 | address_v4::from_string("192.168.2.255"), |
| 57 | IFF_UP}); |
| 58 | interfaces.push_back( |
| 59 | NetworkInterfaceInfo{2, "eth2", |
| 60 | ethernet::Address::fromString("3e:15:c2:8b:65:02"), |
| 61 | {address_v4::from_string("198.51.100.1")}, |
| 62 | {address_v6::from_string("2001:db8::1")}, |
| 63 | address_v4::from_string("198.51.100.255"), |
| 64 | IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 65 | interfaces.push_back( |
| 66 | NetworkInterfaceInfo{3, "enp68s0f1", |
| 67 | ethernet::Address::fromString("3e:15:c2:8b:65:03"), |
| 68 | {address_v4::from_string("192.168.2.3")}, |
| 69 | {}, |
| 70 | address_v4::from_string("192.168.2.255"), |
| 71 | IFF_UP}); |
| 72 | |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 73 | using namespace ndn::net; |
| 74 | |
| 75 | netifs.push_back(NetworkMonitorStub::makeNetworkInterface()); |
| 76 | netifs.back()->setIndex(0); |
| 77 | netifs.back()->setName("eth0"); |
| 78 | netifs.back()->setEthernetAddress(ethernet::Address::fromString("3e:15:c2:8b:65:00")); |
| 79 | netifs.back()->addNetworkAddress(NetworkAddress(AddressFamily::V4, |
| 80 | address_v4::from_string("129.82.100.1"), address_v4::from_string("129.82.255.255"), |
| 81 | 16, AddressScope::GLOBAL, 0)); |
| 82 | netifs.back()->setFlags(IFF_UP); |
| 83 | |
| 84 | netifs.push_back(NetworkMonitorStub::makeNetworkInterface()); |
| 85 | netifs.back()->setIndex(1); |
| 86 | netifs.back()->setName("eth1"); |
| 87 | netifs.back()->setEthernetAddress(ethernet::Address::fromString("3e:15:c2:8b:65:01")); |
| 88 | netifs.back()->addNetworkAddress(NetworkAddress(AddressFamily::V4, |
| 89 | address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.255"), |
| 90 | 24, AddressScope::GLOBAL, 0)); |
| 91 | netifs.back()->setFlags(IFF_UP); |
| 92 | |
| 93 | netifs.push_back(NetworkMonitorStub::makeNetworkInterface()); |
| 94 | netifs.back()->setIndex(2); |
| 95 | netifs.back()->setName("eth2"); |
| 96 | netifs.back()->setEthernetAddress(ethernet::Address::fromString("3e:15:c2:8b:65:02")); |
| 97 | netifs.back()->addNetworkAddress(NetworkAddress(AddressFamily::V4, |
| 98 | address_v4::from_string("198.51.100.1"), address_v4::from_string("198.51.100.255"), |
| 99 | 24, AddressScope::GLOBAL, 0)); |
| 100 | netifs.back()->addNetworkAddress(NetworkAddress(AddressFamily::V6, |
| 101 | address_v6::from_string("2001:db8::1"), address_v6::from_string("2001:db8::ffff"), |
| 102 | 112, AddressScope::GLOBAL, 0)); |
| 103 | netifs.back()->setFlags(IFF_MULTICAST | IFF_BROADCAST | IFF_UP); |
| 104 | |
| 105 | netifs.push_back(NetworkMonitorStub::makeNetworkInterface()); |
| 106 | netifs.back()->setIndex(3); |
| 107 | netifs.back()->setName("enp68s0f1"); |
| 108 | netifs.back()->setEthernetAddress(ethernet::Address::fromString("3e:15:c2:8b:65:03")); |
| 109 | netifs.back()->addNetworkAddress(NetworkAddress(AddressFamily::V4, |
| 110 | address_v4::from_string("192.168.2.3"), address_v4::from_string("192.168.2.255"), |
| 111 | 24, AddressScope::GLOBAL, 0)); |
| 112 | netifs.back()->setFlags(IFF_UP); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void |
| 116 | parseConfig(const std::string& config) |
| 117 | { |
| 118 | std::istringstream input(config); |
| 119 | boost::property_tree::ptree ptree; |
| 120 | boost::property_tree::read_info(input, ptree); |
| 121 | |
| 122 | for (const auto& i : ptree) { |
| 123 | if (i.first == "whitelist") { |
| 124 | predicate.parseWhitelist(i.second); |
| 125 | } |
| 126 | else if (i.first == "blacklist") { |
| 127 | predicate.parseBlacklist(i.second); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | protected: |
| 133 | NetworkInterfacePredicate predicate; |
| 134 | std::vector<NetworkInterfaceInfo> interfaces; |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 135 | std::vector<shared_ptr<ndn::net::NetworkInterface>> netifs; |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | BOOST_FIXTURE_TEST_SUITE(TestNetworkInterfacePredicate, NetworkInterfacePredicateFixture) |
| 139 | |
| 140 | BOOST_AUTO_TEST_CASE(Default) |
| 141 | { |
| 142 | parseConfig(""); |
| 143 | |
| 144 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 145 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 146 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 147 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 148 | |
| 149 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 150 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 151 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 152 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | BOOST_AUTO_TEST_CASE(EmptyWhitelist) |
| 156 | { |
| 157 | parseConfig("whitelist\n" |
| 158 | "{\n" |
| 159 | "}"); |
| 160 | |
| 161 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 162 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 163 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 164 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 165 | |
| 166 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 167 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 168 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 169 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | BOOST_AUTO_TEST_CASE(WildcardBlacklist) |
| 173 | { |
| 174 | parseConfig("blacklist\n" |
| 175 | "{\n" |
| 176 | " *\n" |
| 177 | "}"); |
| 178 | |
| 179 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 180 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 181 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 183 | |
| 184 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 185 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 186 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 187 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | BOOST_AUTO_TEST_CASE(IfnameWhitelist) |
| 191 | { |
| 192 | parseConfig("whitelist\n" |
| 193 | "{\n" |
| 194 | " ifname eth0\n" |
| 195 | " ifname eth1\n" |
| 196 | "}"); |
| 197 | |
| 198 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 199 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 200 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 202 | |
| 203 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 204 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 205 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 206 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | BOOST_AUTO_TEST_CASE(IfnameBlacklist) |
| 210 | { |
| 211 | parseConfig("blacklist\n" |
| 212 | "{\n" |
| 213 | " ifname eth0\n" |
| 214 | " ifname eth1\n" |
| 215 | "}"); |
| 216 | |
| 217 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 218 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 219 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 220 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 221 | |
| 222 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 223 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 224 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 225 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | BOOST_AUTO_TEST_CASE(IfnameWildcardStart) |
| 229 | { |
| 230 | parseConfig("whitelist\n" |
| 231 | "{\n" |
| 232 | " ifname enp*\n" |
| 233 | "}"); |
| 234 | |
| 235 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 236 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 237 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
| 238 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 239 | |
| 240 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 241 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 242 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 243 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(IfnameWildcardMiddle) |
| 247 | { |
| 248 | parseConfig("whitelist\n" |
| 249 | "{\n" |
| 250 | " ifname *th*\n" |
| 251 | "}"); |
| 252 | |
| 253 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 254 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 255 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
| 256 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 257 | |
| 258 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 259 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 260 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 261 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | BOOST_AUTO_TEST_CASE(IfnameWildcardDouble) |
| 265 | { |
| 266 | parseConfig("whitelist\n" |
| 267 | "{\n" |
| 268 | " ifname eth**\n" |
| 269 | "}"); |
| 270 | |
| 271 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 272 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 273 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
| 274 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 275 | |
| 276 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 277 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 278 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 279 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | BOOST_AUTO_TEST_CASE(IfnameWildcardOnly) |
| 283 | { |
| 284 | parseConfig("whitelist\n" |
| 285 | "{\n" |
| 286 | " ifname *\n" |
| 287 | "}"); |
| 288 | |
| 289 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 290 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 291 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
| 292 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 293 | |
| 294 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 295 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 296 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 297 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | BOOST_AUTO_TEST_CASE(IfnameQuestionMark) |
| 301 | { |
| 302 | parseConfig("whitelist\n" |
| 303 | "{\n" |
| 304 | " ifname eth?\n" |
| 305 | "}"); |
| 306 | |
| 307 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 308 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 309 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
| 310 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 311 | |
| 312 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 313 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 314 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 315 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | BOOST_AUTO_TEST_CASE(IfnameMalformed) |
| 319 | { |
| 320 | BOOST_CHECK_THROW( |
| 321 | parseConfig("whitelist\n" |
| 322 | "{\n" |
| 323 | " ifname\n" |
| 324 | "}"), |
| 325 | ConfigFile::Error); |
| 326 | } |
| 327 | |
| 328 | BOOST_AUTO_TEST_CASE(EtherWhitelist) |
| 329 | { |
| 330 | parseConfig("whitelist\n" |
| 331 | "{\n" |
| 332 | " ether 3e:15:c2:8b:65:00\n" |
| 333 | " ether 3e:15:c2:8b:65:01\n" |
| 334 | "}"); |
| 335 | |
| 336 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 337 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 338 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 340 | |
| 341 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 342 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 343 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 344 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | BOOST_AUTO_TEST_CASE(EtherBlacklist) |
| 348 | { |
| 349 | parseConfig("blacklist\n" |
| 350 | "{\n" |
| 351 | " ether 3e:15:c2:8b:65:00\n" |
| 352 | " ether 3e:15:c2:8b:65:01\n" |
| 353 | "}"); |
| 354 | |
| 355 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 356 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 357 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 358 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 359 | |
| 360 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 361 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 362 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 363 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | BOOST_AUTO_TEST_CASE(EtherMalformed) |
| 367 | { |
| 368 | BOOST_CHECK_THROW( |
| 369 | parseConfig("blacklist\n" |
| 370 | "{\n" |
| 371 | " ether foo\n" |
| 372 | "}"), |
| 373 | ConfigFile::Error); |
| 374 | } |
| 375 | |
| 376 | BOOST_AUTO_TEST_CASE(SubnetWhitelist) |
| 377 | { |
| 378 | parseConfig("whitelist\n" |
| 379 | "{\n" |
| 380 | " subnet 192.168.0.0/16\n" |
| 381 | "}"); |
| 382 | |
| 383 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), false); |
| 384 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), true); |
| 385 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), false); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 386 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), true); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 387 | |
| 388 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), false); |
| 389 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), true); |
| 390 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), false); |
| 391 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), true); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | BOOST_AUTO_TEST_CASE(SubnetBlacklist) |
| 395 | { |
| 396 | parseConfig("blacklist\n" |
| 397 | "{\n" |
| 398 | " subnet 192.168.0.0/16\n" |
| 399 | "}"); |
| 400 | |
| 401 | BOOST_CHECK_EQUAL(predicate(interfaces[0]), true); |
| 402 | BOOST_CHECK_EQUAL(predicate(interfaces[1]), false); |
| 403 | BOOST_CHECK_EQUAL(predicate(interfaces[2]), true); |
susmit | 21f22e6 | 2017-03-25 15:44:45 -0500 | [diff] [blame] | 404 | BOOST_CHECK_EQUAL(predicate(interfaces[3]), false); |
Junxiao Shi | 2760adc | 2017-07-06 05:44:52 +0000 | [diff] [blame^] | 405 | |
| 406 | BOOST_CHECK_EQUAL(predicate(*netifs[0]), true); |
| 407 | BOOST_CHECK_EQUAL(predicate(*netifs[1]), false); |
| 408 | BOOST_CHECK_EQUAL(predicate(*netifs[2]), true); |
| 409 | BOOST_CHECK_EQUAL(predicate(*netifs[3]), false); |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | BOOST_AUTO_TEST_CASE(SubnetMalformed) |
| 413 | { |
| 414 | BOOST_CHECK_THROW( |
| 415 | parseConfig("blacklist\n" |
| 416 | "{\n" |
| 417 | " subnet 266.0.0.91/\n" |
| 418 | "}"), |
| 419 | ConfigFile::Error); |
| 420 | } |
| 421 | |
| 422 | BOOST_AUTO_TEST_SUITE_END() // TestNetworkInterfacePredicate |
| 423 | |
| 424 | } // namespace tests |
| 425 | } // namespace nfd |