Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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 | |
| 33 | #include "manager-common-fixture.hpp" |
| 34 | |
| 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 39 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 40 | |
| 41 | class FaceManagerProcessConfigFixture : public ManagerCommonFixture |
| 42 | { |
| 43 | public: |
| 44 | FaceManagerProcessConfigFixture() |
| 45 | : m_manager(m_forwarder.getFaceTable(), m_dispatcher, m_validator) |
| 46 | { |
| 47 | m_manager.setConfigFile(m_config); |
| 48 | } |
| 49 | |
| 50 | public: |
| 51 | void |
| 52 | parseConfig(const std::string& type, bool isDryRun) |
| 53 | { |
| 54 | m_config.parse(type, isDryRun, "test-config"); |
| 55 | } |
| 56 | |
| 57 | protected: |
| 58 | FaceManager m_manager; |
| 59 | ConfigFile m_config; |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture) |
| 64 | |
| 65 | #ifdef HAVE_UNIX_SOCKETS |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(ProcessSectionUnix) |
| 68 | { |
| 69 | const std::string CONFIG = |
| 70 | "face_system\n" |
| 71 | "{\n" |
| 72 | " unix\n" |
| 73 | " {\n" |
| 74 | " path /tmp/nfd.sock\n" |
| 75 | " }\n" |
| 76 | "}\n"; |
| 77 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 78 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 79 | } |
| 80 | |
| 81 | BOOST_AUTO_TEST_CASE(ProcessSectionUnixUnknownOption) |
| 82 | { |
| 83 | const std::string CONFIG = |
| 84 | "face_system\n" |
| 85 | "{\n" |
| 86 | " unix\n" |
| 87 | " {\n" |
| 88 | " hello\n" |
| 89 | " }\n" |
| 90 | "}\n"; |
| 91 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 92 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 93 | } |
| 94 | |
| 95 | #endif // HAVE_UNIX_SOCKETS |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(ProcessSectionTcp) |
| 98 | { |
| 99 | const std::string CONFIG = |
| 100 | "face_system\n" |
| 101 | "{\n" |
| 102 | " tcp\n" |
| 103 | " {\n" |
| 104 | " listen yes\n" |
| 105 | " port 16363\n" |
| 106 | " enable_v4 yes\n" |
| 107 | " enable_v6 yes\n" |
| 108 | " }\n" |
| 109 | "}\n"; |
| 110 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 111 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpBadListen) |
| 115 | { |
| 116 | const std::string CONFIG = |
| 117 | "face_system\n" |
| 118 | "{\n" |
| 119 | " tcp\n" |
| 120 | " {\n" |
| 121 | " listen hello\n" |
| 122 | " }\n" |
| 123 | "}\n"; |
| 124 | |
| 125 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 126 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 127 | } |
| 128 | |
| 129 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpChannelsDisabled) |
| 130 | { |
| 131 | const std::string CONFIG = |
| 132 | "face_system\n" |
| 133 | "{\n" |
| 134 | " tcp\n" |
| 135 | " {\n" |
| 136 | " port 6363\n" |
| 137 | " enable_v4 no\n" |
| 138 | " enable_v6 no\n" |
| 139 | " }\n" |
| 140 | "}\n"; |
| 141 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 142 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpUnknownOption) |
| 146 | { |
| 147 | const std::string CONFIG = |
| 148 | "face_system\n" |
| 149 | "{\n" |
| 150 | " tcp\n" |
| 151 | " {\n" |
| 152 | " hello\n" |
| 153 | " }\n" |
| 154 | "}\n"; |
| 155 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 156 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 157 | } |
| 158 | |
| 159 | BOOST_AUTO_TEST_CASE(ProcessSectionUdp) |
| 160 | { |
| 161 | const std::string CONFIG = |
| 162 | "face_system\n" |
| 163 | "{\n" |
| 164 | " udp\n" |
| 165 | " {\n" |
| 166 | " port 6363\n" |
| 167 | " enable_v4 yes\n" |
| 168 | " enable_v6 yes\n" |
| 169 | " idle_timeout 30\n" |
| 170 | " keep_alive_interval 25\n" |
| 171 | " mcast yes\n" |
| 172 | " mcast_port 56363\n" |
| 173 | " mcast_group 224.0.23.170\n" |
| 174 | " }\n" |
| 175 | "}\n"; |
| 176 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 177 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 178 | } |
| 179 | |
| 180 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadIdleTimeout) |
| 181 | { |
| 182 | const std::string CONFIG = |
| 183 | "face_system\n" |
| 184 | "{\n" |
| 185 | " udp\n" |
| 186 | " {\n" |
| 187 | " idle_timeout hello\n" |
| 188 | " }\n" |
| 189 | "}\n"; |
| 190 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 191 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 192 | } |
| 193 | |
| 194 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcast) |
| 195 | { |
| 196 | const std::string CONFIG = |
| 197 | "face_system\n" |
| 198 | "{\n" |
| 199 | " udp\n" |
| 200 | " {\n" |
| 201 | " mcast hello\n" |
| 202 | " }\n" |
| 203 | "}\n"; |
| 204 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 205 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 206 | } |
| 207 | |
| 208 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroup) |
| 209 | { |
| 210 | const std::string CONFIG = |
| 211 | "face_system\n" |
| 212 | "{\n" |
| 213 | " udp\n" |
| 214 | " {\n" |
| 215 | " mcast no\n" |
| 216 | " mcast_port 50\n" |
| 217 | " mcast_group hello\n" |
| 218 | " }\n" |
| 219 | "}\n"; |
| 220 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 221 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 222 | } |
| 223 | |
| 224 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroupV6) |
| 225 | { |
| 226 | const std::string CONFIG = |
| 227 | "face_system\n" |
| 228 | "{\n" |
| 229 | " udp\n" |
| 230 | " {\n" |
| 231 | " mcast no\n" |
| 232 | " mcast_port 50\n" |
| 233 | " mcast_group ::1\n" |
| 234 | " }\n" |
| 235 | "}\n"; |
| 236 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 237 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 238 | } |
| 239 | |
| 240 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpChannelsDisabled) |
| 241 | { |
| 242 | const std::string CONFIG = |
| 243 | "face_system\n" |
| 244 | "{\n" |
| 245 | " udp\n" |
| 246 | " {\n" |
| 247 | " port 6363\n" |
| 248 | " enable_v4 no\n" |
| 249 | " enable_v6 no\n" |
| 250 | " idle_timeout 30\n" |
| 251 | " keep_alive_interval 25\n" |
| 252 | " mcast yes\n" |
| 253 | " mcast_port 56363\n" |
| 254 | " mcast_group 224.0.23.170\n" |
| 255 | " }\n" |
| 256 | "}\n"; |
| 257 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 258 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 259 | } |
| 260 | |
| 261 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpConflictingMcast) |
| 262 | { |
| 263 | const std::string CONFIG = |
| 264 | "face_system\n" |
| 265 | "{\n" |
| 266 | " udp\n" |
| 267 | " {\n" |
| 268 | " port 6363\n" |
| 269 | " enable_v4 no\n" |
| 270 | " enable_v6 yes\n" |
| 271 | " idle_timeout 30\n" |
| 272 | " keep_alive_interval 25\n" |
| 273 | " mcast yes\n" |
| 274 | " mcast_port 56363\n" |
| 275 | " mcast_group 224.0.23.170\n" |
| 276 | " }\n" |
| 277 | "}\n"; |
| 278 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 279 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 280 | } |
| 281 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 282 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption) |
| 283 | { |
| 284 | const std::string CONFIG = |
| 285 | "face_system\n" |
| 286 | "{\n" |
| 287 | " udp\n" |
| 288 | " {\n" |
| 289 | " hello\n" |
| 290 | " }\n" |
| 291 | "}\n"; |
| 292 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 293 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 294 | } |
| 295 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 296 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit) |
| 297 | { |
| 298 | const std::string CONFIG_WITH_MCAST = |
| 299 | "face_system\n" |
| 300 | "{\n" |
| 301 | " udp\n" |
| 302 | " {\n" |
| 303 | " mcast yes\n" |
| 304 | " }\n" |
| 305 | "}\n"; |
| 306 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 307 | |
| 308 | BOOST_REQUIRE(m_manager.m_factories.find("udp") != m_manager.m_factories.end()); |
| 309 | auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second); |
| 310 | BOOST_REQUIRE(factory != nullptr); |
| 311 | |
| 312 | if (factory->getMulticastFaces().size() == 0) { |
| 313 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 314 | "no UDP multicast faces are available"); |
| 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 | { |
| 335 | |
| 336 | const std::string CONFIG = |
| 337 | "face_system\n" |
| 338 | "{\n" |
| 339 | " ether\n" |
| 340 | " {\n" |
| 341 | " mcast yes\n" |
| 342 | " mcast_group 01:00:5E:00:17:AA\n" |
| 343 | " }\n" |
| 344 | "}\n"; |
| 345 | |
| 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 | { |
| 395 | const std::string CONFIG_WITH_MCAST = |
| 396 | "face_system\n" |
| 397 | "{\n" |
| 398 | " ether\n" |
| 399 | " {\n" |
| 400 | " mcast yes\n" |
| 401 | " }\n" |
| 402 | "}\n"; |
| 403 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 404 | |
| 405 | BOOST_REQUIRE(m_manager.m_factories.find("ether") != m_manager.m_factories.end()); |
| 406 | auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second); |
| 407 | BOOST_REQUIRE(factory != nullptr); |
| 408 | |
| 409 | if (factory->getMulticastFaces().size() == 0) { |
| 410 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 411 | "no Ethernet multicast faces are available"); |
| 412 | return; |
| 413 | } |
| 414 | BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0); |
| 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)); |
| 425 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 426 | } |
| 427 | |
| 428 | #endif // HAVE_LIBPCAP |
| 429 | |
| 430 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 431 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 432 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 433 | |
| 434 | } // namespace tests |
| 435 | } // namespace nfd |