Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 187e9f9 | 2023-03-20 22:46:22 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/mgmt/nfd/controller.hpp" |
| 23 | #include "ndn-cxx/mgmt/nfd/control-response.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 25 | #include "tests/test-common.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 26 | #include "tests/unit/mgmt/nfd/controller-fixture.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 28 | namespace ndn::tests { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 30 | using namespace ndn::nfd; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 32 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 33 | BOOST_AUTO_TEST_SUITE(Nfd) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 35 | class CommandFixture : public ControllerFixture |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 36 | { |
| 37 | protected: |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 38 | void |
| 39 | respond(const ControlResponse& responsePayload) |
| 40 | { |
| 41 | auto responseData = makeData(face.sentInterests.at(0).getName()); |
| 42 | responseData->setContent(responsePayload.wireEncode()); |
| 43 | face.receive(*responseData); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 44 | this->advanceClocks(1_ms); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 47 | protected: |
Davide Pesavento | 0910343 | 2023-03-24 20:30:41 -0400 | [diff] [blame] | 48 | CommandSuccessCallback succeedCallback = [this] (const auto& params) { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame] | 49 | succeeds.push_back(params); |
| 50 | }; |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 51 | std::vector<ControlParameters> succeeds; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 54 | // This test suite focuses on ControlCommand functionality of Controller. |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 55 | // Individual commands are tested in control-command.t.cpp |
| 56 | // StatusDataset functionality is tested in status-dataset.t.cpp |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 57 | BOOST_FIXTURE_TEST_SUITE(TestController, CommandFixture) |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 58 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 59 | static ControlParameters |
| 60 | makeFaceCreateResponse() |
| 61 | { |
| 62 | ControlParameters resp; |
| 63 | resp.setFaceId(22) |
| 64 | .setUri("tcp4://192.0.2.1:6363") |
| 65 | .setLocalUri("tcp4://192.0.2.2:10847") |
| 66 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | d567aab | 2018-01-27 16:38:24 -0700 | [diff] [blame] | 67 | .setFlags(0x7); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 68 | return resp; |
| 69 | } |
| 70 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 71 | BOOST_AUTO_TEST_CASE(Success) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 72 | { |
| 73 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 74 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 76 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 77 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 79 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 80 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 82 | BOOST_CHECK(Name("/localhost/nfd/faces/create").isPrefixOf(requestInterest.getName())); |
Davide Pesavento | 8fbffe4 | 2022-06-15 18:36:03 -0400 | [diff] [blame] | 83 | BOOST_CHECK(requestInterest.isSigned()); |
| 84 | BOOST_CHECK(requestInterest.isParametersDigestValid()); |
Junxiao Shi | 415b17c | 2014-11-12 00:43:25 -0700 | [diff] [blame] | 85 | BOOST_CHECK_EQUAL(requestInterest.getInterestLifetime(), CommandOptions::DEFAULT_TIMEOUT); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 86 | |
Davide Pesavento | 8fbffe4 | 2022-06-15 18:36:03 -0400 | [diff] [blame] | 87 | // 6 components: /localhost/nfd/faces/create/<parameters>/params-sha256=... |
| 88 | BOOST_REQUIRE_EQUAL(requestInterest.getName().size(), 6); |
| 89 | ControlParameters requestParams(requestInterest.getName()[4].blockFromValue()); |
| 90 | FaceCreateCommand command; |
| 91 | BOOST_CHECK_NO_THROW(command.validateRequest(requestParams)); |
| 92 | BOOST_CHECK_EQUAL(requestParams.getUri(), parameters.getUri()); |
| 93 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 94 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 95 | ControlResponse responsePayload(201, "created"); |
| 96 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 97 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 98 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 100 | BOOST_REQUIRE_EQUAL(succeeds.size(), 1); |
| 101 | BOOST_CHECK_EQUAL(succeeds.back().getUri(), responseBody.getUri()); |
| 102 | BOOST_CHECK_EQUAL(succeeds.back().getFaceId(), responseBody.getFaceId()); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 105 | BOOST_AUTO_TEST_CASE(SuccessNoCallback) |
| 106 | { |
| 107 | ControlParameters parameters; |
| 108 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 109 | |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 110 | controller.start<FaceCreateCommand>(parameters, nullptr, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 111 | this->advanceClocks(1_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 112 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 113 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 114 | ControlResponse responsePayload(201, "created"); |
| 115 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 116 | this->respond(responsePayload); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 117 | |
| 118 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 119 | } |
| 120 | |
| 121 | BOOST_AUTO_TEST_CASE(OptionsPrefix) |
| 122 | { |
| 123 | ControlParameters parameters; |
| 124 | parameters.setName("/ndn/com/example"); |
| 125 | parameters.setFaceId(400); |
| 126 | |
| 127 | CommandOptions options; |
| 128 | options.setPrefix("/localhop/net/example/router1/nfd"); |
| 129 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 130 | controller.start<RibRegisterCommand>(parameters, succeedCallback, commandFailCallback, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 131 | this->advanceClocks(1_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 132 | |
| 133 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 134 | const Interest& requestInterest = face.sentInterests[0]; |
| 135 | |
| 136 | FaceCreateCommand command; |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 137 | BOOST_CHECK(Name("/localhop/net/example/router1/nfd/rib/register").isPrefixOf(requestInterest.getName())); |
Davide Pesavento | 8fbffe4 | 2022-06-15 18:36:03 -0400 | [diff] [blame] | 138 | BOOST_CHECK(requestInterest.isSigned()); |
| 139 | BOOST_CHECK(requestInterest.isParametersDigestValid()); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_CASE(InvalidRequest) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 143 | { |
| 144 | ControlParameters parameters; |
| 145 | parameters.setName("ndn:/should-not-have-this-field"); |
| 146 | // Uri is missing |
| 147 | |
Davide Pesavento | 8fbffe4 | 2022-06-15 18:36:03 -0400 | [diff] [blame] | 148 | BOOST_CHECK_THROW(controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback), |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 149 | ControlCommand::ArgumentError); |
| 150 | } |
| 151 | |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 152 | BOOST_AUTO_TEST_CASE(ValidationFailure) |
| 153 | { |
| 154 | this->setValidationResult(false); |
| 155 | |
| 156 | ControlParameters parameters; |
| 157 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 158 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 159 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 160 | this->advanceClocks(1_ms); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 161 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 162 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 163 | ControlResponse responsePayload(201, "created"); |
| 164 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 165 | this->respond(responsePayload); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 166 | |
| 167 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 168 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 169 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION); |
| 170 | } |
| 171 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 172 | BOOST_AUTO_TEST_CASE(ErrorCode) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 173 | { |
| 174 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 175 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 176 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 177 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 178 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 179 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 180 | ControlResponse responsePayload(401, "Not Authenticated"); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 181 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 182 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 183 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 184 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 185 | BOOST_CHECK_EQUAL(failCodes.back(), 401); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 188 | BOOST_AUTO_TEST_CASE(InvalidResponse) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 189 | { |
| 190 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 191 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 192 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 193 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 194 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 195 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 196 | ControlParameters responseBody = makeFaceCreateResponse(); |
| 197 | responseBody.unsetFaceId() // FaceId is missing |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 198 | .setName("ndn:/should-not-have-this-field"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 199 | ControlResponse responsePayload(201, "created"); |
| 200 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 201 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 202 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 204 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 207 | BOOST_AUTO_TEST_CASE(Nack) |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 208 | { |
| 209 | ControlParameters parameters; |
| 210 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 211 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 212 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 213 | this->advanceClocks(1_ms); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 214 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 215 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 216 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 217 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 218 | auto responseNack = makeNack(requestInterest, lp::NackReason::NO_ROUTE); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 219 | face.receive(responseNack); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 220 | this->advanceClocks(1_ms); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 221 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 222 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 223 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 226 | BOOST_AUTO_TEST_CASE(Timeout) |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 227 | { |
| 228 | ControlParameters parameters; |
| 229 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 230 | |
| 231 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 232 | options.setTimeout(50_ms); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 233 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 234 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 235 | this->advanceClocks(1_ms); // express Interest |
| 236 | this->advanceClocks(51_ms); // timeout |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 237 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 238 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 239 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 242 | BOOST_AUTO_TEST_CASE(FailureNoCallback) |
| 243 | { |
| 244 | ControlParameters parameters; |
| 245 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 246 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 247 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 248 | options.setTimeout(50_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 249 | |
| 250 | controller.start<FaceCreateCommand>(parameters, succeedCallback, nullptr, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 251 | this->advanceClocks(1_ms); // express Interest |
| 252 | this->advanceClocks(51_ms); // timeout |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 253 | |
| 254 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 255 | } |
| 256 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 257 | BOOST_AUTO_TEST_SUITE_END() // TestController |
| 258 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 259 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 260 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 261 | } // namespace ndn::tests |