Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [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 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 25 | |
| 26 | #include "mgmt/face-manager.hpp" |
| 27 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 28 | #include "mgmt/face-status-publisher.hpp" |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 29 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 30 | #include "face/face.hpp" |
| 31 | #include "../face/dummy-face.hpp" |
| 32 | #include "fw/face-table.hpp" |
| 33 | #include "fw/forwarder.hpp" |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 34 | #include "face/udp-factory.hpp" |
| 35 | #include "face/ethernet-factory.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 36 | |
| 37 | #include "common.hpp" |
| 38 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 39 | #include "validation-common.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 40 | #include "face-status-publisher-common.hpp" |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 41 | #include "channel-status-common.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 42 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 43 | #include <ndn-cxx/encoding/tlv.hpp> |
| 44 | #include <ndn-cxx/management/nfd-face-event-notification.hpp> |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 45 | |
| 46 | namespace nfd { |
| 47 | namespace tests { |
| 48 | |
| 49 | NFD_LOG_INIT("FaceManagerTest"); |
| 50 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 51 | class FaceManagerTestFace : public DummyFace |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 55 | FaceManagerTestFace() |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 56 | : m_closeFired(false) |
| 57 | { |
| 58 | |
| 59 | } |
| 60 | |
| 61 | virtual |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 62 | ~FaceManagerTestFace() |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 63 | { |
| 64 | |
| 65 | } |
| 66 | |
| 67 | virtual void |
| 68 | close() |
| 69 | { |
| 70 | m_closeFired = true; |
| 71 | } |
| 72 | |
| 73 | bool |
| 74 | didCloseFire() const |
| 75 | { |
| 76 | return m_closeFired; |
| 77 | } |
| 78 | |
| 79 | private: |
| 80 | bool m_closeFired; |
| 81 | }; |
| 82 | |
| 83 | class TestFaceTable : public FaceTable |
| 84 | { |
| 85 | public: |
| 86 | TestFaceTable(Forwarder& forwarder) |
| 87 | : FaceTable(forwarder), |
| 88 | m_addFired(false), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 89 | m_getFired(false), |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 90 | m_dummy(make_shared<FaceManagerTestFace>()) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 91 | { |
| 92 | |
| 93 | } |
| 94 | |
| 95 | virtual |
| 96 | ~TestFaceTable() |
| 97 | { |
| 98 | |
| 99 | } |
| 100 | |
| 101 | virtual void |
| 102 | add(shared_ptr<Face> face) |
| 103 | { |
| 104 | m_addFired = true; |
| 105 | } |
| 106 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 107 | virtual shared_ptr<Face> |
| 108 | get(FaceId id) const |
| 109 | { |
| 110 | m_getFired = true; |
| 111 | return m_dummy; |
| 112 | } |
| 113 | |
| 114 | bool |
| 115 | didAddFire() const |
| 116 | { |
| 117 | return m_addFired; |
| 118 | } |
| 119 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 120 | bool |
| 121 | didGetFire() const |
| 122 | { |
| 123 | return m_getFired; |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | reset() |
| 128 | { |
| 129 | m_addFired = false; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 130 | m_getFired = false; |
| 131 | } |
| 132 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 133 | shared_ptr<FaceManagerTestFace>& |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 134 | getDummyFace() |
| 135 | { |
| 136 | return m_dummy; |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | bool m_addFired; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 141 | mutable bool m_getFired; |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 142 | shared_ptr<FaceManagerTestFace> m_dummy; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | |
| 146 | class TestFaceTableFixture : public BaseFixture |
| 147 | { |
| 148 | public: |
| 149 | TestFaceTableFixture() |
| 150 | : m_faceTable(m_forwarder) |
| 151 | { |
| 152 | |
| 153 | } |
| 154 | |
| 155 | virtual |
| 156 | ~TestFaceTableFixture() |
| 157 | { |
| 158 | |
| 159 | } |
| 160 | |
| 161 | protected: |
| 162 | Forwarder m_forwarder; |
| 163 | TestFaceTable m_faceTable; |
| 164 | }; |
| 165 | |
| 166 | class TestFaceManagerCommon |
| 167 | { |
| 168 | public: |
| 169 | TestFaceManagerCommon() |
| 170 | : m_face(make_shared<InternalFace>()), |
| 171 | m_callbackFired(false) |
| 172 | { |
| 173 | |
| 174 | } |
| 175 | |
| 176 | virtual |
| 177 | ~TestFaceManagerCommon() |
| 178 | { |
| 179 | |
| 180 | } |
| 181 | |
| 182 | shared_ptr<InternalFace>& |
| 183 | getFace() |
| 184 | { |
| 185 | return m_face; |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | validateControlResponseCommon(const Data& response, |
| 190 | const Name& expectedName, |
| 191 | uint32_t expectedCode, |
| 192 | const std::string& expectedText, |
| 193 | ControlResponse& control) |
| 194 | { |
| 195 | m_callbackFired = true; |
| 196 | Block controlRaw = response.getContent().blockFromValue(); |
| 197 | |
| 198 | control.wireDecode(controlRaw); |
| 199 | |
| 200 | // NFD_LOG_DEBUG("received control response" |
| 201 | // << " Name: " << response.getName() |
| 202 | // << " code: " << control.getCode() |
| 203 | // << " text: " << control.getText()); |
| 204 | |
| 205 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 206 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 207 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
| 208 | } |
| 209 | |
| 210 | void |
| 211 | validateControlResponse(const Data& response, |
| 212 | const Name& expectedName, |
| 213 | uint32_t expectedCode, |
| 214 | const std::string& expectedText) |
| 215 | { |
| 216 | ControlResponse control; |
| 217 | validateControlResponseCommon(response, expectedName, |
| 218 | expectedCode, expectedText, control); |
| 219 | |
| 220 | if (!control.getBody().empty()) |
| 221 | { |
| 222 | BOOST_FAIL("found unexpected control response body"); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | validateControlResponse(const Data& response, |
| 228 | const Name& expectedName, |
| 229 | uint32_t expectedCode, |
| 230 | const std::string& expectedText, |
| 231 | const Block& expectedBody) |
| 232 | { |
| 233 | ControlResponse control; |
| 234 | validateControlResponseCommon(response, expectedName, |
| 235 | expectedCode, expectedText, control); |
| 236 | |
| 237 | BOOST_REQUIRE(!control.getBody().empty()); |
| 238 | BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size()); |
| 239 | |
| 240 | BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(), |
| 241 | expectedBody.value_size()) == 0); |
| 242 | |
| 243 | } |
| 244 | |
| 245 | bool |
| 246 | didCallbackFire() const |
| 247 | { |
| 248 | return m_callbackFired; |
| 249 | } |
| 250 | |
| 251 | void |
| 252 | resetCallbackFired() |
| 253 | { |
| 254 | m_callbackFired = false; |
| 255 | } |
| 256 | |
| 257 | protected: |
| 258 | shared_ptr<InternalFace> m_face; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 314 | protected: |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 674 | if (factory->getMulticastFaces().size() == 0) { |
| 675 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 676 | "no UDP multicast faces are available"); |
| 677 | } |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 678 | |
| 679 | const std::string CONFIG_WITHOUT_MCAST = |
| 680 | "face_system\n" |
| 681 | "{\n" |
| 682 | " udp\n" |
| 683 | " {\n" |
| 684 | " mcast no\n" |
| 685 | " }\n" |
| 686 | "}\n"; |
| 687 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
| 688 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 689 | } |
| 690 | |
| 691 | |
Alexander Afanasyev | 885a85b | 2014-04-12 21:01:13 -0700 | [diff] [blame] | 692 | #ifdef HAVE_LIBPCAP |
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 | BOOST_AUTO_TEST_CASE(TestProcessSectionEther) |
| 695 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 696 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 697 | const std::string CONFIG = |
| 698 | "face_system\n" |
| 699 | "{\n" |
| 700 | " ether\n" |
| 701 | " {\n" |
| 702 | " mcast yes\n" |
| 703 | " mcast_group 01:00:5E:00:17:AA\n" |
| 704 | " }\n" |
| 705 | "}\n"; |
| 706 | |
| 707 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 708 | } |
| 709 | |
| 710 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun) |
| 711 | { |
| 712 | const std::string CONFIG = |
| 713 | "face_system\n" |
| 714 | "{\n" |
| 715 | " ether\n" |
| 716 | " {\n" |
| 717 | " mcast yes\n" |
| 718 | " mcast_group 01:00:5E:00:17:AA\n" |
| 719 | " }\n" |
| 720 | "}\n"; |
| 721 | |
| 722 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 723 | } |
| 724 | |
| 725 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast) |
| 726 | { |
| 727 | const std::string CONFIG = |
| 728 | "face_system\n" |
| 729 | "{\n" |
| 730 | " ether\n" |
| 731 | " {\n" |
| 732 | " mcast hello\n" |
| 733 | " }\n" |
| 734 | "}\n"; |
| 735 | |
| 736 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 737 | bind(&isExpectedException, _1, |
| 738 | "Invalid value for option \"mcast\" in \"ether\" section")); |
| 739 | } |
| 740 | |
| 741 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup) |
| 742 | { |
| 743 | const std::string CONFIG = |
| 744 | "face_system\n" |
| 745 | "{\n" |
| 746 | " ether\n" |
| 747 | " {\n" |
| 748 | " mcast yes\n" |
| 749 | " mcast_group\n" |
| 750 | " }\n" |
| 751 | "}\n"; |
| 752 | |
| 753 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 754 | bind(&isExpectedException, _1, |
| 755 | "Invalid value for option \"mcast_group\" in \"ether\" section")); |
| 756 | } |
| 757 | |
| 758 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption) |
| 759 | { |
| 760 | const std::string CONFIG = |
| 761 | "face_system\n" |
| 762 | "{\n" |
| 763 | " ether\n" |
| 764 | " {\n" |
| 765 | " hello\n" |
| 766 | " }\n" |
| 767 | "}\n"; |
| 768 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 769 | bind(&isExpectedException, _1, |
| 770 | "Unrecognized option \"hello\" in \"ether\" section")); |
| 771 | } |
| 772 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 773 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit) |
| 774 | { |
| 775 | const std::string CONFIG_WITH_MCAST = |
| 776 | "face_system\n" |
| 777 | "{\n" |
| 778 | " ether\n" |
| 779 | " {\n" |
| 780 | " mcast yes\n" |
| 781 | " }\n" |
| 782 | "}\n"; |
| 783 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 784 | |
| 785 | shared_ptr<EthernetFactory> factory = |
| 786 | static_pointer_cast<EthernetFactory>(getManager().findFactory("ether")); |
| 787 | BOOST_REQUIRE(static_cast<bool>(factory)); |
| 788 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 789 | if (factory->getMulticastFaces().size() == 0) { |
| 790 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 791 | "no Ethernet multicast faces are available"); |
| 792 | } |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 793 | |
| 794 | const std::string CONFIG_WITHOUT_MCAST = |
| 795 | "face_system\n" |
| 796 | "{\n" |
| 797 | " ether\n" |
| 798 | " {\n" |
| 799 | " mcast no\n" |
| 800 | " }\n" |
| 801 | "}\n"; |
| 802 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
| 803 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 804 | } |
| 805 | |
| 806 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 807 | #endif |
| 808 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 809 | BOOST_AUTO_TEST_CASE(TestFireInterestFilter) |
| 810 | { |
| 811 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 812 | |
| 813 | getFace()->onReceiveData += |
| 814 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 815 | command->getName(), 400, "Malformed command"); |
| 816 | |
| 817 | getFace()->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 818 | g_io.run_one(); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 819 | |
| 820 | BOOST_REQUIRE(didCallbackFire()); |
| 821 | } |
| 822 | |
| 823 | BOOST_AUTO_TEST_CASE(MalformedCommmand) |
| 824 | { |
| 825 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 826 | |
| 827 | getFace()->onReceiveData += |
| 828 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 829 | command->getName(), 400, "Malformed command"); |
| 830 | |
| 831 | getManager().onFaceRequest(*command); |
| 832 | |
| 833 | BOOST_REQUIRE(didCallbackFire()); |
| 834 | } |
| 835 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 836 | BOOST_AUTO_TEST_CASE(UnsignedCommand) |
| 837 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 838 | ControlParameters parameters; |
| 839 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 840 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 841 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 842 | |
| 843 | Name commandName("/localhost/nfd/faces"); |
| 844 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 845 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 846 | |
| 847 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 848 | |
| 849 | getFace()->onReceiveData += |
| 850 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 851 | command->getName(), 401, "Signature required"); |
| 852 | |
| 853 | getManager().onFaceRequest(*command); |
| 854 | |
| 855 | BOOST_REQUIRE(didCallbackFire()); |
| 856 | } |
| 857 | |
| 858 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>) |
| 859 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 860 | ControlParameters parameters; |
| 861 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 862 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 863 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 864 | |
| 865 | Name commandName("/localhost/nfd/faces"); |
| 866 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 867 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 868 | |
| 869 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 870 | generateCommand(*command); |
| 871 | |
| 872 | getFace()->onReceiveData += |
| 873 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 874 | command->getName(), 403, "Unauthorized command"); |
| 875 | |
| 876 | getManager().onFaceRequest(*command); |
| 877 | |
| 878 | BOOST_REQUIRE(didCallbackFire()); |
| 879 | } |
| 880 | |
| 881 | template <typename T> class AuthorizedCommandFixture : public CommandFixture<T> |
| 882 | { |
| 883 | public: |
| 884 | AuthorizedCommandFixture() |
| 885 | { |
| 886 | const std::string regex = "^<localhost><nfd><faces>"; |
| 887 | T::addInterestRule(regex, *CommandFixture<T>::m_certificate); |
| 888 | } |
| 889 | |
| 890 | virtual |
| 891 | ~AuthorizedCommandFixture() |
| 892 | { |
| 893 | |
| 894 | } |
| 895 | }; |
| 896 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 897 | BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 898 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 899 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 900 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 901 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 902 | |
| 903 | Name commandName("/localhost/nfd/faces"); |
| 904 | commandName.append("unsupported"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 905 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 906 | |
| 907 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 908 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 909 | |
| 910 | getFace()->onReceiveData += |
| 911 | bind(&FaceManagerFixture::validateControlResponse, this, _1, |
| 912 | command->getName(), 501, "Unsupported command"); |
| 913 | |
| 914 | getManager().onFaceRequest(*command); |
| 915 | |
| 916 | BOOST_REQUIRE(didCallbackFire()); |
| 917 | } |
| 918 | |
| 919 | class ValidatedFaceRequestFixture : public TestFaceTableFixture, |
| 920 | public TestFaceManagerCommon, |
| 921 | public FaceManager |
| 922 | { |
| 923 | public: |
| 924 | |
| 925 | ValidatedFaceRequestFixture() |
| 926 | : FaceManager(TestFaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face), |
| 927 | m_createFaceFired(false), |
| 928 | m_destroyFaceFired(false) |
| 929 | { |
| 930 | |
| 931 | } |
| 932 | |
| 933 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 934 | createFace(const Interest& request, |
| 935 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 936 | { |
| 937 | m_createFaceFired = true; |
| 938 | } |
| 939 | |
| 940 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 941 | destroyFace(const Interest& request, |
| 942 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 943 | { |
| 944 | m_destroyFaceFired = true; |
| 945 | } |
| 946 | |
| 947 | virtual |
| 948 | ~ValidatedFaceRequestFixture() |
| 949 | { |
| 950 | |
| 951 | } |
| 952 | |
| 953 | bool |
| 954 | didCreateFaceFire() const |
| 955 | { |
| 956 | return m_createFaceFired; |
| 957 | } |
| 958 | |
| 959 | bool |
| 960 | didDestroyFaceFire() const |
| 961 | { |
| 962 | return m_destroyFaceFired; |
| 963 | } |
| 964 | |
| 965 | private: |
| 966 | bool m_createFaceFired; |
| 967 | bool m_destroyFaceFired; |
| 968 | }; |
| 969 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 970 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, |
| 971 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 972 | { |
| 973 | Name commandName("/localhost/nfd/faces"); |
| 974 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 975 | commandName.append("NotReallyParameters"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 976 | |
| 977 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 978 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 979 | |
| 980 | getFace()->onReceiveData += |
| 981 | bind(&ValidatedFaceRequestFixture::validateControlResponse, this, _1, |
| 982 | command->getName(), 400, "Malformed command"); |
| 983 | |
| 984 | onValidatedFaceRequest(command); |
| 985 | |
| 986 | BOOST_REQUIRE(didCallbackFire()); |
| 987 | } |
| 988 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 989 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace, |
| 990 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 991 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 992 | ControlParameters parameters; |
| 993 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 994 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 995 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 996 | |
| 997 | Name commandName("/localhost/nfd/faces"); |
| 998 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 999 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1000 | |
| 1001 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1002 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1003 | |
| 1004 | onValidatedFaceRequest(command); |
| 1005 | BOOST_CHECK(didCreateFaceFire()); |
| 1006 | } |
| 1007 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1008 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace, |
| 1009 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1010 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1011 | ControlParameters parameters; |
| 1012 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1013 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1014 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1015 | |
| 1016 | Name commandName("/localhost/nfd/faces"); |
| 1017 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1018 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1019 | |
| 1020 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1021 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1022 | |
| 1023 | onValidatedFaceRequest(command); |
| 1024 | BOOST_CHECK(didDestroyFaceFire()); |
| 1025 | } |
| 1026 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1027 | class FaceTableFixture |
| 1028 | { |
| 1029 | public: |
| 1030 | FaceTableFixture() |
| 1031 | : m_faceTable(m_forwarder) |
| 1032 | { |
| 1033 | } |
| 1034 | |
| 1035 | virtual |
| 1036 | ~FaceTableFixture() |
| 1037 | { |
| 1038 | } |
| 1039 | |
| 1040 | protected: |
| 1041 | Forwarder m_forwarder; |
| 1042 | FaceTable m_faceTable; |
| 1043 | }; |
| 1044 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1045 | class LocalControlFixture : public FaceTableFixture, |
| 1046 | public TestFaceManagerCommon, |
| 1047 | public FaceManager |
| 1048 | { |
| 1049 | public: |
| 1050 | LocalControlFixture() |
| 1051 | : FaceManager(FaceTableFixture::m_faceTable, TestFaceManagerCommon::m_face) |
| 1052 | { |
| 1053 | } |
| 1054 | }; |
| 1055 | |
| 1056 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId, |
| 1057 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1058 | { |
| 1059 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1060 | BOOST_REQUIRE(dummy->isLocal()); |
| 1061 | FaceTableFixture::m_faceTable.add(dummy); |
| 1062 | |
| 1063 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1064 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1065 | |
| 1066 | Block encodedParameters(parameters.wireEncode()); |
| 1067 | |
| 1068 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1069 | enable.append(encodedParameters); |
| 1070 | |
| 1071 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1072 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1073 | |
| 1074 | generateCommand(*enableCommand); |
| 1075 | |
| 1076 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1077 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1078 | enableCommand->getName(), 200, "Success", encodedParameters); |
| 1079 | |
| 1080 | onValidatedFaceRequest(enableCommand); |
| 1081 | |
| 1082 | BOOST_REQUIRE(didCallbackFire()); |
| 1083 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1084 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1085 | |
| 1086 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1087 | resetCallbackFired(); |
| 1088 | |
| 1089 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1090 | disable.append(encodedParameters); |
| 1091 | |
| 1092 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1093 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1094 | |
| 1095 | generateCommand(*disableCommand); |
| 1096 | |
| 1097 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1098 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1099 | disableCommand->getName(), 200, "Success", encodedParameters); |
| 1100 | |
| 1101 | onValidatedFaceRequest(disableCommand); |
| 1102 | |
| 1103 | BOOST_REQUIRE(didCallbackFire()); |
| 1104 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1105 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1106 | } |
| 1107 | |
| 1108 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound, |
| 1109 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1110 | { |
| 1111 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1112 | BOOST_REQUIRE(dummy->isLocal()); |
| 1113 | FaceTableFixture::m_faceTable.add(dummy); |
| 1114 | |
| 1115 | ControlParameters parameters; |
| 1116 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1117 | |
| 1118 | Block encodedParameters(parameters.wireEncode()); |
| 1119 | |
| 1120 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1121 | enable.append(encodedParameters); |
| 1122 | |
| 1123 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1124 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1125 | |
| 1126 | generateCommand(*enableCommand); |
| 1127 | |
| 1128 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1129 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1130 | enableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1131 | |
| 1132 | onValidatedFaceRequest(enableCommand); |
| 1133 | |
| 1134 | BOOST_REQUIRE(didCallbackFire()); |
| 1135 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1136 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1137 | |
| 1138 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1139 | resetCallbackFired(); |
| 1140 | |
| 1141 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1142 | disable.append(encodedParameters); |
| 1143 | |
| 1144 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1145 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1146 | |
| 1147 | generateCommand(*disableCommand); |
| 1148 | |
| 1149 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1150 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1151 | disableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1152 | |
| 1153 | onValidatedFaceRequest(disableCommand); |
| 1154 | |
| 1155 | BOOST_REQUIRE(didCallbackFire()); |
| 1156 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1157 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1158 | } |
| 1159 | |
| 1160 | BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature, |
| 1161 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1162 | { |
| 1163 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1164 | BOOST_REQUIRE(dummy->isLocal()); |
| 1165 | FaceTableFixture::m_faceTable.add(dummy); |
| 1166 | |
| 1167 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1168 | |
| 1169 | Block encodedParameters(parameters.wireEncode()); |
| 1170 | |
| 1171 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1172 | enable.append(encodedParameters); |
| 1173 | |
| 1174 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1175 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1176 | |
| 1177 | generateCommand(*enableCommand); |
| 1178 | |
| 1179 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1180 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1181 | enableCommand->getName(), 400, "Malformed command"); |
| 1182 | |
| 1183 | onValidatedFaceRequest(enableCommand); |
| 1184 | |
| 1185 | BOOST_REQUIRE(didCallbackFire()); |
| 1186 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1187 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1188 | |
| 1189 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1190 | resetCallbackFired(); |
| 1191 | |
| 1192 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1193 | disable.append(encodedParameters); |
| 1194 | |
| 1195 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1196 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1197 | |
| 1198 | generateCommand(*disableCommand); |
| 1199 | |
| 1200 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1201 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1202 | disableCommand->getName(), 400, "Malformed command"); |
| 1203 | |
| 1204 | onValidatedFaceRequest(disableCommand); |
| 1205 | |
| 1206 | BOOST_REQUIRE(didCallbackFire()); |
| 1207 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1208 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1209 | } |
| 1210 | |
| 1211 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal, |
| 1212 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1213 | { |
| 1214 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1215 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1216 | FaceTableFixture::m_faceTable.add(dummy); |
| 1217 | |
| 1218 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1219 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1220 | |
| 1221 | Block encodedParameters(parameters.wireEncode()); |
| 1222 | |
| 1223 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1224 | enable.append(encodedParameters); |
| 1225 | |
| 1226 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1227 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1228 | |
| 1229 | generateCommand(*enableCommand); |
| 1230 | |
| 1231 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1232 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1233 | enableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1234 | |
| 1235 | onValidatedFaceRequest(enableCommand); |
| 1236 | |
| 1237 | BOOST_REQUIRE(didCallbackFire()); |
| 1238 | |
| 1239 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1240 | resetCallbackFired(); |
| 1241 | |
| 1242 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1243 | enable.append(encodedParameters); |
| 1244 | |
| 1245 | shared_ptr<Interest> disableCommand(make_shared<Interest>(enable)); |
| 1246 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1247 | |
| 1248 | generateCommand(*disableCommand); |
| 1249 | |
| 1250 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1251 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1252 | disableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1253 | |
| 1254 | onValidatedFaceRequest(disableCommand); |
| 1255 | |
| 1256 | BOOST_REQUIRE(didCallbackFire()); |
| 1257 | } |
| 1258 | |
| 1259 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, |
| 1260 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1261 | { |
| 1262 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1263 | BOOST_REQUIRE(dummy->isLocal()); |
| 1264 | FaceTableFixture::m_faceTable.add(dummy); |
| 1265 | |
| 1266 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1267 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1268 | |
| 1269 | Block encodedParameters(parameters.wireEncode()); |
| 1270 | |
| 1271 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1272 | enable.append(encodedParameters); |
| 1273 | |
| 1274 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1275 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1276 | |
| 1277 | generateCommand(*enableCommand); |
| 1278 | |
| 1279 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1280 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1281 | enableCommand->getName(), 200, "Success", encodedParameters); |
| 1282 | |
| 1283 | onValidatedFaceRequest(enableCommand); |
| 1284 | |
| 1285 | BOOST_REQUIRE(didCallbackFire()); |
| 1286 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1287 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1288 | |
| 1289 | |
| 1290 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1291 | resetCallbackFired(); |
| 1292 | |
| 1293 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1294 | disable.append(encodedParameters); |
| 1295 | |
| 1296 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1297 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1298 | |
| 1299 | generateCommand(*disableCommand); |
| 1300 | |
| 1301 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1302 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
| 1303 | disableCommand->getName(), 200, "Success", encodedParameters); |
| 1304 | |
| 1305 | onValidatedFaceRequest(disableCommand); |
| 1306 | |
| 1307 | BOOST_REQUIRE(didCallbackFire()); |
| 1308 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1309 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1310 | } |
| 1311 | |
| 1312 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound, |
| 1313 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1314 | { |
| 1315 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1316 | BOOST_REQUIRE(dummy->isLocal()); |
| 1317 | FaceTableFixture::m_faceTable.add(dummy); |
| 1318 | |
| 1319 | ControlParameters parameters; |
| 1320 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1321 | |
| 1322 | Block encodedParameters(parameters.wireEncode()); |
| 1323 | |
| 1324 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1325 | enable.append(encodedParameters); |
| 1326 | |
| 1327 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1328 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1329 | |
| 1330 | generateCommand(*enableCommand); |
| 1331 | |
| 1332 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1333 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1334 | enableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1335 | |
| 1336 | onValidatedFaceRequest(enableCommand); |
| 1337 | |
| 1338 | BOOST_REQUIRE(didCallbackFire()); |
| 1339 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1340 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1341 | |
| 1342 | |
| 1343 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1344 | resetCallbackFired(); |
| 1345 | |
| 1346 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1347 | disable.append(encodedParameters); |
| 1348 | |
| 1349 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1350 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1351 | |
| 1352 | generateCommand(*disableCommand); |
| 1353 | |
| 1354 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1355 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1356 | disableCommand->getName(), 410, "Face not found"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1357 | |
| 1358 | onValidatedFaceRequest(disableCommand); |
| 1359 | |
| 1360 | BOOST_REQUIRE(didCallbackFire()); |
| 1361 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1362 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1363 | } |
| 1364 | |
| 1365 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, |
| 1366 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1367 | { |
| 1368 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1369 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1370 | FaceTableFixture::m_faceTable.add(dummy); |
| 1371 | |
| 1372 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1373 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1374 | |
| 1375 | Block encodedParameters(parameters.wireEncode()); |
| 1376 | |
| 1377 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1378 | enable.append(encodedParameters); |
| 1379 | |
| 1380 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1381 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1382 | |
| 1383 | generateCommand(*enableCommand); |
| 1384 | |
| 1385 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1386 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1387 | enableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1388 | |
| 1389 | onValidatedFaceRequest(enableCommand); |
| 1390 | |
| 1391 | BOOST_REQUIRE(didCallbackFire()); |
| 1392 | |
| 1393 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1394 | resetCallbackFired(); |
| 1395 | |
| 1396 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1397 | disable.append(encodedParameters); |
| 1398 | |
| 1399 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1400 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1401 | |
| 1402 | generateCommand(*disableCommand); |
| 1403 | |
| 1404 | TestFaceManagerCommon::m_face->onReceiveData += |
| 1405 | bind(&LocalControlFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 1406 | disableCommand->getName(), 412, "Face is non-local"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1407 | |
| 1408 | onValidatedFaceRequest(disableCommand); |
| 1409 | |
| 1410 | BOOST_REQUIRE(didCallbackFire()); |
| 1411 | } |
| 1412 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1413 | class FaceFixture : public FaceTableFixture, |
| 1414 | public TestFaceManagerCommon, |
| 1415 | public FaceManager |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1416 | { |
| 1417 | public: |
| 1418 | FaceFixture() |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1419 | : FaceManager(FaceTableFixture::m_faceTable, |
| 1420 | TestFaceManagerCommon::m_face) |
| 1421 | , m_receivedNotification(false) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1422 | { |
| 1423 | |
| 1424 | } |
| 1425 | |
| 1426 | virtual |
| 1427 | ~FaceFixture() |
| 1428 | { |
| 1429 | |
| 1430 | } |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1431 | |
| 1432 | void |
| 1433 | callbackDispatch(const Data& response, |
| 1434 | const Name& expectedName, |
| 1435 | uint32_t expectedCode, |
| 1436 | const std::string& expectedText, |
| 1437 | const Block& expectedBody, |
| 1438 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1439 | { |
| 1440 | Block payload = response.getContent().blockFromValue(); |
| 1441 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1442 | { |
| 1443 | validateControlResponse(response, expectedName, expectedCode, |
| 1444 | expectedText, expectedBody); |
| 1445 | } |
| 1446 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1447 | { |
| 1448 | validateFaceEvent(payload, expectedFaceEvent); |
| 1449 | } |
| 1450 | else |
| 1451 | { |
| 1452 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | void |
| 1457 | callbackDispatch(const Data& response, |
| 1458 | const Name& expectedName, |
| 1459 | uint32_t expectedCode, |
| 1460 | const std::string& expectedText, |
| 1461 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1462 | { |
| 1463 | Block payload = response.getContent().blockFromValue(); |
| 1464 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1465 | { |
| 1466 | validateControlResponse(response, expectedName, |
| 1467 | expectedCode, expectedText); |
| 1468 | } |
| 1469 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1470 | { |
| 1471 | validateFaceEvent(payload, expectedFaceEvent); |
| 1472 | } |
| 1473 | else |
| 1474 | { |
| 1475 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | void |
| 1480 | validateFaceEvent(const Block& wire, |
| 1481 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1482 | { |
| 1483 | |
| 1484 | m_receivedNotification = true; |
| 1485 | |
| 1486 | ndn::nfd::FaceEventNotification notification(wire); |
| 1487 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1488 | BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1489 | BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId()); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1490 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri()); |
| 1491 | BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | bool |
| 1495 | didReceiveNotication() const |
| 1496 | { |
| 1497 | return m_receivedNotification; |
| 1498 | } |
| 1499 | |
| 1500 | protected: |
| 1501 | bool m_receivedNotification; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1502 | }; |
| 1503 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1504 | BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1505 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1506 | ControlParameters parameters; |
| 1507 | parameters.setUri("tcp:/127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1508 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1509 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1510 | |
| 1511 | Name commandName("/localhost/nfd/faces"); |
| 1512 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1513 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1514 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1515 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1516 | generateCommand(*command); |
| 1517 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1518 | getFace()->onReceiveData += |
| 1519 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1520 | command->getName(), 400, "Malformed command"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1521 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1522 | createFace(*command, parameters); |
| 1523 | |
| 1524 | BOOST_REQUIRE(didCallbackFire()); |
| 1525 | } |
| 1526 | |
| 1527 | BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) |
| 1528 | { |
| 1529 | ControlParameters parameters; |
| 1530 | |
| 1531 | Block encodedParameters(parameters.wireEncode()); |
| 1532 | |
| 1533 | Name commandName("/localhost/nfd/faces"); |
| 1534 | commandName.append("create"); |
| 1535 | commandName.append(encodedParameters); |
| 1536 | |
| 1537 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1538 | generateCommand(*command); |
| 1539 | |
| 1540 | getFace()->onReceiveData += |
| 1541 | bind(&FaceFixture::validateControlResponse, this, _1, |
| 1542 | command->getName(), 400, "Malformed command"); |
| 1543 | |
| 1544 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1545 | |
| 1546 | BOOST_REQUIRE(didCallbackFire()); |
| 1547 | } |
| 1548 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1549 | BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1550 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1551 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1552 | // this will be an unsupported protocol because no factories have been |
| 1553 | // added to the face manager |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1554 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1555 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1556 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1557 | |
| 1558 | Name commandName("/localhost/nfd/faces"); |
| 1559 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1560 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1561 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1562 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1563 | generateCommand(*command); |
| 1564 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1565 | getFace()->onReceiveData += |
| 1566 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1567 | command->getName(), 501, "Unsupported protocol"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1568 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1569 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1570 | |
| 1571 | BOOST_REQUIRE(didCallbackFire()); |
| 1572 | } |
| 1573 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1574 | BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1575 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1576 | ControlParameters parameters; |
| 1577 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1578 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1579 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1580 | |
| 1581 | Name commandName("/localhost/nfd/faces"); |
| 1582 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1583 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1584 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1585 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1586 | generateCommand(*command); |
| 1587 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1588 | ControlParameters resultParameters; |
Steve DiBenedetto | 2599928 | 2014-05-22 15:25:12 -0600 | [diff] [blame] | 1589 | resultParameters.setUri("dummy://"); |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1590 | resultParameters.setFaceId(FACEID_RESERVED_MAX + 1); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1591 | |
| 1592 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1593 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1594 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1595 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1596 | .setFaceId(FACEID_RESERVED_MAX + 1) |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1597 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1598 | .setLocalUri(dummy->getLocalUri().toString()) |
| 1599 | .setFlags(0); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1600 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1601 | Block encodedResultParameters(resultParameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1602 | |
| 1603 | getFace()->onReceiveData += |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1604 | bind(&FaceFixture::callbackDispatch, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1605 | command->getName(), 200, "Success", |
| 1606 | encodedResultParameters, expectedFaceEvent); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1607 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1608 | onCreated(command->getName(), parameters, dummy); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1609 | |
| 1610 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1611 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1614 | BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1615 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1616 | ControlParameters parameters; |
| 1617 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1618 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1619 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1620 | |
| 1621 | Name commandName("/localhost/nfd/faces"); |
| 1622 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1623 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1624 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1625 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1626 | generateCommand(*command); |
| 1627 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1628 | getFace()->onReceiveData += |
| 1629 | bind(&FaceFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 1630 | command->getName(), 408, "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1631 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1632 | onConnectFailed(command->getName(), "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1633 | |
| 1634 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1635 | BOOST_CHECK_EQUAL(didReceiveNotication(), false); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1639 | BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1640 | { |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1641 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1642 | FaceTableFixture::m_faceTable.add(dummy); |
| 1643 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1644 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1645 | parameters.setFaceId(dummy->getId()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1646 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1647 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1648 | |
| 1649 | Name commandName("/localhost/nfd/faces"); |
| 1650 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1651 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1652 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1653 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1654 | generateCommand(*command); |
| 1655 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1656 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1657 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 1658 | .setFaceId(dummy->getId()) |
| 1659 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1660 | .setLocalUri(dummy->getLocalUri().toString()) |
| 1661 | .setFlags(0); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1662 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1663 | getFace()->onReceiveData += |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 1664 | bind(&FaceFixture::callbackDispatch, this, _1, command->getName(), |
| 1665 | 200, "Success", ref(encodedParameters), expectedFaceEvent); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1666 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1667 | destroyFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1668 | |
| 1669 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1670 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1673 | class FaceListFixture : public FaceStatusPublisherFixture |
| 1674 | { |
| 1675 | public: |
| 1676 | FaceListFixture() |
| 1677 | : m_manager(m_table, m_face) |
| 1678 | { |
| 1679 | |
| 1680 | } |
| 1681 | |
| 1682 | virtual |
| 1683 | ~FaceListFixture() |
| 1684 | { |
| 1685 | |
| 1686 | } |
| 1687 | |
| 1688 | protected: |
| 1689 | FaceManager m_manager; |
| 1690 | }; |
| 1691 | |
| 1692 | BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1693 | { |
| 1694 | Name commandName("/localhost/nfd/faces/list"); |
| 1695 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1696 | |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame^] | 1697 | // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75 |
| 1698 | // use 59 FaceStatuses to force a FaceStatus to span Data packets |
| 1699 | for (int i = 0; i < 59; i++) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1700 | { |
| 1701 | shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>()); |
| 1702 | |
| 1703 | uint64_t filler = std::numeric_limits<uint64_t>::max() - 1; |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame^] | 1704 | dummy->setCounters(filler, filler, filler, filler, filler, filler); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1705 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 1706 | m_referenceFaces.push_back(dummy); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1707 | |
| 1708 | add(dummy); |
| 1709 | } |
| 1710 | |
| 1711 | ndn::EncodingBuffer buffer; |
| 1712 | |
| 1713 | m_face->onReceiveData += |
| 1714 | bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1); |
| 1715 | |
| 1716 | m_manager.listFaces(*command); |
| 1717 | BOOST_REQUIRE(m_finished); |
| 1718 | } |
| 1719 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 1720 | class ChannelStatusFixture : public FaceManagerFixture |
| 1721 | { |
| 1722 | public: |
| 1723 | void |
| 1724 | validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry) |
| 1725 | { |
| 1726 | m_callbackFired = true; |
| 1727 | Block b = data.getContent().blockFromValue(); |
| 1728 | ndn::nfd::ChannelStatus entry(b); |
| 1729 | BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri()); |
| 1730 | } |
| 1731 | |
| 1732 | virtual shared_ptr<DummyProtocolFactory> |
| 1733 | addProtocolFactory(const std::string& protocol) |
| 1734 | { |
| 1735 | shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>()); |
| 1736 | m_manager.m_factories[protocol] = factory; |
| 1737 | |
| 1738 | return factory; |
| 1739 | } |
| 1740 | }; |
| 1741 | |
| 1742 | BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture) |
| 1743 | { |
| 1744 | shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy")); |
| 1745 | factory->addChannel("dummy://"); |
| 1746 | |
| 1747 | Name requestName("/localhost/nfd/faces/channels"); |
| 1748 | shared_ptr<Interest> request(make_shared<Interest>(requestName)); |
| 1749 | |
| 1750 | ndn::nfd::ChannelStatus expectedEntry; |
| 1751 | expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString()); |
| 1752 | |
| 1753 | m_face->onReceiveData += |
| 1754 | bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry); |
| 1755 | |
| 1756 | m_manager.listChannels(*request); |
| 1757 | BOOST_REQUIRE(m_callbackFired); |
| 1758 | } |
| 1759 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1760 | BOOST_AUTO_TEST_SUITE_END() |
| 1761 | |
| 1762 | } // namespace tests |
| 1763 | } // namespace nfd |