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 | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 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 | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "tests/boost-test.hpp" |
| 26 | #include "tests/make-interest-data.hpp" |
| 27 | #include "tests/unit/mgmt/nfd/controller-fixture.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | namespace nfd { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 31 | namespace tests { |
| 32 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 33 | using namespace ndn::tests; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 36 | BOOST_AUTO_TEST_SUITE(Nfd) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 38 | class CommandFixture : public ControllerFixture |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 39 | { |
| 40 | protected: |
| 41 | CommandFixture() |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 42 | : succeedCallback(bind(&CommandFixture::succeed, this, _1)) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 46 | void |
| 47 | respond(const ControlResponse& responsePayload) |
| 48 | { |
| 49 | auto responseData = makeData(face.sentInterests.at(0).getName()); |
| 50 | responseData->setContent(responsePayload.wireEncode()); |
| 51 | face.receive(*responseData); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 52 | this->advanceClocks(1_ms); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 55 | private: |
| 56 | void |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 57 | succeed(const ControlParameters& parameters) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 58 | { |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 59 | succeeds.push_back(parameters); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | protected: |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 63 | Controller::CommandSucceedCallback succeedCallback; |
| 64 | std::vector<ControlParameters> succeeds; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 67 | // This test suite focuses on ControlCommand functionality of Controller. |
| 68 | // Individual commands are tested in nfd-control-command.t.cpp |
| 69 | // StatusDataset functionality is tested in nfd-status-dataset.t.cpp |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 70 | BOOST_FIXTURE_TEST_SUITE(TestController, CommandFixture) |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 71 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 72 | static ControlParameters |
| 73 | makeFaceCreateResponse() |
| 74 | { |
| 75 | ControlParameters resp; |
| 76 | resp.setFaceId(22) |
| 77 | .setUri("tcp4://192.0.2.1:6363") |
| 78 | .setLocalUri("tcp4://192.0.2.2:10847") |
| 79 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
Eric Newberry | d567aab | 2018-01-27 16:38:24 -0700 | [diff] [blame] | 80 | .setFlags(0x7); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 81 | return resp; |
| 82 | } |
| 83 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(Success) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 85 | { |
| 86 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 87 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 88 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 89 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 90 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 92 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 93 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 94 | |
| 95 | FaceCreateCommand command; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 96 | BOOST_CHECK(Name("/localhost/nfd/faces/create").isPrefixOf(requestInterest.getName())); |
| 97 | // 9 components: ndn:/localhost/nfd/faces/create/<parameters>/<signed Interest x4> |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 98 | BOOST_REQUIRE_EQUAL(requestInterest.getName().size(), 9); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 99 | ControlParameters request; |
| 100 | // 4th component: <parameters> |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 101 | BOOST_REQUIRE_NO_THROW(request.wireDecode(requestInterest.getName().at(4).blockFromValue())); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 102 | BOOST_CHECK_NO_THROW(command.validateRequest(request)); |
| 103 | BOOST_CHECK_EQUAL(request.getUri(), parameters.getUri()); |
Junxiao Shi | 415b17c | 2014-11-12 00:43:25 -0700 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(requestInterest.getInterestLifetime(), CommandOptions::DEFAULT_TIMEOUT); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 105 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 106 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 107 | ControlResponse responsePayload(201, "created"); |
| 108 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 109 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 112 | BOOST_REQUIRE_EQUAL(succeeds.size(), 1); |
| 113 | BOOST_CHECK_EQUAL(succeeds.back().getUri(), responseBody.getUri()); |
| 114 | BOOST_CHECK_EQUAL(succeeds.back().getFaceId(), responseBody.getFaceId()); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 117 | BOOST_AUTO_TEST_CASE(SuccessNoCallback) |
| 118 | { |
| 119 | ControlParameters parameters; |
| 120 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 121 | |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 122 | controller.start<FaceCreateCommand>(parameters, nullptr, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 123 | this->advanceClocks(1_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 124 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 125 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 126 | ControlResponse responsePayload(201, "created"); |
| 127 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 128 | this->respond(responsePayload); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 129 | |
| 130 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 131 | } |
| 132 | |
| 133 | BOOST_AUTO_TEST_CASE(OptionsPrefix) |
| 134 | { |
| 135 | ControlParameters parameters; |
| 136 | parameters.setName("/ndn/com/example"); |
| 137 | parameters.setFaceId(400); |
| 138 | |
| 139 | CommandOptions options; |
| 140 | options.setPrefix("/localhop/net/example/router1/nfd"); |
| 141 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 142 | controller.start<RibRegisterCommand>(parameters, succeedCallback, commandFailCallback, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 143 | this->advanceClocks(1_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 144 | |
| 145 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 146 | const Interest& requestInterest = face.sentInterests[0]; |
| 147 | |
| 148 | FaceCreateCommand command; |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 149 | BOOST_CHECK(Name("/localhop/net/example/router1/nfd/rib/register").isPrefixOf(requestInterest.getName())); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | BOOST_AUTO_TEST_CASE(InvalidRequest) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 153 | { |
| 154 | ControlParameters parameters; |
| 155 | parameters.setName("ndn:/should-not-have-this-field"); |
| 156 | // Uri is missing |
| 157 | |
| 158 | BOOST_CHECK_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 159 | parameters, succeedCallback, commandFailCallback), |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 160 | ControlCommand::ArgumentError); |
| 161 | } |
| 162 | |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 163 | BOOST_AUTO_TEST_CASE(ValidationFailure) |
| 164 | { |
| 165 | this->setValidationResult(false); |
| 166 | |
| 167 | ControlParameters parameters; |
| 168 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 169 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 170 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 171 | this->advanceClocks(1_ms); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 172 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 173 | ControlParameters responseBody = makeFaceCreateResponse(); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 174 | ControlResponse responsePayload(201, "created"); |
| 175 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 176 | this->respond(responsePayload); |
Junxiao Shi | 54f727d | 2016-08-08 20:29:11 +0000 | [diff] [blame] | 177 | |
| 178 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 179 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 180 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION); |
| 181 | } |
| 182 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 183 | BOOST_AUTO_TEST_CASE(ErrorCode) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 184 | { |
| 185 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 186 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 187 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 188 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 189 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 190 | |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 191 | ControlResponse responsePayload(401, "Not Authenticated"); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 192 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 193 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 195 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 196 | BOOST_CHECK_EQUAL(failCodes.back(), 401); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 199 | BOOST_AUTO_TEST_CASE(InvalidResponse) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 200 | { |
| 201 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 202 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 203 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 204 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 205 | this->advanceClocks(1_ms); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 206 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 207 | ControlParameters responseBody = makeFaceCreateResponse(); |
| 208 | responseBody.unsetFaceId() // FaceId is missing |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 209 | .setName("ndn:/should-not-have-this-field"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 210 | ControlResponse responsePayload(201, "created"); |
| 211 | responsePayload.setBody(responseBody.wireEncode()); |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 212 | this->respond(responsePayload); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 213 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 214 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 215 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 218 | BOOST_AUTO_TEST_CASE(Nack) |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 219 | { |
| 220 | ControlParameters parameters; |
| 221 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 222 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 223 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 224 | this->advanceClocks(1_ms); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 225 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 226 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 227 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 228 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 229 | auto responseNack = makeNack(requestInterest, lp::NackReason::NO_ROUTE); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 230 | face.receive(responseNack); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 231 | this->advanceClocks(1_ms); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 232 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 233 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 234 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 237 | BOOST_AUTO_TEST_CASE(Timeout) |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 238 | { |
| 239 | ControlParameters parameters; |
| 240 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 241 | |
| 242 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 243 | options.setTimeout(50_ms); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 244 | |
Junxiao Shi | 8c2ab2e | 2017-05-05 20:26:34 +0000 | [diff] [blame] | 245 | controller.start<FaceCreateCommand>(parameters, succeedCallback, commandFailCallback, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 246 | this->advanceClocks(1_ms); // express Interest |
| 247 | this->advanceClocks(51_ms); // timeout |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 248 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 249 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 250 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 253 | BOOST_AUTO_TEST_CASE(FailureNoCallback) |
| 254 | { |
| 255 | ControlParameters parameters; |
| 256 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 257 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 258 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 259 | options.setTimeout(50_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 260 | |
| 261 | controller.start<FaceCreateCommand>(parameters, succeedCallback, nullptr, options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 262 | this->advanceClocks(1_ms); // express Interest |
| 263 | this->advanceClocks(51_ms); // timeout |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 264 | |
| 265 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 266 | } |
| 267 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 268 | BOOST_AUTO_TEST_SUITE_END() // TestController |
| 269 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 270 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 271 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 272 | } // namespace tests |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 273 | } // namespace nfd |
| 274 | } // namespace ndn |