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 | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 2 | /** |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | |
| 22 | #include "management/nfd-controller.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 23 | #include "management/nfd-control-response.hpp" |
| 24 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 25 | #include <boost/tuple/tuple.hpp> |
| 26 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 27 | #include "nfd-controller-fixture.hpp" |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 28 | #include "../make-interest-data.hpp" |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace nfd { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 32 | namespace tests { |
| 33 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 34 | using namespace ndn::tests; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Management) |
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 | |
| 46 | private: |
| 47 | void |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 48 | succeed(const ControlParameters& parameters) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 49 | { |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 50 | succeeds.push_back(parameters); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | protected: |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 54 | Controller::CommandSucceedCallback succeedCallback; |
| 55 | std::vector<ControlParameters> succeeds; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 58 | // This test suite focuses on ControlCommand functionality of Controller. |
| 59 | // Individual commands are tested in nfd-control-command.t.cpp |
| 60 | // StatusDataset functionality is tested in nfd-status-dataset.t.cpp |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 61 | BOOST_FIXTURE_TEST_SUITE(TestNfdController, CommandFixture) |
| 62 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 63 | BOOST_AUTO_TEST_CASE(Success) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 64 | { |
| 65 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 66 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 67 | |
| 68 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 69 | parameters, succeedCallback, failCallback)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 70 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 72 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 73 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 74 | |
| 75 | FaceCreateCommand command; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 76 | BOOST_CHECK(Name("/localhost/nfd/faces/create").isPrefixOf(requestInterest.getName())); |
| 77 | // 9 components: ndn:/localhost/nfd/faces/create/<parameters>/<signed Interest x4> |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 78 | BOOST_REQUIRE_EQUAL(requestInterest.getName().size(), 9); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 79 | ControlParameters request; |
| 80 | // 4th component: <parameters> |
Junxiao Shi | 6a90f37 | 2014-10-13 20:29:30 -0700 | [diff] [blame] | 81 | BOOST_REQUIRE_NO_THROW(request.wireDecode(requestInterest.getName().at(4).blockFromValue())); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 82 | BOOST_CHECK_NO_THROW(command.validateRequest(request)); |
| 83 | BOOST_CHECK_EQUAL(request.getUri(), parameters.getUri()); |
Junxiao Shi | 415b17c | 2014-11-12 00:43:25 -0700 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(requestInterest.getInterestLifetime(), CommandOptions::DEFAULT_TIMEOUT); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 85 | |
| 86 | ControlParameters responseBody; |
| 87 | responseBody.setUri("tcp4://192.0.2.1:6363") |
Yukai Tu | d93c5fc | 2015-08-25 11:37:16 +0800 | [diff] [blame] | 88 | .setFaceId(22) |
| 89 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 90 | ControlResponse responsePayload(201, "created"); |
| 91 | responsePayload.setBody(responseBody.wireEncode()); |
| 92 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 93 | auto responseData = makeData(requestInterest.getName()); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 94 | responseData->setContent(responsePayload.wireEncode()); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 95 | face.receive(*responseData); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 96 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 97 | this->advanceClocks(time::milliseconds(1)); |
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 | |
| 110 | controller.start<FaceCreateCommand>(parameters, nullptr, failCallback); |
| 111 | this->advanceClocks(time::milliseconds(1)); |
| 112 | |
| 113 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 114 | const Interest& requestInterest = face.sentInterests[0]; |
| 115 | |
| 116 | ControlParameters responseBody; |
| 117 | responseBody.setUri("tcp4://192.0.2.1:6363") |
| 118 | .setFaceId(22) |
| 119 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 120 | ControlResponse responsePayload(201, "created"); |
| 121 | responsePayload.setBody(responseBody.wireEncode()); |
| 122 | |
| 123 | auto responseData = makeData(requestInterest.getName()); |
| 124 | responseData->setContent(responsePayload.wireEncode()); |
| 125 | face.receive(*responseData); |
| 126 | |
| 127 | BOOST_CHECK_NO_THROW(this->advanceClocks(time::milliseconds(1))); |
| 128 | |
| 129 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 130 | } |
| 131 | |
| 132 | BOOST_AUTO_TEST_CASE(OptionsPrefix) |
| 133 | { |
| 134 | ControlParameters parameters; |
| 135 | parameters.setName("/ndn/com/example"); |
| 136 | parameters.setFaceId(400); |
| 137 | |
| 138 | CommandOptions options; |
| 139 | options.setPrefix("/localhop/net/example/router1/nfd"); |
| 140 | |
| 141 | BOOST_CHECK_NO_THROW(controller.start<RibRegisterCommand>( |
| 142 | parameters, succeedCallback, failCallback, options)); |
| 143 | this->advanceClocks(time::milliseconds(1)); |
| 144 | |
| 145 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 146 | const Interest& requestInterest = face.sentInterests[0]; |
| 147 | |
| 148 | FaceCreateCommand command; |
| 149 | BOOST_CHECK(Name("/localhop/net/example/router1/nfd/rib/register").isPrefixOf( |
| 150 | requestInterest.getName())); |
| 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 | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 160 | parameters, succeedCallback, failCallback), |
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 | |
| 171 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
| 172 | parameters, succeedCallback, failCallback)); |
| 173 | this->advanceClocks(time::milliseconds(1)); |
| 174 | |
| 175 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 176 | const Interest& requestInterest = face.sentInterests[0]; |
| 177 | |
| 178 | ControlParameters responseBody; |
| 179 | responseBody.setUri("tcp4://192.0.2.1:6363") |
| 180 | .setFaceId(22) |
| 181 | .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 182 | ControlResponse responsePayload(201, "created"); |
| 183 | responsePayload.setBody(responseBody.wireEncode()); |
| 184 | |
| 185 | auto responseData = makeData(requestInterest.getName()); |
| 186 | responseData->setContent(responsePayload.wireEncode()); |
| 187 | face.receive(*responseData); |
| 188 | this->advanceClocks(time::milliseconds(1)); |
| 189 | |
| 190 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 191 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 192 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION); |
| 193 | } |
| 194 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 195 | BOOST_AUTO_TEST_CASE(ErrorCode) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 196 | { |
| 197 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 198 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 199 | |
| 200 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 201 | parameters, succeedCallback, failCallback)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 202 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 203 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 204 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 205 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 206 | |
| 207 | ControlResponse responsePayload(401, "Not Authenticated"); |
| 208 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 209 | auto responseData = makeData(requestInterest.getName()); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 210 | responseData->setContent(responsePayload.wireEncode()); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 211 | face.receive(*responseData); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 212 | this->advanceClocks(time::milliseconds(1)); |
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); |
| 216 | BOOST_CHECK_EQUAL(failCodes.back(), 401); |
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(InvalidResponse) |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 220 | { |
| 221 | ControlParameters parameters; |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 222 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 223 | |
| 224 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 225 | parameters, succeedCallback, failCallback)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 226 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 227 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 228 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 229 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 230 | |
| 231 | ControlParameters responseBody; |
| 232 | responseBody.setUri("tcp4://192.0.2.1:6363") |
| 233 | .setName("ndn:/should-not-have-this-field"); |
| 234 | // FaceId is missing |
| 235 | ControlResponse responsePayload(201, "created"); |
| 236 | responsePayload.setBody(responseBody.wireEncode()); |
| 237 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 238 | auto responseData = makeData(requestInterest.getName()); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 239 | responseData->setContent(responsePayload.wireEncode()); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 240 | face.receive(*responseData); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 241 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 242 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 244 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 247 | BOOST_AUTO_TEST_CASE(Nack) |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 248 | { |
| 249 | ControlParameters parameters; |
| 250 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 251 | |
| 252 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 253 | parameters, succeedCallback, failCallback)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 254 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 255 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 256 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 257 | const Interest& requestInterest = face.sentInterests[0]; |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 258 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 259 | auto responseNack = makeNack(requestInterest, lp::NackReason::NO_ROUTE); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 260 | face.receive(responseNack); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 261 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 262 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 263 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 264 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK); |
Junxiao Shi | b1990df | 2015-11-05 00:14:44 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 267 | BOOST_AUTO_TEST_CASE(Timeout) |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 268 | { |
| 269 | ControlParameters parameters; |
| 270 | parameters.setUri("tcp4://192.0.2.1:6363"); |
| 271 | |
| 272 | CommandOptions options; |
| 273 | options.setTimeout(time::milliseconds(50)); |
| 274 | |
| 275 | BOOST_CHECK_NO_THROW(controller.start<FaceCreateCommand>( |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 276 | parameters, succeedCallback, failCallback, options)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 277 | this->advanceClocks(time::milliseconds(1), 101); // Face's PIT granularity is 100ms |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 278 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 279 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 280 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT); |
Junxiao Shi | 5de006b | 2014-10-26 20:20:52 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 283 | BOOST_AUTO_TEST_CASE(FailureNoCallback) |
| 284 | { |
| 285 | ControlParameters parameters; |
| 286 | parameters.setUri("tcp4://192.0.2.1:6363"); |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 287 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 288 | CommandOptions options; |
| 289 | options.setTimeout(time::milliseconds(50)); |
| 290 | |
| 291 | controller.start<FaceCreateCommand>(parameters, succeedCallback, nullptr, options); |
| 292 | BOOST_CHECK_NO_THROW(this->advanceClocks(time::milliseconds(100), 10)); |
| 293 | // timeout |
| 294 | |
| 295 | BOOST_CHECK_EQUAL(succeeds.size(), 0); |
| 296 | } |
| 297 | |
| 298 | BOOST_AUTO_TEST_SUITE_END() // TestNfdController |
| 299 | BOOST_AUTO_TEST_SUITE_END() // Management |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 300 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 301 | } // namespace tests |
Junxiao Shi | 7b6b79d | 2014-03-26 20:59:35 -0700 | [diff] [blame] | 302 | } // namespace nfd |
| 303 | } // namespace ndn |