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