Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 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" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 359 | " path /var/run/nfd.sock\n" |
| 360 | " }\n" |
| 361 | "}\n"; |
| 362 | |
| 363 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 364 | } |
| 365 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 366 | BOOST_AUTO_TEST_CASE(TestProcessSectionUnixUnknownOption) |
| 367 | { |
| 368 | const std::string CONFIG = |
| 369 | "face_system\n" |
| 370 | "{\n" |
| 371 | " unix\n" |
| 372 | " {\n" |
| 373 | " hello\n" |
| 374 | " }\n" |
| 375 | "}\n"; |
| 376 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 377 | bind(&isExpectedException, _1, |
| 378 | "Unrecognized option \"hello\" in \"unix\" section")); |
| 379 | } |
| 380 | |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 381 | #endif // HAVE_UNIX_SOCKETS |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 382 | |
| 383 | |
| 384 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcp) |
| 385 | { |
| 386 | const std::string CONFIG = |
| 387 | "face_system\n" |
| 388 | "{\n" |
| 389 | " tcp\n" |
| 390 | " {\n" |
| 391 | " listen yes\n" |
| 392 | " port 6363\n" |
Steve DiBenedetto | 9515287 | 2014-04-11 12:40:59 -0600 | [diff] [blame] | 393 | " enable_v4 yes\n" |
| 394 | " enable_v6 yes\n" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 395 | " }\n" |
| 396 | "}\n"; |
| 397 | try |
| 398 | { |
| 399 | parseConfig(CONFIG, false); |
| 400 | } |
| 401 | catch (const std::runtime_error& e) |
| 402 | { |
| 403 | const std::string reason = e.what(); |
| 404 | if (reason.find("Address in use") != std::string::npos) |
| 405 | { |
| 406 | BOOST_FAIL(reason); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpDryRun) |
| 412 | { |
| 413 | const std::string CONFIG = |
| 414 | "face_system\n" |
| 415 | "{\n" |
| 416 | " tcp\n" |
| 417 | " {\n" |
| 418 | " listen yes\n" |
| 419 | " port 6363\n" |
Steve DiBenedetto | 9515287 | 2014-04-11 12:40:59 -0600 | [diff] [blame] | 420 | " enable_v4 yes\n" |
| 421 | " enable_v6 yes\n" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 422 | " }\n" |
| 423 | "}\n"; |
| 424 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 425 | } |
| 426 | |
| 427 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpBadListen) |
| 428 | { |
| 429 | const std::string CONFIG = |
| 430 | "face_system\n" |
| 431 | "{\n" |
| 432 | " tcp\n" |
| 433 | " {\n" |
| 434 | " listen hello\n" |
| 435 | " }\n" |
| 436 | "}\n"; |
| 437 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 438 | bind(&isExpectedException, _1, |
| 439 | "Invalid value for option \"listen\" in \"tcp\" section")); |
| 440 | } |
| 441 | |
Steve DiBenedetto | 9515287 | 2014-04-11 12:40:59 -0600 | [diff] [blame] | 442 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpChannelsDisabled) |
| 443 | { |
| 444 | const std::string CONFIG = |
| 445 | "face_system\n" |
| 446 | "{\n" |
| 447 | " tcp\n" |
| 448 | " {\n" |
| 449 | " port 6363\n" |
| 450 | " enable_v4 no\n" |
| 451 | " enable_v6 no\n" |
| 452 | " }\n" |
| 453 | "}\n"; |
| 454 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 455 | bind(&isExpectedException, _1, |
| 456 | "IPv4 and IPv6 channels have been disabled." |
| 457 | " Remove \"tcp\" section to disable TCP channels or" |
| 458 | " re-enable at least one channel type.")); |
| 459 | } |
| 460 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 461 | BOOST_AUTO_TEST_CASE(TestProcessSectionTcpUnknownOption) |
| 462 | { |
| 463 | const std::string CONFIG = |
| 464 | "face_system\n" |
| 465 | "{\n" |
| 466 | " tcp\n" |
| 467 | " {\n" |
| 468 | " hello\n" |
| 469 | " }\n" |
| 470 | "}\n"; |
| 471 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 472 | bind(&isExpectedException, _1, |
| 473 | "Unrecognized option \"hello\" in \"tcp\" section")); |
| 474 | } |
| 475 | |
| 476 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdp) |
| 477 | { |
| 478 | const std::string CONFIG = |
| 479 | "face_system\n" |
| 480 | "{\n" |
| 481 | " udp\n" |
| 482 | " {\n" |
| 483 | " port 6363\n" |
Steve DiBenedetto | 9515287 | 2014-04-11 12:40:59 -0600 | [diff] [blame] | 484 | " enable_v4 yes\n" |
| 485 | " enable_v6 yes\n" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 486 | " idle_timeout 30\n" |
| 487 | " keep_alive_interval 25\n" |
| 488 | " mcast yes\n" |
| 489 | " mcast_port 56363\n" |
| 490 | " mcast_group 224.0.23.170\n" |
| 491 | " }\n" |
| 492 | "}\n"; |
| 493 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 494 | } |
| 495 | |
| 496 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpDryRun) |
| 497 | { |
| 498 | const std::string CONFIG = |
| 499 | "face_system\n" |
| 500 | "{\n" |
| 501 | " udp\n" |
| 502 | " {\n" |
| 503 | " port 6363\n" |
| 504 | " idle_timeout 30\n" |
| 505 | " keep_alive_interval 25\n" |
| 506 | " mcast yes\n" |
| 507 | " mcast_port 56363\n" |
| 508 | " mcast_group 224.0.23.170\n" |
| 509 | " }\n" |
| 510 | "}\n"; |
| 511 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 512 | } |
| 513 | |
| 514 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadIdleTimeout) |
| 515 | { |
| 516 | const std::string CONFIG = |
| 517 | "face_system\n" |
| 518 | "{\n" |
| 519 | " udp\n" |
| 520 | " {\n" |
| 521 | " idle_timeout hello\n" |
| 522 | " }\n" |
| 523 | "}\n"; |
| 524 | |
| 525 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 526 | bind(&isExpectedException, _1, |
| 527 | "Invalid value for option \"idle_timeout\" in \"udp\" section")); |
| 528 | } |
| 529 | |
| 530 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcast) |
| 531 | { |
| 532 | const std::string CONFIG = |
| 533 | "face_system\n" |
| 534 | "{\n" |
| 535 | " udp\n" |
| 536 | " {\n" |
| 537 | " mcast 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 \"mcast\" in \"udp\" section")); |
| 544 | } |
| 545 | |
| 546 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroup) |
| 547 | { |
| 548 | const std::string CONFIG = |
| 549 | "face_system\n" |
| 550 | "{\n" |
| 551 | " udp\n" |
| 552 | " {\n" |
| 553 | " mcast no\n" |
| 554 | " mcast_port 50\n" |
| 555 | " mcast_group hello\n" |
| 556 | " }\n" |
| 557 | "}\n"; |
| 558 | |
| 559 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 560 | bind(&isExpectedException, _1, |
| 561 | "Invalid value for option \"mcast_group\" in \"udp\" section")); |
| 562 | } |
| 563 | |
| 564 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpBadMcastGroupV6) |
| 565 | { |
| 566 | const std::string CONFIG = |
| 567 | "face_system\n" |
| 568 | "{\n" |
| 569 | " udp\n" |
| 570 | " {\n" |
| 571 | " mcast no\n" |
| 572 | " mcast_port 50\n" |
| 573 | " mcast_group ::1\n" |
| 574 | " }\n" |
| 575 | "}\n"; |
| 576 | |
| 577 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 578 | bind(&isExpectedException, _1, |
| 579 | "Invalid value for option \"mcast_group\" in \"udp\" section")); |
| 580 | } |
| 581 | |
Steve DiBenedetto | 9515287 | 2014-04-11 12:40:59 -0600 | [diff] [blame] | 582 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpChannelsDisabled) |
| 583 | { |
| 584 | const std::string CONFIG = |
| 585 | "face_system\n" |
| 586 | "{\n" |
| 587 | " udp\n" |
| 588 | " {\n" |
| 589 | " port 6363\n" |
| 590 | " enable_v4 no\n" |
| 591 | " enable_v6 no\n" |
| 592 | " idle_timeout 30\n" |
| 593 | " keep_alive_interval 25\n" |
| 594 | " mcast yes\n" |
| 595 | " mcast_port 56363\n" |
| 596 | " mcast_group 224.0.23.170\n" |
| 597 | " }\n" |
| 598 | "}\n"; |
| 599 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 600 | bind(&isExpectedException, _1, |
| 601 | "IPv4 and IPv6 channels have been disabled." |
| 602 | " Remove \"udp\" section to disable UDP channels or" |
| 603 | " re-enable at least one channel type.")); |
| 604 | } |
| 605 | |
| 606 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpConflictingMcast) |
| 607 | { |
| 608 | const std::string CONFIG = |
| 609 | "face_system\n" |
| 610 | "{\n" |
| 611 | " udp\n" |
| 612 | " {\n" |
| 613 | " port 6363\n" |
| 614 | " enable_v4 no\n" |
| 615 | " enable_v6 yes\n" |
| 616 | " idle_timeout 30\n" |
| 617 | " keep_alive_interval 25\n" |
| 618 | " mcast yes\n" |
| 619 | " mcast_port 56363\n" |
| 620 | " mcast_group 224.0.23.170\n" |
| 621 | " }\n" |
| 622 | "}\n"; |
| 623 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 624 | bind(&isExpectedException, _1, |
| 625 | "IPv4 multicast requested, but IPv4 channels" |
| 626 | " have been disabled (conflicting configuration options set)")); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 631 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpUnknownOption) |
| 632 | { |
| 633 | const std::string CONFIG = |
| 634 | "face_system\n" |
| 635 | "{\n" |
| 636 | " udp\n" |
| 637 | " {\n" |
| 638 | " hello\n" |
| 639 | " }\n" |
| 640 | "}\n"; |
| 641 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 642 | bind(&isExpectedException, _1, |
| 643 | "Unrecognized option \"hello\" in \"udp\" section")); |
| 644 | } |
| 645 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 646 | |
| 647 | BOOST_AUTO_TEST_CASE(TestProcessSectionUdpMulticastReinit) |
| 648 | { |
| 649 | const std::string CONFIG_WITH_MCAST = |
| 650 | "face_system\n" |
| 651 | "{\n" |
| 652 | " udp\n" |
| 653 | " {\n" |
| 654 | " mcast yes\n" |
| 655 | " }\n" |
| 656 | "}\n"; |
| 657 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 658 | |
| 659 | shared_ptr<UdpFactory> factory = static_pointer_cast<UdpFactory>(getManager().findFactory("udp")); |
| 660 | BOOST_REQUIRE(static_cast<bool>(factory)); |
| 661 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 662 | if (factory->getMulticastFaces().size() == 0) { |
| 663 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 664 | "no UDP multicast faces are available"); |
| 665 | } |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 666 | |
| 667 | const std::string CONFIG_WITHOUT_MCAST = |
| 668 | "face_system\n" |
| 669 | "{\n" |
| 670 | " udp\n" |
| 671 | " {\n" |
| 672 | " mcast no\n" |
| 673 | " }\n" |
| 674 | "}\n"; |
| 675 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
| 676 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 677 | } |
| 678 | |
| 679 | |
Alexander Afanasyev | 885a85b | 2014-04-12 21:01:13 -0700 | [diff] [blame] | 680 | #ifdef HAVE_LIBPCAP |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 681 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 682 | BOOST_AUTO_TEST_CASE(TestProcessSectionEther) |
| 683 | { |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 684 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 685 | const std::string CONFIG = |
| 686 | "face_system\n" |
| 687 | "{\n" |
| 688 | " ether\n" |
| 689 | " {\n" |
| 690 | " mcast yes\n" |
| 691 | " mcast_group 01:00:5E:00:17:AA\n" |
| 692 | " }\n" |
| 693 | "}\n"; |
| 694 | |
| 695 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false)); |
| 696 | } |
| 697 | |
| 698 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherDryRun) |
| 699 | { |
| 700 | const std::string CONFIG = |
| 701 | "face_system\n" |
| 702 | "{\n" |
| 703 | " ether\n" |
| 704 | " {\n" |
| 705 | " mcast yes\n" |
| 706 | " mcast_group 01:00:5E:00:17:AA\n" |
| 707 | " }\n" |
| 708 | "}\n"; |
| 709 | |
| 710 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true)); |
| 711 | } |
| 712 | |
| 713 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcast) |
| 714 | { |
| 715 | const std::string CONFIG = |
| 716 | "face_system\n" |
| 717 | "{\n" |
| 718 | " ether\n" |
| 719 | " {\n" |
| 720 | " mcast hello\n" |
| 721 | " }\n" |
| 722 | "}\n"; |
| 723 | |
| 724 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 725 | bind(&isExpectedException, _1, |
| 726 | "Invalid value for option \"mcast\" in \"ether\" section")); |
| 727 | } |
| 728 | |
| 729 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherBadMcastGroup) |
| 730 | { |
| 731 | const std::string CONFIG = |
| 732 | "face_system\n" |
| 733 | "{\n" |
| 734 | " ether\n" |
| 735 | " {\n" |
| 736 | " mcast yes\n" |
| 737 | " mcast_group\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_group\" in \"ether\" section")); |
| 744 | } |
| 745 | |
| 746 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherUnknownOption) |
| 747 | { |
| 748 | const std::string CONFIG = |
| 749 | "face_system\n" |
| 750 | "{\n" |
| 751 | " ether\n" |
| 752 | " {\n" |
| 753 | " hello\n" |
| 754 | " }\n" |
| 755 | "}\n"; |
| 756 | BOOST_CHECK_EXCEPTION(parseConfig(CONFIG, false), ConfigFile::Error, |
| 757 | bind(&isExpectedException, _1, |
| 758 | "Unrecognized option \"hello\" in \"ether\" section")); |
| 759 | } |
| 760 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 761 | BOOST_AUTO_TEST_CASE(TestProcessSectionEtherMulticastReinit) |
| 762 | { |
| 763 | const std::string CONFIG_WITH_MCAST = |
| 764 | "face_system\n" |
| 765 | "{\n" |
| 766 | " ether\n" |
| 767 | " {\n" |
| 768 | " mcast yes\n" |
| 769 | " }\n" |
| 770 | "}\n"; |
| 771 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false)); |
| 772 | |
| 773 | shared_ptr<EthernetFactory> factory = |
| 774 | static_pointer_cast<EthernetFactory>(getManager().findFactory("ether")); |
| 775 | BOOST_REQUIRE(static_cast<bool>(factory)); |
| 776 | |
Alexander Afanasyev | b56c5b9 | 2014-06-05 08:05:24 +0300 | [diff] [blame] | 777 | if (factory->getMulticastFaces().size() == 0) { |
| 778 | BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because " |
| 779 | "no Ethernet multicast faces are available"); |
| 780 | } |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 781 | |
| 782 | const std::string CONFIG_WITHOUT_MCAST = |
| 783 | "face_system\n" |
| 784 | "{\n" |
| 785 | " ether\n" |
| 786 | " {\n" |
| 787 | " mcast no\n" |
| 788 | " }\n" |
| 789 | "}\n"; |
| 790 | BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false)); |
| 791 | BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0); |
| 792 | } |
| 793 | |
Alexander Afanasyev | e918621 | 2014-08-23 20:15:48 -0700 | [diff] [blame] | 794 | #endif // HAVE_LIBPCAP |
Steve DiBenedetto | 4aca99c | 2014-03-11 11:27:54 -0600 | [diff] [blame] | 795 | |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 796 | BOOST_AUTO_TEST_CASE(ShortName) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 797 | { |
| 798 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 799 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 800 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 801 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 802 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 803 | |
| 804 | getFace()->sendInterest(*command); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame] | 805 | g_io.run_one(); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 806 | |
| 807 | BOOST_REQUIRE(didCallbackFire()); |
| 808 | } |
| 809 | |
| 810 | BOOST_AUTO_TEST_CASE(MalformedCommmand) |
| 811 | { |
| 812 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/faces")); |
| 813 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 814 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 815 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 816 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 817 | |
| 818 | getManager().onFaceRequest(*command); |
| 819 | |
| 820 | BOOST_REQUIRE(didCallbackFire()); |
| 821 | } |
| 822 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 823 | BOOST_AUTO_TEST_CASE(UnsignedCommand) |
| 824 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 825 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 826 | parameters.setUri("tcp4://127.0.0.1:6363"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 827 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 828 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 829 | |
| 830 | Name commandName("/localhost/nfd/faces"); |
| 831 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 832 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 833 | |
| 834 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 835 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 836 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 837 | this->validateControlResponse(response, command->getName(), 401, "Signature required"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 838 | }); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 839 | |
| 840 | getManager().onFaceRequest(*command); |
| 841 | |
| 842 | BOOST_REQUIRE(didCallbackFire()); |
| 843 | } |
| 844 | |
| 845 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedCommandFixture<FaceManagerFixture>) |
| 846 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 847 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 848 | parameters.setUri("tcp4://127.0.0.1:6363"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 849 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 850 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 851 | |
| 852 | Name commandName("/localhost/nfd/faces"); |
| 853 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 854 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 855 | |
| 856 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 857 | generateCommand(*command); |
| 858 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 859 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 860 | this->validateControlResponse(response, command->getName(), 403, "Unauthorized command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 861 | }); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 862 | |
| 863 | getManager().onFaceRequest(*command); |
| 864 | |
| 865 | BOOST_REQUIRE(didCallbackFire()); |
| 866 | } |
| 867 | |
| 868 | template <typename T> class AuthorizedCommandFixture : public CommandFixture<T> |
| 869 | { |
| 870 | public: |
| 871 | AuthorizedCommandFixture() |
| 872 | { |
| 873 | const std::string regex = "^<localhost><nfd><faces>"; |
| 874 | T::addInterestRule(regex, *CommandFixture<T>::m_certificate); |
| 875 | } |
| 876 | |
| 877 | virtual |
| 878 | ~AuthorizedCommandFixture() |
| 879 | { |
| 880 | |
| 881 | } |
| 882 | }; |
| 883 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 884 | BOOST_FIXTURE_TEST_CASE(UnsupportedCommand, AuthorizedCommandFixture<FaceManagerFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 885 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 886 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 887 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 888 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 889 | |
| 890 | Name commandName("/localhost/nfd/faces"); |
| 891 | commandName.append("unsupported"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 892 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 893 | |
| 894 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 895 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 896 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 897 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 898 | this->validateControlResponse(response, command->getName(), 501, "Unsupported command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 899 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 900 | |
| 901 | getManager().onFaceRequest(*command); |
| 902 | |
| 903 | BOOST_REQUIRE(didCallbackFire()); |
| 904 | } |
| 905 | |
| 906 | class ValidatedFaceRequestFixture : public TestFaceTableFixture, |
| 907 | public TestFaceManagerCommon, |
| 908 | public FaceManager |
| 909 | { |
| 910 | public: |
| 911 | |
| 912 | ValidatedFaceRequestFixture() |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 913 | : FaceManager(TestFaceTableFixture::m_faceTable, getFace(), m_testKeyChain), |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 914 | m_createFaceFired(false), |
| 915 | m_destroyFaceFired(false) |
| 916 | { |
| 917 | |
| 918 | } |
| 919 | |
| 920 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 921 | createFace(const Interest& request, |
| 922 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 923 | { |
| 924 | m_createFaceFired = true; |
| 925 | } |
| 926 | |
| 927 | virtual void |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 928 | destroyFace(const Interest& request, |
| 929 | ControlParameters& parameters) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 930 | { |
| 931 | m_destroyFaceFired = true; |
| 932 | } |
| 933 | |
| 934 | virtual |
| 935 | ~ValidatedFaceRequestFixture() |
| 936 | { |
| 937 | |
| 938 | } |
| 939 | |
| 940 | bool |
| 941 | didCreateFaceFire() const |
| 942 | { |
| 943 | return m_createFaceFired; |
| 944 | } |
| 945 | |
| 946 | bool |
| 947 | didDestroyFaceFire() const |
| 948 | { |
| 949 | return m_destroyFaceFired; |
| 950 | } |
| 951 | |
| 952 | private: |
| 953 | bool m_createFaceFired; |
| 954 | bool m_destroyFaceFired; |
| 955 | }; |
| 956 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 957 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestBadOptionParse, |
| 958 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 959 | { |
| 960 | Name commandName("/localhost/nfd/faces"); |
| 961 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 962 | commandName.append("NotReallyParameters"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 963 | |
| 964 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 965 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 966 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 967 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 968 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 969 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 970 | |
| 971 | onValidatedFaceRequest(command); |
| 972 | |
| 973 | BOOST_REQUIRE(didCallbackFire()); |
| 974 | } |
| 975 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 976 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestCreateFace, |
| 977 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 978 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 979 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 980 | parameters.setUri("tcp4://127.0.0.1:6363"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 981 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 982 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 983 | |
| 984 | Name commandName("/localhost/nfd/faces"); |
| 985 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 986 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 987 | |
| 988 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 989 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 990 | |
| 991 | onValidatedFaceRequest(command); |
| 992 | BOOST_CHECK(didCreateFaceFire()); |
| 993 | } |
| 994 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 995 | BOOST_FIXTURE_TEST_CASE(ValidatedFaceRequestDestroyFace, |
| 996 | AuthorizedCommandFixture<ValidatedFaceRequestFixture>) |
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 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 999 | parameters.setUri("tcp4://127.0.0.1:6363"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1000 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1001 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1002 | |
| 1003 | Name commandName("/localhost/nfd/faces"); |
| 1004 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1005 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1006 | |
| 1007 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1008 | generateCommand(*command); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1009 | |
| 1010 | onValidatedFaceRequest(command); |
| 1011 | BOOST_CHECK(didDestroyFaceFire()); |
| 1012 | } |
| 1013 | |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1014 | class FaceTableFixture |
| 1015 | { |
| 1016 | public: |
| 1017 | FaceTableFixture() |
| 1018 | : m_faceTable(m_forwarder) |
| 1019 | { |
| 1020 | } |
| 1021 | |
| 1022 | virtual |
| 1023 | ~FaceTableFixture() |
| 1024 | { |
| 1025 | } |
| 1026 | |
| 1027 | protected: |
| 1028 | Forwarder m_forwarder; |
| 1029 | FaceTable m_faceTable; |
| 1030 | }; |
| 1031 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1032 | class LocalControlFixture : public FaceTableFixture, |
| 1033 | public TestFaceManagerCommon, |
| 1034 | public FaceManager |
| 1035 | { |
| 1036 | public: |
| 1037 | LocalControlFixture() |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1038 | : FaceManager(FaceTableFixture::m_faceTable, getFace(), m_testKeyChain) |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1039 | { |
| 1040 | } |
| 1041 | }; |
| 1042 | |
| 1043 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceId, |
| 1044 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1045 | { |
| 1046 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1047 | BOOST_REQUIRE(dummy->isLocal()); |
| 1048 | FaceTableFixture::m_faceTable.add(dummy); |
| 1049 | |
| 1050 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1051 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1052 | |
| 1053 | Block encodedParameters(parameters.wireEncode()); |
| 1054 | |
| 1055 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1056 | enable.append(encodedParameters); |
| 1057 | |
| 1058 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1059 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1060 | |
| 1061 | generateCommand(*enableCommand); |
| 1062 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1063 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1064 | [this, enableCommand, encodedParameters] (const Data& response) { |
| 1065 | this->validateControlResponse(response, enableCommand->getName(), |
| 1066 | 200, "Success", encodedParameters); |
| 1067 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1068 | |
| 1069 | onValidatedFaceRequest(enableCommand); |
| 1070 | |
| 1071 | BOOST_REQUIRE(didCallbackFire()); |
| 1072 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1073 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1074 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1075 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1076 | resetCallbackFired(); |
| 1077 | |
| 1078 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1079 | disable.append(encodedParameters); |
| 1080 | |
| 1081 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1082 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1083 | |
| 1084 | generateCommand(*disableCommand); |
| 1085 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1086 | getFace()->onReceiveData.connect( |
| 1087 | [this, disableCommand, encodedParameters] (const Data& response) { |
| 1088 | this->validateControlResponse(response, disableCommand->getName(), |
| 1089 | 200, "Success", encodedParameters); |
| 1090 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1091 | |
| 1092 | onValidatedFaceRequest(disableCommand); |
| 1093 | |
| 1094 | BOOST_REQUIRE(didCallbackFire()); |
| 1095 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1096 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1097 | } |
| 1098 | |
| 1099 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdFaceNotFound, |
| 1100 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1101 | { |
| 1102 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1103 | BOOST_REQUIRE(dummy->isLocal()); |
| 1104 | FaceTableFixture::m_faceTable.add(dummy); |
| 1105 | |
| 1106 | ControlParameters parameters; |
| 1107 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1108 | |
| 1109 | Block encodedParameters(parameters.wireEncode()); |
| 1110 | |
| 1111 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1112 | enable.append(encodedParameters); |
| 1113 | |
| 1114 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1115 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1116 | |
| 1117 | generateCommand(*enableCommand); |
| 1118 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1119 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1120 | [this, enableCommand] (const Data& response) { |
| 1121 | this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found"); |
| 1122 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1123 | |
| 1124 | onValidatedFaceRequest(enableCommand); |
| 1125 | |
| 1126 | BOOST_REQUIRE(didCallbackFire()); |
| 1127 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1128 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1129 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1130 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1131 | resetCallbackFired(); |
| 1132 | |
| 1133 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1134 | disable.append(encodedParameters); |
| 1135 | |
| 1136 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1137 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1138 | |
| 1139 | generateCommand(*disableCommand); |
| 1140 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1141 | getFace()->onReceiveData.connect( |
| 1142 | [this, disableCommand] (const Data& response) { |
| 1143 | this->validateControlResponse(response, disableCommand->getName(), 410, "Face not found"); |
| 1144 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1145 | |
| 1146 | onValidatedFaceRequest(disableCommand); |
| 1147 | |
| 1148 | BOOST_REQUIRE(didCallbackFire()); |
| 1149 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1150 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1151 | } |
| 1152 | |
| 1153 | BOOST_FIXTURE_TEST_CASE(LocalControlMissingFeature, |
| 1154 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1155 | { |
| 1156 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1157 | BOOST_REQUIRE(dummy->isLocal()); |
| 1158 | FaceTableFixture::m_faceTable.add(dummy); |
| 1159 | |
| 1160 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1161 | |
| 1162 | Block encodedParameters(parameters.wireEncode()); |
| 1163 | |
| 1164 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1165 | enable.append(encodedParameters); |
| 1166 | |
| 1167 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1168 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1169 | |
| 1170 | generateCommand(*enableCommand); |
| 1171 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1172 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1173 | [this, enableCommand] (const Data& response) { |
| 1174 | this->validateControlResponse(response, enableCommand->getName(), |
| 1175 | 400, "Malformed command"); |
| 1176 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1177 | |
| 1178 | onValidatedFaceRequest(enableCommand); |
| 1179 | |
| 1180 | BOOST_REQUIRE(didCallbackFire()); |
| 1181 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1182 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1183 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1184 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1185 | resetCallbackFired(); |
| 1186 | |
| 1187 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1188 | disable.append(encodedParameters); |
| 1189 | |
| 1190 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1191 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1192 | |
| 1193 | generateCommand(*disableCommand); |
| 1194 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1195 | getFace()->onReceiveData.connect( |
| 1196 | [this, disableCommand] (const Data& response) { |
| 1197 | this->validateControlResponse(response, disableCommand->getName(), |
| 1198 | 400, "Malformed command"); |
| 1199 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1200 | |
| 1201 | onValidatedFaceRequest(disableCommand); |
| 1202 | |
| 1203 | BOOST_REQUIRE(didCallbackFire()); |
| 1204 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1205 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1206 | } |
| 1207 | |
| 1208 | BOOST_FIXTURE_TEST_CASE(LocalControlInFaceIdNonLocal, |
| 1209 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1210 | { |
| 1211 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1212 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1213 | FaceTableFixture::m_faceTable.add(dummy); |
| 1214 | |
| 1215 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1216 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 1217 | |
| 1218 | Block encodedParameters(parameters.wireEncode()); |
| 1219 | |
| 1220 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1221 | enable.append(encodedParameters); |
| 1222 | |
| 1223 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1224 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1225 | |
| 1226 | generateCommand(*enableCommand); |
| 1227 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1228 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1229 | [this, enableCommand] (const Data& response) { |
| 1230 | this->validateControlResponse(response, enableCommand->getName(), |
| 1231 | 412, "Face is non-local"); |
| 1232 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1233 | |
| 1234 | onValidatedFaceRequest(enableCommand); |
| 1235 | |
| 1236 | BOOST_REQUIRE(didCallbackFire()); |
| 1237 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1238 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1239 | resetCallbackFired(); |
| 1240 | |
| 1241 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1242 | enable.append(encodedParameters); |
| 1243 | |
| 1244 | shared_ptr<Interest> disableCommand(make_shared<Interest>(enable)); |
| 1245 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1246 | |
| 1247 | generateCommand(*disableCommand); |
| 1248 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1249 | getFace()->onReceiveData.connect( |
| 1250 | [this, disableCommand] (const Data& response) { |
| 1251 | this->validateControlResponse(response, disableCommand->getName(), |
| 1252 | 412, "Face is non-local"); |
| 1253 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1254 | |
| 1255 | onValidatedFaceRequest(disableCommand); |
| 1256 | |
| 1257 | BOOST_REQUIRE(didCallbackFire()); |
| 1258 | } |
| 1259 | |
| 1260 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceId, |
| 1261 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1262 | { |
| 1263 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1264 | BOOST_REQUIRE(dummy->isLocal()); |
| 1265 | FaceTableFixture::m_faceTable.add(dummy); |
| 1266 | |
| 1267 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1268 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1269 | |
| 1270 | Block encodedParameters(parameters.wireEncode()); |
| 1271 | |
| 1272 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1273 | enable.append(encodedParameters); |
| 1274 | |
| 1275 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1276 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1277 | |
| 1278 | generateCommand(*enableCommand); |
| 1279 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1280 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1281 | [this, enableCommand, encodedParameters] (const Data& response) { |
| 1282 | this->validateControlResponse(response, enableCommand->getName(), |
| 1283 | 200, "Success", encodedParameters); |
| 1284 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1285 | |
| 1286 | onValidatedFaceRequest(enableCommand); |
| 1287 | |
| 1288 | BOOST_REQUIRE(didCallbackFire()); |
| 1289 | BOOST_REQUIRE(dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1290 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1291 | |
| 1292 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1293 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1294 | resetCallbackFired(); |
| 1295 | |
| 1296 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1297 | disable.append(encodedParameters); |
| 1298 | |
| 1299 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1300 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1301 | |
| 1302 | generateCommand(*disableCommand); |
| 1303 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1304 | getFace()->onReceiveData.connect( |
| 1305 | [this, disableCommand, encodedParameters] (const Data& response) { |
| 1306 | this->validateControlResponse(response, disableCommand->getName(), |
| 1307 | 200, "Success", encodedParameters); |
| 1308 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1309 | |
| 1310 | onValidatedFaceRequest(disableCommand); |
| 1311 | |
| 1312 | BOOST_REQUIRE(didCallbackFire()); |
| 1313 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1314 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1315 | } |
| 1316 | |
| 1317 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdFaceNotFound, |
| 1318 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1319 | { |
| 1320 | shared_ptr<LocalFace> dummy = make_shared<DummyLocalFace>(); |
| 1321 | BOOST_REQUIRE(dummy->isLocal()); |
| 1322 | FaceTableFixture::m_faceTable.add(dummy); |
| 1323 | |
| 1324 | ControlParameters parameters; |
| 1325 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1326 | |
| 1327 | Block encodedParameters(parameters.wireEncode()); |
| 1328 | |
| 1329 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1330 | enable.append(encodedParameters); |
| 1331 | |
| 1332 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1333 | enableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1334 | |
| 1335 | generateCommand(*enableCommand); |
| 1336 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1337 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1338 | [this, enableCommand] (const Data& response) { |
| 1339 | this->validateControlResponse(response, enableCommand->getName(), 410, "Face not found"); |
| 1340 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1341 | |
| 1342 | onValidatedFaceRequest(enableCommand); |
| 1343 | |
| 1344 | BOOST_REQUIRE(didCallbackFire()); |
| 1345 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1346 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1347 | |
| 1348 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1349 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1350 | resetCallbackFired(); |
| 1351 | |
| 1352 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1353 | disable.append(encodedParameters); |
| 1354 | |
| 1355 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1356 | disableCommand->setIncomingFaceId(dummy->getId() + 100); |
| 1357 | |
| 1358 | generateCommand(*disableCommand); |
| 1359 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1360 | getFace()->onReceiveData.connect( |
| 1361 | [this, disableCommand] (const Data& response) { |
| 1362 | this->validateControlResponse(response, disableCommand->getName(), |
| 1363 | 410, "Face not found"); |
| 1364 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1365 | |
| 1366 | onValidatedFaceRequest(disableCommand); |
| 1367 | |
| 1368 | BOOST_REQUIRE(didCallbackFire()); |
| 1369 | BOOST_REQUIRE(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
| 1370 | BOOST_CHECK(!dummy->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 1371 | } |
| 1372 | |
| 1373 | BOOST_FIXTURE_TEST_CASE(LocalControlNextHopFaceIdNonLocal, |
| 1374 | AuthorizedCommandFixture<LocalControlFixture>) |
| 1375 | { |
| 1376 | shared_ptr<DummyFace> dummy = make_shared<DummyFace>(); |
| 1377 | BOOST_REQUIRE(!dummy->isLocal()); |
| 1378 | FaceTableFixture::m_faceTable.add(dummy); |
| 1379 | |
| 1380 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1381 | parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 1382 | |
| 1383 | Block encodedParameters(parameters.wireEncode()); |
| 1384 | |
| 1385 | Name enable("/localhost/nfd/faces/enable-local-control"); |
| 1386 | enable.append(encodedParameters); |
| 1387 | |
| 1388 | shared_ptr<Interest> enableCommand(make_shared<Interest>(enable)); |
| 1389 | enableCommand->setIncomingFaceId(dummy->getId()); |
| 1390 | |
| 1391 | generateCommand(*enableCommand); |
| 1392 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1393 | signal::Connection conn = getFace()->onReceiveData.connect( |
| 1394 | [this, enableCommand] (const Data& response) { |
| 1395 | this->validateControlResponse(response, enableCommand->getName(), |
| 1396 | 412, "Face is non-local"); |
| 1397 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1398 | |
| 1399 | onValidatedFaceRequest(enableCommand); |
| 1400 | |
| 1401 | BOOST_REQUIRE(didCallbackFire()); |
| 1402 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1403 | conn.disconnect(); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1404 | resetCallbackFired(); |
| 1405 | |
| 1406 | Name disable("/localhost/nfd/faces/disable-local-control"); |
| 1407 | disable.append(encodedParameters); |
| 1408 | |
| 1409 | shared_ptr<Interest> disableCommand(make_shared<Interest>(disable)); |
| 1410 | disableCommand->setIncomingFaceId(dummy->getId()); |
| 1411 | |
| 1412 | generateCommand(*disableCommand); |
| 1413 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1414 | getFace()->onReceiveData.connect( |
| 1415 | [this, disableCommand] (const Data& response) { |
| 1416 | this->validateControlResponse(response, disableCommand->getName(), |
| 1417 | 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, |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1432 | getFace(), |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 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; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1523 | parameters.setUri("tcp4:/127.0.0.1:6363"); |
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 | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1534 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 1535 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 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 | } |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1542 | BOOST_FIXTURE_TEST_CASE(CreateFaceNoncanonicalUri, AuthorizedCommandFixture<FaceFixture>) |
| 1543 | { |
| 1544 | ControlParameters parameters; |
| 1545 | parameters.setUri("tcp://127.0.0.1"); |
| 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 | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1556 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1557 | this->validateControlResponse(response, command->getName(), 400, "Non-canonical URI"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1558 | }); |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1559 | |
| 1560 | createFace(*command, parameters); |
| 1561 | |
| 1562 | BOOST_REQUIRE(didCallbackFire()); |
| 1563 | } |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1564 | |
| 1565 | BOOST_FIXTURE_TEST_CASE(CreateFaceMissingUri, AuthorizedCommandFixture<FaceFixture>) |
| 1566 | { |
| 1567 | ControlParameters parameters; |
| 1568 | |
| 1569 | Block encodedParameters(parameters.wireEncode()); |
| 1570 | |
| 1571 | Name commandName("/localhost/nfd/faces"); |
| 1572 | commandName.append("create"); |
| 1573 | commandName.append(encodedParameters); |
| 1574 | |
| 1575 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1576 | generateCommand(*command); |
| 1577 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1578 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 1579 | this->validateControlResponse(response, command->getName(), 400, "Malformed command"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1580 | }); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1581 | |
| 1582 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1583 | |
| 1584 | BOOST_REQUIRE(didCallbackFire()); |
| 1585 | } |
| 1586 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1587 | BOOST_FIXTURE_TEST_CASE(CreateFaceUnknownScheme, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1588 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1589 | ControlParameters parameters; |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1590 | // this will be an unsupported protocol because no factories have been |
| 1591 | // added to the face manager |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1592 | parameters.setUri("tcp4://127.0.0.1:6363"); |
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 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1603 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 1604 | this->validateControlResponse(response, command->getName(), 501, "Unsupported protocol"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1605 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1606 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1607 | createFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1608 | |
| 1609 | BOOST_REQUIRE(didCallbackFire()); |
| 1610 | } |
| 1611 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1612 | BOOST_FIXTURE_TEST_CASE(OnCreated, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1613 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1614 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1615 | parameters.setUri("tcp4://127.0.0.1:6363"); |
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 encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1618 | |
| 1619 | Name commandName("/localhost/nfd/faces"); |
| 1620 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1621 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1622 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1623 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1624 | generateCommand(*command); |
| 1625 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1626 | ControlParameters resultParameters; |
Steve DiBenedetto | 2599928 | 2014-05-22 15:25:12 -0600 | [diff] [blame] | 1627 | resultParameters.setUri("dummy://"); |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1628 | resultParameters.setFaceId(FACEID_RESERVED_MAX + 1); |
Yukai Tu | 8149d10 | 2015-09-04 06:57:01 +0800 | [diff] [blame] | 1629 | resultParameters.setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1630 | |
| 1631 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1632 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1633 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1634 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_CREATED) |
Junxiao Shi | 7b984c6 | 2014-07-17 22:18:34 -0700 | [diff] [blame] | 1635 | .setFaceId(FACEID_RESERVED_MAX + 1) |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1636 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1637 | .setLocalUri(dummy->getLocalUri().toString()) |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 1638 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 1639 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1640 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1641 | Block encodedResultParameters(resultParameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1642 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1643 | getFace()->onReceiveData.connect( |
| 1644 | [this, command, encodedResultParameters, expectedFaceEvent] (const Data& response) { |
| 1645 | this->callbackDispatch(response,command->getName(), 200, "Success", |
| 1646 | encodedResultParameters, expectedFaceEvent); |
| 1647 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1648 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1649 | onCreated(command->getName(), parameters, dummy); |
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_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1655 | BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1656 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1657 | ControlParameters parameters; |
Chengyu Fan | b94af7c | 2014-12-17 11:46:47 +0800 | [diff] [blame] | 1658 | parameters.setUri("tcp4://127.0.0.1:6363"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1659 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1660 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1661 | |
| 1662 | Name commandName("/localhost/nfd/faces"); |
| 1663 | commandName.append("create"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1664 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1665 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1666 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1667 | generateCommand(*command); |
| 1668 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1669 | getFace()->onReceiveData.connect([this, command] (const Data& response) { |
Junxiao Shi | cd55cde | 2014-11-13 16:03:24 -0700 | [diff] [blame] | 1670 | this->validateControlResponse(response, command->getName(), 408, "unit-test-reason"); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1671 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1672 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1673 | onConnectFailed(command->getName(), "unit-test-reason"); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1674 | |
| 1675 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1676 | BOOST_CHECK_EQUAL(didReceiveNotication(), false); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1680 | BOOST_FIXTURE_TEST_CASE(DestroyFace, AuthorizedCommandFixture<FaceFixture>) |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1681 | { |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1682 | shared_ptr<DummyFace> dummy(make_shared<DummyFace>()); |
| 1683 | FaceTableFixture::m_faceTable.add(dummy); |
| 1684 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1685 | ControlParameters parameters; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1686 | parameters.setFaceId(dummy->getId()); |
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 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1689 | |
| 1690 | Name commandName("/localhost/nfd/faces"); |
| 1691 | commandName.append("destroy"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1692 | commandName.append(encodedParameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1693 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1694 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1695 | generateCommand(*command); |
| 1696 | |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 1697 | ndn::nfd::FaceEventNotification expectedFaceEvent; |
| 1698 | expectedFaceEvent.setKind(ndn::nfd::FACE_EVENT_DESTROYED) |
| 1699 | .setFaceId(dummy->getId()) |
| 1700 | .setRemoteUri(dummy->getRemoteUri().toString()) |
| 1701 | .setLocalUri(dummy->getLocalUri().toString()) |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 1702 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 1703 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1704 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1705 | getFace()->onReceiveData.connect( |
| 1706 | [this, command, encodedParameters, expectedFaceEvent] (const Data& response) { |
| 1707 | this->callbackDispatch(response,command->getName(), 200, "Success", |
| 1708 | encodedParameters, expectedFaceEvent); |
| 1709 | }); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1710 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 1711 | destroyFace(*command, parameters); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1712 | |
| 1713 | BOOST_REQUIRE(didCallbackFire()); |
Steve DiBenedetto | fbb40a8 | 2014-03-11 19:40:15 -0600 | [diff] [blame] | 1714 | BOOST_REQUIRE(didReceiveNotication()); |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1717 | class FaceListFixture : public FaceStatusPublisherFixture |
| 1718 | { |
| 1719 | public: |
| 1720 | FaceListFixture() |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 1721 | : m_manager(m_table, m_face, m_testKeyChain) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1722 | { |
| 1723 | |
| 1724 | } |
| 1725 | |
| 1726 | virtual |
| 1727 | ~FaceListFixture() |
| 1728 | { |
| 1729 | |
| 1730 | } |
| 1731 | |
| 1732 | protected: |
| 1733 | FaceManager m_manager; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 1734 | ndn::KeyChain m_testKeyChain; |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1735 | }; |
| 1736 | |
| 1737 | BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1738 | { |
| 1739 | Name commandName("/localhost/nfd/faces/list"); |
| 1740 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 1741 | |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 1742 | // MAX_SEGMENT_SIZE == 4400, FaceStatus size with filler counters is 75 |
| 1743 | // use 59 FaceStatuses to force a FaceStatus to span Data packets |
| 1744 | for (int i = 0; i < 59; i++) |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1745 | { |
| 1746 | shared_ptr<TestCountersFace> dummy(make_shared<TestCountersFace>()); |
| 1747 | |
| 1748 | uint64_t filler = std::numeric_limits<uint64_t>::max() - 1; |
Junxiao Shi | 632a620 | 2014-07-20 01:14:30 -0700 | [diff] [blame] | 1749 | dummy->setCounters(filler, filler, filler, filler, filler, filler); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1750 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 1751 | m_referenceFaces.push_back(dummy); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1752 | |
| 1753 | add(dummy); |
| 1754 | } |
| 1755 | |
| 1756 | ndn::EncodingBuffer buffer; |
| 1757 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1758 | m_face->onReceiveData.connect(bind(&FaceStatusPublisherFixture::decodeFaceStatusBlock, |
| 1759 | this, _1)); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1760 | |
| 1761 | m_manager.listFaces(*command); |
| 1762 | BOOST_REQUIRE(m_finished); |
| 1763 | } |
| 1764 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 1765 | class ChannelStatusFixture : public FaceManagerFixture |
| 1766 | { |
| 1767 | public: |
| 1768 | void |
| 1769 | validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry) |
| 1770 | { |
| 1771 | m_callbackFired = true; |
| 1772 | Block b = data.getContent().blockFromValue(); |
| 1773 | ndn::nfd::ChannelStatus entry(b); |
| 1774 | BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri()); |
| 1775 | } |
| 1776 | |
| 1777 | virtual shared_ptr<DummyProtocolFactory> |
| 1778 | addProtocolFactory(const std::string& protocol) |
| 1779 | { |
| 1780 | shared_ptr<DummyProtocolFactory> factory(make_shared<DummyProtocolFactory>()); |
| 1781 | m_manager.m_factories[protocol] = factory; |
| 1782 | |
| 1783 | return factory; |
| 1784 | } |
| 1785 | }; |
| 1786 | |
| 1787 | BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture) |
| 1788 | { |
| 1789 | shared_ptr<DummyProtocolFactory> factory(addProtocolFactory("dummy")); |
| 1790 | factory->addChannel("dummy://"); |
| 1791 | |
| 1792 | Name requestName("/localhost/nfd/faces/channels"); |
| 1793 | shared_ptr<Interest> request(make_shared<Interest>(requestName)); |
| 1794 | |
| 1795 | ndn::nfd::ChannelStatus expectedEntry; |
| 1796 | expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString()); |
| 1797 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1798 | m_face->onReceiveData.connect(bind(&ChannelStatusFixture::validatePublish, |
| 1799 | this, _1, expectedEntry)); |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 1800 | |
| 1801 | m_manager.listChannels(*request); |
| 1802 | BOOST_REQUIRE(m_callbackFired); |
| 1803 | } |
| 1804 | |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1805 | class FaceQueryListFixture : public FaceQueryStatusPublisherFixture |
| 1806 | { |
| 1807 | public: |
| 1808 | FaceQueryListFixture() |
| 1809 | : m_manager(m_table, m_face, m_testKeyChain) |
| 1810 | { |
| 1811 | |
| 1812 | } |
| 1813 | |
| 1814 | virtual |
| 1815 | ~FaceQueryListFixture() |
| 1816 | { |
| 1817 | |
| 1818 | } |
| 1819 | |
| 1820 | protected: |
| 1821 | FaceManager m_manager; |
| 1822 | ndn::KeyChain m_testKeyChain; |
| 1823 | }; |
| 1824 | |
| 1825 | BOOST_FIXTURE_TEST_CASE(TestValidQueryFilter, FaceQueryListFixture) |
| 1826 | { |
| 1827 | Name queryName("/localhost/nfd/faces/query"); |
| 1828 | ndn::nfd::FaceQueryFilter queryFilter; |
| 1829 | queryFilter.setUriScheme("dummy"); |
| 1830 | queryName.append(queryFilter.wireEncode()); |
| 1831 | |
| 1832 | shared_ptr<Interest> query(make_shared<Interest>(queryName)); |
| 1833 | |
| 1834 | // add expected faces |
| 1835 | shared_ptr<DummyLocalFace> expectedFace1(make_shared<DummyLocalFace>()); |
| 1836 | m_referenceFaces.push_back(expectedFace1); |
| 1837 | add(expectedFace1); |
| 1838 | |
| 1839 | shared_ptr<DummyFace> expectedFace2(make_shared<DummyFace>()); |
| 1840 | m_referenceFaces.push_back(expectedFace2); |
| 1841 | add(expectedFace2); |
| 1842 | |
| 1843 | // add other faces |
| 1844 | shared_ptr<DummyFace> face1(make_shared<DummyFace>("udp://", "udp://")); |
| 1845 | add(face1); |
| 1846 | shared_ptr<DummyLocalFace> face2(make_shared<DummyLocalFace>("tcp://", "tcp://")); |
| 1847 | add(face2); |
| 1848 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1849 | m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeFaceStatusBlock, |
| 1850 | this, _1)); |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1851 | |
| 1852 | m_manager.listQueriedFaces(*query); |
| 1853 | BOOST_REQUIRE(m_finished); |
| 1854 | } |
| 1855 | |
Chengyu Fan | ab205c2 | 2014-11-18 10:58:41 -0700 | [diff] [blame] | 1856 | BOOST_FIXTURE_TEST_CASE(TestInvalidQueryFilter, FaceQueryListFixture) |
| 1857 | { |
| 1858 | Name queryName("/localhost/nfd/faces/query"); |
| 1859 | ndn::nfd::FaceStatus queryFilter; |
| 1860 | queryName.append(queryFilter.wireEncode()); |
| 1861 | |
| 1862 | shared_ptr<Interest> query(make_shared<Interest>(queryName)); |
| 1863 | |
| 1864 | shared_ptr<DummyLocalFace> face(make_shared<DummyLocalFace>()); |
| 1865 | add(face); |
| 1866 | |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 1867 | m_face->onReceiveData.connect(bind(&FaceQueryStatusPublisherFixture::decodeNackBlock, this, _1)); |
Chengyu Fan | ab205c2 | 2014-11-18 10:58:41 -0700 | [diff] [blame] | 1868 | |
| 1869 | m_manager.listQueriedFaces(*query); |
| 1870 | BOOST_REQUIRE(m_finished); |
| 1871 | } |
Chengyu Fan | 320d233 | 2014-10-29 16:40:33 -0600 | [diff] [blame] | 1872 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 1873 | BOOST_AUTO_TEST_SUITE_END() |
| 1874 | |
| 1875 | } // namespace tests |
| 1876 | } // namespace nfd |