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