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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 816 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 817 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
| 818 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 830 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 831 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
| 832 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 852 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 853 | this->validateControlResponse(response, command->getName(), 401, "Signature required"); |
| 854 | }; |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 875 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 876 | this->validateControlResponse(response, command->getName(), 403, "Unauthorized command"); |
| 877 | }; |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 913 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 914 | this->validateControlResponse(response, command->getName(), 501, "Unsupported command"); |
| 915 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 983 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 984 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
| 985 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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 += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1080 | [this, enableCommand, encodedParameters] (const Data& response) { |
| 1081 | this->validateControlResponse(response, enableCommand->getName(), |
| 1082 | 200, "Success", encodedParameters); |
| 1083 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1084 | |
| 1085 | onValidatedFaceRequest(enableCommand); |
| 1086 | |
| 1087 | BOOST_REQUIRE(didCallbackFire()); |
| 1088 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1089 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1090 | |
| 1091 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1092 | resetCallbackFired(); |
| 1093 | |
| 1094 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1095 | disable.append(encodedParameters); |
| 1096 | |
| 1097 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1098 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1099 | |
| 1100 | generateCommand(*disableCommand); |
| 1101 | |
| 1102 | TestFaceManagerCommon::m_face->onReceiveData += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1103 | [this, disableCommand, encodedParameters] (const Data& response) { |
| 1104 | this->validateControlResponse(response, disableCommand->getName(), |
| 1105 | 200, "Success", encodedParameters); |
| 1106 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1107 | |
| 1108 | onValidatedFaceRequest(disableCommand); |
| 1109 | |
| 1110 | BOOST_REQUIRE(didCallbackFire()); |
| 1111 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1112 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1113 | } |
| 1114 | |
| 1115 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound, |
| 1116 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1117 | { |
| 1118 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1119 | BOOST_REQUIRE(dummy->isLocal()); |
| 1120 | FaceTableFixture::m_faceTable.add(dummy); |
| 1121 | |
| 1122 | ControlParameters parameters; |
| 1123 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1124 | |
| 1125 | Block encodedParameters(parameters.wireEncode()); |
| 1126 | |
| 1127 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1128 | enable.append(encodedParameters); |
| 1129 | |
| 1130 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1131 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1132 | |
| 1133 | generateCommand(*enableCommand); |
| 1134 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1135 | TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) { |
| 1136 | this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found"); |
| 1137 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1138 | |
| 1139 | onValidatedFaceRequest(enableCommand); |
| 1140 | |
| 1141 | BOOST_REQUIRE(didCallbackFire()); |
| 1142 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1143 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1144 | |
| 1145 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1146 | resetCallbackFired(); |
| 1147 | |
| 1148 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1149 | disable.append(encodedParameters); |
| 1150 | |
| 1151 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1152 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1153 | |
| 1154 | generateCommand(*disableCommand); |
| 1155 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1156 | TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) { |
| 1157 | this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found"); |
| 1158 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1159 | |
| 1160 | onValidatedFaceRequest(disableCommand); |
| 1161 | |
| 1162 | BOOST_REQUIRE(didCallbackFire()); |
| 1163 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1164 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1165 | } |
| 1166 | |
| 1167 | BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature, |
| 1168 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1169 | { |
| 1170 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1171 | BOOST_REQUIRE(dummy->isLocal()); |
| 1172 | FaceTableFixture::m_faceTable.add(dummy); |
| 1173 | |
| 1174 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1175 | |
| 1176 | Block encodedParameters(parameters.wireEncode()); |
| 1177 | |
| 1178 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1179 | enable.append(encodedParameters); |
| 1180 | |
| 1181 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1182 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1183 | |
| 1184 | generateCommand(*enableCommand); |
| 1185 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1186 | TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) { |
| 1187 | this->validateControlResponse(response, enableCommand->getName(), 400, "Malformed command"); |
| 1188 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1189 | |
| 1190 | onValidatedFaceRequest(enableCommand); |
| 1191 | |
| 1192 | BOOST_REQUIRE(didCallbackFire()); |
| 1193 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1194 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1195 | |
| 1196 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1197 | resetCallbackFired(); |
| 1198 | |
| 1199 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1200 | disable.append(encodedParameters); |
| 1201 | |
| 1202 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1203 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1204 | |
| 1205 | generateCommand(*disableCommand); |
| 1206 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1207 | TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) { |
| 1208 | this->validateControlResponse(response, disableCommand->getName(), 400, "Malformed command"); |
| 1209 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1210 | |
| 1211 | onValidatedFaceRequest(disableCommand); |
| 1212 | |
| 1213 | BOOST_REQUIRE(didCallbackFire()); |
| 1214 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1215 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1216 | } |
| 1217 | |
| 1218 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal, |
| 1219 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1220 | { |
| 1221 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1222 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1223 | FaceTableFixture::m_faceTable.add(dummy); |
| 1224 | |
| 1225 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1226 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1227 | |
| 1228 | Block encodedParameters(parameters.wireEncode()); |
| 1229 | |
| 1230 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1231 | enable.append(encodedParameters); |
| 1232 | |
| 1233 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1234 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1235 | |
| 1236 | generateCommand(*enableCommand); |
| 1237 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1238 | TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) { |
| 1239 | this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local"); |
| 1240 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1241 | |
| 1242 | onValidatedFaceRequest(enableCommand); |
| 1243 | |
| 1244 | BOOST_REQUIRE(didCallbackFire()); |
| 1245 | |
| 1246 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1247 | resetCallbackFired(); |
| 1248 | |
| 1249 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1250 | enable.append(encodedParameters); |
| 1251 | |
| 1252 | shared_ptr<Interest> disableCommand(make_shared<Interest>(enable)); |
| 1253 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1254 | |
| 1255 | generateCommand(*disableCommand); |
| 1256 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1257 | TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) { |
| 1258 | this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local"); |
| 1259 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1260 | |
| 1261 | onValidatedFaceRequest(disableCommand); |
| 1262 | |
| 1263 | BOOST_REQUIRE(didCallbackFire()); |
| 1264 | } |
| 1265 | |
| 1266 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, |
| 1267 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1268 | { |
| 1269 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1270 | BOOST_REQUIRE(dummy->isLocal()); |
| 1271 | FaceTableFixture::m_faceTable.add(dummy); |
| 1272 | |
| 1273 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1274 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1275 | |
| 1276 | Block encodedParameters(parameters.wireEncode()); |
| 1277 | |
| 1278 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1279 | enable.append(encodedParameters); |
| 1280 | |
| 1281 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1282 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1283 | |
| 1284 | generateCommand(*enableCommand); |
| 1285 | |
| 1286 | TestFaceManagerCommon::m_face->onReceiveData += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1287 | [this, enableCommand, encodedParameters] (const Data& response) { |
| 1288 | this->validateControlResponse(response, enableCommand->getName(), |
| 1289 | 200, "Success", encodedParameters); |
| 1290 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1291 | |
| 1292 | onValidatedFaceRequest(enableCommand); |
| 1293 | |
| 1294 | BOOST_REQUIRE(didCallbackFire()); |
| 1295 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1296 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1297 | |
| 1298 | |
| 1299 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1300 | resetCallbackFired(); |
| 1301 | |
| 1302 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1303 | disable.append(encodedParameters); |
| 1304 | |
| 1305 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1306 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1307 | |
| 1308 | generateCommand(*disableCommand); |
| 1309 | |
| 1310 | TestFaceManagerCommon::m_face->onReceiveData += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1311 | [this, disableCommand, encodedParameters] (const Data& response) { |
| 1312 | this->validateControlResponse(response, disableCommand->getName(), |
| 1313 | 200, "Success", encodedParameters); |
| 1314 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1315 | |
| 1316 | onValidatedFaceRequest(disableCommand); |
| 1317 | |
| 1318 | BOOST_REQUIRE(didCallbackFire()); |
| 1319 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1320 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1321 | } |
| 1322 | |
| 1323 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound, |
| 1324 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1325 | { |
| 1326 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1327 | BOOST_REQUIRE(dummy->isLocal()); |
| 1328 | FaceTableFixture::m_faceTable.add(dummy); |
| 1329 | |
| 1330 | ControlParameters parameters; |
| 1331 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1332 | |
| 1333 | Block encodedParameters(parameters.wireEncode()); |
| 1334 | |
| 1335 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1336 | enable.append(encodedParameters); |
| 1337 | |
| 1338 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1339 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1340 | |
| 1341 | generateCommand(*enableCommand); |
| 1342 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1343 | TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) { |
| 1344 | this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found"); |
| 1345 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1346 | |
| 1347 | onValidatedFaceRequest(enableCommand); |
| 1348 | |
| 1349 | BOOST_REQUIRE(didCallbackFire()); |
| 1350 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1351 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1352 | |
| 1353 | |
| 1354 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1355 | resetCallbackFired(); |
| 1356 | |
| 1357 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1358 | disable.append(encodedParameters); |
| 1359 | |
| 1360 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1361 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1362 | |
| 1363 | generateCommand(*disableCommand); |
| 1364 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1365 | TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) { |
| 1366 | this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found"); |
| 1367 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1368 | |
| 1369 | onValidatedFaceRequest(disableCommand); |
| 1370 | |
| 1371 | BOOST_REQUIRE(didCallbackFire()); |
| 1372 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1373 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1374 | } |
| 1375 | |
| 1376 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, |
| 1377 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1378 | { |
| 1379 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1380 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1381 | FaceTableFixture::m_faceTable.add(dummy); |
| 1382 | |
| 1383 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1384 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1385 | |
| 1386 | Block encodedParameters(parameters.wireEncode()); |
| 1387 | |
| 1388 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1389 | enable.append(encodedParameters); |
| 1390 | |
| 1391 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1392 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1393 | |
| 1394 | generateCommand(*enableCommand); |
| 1395 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1396 | TestFaceManagerCommon::m_face->onReceiveData += [this, enableCommand] (const Data& response) { |
| 1397 | this->validateControlResponse(response, enableCommand->getName(), 412, "Face is non-local"); |
| 1398 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1399 | |
| 1400 | onValidatedFaceRequest(enableCommand); |
| 1401 | |
| 1402 | BOOST_REQUIRE(didCallbackFire()); |
| 1403 | |
| 1404 | TestFaceManagerCommon::m_face->onReceiveData.clear(); |
| 1405 | resetCallbackFired(); |
| 1406 | |
| 1407 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1408 | disable.append(encodedParameters); |
| 1409 | |
| 1410 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1411 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1412 | |
| 1413 | generateCommand(*disableCommand); |
| 1414 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1415 | TestFaceManagerCommon::m_face->onReceiveData += [this, disableCommand] (const Data& response) { |
| 1416 | this->validateControlResponse(response, disableCommand->getName(), 412, "Face is non-local"); |
| 1417 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1418 | |
| 1419 | onValidatedFaceRequest(disableCommand); |
| 1420 | |
| 1421 | BOOST_REQUIRE(didCallbackFire()); |
| 1422 | } |
| 1423 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1424 | class FaceFixture : public FaceTableFixture, |
| 1425 | public TestFaceManagerCommon, |
| 1426 | public FaceManager |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1427 | { |
| 1428 | public: |
| 1429 | FaceFixture() |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1430 | : FaceManager(FaceTableFixture::m_faceTable, |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 1431 | TestFaceManagerCommon::m_face, |
| 1432 | m_testKeyChain) |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1433 | , m_receivedNotification(false) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1434 | { |
| 1435 | |
| 1436 | } |
| 1437 | |
| 1438 | virtual |
| 1439 | ~FaceFixture() |
| 1440 | { |
| 1441 | |
| 1442 | } |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1443 | |
| 1444 | void |
| 1445 | callbackDispatch(const Data& response, |
| 1446 | const Name& expectedName, |
| 1447 | uint32_t expectedCode, |
| 1448 | const std::string& expectedText, |
| 1449 | const Block& expectedBody, |
| 1450 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1451 | { |
| 1452 | Block payload = response.getContent().blockFromValue(); |
| 1453 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1454 | { |
| 1455 | validateControlResponse(response, expectedName, expectedCode, |
| 1456 | expectedText, expectedBody); |
| 1457 | } |
| 1458 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1459 | { |
| 1460 | validateFaceEvent(payload, expectedFaceEvent); |
| 1461 | } |
| 1462 | else |
| 1463 | { |
| 1464 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | void |
| 1469 | callbackDispatch(const Data& response, |
| 1470 | const Name& expectedName, |
| 1471 | uint32_t expectedCode, |
| 1472 | const std::string& expectedText, |
| 1473 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1474 | { |
| 1475 | Block payload = response.getContent().blockFromValue(); |
| 1476 | if (payload.type() == ndn::tlv::nfd::ControlResponse) |
| 1477 | { |
| 1478 | validateControlResponse(response, expectedName, |
| 1479 | expectedCode, expectedText); |
| 1480 | } |
| 1481 | else if (payload.type() == ndn::tlv::nfd::FaceEventNotification) |
| 1482 | { |
| 1483 | validateFaceEvent(payload, expectedFaceEvent); |
| 1484 | } |
| 1485 | else |
| 1486 | { |
| 1487 | BOOST_FAIL("Received unknown message type: #" << payload.type()); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | void |
| 1492 | validateFaceEvent(const Block& wire, |
| 1493 | const ndn::nfd::FaceEventNotification& expectedFaceEvent) |
| 1494 | { |
| 1495 | |
| 1496 | m_receivedNotification = true; |
| 1497 | |
| 1498 | ndn::nfd::FaceEventNotification notification(wire); |
| 1499 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1500 | BOOST_CHECK_EQUAL(notification.getKind(), expectedFaceEvent.getKind()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1501 | BOOST_CHECK_EQUAL(notification.getFaceId(), expectedFaceEvent.getFaceId()); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1502 | BOOST_CHECK_EQUAL(notification.getRemoteUri(), expectedFaceEvent.getRemoteUri()); |
| 1503 | BOOST_CHECK_EQUAL(notification.getLocalUri(), expectedFaceEvent.getLocalUri()); |
Chengyu Fan | f9c2bb1 | 2014-10-06 11:52:44 -0600 | [diff] [blame] | 1504 | BOOST_CHECK_EQUAL(notification.getFaceScope(), expectedFaceEvent.getFaceScope()); |
| 1505 | BOOST_CHECK_EQUAL(notification.getFacePersistency(), expectedFaceEvent.getFacePersistency()); |
| 1506 | BOOST_CHECK_EQUAL(notification.getLinkType(), expectedFaceEvent.getLinkType()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | bool |
| 1510 | didReceiveNotication() const |
| 1511 | { |
| 1512 | return m_receivedNotification; |
| 1513 | } |
| 1514 | |
| 1515 | protected: |
| 1516 | bool m_receivedNotification; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1517 | }; |
| 1518 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1519 | BOOST_FIXTURE_TEST_CASE(CreateFaceBadUri, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1520 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1521 | ControlParameters parameters; |
| 1522 | parameters.setUri("tcp:/127.0.0.1"); |
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 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1525 | |
| 1526 | Name commandName("/localhost/nfd/faces"); |
| 1527 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1528 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1529 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1530 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1531 | generateCommand(*command); |
| 1532 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1533 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 1534 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
| 1535 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1536 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1537 | createFace(*command, parameters); |
| 1538 | |
| 1539 | BOOST_REQUIRE(didCallbackFire()); |
| 1540 | } |
| 1541 | |
| 1542 | BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) |
| 1543 | { |
| 1544 | ControlParameters parameters; |
| 1545 | |
| 1546 | Block encodedParameters(parameters.wireEncode()); |
| 1547 | |
| 1548 | Name commandName("/localhost/nfd/faces"); |
| 1549 | commandName.append("create"); |
| 1550 | commandName.append(encodedParameters); |
| 1551 | |
| 1552 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1553 | generateCommand(*command); |
| 1554 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1555 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 1556 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
| 1557 | }; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1558 | |
| 1559 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1560 | |
| 1561 | BOOST_REQUIRE(didCallbackFire()); |
| 1562 | } |
| 1563 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1564 | BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1565 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1566 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1567 | // this will be an unsupported protocol because no factories have been |
| 1568 | // added to the face manager |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1569 | parameters.setUri("tcp://127.0.0.1"); |
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 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1572 | |
| 1573 | Name commandName("/localhost/nfd/faces"); |
| 1574 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1575 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1576 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1577 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1578 | generateCommand(*command); |
| 1579 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1580 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 1581 | this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol"); |
| 1582 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1583 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1584 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1585 | |
| 1586 | BOOST_REQUIRE(didCallbackFire()); |
| 1587 | } |
| 1588 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1589 | BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1590 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1591 | ControlParameters parameters; |
| 1592 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1593 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1594 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1595 | |
| 1596 | Name commandName("/localhost/nfd/faces"); |
| 1597 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1598 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1599 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1600 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1601 | generateCommand(*command); |
| 1602 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1603 | ControlParameters resultParameters; |
Steve DiBenedetto | 2599928 | 2014-05-22 15:25:12 -0600 | [diff] [blame] | 1604 | resultParameters.setUri("dummy://"); |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1605 | resultParameters.setFaceId(FACEID_RESERVED_MAX + 1); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1606 | |
| 1607 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1608 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1609 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1610 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1611 | .setFaceId(FACEID_RESERVED_MAX + 1) |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1612 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1613 | .setLocalUri(dummy->getLocalUri().toString()) |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 1614 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 1615 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1616 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1617 | Block encodedResultParameters(resultParameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1618 | |
| 1619 | getFace()->onReceiveData += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1620 | [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) { |
| 1621 | this->callbackDispatch(response,command->getName(), 200, "Success", |
| 1622 | encodedResultParameters, expectedFaceEvent); |
| 1623 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1624 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1625 | onCreated(command->getName(), parameters, dummy); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1626 | |
| 1627 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1628 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1631 | BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1632 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1633 | ControlParameters parameters; |
| 1634 | parameters.setUri("tcp://127.0.0.1"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1635 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1636 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1637 | |
| 1638 | Name commandName("/localhost/nfd/faces"); |
| 1639 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1640 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1641 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1642 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1643 | generateCommand(*command); |
| 1644 | |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1645 | getFace()->onReceiveData += [this, command] (const Data& response) { |
| 1646 | this->validateControlResponse(response, command->getName(), 408, "unit-test-reason"); |
| 1647 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1648 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1649 | onConnectFailed(command->getName(), "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1650 | |
| 1651 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1652 | BOOST_CHECK_EQUAL(didReceiveNotication(), false); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1656 | BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1657 | { |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1658 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1659 | FaceTableFixture::m_faceTable.add(dummy); |
| 1660 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1661 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1662 | parameters.setFaceId(dummy->getId()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1663 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1664 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1665 | |
| 1666 | Name commandName("/localhost/nfd/faces"); |
| 1667 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1668 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1669 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1670 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1671 | generateCommand(*command); |
| 1672 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1673 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1674 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 1675 | .setFaceId(dummy->getId()) |
| 1676 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1677 | .setLocalUri(dummy->getLocalUri().toString()) |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 1678 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 1679 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1680 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1681 | getFace()->onReceiveData += |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame^] | 1682 | [this, command, encodedParameters, expectedFaceEvent] (const Data& response) { |
| 1683 | this->callbackDispatch(response,command->getName(), 200, "Success", |
| 1684 | encodedParameters, expectedFaceEvent); |
| 1685 | }; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1686 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1687 | destroyFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1688 | |
| 1689 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1690 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1693 | class FaceListFixture : public FaceStatusPublisherFixture |
| 1694 | { |
| 1695 | public: |
| 1696 | FaceListFixture() |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 1697 | : m_manager(m_table, m_face, m_testKeyChain) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1698 | { |
| 1699 | |
| 1700 | } |
| 1701 | |
| 1702 | virtual |
| 1703 | ~FaceListFixture() |
| 1704 | { |
| 1705 | |
| 1706 | } |
| 1707 | |
| 1708 | protected: |
| 1709 | FaceManager m_manager; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 1710 | ndn::KeyChain m_testKeyChain; |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1711 | }; |
| 1712 | |
| 1713 | BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1714 | { |
| 1715 | Name commandName("/localhost/nfd/faces/list"); |
| 1716 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1717 | |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 1718 | // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75 |
| 1719 | // use 59 FaceStatuses to force a FaceStatus to span Data packets |
| 1720 | for (int i = 0; i < 59; i++) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1721 | { |
| 1722 | shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>()); |
| 1723 | |
| 1724 | uint64_t filler = std::numeric_limits<uint64_t>::max() - 1; |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 1725 | dummy->setCounters(filler, filler, filler, filler, filler, filler); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1726 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 1727 | m_referenceFaces.push_back(dummy); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1728 | |
| 1729 | add(dummy); |
| 1730 | } |
| 1731 | |
| 1732 | ndn::EncodingBuffer buffer; |
| 1733 | |
| 1734 | m_face->onReceiveData += |
| 1735 | bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, this, _1); |
| 1736 | |
| 1737 | m_manager.listFaces(*command); |
| 1738 | BOOST_REQUIRE(m_finished); |
| 1739 | } |
| 1740 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 1741 | class ChannelStatusFixture : public FaceManagerFixture |
| 1742 | { |
| 1743 | public: |
| 1744 | void |
| 1745 | validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry) |
| 1746 | { |
| 1747 | m_callbackFired = true; |
| 1748 | Block b = data.getContent().blockFromValue(); |
| 1749 | ndn::nfd::ChannelStatus entry(b); |
| 1750 | BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri()); |
| 1751 | } |
| 1752 | |
| 1753 | virtual shared_ptr<DummyProtocolFactory> |
| 1754 | addProtocolFactory(const std::string& protocol) |
| 1755 | { |
| 1756 | shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>()); |
| 1757 | m_manager.m_factories[protocol] = factory; |
| 1758 | |
| 1759 | return factory; |
| 1760 | } |
| 1761 | }; |
| 1762 | |
| 1763 | BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture) |
| 1764 | { |
| 1765 | shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy")); |
| 1766 | factory->addChannel("dummy://"); |
| 1767 | |
| 1768 | Name requestName("/localhost/nfd/faces/channels"); |
| 1769 | shared_ptr<Interest> request(make_shared<Interest>(requestName)); |
| 1770 | |
| 1771 | ndn::nfd::ChannelStatus expectedEntry; |
| 1772 | expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString()); |
| 1773 | |
| 1774 | m_face->onReceiveData += |
| 1775 | bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry); |
| 1776 | |
| 1777 | m_manager.listChannels(*request); |
| 1778 | BOOST_REQUIRE(m_callbackFired); |
| 1779 | } |
| 1780 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1781 | BOOST_AUTO_TEST_SUITE_END() |
| 1782 | |
| 1783 | } // namespace tests |
| 1784 | } // namespace nfd |