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