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 | |
| 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 | { |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 160 | SKIP_IF_NOT_SUPERUSER(); |
| 161 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 162 | const std::string CONFIG = |
| 163 | "face_system\n" |
| 164 | "{\n" |
| 165 | " udp\n" |
| 166 | " {\n" |
| 167 | " port 6363\n" |
| 168 | " enable_v4 yes\n" |
| 169 | " enable_v6 yes\n" |
| 170 | " idle_timeout 30\n" |
| 171 | " keep_alive_interval 25\n" |
| 172 | " mcast yes\n" |
| 173 | " mcast_port 56363\n" |
| 174 | " mcast_group 224.0.23.170\n" |
| 175 | " }\n" |
| 176 | "}\n"; |
| 177 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 178 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 179 | } |
| 180 | |
| 181 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadIdleTimeout) |
| 182 | { |
| 183 | const std::string CONFIG = |
| 184 | "face_system\n" |
| 185 | "{\n" |
| 186 | " udp\n" |
| 187 | " {\n" |
| 188 | " idle_timeout hello\n" |
| 189 | " }\n" |
| 190 | "}\n"; |
| 191 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 192 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 193 | } |
| 194 | |
| 195 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcast) |
| 196 | { |
| 197 | const std::string CONFIG = |
| 198 | "face_system\n" |
| 199 | "{\n" |
| 200 | " udp\n" |
| 201 | " {\n" |
| 202 | " mcast hello\n" |
| 203 | " }\n" |
| 204 | "}\n"; |
| 205 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 206 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 207 | } |
| 208 | |
| 209 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroup) |
| 210 | { |
| 211 | const std::string CONFIG = |
| 212 | "face_system\n" |
| 213 | "{\n" |
| 214 | " udp\n" |
| 215 | " {\n" |
| 216 | " mcast no\n" |
| 217 | " mcast_port 50\n" |
| 218 | " mcast_group hello\n" |
| 219 | " }\n" |
| 220 | "}\n"; |
| 221 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 222 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 223 | } |
| 224 | |
| 225 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroupV6) |
| 226 | { |
| 227 | const std::string CONFIG = |
| 228 | "face_system\n" |
| 229 | "{\n" |
| 230 | " udp\n" |
| 231 | " {\n" |
| 232 | " mcast no\n" |
| 233 | " mcast_port 50\n" |
| 234 | " mcast_group ::1\n" |
| 235 | " }\n" |
| 236 | "}\n"; |
| 237 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 238 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 239 | } |
| 240 | |
| 241 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpChannelsDisabled) |
| 242 | { |
| 243 | const std::string CONFIG = |
| 244 | "face_system\n" |
| 245 | "{\n" |
| 246 | " udp\n" |
| 247 | " {\n" |
| 248 | " port 6363\n" |
| 249 | " enable_v4 no\n" |
| 250 | " enable_v6 no\n" |
| 251 | " idle_timeout 30\n" |
| 252 | " keep_alive_interval 25\n" |
| 253 | " mcast yes\n" |
| 254 | " mcast_port 56363\n" |
| 255 | " mcast_group 224.0.23.170\n" |
| 256 | " }\n" |
| 257 | "}\n"; |
| 258 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 259 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 260 | } |
| 261 | |
| 262 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpConflictingMcast) |
| 263 | { |
| 264 | const std::string CONFIG = |
| 265 | "face_system\n" |
| 266 | "{\n" |
| 267 | " udp\n" |
| 268 | " {\n" |
| 269 | " port 6363\n" |
| 270 | " enable_v4 no\n" |
| 271 | " enable_v6 yes\n" |
| 272 | " idle_timeout 30\n" |
| 273 | " keep_alive_interval 25\n" |
| 274 | " mcast yes\n" |
| 275 | " mcast_port 56363\n" |
| 276 | " mcast_group 224.0.23.170\n" |
| 277 | " }\n" |
| 278 | "}\n"; |
| 279 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 280 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 281 | } |
| 282 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 283 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption) |
| 284 | { |
| 285 | const std::string CONFIG = |
| 286 | "face_system\n" |
| 287 | "{\n" |
| 288 | " udp\n" |
| 289 | " {\n" |
| 290 | " hello\n" |
| 291 | " }\n" |
| 292 | "}\n"; |
| 293 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 294 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 295 | } |
| 296 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 297 | BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit) |
| 298 | { |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 299 | SKIP_IF_NOT_SUPERUSER(); |
| 300 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 301 | const std::string CONFIG_WITH_MCAST = |
| 302 | "face_system\n" |
| 303 | "{\n" |
| 304 | " udp\n" |
| 305 | " {\n" |
| 306 | " mcast yes\n" |
| 307 | " }\n" |
| 308 | "}\n"; |
| 309 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 310 | |
| 311 | BOOST_REQUIRE(m_manager.m_factories.find("udp") != m_manager.m_factories.end()); |
| 312 | auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second); |
| 313 | BOOST_REQUIRE(factory != nullptr); |
| 314 | |
| 315 | if (factory->getMulticastFaces().size() == 0) { |
| 316 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 317 | "no UDP multicast faces are available"); |
| 318 | return; |
| 319 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 320 | |
| 321 | const std::string CONFIG_WITHOUT_MCAST = |
| 322 | "face_system\n" |
| 323 | "{\n" |
| 324 | " udp\n" |
| 325 | " {\n" |
| 326 | " mcast no\n" |
| 327 | " }\n" |
| 328 | "}\n"; |
| 329 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 330 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 331 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 332 | } |
| 333 | |
| 334 | #ifdef HAVE_LIBPCAP |
| 335 | |
| 336 | BOOST_AUTO_TEST_CASE(ProcessSectionEther) |
| 337 | { |
| 338 | |
| 339 | const std::string CONFIG = |
| 340 | "face_system\n" |
| 341 | "{\n" |
| 342 | " ether\n" |
| 343 | " {\n" |
| 344 | " mcast yes\n" |
| 345 | " mcast_group 01:00:5E:00:17:AA\n" |
| 346 | " }\n" |
| 347 | "}\n"; |
| 348 | |
| 349 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 350 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 351 | } |
| 352 | |
| 353 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcast) |
| 354 | { |
| 355 | const std::string CONFIG = |
| 356 | "face_system\n" |
| 357 | "{\n" |
| 358 | " ether\n" |
| 359 | " {\n" |
| 360 | " mcast hello\n" |
| 361 | " }\n" |
| 362 | "}\n"; |
| 363 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 364 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 365 | } |
| 366 | |
| 367 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcastGroup) |
| 368 | { |
| 369 | const std::string CONFIG = |
| 370 | "face_system\n" |
| 371 | "{\n" |
| 372 | " ether\n" |
| 373 | " {\n" |
| 374 | " mcast yes\n" |
| 375 | " mcast_group\n" |
| 376 | " }\n" |
| 377 | "}\n"; |
| 378 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 379 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 380 | } |
| 381 | |
| 382 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherUnknownOption) |
| 383 | { |
| 384 | const std::string CONFIG = |
| 385 | "face_system\n" |
| 386 | "{\n" |
| 387 | " ether\n" |
| 388 | " {\n" |
| 389 | " hello\n" |
| 390 | " }\n" |
| 391 | "}\n"; |
| 392 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 393 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 394 | } |
| 395 | |
| 396 | BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit) |
| 397 | { |
| 398 | const std::string CONFIG_WITH_MCAST = |
| 399 | "face_system\n" |
| 400 | "{\n" |
| 401 | " ether\n" |
| 402 | " {\n" |
| 403 | " mcast yes\n" |
| 404 | " }\n" |
| 405 | "}\n"; |
| 406 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 407 | |
| 408 | BOOST_REQUIRE(m_manager.m_factories.find("ether") != m_manager.m_factories.end()); |
| 409 | auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second); |
| 410 | BOOST_REQUIRE(factory != nullptr); |
| 411 | |
| 412 | if (factory->getMulticastFaces().size() == 0) { |
| 413 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 414 | "no Ethernet multicast faces are available"); |
| 415 | return; |
| 416 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 417 | |
| 418 | const std::string CONFIG_WITHOUT_MCAST = |
| 419 | "face_system\n" |
| 420 | "{\n" |
| 421 | " ether\n" |
| 422 | " {\n" |
| 423 | " mcast no\n" |
| 424 | " }\n" |
| 425 | "}\n"; |
| 426 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
Davide Pesavento | 35120ea | 2015-11-17 21:13:18 +0100 | [diff] [blame] | 427 | BOOST_REQUIRE_NO_THROW(g_io.poll()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 428 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 429 | } |
| 430 | |
| 431 | #endif // HAVE_LIBPCAP |
| 432 | |
| 433 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 434 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 435 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 436 | |
| 437 | } // namespace tests |
| 438 | } // namespace nfd |