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