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