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