Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [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 | fbea4fc | 2022-02-08 07:26:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2022 Regents of the University of California. |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/mgmt/nfd/status-dataset.hpp" |
| 23 | #include "ndn-cxx/mgmt/nfd/controller.hpp" |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [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 | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | namespace tests { |
| 31 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 32 | using namespace ndn::tests; |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [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 | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 36 | |
| 37 | class ControllerStatusDatasetFixture : public ControllerFixture |
| 38 | { |
| 39 | protected: |
| 40 | /** \brief send one WireEncodable as Data reply |
| 41 | * \param prefix dataset prefix without version and segment |
| 42 | * \param payload payload block |
| 43 | * \note payload must fit in one Data |
| 44 | */ |
| 45 | template<typename T> |
| 46 | void |
| 47 | sendDataset(const Name& prefix, const T& payload) |
| 48 | { |
| 49 | BOOST_CONCEPT_ASSERT((WireEncodable<T>)); |
| 50 | |
| 51 | auto data = this->prepareDatasetReply(prefix); |
| 52 | data->setContent(payload.wireEncode()); |
| 53 | face.receive(*signData(data)); |
| 54 | } |
| 55 | |
| 56 | /** \brief send two WireEncodables as Data reply |
| 57 | * \param prefix dataset prefix without version and segment |
| 58 | * \param payload1 first vector item |
| 59 | * \param payload2 second vector item |
| 60 | * \note all payloads must fit in one Data |
| 61 | */ |
| 62 | template<typename T1, typename T2> |
| 63 | void |
| 64 | sendDataset(const Name& prefix, const T1& payload1, const T2& payload2) |
| 65 | { |
| 66 | // The test suite allows up to two items, and put them in the same Data packet, |
| 67 | // because this test suite focuses on Controller::fetch<StatusDataset>, |
| 68 | // and is not intended to cover SegmentFetcher behavior. |
| 69 | |
| 70 | BOOST_CONCEPT_ASSERT((WireEncodable<T1>)); |
| 71 | BOOST_CONCEPT_ASSERT((WireEncodable<T2>)); |
| 72 | |
Davide Pesavento | fbea4fc | 2022-02-08 07:26:04 -0500 | [diff] [blame] | 73 | EncodingBuffer buffer; |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 74 | payload2.wireEncode(buffer); |
| 75 | payload1.wireEncode(buffer); |
| 76 | |
| 77 | auto data = this->prepareDatasetReply(prefix); |
Davide Pesavento | fbea4fc | 2022-02-08 07:26:04 -0500 | [diff] [blame] | 78 | data->setContent(buffer); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 79 | face.receive(*signData(data)); |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | shared_ptr<Data> |
| 84 | prepareDatasetReply(const Name& prefix) |
| 85 | { |
| 86 | Name name = prefix; |
| 87 | name.appendVersion().appendSegment(0); |
| 88 | |
| 89 | // These warnings assist in debugging a `hasResult` check failure. |
| 90 | // They usually indicate a misspelled prefix or incorrect timing in the test case. |
| 91 | if (face.sentInterests.size() < 1) { |
| 92 | BOOST_WARN_MESSAGE(false, "no Interest expressed"); |
| 93 | } |
| 94 | else { |
| 95 | BOOST_WARN_MESSAGE(face.sentInterests.back().getName().isPrefixOf(name), |
| 96 | "last Interest " << face.sentInterests.back().getName() << |
| 97 | " cannot be satisfied by this Data " << name); |
| 98 | } |
| 99 | |
| 100 | auto data = make_shared<Data>(name); |
Junxiao Shi | 2ad2fbe | 2019-05-24 03:11:05 +0000 | [diff] [blame] | 101 | data->setFreshnessPeriod(1_s); |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 102 | data->setFinalBlock(name[-1]); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 103 | return data; |
| 104 | } |
| 105 | }; |
| 106 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 107 | BOOST_FIXTURE_TEST_SUITE(TestStatusDataset, ControllerStatusDatasetFixture) |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 108 | |
| 109 | BOOST_AUTO_TEST_SUITE(Failures) |
| 110 | |
| 111 | BOOST_AUTO_TEST_CASE(Timeout) |
| 112 | { |
| 113 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 114 | options.setTimeout(3000_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 115 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 116 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 117 | datasetFailCallback, |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 118 | options); |
Ashlesh Gawande | 3e3a989 | 2018-11-16 20:26:15 -0600 | [diff] [blame] | 119 | this->advanceClocks(500_ms); |
| 120 | BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 121 | |
Ashlesh Gawande | 3e3a989 | 2018-11-16 20:26:15 -0600 | [diff] [blame] | 122 | this->advanceClocks(500_ms, 6); |
| 123 | BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 124 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 125 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT); |
| 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_CASE(DataHasNoSegment) |
| 129 | { |
| 130 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 131 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 132 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 133 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 134 | |
Junxiao Shi | 2ad2fbe | 2019-05-24 03:11:05 +0000 | [diff] [blame] | 135 | auto data = makeData("/localhost/nfd/faces/list/%FD%00"); |
| 136 | data->setFreshnessPeriod(1_s); |
| 137 | face.receive(*data); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 138 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 139 | |
| 140 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 141 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER); |
| 142 | } |
| 143 | |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 144 | BOOST_AUTO_TEST_CASE(ValidationFailure) |
| 145 | { |
| 146 | this->setValidationResult(false); |
| 147 | |
| 148 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 149 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 150 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 151 | this->advanceClocks(500_ms); |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 152 | |
| 153 | FaceStatus payload; |
| 154 | payload.setFaceId(5744); |
| 155 | this->sendDataset("/localhost/nfd/faces/list", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 156 | this->advanceClocks(500_ms); |
Junxiao Shi | 0f3f0b4 | 2016-07-14 13:26:37 +0000 | [diff] [blame] | 157 | |
| 158 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 159 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION); |
| 160 | } |
| 161 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 162 | BOOST_AUTO_TEST_CASE(Nack) |
| 163 | { |
| 164 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 165 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 166 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 167 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 168 | |
| 169 | BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); |
| 170 | face.receive(lp::Nack(face.sentInterests.back())); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 171 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 172 | |
| 173 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 174 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK); |
| 175 | } |
| 176 | |
| 177 | BOOST_AUTO_TEST_CASE(ParseError1) |
| 178 | { |
| 179 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 180 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 181 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 182 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 183 | |
| 184 | Name payload; // Name is not valid FaceStatus |
| 185 | this->sendDataset("/localhost/nfd/faces/list", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 186 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 187 | |
| 188 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 189 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER); |
| 190 | } |
| 191 | |
| 192 | BOOST_AUTO_TEST_CASE(ParseError2) |
| 193 | { |
| 194 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 195 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 196 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 197 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 198 | |
| 199 | FaceStatus payload1; |
| 200 | payload1.setFaceId(10930); |
| 201 | Name payload2; // Name is not valid FaceStatus |
| 202 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 203 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 204 | |
| 205 | BOOST_REQUIRE_EQUAL(failCodes.size(), 1); |
| 206 | BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER); |
| 207 | } |
| 208 | |
| 209 | BOOST_AUTO_TEST_SUITE_END() // Failures |
| 210 | |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 211 | BOOST_AUTO_TEST_SUITE(NoCallback) |
| 212 | |
| 213 | BOOST_AUTO_TEST_CASE(Success) |
| 214 | { |
| 215 | controller.fetch<FaceDataset>( |
| 216 | nullptr, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 217 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 218 | this->advanceClocks(500_ms); |
Ashlesh Gawande | 3e3a989 | 2018-11-16 20:26:15 -0600 | [diff] [blame] | 219 | BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 220 | |
| 221 | FaceStatus payload; |
| 222 | payload.setFaceId(2577); |
| 223 | this->sendDataset("/localhost/nfd/faces/list", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 224 | BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 225 | |
| 226 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
Ashlesh Gawande | 3e3a989 | 2018-11-16 20:26:15 -0600 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | BOOST_AUTO_TEST_CASE(Failure) |
| 231 | { |
| 232 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 233 | options.setTimeout(3000_ms); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 234 | controller.fetch<FaceDataset>( |
Davide Pesavento | 221a72d | 2021-12-30 17:48:36 -0500 | [diff] [blame] | 235 | [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); }, |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 236 | nullptr, |
| 237 | options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 238 | BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms, 7)); |
Junxiao Shi | 600f711 | 2016-07-16 11:57:18 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | BOOST_AUTO_TEST_SUITE_END() // NoCallback |
| 242 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 243 | BOOST_AUTO_TEST_SUITE(Datasets) |
| 244 | |
| 245 | BOOST_AUTO_TEST_CASE(StatusGeneral) |
| 246 | { |
| 247 | bool hasResult = false; |
| 248 | controller.fetch<ForwarderGeneralStatusDataset>( |
| 249 | [&hasResult] (const ForwarderStatus& result) { |
| 250 | hasResult = true; |
| 251 | BOOST_CHECK_EQUAL(result.getNfdVersion(), "0.4.2"); |
| 252 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 253 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 254 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 255 | |
| 256 | ForwarderStatus payload; |
| 257 | payload.setNfdVersion("0.4.2"); |
| 258 | this->sendDataset("/localhost/nfd/status/general", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 259 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 260 | |
| 261 | BOOST_CHECK(hasResult); |
| 262 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 263 | } |
| 264 | |
| 265 | BOOST_AUTO_TEST_CASE(FaceList) |
| 266 | { |
| 267 | bool hasResult = false; |
| 268 | controller.fetch<FaceDataset>( |
| 269 | [&hasResult] (const std::vector<FaceStatus>& result) { |
| 270 | hasResult = true; |
| 271 | BOOST_CHECK_EQUAL(result.size(), 2); |
| 272 | BOOST_CHECK_EQUAL(result.front().getFaceId(), 24485); |
| 273 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 274 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 275 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 276 | |
| 277 | FaceStatus payload1; |
| 278 | payload1.setFaceId(24485); |
| 279 | FaceStatus payload2; |
| 280 | payload2.setFaceId(12987); |
| 281 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 282 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 283 | |
| 284 | BOOST_CHECK(hasResult); |
| 285 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 286 | } |
| 287 | |
| 288 | BOOST_AUTO_TEST_CASE(FaceQuery) |
| 289 | { |
| 290 | FaceQueryFilter filter; |
| 291 | filter.setUriScheme("udp4"); |
| 292 | bool hasResult = false; |
| 293 | controller.fetch<FaceQueryDataset>( |
| 294 | filter, |
| 295 | [&hasResult] (const std::vector<FaceStatus>& result) { |
| 296 | hasResult = true; |
| 297 | BOOST_CHECK_EQUAL(result.size(), 1); |
| 298 | BOOST_CHECK_EQUAL(result.front().getFaceId(), 8795); |
| 299 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 300 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 301 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 302 | |
| 303 | Name prefix("/localhost/nfd/faces/query"); |
Davide Pesavento | 2f92b6e | 2022-04-10 16:42:01 -0400 | [diff] [blame] | 304 | prefix.append(filter.wireEncode()); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 305 | FaceStatus payload; |
| 306 | payload.setFaceId(8795); |
| 307 | this->sendDataset(prefix, payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 308 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 309 | |
| 310 | BOOST_CHECK(hasResult); |
| 311 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 312 | } |
| 313 | |
| 314 | BOOST_AUTO_TEST_CASE(FaceQueryWithOptions) |
| 315 | { |
| 316 | FaceQueryFilter filter; |
| 317 | filter.setUriScheme("udp4"); |
| 318 | CommandOptions options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 319 | options.setTimeout(3000_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 320 | bool hasResult = false; |
| 321 | controller.fetch<FaceQueryDataset>( |
| 322 | filter, |
| 323 | [&hasResult] (const std::vector<FaceStatus>& result) { |
| 324 | hasResult = true; |
| 325 | BOOST_CHECK_EQUAL(result.size(), 1); |
| 326 | BOOST_CHECK_EQUAL(result.front().getFaceId(), 14022); |
| 327 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 328 | datasetFailCallback, |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 329 | options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 330 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 331 | |
| 332 | Name prefix("/localhost/nfd/faces/query"); |
Davide Pesavento | 2f92b6e | 2022-04-10 16:42:01 -0400 | [diff] [blame] | 333 | prefix.append(filter.wireEncode()); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 334 | FaceStatus payload; |
| 335 | payload.setFaceId(14022); |
| 336 | this->sendDataset(prefix, payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 337 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 338 | |
| 339 | BOOST_CHECK(hasResult); |
| 340 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 341 | } |
| 342 | |
Junxiao Shi | 1eacb97 | 2016-07-07 22:51:07 +0000 | [diff] [blame] | 343 | BOOST_AUTO_TEST_CASE(FaceChannels) |
| 344 | { |
| 345 | bool hasResult = false; |
| 346 | controller.fetch<ChannelDataset>( |
| 347 | [&hasResult] (const std::vector<ChannelStatus>& result) { |
| 348 | hasResult = true; |
| 349 | BOOST_CHECK_EQUAL(result.size(), 2); |
| 350 | BOOST_CHECK_EQUAL(result.front().getLocalUri(), "tcp4://192.0.2.1:6363"); |
| 351 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 352 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 353 | this->advanceClocks(500_ms); |
Junxiao Shi | 1eacb97 | 2016-07-07 22:51:07 +0000 | [diff] [blame] | 354 | |
| 355 | ChannelStatus payload1; |
| 356 | payload1.setLocalUri("tcp4://192.0.2.1:6363"); |
| 357 | ChannelStatus payload2; |
| 358 | payload2.setLocalUri("udp4://192.0.2.1:6363"); |
| 359 | this->sendDataset("/localhost/nfd/faces/channels", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 360 | this->advanceClocks(500_ms); |
Junxiao Shi | 1eacb97 | 2016-07-07 22:51:07 +0000 | [diff] [blame] | 361 | |
| 362 | BOOST_CHECK(hasResult); |
| 363 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 364 | } |
| 365 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 366 | BOOST_AUTO_TEST_CASE(FibList) |
| 367 | { |
| 368 | bool hasResult = false; |
| 369 | controller.fetch<FibDataset>( |
| 370 | [&hasResult] (const std::vector<FibEntry>& result) { |
| 371 | hasResult = true; |
| 372 | BOOST_CHECK_EQUAL(result.size(), 2); |
| 373 | BOOST_CHECK_EQUAL(result.front().getPrefix(), "/wYs7fzYcfG"); |
| 374 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 375 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 376 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 377 | |
| 378 | FibEntry payload1; |
| 379 | payload1.setPrefix("/wYs7fzYcfG"); |
| 380 | FibEntry payload2; |
| 381 | payload2.setPrefix("/LKvmnzY5S"); |
| 382 | this->sendDataset("/localhost/nfd/fib/list", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 383 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 384 | |
| 385 | BOOST_CHECK(hasResult); |
| 386 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 387 | } |
| 388 | |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 389 | BOOST_AUTO_TEST_CASE(CsInfo) |
| 390 | { |
| 391 | using ndn::nfd::CsInfo; |
| 392 | |
| 393 | bool hasResult = false; |
| 394 | controller.fetch<CsInfoDataset>( |
| 395 | [&hasResult] (const CsInfo& result) { |
| 396 | hasResult = true; |
| 397 | BOOST_CHECK_EQUAL(result.getNHits(), 4539); |
| 398 | }, |
| 399 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 400 | this->advanceClocks(500_ms); |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 401 | |
| 402 | CsInfo payload; |
| 403 | payload.setNHits(4539); |
| 404 | this->sendDataset("/localhost/nfd/cs/info", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 405 | this->advanceClocks(500_ms); |
Junxiao Shi | 7f01247 | 2017-12-07 20:40:47 +0000 | [diff] [blame] | 406 | |
| 407 | BOOST_CHECK(hasResult); |
| 408 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 409 | } |
| 410 | |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 411 | BOOST_AUTO_TEST_CASE(StrategyChoiceList) |
| 412 | { |
| 413 | bool hasResult = false; |
| 414 | controller.fetch<StrategyChoiceDataset>( |
| 415 | [&hasResult] (const std::vector<StrategyChoice>& result) { |
| 416 | hasResult = true; |
| 417 | BOOST_CHECK_EQUAL(result.size(), 2); |
| 418 | BOOST_CHECK_EQUAL(result.front().getName(), "/8MLz6N3B"); |
| 419 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 420 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 421 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 422 | |
| 423 | StrategyChoice payload1; |
| 424 | payload1.setName("/8MLz6N3B"); |
| 425 | StrategyChoice payload2; |
| 426 | payload2.setName("/svqcBu0YwU"); |
| 427 | this->sendDataset("/localhost/nfd/strategy-choice/list", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 428 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 429 | |
| 430 | BOOST_CHECK(hasResult); |
| 431 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 432 | } |
| 433 | |
| 434 | BOOST_AUTO_TEST_CASE(RibList) |
| 435 | { |
| 436 | bool hasResult = false; |
| 437 | controller.fetch<RibDataset>( |
| 438 | [&hasResult] (const std::vector<RibEntry>& result) { |
| 439 | hasResult = true; |
| 440 | BOOST_CHECK_EQUAL(result.size(), 2); |
| 441 | BOOST_CHECK_EQUAL(result.front().getName(), "/zXxBth97ee"); |
| 442 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 443 | datasetFailCallback); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 444 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 445 | |
| 446 | RibEntry payload1; |
| 447 | payload1.setName("/zXxBth97ee"); |
| 448 | RibEntry payload2; |
| 449 | payload2.setName("/rJ8CvUpr4G"); |
| 450 | this->sendDataset("/localhost/nfd/rib/list", payload1, payload2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 451 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 452 | |
| 453 | BOOST_CHECK(hasResult); |
| 454 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 455 | } |
| 456 | |
| 457 | BOOST_AUTO_TEST_CASE(RibListWithOptions) |
| 458 | { |
| 459 | CommandOptions options; |
| 460 | options.setPrefix("/localhop/nfd"); |
| 461 | bool hasResult = false; |
| 462 | controller.fetch<RibDataset>( |
| 463 | [&hasResult] (const std::vector<RibEntry>& result) { |
| 464 | hasResult = true; |
| 465 | BOOST_CHECK_EQUAL(result.size(), 1); |
| 466 | BOOST_CHECK_EQUAL(result.front().getName(), "/e6L5K4ascd"); |
| 467 | }, |
Junxiao Shi | e7c7f15 | 2016-08-20 22:36:22 +0000 | [diff] [blame] | 468 | datasetFailCallback, |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 469 | options); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 470 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 471 | |
| 472 | RibEntry payload; |
| 473 | payload.setName("/e6L5K4ascd"); |
| 474 | this->sendDataset("/localhop/nfd/rib/list", payload); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 475 | this->advanceClocks(500_ms); |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 476 | |
| 477 | BOOST_CHECK(hasResult); |
| 478 | BOOST_CHECK_EQUAL(failCodes.size(), 0); |
| 479 | } |
| 480 | |
| 481 | BOOST_AUTO_TEST_SUITE_END() // Datasets |
| 482 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 483 | BOOST_AUTO_TEST_SUITE_END() // TestStatusDataset |
| 484 | BOOST_AUTO_TEST_SUITE_END() // Nfd |
| 485 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 034c188 | 2016-06-24 18:06:51 +0000 | [diff] [blame] | 486 | |
| 487 | } // namespace tests |
| 488 | } // namespace nfd |
| 489 | } // namespace ndn |