Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 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. |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "mgmt/face-manager.hpp" |
| 27 | #include "fw/forwarder.hpp" |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
| 29 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 30 | |
| 31 | #include <thread> |
| 32 | #include <boost/property_tree/info_parser.hpp> |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 33 | |
| 34 | #include "tests/test-common.hpp" |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 35 | #include "tests/identity-management-fixture.hpp" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 36 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 37 | namespace nfd { |
| 38 | namespace tests { |
| 39 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 40 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 41 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 42 | |
| 43 | BOOST_FIXTURE_TEST_SUITE(CreateFace, BaseFixture) |
| 44 | |
| 45 | class FaceManagerNode |
| 46 | { |
| 47 | public: |
| 48 | FaceManagerNode(ndn::KeyChain& keyChain, const std::string& port = "6363") |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 49 | : faceTable(forwarder.getFaceTable()) |
| 50 | , face(getGlobalIoService(), keyChain, {true, true}) |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 51 | , dispatcher(face, keyChain, ndn::security::SigningInfo()) |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 52 | , manager(faceTable, dispatcher, validator) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 53 | { |
| 54 | dispatcher.addTopPrefix("/localhost/nfd"); |
| 55 | |
| 56 | std::string basicConfig = |
| 57 | "face_system\n" |
| 58 | "{\n" |
| 59 | " tcp\n" |
| 60 | " {\n" |
| 61 | " port " + port + "\n" |
| 62 | " }\n" |
| 63 | " udp\n" |
| 64 | " {\n" |
| 65 | " port " + port + "\n" |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 66 | " mcast no\n" |
| 67 | " }\n" |
| 68 | " ether\n" |
| 69 | " {\n" |
| 70 | " mcast no\n" |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 71 | " }\n" |
| 72 | "}\n" |
| 73 | "authorizations\n" |
| 74 | "{\n" |
| 75 | " authorize\n" |
| 76 | " {\n" |
| 77 | " certfile any\n" |
| 78 | " privileges\n" |
| 79 | " {\n" |
| 80 | " faces\n" |
| 81 | " }\n" |
| 82 | " }\n" |
| 83 | "}\n" |
| 84 | "\n"; |
| 85 | std::istringstream input(basicConfig); |
| 86 | nfd::ConfigSection configSection; |
| 87 | boost::property_tree::read_info(input, configSection); |
| 88 | |
| 89 | ConfigFile config; |
| 90 | manager.setConfigFile(config); |
| 91 | validator.setConfigFile(config); |
| 92 | config.parse(configSection, false, "dummy-config"); |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | closeFaces() |
| 97 | { |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 98 | std::vector<std::reference_wrapper<Face>> facesToClose; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 99 | std::copy(forwarder.getFaceTable().begin(), forwarder.getFaceTable().end(), |
| 100 | std::back_inserter(facesToClose)); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 101 | for (Face& face : facesToClose) { |
| 102 | face.close(); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | public: |
| 107 | Forwarder forwarder; |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 108 | FaceTable& faceTable; |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 109 | ndn::util::DummyClientFace face; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 110 | ndn::mgmt::Dispatcher dispatcher; |
| 111 | CommandValidator validator; |
| 112 | FaceManager manager; |
| 113 | }; |
| 114 | |
| 115 | class FaceManagerFixture : public UnitTestTimeFixture |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 116 | , public IdentityManagementFixture |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 117 | { |
| 118 | public: |
| 119 | FaceManagerFixture() |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 120 | : node1(m_keyChain, "16363") |
| 121 | , node2(m_keyChain, "26363") |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 122 | { |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 123 | advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | ~FaceManagerFixture() |
| 127 | { |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 128 | // Explicitly closing faces is necessary. Otherwise, in a subsequent test case, |
| 129 | // incoming packets may be delivered to an old socket from previous test cases. |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 130 | node1.closeFaces(); |
| 131 | node2.closeFaces(); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 132 | advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | public: |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 136 | FaceManagerNode node1; // used to test FaceManager |
| 137 | FaceManagerNode node2; // acts as a remote endpoint |
| 138 | }; |
| 139 | |
| 140 | class TcpFaceOnDemand |
| 141 | { |
| 142 | public: |
| 143 | ControlParameters |
| 144 | getParameters() |
| 145 | { |
| 146 | return ControlParameters() |
| 147 | .setUri("tcp4://127.0.0.1:26363") |
| 148 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | class TcpFacePersistent |
| 153 | { |
| 154 | public: |
| 155 | ControlParameters |
| 156 | getParameters() |
| 157 | { |
| 158 | return ControlParameters() |
| 159 | .setUri("tcp4://127.0.0.1:26363") |
| 160 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | class TcpFacePermanent |
| 165 | { |
| 166 | public: |
| 167 | ControlParameters |
| 168 | getParameters() |
| 169 | { |
| 170 | return ControlParameters() |
| 171 | .setUri("tcp4://127.0.0.1:26363") |
| 172 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | class UdpFaceOnDemand |
| 177 | { |
| 178 | public: |
| 179 | ControlParameters |
| 180 | getParameters() |
| 181 | { |
| 182 | return ControlParameters() |
| 183 | .setUri("udp4://127.0.0.1:26363") |
| 184 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | class UdpFaceCannotConnect // face that will cause afterCreateFaceFailure to be invoked |
| 189 | { |
| 190 | public: |
| 191 | ControlParameters |
| 192 | getParameters() |
| 193 | { |
| 194 | return ControlParameters() |
| 195 | .setUri("udp4://0.0.0.0:16363"); // cannot connect to self |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | |
| 200 | class UdpFacePersistent |
| 201 | { |
| 202 | public: |
| 203 | ControlParameters |
| 204 | getParameters() |
| 205 | { |
| 206 | return ControlParameters() |
| 207 | .setUri("udp4://127.0.0.1:26363") |
| 208 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | class UdpFacePermanent |
| 213 | { |
| 214 | public: |
| 215 | ControlParameters |
| 216 | getParameters() |
| 217 | { |
| 218 | return ControlParameters() |
| 219 | .setUri("udp4://127.0.0.1:26363") |
| 220 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 221 | } |
| 222 | }; |
| 223 | |
| 224 | class Success |
| 225 | { |
| 226 | public: |
| 227 | ControlResponse |
| 228 | getExpected() |
| 229 | { |
| 230 | return ControlResponse() |
| 231 | .setCode(200) |
| 232 | .setText("OK"); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | template<int CODE> |
| 237 | class Failure |
| 238 | { |
| 239 | public: |
| 240 | ControlResponse |
| 241 | getExpected() |
| 242 | { |
| 243 | return ControlResponse() |
| 244 | .setCode(CODE) |
| 245 | .setText("Error"); // error description should not be checked |
| 246 | } |
| 247 | }; |
| 248 | |
| 249 | namespace mpl = boost::mpl; |
| 250 | |
| 251 | // pairs of CreateCommand and Success status |
| 252 | typedef mpl::vector<mpl::pair<TcpFaceOnDemand, Failure<500>>, |
| 253 | mpl::pair<TcpFacePersistent, Success>, |
| 254 | mpl::pair<TcpFacePermanent, Failure<500>>, |
| 255 | mpl::pair<UdpFaceOnDemand, Failure<500>>, |
| 256 | mpl::pair<UdpFacePersistent, Success>, |
| 257 | mpl::pair<UdpFacePermanent, Success>, |
| 258 | mpl::pair<UdpFaceCannotConnect, Failure<408>>> Faces; |
| 259 | |
| 260 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, Faces, FaceManagerFixture) |
| 261 | { |
| 262 | typedef typename T::first FaceType; |
| 263 | typedef typename T::second CreateResult; |
| 264 | |
| 265 | Name commandName("/localhost/nfd/faces"); |
| 266 | commandName.append("create"); |
| 267 | commandName.append(FaceType().getParameters().wireEncode()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 268 | auto command = makeInterest(commandName); |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 269 | m_keyChain.sign(*command); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 270 | |
| 271 | bool hasCallbackFired = false; |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 272 | this->node1.face.onSendData.connect([this, command, &hasCallbackFired] (const Data& response) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 273 | if (!command->getName().isPrefixOf(response.getName())) { |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | ControlResponse actual(response.getContent().blockFromValue()); |
| 278 | ControlResponse expected(CreateResult().getExpected()); |
| 279 | BOOST_CHECK_EQUAL(expected.getCode(), actual.getCode()); |
Alexander Afanasyev | 964d459 | 2015-10-09 13:03:19 -0700 | [diff] [blame] | 280 | BOOST_TEST_MESSAGE(actual.getText()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 281 | |
| 282 | if (actual.getBody().hasWire()) { |
| 283 | ControlParameters expectedParams(FaceType().getParameters()); |
| 284 | ControlParameters actualParams(actual.getBody()); |
| 285 | |
| 286 | BOOST_CHECK_EQUAL(expectedParams.getUri(), actualParams.getUri()); |
| 287 | BOOST_CHECK_EQUAL(expectedParams.getFacePersistency(), actualParams.getFacePersistency()); |
| 288 | } |
| 289 | hasCallbackFired = true; |
| 290 | }); |
| 291 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 292 | this->node1.face.receive(*command); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 293 | this->advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 294 | |
| 295 | BOOST_CHECK(hasCallbackFired); |
| 296 | } |
| 297 | |
| 298 | |
| 299 | typedef mpl::vector<// mpl::pair<mpl::pair<TcpFacePersistent, TcpFacePermanent>, TcpFacePermanent>, // no need to check now |
| 300 | // mpl::pair<mpl::pair<TcpFacePermanent, TcpFacePersistent>, TcpFacePermanent>, // no need to check now |
| 301 | mpl::pair<mpl::pair<UdpFacePersistent, UdpFacePermanent>, UdpFacePermanent>, |
| 302 | mpl::pair<mpl::pair<UdpFacePermanent, UdpFacePersistent>, UdpFacePermanent>> FaceTransitions; |
| 303 | |
| 304 | |
| 305 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFace, T, FaceTransitions, FaceManagerFixture) |
| 306 | { |
| 307 | typedef typename T::first::first FaceType1; |
| 308 | typedef typename T::first::second FaceType2; |
| 309 | typedef typename T::second FinalFaceType; |
| 310 | |
| 311 | { |
| 312 | // create face |
| 313 | |
| 314 | Name commandName("/localhost/nfd/faces"); |
| 315 | commandName.append("create"); |
| 316 | commandName.append(FaceType1().getParameters().wireEncode()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 317 | auto command = makeInterest(commandName); |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 318 | m_keyChain.sign(*command); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 319 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 320 | this->node1.face.receive(*command); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 321 | this->advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // |
| 325 | { |
| 326 | // re-create face (= change face persistency) |
| 327 | |
| 328 | Name commandName("/localhost/nfd/faces"); |
| 329 | commandName.append("create"); |
| 330 | commandName.append(FaceType2().getParameters().wireEncode()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 331 | auto command = makeInterest(commandName); |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 332 | m_keyChain.sign(*command); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 333 | |
| 334 | bool hasCallbackFired = false; |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 335 | this->node1.face.onSendData.connect([this, command, &hasCallbackFired] (const Data& response) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 336 | if (!command->getName().isPrefixOf(response.getName())) { |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | ControlResponse actual(response.getContent().blockFromValue()); |
| 341 | BOOST_REQUIRE_EQUAL(actual.getCode(), 200); |
| 342 | |
| 343 | ControlParameters expectedParams(FinalFaceType().getParameters()); |
| 344 | ControlParameters actualParams(actual.getBody()); |
| 345 | BOOST_CHECK_EQUAL(expectedParams.getFacePersistency(), actualParams.getFacePersistency()); |
| 346 | |
| 347 | hasCallbackFired = true; |
| 348 | }); |
| 349 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 350 | this->node1.face.receive(*command); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 351 | this->advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 352 | |
| 353 | BOOST_CHECK(hasCallbackFired); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | |
| 358 | class UdpFace |
| 359 | { |
| 360 | public: |
| 361 | ControlParameters |
| 362 | getParameters() |
| 363 | { |
| 364 | return ControlParameters() |
| 365 | .setUri("udp4://127.0.0.1:16363") |
| 366 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | |
| 371 | // Note that the transitions from on-demand TcpFace are intentionally not tested. |
| 372 | // On-demand TcpFace has a remote endpoint with a randomized port number. Normal face |
| 373 | // creation operations will not need to create a face toward a remote port not listened by |
| 374 | // a channel. |
| 375 | |
| 376 | typedef mpl::vector<mpl::pair<UdpFace, UdpFacePersistent>, |
| 377 | mpl::pair<UdpFace, UdpFacePermanent>> OnDemandFaceTransitions; |
| 378 | |
| 379 | // need a slightly different logic to test transitions from OnDemand state |
| 380 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExistingFaceOnDemand, T, OnDemandFaceTransitions, FaceManagerFixture) |
| 381 | { |
| 382 | typedef typename T::first OtherNodeFace; |
| 383 | typedef typename T::second FaceType; |
| 384 | |
| 385 | { |
| 386 | // create on-demand face |
| 387 | |
| 388 | Name commandName("/localhost/nfd/faces"); |
| 389 | commandName.append("create"); |
| 390 | commandName.append(OtherNodeFace().getParameters().wireEncode()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 391 | auto command = makeInterest(commandName); |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 392 | m_keyChain.sign(*command); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 393 | |
| 394 | ndn::util::signal::ScopedConnection connection = |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 395 | this->node2.face.onSendData.connect([this, command] (const Data& response) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 396 | if (!command->getName().isPrefixOf(response.getName())) { |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | ControlResponse controlResponse(response.getContent().blockFromValue()); |
| 401 | BOOST_REQUIRE_EQUAL(controlResponse.getText(), "OK"); |
| 402 | BOOST_REQUIRE_EQUAL(controlResponse.getCode(), 200); |
| 403 | uint64_t faceId = ControlParameters(controlResponse.getBody()).getFaceId(); |
| 404 | auto face = this->node2.forwarder.getFace(static_cast<FaceId>(faceId)); |
| 405 | |
| 406 | // to force creation of on-demand face |
| 407 | auto dummyInterest = make_shared<Interest>("/hello/world"); |
| 408 | face->sendInterest(*dummyInterest); |
| 409 | }); |
| 410 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 411 | this->node2.face.receive(*command); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 412 | this->advanceClocks(time::milliseconds(1), 5); // let node2 process command and send Interest |
| 413 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO |
| 414 | this->advanceClocks(time::milliseconds(1), 5); // let node1 accept Interest and create on-demand face |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | // make sure there is on-demand face |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 418 | FaceUri onDemandFaceUri(FaceType().getParameters().getUri()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 419 | const Face* foundFace = nullptr; |
| 420 | for (const Face& face : this->node1.faceTable) { |
| 421 | if (face.getRemoteUri() == onDemandFaceUri) { |
| 422 | foundFace = &face; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | } |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 426 | BOOST_REQUIRE_MESSAGE(foundFace != nullptr, "on-demand face is not created"); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 427 | |
| 428 | // |
| 429 | { |
| 430 | // re-create face (= change face persistency) |
| 431 | |
| 432 | Name commandName("/localhost/nfd/faces"); |
| 433 | commandName.append("create"); |
| 434 | commandName.append(FaceType().getParameters().wireEncode()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 435 | auto command = makeInterest(commandName); |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 436 | m_keyChain.sign(*command); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 437 | |
| 438 | bool hasCallbackFired = false; |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 439 | this->node1.face.onSendData.connect( |
| 440 | [this, command, &hasCallbackFired, foundFace] (const Data& response) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 441 | if (!command->getName().isPrefixOf(response.getName())) { |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | ControlResponse actual(response.getContent().blockFromValue()); |
| 446 | BOOST_REQUIRE_EQUAL(actual.getCode(), 200); |
| 447 | |
| 448 | ControlParameters expectedParams(FaceType().getParameters()); |
| 449 | ControlParameters actualParams(actual.getBody()); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 450 | BOOST_CHECK_EQUAL(actualParams.getFacePersistency(), expectedParams.getFacePersistency()); |
| 451 | BOOST_CHECK_EQUAL(actualParams.getFaceId(), foundFace->getId()); |
| 452 | BOOST_CHECK_EQUAL(foundFace->getPersistency(), expectedParams.getFacePersistency()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 453 | |
| 454 | hasCallbackFired = true; |
| 455 | }); |
| 456 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 457 | this->node1.face.receive(*command); |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 458 | this->advanceClocks(time::milliseconds(1), 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 459 | |
| 460 | BOOST_CHECK(hasCallbackFired); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | BOOST_AUTO_TEST_SUITE_END() // CreateFace |
| 465 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 466 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 467 | |
Weiwei Liu | f5aee94 | 2016-03-19 07:00:42 +0000 | [diff] [blame] | 468 | } // namespace tests |
| 469 | } // namespace nfd |