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