Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -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 "mgmt/face-manager.hpp" |
| 27 | #include "face/udp-factory.hpp" |
| 28 | |
| 29 | #ifdef HAVE_LIBPCAP |
| 30 | #include "face/ethernet-factory.hpp" |
| 31 | #endif // HAVE_LIBPCAP |
| 32 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 33 | #include "nfd-manager-common-fixture.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 39 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 40 | |
Yanbiao Li | df846e5 | 2016-01-30 21:53:47 -0800 | [diff] [blame] | 41 | class FaceManagerProcessConfigFixture : public NfdManagerCommonFixture |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 42 | { |
| 43 | public: |
| 44 | FaceManagerProcessConfigFixture() |
Junxiao Shi | 9ddf1b5 | 2016-08-22 03:58:55 +0000 | [diff] [blame] | 45 | : m_manager(m_forwarder.getFaceTable(), m_dispatcher, *m_authenticator) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 46 | { |
| 47 | m_manager.setConfigFile(m_config); |
| 48 | } |
| 49 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 50 | void |
| 51 | parseConfig(const std::string& type, bool isDryRun) |
| 52 | { |
| 53 | m_config.parse(type, isDryRun, "test-config"); |
| 54 | } |
| 55 | |
| 56 | protected: |
| 57 | FaceManager m_manager; |
| 58 | ConfigFile m_config; |
| 59 | }; |
| 60 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 61 | BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture) |
| 62 | |
| 63 | #ifdef HAVE_UNIX_SOCKETS |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE(ProcessSectionUnix) |
| 66 | { |
| 67 | const std::string CONFIG = |
| 68 | "face_system\n" |
| 69 | "{\n" |
| 70 | " unix\n" |
| 71 | " {\n" |
| 72 | " path /tmp/nfd.sock\n" |
| 73 | " }\n" |
| 74 | "}\n"; |
| 75 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 76 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 77 | } |
| 78 | |
| 79 | BOOST_AUTO_TEST_CASE(ProcessSectionUnixUnknownOption) |
| 80 | { |
| 81 | const std::string CONFIG = |
| 82 | "face_system\n" |
| 83 | "{\n" |
| 84 | " unix\n" |
| 85 | " {\n" |
| 86 | " hello\n" |
| 87 | " }\n" |
| 88 | "}\n"; |
| 89 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 90 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 91 | } |
| 92 | |
| 93 | #endif // HAVE_UNIX_SOCKETS |
| 94 | |
| 95 | BOOST_AUTO_TEST_CASE(ProcessSectionTcp) |
| 96 | { |
| 97 | const std::string CONFIG = |
| 98 | "face_system\n" |
| 99 | "{\n" |
| 100 | " tcp\n" |
| 101 | " {\n" |
| 102 | " listen yes\n" |
| 103 | " port 16363\n" |
| 104 | " enable_v4 yes\n" |
| 105 | " enable_v6 yes\n" |
| 106 | " }\n" |
| 107 | "}\n"; |
| 108 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 109 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 110 | } |
| 111 | |
| 112 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpBadListen) |
| 113 | { |
| 114 | const std::string CONFIG = |
| 115 | "face_system\n" |
| 116 | "{\n" |
| 117 | " tcp\n" |
| 118 | " {\n" |
| 119 | " listen hello\n" |
| 120 | " }\n" |
| 121 | "}\n"; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 122 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 123 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpChannelsDisabled) |
| 127 | { |
| 128 | const std::string CONFIG = |
| 129 | "face_system\n" |
| 130 | "{\n" |
| 131 | " tcp\n" |
| 132 | " {\n" |
| 133 | " port 6363\n" |
| 134 | " enable_v4 no\n" |
| 135 | " enable_v6 no\n" |
| 136 | " }\n" |
| 137 | "}\n"; |
| 138 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 139 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpUnknownOption) |
| 143 | { |
| 144 | const std::string CONFIG = |
| 145 | "face_system\n" |
| 146 | "{\n" |
| 147 | " tcp\n" |
| 148 | " {\n" |
| 149 | " hello\n" |
| 150 | " }\n" |
| 151 | "}\n"; |
| 152 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 153 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 154 | } |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(ProcessSectionUdp) |
| 157 | { |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 158 | SKIP_IF_NOT_SUPERUSER(); |
| 159 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 160 | const std::string CONFIG = |
| 161 | "face_system\n" |
| 162 | "{\n" |
| 163 | " udp\n" |
| 164 | " {\n" |
| 165 | " port 6363\n" |
| 166 | " enable_v4 yes\n" |
| 167 | " enable_v6 yes\n" |
| 168 | " idle_timeout 30\n" |
| 169 | " keep_alive_interval 25\n" |
| 170 | " mcast yes\n" |
| 171 | " mcast_port 56363\n" |
| 172 | " mcast_group 224.0.23.170\n" |
| 173 | " }\n" |
| 174 | "}\n"; |
| 175 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 176 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadIdleTimeout) |
| 180 | { |
| 181 | const std::string CONFIG = |
| 182 | "face_system\n" |
| 183 | "{\n" |
| 184 | " udp\n" |
| 185 | " {\n" |
| 186 | " idle_timeout hello\n" |
| 187 | " }\n" |
| 188 | "}\n"; |
| 189 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 190 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 191 | } |
| 192 | |
| 193 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcast) |
| 194 | { |
| 195 | const std::string CONFIG = |
| 196 | "face_system\n" |
| 197 | "{\n" |
| 198 | " udp\n" |
| 199 | " {\n" |
| 200 | " mcast hello\n" |
| 201 | " }\n" |
| 202 | "}\n"; |
| 203 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 204 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 205 | } |
| 206 | |
| 207 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroup) |
| 208 | { |
| 209 | const std::string CONFIG = |
| 210 | "face_system\n" |
| 211 | "{\n" |
| 212 | " udp\n" |
| 213 | " {\n" |
| 214 | " mcast no\n" |
| 215 | " mcast_port 50\n" |
| 216 | " mcast_group hello\n" |
| 217 | " }\n" |
| 218 | "}\n"; |
| 219 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 220 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 221 | } |
| 222 | |
| 223 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroupV6) |
| 224 | { |
| 225 | const std::string CONFIG = |
| 226 | "face_system\n" |
| 227 | "{\n" |
| 228 | " udp\n" |
| 229 | " {\n" |
| 230 | " mcast no\n" |
| 231 | " mcast_port 50\n" |
| 232 | " mcast_group ::1\n" |
| 233 | " }\n" |
| 234 | "}\n"; |
| 235 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 236 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 237 | } |
| 238 | |
| 239 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpChannelsDisabled) |
| 240 | { |
| 241 | const std::string CONFIG = |
| 242 | "face_system\n" |
| 243 | "{\n" |
| 244 | " udp\n" |
| 245 | " {\n" |
| 246 | " port 6363\n" |
| 247 | " enable_v4 no\n" |
| 248 | " enable_v6 no\n" |
| 249 | " idle_timeout 30\n" |
| 250 | " keep_alive_interval 25\n" |
| 251 | " mcast yes\n" |
| 252 | " mcast_port 56363\n" |
| 253 | " mcast_group 224.0.23.170\n" |
| 254 | " }\n" |
| 255 | "}\n"; |
| 256 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 257 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 258 | } |
| 259 | |
| 260 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpConflictingMcast) |
| 261 | { |
| 262 | const std::string CONFIG = |
| 263 | "face_system\n" |
| 264 | "{\n" |
| 265 | " udp\n" |
| 266 | " {\n" |
| 267 | " port 6363\n" |
| 268 | " enable_v4 no\n" |
| 269 | " enable_v6 yes\n" |
| 270 | " idle_timeout 30\n" |
| 271 | " keep_alive_interval 25\n" |
| 272 | " mcast yes\n" |
| 273 | " mcast_port 56363\n" |
| 274 | " mcast_group 224.0.23.170\n" |
| 275 | " }\n" |
| 276 | "}\n"; |
| 277 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 278 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 279 | } |
| 280 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 281 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption) |
| 282 | { |
| 283 | const std::string CONFIG = |
| 284 | "face_system\n" |
| 285 | "{\n" |
| 286 | " udp\n" |
| 287 | " {\n" |
| 288 | " hello\n" |
| 289 | " }\n" |
| 290 | "}\n"; |
| 291 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 292 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 293 | } |
| 294 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 295 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit) |
| 296 | { |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 297 | SKIP_IF_NOT_SUPERUSER(); |
| 298 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 299 | const std::string CONFIG_WITH_MCAST = |
| 300 | "face_system\n" |
| 301 | "{\n" |
| 302 | " udp\n" |
| 303 | " {\n" |
| 304 | " mcast yes\n" |
| 305 | " }\n" |
| 306 | "}\n"; |
| 307 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 308 | |
| 309 | BOOST_REQUIRE(m_manager.m_factories.find("udp") != m_manager.m_factories.end()); |
| 310 | auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second); |
| 311 | BOOST_REQUIRE(factory != nullptr); |
| 312 | |
Davide Pesavento | 231ddd7 | 2016-09-02 22:20:00 +0000 | [diff] [blame] | 313 | if (factory->getMulticastFaces().empty()) { |
| 314 | BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one UDP multicast face"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 315 | return; |
| 316 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 317 | |
| 318 | const std::string CONFIG_WITHOUT_MCAST = |
| 319 | "face_system\n" |
| 320 | "{\n" |
| 321 | " udp\n" |
| 322 | " {\n" |
| 323 | " mcast no\n" |
| 324 | " }\n" |
| 325 | "}\n"; |
| 326 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 327 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 328 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 329 | } |
| 330 | |
| 331 | #ifdef HAVE_LIBPCAP |
| 332 | |
| 333 | BOOST_AUTO_TEST_CASE(ProcessSectionEther) |
| 334 | { |
Davide Pesavento | 231ddd7 | 2016-09-02 22:20:00 +0000 | [diff] [blame] | 335 | SKIP_IF_NOT_SUPERUSER(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 336 | |
| 337 | const std::string CONFIG = |
| 338 | "face_system\n" |
| 339 | "{\n" |
| 340 | " ether\n" |
| 341 | " {\n" |
| 342 | " mcast yes\n" |
| 343 | " mcast_group 01:00:5E:00:17:AA\n" |
| 344 | " }\n" |
| 345 | "}\n"; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 346 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 347 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 348 | } |
| 349 | |
| 350 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcast) |
| 351 | { |
| 352 | const std::string CONFIG = |
| 353 | "face_system\n" |
| 354 | "{\n" |
| 355 | " ether\n" |
| 356 | " {\n" |
| 357 | " mcast hello\n" |
| 358 | " }\n" |
| 359 | "}\n"; |
| 360 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 361 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 362 | } |
| 363 | |
| 364 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcastGroup) |
| 365 | { |
| 366 | const std::string CONFIG = |
| 367 | "face_system\n" |
| 368 | "{\n" |
| 369 | " ether\n" |
| 370 | " {\n" |
| 371 | " mcast yes\n" |
| 372 | " mcast_group\n" |
| 373 | " }\n" |
| 374 | "}\n"; |
| 375 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 376 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 377 | } |
| 378 | |
| 379 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherUnknownOption) |
| 380 | { |
| 381 | const std::string CONFIG = |
| 382 | "face_system\n" |
| 383 | "{\n" |
| 384 | " ether\n" |
| 385 | " {\n" |
| 386 | " hello\n" |
| 387 | " }\n" |
| 388 | "}\n"; |
| 389 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 390 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 391 | } |
| 392 | |
| 393 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit) |
| 394 | { |
Davide Pesavento | 231ddd7 | 2016-09-02 22:20:00 +0000 | [diff] [blame] | 395 | SKIP_IF_NOT_SUPERUSER(); |
| 396 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 397 | const std::string CONFIG_WITH_MCAST = |
| 398 | "face_system\n" |
| 399 | "{\n" |
| 400 | " ether\n" |
| 401 | " {\n" |
| 402 | " mcast yes\n" |
| 403 | " }\n" |
| 404 | "}\n"; |
| 405 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 406 | |
| 407 | BOOST_REQUIRE(m_manager.m_factories.find("ether") != m_manager.m_factories.end()); |
| 408 | auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second); |
| 409 | BOOST_REQUIRE(factory != nullptr); |
| 410 | |
Davide Pesavento | 231ddd7 | 2016-09-02 22:20:00 +0000 | [diff] [blame] | 411 | if (factory->getMulticastFaces().empty()) { |
| 412 | BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one Ethernet multicast face"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 413 | return; |
| 414 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 415 | |
| 416 | const std::string CONFIG_WITHOUT_MCAST = |
| 417 | "face_system\n" |
| 418 | "{\n" |
| 419 | " ether\n" |
| 420 | " {\n" |
| 421 | " mcast no\n" |
| 422 | " }\n" |
| 423 | "}\n"; |
| 424 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 425 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 426 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 427 | } |
| 428 | |
| 429 | #endif // HAVE_LIBPCAP |
| 430 | |
| 431 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 432 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 433 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 434 | |
| 435 | } // namespace tests |
| 436 | } // namespace nfd |