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