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