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/rib-module.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 27 | |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 28 | #include "execute-command-fixture.hpp" |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 29 | #include "status-fixture.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 33 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Nfdc) |
Junxiao Shi | 1f481fa | 2017-01-26 15:14:43 +0000 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 38 | |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 39 | class RouteListFixture : public ExecuteCommandFixture |
| 40 | { |
| 41 | protected: |
| 42 | bool |
| 43 | respondRibDataset(const Interest& interest) |
| 44 | { |
| 45 | if (!Name("/localhost/nfd/rib/list").isPrefixOf(interest.getName())) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | RibEntry entry1; |
| 50 | entry1.setName("/5BBmTevRJ"); |
| 51 | entry1.addRoute(Route() |
| 52 | .setFaceId(6720) |
| 53 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT) |
| 54 | .setCost(2956) |
| 55 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE) |
| 56 | .setExpirationPeriod(time::milliseconds(29950035))); |
| 57 | entry1.addRoute(Route() |
| 58 | .setFaceId(6720) |
| 59 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 60 | .setCost(425) |
| 61 | .setFlags(ndn::nfd::ROUTE_FLAGS_NONE)); |
| 62 | entry1.addRoute(Route() |
| 63 | .setFaceId(8599) |
| 64 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 65 | .setCost(9140) |
| 66 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)); |
| 67 | |
| 68 | RibEntry entry2; |
| 69 | entry2.setName("/aDPTKCio"); |
| 70 | entry2.addRoute(Route() |
| 71 | .setFaceId(31066) |
| 72 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT) |
| 73 | .setCost(4617) |
| 74 | .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE)); |
| 75 | |
| 76 | this->sendDataset(interest.getName(), entry1, entry2); |
| 77 | return true; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | BOOST_FIXTURE_TEST_SUITE(ListShowCommand, RouteListFixture) |
| 82 | |
| 83 | const std::string NOFILTER_OUTPUT = std::string(R"TEXT( |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 84 | prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s |
| 85 | prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never |
| 86 | prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never |
| 87 | prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 88 | )TEXT").substr(1); |
| 89 | |
| 90 | BOOST_AUTO_TEST_CASE(ListNoFilter) |
| 91 | { |
| 92 | this->processInterest = [this] (const Interest& interest) { |
| 93 | BOOST_CHECK(this->respondRibDataset(interest)); |
| 94 | }; |
| 95 | |
| 96 | this->execute("route"); |
| 97 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 98 | BOOST_CHECK(out.is_equal(NOFILTER_OUTPUT)); |
| 99 | BOOST_CHECK(err.is_empty()); |
| 100 | } |
| 101 | |
| 102 | const std::string NEXTHOP_OUTPUT = std::string(R"TEXT( |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 103 | prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s |
| 104 | prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never |
| 105 | prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 106 | )TEXT").substr(1); |
| 107 | |
| 108 | BOOST_AUTO_TEST_CASE(ListByNexthop) |
| 109 | { |
| 110 | this->processInterest = [this] (const Interest& interest) { |
| 111 | BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest)); |
| 112 | }; |
| 113 | |
| 114 | this->execute("route list udp4://225.131.75.231:56363"); |
| 115 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 116 | BOOST_CHECK(out.is_equal(NEXTHOP_OUTPUT)); |
| 117 | BOOST_CHECK(err.is_empty()); |
| 118 | } |
| 119 | |
| 120 | const std::string ORIGIN_OUTPUT = std::string(R"TEXT( |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 121 | prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never |
| 122 | prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 123 | )TEXT").substr(1); |
| 124 | |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 125 | BOOST_AUTO_TEST_CASE(ListByOriginNumeric) |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 126 | { |
| 127 | this->processInterest = [this] (const Interest& interest) { |
| 128 | BOOST_CHECK(this->respondRibDataset(interest)); |
| 129 | }; |
| 130 | |
| 131 | this->execute("route list origin 255"); |
| 132 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 133 | BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT)); |
| 134 | BOOST_CHECK(err.is_empty()); |
| 135 | } |
| 136 | |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 137 | BOOST_AUTO_TEST_CASE(ListByOriginString) |
| 138 | { |
| 139 | this->processInterest = [this] (const Interest& interest) { |
| 140 | BOOST_CHECK(this->respondRibDataset(interest)); |
| 141 | }; |
| 142 | |
| 143 | this->execute("route list origin static"); |
| 144 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 145 | BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT)); |
| 146 | BOOST_CHECK(err.is_empty()); |
| 147 | } |
| 148 | |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 149 | const std::string PREFIX_OUTPUT = std::string(R"TEXT( |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 150 | prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s |
| 151 | prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never |
| 152 | prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never |
Junxiao Shi | 1d62e62 | 2017-03-08 22:39:28 +0000 | [diff] [blame] | 153 | )TEXT").substr(1); |
| 154 | |
| 155 | BOOST_AUTO_TEST_CASE(ShowByPrefix) |
| 156 | { |
| 157 | this->processInterest = [this] (const Interest& interest) { |
| 158 | BOOST_CHECK(this->respondRibDataset(interest)); |
| 159 | }; |
| 160 | |
| 161 | this->execute("route show 5BBmTevRJ"); |
| 162 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 163 | BOOST_CHECK(out.is_equal(PREFIX_OUTPUT)); |
| 164 | BOOST_CHECK(err.is_empty()); |
| 165 | } |
| 166 | |
| 167 | BOOST_AUTO_TEST_CASE(FaceNotExist) |
| 168 | { |
| 169 | this->processInterest = [this] (const Interest& interest) { |
| 170 | BOOST_CHECK(this->respondFaceQuery(interest)); |
| 171 | }; |
| 172 | |
| 173 | this->execute("route list 23728"); |
| 174 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 175 | BOOST_CHECK(out.is_empty()); |
| 176 | BOOST_CHECK(err.is_equal("Face not found\n")); |
| 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_CASE(RouteNotExist) |
| 180 | { |
| 181 | this->processInterest = [this] (const Interest& interest) { |
| 182 | BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest)); |
| 183 | }; |
| 184 | |
| 185 | this->execute("route list 10156"); |
| 186 | BOOST_CHECK_EQUAL(exitCode, 6); |
| 187 | BOOST_CHECK(out.is_empty()); |
| 188 | BOOST_CHECK(err.is_equal("Route not found\n")); |
| 189 | } |
| 190 | |
| 191 | BOOST_AUTO_TEST_CASE(ErrorDataset) |
| 192 | { |
| 193 | this->processInterest = nullptr; // no response to dataset |
| 194 | |
| 195 | this->execute("route list"); |
| 196 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 197 | BOOST_CHECK(out.is_empty()); |
| 198 | BOOST_CHECK(err.is_equal("Error 10060 when fetching RIB dataset: Timeout\n")); |
| 199 | } |
| 200 | |
| 201 | BOOST_AUTO_TEST_SUITE_END() // ListShowCommand |
| 202 | |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 203 | BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture) |
| 204 | |
| 205 | BOOST_AUTO_TEST_CASE(NormalByFaceId) |
| 206 | { |
| 207 | this->processInterest = [this] (const Interest& interest) { |
| 208 | if (this->respondFaceQuery(interest)) { |
| 209 | return; |
| 210 | } |
| 211 | |
Junxiao Shi | 1a25a6e | 2017-03-06 03:09:47 +0000 | [diff] [blame] | 212 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 213 | ndn::nfd::RibRegisterCommand cmd; |
| 214 | cmd.validateRequest(req); |
| 215 | cmd.applyDefaultsToRequest(req); |
| 216 | BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB"); |
| 217 | BOOST_CHECK_EQUAL(req.getFaceId(), 10156); |
| 218 | BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC); |
| 219 | BOOST_CHECK_EQUAL(req.getCost(), 0); |
| 220 | BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAGS_NONE); |
| 221 | BOOST_CHECK_EQUAL(req.hasExpirationPeriod(), false); |
| 222 | |
Junxiao Shi | 1a25a6e | 2017-03-06 03:09:47 +0000 | [diff] [blame] | 223 | this->succeedCommand(interest, req); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | this->execute("route add /vxXoEaWeDB 10156 no-inherit"); |
| 227 | BOOST_CHECK_EQUAL(exitCode, 0); |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 228 | BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=static " |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 229 | "cost=0 flags=none expires=never\n")); |
| 230 | BOOST_CHECK(err.is_empty()); |
| 231 | } |
| 232 | |
| 233 | BOOST_AUTO_TEST_CASE(NormalByFaceUri) |
| 234 | { |
| 235 | this->processInterest = [this] (const Interest& interest) { |
| 236 | if (this->respondFaceQuery(interest)) { |
| 237 | return; |
| 238 | } |
| 239 | |
Junxiao Shi | 1a25a6e | 2017-03-06 03:09:47 +0000 | [diff] [blame] | 240 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 241 | ndn::nfd::RibRegisterCommand cmd; |
| 242 | cmd.validateRequest(req); |
| 243 | cmd.applyDefaultsToRequest(req); |
| 244 | BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf"); |
| 245 | BOOST_CHECK_EQUAL(req.getFaceId(), 2249); |
| 246 | BOOST_CHECK_EQUAL(req.getOrigin(), 17591); |
| 247 | BOOST_CHECK_EQUAL(req.getCost(), 702); |
| 248 | BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | |
| 249 | ndn::nfd::ROUTE_FLAG_CAPTURE); |
| 250 | BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true); |
| 251 | BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), time::milliseconds(727411987)); |
| 252 | |
| 253 | ControlParameters resp = req; |
| 254 | resp.setExpirationPeriod(time::milliseconds(727411154)); // server side may change expiration |
Junxiao Shi | 1a25a6e | 2017-03-06 03:09:47 +0000 | [diff] [blame] | 255 | this->succeedCommand(interest, resp); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | this->execute("route add /FLQAsaYnYf tcp4://32.121.182.82:6363 " |
| 259 | "origin 17591 cost 702 capture expires 727411987"); |
| 260 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 261 | BOOST_CHECK(out.is_equal("route-add-accepted prefix=/FLQAsaYnYf nexthop=2249 origin=17591 " |
| 262 | "cost=702 flags=child-inherit|capture expires=727411154ms\n")); |
| 263 | BOOST_CHECK(err.is_empty()); |
| 264 | } |
| 265 | |
| 266 | BOOST_AUTO_TEST_CASE(FaceNotExist) |
| 267 | { |
| 268 | this->processInterest = [this] (const Interest& interest) { |
| 269 | BOOST_CHECK(this->respondFaceQuery(interest)); |
| 270 | }; |
| 271 | |
| 272 | this->execute("route add /GJiKDus5i 23728"); |
| 273 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 274 | BOOST_CHECK(out.is_empty()); |
| 275 | BOOST_CHECK(err.is_equal("Face not found\n")); |
| 276 | } |
| 277 | |
| 278 | BOOST_AUTO_TEST_CASE(Ambiguous) |
| 279 | { |
| 280 | this->processInterest = [this] (const Interest& interest) { |
| 281 | BOOST_CHECK(this->respondFaceQuery(interest)); |
| 282 | }; |
| 283 | |
| 284 | this->execute("route add /BQqjjnVsz udp4://225.131.75.231:56363"); |
| 285 | BOOST_CHECK_EQUAL(exitCode, 5); |
| 286 | BOOST_CHECK(out.is_empty()); |
| 287 | BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. " |
| 288 | "Re-run the command with a FaceId: " |
| 289 | "6720 (local=udp4://202.83.168.28:56363), " |
| 290 | "31066 (local=udp4://25.90.26.32:56363)\n")); |
| 291 | } |
| 292 | |
| 293 | BOOST_AUTO_TEST_CASE(ErrorCanonization) |
| 294 | { |
| 295 | this->execute("route add /bxJfGsVtDt udp6://32.38.164.64:10445"); |
| 296 | BOOST_CHECK_EQUAL(exitCode, 4); |
| 297 | BOOST_CHECK(out.is_empty()); |
| 298 | BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: " |
| 299 | "No endpoints match the specified address selector\n")); |
| 300 | } |
| 301 | |
| 302 | BOOST_AUTO_TEST_CASE(ErrorDataset) |
| 303 | { |
| 304 | this->processInterest = nullptr; // no response to dataset or command |
| 305 | |
| 306 | this->execute("route add /q1Qf7go7 udp://159.242.33.78"); |
| 307 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 308 | BOOST_CHECK(out.is_empty()); |
| 309 | BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n")); |
| 310 | } |
| 311 | |
| 312 | BOOST_AUTO_TEST_CASE(ErrorCommand) |
| 313 | { |
| 314 | this->processInterest = [this] (const Interest& interest) { |
| 315 | if (this->respondFaceQuery(interest)) { |
| 316 | return; |
| 317 | } |
| 318 | |
Junxiao Shi | 1a25a6e | 2017-03-06 03:09:47 +0000 | [diff] [blame] | 319 | MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); |
Junxiao Shi | 918e5d4 | 2017-02-25 03:58:21 +0000 | [diff] [blame] | 320 | // no response to command |
| 321 | }; |
| 322 | |
| 323 | this->execute("route add /bYiMbEuE 10156"); |
| 324 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 325 | BOOST_CHECK(out.is_empty()); |
| 326 | BOOST_CHECK(err.is_equal("Error 10060 when adding route: request timed out\n")); |
| 327 | } |
| 328 | |
| 329 | BOOST_AUTO_TEST_SUITE_END() // AddCommand |
| 330 | |
Junxiao Shi | 084b795 | 2017-02-26 22:00:53 +0000 | [diff] [blame] | 331 | BOOST_FIXTURE_TEST_SUITE(RemoveCommand, ExecuteCommandFixture) |
| 332 | |
| 333 | BOOST_AUTO_TEST_CASE(NormalByFaceId) |
| 334 | { |
| 335 | this->processInterest = [this] (const Interest& interest) { |
| 336 | if (this->respondFaceQuery(interest)) { |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); |
| 341 | ndn::nfd::RibUnregisterCommand cmd; |
| 342 | cmd.validateRequest(req); |
| 343 | cmd.applyDefaultsToRequest(req); |
| 344 | BOOST_CHECK_EQUAL(req.getName(), "/2B5NUGjpt"); |
| 345 | BOOST_CHECK_EQUAL(req.getFaceId(), 10156); |
| 346 | BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC); |
| 347 | |
| 348 | this->succeedCommand(interest, req); |
| 349 | }; |
| 350 | |
| 351 | this->execute("route remove /2B5NUGjpt 10156"); |
| 352 | BOOST_CHECK_EQUAL(exitCode, 0); |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 353 | BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=static\n")); |
Junxiao Shi | 084b795 | 2017-02-26 22:00:53 +0000 | [diff] [blame] | 354 | BOOST_CHECK(err.is_empty()); |
| 355 | } |
| 356 | |
| 357 | BOOST_AUTO_TEST_CASE(NormalByFaceUri) |
| 358 | { |
| 359 | this->processInterest = [this] (const Interest& interest) { |
| 360 | if (this->respondFaceQuery(interest)) { |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); |
| 365 | ndn::nfd::RibUnregisterCommand cmd; |
| 366 | cmd.validateRequest(req); |
| 367 | cmd.applyDefaultsToRequest(req); |
| 368 | BOOST_CHECK_EQUAL(req.getName(), "/wHdNn0BtUF"); |
| 369 | BOOST_CHECK_EQUAL(req.getFaceId(), 2249); |
| 370 | BOOST_CHECK_EQUAL(req.getOrigin(), 15246); |
| 371 | |
| 372 | this->succeedCommand(interest, req); |
| 373 | }; |
| 374 | |
| 375 | this->execute("route remove /wHdNn0BtUF tcp4://32.121.182.82:6363 origin 15246"); |
| 376 | BOOST_CHECK_EQUAL(exitCode, 0); |
| 377 | BOOST_CHECK(out.is_equal("route-removed prefix=/wHdNn0BtUF nexthop=2249 origin=15246\n")); |
| 378 | BOOST_CHECK(err.is_empty()); |
| 379 | } |
| 380 | |
| 381 | BOOST_AUTO_TEST_CASE(MultipleFaces) |
| 382 | { |
| 383 | std::set<uint64_t> faceIds{6720, 31066}; |
| 384 | this->processInterest = [this, &faceIds] (const Interest& interest) { |
| 385 | if (this->respondFaceQuery(interest)) { |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); |
| 390 | ndn::nfd::RibUnregisterCommand cmd; |
| 391 | cmd.validateRequest(req); |
| 392 | cmd.applyDefaultsToRequest(req); |
| 393 | BOOST_CHECK_EQUAL(req.getName(), "/nm5y8X8b2"); |
| 394 | BOOST_CHECK_MESSAGE(faceIds.erase(req.getFaceId()), "expected face " + std::to_string(req.getFaceId())); |
| 395 | BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC); |
| 396 | |
| 397 | this->succeedCommand(interest, req); |
| 398 | }; |
| 399 | |
| 400 | this->execute("route remove /nm5y8X8b2 udp4://225.131.75.231:56363"); |
| 401 | BOOST_CHECK(faceIds.empty()); |
| 402 | BOOST_CHECK_EQUAL(exitCode, 0); |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 403 | BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=static\n" |
| 404 | "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=static\n")); |
Junxiao Shi | 084b795 | 2017-02-26 22:00:53 +0000 | [diff] [blame] | 405 | BOOST_CHECK(err.is_empty()); |
| 406 | } |
| 407 | |
| 408 | BOOST_AUTO_TEST_CASE(FaceNotExist) |
| 409 | { |
| 410 | this->processInterest = [this] (const Interest& interest) { |
| 411 | BOOST_CHECK(this->respondFaceQuery(interest)); |
| 412 | }; |
| 413 | |
| 414 | this->execute("route remove /HeGRjzwFM 23728"); |
| 415 | BOOST_CHECK_EQUAL(exitCode, 3); |
| 416 | BOOST_CHECK(out.is_empty()); |
| 417 | BOOST_CHECK(err.is_equal("Face not found\n")); |
| 418 | } |
| 419 | |
| 420 | BOOST_AUTO_TEST_CASE(ErrorDataset) |
| 421 | { |
| 422 | this->processInterest = nullptr; // no response to dataset or command |
| 423 | |
| 424 | this->execute("route remove /YX4xQQN3v5 udp://26.97.248.3"); |
| 425 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 426 | BOOST_CHECK(out.is_empty()); |
| 427 | BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout\n")); |
| 428 | } |
| 429 | |
| 430 | BOOST_AUTO_TEST_CASE(ErrorCommand) |
| 431 | { |
| 432 | this->processInterest = [this] (const Interest& interest) { |
| 433 | if (this->respondFaceQuery(interest)) { |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); |
| 438 | // no response to command |
| 439 | }; |
| 440 | |
| 441 | this->execute("route remove /mvGRoxD2 10156"); |
| 442 | BOOST_CHECK_EQUAL(exitCode, 1); |
| 443 | BOOST_CHECK(out.is_empty()); |
| 444 | BOOST_CHECK(err.is_equal("Error 10060 when removing route: request timed out\n")); |
| 445 | } |
| 446 | |
| 447 | BOOST_AUTO_TEST_SUITE_END() // RemoveCommand |
| 448 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 449 | const std::string STATUS_XML = stripXmlSpaces(R"XML( |
| 450 | <rib> |
| 451 | <ribEntry> |
| 452 | <prefix>/</prefix> |
| 453 | <routes> |
| 454 | <route> |
| 455 | <faceId>262</faceId> |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 456 | <origin>static</origin> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 457 | <cost>9</cost> |
| 458 | <flags> |
| 459 | <ribCapture/> |
| 460 | </flags> |
| 461 | </route> |
| 462 | <route> |
| 463 | <faceId>272</faceId> |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 464 | <origin>static</origin> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 465 | <cost>50</cost> |
| 466 | <flags/> |
| 467 | </route> |
| 468 | <route> |
| 469 | <faceId>274</faceId> |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 470 | <origin>static</origin> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 471 | <cost>78</cost> |
| 472 | <flags> |
| 473 | <childInherit/> |
| 474 | <ribCapture/> |
| 475 | </flags> |
| 476 | </route> |
| 477 | <route> |
| 478 | <faceId>276</faceId> |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 479 | <origin>static</origin> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 480 | <cost>79</cost> |
| 481 | <flags> |
| 482 | <childInherit/> |
| 483 | </flags> |
| 484 | <expirationPeriod>PT47S</expirationPeriod> |
| 485 | </route> |
| 486 | </routes> |
| 487 | </ribEntry> |
| 488 | <ribEntry> |
| 489 | <prefix>/localhost/nfd</prefix> |
| 490 | <routes> |
| 491 | <route> |
| 492 | <faceId>258</faceId> |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 493 | <origin>app</origin> |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 494 | <cost>0</cost> |
| 495 | <flags> |
| 496 | <childInherit/> |
| 497 | </flags> |
| 498 | </route> |
| 499 | </routes> |
| 500 | </ribEntry> |
| 501 | </rib> |
| 502 | )XML"); |
| 503 | |
| 504 | const std::string STATUS_TEXT = |
| 505 | "RIB:\n" |
Junxiao Shi | 8eda682 | 2017-04-12 02:53:14 +0000 | [diff] [blame] | 506 | " / routes={nexthop=262 origin=static cost=9 flags=capture expires=never, " |
| 507 | "nexthop=272 origin=static cost=50 flags=none expires=never, " |
| 508 | "nexthop=274 origin=static cost=78 flags=child-inherit|capture expires=never, " |
| 509 | "nexthop=276 origin=static cost=79 flags=child-inherit expires=47s}\n" |
| 510 | " /localhost/nfd routes={nexthop=258 origin=app cost=0 flags=child-inherit expires=never}\n"; |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 511 | |
| 512 | BOOST_AUTO_TEST_CASE(Status) |
| 513 | { |
| 514 | this->fetchStatus(); |
| 515 | RibEntry payload1; |
| 516 | payload1.setName("/") |
| 517 | .addRoute(Route().setFaceId(262) |
| 518 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 519 | .setCost(9) |
| 520 | .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE)) |
| 521 | .addRoute(Route().setFaceId(272) |
| 522 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 523 | .setCost(50) |
| 524 | .setFlags(ndn::nfd::ROUTE_FLAGS_NONE)) |
| 525 | .addRoute(Route().setFaceId(274) |
| 526 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 527 | .setCost(78) |
| 528 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)) |
| 529 | .addRoute(Route().setFaceId(276) |
| 530 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC) |
| 531 | .setCost(79) |
| 532 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT) |
| 533 | .setExpirationPeriod(time::milliseconds(47292))); |
| 534 | RibEntry payload2; |
| 535 | payload2.setName("/localhost/nfd") |
| 536 | .addRoute(Route().setFaceId(258) |
| 537 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_APP) |
| 538 | .setCost(0) |
| 539 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)); |
| 540 | this->sendDataset("/localhost/nfd/rib/list", payload1, payload2); |
| 541 | this->prepareStatusOutput(); |
| 542 | |
| 543 | BOOST_CHECK(statusXml.is_equal(STATUS_XML)); |
| 544 | BOOST_CHECK(statusText.is_equal(STATUS_TEXT)); |
| 545 | } |
| 546 | |
| 547 | BOOST_AUTO_TEST_SUITE_END() // TestRibModule |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 548 | BOOST_AUTO_TEST_SUITE_END() // Nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 549 | |
| 550 | } // namespace tests |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 551 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 552 | } // namespace tools |
| 553 | } // namespace nfd |