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