Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 6 | |
| 7 | #include "mgmt/face-manager.hpp" |
| 8 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 9 | #include "mgmt/face-status-publisher.hpp" |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 10 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 11 | #include "face/face.hpp" |
| 12 | #include "../face/dummy-face.hpp" |
| 13 | #include "fw/face-table.hpp" |
| 14 | #include "fw/forwarder.hpp" |
| 15 | |
| 16 | #include "common.hpp" |
| 17 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 18 | #include "validation-common.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 19 | #include "face-status-publisher-common.hpp" |
| 20 | |
| 21 | #include <ndn-cpp-dev/encoding/tlv.hpp> |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 22 | #include <ndn-cpp-dev/management/nfd-face-event-notification.hpp> |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 23 | |
| 24 | namespace nfd { |
| 25 | namespace tests { |
| 26 | |
| 27 | NFD_LOG_INIT("FaceManagerTest"); |
| 28 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 29 | class FaceManagerTestFace : public DummyFace |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 30 | { |
| 31 | public: |
| 32 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 33 | FaceManagerTestFace() |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 34 | : m_closeFired(false) |
| 35 | { |
| 36 | |
| 37 | } |
| 38 | |
| 39 | virtual |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 40 | ~FaceManagerTestFace() |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 41 | { |
| 42 | |
| 43 | } |
| 44 | |
| 45 | virtual void |
| 46 | close() |
| 47 | { |
| 48 | m_closeFired = true; |
| 49 | } |
| 50 | |
| 51 | bool |
| 52 | didCloseFire() const |
| 53 | { |
| 54 | return m_closeFired; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | bool m_closeFired; |
| 59 | }; |
| 60 | |
| 61 | class TestFaceTable : public FaceTable |
| 62 | { |
| 63 | public: |
| 64 | TestFaceTable(Forwarder& forwarder) |
| 65 | : FaceTable(forwarder), |
| 66 | m_addFired(false), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 67 | m_getFired(false), |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 68 | m_dummy(make_shared<FaceManagerTestFace>()) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 69 | { |
| 70 | |
| 71 | } |
| 72 | |
| 73 | virtual |
| 74 | ~TestFaceTable() |
| 75 | { |
| 76 | |
| 77 | } |
| 78 | |
| 79 | virtual void |
| 80 | add(shared_ptr<Face> face) |
| 81 | { |
| 82 | m_addFired = true; |
| 83 | } |
| 84 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 85 | virtual shared_ptr<Face> |
| 86 | get(FaceId id) const |
| 87 | { |
| 88 | m_getFired = true; |
| 89 | return m_dummy; |
| 90 | } |
| 91 | |
| 92 | bool |
| 93 | didAddFire() const |
| 94 | { |
| 95 | return m_addFired; |
| 96 | } |
| 97 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 98 | bool |
| 99 | didGetFire() const |
| 100 | { |
| 101 | return m_getFired; |
| 102 | } |
| 103 | |
| 104 | void |
| 105 | reset() |
| 106 | { |
| 107 | m_addFired = false; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 108 | m_getFired = false; |
| 109 | } |
| 110 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 111 | shared_ptr<FaceManagerTestFace>& |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 112 | getDummyFace() |
| 113 | { |
| 114 | return m_dummy; |
| 115 | } |
| 116 | |
| 117 | private: |
| 118 | bool m_addFired; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 119 | mutable bool m_getFired; |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 120 | shared_ptr<FaceManagerTestFace> m_dummy; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | |
| 124 | class TestFaceTableFixture : public BaseFixture |
| 125 | { |
| 126 | public: |
| 127 | TestFaceTableFixture() |
| 128 | : m_faceTable(m_forwarder) |
| 129 | { |
| 130 | |
| 131 | } |
| 132 | |
| 133 | virtual |
| 134 | ~TestFaceTableFixture() |
| 135 | { |
| 136 | |
| 137 | } |
| 138 | |
| 139 | protected: |
| 140 | Forwarder m_forwarder; |
| 141 | TestFaceTable m_faceTable; |
| 142 | }; |
| 143 | |
| 144 | class TestFaceManagerCommon |
| 145 | { |
| 146 | public: |
| 147 | TestFaceManagerCommon() |
| 148 | : m_face(make_shared<InternalFace>()), |
| 149 | m_callbackFired(false) |
| 150 | { |
| 151 | |
| 152 | } |
| 153 | |
| 154 | virtual |
| 155 | ~TestFaceManagerCommon() |
| 156 | { |
| 157 | |
| 158 | } |
| 159 | |
| 160 | shared_ptr<InternalFace>& |
| 161 | getFace() |
| 162 | { |
| 163 | return m_face; |
| 164 | } |
| 165 | |
| 166 | void |
| 167 | validateControlResponseCommon(const Data& response, |
| 168 | const Name& expectedName, |
| 169 | uint32_t expectedCode, |
| 170 | const std::string& expectedText, |
| 171 | ControlResponse& control) |
| 172 | { |
| 173 | m_callbackFired = true; |
| 174 | Block controlRaw = response.getContent().blockFromValue(); |
| 175 | |
| 176 | control.wireDecode(controlRaw); |
| 177 | |
| 178 | // NFD_LOG_DEBUG("received control response" |
| 179 | // << " Name: " << response.getName() |
| 180 | // << " code: " << control.getCode() |
| 181 | // << " text: " << control.getText()); |
| 182 | |
| 183 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 184 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 185 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | validateControlResponse(const Data& response, |
| 190 | const Name& expectedName, |
| 191 | uint32_t expectedCode, |
| 192 | const std::string& expectedText) |
| 193 | { |
| 194 | ControlResponse control; |
| 195 | validateControlResponseCommon(response, expectedName, |
| 196 | expectedCode, expectedText, control); |
| 197 | |
| 198 | if (!control.getBody().empty()) |
| 199 | { |
| 200 | BOOST_FAIL("found unexpected control response body"); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void |
| 205 | validateControlResponse(const Data& response, |
| 206 | const Name& expectedName, |
| 207 | uint32_t expectedCode, |
| 208 | const std::string& expectedText, |
| 209 | const Block& expectedBody) |
| 210 | { |
| 211 | ControlResponse control; |
| 212 | validateControlResponseCommon(response, expectedName, |
| 213 | expectedCode, expectedText, control); |
| 214 | |
| 215 | BOOST_REQUIRE(!control.getBody().empty()); |
| 216 | BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size()); |
| 217 | |
| 218 | BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(), |
| 219 | expectedBody.value_size()) == 0); |
| 220 | |
| 221 | } |
| 222 | |
| 223 | bool |
| 224 | didCallbackFire() const |
| 225 | { |
| 226 | return m_callbackFired; |
| 227 | } |
| 228 | |
| 229 | void |
| 230 | resetCallbackFired() |
| 231 | { |
| 232 | m_callbackFired = false; |
| 233 | } |
| 234 | |
| 235 | protected: |
| 236 | shared_ptr<InternalFace> m_face; |
| 237 | |
| 238 | private: |
| 239 | bool m_callbackFired; |
| 240 | }; |
| 241 | |
| 242 | class FaceManagerFixture : public TestFaceTableFixture, public TestFaceManagerCommon |
| 243 | { |
| 244 | public: |
| 245 | FaceManagerFixture() |
| 246 | : m_manager(m_faceTable, m_face) |
| 247 | { |
| 248 | m_manager.setConfigFile(m_config); |
| 249 | } |
| 250 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 251 | virtual |
| 252 | ~FaceManagerFixture() |
| 253 | { |
| 254 | |
| 255 | } |
| 256 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 257 | void |
| 258 | parseConfig(const std::string configuration, bool isDryRun) |
| 259 | { |
| 260 | m_config.parse(configuration, isDryRun, "dummy-config"); |
| 261 | } |
| 262 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 263 | FaceManager& |
| 264 | getManager() |
| 265 | { |
| 266 | return m_manager; |
| 267 | } |
| 268 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 269 | void |
| 270 | addInterestRule(const std::string& regex, |
| 271 | ndn::IdentityCertificate& certificate) |
| 272 | { |
| 273 | m_manager.addInterestRule(regex, certificate); |
| 274 | } |
| 275 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 276 | bool |
| 277 | didFaceTableAddFire() const |
| 278 | { |
| 279 | return m_faceTable.didAddFire(); |
| 280 | } |
| 281 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 282 | bool |
| 283 | didFaceTableGetFire() const |
| 284 | { |
| 285 | return m_faceTable.didGetFire(); |
| 286 | } |
| 287 | |
| 288 | void |
| 289 | resetFaceTable() |
| 290 | { |
| 291 | m_faceTable.reset(); |
| 292 | } |
| 293 | |
| 294 | private: |
| 295 | FaceManager m_manager; |
| 296 | ConfigFile m_config; |
| 297 | }; |
| 298 | |
| 299 | BOOST_FIXTURE_TEST_SUITE(MgmtFaceManager, FaceManagerFixture) |
| 300 | |
| 301 | bool |
| 302 | isExpectedException(const ConfigFile::Error& error, const std::string& expectedMessage) |
| 303 | { |
| 304 | if (error.what() != expectedMessage) |
| 305 | { |
| 306 | NFD_LOG_ERROR("expected: " << expectedMessage << "\tgot: " << error.what()); |
| 307 | } |
| 308 | return error.what() == expectedMessage; |
| 309 | } |
| 310 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 311 | #ifdef HAVE_UNIX_SOCKETS |
| 312 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 313 | BOOST_AUTO_TEST_CASE(TestProcessSectionUnix) |
| 314 | { |
| 315 | const std::string CONFIG = |
| 316 | "face_system\n" |
| 317 | "{\n" |
| 318 | " unix\n" |
| 319 | " {\n" |
| 320 | " listen yes\n" |
| 321 | " path /tmp/nfd.sock\n" |
| 322 | " }\n" |
| 323 | "}\n"; |
| 324 | BOOST_TEST_CHECKPOINT("Calling parse"); |
| 325 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 326 | } |
| 327 | |
| 328 | BOOST_AUTO_TEST_CASE(TestProcessSectionUnixDryRun) |
| 329 | { |
| 330 | const std::string CONFIG = |
| 331 | "face_system\n" |
| 332 | "{\n" |
| 333 | " unix\n" |
| 334 | " {\n" |
| 335 | " listen yes\n" |
| 336 | " path /var/run/nfd.sock\n" |
| 337 | " }\n" |
| 338 | "}\n"; |
| 339 | |
| 340 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 341 | } |
| 342 | |
| 343 | BOOST_AUTO_TEST_CASE(TestProcessSectionUnixBadListen) |
| 344 | { |
| 345 | const std::string CONFIG = |
| 346 | "face_system\n" |
| 347 | "{\n" |
| 348 | " unix\n" |
| 349 | " {\n" |
| 350 | " listen hello\n" |
| 351 | " }\n" |
| 352 | "}\n"; |
| 353 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 354 | bind(&isExpectedException, _1, |
| 355 | "Invalid value for option \"listen\" in \"unix\" section")); |
| 356 | } |
| 357 | |
| 358 | BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption) |
| 359 | { |
| 360 | const std::string CONFIG = |
| 361 | "face_system\n" |
| 362 | "{\n" |
| 363 | " unix\n" |
| 364 | " {\n" |
| 365 | " hello\n" |
| 366 | " }\n" |
| 367 | "}\n"; |
| 368 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 369 | bind(&isExpectedException, _1, |
| 370 | "Unrecognized option \"hello\" in \"unix\" section")); |
| 371 | } |
| 372 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 373 | #endif // HAVE_UNIX_SOCKETS |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 374 | |
| 375 | |
| 376 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcp) |
| 377 | { |
| 378 | const std::string CONFIG = |
| 379 | "face_system\n" |
| 380 | "{\n" |
| 381 | " tcp\n" |
| 382 | " {\n" |
| 383 | " listen yes\n" |
| 384 | " port 6363\n" |
| 385 | " }\n" |
| 386 | "}\n"; |
| 387 | try |
| 388 | { |
| 389 | parseConfig(CONFIG, false); |
| 390 | } |
| 391 | catch (const std::runtime_error& e) |
| 392 | { |
| 393 | const std::string reason = e.what(); |
| 394 | if (reason.find("Address in use") != std::string::npos) |
| 395 | { |
| 396 | BOOST_FAIL(reason); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun) |
| 402 | { |
| 403 | const std::string CONFIG = |
| 404 | "face_system\n" |
| 405 | "{\n" |
| 406 | " tcp\n" |
| 407 | " {\n" |
| 408 | " listen yes\n" |
| 409 | " port 6363\n" |
| 410 | " }\n" |
| 411 | "}\n"; |
| 412 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 413 | } |
| 414 | |
| 415 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen) |
| 416 | { |
| 417 | const std::string CONFIG = |
| 418 | "face_system\n" |
| 419 | "{\n" |
| 420 | " tcp\n" |
| 421 | " {\n" |
| 422 | " listen hello\n" |
| 423 | " }\n" |
| 424 | "}\n"; |
| 425 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 426 | bind(&isExpectedException, _1, |
| 427 | "Invalid value for option \"listen\" in \"tcp\" section")); |
| 428 | } |
| 429 | |
| 430 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption) |
| 431 | { |
| 432 | const std::string CONFIG = |
| 433 | "face_system\n" |
| 434 | "{\n" |
| 435 | " tcp\n" |
| 436 | " {\n" |
| 437 | " hello\n" |
| 438 | " }\n" |
| 439 | "}\n"; |
| 440 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 441 | bind(&isExpectedException, _1, |
| 442 | "Unrecognized option \"hello\" in \"tcp\" section")); |
| 443 | } |
| 444 | |
| 445 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdp) |
| 446 | { |
| 447 | const std::string CONFIG = |
| 448 | "face_system\n" |
| 449 | "{\n" |
| 450 | " udp\n" |
| 451 | " {\n" |
| 452 | " port 6363\n" |
| 453 | " idle_timeout 30\n" |
| 454 | " keep_alive_interval 25\n" |
| 455 | " mcast yes\n" |
| 456 | " mcast_port 56363\n" |
| 457 | " mcast_group 224.0.23.170\n" |
| 458 | " }\n" |
| 459 | "}\n"; |
| 460 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 461 | } |
| 462 | |
| 463 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun) |
| 464 | { |
| 465 | const std::string CONFIG = |
| 466 | "face_system\n" |
| 467 | "{\n" |
| 468 | " udp\n" |
| 469 | " {\n" |
| 470 | " port 6363\n" |
| 471 | " idle_timeout 30\n" |
| 472 | " keep_alive_interval 25\n" |
| 473 | " mcast yes\n" |
| 474 | " mcast_port 56363\n" |
| 475 | " mcast_group 224.0.23.170\n" |
| 476 | " }\n" |
| 477 | "}\n"; |
| 478 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 479 | } |
| 480 | |
| 481 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout) |
| 482 | { |
| 483 | const std::string CONFIG = |
| 484 | "face_system\n" |
| 485 | "{\n" |
| 486 | " udp\n" |
| 487 | " {\n" |
| 488 | " idle_timeout hello\n" |
| 489 | " }\n" |
| 490 | "}\n"; |
| 491 | |
| 492 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 493 | bind(&isExpectedException, _1, |
| 494 | "Invalid value for option \"idle_timeout\" in \"udp\" section")); |
| 495 | } |
| 496 | |
| 497 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast) |
| 498 | { |
| 499 | const std::string CONFIG = |
| 500 | "face_system\n" |
| 501 | "{\n" |
| 502 | " udp\n" |
| 503 | " {\n" |
| 504 | " mcast hello\n" |
| 505 | " }\n" |
| 506 | "}\n"; |
| 507 | |
| 508 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 509 | bind(&isExpectedException, _1, |
| 510 | "Invalid value for option \"mcast\" in \"udp\" section")); |
| 511 | } |
| 512 | |
| 513 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup) |
| 514 | { |
| 515 | const std::string CONFIG = |
| 516 | "face_system\n" |
| 517 | "{\n" |
| 518 | " udp\n" |
| 519 | " {\n" |
| 520 | " mcast no\n" |
| 521 | " mcast_port 50\n" |
| 522 | " mcast_group hello\n" |
| 523 | " }\n" |
| 524 | "}\n"; |
| 525 | |
| 526 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 527 | bind(&isExpectedException, _1, |
| 528 | "Invalid value for option \"mcast_group\" in \"udp\" section")); |
| 529 | } |
| 530 | |
| 531 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6) |
| 532 | { |
| 533 | const std::string CONFIG = |
| 534 | "face_system\n" |
| 535 | "{\n" |
| 536 | " udp\n" |
| 537 | " {\n" |
| 538 | " mcast no\n" |
| 539 | " mcast_port 50\n" |
| 540 | " mcast_group ::1\n" |
| 541 | " }\n" |
| 542 | "}\n"; |
| 543 | |
| 544 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 545 | bind(&isExpectedException, _1, |
| 546 | "Invalid value for option \"mcast_group\" in \"udp\" section")); |
| 547 | } |
| 548 | |
| 549 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption) |
| 550 | { |
| 551 | const std::string CONFIG = |
| 552 | "face_system\n" |
| 553 | "{\n" |
| 554 | " udp\n" |
| 555 | " {\n" |
| 556 | " hello\n" |
| 557 | " }\n" |
| 558 | "}\n"; |
| 559 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 560 | bind(&isExpectedException, _1, |
| 561 | "Unrecognized option \"hello\" in \"udp\" section")); |
| 562 | } |
| 563 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 564 | #ifdef HAVE_PCAP |
| 565 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 566 | BOOST_AUTO_TEST_CASE(TestProcessSectionEther) |
| 567 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 568 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 569 | const std::string CONFIG = |
| 570 | "face_system\n" |
| 571 | "{\n" |
| 572 | " ether\n" |
| 573 | " {\n" |
| 574 | " mcast yes\n" |
| 575 | " mcast_group 01:00:5E:00:17:AA\n" |
| 576 | " }\n" |
| 577 | "}\n"; |
| 578 | |
| 579 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 580 | } |
| 581 | |
| 582 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun) |
| 583 | { |
| 584 | const std::string CONFIG = |
| 585 | "face_system\n" |
| 586 | "{\n" |
| 587 | " ether\n" |
| 588 | " {\n" |
| 589 | " mcast yes\n" |
| 590 | " mcast_group 01:00:5E:00:17:AA\n" |
| 591 | " }\n" |
| 592 | "}\n"; |
| 593 | |
| 594 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 595 | } |
| 596 | |
| 597 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast) |
| 598 | { |
| 599 | const std::string CONFIG = |
| 600 | "face_system\n" |
| 601 | "{\n" |
| 602 | " ether\n" |
| 603 | " {\n" |
| 604 | " mcast hello\n" |
| 605 | " }\n" |
| 606 | "}\n"; |
| 607 | |
| 608 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 609 | bind(&isExpectedException, _1, |
| 610 | "Invalid value for option \"mcast\" in \"ether\" section")); |
| 611 | } |
| 612 | |
| 613 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup) |
| 614 | { |
| 615 | const std::string CONFIG = |
| 616 | "face_system\n" |
| 617 | "{\n" |
| 618 | " ether\n" |
| 619 | " {\n" |
| 620 | " mcast yes\n" |
| 621 | " mcast_group\n" |
| 622 | " }\n" |
| 623 | "}\n"; |
| 624 | |
| 625 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 626 | bind(&isExpectedException, _1, |
| 627 | "Invalid value for option \"mcast_group\" in \"ether\" section")); |
| 628 | } |
| 629 | |
| 630 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption) |
| 631 | { |
| 632 | const std::string CONFIG = |
| 633 | "face_system\n" |
| 634 | "{\n" |
| 635 | " ether\n" |
| 636 | " {\n" |
| 637 | " hello\n" |
| 638 | " }\n" |
| 639 | "}\n"; |
| 640 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 641 | bind(&isExpectedException, _1, |
| 642 | "Unrecognized option \"hello\" in \"ether\" section")); |
| 643 | } |
| 644 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 645 | #endif |
| 646 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 647 | BOOST_AUTO_TEST_CASE(TestFireInterestFilter) |
| 648 | { |
| 649 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 650 | |
| 651 | getFace()->onReceiveData += |
| 652 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 653 | command->getName(), 400, "Malformed command"); |
| 654 | |
| 655 | getFace()->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 656 | g_io.run_one(); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 657 | |
| 658 | BOOST_REQUIRE(didCallbackFire()); |
| 659 | } |
| 660 | |
| 661 | BOOST_AUTO_TEST_CASE(MalformedCommmand) |
| 662 | { |
| 663 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 664 | |
| 665 | getFace()->onReceiveData += |
| 666 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 667 | command->getName(), 400, "Malformed command"); |
| 668 | |
| 669 | getManager().onFaceRequest(*command); |
| 670 | |
| 671 | BOOST_REQUIRE(didCallbackFire()); |
| 672 | } |
| 673 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 674 | BOOST_AUTO_TEST_CASE(UnsignedCommand) |
| 675 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 676 | ControlParameters parameters; |
| 677 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 678 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 679 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 680 | |
| 681 | Name commandName("/localhost/nfd/faces"); |
| 682 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 683 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 684 | |
| 685 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 686 | |
| 687 | getFace()->onReceiveData += |
| 688 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 689 | command->getName(), 401, "Signature required"); |
| 690 | |
| 691 | getManager().onFaceRequest(*command); |
| 692 | |
| 693 | BOOST_REQUIRE(didCallbackFire()); |
| 694 | } |
| 695 | |
| 696 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>) |
| 697 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 698 | ControlParameters parameters; |
| 699 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 700 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 701 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 702 | |
| 703 | Name commandName("/localhost/nfd/faces"); |
| 704 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 705 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 706 | |
| 707 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 708 | generateCommand(*command); |
| 709 | |
| 710 | getFace()->onReceiveData += |
| 711 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 712 | command->getName(), 403, "Unauthorized command"); |
| 713 | |
| 714 | getManager().onFaceRequest(*command); |
| 715 | |
| 716 | BOOST_REQUIRE(didCallbackFire()); |
| 717 | } |
| 718 | |
| 719 | template <typename T> class AuthorizedCommandFixture : public CommandFixture<T> |
| 720 | { |
| 721 | public: |
| 722 | AuthorizedCommandFixture() |
| 723 | { |
| 724 | const std::string regex = "^<localhost><nfd><faces>"; |
| 725 | T::addInterestRule(regex, *CommandFixture<T>::m_certificate); |
| 726 | } |
| 727 | |
| 728 | virtual |
| 729 | ~AuthorizedCommandFixture() |
| 730 | { |
| 731 | |
| 732 | } |
| 733 | }; |
| 734 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 735 | BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 736 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 737 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 738 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 739 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 740 | |
| 741 | Name commandName("/localhost/nfd/faces"); |
| 742 | commandName.append("unsupported"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 743 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 744 | |
| 745 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 746 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 747 | |
| 748 | getFace()->onReceiveData += |
| 749 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 750 | command->getName(), 501, "Unsupported command"); |
| 751 | |
| 752 | getManager().onFaceRequest(*command); |
| 753 | |
| 754 | BOOST_REQUIRE(didCallbackFire()); |
| 755 | } |
| 756 | |
| 757 | class ValidatedFaceRequestFixture : public TestFaceTableFixture, |
| 758 | public TestFaceManagerCommon, |
| 759 | public FaceManager |
| 760 | { |
| 761 | public: |
| 762 | |
| 763 | ValidatedFaceRequestFixture() |
| 764 | : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face), |
| 765 | m_createFaceFired(false), |
| 766 | m_destroyFaceFired(false) |
| 767 | { |
| 768 | |
| 769 | } |
| 770 | |
| 771 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 772 | createFace(const Interest& request, |
| 773 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 774 | { |
| 775 | m_createFaceFired = true; |
| 776 | } |
| 777 | |
| 778 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 779 | destroyFace(const Interest& request, |
| 780 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 781 | { |
| 782 | m_destroyFaceFired = true; |
| 783 | } |
| 784 | |
| 785 | virtual |
| 786 | ~ValidatedFaceRequestFixture() |
| 787 | { |
| 788 | |
| 789 | } |
| 790 | |
| 791 | bool |
| 792 | didCreateFaceFire() const |
| 793 | { |
| 794 | return m_createFaceFired; |
| 795 | } |
| 796 | |
| 797 | bool |
| 798 | didDestroyFaceFire() const |
| 799 | { |
| 800 | return m_destroyFaceFired; |
| 801 | } |
| 802 | |
| 803 | private: |
| 804 | bool m_createFaceFired; |
| 805 | bool m_destroyFaceFired; |
| 806 | }; |
| 807 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 808 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, |
| 809 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 810 | { |
| 811 | Name commandName("/localhost/nfd/faces"); |
| 812 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 813 | commandName.append("NotReallyParameters"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 814 | |
| 815 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 816 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 817 | |
| 818 | getFace()->onReceiveData += |
| 819 | bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1, |
| 820 | command->getName(), 400, "Malformed command"); |
| 821 | |
| 822 | onValidatedFaceRequest(command); |
| 823 | |
| 824 | BOOST_REQUIRE(didCallbackFire()); |
| 825 | } |
| 826 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 827 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace, |
| 828 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 829 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 830 | ControlParameters parameters; |
| 831 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 832 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 833 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 834 | |
| 835 | Name commandName("/localhost/nfd/faces"); |
| 836 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 837 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 838 | |
| 839 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 840 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 841 | |
| 842 | onValidatedFaceRequest(command); |
| 843 | BOOST_CHECK(didCreateFaceFire()); |
| 844 | } |
| 845 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 846 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace, |
| 847 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 848 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 849 | ControlParameters parameters; |
| 850 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 851 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 852 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 853 | |
| 854 | Name commandName("/localhost/nfd/faces"); |
| 855 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 856 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 857 | |
| 858 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 859 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 860 | |
| 861 | onValidatedFaceRequest(command); |
| 862 | BOOST_CHECK(didDestroyFaceFire()); |
| 863 | } |
| 864 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 865 | class FaceTableFixture |
| 866 | { |
| 867 | public: |
| 868 | FaceTableFixture() |
| 869 | : m_faceTable(m_forwarder) |
| 870 | { |
| 871 | } |
| 872 | |
| 873 | virtual |
| 874 | ~FaceTableFixture() |
| 875 | { |
| 876 | } |
| 877 | |
| 878 | protected: |
| 879 | Forwarder m_forwarder; |
| 880 | FaceTable m_faceTable; |
| 881 | }; |
| 882 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 883 | class LocalControlFixture : public FaceTableFixture, |
| 884 | public TestFaceManagerCommon, |
| 885 | public FaceManager |
| 886 | { |
| 887 | public: |
| 888 | LocalControlFixture() |
| 889 | : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face) |
| 890 | { |
| 891 | } |
| 892 | }; |
| 893 | |
| 894 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId, |
| 895 | AuthorizedCommandFixture<LocalControlFixture>) |
| 896 | { |
| 897 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 898 | BOOST_REQUIRE(dummy->isLocal()); |
| 899 | FaceTableFixture::m_faceTable.add(dummy); |
| 900 | |
| 901 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 902 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 903 | |
| 904 | Block encodedParameters(parameters.wireEncode()); |
| 905 | |
| 906 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 907 | enable.append(encodedParameters); |
| 908 | |
| 909 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 910 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 911 | |
| 912 | generateCommand(*enableCommand); |
| 913 | |
| 914 | TestFaceManagerCommon::m_face->onReceiveData += |
| 915 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 916 | enableCommand->getName(), 200, "Success", encodedParameters); |
| 917 | |
| 918 | onValidatedFaceRequest(enableCommand); |
| 919 | |
| 920 | BOOST_REQUIRE(didCallbackFire()); |
| 921 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 922 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 923 | |
| 924 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 925 | resetCallbackFired(); |
| 926 | |
| 927 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 928 | disable.append(encodedParameters); |
| 929 | |
| 930 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 931 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 932 | |
| 933 | generateCommand(*disableCommand); |
| 934 | |
| 935 | TestFaceManagerCommon::m_face->onReceiveData += |
| 936 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 937 | disableCommand->getName(), 200, "Success", encodedParameters); |
| 938 | |
| 939 | onValidatedFaceRequest(disableCommand); |
| 940 | |
| 941 | BOOST_REQUIRE(didCallbackFire()); |
| 942 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 943 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 944 | } |
| 945 | |
| 946 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound, |
| 947 | AuthorizedCommandFixture<LocalControlFixture>) |
| 948 | { |
| 949 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 950 | BOOST_REQUIRE(dummy->isLocal()); |
| 951 | FaceTableFixture::m_faceTable.add(dummy); |
| 952 | |
| 953 | ControlParameters parameters; |
| 954 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 955 | |
| 956 | Block encodedParameters(parameters.wireEncode()); |
| 957 | |
| 958 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 959 | enable.append(encodedParameters); |
| 960 | |
| 961 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 962 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 963 | |
| 964 | generateCommand(*enableCommand); |
| 965 | |
| 966 | TestFaceManagerCommon::m_face->onReceiveData += |
| 967 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 968 | enableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 969 | |
| 970 | onValidatedFaceRequest(enableCommand); |
| 971 | |
| 972 | BOOST_REQUIRE(didCallbackFire()); |
| 973 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 974 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 975 | |
| 976 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 977 | resetCallbackFired(); |
| 978 | |
| 979 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 980 | disable.append(encodedParameters); |
| 981 | |
| 982 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 983 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 984 | |
| 985 | generateCommand(*disableCommand); |
| 986 | |
| 987 | TestFaceManagerCommon::m_face->onReceiveData += |
| 988 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 989 | disableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 990 | |
| 991 | onValidatedFaceRequest(disableCommand); |
| 992 | |
| 993 | BOOST_REQUIRE(didCallbackFire()); |
| 994 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 995 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 996 | } |
| 997 | |
| 998 | BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature, |
| 999 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1000 | { |
| 1001 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1002 | BOOST_REQUIRE(dummy->isLocal()); |
| 1003 | FaceTableFixture::m_faceTable.add(dummy); |
| 1004 | |
| 1005 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1006 | |
| 1007 | Block encodedParameters(parameters.wireEncode()); |
| 1008 | |
| 1009 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1010 | enable.append(encodedParameters); |
| 1011 | |
| 1012 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1013 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1014 | |
| 1015 | generateCommand(*enableCommand); |
| 1016 | |
| 1017 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1018 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1019 | enableCommand->getName(), 400, "Malformed command"); |
| 1020 | |
| 1021 | onValidatedFaceRequest(enableCommand); |
| 1022 | |
| 1023 | BOOST_REQUIRE(didCallbackFire()); |
| 1024 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1025 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1026 | |
| 1027 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1028 | resetCallbackFired(); |
| 1029 | |
| 1030 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1031 | disable.append(encodedParameters); |
| 1032 | |
| 1033 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1034 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1035 | |
| 1036 | generateCommand(*disableCommand); |
| 1037 | |
| 1038 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1039 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1040 | disableCommand->getName(), 400, "Malformed command"); |
| 1041 | |
| 1042 | onValidatedFaceRequest(disableCommand); |
| 1043 | |
| 1044 | BOOST_REQUIRE(didCallbackFire()); |
| 1045 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1046 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1047 | } |
| 1048 | |
| 1049 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal, |
| 1050 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1051 | { |
| 1052 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1053 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1054 | FaceTableFixture::m_faceTable.add(dummy); |
| 1055 | |
| 1056 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1057 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1058 | |
| 1059 | Block encodedParameters(parameters.wireEncode()); |
| 1060 | |
| 1061 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1062 | enable.append(encodedParameters); |
| 1063 | |
| 1064 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1065 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1066 | |
| 1067 | generateCommand(*enableCommand); |
| 1068 | |
| 1069 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1070 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1071 | enableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1072 | |
| 1073 | onValidatedFaceRequest(enableCommand); |
| 1074 | |
| 1075 | BOOST_REQUIRE(didCallbackFire()); |
| 1076 | |
| 1077 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1078 | resetCallbackFired(); |
| 1079 | |
| 1080 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1081 | enable.append(encodedParameters); |
| 1082 | |
| 1083 | shared_ptr<Interest> disableCommand(make_shared<Interest>(enable)); |
| 1084 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1085 | |
| 1086 | generateCommand(*disableCommand); |
| 1087 | |
| 1088 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1089 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1090 | disableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1091 | |
| 1092 | onValidatedFaceRequest(disableCommand); |
| 1093 | |
| 1094 | BOOST_REQUIRE(didCallbackFire()); |
| 1095 | } |
| 1096 | |
| 1097 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, |
| 1098 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1099 | { |
| 1100 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1101 | BOOST_REQUIRE(dummy->isLocal()); |
| 1102 | FaceTableFixture::m_faceTable.add(dummy); |
| 1103 | |
| 1104 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1105 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1106 | |
| 1107 | Block encodedParameters(parameters.wireEncode()); |
| 1108 | |
| 1109 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1110 | enable.append(encodedParameters); |
| 1111 | |
| 1112 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1113 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1114 | |
| 1115 | generateCommand(*enableCommand); |
| 1116 | |
| 1117 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1118 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1119 | enableCommand->getName(), 200, "Success", encodedParameters); |
| 1120 | |
| 1121 | onValidatedFaceRequest(enableCommand); |
| 1122 | |
| 1123 | BOOST_REQUIRE(didCallbackFire()); |
| 1124 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1125 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1126 | |
| 1127 | |
| 1128 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1129 | resetCallbackFired(); |
| 1130 | |
| 1131 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1132 | disable.append(encodedParameters); |
| 1133 | |
| 1134 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1135 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1136 | |
| 1137 | generateCommand(*disableCommand); |
| 1138 | |
| 1139 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1140 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1141 | disableCommand->getName(), 200, "Success", encodedParameters); |
| 1142 | |
| 1143 | onValidatedFaceRequest(disableCommand); |
| 1144 | |
| 1145 | BOOST_REQUIRE(didCallbackFire()); |
| 1146 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1147 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1148 | } |
| 1149 | |
| 1150 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound, |
| 1151 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1152 | { |
| 1153 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1154 | BOOST_REQUIRE(dummy->isLocal()); |
| 1155 | FaceTableFixture::m_faceTable.add(dummy); |
| 1156 | |
| 1157 | ControlParameters parameters; |
| 1158 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1159 | |
| 1160 | Block encodedParameters(parameters.wireEncode()); |
| 1161 | |
| 1162 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1163 | enable.append(encodedParameters); |
| 1164 | |
| 1165 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1166 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1167 | |
| 1168 | generateCommand(*enableCommand); |
| 1169 | |
| 1170 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1171 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1172 | enableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1173 | |
| 1174 | onValidatedFaceRequest(enableCommand); |
| 1175 | |
| 1176 | BOOST_REQUIRE(didCallbackFire()); |
| 1177 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1178 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1179 | |
| 1180 | |
| 1181 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1182 | resetCallbackFired(); |
| 1183 | |
| 1184 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1185 | disable.append(encodedParameters); |
| 1186 | |
| 1187 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1188 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1189 | |
| 1190 | generateCommand(*disableCommand); |
| 1191 | |
| 1192 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1193 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1194 | disableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1195 | |
| 1196 | onValidatedFaceRequest(disableCommand); |
| 1197 | |
| 1198 | BOOST_REQUIRE(didCallbackFire()); |
| 1199 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1200 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1201 | } |
| 1202 | |
| 1203 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, |
| 1204 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1205 | { |
| 1206 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1207 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1208 | FaceTableFixture::m_faceTable.add(dummy); |
| 1209 | |
| 1210 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1211 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1212 | |
| 1213 | Block encodedParameters(parameters.wireEncode()); |
| 1214 | |
| 1215 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1216 | enable.append(encodedParameters); |
| 1217 | |
| 1218 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1219 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1220 | |
| 1221 | generateCommand(*enableCommand); |
| 1222 | |
| 1223 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1224 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1225 | enableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1226 | |
| 1227 | onValidatedFaceRequest(enableCommand); |
| 1228 | |
| 1229 | BOOST_REQUIRE(didCallbackFire()); |
| 1230 | |
| 1231 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1232 | resetCallbackFired(); |
| 1233 | |
| 1234 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1235 | disable.append(encodedParameters); |
| 1236 | |
| 1237 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1238 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1239 | |
| 1240 | generateCommand(*disableCommand); |
| 1241 | |
| 1242 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1243 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1244 | disableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1245 | |
| 1246 | onValidatedFaceRequest(disableCommand); |
| 1247 | |
| 1248 | BOOST_REQUIRE(didCallbackFire()); |
| 1249 | } |
| 1250 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1251 | class FaceFixture : public FaceTableFixture, |
| 1252 | public TestFaceManagerCommon, |
| 1253 | public FaceManager |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1254 | { |
| 1255 | public: |
| 1256 | FaceFixture() |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1257 | : FaceManager(FaceTableFixture::m_faceTable, |
| 1258 | TestFaceManagerCommon::m_face) |
| 1259 | , m_receivedNotification(false) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1260 | { |
| 1261 | |
| 1262 | } |
| 1263 | |
| 1264 | virtual |
| 1265 | ~FaceFixture() |
| 1266 | { |
| 1267 | |
| 1268 | } |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1269 | |
| 1270 | void |
| 1271 | callbackDispatch(const Data& response, |
| 1272 | const Name& expectedName, |
| 1273 | uint32_t expectedCode, |
| 1274 | const std::string& expectedText, |
| 1275 | const Block& expectedBody, |
| 1276 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1277 | { |
| 1278 | Block payload = response.getContent().blockFromValue(); |
| 1279 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1280 | { |
| 1281 | validateControlResponse(response, expectedName, expectedCode, |
| 1282 | expectedText, expectedBody); |
| 1283 | } |
| 1284 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1285 | { |
| 1286 | validateFaceEvent(payload, expectedFaceEvent); |
| 1287 | } |
| 1288 | else |
| 1289 | { |
| 1290 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | void |
| 1295 | callbackDispatch(const Data& response, |
| 1296 | const Name& expectedName, |
| 1297 | uint32_t expectedCode, |
| 1298 | const std::string& expectedText, |
| 1299 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1300 | { |
| 1301 | Block payload = response.getContent().blockFromValue(); |
| 1302 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1303 | { |
| 1304 | validateControlResponse(response, expectedName, |
| 1305 | expectedCode, expectedText); |
| 1306 | } |
| 1307 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1308 | { |
| 1309 | validateFaceEvent(payload, expectedFaceEvent); |
| 1310 | } |
| 1311 | else |
| 1312 | { |
| 1313 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | void |
| 1318 | validateFaceEvent(const Block& wire, |
| 1319 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1320 | { |
| 1321 | |
| 1322 | m_receivedNotification = true; |
| 1323 | |
| 1324 | ndn::nfd::FaceEventNotification notification(wire); |
| 1325 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1326 | BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1327 | BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId()); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1328 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri()); |
| 1329 | BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | bool |
| 1333 | didReceiveNotication() const |
| 1334 | { |
| 1335 | return m_receivedNotification; |
| 1336 | } |
| 1337 | |
| 1338 | protected: |
| 1339 | bool m_receivedNotification; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1340 | }; |
| 1341 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1342 | BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1343 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1344 | ControlParameters parameters; |
| 1345 | parameters.setUri("tcp:/127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1346 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1347 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1348 | |
| 1349 | Name commandName("/localhost/nfd/faces"); |
| 1350 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1351 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1352 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1353 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1354 | generateCommand(*command); |
| 1355 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1356 | getFace()->onReceiveData += |
| 1357 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1358 | command->getName(), 400, "Malformed command"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1359 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1360 | createFace(*command, parameters); |
| 1361 | |
| 1362 | BOOST_REQUIRE(didCallbackFire()); |
| 1363 | } |
| 1364 | |
| 1365 | BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) |
| 1366 | { |
| 1367 | ControlParameters parameters; |
| 1368 | |
| 1369 | Block encodedParameters(parameters.wireEncode()); |
| 1370 | |
| 1371 | Name commandName("/localhost/nfd/faces"); |
| 1372 | commandName.append("create"); |
| 1373 | commandName.append(encodedParameters); |
| 1374 | |
| 1375 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1376 | generateCommand(*command); |
| 1377 | |
| 1378 | getFace()->onReceiveData += |
| 1379 | bind(&FaceFixture::validateControlResponse, this, _1, |
| 1380 | command->getName(), 400, "Malformed command"); |
| 1381 | |
| 1382 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1383 | |
| 1384 | BOOST_REQUIRE(didCallbackFire()); |
| 1385 | } |
| 1386 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1387 | BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1388 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1389 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1390 | // this will be an unsupported protocol because no factories have been |
| 1391 | // added to the face manager |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1392 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1393 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1394 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1395 | |
| 1396 | Name commandName("/localhost/nfd/faces"); |
| 1397 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1398 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1399 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1400 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1401 | generateCommand(*command); |
| 1402 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1403 | getFace()->onReceiveData += |
| 1404 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1405 | command->getName(), 501, "Unsupported protocol"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1406 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1407 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1408 | |
| 1409 | BOOST_REQUIRE(didCallbackFire()); |
| 1410 | } |
| 1411 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1412 | BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1413 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1414 | ControlParameters parameters; |
| 1415 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1416 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1417 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1418 | |
| 1419 | Name commandName("/localhost/nfd/faces"); |
| 1420 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1421 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1422 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1423 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1424 | generateCommand(*command); |
| 1425 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1426 | ControlParameters resultParameters; |
| 1427 | resultParameters.setUri("tcp://127.0.0.1"); |
| 1428 | resultParameters.setFaceId(1); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1429 | |
| 1430 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1431 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1432 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1433 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) |
| 1434 | .setFaceId(1) |
| 1435 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1436 | .setLocalUri(dummy->getLocalUri().toString()) |
| 1437 | .setFlags(0); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1438 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1439 | Block encodedResultParameters(resultParameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1440 | |
| 1441 | getFace()->onReceiveData += |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1442 | bind(&FaceFixture::callbackDispatch, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1443 | command->getName(), 200, "Success", |
| 1444 | encodedResultParameters, expectedFaceEvent); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1445 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1446 | onCreated(command->getName(), parameters, dummy); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1447 | |
| 1448 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1449 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1452 | BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1453 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1454 | ControlParameters parameters; |
| 1455 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1456 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1457 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1458 | |
| 1459 | Name commandName("/localhost/nfd/faces"); |
| 1460 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1461 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1462 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1463 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1464 | generateCommand(*command); |
| 1465 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1466 | getFace()->onReceiveData += |
| 1467 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 1468 | command->getName(), 408, "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1469 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1470 | onConnectFailed(command->getName(), "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1471 | |
| 1472 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1473 | BOOST_CHECK_EQUAL(didReceiveNotication(), false); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1477 | BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1478 | { |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1479 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1480 | FaceTableFixture::m_faceTable.add(dummy); |
| 1481 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1482 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1483 | parameters.setFaceId(dummy->getId()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1484 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1485 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1486 | |
| 1487 | Name commandName("/localhost/nfd/faces"); |
| 1488 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1489 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1490 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1491 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1492 | generateCommand(*command); |
| 1493 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1494 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1495 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 1496 | .setFaceId(dummy->getId()) |
| 1497 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1498 | .setLocalUri(dummy->getLocalUri().toString()) |
| 1499 | .setFlags(0); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1500 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1501 | getFace()->onReceiveData += |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1502 | bind(&FaceFixture::callbackDispatch, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1503 | command->getName(), 200, "Success", boost::ref(encodedParameters), expectedFaceEvent); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1504 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1505 | destroyFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1506 | |
| 1507 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1508 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1511 | class FaceListFixture : public FaceStatusPublisherFixture |
| 1512 | { |
| 1513 | public: |
| 1514 | FaceListFixture() |
| 1515 | : m_manager(m_table, m_face) |
| 1516 | { |
| 1517 | |
| 1518 | } |
| 1519 | |
| 1520 | virtual |
| 1521 | ~FaceListFixture() |
| 1522 | { |
| 1523 | |
| 1524 | } |
| 1525 | |
| 1526 | protected: |
| 1527 | FaceManager m_manager; |
| 1528 | }; |
| 1529 | |
| 1530 | BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) |
| 1531 | |
| 1532 | { |
| 1533 | Name commandName("/localhost/nfd/faces/list"); |
| 1534 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1535 | |
| 1536 | // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 55 |
| 1537 | // 55 divides 4400 (== 80), so only use 79 FaceStatuses and then two smaller ones |
| 1538 | // to force a FaceStatus to span Data packets |
| 1539 | for (int i = 0; i < 79; i++) |
| 1540 | { |
| 1541 | shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>()); |
| 1542 | |
| 1543 | uint64_t filler = std::numeric_limits<uint64_t>::max() - 1; |
| 1544 | dummy->setCounters(filler, filler, filler, filler); |
| 1545 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 1546 | m_referenceFaces.push_back(dummy); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1547 | |
| 1548 | add(dummy); |
| 1549 | } |
| 1550 | |
| 1551 | for (int i = 0; i < 2; i++) |
| 1552 | { |
| 1553 | shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>()); |
| 1554 | uint64_t filler = std::numeric_limits<uint32_t>::max() - 1; |
| 1555 | dummy->setCounters(filler, filler, filler, filler); |
| 1556 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 1557 | m_referenceFaces.push_back(dummy); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1558 | |
| 1559 | add(dummy); |
| 1560 | } |
| 1561 | |
| 1562 | ndn::EncodingBuffer buffer; |
| 1563 | |
| 1564 | m_face->onReceiveData += |
| 1565 | bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1); |
| 1566 | |
| 1567 | m_manager.listFaces(*command); |
| 1568 | BOOST_REQUIRE(m_finished); |
| 1569 | } |
| 1570 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1571 | BOOST_AUTO_TEST_SUITE_END() |
| 1572 | |
| 1573 | } // namespace tests |
| 1574 | } // namespace nfd |
| 1575 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1576 | |