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() |
| 45 | : m_manager(m_forwarder.getFaceTable(), m_dispatcher, m_validator) |
| 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 | |
| 61 | |
| 62 | BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture) |
| 63 | |
| 64 | #ifdef HAVE_UNIX_SOCKETS |
| 65 | |
| 66 | BOOST_AUTO_TEST_CASE(ProcessSectionUnix) |
| 67 | { |
| 68 | const std::string CONFIG = |
| 69 | "face_system\n" |
| 70 | "{\n" |
| 71 | " unix\n" |
| 72 | " {\n" |
| 73 | " path /tmp/nfd.sock\n" |
| 74 | " }\n" |
| 75 | "}\n"; |
| 76 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 77 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 78 | } |
| 79 | |
| 80 | BOOST_AUTO_TEST_CASE(ProcessSectionUnixUnknownOption) |
| 81 | { |
| 82 | const std::string CONFIG = |
| 83 | "face_system\n" |
| 84 | "{\n" |
| 85 | " unix\n" |
| 86 | " {\n" |
| 87 | " hello\n" |
| 88 | " }\n" |
| 89 | "}\n"; |
| 90 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 91 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 92 | } |
| 93 | |
| 94 | #endif // HAVE_UNIX_SOCKETS |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(ProcessSectionTcp) |
| 97 | { |
| 98 | const std::string CONFIG = |
| 99 | "face_system\n" |
| 100 | "{\n" |
| 101 | " tcp\n" |
| 102 | " {\n" |
| 103 | " listen yes\n" |
| 104 | " port 16363\n" |
| 105 | " enable_v4 yes\n" |
| 106 | " enable_v6 yes\n" |
| 107 | " }\n" |
| 108 | "}\n"; |
| 109 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 110 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpBadListen) |
| 114 | { |
| 115 | const std::string CONFIG = |
| 116 | "face_system\n" |
| 117 | "{\n" |
| 118 | " tcp\n" |
| 119 | " {\n" |
| 120 | " listen hello\n" |
| 121 | " }\n" |
| 122 | "}\n"; |
| 123 | |
| 124 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 125 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpChannelsDisabled) |
| 129 | { |
| 130 | const std::string CONFIG = |
| 131 | "face_system\n" |
| 132 | "{\n" |
| 133 | " tcp\n" |
| 134 | " {\n" |
| 135 | " port 6363\n" |
| 136 | " enable_v4 no\n" |
| 137 | " enable_v6 no\n" |
| 138 | " }\n" |
| 139 | "}\n"; |
| 140 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 141 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 142 | } |
| 143 | |
| 144 | BOOST_AUTO_TEST_CASE(ProcessSectionTcpUnknownOption) |
| 145 | { |
| 146 | const std::string CONFIG = |
| 147 | "face_system\n" |
| 148 | "{\n" |
| 149 | " tcp\n" |
| 150 | " {\n" |
| 151 | " hello\n" |
| 152 | " }\n" |
| 153 | "}\n"; |
| 154 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 155 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 156 | } |
| 157 | |
| 158 | BOOST_AUTO_TEST_CASE(ProcessSectionUdp) |
| 159 | { |
| 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 | { |
| 297 | const std::string CONFIG_WITH_MCAST = |
| 298 | "face_system\n" |
| 299 | "{\n" |
| 300 | " udp\n" |
| 301 | " {\n" |
| 302 | " mcast yes\n" |
| 303 | " }\n" |
| 304 | "}\n"; |
| 305 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 306 | |
| 307 | BOOST_REQUIRE(m_manager.m_factories.find("udp") != m_manager.m_factories.end()); |
| 308 | auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second); |
| 309 | BOOST_REQUIRE(factory != nullptr); |
| 310 | |
| 311 | if (factory->getMulticastFaces().size() == 0) { |
| 312 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 313 | "no UDP multicast faces are available"); |
| 314 | return; |
| 315 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 316 | |
| 317 | const std::string CONFIG_WITHOUT_MCAST = |
| 318 | "face_system\n" |
| 319 | "{\n" |
| 320 | " udp\n" |
| 321 | " {\n" |
| 322 | " mcast no\n" |
| 323 | " }\n" |
| 324 | "}\n"; |
| 325 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 326 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 327 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 328 | } |
| 329 | |
| 330 | #ifdef HAVE_LIBPCAP |
| 331 | |
| 332 | BOOST_AUTO_TEST_CASE(ProcessSectionEther) |
| 333 | { |
| 334 | |
| 335 | const std::string CONFIG = |
| 336 | "face_system\n" |
| 337 | "{\n" |
| 338 | " ether\n" |
| 339 | " {\n" |
| 340 | " mcast yes\n" |
| 341 | " mcast_group 01:00:5E:00:17:AA\n" |
| 342 | " }\n" |
| 343 | "}\n"; |
| 344 | |
| 345 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 346 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 347 | } |
| 348 | |
| 349 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcast) |
| 350 | { |
| 351 | const std::string CONFIG = |
| 352 | "face_system\n" |
| 353 | "{\n" |
| 354 | " ether\n" |
| 355 | " {\n" |
| 356 | " mcast hello\n" |
| 357 | " }\n" |
| 358 | "}\n"; |
| 359 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 360 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 361 | } |
| 362 | |
| 363 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcastGroup) |
| 364 | { |
| 365 | const std::string CONFIG = |
| 366 | "face_system\n" |
| 367 | "{\n" |
| 368 | " ether\n" |
| 369 | " {\n" |
| 370 | " mcast yes\n" |
| 371 | " mcast_group\n" |
| 372 | " }\n" |
| 373 | "}\n"; |
| 374 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 375 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 376 | } |
| 377 | |
| 378 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherUnknownOption) |
| 379 | { |
| 380 | const std::string CONFIG = |
| 381 | "face_system\n" |
| 382 | "{\n" |
| 383 | " ether\n" |
| 384 | " {\n" |
| 385 | " hello\n" |
| 386 | " }\n" |
| 387 | "}\n"; |
| 388 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 389 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 390 | } |
| 391 | |
| 392 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit) |
| 393 | { |
| 394 | const std::string CONFIG_WITH_MCAST = |
| 395 | "face_system\n" |
| 396 | "{\n" |
| 397 | " ether\n" |
| 398 | " {\n" |
| 399 | " mcast yes\n" |
| 400 | " }\n" |
| 401 | "}\n"; |
| 402 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 403 | |
| 404 | BOOST_REQUIRE(m_manager.m_factories.find("ether") != m_manager.m_factories.end()); |
| 405 | auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second); |
| 406 | BOOST_REQUIRE(factory != nullptr); |
| 407 | |
| 408 | if (factory->getMulticastFaces().size() == 0) { |
| 409 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 410 | "no Ethernet multicast faces are available"); |
| 411 | return; |
| 412 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 413 | |
| 414 | const std::string CONFIG_WITHOUT_MCAST = |
| 415 | "face_system\n" |
| 416 | "{\n" |
| 417 | " ether\n" |
| 418 | " {\n" |
| 419 | " mcast no\n" |
| 420 | " }\n" |
| 421 | "}\n"; |
| 422 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 423 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 424 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 425 | } |
| 426 | |
| 427 | #endif // HAVE_LIBPCAP |
| 428 | |
| 429 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 430 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 431 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 432 | |
| 433 | } // namespace tests |
| 434 | } // namespace nfd |