Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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. |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 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 | |
| 26 | #include "rib/rib-manager.hpp" |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/management/nfd-face-status.hpp> |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 28 | #include "rib/rib-status-publisher-common.hpp" |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 29 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 30 | #include "tests/test-common.hpp" |
| 31 | #include "tests/limited-io.hpp" |
| 32 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 33 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 34 | namespace nfd { |
| 35 | namespace rib { |
| 36 | namespace tests { |
| 37 | |
| 38 | class RibManagerFixture : public nfd::tests::BaseFixture |
| 39 | { |
| 40 | public: |
| 41 | RibManagerFixture() |
| 42 | : COMMAND_PREFIX("/localhost/nfd/rib") |
| 43 | , ADD_NEXTHOP_VERB("add-nexthop") |
| 44 | , REMOVE_NEXTHOP_VERB("remove-nexthop") |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 45 | , REGISTER_COMMAND("/localhost/nfd/rib/register") |
| 46 | , UNREGISTER_COMMAND("/localhost/nfd/rib/unregister") |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 47 | { |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 48 | face = ndn::util::makeDummyClientFace(); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 49 | |
| 50 | manager = make_shared<RibManager>(ndn::ref(*face)); |
| 51 | manager->registerWithNfd(); |
| 52 | |
| 53 | face->processEvents(time::milliseconds(1)); |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 54 | face->sentInterests.clear(); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | ~RibManagerFixture() |
| 58 | { |
| 59 | manager.reset(); |
| 60 | face.reset(); |
| 61 | } |
| 62 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 63 | void |
| 64 | extractParameters(Interest& interest, Name::Component& verb, |
| 65 | ControlParameters& extractedParameters) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 66 | { |
| 67 | const Name& name = interest.getName(); |
| 68 | verb = name[COMMAND_PREFIX.size()]; |
| 69 | const Name::Component& parameterComponent = name[COMMAND_PREFIX.size() + 1]; |
| 70 | |
| 71 | Block rawParameters = parameterComponent.blockFromValue(); |
| 72 | extractedParameters.wireDecode(rawParameters); |
| 73 | } |
| 74 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 75 | void |
| 76 | receiveCommandInterest(const Name& name, ControlParameters& parameters) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 77 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 78 | Name commandName = name; |
| 79 | commandName.append(parameters.wireEncode()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 80 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 81 | Interest commandInterest(commandName); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 82 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 83 | manager->m_managedRib.m_onSendBatchFromQueue = bind(&RibManagerFixture::onSendBatchFromQueue, |
| 84 | this, _1, parameters); |
| 85 | |
| 86 | face->receive(commandInterest); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 87 | face->processEvents(time::milliseconds(1)); |
| 88 | } |
| 89 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 90 | void |
| 91 | onSendBatchFromQueue(const RibUpdateBatch& batch, const ControlParameters parameters) |
| 92 | { |
| 93 | BOOST_REQUIRE(batch.begin() != batch.end()); |
| 94 | RibUpdate update = *(batch.begin()); |
| 95 | |
| 96 | Rib::UpdateSuccessCallback managerCallback = |
| 97 | bind(&RibManager::onRibUpdateSuccess, manager, update); |
| 98 | |
| 99 | Rib& rib = manager->m_managedRib; |
| 100 | |
| 101 | // Simulate a successful response from NFD |
| 102 | FibUpdater& updater = manager->m_fibUpdater; |
| 103 | rib.onFibUpdateSuccess(batch, updater.m_inheritedRoutes, managerCallback); |
| 104 | } |
| 105 | |
| 106 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 107 | public: |
| 108 | shared_ptr<RibManager> manager; |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 109 | shared_ptr<ndn::util::DummyClientFace> face; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 110 | |
| 111 | const Name COMMAND_PREFIX; |
| 112 | const Name::Component ADD_NEXTHOP_VERB; |
| 113 | const Name::Component REMOVE_NEXTHOP_VERB; |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 114 | |
| 115 | const Name REGISTER_COMMAND; |
| 116 | const Name UNREGISTER_COMMAND; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | class AuthorizedRibManager : public RibManagerFixture |
| 120 | { |
| 121 | public: |
| 122 | AuthorizedRibManager() |
| 123 | { |
| 124 | ConfigFile config; |
| 125 | manager->setConfigFile(config); |
| 126 | |
| 127 | const std::string CONFIG_STRING = |
| 128 | "rib\n" |
| 129 | "{\n" |
| 130 | " localhost_security\n" |
| 131 | " {\n" |
| 132 | " trust-anchor\n" |
| 133 | " {\n" |
| 134 | " type any\n" |
| 135 | " }\n" |
| 136 | " }" |
| 137 | "}"; |
| 138 | |
| 139 | config.parse(CONFIG_STRING, true, "test-rib"); |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | typedef RibManagerFixture UnauthorizedRibManager; |
| 144 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 145 | BOOST_FIXTURE_TEST_SUITE(TestRibManager, RibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 146 | |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 147 | BOOST_FIXTURE_TEST_CASE(ShortName, AuthorizedRibManager) |
| 148 | { |
| 149 | Name commandName("/localhost/nfd/rib"); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 150 | ndn::nfd::ControlParameters parameters; |
| 151 | |
| 152 | receiveCommandInterest(commandName, parameters); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 153 | // TODO verify error response |
| 154 | } |
| 155 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 156 | BOOST_FIXTURE_TEST_CASE(Basic, AuthorizedRibManager) |
| 157 | { |
| 158 | ControlParameters parameters; |
| 159 | parameters |
| 160 | .setName("/hello") |
| 161 | .setFaceId(1) |
| 162 | .setCost(10) |
| 163 | .setFlags(0) |
| 164 | .setOrigin(128) |
| 165 | .setExpirationPeriod(ndn::time::milliseconds::max()); |
| 166 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 167 | receiveCommandInterest(REGISTER_COMMAND, parameters); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 168 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 169 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | BOOST_FIXTURE_TEST_CASE(Register, AuthorizedRibManager) |
| 173 | { |
| 174 | ControlParameters parameters; |
| 175 | parameters |
| 176 | .setName("/hello") |
| 177 | .setFaceId(1) |
| 178 | .setCost(10) |
| 179 | .setFlags(0) |
| 180 | .setOrigin(128) |
| 181 | .setExpirationPeriod(ndn::time::milliseconds::max()); |
| 182 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 183 | receiveCommandInterest(REGISTER_COMMAND, parameters); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 184 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 185 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 186 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 187 | Interest& request = face->sentInterests[0]; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 188 | |
| 189 | ControlParameters extractedParameters; |
| 190 | Name::Component verb; |
| 191 | extractParameters(request, verb, extractedParameters); |
| 192 | |
| 193 | BOOST_CHECK_EQUAL(verb, ADD_NEXTHOP_VERB); |
| 194 | BOOST_CHECK_EQUAL(extractedParameters.getName(), parameters.getName()); |
| 195 | BOOST_CHECK_EQUAL(extractedParameters.getFaceId(), parameters.getFaceId()); |
| 196 | BOOST_CHECK_EQUAL(extractedParameters.getCost(), parameters.getCost()); |
| 197 | } |
| 198 | |
| 199 | BOOST_FIXTURE_TEST_CASE(Unregister, AuthorizedRibManager) |
| 200 | { |
| 201 | ControlParameters addParameters; |
| 202 | addParameters |
| 203 | .setName("/hello") |
| 204 | .setFaceId(1) |
| 205 | .setCost(10) |
| 206 | .setFlags(0) |
| 207 | .setOrigin(128) |
| 208 | .setExpirationPeriod(ndn::time::milliseconds::max()); |
| 209 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 210 | receiveCommandInterest(REGISTER_COMMAND, addParameters); |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 211 | face->sentInterests.clear(); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 212 | |
| 213 | ControlParameters removeParameters; |
| 214 | removeParameters |
| 215 | .setName("/hello") |
| 216 | .setFaceId(1) |
| 217 | .setOrigin(128); |
| 218 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 219 | receiveCommandInterest(UNREGISTER_COMMAND, removeParameters); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 220 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 221 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 1); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 222 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 223 | Interest& request = face->sentInterests[0]; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 224 | |
| 225 | ControlParameters extractedParameters; |
| 226 | Name::Component verb; |
| 227 | extractParameters(request, verb, extractedParameters); |
| 228 | |
| 229 | BOOST_CHECK_EQUAL(verb, REMOVE_NEXTHOP_VERB); |
| 230 | BOOST_CHECK_EQUAL(extractedParameters.getName(), removeParameters.getName()); |
| 231 | BOOST_CHECK_EQUAL(extractedParameters.getFaceId(), removeParameters.getFaceId()); |
| 232 | } |
| 233 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 234 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 235 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, UnauthorizedRibManager) |
| 236 | { |
| 237 | ControlParameters parameters; |
| 238 | parameters |
| 239 | .setName("/hello") |
| 240 | .setFaceId(1) |
| 241 | .setCost(10) |
| 242 | .setFlags(0) |
| 243 | .setOrigin(128) |
| 244 | .setExpirationPeriod(ndn::time::milliseconds::max()); |
| 245 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 246 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 247 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 248 | receiveCommandInterest(REGISTER_COMMAND, parameters); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 249 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 250 | BOOST_REQUIRE_EQUAL(face->sentInterests.size(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 253 | BOOST_FIXTURE_TEST_CASE(RibStatusRequest, AuthorizedRibManager) |
| 254 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 255 | Name prefix("/"); |
| 256 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 257 | Route route; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 258 | route.faceId = 1; |
| 259 | route.origin = 128; |
| 260 | route.cost = 32; |
| 261 | route.flags = ndn::nfd::ROUTE_FLAG_CAPTURE; |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 262 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 263 | manager->m_managedRib.insert(prefix, route); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 264 | |
| 265 | face->receive(Interest("/localhost/nfd/rib/list")); |
| 266 | face->processEvents(time::milliseconds(1)); |
| 267 | |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 268 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 269 | RibStatusPublisherFixture::decodeRibEntryBlock(face->sentDatas[0], prefix, route); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 272 | BOOST_FIXTURE_TEST_CASE(CancelExpirationEvent, AuthorizedRibManager) |
| 273 | { |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 274 | // Register route |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 275 | ControlParameters addParameters; |
| 276 | addParameters |
| 277 | .setName("/expire") |
| 278 | .setFaceId(1) |
| 279 | .setCost(10) |
| 280 | .setFlags(0) |
| 281 | .setOrigin(128) |
| 282 | .setExpirationPeriod(ndn::time::milliseconds(500)); |
| 283 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 284 | receiveCommandInterest(REGISTER_COMMAND, addParameters); |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 285 | face->sentInterests.clear(); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 286 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 287 | // Unregister route |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 288 | ControlParameters removeParameters; |
| 289 | removeParameters |
| 290 | .setName("/expire") |
| 291 | .setFaceId(1) |
| 292 | .setOrigin(128); |
| 293 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 294 | receiveCommandInterest(UNREGISTER_COMMAND, removeParameters); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 295 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 296 | // Reregister route |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 297 | addParameters.setExpirationPeriod(ndn::time::milliseconds::max()); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 298 | receiveCommandInterest(REGISTER_COMMAND, addParameters); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 299 | |
| 300 | nfd::tests::LimitedIo limitedIo; |
| 301 | limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1)); |
| 302 | |
| 303 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1); |
| 304 | } |
| 305 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 306 | BOOST_FIXTURE_TEST_CASE(RemoveInvalidFaces, AuthorizedRibManager) |
| 307 | { |
| 308 | // Register valid face |
| 309 | ControlParameters validParameters; |
| 310 | validParameters |
| 311 | .setName("/test") |
| 312 | .setFaceId(1); |
| 313 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 314 | receiveCommandInterest(REGISTER_COMMAND, validParameters); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 315 | |
| 316 | // Register invalid face |
| 317 | ControlParameters invalidParameters; |
| 318 | invalidParameters |
| 319 | .setName("/test") |
| 320 | .setFaceId(2); |
| 321 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 322 | receiveCommandInterest(REGISTER_COMMAND, invalidParameters); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 323 | |
| 324 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 2); |
| 325 | |
| 326 | // Receive status with only faceId: 1 |
| 327 | ndn::nfd::FaceStatus status; |
| 328 | status.setFaceId(1); |
| 329 | |
| 330 | shared_ptr<Data> data = nfd::tests::makeData("/localhost/nfd/faces/list"); |
| 331 | data->setContent(status.wireEncode()); |
| 332 | |
| 333 | shared_ptr<ndn::OBufferStream> buffer = make_shared<ndn::OBufferStream>(); |
| 334 | buffer->write(reinterpret_cast<const char*>(data->getContent().value()), |
| 335 | data->getContent().value_size()); |
| 336 | |
| 337 | manager->removeInvalidFaces(buffer); |
| 338 | |
| 339 | // Run scheduler |
| 340 | nfd::tests::LimitedIo limitedIo; |
| 341 | limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1)); |
| 342 | |
| 343 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1); |
| 344 | |
| 345 | Rib::const_iterator it = manager->m_managedRib.find("/test"); |
| 346 | BOOST_REQUIRE(it != manager->m_managedRib.end()); |
| 347 | |
| 348 | shared_ptr<RibEntry> entry = it->second; |
| 349 | BOOST_CHECK_EQUAL(entry->hasFaceId(1), true); |
| 350 | BOOST_CHECK_EQUAL(entry->hasFaceId(2), false); |
| 351 | } |
| 352 | |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 353 | BOOST_FIXTURE_TEST_CASE(LocalHopInherit, AuthorizedRibManager) |
| 354 | { |
| 355 | using nfd::rib::RibManager; |
| 356 | |
| 357 | // Simulate NFD response |
| 358 | ControlParameters result; |
| 359 | result.setFaceId(261); |
| 360 | |
| 361 | manager->onNrdCommandPrefixAddNextHopSuccess(RibManager::REMOTE_COMMAND_PREFIX, result); |
| 362 | |
| 363 | // Register route that localhop prefix should inherit |
| 364 | ControlParameters parameters; |
| 365 | parameters |
| 366 | .setName("/localhop/nfd") |
| 367 | .setFaceId(262) |
| 368 | .setCost(25) |
| 369 | .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT); |
| 370 | |
| 371 | Name commandName("/localhost/nfd/rib/register"); |
| 372 | |
| 373 | receiveCommandInterest(commandName, parameters); |
| 374 | |
| 375 | // REMOTE_COMMAND_PREFIX should have its original route and the inherited route |
| 376 | auto it = manager->m_managedRib.find(RibManager::REMOTE_COMMAND_PREFIX); |
| 377 | |
| 378 | BOOST_REQUIRE(it != manager->m_managedRib.end()); |
| 379 | const RibEntry::RouteList& inheritedRoutes = (*(it->second)).getInheritedRoutes(); |
| 380 | |
| 381 | BOOST_CHECK_EQUAL(inheritedRoutes.size(), 1); |
| 382 | auto routeIt = inheritedRoutes.begin(); |
| 383 | |
| 384 | BOOST_CHECK_EQUAL(routeIt->faceId, 262); |
| 385 | BOOST_CHECK_EQUAL(routeIt->cost, 25); |
| 386 | } |
| 387 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 388 | BOOST_FIXTURE_TEST_CASE(RouteExpiration, AuthorizedRibManager) |
| 389 | { |
| 390 | // Register route |
| 391 | ControlParameters parameters; |
| 392 | parameters.setName("/expire") |
| 393 | .setExpirationPeriod(ndn::time::milliseconds(500)); |
| 394 | |
| 395 | receiveCommandInterest(REGISTER_COMMAND, parameters); |
| 396 | face->sentInterests.clear(); |
| 397 | |
| 398 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1); |
| 399 | |
| 400 | // Route should expire |
| 401 | nfd::tests::LimitedIo limitedIo; |
| 402 | limitedIo.run(nfd::tests::LimitedIo::UNLIMITED_OPS, time::seconds(1)); |
| 403 | |
| 404 | BOOST_CHECK_EQUAL(manager->m_managedRib.size(), 0); |
| 405 | } |
| 406 | |
| 407 | BOOST_FIXTURE_TEST_CASE(FaceDestroyEvent, AuthorizedRibManager) |
| 408 | { |
| 409 | uint64_t faceToDestroy = 128; |
| 410 | |
| 411 | // Register valid face |
| 412 | ControlParameters parameters; |
| 413 | parameters.setName("/test") |
| 414 | .setFaceId(faceToDestroy); |
| 415 | |
| 416 | receiveCommandInterest(REGISTER_COMMAND, parameters); |
| 417 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 1); |
| 418 | |
| 419 | // Don't respond with a success message from the FIB |
| 420 | manager->m_managedRib.m_onSendBatchFromQueue = nullptr; |
| 421 | |
| 422 | manager->onFaceDestroyedEvent(faceToDestroy); |
| 423 | BOOST_REQUIRE_EQUAL(manager->m_managedRib.size(), 0); |
| 424 | } |
| 425 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 426 | BOOST_AUTO_TEST_SUITE_END() |
| 427 | |
| 428 | } // namespace tests |
| 429 | } // namespace rib |
| 430 | } // namespace nfd |