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