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