Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 26 | #include "nfdc/face-module.hpp" |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 27 | #include <ndn-cxx/mgmt/nfd/face-query-filter.hpp> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 28 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 29 | #include "execute-command-fixture.hpp" |
| 30 | #include "status-fixture.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 34 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 37 | using ndn::nfd::FaceQueryFilter; |
| 38 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Nfdc) |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 40 | BOOST_AUTO_TEST_SUITE(TestFaceModule) |
| 41 | |
Junxiao Shi | 36e5429 | 2017-02-17 18:43:16 +0000 | [diff] [blame^] | 42 | BOOST_FIXTURE_TEST_SUITE(ListCommand, ExecuteCommandFixture) |
| 43 | |
| 44 | const std::string NONQUERY_OUTPUT = |
| 45 | "faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363" |
| 46 | " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}" |
| 47 | " flags={non-local permanent multi-access}\n" |
| 48 | "faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock" |
| 49 | " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}" |
| 50 | " flags={local on-demand point-to-point local-fields}\n"; |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(NormalNonQuery) |
| 53 | { |
| 54 | this->processInterest = [this] (const Interest& interest) { |
| 55 | FaceStatus payload1; |
| 56 | payload1.setFaceId(134) |
| 57 | .setRemoteUri("udp4://233.252.0.4:6363") |
| 58 | .setLocalUri("udp4://192.0.2.1:6363") |
| 59 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 60 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT) |
| 61 | .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS) |
| 62 | .setNInInterests(22562) |
| 63 | .setNInDatas(22031) |
| 64 | .setNInNacks(63) |
| 65 | .setNOutInterests(30121) |
| 66 | .setNOutDatas(20940) |
| 67 | .setNOutNacks(1218) |
| 68 | .setNInBytes(2522915) |
| 69 | .setNOutBytes(1353592); |
| 70 | FaceStatus payload2; |
| 71 | payload2.setFaceId(745) |
| 72 | .setRemoteUri("fd://75") |
| 73 | .setLocalUri("unix:///var/run/nfd.sock") |
| 74 | .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL) |
| 75 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) |
| 76 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT) |
| 77 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true) |
| 78 | .setNInInterests(18998) |
| 79 | .setNInDatas(26701) |
| 80 | .setNInNacks(147) |
| 81 | .setNOutInterests(34779) |
| 82 | .setNOutDatas(17028) |
| 83 | .setNOutNacks(1176) |
| 84 | .setNInBytes(4672308) |
| 85 | .setNOutBytes(8957187); |
| 86 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 87 | }; |
| 88 | |
| 89 | this->execute("face list"); |
| 90 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 91 | BOOST_CHECK(out.is_equal(NONQUERY_OUTPUT)); |
| 92 | BOOST_CHECK(err.is_empty()); |
| 93 | } |
| 94 | |
| 95 | const std::string QUERY_OUTPUT = |
| 96 | "faceid=177 remote=tcp4://53.239.9.114:6363 local=tcp4://164.0.31.106:20396" |
| 97 | " counters={in={2325i 1110d 79n 4716834B} out={2278i 485d 841n 308108B}}" |
| 98 | " flags={non-local persistent point-to-point}\n"; |
| 99 | |
| 100 | BOOST_AUTO_TEST_CASE(NormalQuery) |
| 101 | { |
| 102 | this->processInterest = [this] (const Interest& interest) { |
| 103 | BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())); |
| 104 | BOOST_CHECK_EQUAL(interest.getName().size(), 5); |
| 105 | FaceQueryFilter filter(interest.getName().at(4).blockFromValue()); |
| 106 | FaceQueryFilter expectedFilter; |
| 107 | expectedFilter.setRemoteUri("tcp4://53.239.9.114:6363") |
| 108 | .setLocalUri("tcp4://164.0.31.106:20396") |
| 109 | .setUriScheme("tcp4"); |
| 110 | BOOST_CHECK_EQUAL(filter, expectedFilter); |
| 111 | |
| 112 | FaceStatus payload; |
| 113 | payload.setFaceId(177) |
| 114 | .setRemoteUri("tcp4://53.239.9.114:6363") |
| 115 | .setLocalUri("tcp4://164.0.31.106:20396") |
| 116 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 117 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 118 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT) |
| 119 | .setNInInterests(2325) |
| 120 | .setNInDatas(1110) |
| 121 | .setNInNacks(79) |
| 122 | .setNOutInterests(2278) |
| 123 | .setNOutDatas(485) |
| 124 | .setNOutNacks(841) |
| 125 | .setNInBytes(4716834) |
| 126 | .setNOutBytes(308108); |
| 127 | this->sendDataset(interest.getName(), payload); |
| 128 | }; |
| 129 | |
| 130 | this->execute("face list tcp://53.239.9.114 scheme tcp4 local tcp://164.0.31.106:20396"); |
| 131 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 132 | BOOST_CHECK(out.is_equal(QUERY_OUTPUT)); |
| 133 | BOOST_CHECK(err.is_empty()); |
| 134 | } |
| 135 | |
| 136 | BOOST_AUTO_TEST_CASE(NotFound) |
| 137 | { |
| 138 | this->processInterest = [this] (const Interest& interest) { |
| 139 | this->sendEmptyDataset(interest.getName()); |
| 140 | }; |
| 141 | |
| 142 | this->execute("face list scheme udp6"); |
| 143 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 144 | BOOST_CHECK(out.is_empty()); |
| 145 | BOOST_CHECK(err.is_equal("Face not found\n")); |
| 146 | } |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(Error) |
| 149 | { |
| 150 | this->processInterest = nullptr; // no response |
| 151 | |
| 152 | this->execute("face list local udp4://31.67.17.2:6363"); |
| 153 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 154 | BOOST_CHECK(out.is_empty()); |
| 155 | BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n")); |
| 156 | } |
| 157 | |
| 158 | BOOST_AUTO_TEST_SUITE_END() // ListCommand |
| 159 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 160 | BOOST_FIXTURE_TEST_SUITE(ShowCommand, ExecuteCommandFixture) |
| 161 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 162 | const std::string NORMAL_OUTPUT = std::string(R"TEXT( |
| 163 | faceid=256 |
| 164 | remote=udp4://84.67.35.111:6363 |
| 165 | local=udp4://79.91.49.215:6363 |
| 166 | counters={in={28975i 28232d 212n 13307258B} out={19525i 30993d 1038n 6231946B}} |
| 167 | flags={non-local on-demand point-to-point} |
| 168 | )TEXT").substr(1); |
| 169 | |
| 170 | BOOST_AUTO_TEST_CASE(Normal) |
| 171 | { |
| 172 | this->processInterest = [this] (const Interest& interest) { |
Junxiao Shi | 36e5429 | 2017-02-17 18:43:16 +0000 | [diff] [blame^] | 173 | BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())); |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(interest.getName().size(), 5); |
| 175 | FaceQueryFilter filter(interest.getName().at(4).blockFromValue()); |
| 176 | BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(256)); |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 177 | |
| 178 | FaceStatus payload; |
| 179 | payload.setFaceId(256) |
| 180 | .setRemoteUri("udp4://84.67.35.111:6363") |
| 181 | .setLocalUri("udp4://79.91.49.215:6363") |
| 182 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 183 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) |
| 184 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT) |
| 185 | .setNInInterests(28975) |
| 186 | .setNInDatas(28232) |
| 187 | .setNInNacks(212) |
| 188 | .setNOutInterests(19525) |
| 189 | .setNOutDatas(30993) |
| 190 | .setNOutNacks(1038) |
| 191 | .setNInBytes(13307258) |
| 192 | .setNOutBytes(6231946); |
| 193 | |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 194 | this->sendDataset(interest.getName(), payload); |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | this->execute("face show 256"); |
| 198 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 199 | BOOST_CHECK(out.is_equal(NORMAL_OUTPUT)); |
| 200 | BOOST_CHECK(err.is_empty()); |
| 201 | } |
| 202 | |
| 203 | BOOST_AUTO_TEST_CASE(NotFound) |
| 204 | { |
| 205 | this->processInterest = [this] (const Interest& interest) { |
| 206 | this->sendEmptyDataset(interest.getName()); |
| 207 | }; |
| 208 | |
| 209 | this->execute("face show 256"); |
| 210 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 211 | BOOST_CHECK(out.is_empty()); |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 212 | BOOST_CHECK(err.is_equal("Face not found\n")); |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | BOOST_AUTO_TEST_CASE(Error) |
| 216 | { |
| 217 | this->processInterest = nullptr; // no response |
| 218 | |
| 219 | this->execute("face show 256"); |
| 220 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 221 | BOOST_CHECK(out.is_empty()); |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 222 | BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n")); |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | BOOST_AUTO_TEST_SUITE_END() // ShowCommand |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 226 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 227 | class ExecuteFaceCreateCommandFixture : public ExecuteCommandFixture |
| 228 | { |
| 229 | protected: |
| 230 | void |
| 231 | respond409(FacePersistency persistency) |
| 232 | { |
| 233 | MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/create"); |
| 234 | ControlParameters body; |
| 235 | body.setFaceId(1172) |
| 236 | .setUri("udp4://100.77.30.65:6363") |
| 237 | .setFacePersistency(persistency) |
| 238 | .setFlags(0); |
| 239 | this->failCommand(409, "conflict-409", body); |
| 240 | } |
| 241 | }; |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 242 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 243 | BOOST_FIXTURE_TEST_SUITE(CreateCommand, ExecuteFaceCreateCommandFixture) |
| 244 | |
| 245 | BOOST_AUTO_TEST_CASE(Creating) |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 246 | { |
| 247 | this->processInterest = [this] (const Interest& interest) { |
| 248 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/create"); |
| 249 | BOOST_REQUIRE(req.hasUri()); |
| 250 | BOOST_CHECK_EQUAL(req.getUri(), "udp4://159.242.33.78:6363"); |
| 251 | BOOST_REQUIRE(req.hasFacePersistency()); |
| 252 | BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 253 | |
| 254 | ControlParameters resp; |
| 255 | resp.setFaceId(2130) |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 256 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 257 | this->succeedCommand(resp); |
| 258 | }; |
| 259 | |
| 260 | this->execute("face create udp://159.242.33.78"); |
| 261 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 262 | BOOST_CHECK(out.is_equal("face-created id=2130 remote=udp4://159.242.33.78:6363 persistency=persistent\n")); |
| 263 | BOOST_CHECK(err.is_empty()); |
| 264 | } |
| 265 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 266 | BOOST_AUTO_TEST_CASE(UpgradingPersistency) |
| 267 | { |
| 268 | bool hasUpdateCommand = false; |
| 269 | this->processInterest = [this, &hasUpdateCommand] (const Interest& interest) { |
| 270 | if (this->getCommand("/localhost/nfd/faces/create")) { |
| 271 | this->respond409(FacePersistency::FACE_PERSISTENCY_ON_DEMAND); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/update"); |
| 276 | hasUpdateCommand = true; |
| 277 | BOOST_REQUIRE(req.hasFaceId()); |
| 278 | BOOST_CHECK_EQUAL(req.getFaceId(), 1172); |
| 279 | BOOST_REQUIRE(req.hasFacePersistency()); |
| 280 | BOOST_CHECK_EQUAL(req.getFacePersistency(), FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 281 | BOOST_CHECK(!req.hasFlags()); |
| 282 | |
| 283 | ControlParameters resp; |
| 284 | resp.setFaceId(1172) |
| 285 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT) |
| 286 | .setFlags(0); |
| 287 | this->succeedCommand(resp); |
| 288 | }; |
| 289 | |
| 290 | this->execute("face create udp://100.77.30.65"); |
| 291 | BOOST_CHECK(hasUpdateCommand); |
| 292 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 293 | BOOST_CHECK(out.is_equal("face-updated id=1172 remote=udp4://100.77.30.65:6363 persistency=persistent\n")); |
| 294 | BOOST_CHECK(err.is_empty()); |
| 295 | } |
| 296 | |
| 297 | BOOST_AUTO_TEST_CASE(NotDowngradingPersistency) |
| 298 | { |
| 299 | this->processInterest = [this] (const Interest& interest) { |
| 300 | this->respond409(FacePersistency::FACE_PERSISTENCY_PERMANENT); |
| 301 | // no command other than faces/create is expected |
| 302 | }; |
| 303 | |
| 304 | this->execute("face create udp://100.77.30.65"); |
| 305 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 306 | BOOST_CHECK(out.is_equal("face-exists id=1172 remote=udp4://100.77.30.65:6363 persistency=permanent\n")); |
| 307 | BOOST_CHECK(err.is_empty()); |
| 308 | } |
| 309 | |
| 310 | BOOST_AUTO_TEST_CASE(SamePersistency) |
| 311 | { |
| 312 | this->processInterest = [this] (const Interest& interest) { |
| 313 | this->respond409(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 314 | // no command other than faces/create is expected |
| 315 | }; |
| 316 | |
| 317 | this->execute("face create udp://100.77.30.65"); |
| 318 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 319 | BOOST_CHECK(out.is_equal("face-exists id=1172 remote=udp4://100.77.30.65:6363 persistency=persistent\n")); |
| 320 | BOOST_CHECK(err.is_empty()); |
| 321 | } |
| 322 | |
| 323 | BOOST_AUTO_TEST_CASE(ErrorCreate) |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 324 | { |
| 325 | this->processInterest = nullptr; // no response |
| 326 | |
| 327 | this->execute("face create udp://159.242.33.78"); |
| 328 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 329 | BOOST_CHECK(out.is_empty()); |
| 330 | BOOST_CHECK(err.is_equal("Error 10060 when creating face: request timed out\n")); |
| 331 | } |
| 332 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 333 | BOOST_AUTO_TEST_CASE(ErrorConflict) |
| 334 | { |
| 335 | // Current NFD will not report a 409-conflict with a different remote FaceUri, but this is |
| 336 | // allowed by FaceMgmt protocol and nfdc should not attempt to upgrade persistency in this case. |
| 337 | |
| 338 | this->processInterest = [this] (const Interest& interest) { |
| 339 | // conflict with udp4://100.77.30.65:6363 |
| 340 | this->respond409(FacePersistency::FACE_PERSISTENCY_ON_DEMAND); |
| 341 | }; |
| 342 | |
| 343 | this->execute("face create udp://20.53.73.45"); |
| 344 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 345 | BOOST_CHECK(out.is_empty()); |
| 346 | BOOST_CHECK(err.is_equal("Error 409 when creating face: conflict-409\n")); |
| 347 | } |
| 348 | |
| 349 | BOOST_AUTO_TEST_CASE(ErrorUpdate) |
| 350 | { |
| 351 | this->processInterest = [this] (const Interest& interest) { |
| 352 | if (this->getCommand("/localhost/nfd/faces/create")) { |
| 353 | this->respond409(FacePersistency::FACE_PERSISTENCY_ON_DEMAND); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/update"); |
| 358 | // no response to faces/update |
| 359 | }; |
| 360 | |
| 361 | this->execute("face create udp://100.77.30.65"); |
| 362 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 363 | BOOST_CHECK(out.is_empty()); |
| 364 | BOOST_CHECK(err.is_equal("Error 10060 when upgrading face persistency: request timed out\n")); |
| 365 | } |
| 366 | |
Junxiao Shi | 1d7fef5 | 2017-02-02 05:33:14 +0000 | [diff] [blame] | 367 | BOOST_AUTO_TEST_SUITE_END() // CreateCommand |
| 368 | |
Junxiao Shi | 05dd444 | 2017-02-06 22:50:07 +0000 | [diff] [blame] | 369 | BOOST_FIXTURE_TEST_SUITE(DestroyCommand, ExecuteCommandFixture) |
| 370 | |
| 371 | BOOST_AUTO_TEST_CASE(NormalByFaceId) |
| 372 | { |
| 373 | this->processInterest = [this] (const Interest& interest) { |
| 374 | if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 375 | BOOST_CHECK_EQUAL(interest.getName().size(), 5); |
| 376 | FaceQueryFilter filter(interest.getName().at(4).blockFromValue()); |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 377 | BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setFaceId(10156)); |
Junxiao Shi | 05dd444 | 2017-02-06 22:50:07 +0000 | [diff] [blame] | 378 | |
| 379 | FaceStatus faceStatus; |
| 380 | faceStatus.setFaceId(10156) |
| 381 | .setLocalUri("tcp4://151.26.163.27:22967") |
| 382 | .setRemoteUri("tcp4://198.57.27.40:6363") |
| 383 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 384 | this->sendDataset(interest.getName(), faceStatus); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy"); |
| 389 | BOOST_REQUIRE(req.hasFaceId()); |
| 390 | BOOST_CHECK_EQUAL(req.getFaceId(), 10156); |
| 391 | |
| 392 | ControlParameters resp; |
| 393 | resp.setFaceId(10156); |
| 394 | this->succeedCommand(resp); |
| 395 | }; |
| 396 | |
| 397 | this->execute("face destroy 10156"); |
| 398 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 399 | BOOST_CHECK(out.is_equal("face-destroyed id=10156 local=tcp4://151.26.163.27:22967 " |
| 400 | "remote=tcp4://198.57.27.40:6363 persistency=persistent\n")); |
| 401 | BOOST_CHECK(err.is_empty()); |
| 402 | } |
| 403 | |
| 404 | BOOST_AUTO_TEST_CASE(NormalByFaceUri) |
| 405 | { |
| 406 | this->processInterest = [this] (const Interest& interest) { |
| 407 | if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 408 | BOOST_CHECK_EQUAL(interest.getName().size(), 5); |
| 409 | FaceQueryFilter filter(interest.getName().at(4).blockFromValue()); |
Junxiao Shi | 8f803f2 | 2017-02-10 03:04:28 +0000 | [diff] [blame] | 410 | BOOST_CHECK_EQUAL(filter, FaceQueryFilter().setRemoteUri("tcp4://32.121.182.82:6363")); |
Junxiao Shi | 05dd444 | 2017-02-06 22:50:07 +0000 | [diff] [blame] | 411 | |
| 412 | FaceStatus faceStatus; |
| 413 | faceStatus.setFaceId(2249) |
| 414 | .setLocalUri("tcp4://30.99.87.98:31414") |
| 415 | .setRemoteUri("tcp4://32.121.182.82:6363") |
| 416 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 417 | this->sendDataset(interest.getName(), faceStatus); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy"); |
| 422 | BOOST_REQUIRE(req.hasFaceId()); |
| 423 | BOOST_CHECK_EQUAL(req.getFaceId(), 2249); |
| 424 | |
| 425 | ControlParameters resp; |
| 426 | resp.setFaceId(2249); |
| 427 | this->succeedCommand(resp); |
| 428 | }; |
| 429 | |
| 430 | this->execute("face destroy tcp://32.121.182.82"); |
| 431 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 432 | BOOST_CHECK(out.is_equal("face-destroyed id=2249 local=tcp4://30.99.87.98:31414 " |
| 433 | "remote=tcp4://32.121.182.82:6363 persistency=persistent\n")); |
| 434 | BOOST_CHECK(err.is_empty()); |
| 435 | } |
| 436 | |
| 437 | BOOST_AUTO_TEST_CASE(FaceNotExist) |
| 438 | { |
| 439 | this->processInterest = [this] (const Interest& interest) { |
| 440 | BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())); |
| 441 | this->sendEmptyDataset(interest.getName()); |
| 442 | }; |
| 443 | |
| 444 | this->execute("face destroy 23728"); |
| 445 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 446 | BOOST_CHECK(out.is_empty()); |
| 447 | BOOST_CHECK(err.is_equal("Face not found\n")); |
| 448 | } |
| 449 | |
| 450 | BOOST_AUTO_TEST_CASE(Ambiguous) |
| 451 | { |
| 452 | this->processInterest = [this] (const Interest& interest) { |
| 453 | BOOST_CHECK(Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())); |
| 454 | |
| 455 | FaceStatus faceStatus1, faceStatus2; |
| 456 | faceStatus1.setFaceId(6720) |
| 457 | .setLocalUri("udp4://202.83.168.28:56363") |
| 458 | .setRemoteUri("udp4://225.131.75.231:56363") |
| 459 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT); |
| 460 | faceStatus2.setFaceId(31066) |
| 461 | .setLocalUri("udp4://25.90.26.32:56363") |
| 462 | .setRemoteUri("udp4://225.131.75.231:56363") |
| 463 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERMANENT); |
| 464 | this->sendDataset(interest.getName(), faceStatus1, faceStatus2); |
| 465 | }; |
| 466 | |
| 467 | this->execute("face destroy udp4://225.131.75.231:56363"); |
| 468 | BOOST_CHECK_EQUAL(exitCode, 5); |
| 469 | BOOST_CHECK(out.is_empty()); |
| 470 | BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. " |
| 471 | "Re-run the command with a FaceId: " |
| 472 | "6720 (local=udp4://202.83.168.28:56363), " |
| 473 | "31066 (local=udp4://25.90.26.32:56363)\n")); |
| 474 | } |
| 475 | |
| 476 | BOOST_AUTO_TEST_CASE(ErrorCanonization) |
| 477 | { |
| 478 | this->execute("face destroy udp6://32.38.164.64:10445"); |
| 479 | BOOST_CHECK_EQUAL(exitCode, 4); |
| 480 | BOOST_CHECK(out.is_empty()); |
| 481 | BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: " |
| 482 | "No endpoints match the specified address selector\n")); |
| 483 | } |
| 484 | |
| 485 | BOOST_AUTO_TEST_CASE(ErrorDataset) |
| 486 | { |
| 487 | this->processInterest = nullptr; // no response to dataset or command |
| 488 | |
| 489 | this->execute("face destroy udp://159.242.33.78"); |
| 490 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 491 | BOOST_CHECK(out.is_empty()); |
| 492 | BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n")); |
| 493 | } |
| 494 | |
| 495 | BOOST_AUTO_TEST_CASE(ErrorCommand) |
| 496 | { |
| 497 | this->processInterest = [this] (const Interest& interest) { |
| 498 | if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) { |
| 499 | FaceStatus faceStatus; |
| 500 | faceStatus.setFaceId(17757) |
| 501 | .setLocalUri("tcp4://27.65.24.30:19187") |
| 502 | .setRemoteUri("tcp4://70.47.27.77:6363") |
| 503 | .setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT); |
| 504 | this->sendDataset(interest.getName(), faceStatus); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | MOCK_NFD_MGMT_REQUIRE_LAST_COMMAND_IS("/localhost/nfd/faces/destroy"); |
| 509 | // no response to command |
| 510 | }; |
| 511 | |
| 512 | this->execute("face destroy 17757"); |
| 513 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 514 | BOOST_CHECK(out.is_empty()); |
| 515 | BOOST_CHECK(err.is_equal("Error 10060 when destroying face: request timed out\n")); |
| 516 | } |
| 517 | |
| 518 | BOOST_AUTO_TEST_SUITE_END() // DestroyCommand |
| 519 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 520 | const std::string STATUS_XML = stripXmlSpaces(R"XML( |
| 521 | <faces> |
| 522 | <face> |
| 523 | <faceId>134</faceId> |
| 524 | <remoteUri>udp4://233.252.0.4:6363</remoteUri> |
| 525 | <localUri>udp4://192.0.2.1:6363</localUri> |
| 526 | <faceScope>non-local</faceScope> |
| 527 | <facePersistency>permanent</facePersistency> |
| 528 | <linkType>multi-access</linkType> |
Eric Newberry | 6d932e8 | 2016-11-24 05:05:43 +0000 | [diff] [blame] | 529 | <flags/> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 530 | <packetCounters> |
| 531 | <incomingPackets> |
| 532 | <nInterests>22562</nInterests> |
| 533 | <nDatas>22031</nDatas> |
| 534 | <nNacks>63</nNacks> |
| 535 | </incomingPackets> |
| 536 | <outgoingPackets> |
| 537 | <nInterests>30121</nInterests> |
| 538 | <nDatas>20940</nDatas> |
| 539 | <nNacks>1218</nNacks> |
| 540 | </outgoingPackets> |
| 541 | </packetCounters> |
| 542 | <byteCounters> |
| 543 | <incomingBytes>2522915</incomingBytes> |
| 544 | <outgoingBytes>1353592</outgoingBytes> |
| 545 | </byteCounters> |
| 546 | </face> |
| 547 | <face> |
| 548 | <faceId>745</faceId> |
| 549 | <remoteUri>fd://75</remoteUri> |
| 550 | <localUri>unix:///var/run/nfd.sock</localUri> |
| 551 | <faceScope>local</faceScope> |
| 552 | <facePersistency>on-demand</facePersistency> |
| 553 | <linkType>point-to-point</linkType> |
Eric Newberry | 6d932e8 | 2016-11-24 05:05:43 +0000 | [diff] [blame] | 554 | <flags> |
| 555 | <localFieldsEnabled/> |
| 556 | </flags> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 557 | <packetCounters> |
| 558 | <incomingPackets> |
| 559 | <nInterests>18998</nInterests> |
| 560 | <nDatas>26701</nDatas> |
| 561 | <nNacks>147</nNacks> |
| 562 | </incomingPackets> |
| 563 | <outgoingPackets> |
| 564 | <nInterests>34779</nInterests> |
| 565 | <nDatas>17028</nDatas> |
| 566 | <nNacks>1176</nNacks> |
| 567 | </outgoingPackets> |
| 568 | </packetCounters> |
| 569 | <byteCounters> |
| 570 | <incomingBytes>4672308</incomingBytes> |
| 571 | <outgoingBytes>8957187</outgoingBytes> |
| 572 | </byteCounters> |
| 573 | </face> |
| 574 | </faces> |
| 575 | )XML"); |
| 576 | |
| 577 | const std::string STATUS_TEXT = |
| 578 | "Faces:\n" |
| 579 | " faceid=134 remote=udp4://233.252.0.4:6363 local=udp4://192.0.2.1:6363" |
| 580 | " counters={in={22562i 22031d 63n 2522915B} out={30121i 20940d 1218n 1353592B}}" |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 581 | " flags={non-local permanent multi-access}\n" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 582 | " faceid=745 remote=fd://75 local=unix:///var/run/nfd.sock" |
| 583 | " counters={in={18998i 26701d 147n 4672308B} out={34779i 17028d 1176n 8957187B}}" |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 584 | " flags={local on-demand point-to-point local-fields}\n"; |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 585 | |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 586 | BOOST_FIXTURE_TEST_CASE(Status, StatusFixture<FaceModule>) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 587 | { |
| 588 | this->fetchStatus(); |
| 589 | FaceStatus payload1; |
| 590 | payload1.setFaceId(134) |
| 591 | .setRemoteUri("udp4://233.252.0.4:6363") |
| 592 | .setLocalUri("udp4://192.0.2.1:6363") |
| 593 | .setFaceScope(ndn::nfd::FACE_SCOPE_NON_LOCAL) |
| 594 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT) |
| 595 | .setLinkType(ndn::nfd::LINK_TYPE_MULTI_ACCESS) |
| 596 | .setNInInterests(22562) |
| 597 | .setNInDatas(22031) |
| 598 | .setNInNacks(63) |
| 599 | .setNOutInterests(30121) |
| 600 | .setNOutDatas(20940) |
| 601 | .setNOutNacks(1218) |
| 602 | .setNInBytes(2522915) |
| 603 | .setNOutBytes(1353592); |
| 604 | FaceStatus payload2; |
| 605 | payload2.setFaceId(745) |
| 606 | .setRemoteUri("fd://75") |
| 607 | .setLocalUri("unix:///var/run/nfd.sock") |
| 608 | .setFaceScope(ndn::nfd::FACE_SCOPE_LOCAL) |
| 609 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND) |
| 610 | .setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT) |
Eric Newberry | 6d932e8 | 2016-11-24 05:05:43 +0000 | [diff] [blame] | 611 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 612 | .setNInInterests(18998) |
| 613 | .setNInDatas(26701) |
| 614 | .setNInNacks(147) |
| 615 | .setNOutInterests(34779) |
| 616 | .setNOutDatas(17028) |
| 617 | .setNOutNacks(1176) |
| 618 | .setNInBytes(4672308) |
| 619 | .setNOutBytes(8957187); |
| 620 | this->sendDataset("/localhost/nfd/faces/list", payload1, payload2); |
| 621 | this->prepareStatusOutput(); |
| 622 | |
| 623 | BOOST_CHECK(statusXml.is_equal(STATUS_XML)); |
| 624 | BOOST_CHECK(statusText.is_equal(STATUS_TEXT)); |
| 625 | } |
| 626 | |
| 627 | BOOST_AUTO_TEST_SUITE_END() // TestFaceModule |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 628 | BOOST_AUTO_TEST_SUITE_END() // Nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 629 | |
| 630 | } // namespace tests |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 631 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 632 | } // namespace tools |
| 633 | } // namespace nfd |