Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [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. |
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 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 26 | #include "mgmt/rib-manager.hpp" |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 27 | |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 28 | #include "manager-common-fixture.hpp" |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 29 | #include "tests/daemon/rib/fib-updates-common.hpp" |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 30 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/lp/tags.hpp> |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/rib-entry.hpp> |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 34 | |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 35 | namespace nfd { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 36 | namespace tests { |
| 37 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 38 | struct ConfigurationStatus |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 39 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 40 | bool isLocalhostConfigured; |
| 41 | bool isLocalhopConfigured; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 44 | static ConfigSection |
| 45 | getValidatorConfigSection() |
| 46 | { |
| 47 | ConfigSection section; |
| 48 | section.put("trust-anchor.type", "any"); |
| 49 | return section; |
| 50 | } |
| 51 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 52 | class RibManagerFixture : public ManagerCommonFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 53 | { |
| 54 | public: |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 55 | RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib) |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 56 | : m_status(status) |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 57 | , m_nfdController(m_face, m_keyChain) |
| 58 | , m_fibUpdater(m_rib, m_nfdController) |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 59 | , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 60 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 61 | if (m_status.isLocalhostConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 62 | m_manager.applyLocalhostConfig(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 63 | } |
| 64 | if (m_status.isLocalhopConfigured) { |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 65 | m_manager.enableLocalhop(getValidatorConfigSection(), "test"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 66 | } |
Junxiao Shi | f4cfed1 | 2018-08-22 23:26:29 +0000 | [diff] [blame] | 67 | else { |
| 68 | m_manager.disableLocalhop(); |
| 69 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 70 | |
| 71 | registerWithNfd(); |
| 72 | |
| 73 | if (shouldClearRib) { |
| 74 | clearRib(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | void |
| 80 | registerWithNfd() |
| 81 | { |
| 82 | m_manager.registerWithNfd(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 83 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 84 | |
| 85 | auto replyFibAddCommand = [this] (const Interest& interest) { |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 86 | ControlParameters params(interest.getName().get(-5).blockFromValue()); |
Junxiao Shi | fde3f54 | 2016-07-10 19:54:53 +0000 | [diff] [blame] | 87 | BOOST_CHECK(params.getName() == "/localhost/nfd/rib" || params.getName() == "/localhop/nfd/rib"); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 88 | params.setFaceId(1).setCost(0); |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 89 | ControlResponse resp; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 90 | |
| 91 | resp.setCode(200).setBody(params.wireEncode()); |
| 92 | shared_ptr<Data> data = make_shared<Data>(interest.getName()); |
| 93 | data->setContent(resp.wireEncode()); |
| 94 | |
| 95 | m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); |
| 96 | |
Junxiao Shi | 221b6fe | 2016-07-14 18:21:56 +0000 | [diff] [blame] | 97 | m_face.getIoService().post([this, data] { m_face.receive(*data); }); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | Name commandPrefix("/localhost/nfd/fib/add-nexthop"); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 101 | for (const auto& command : m_face.sentInterests) { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 102 | if (commandPrefix.isPrefixOf(command.getName())) { |
| 103 | replyFibAddCommand(command); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 104 | advanceClocks(1_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | // clear commands and responses |
| 109 | m_responses.clear(); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 110 | m_face.sentInterests.clear(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 113 | void |
| 114 | clearRib() |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 115 | { |
| 116 | while (!m_rib.empty()) { |
Davide Pesavento | e94804b | 2016-09-19 17:23:21 +0000 | [diff] [blame] | 117 | m_rib.erase(m_rib.begin()->first, *m_rib.begin()->second->begin()); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | public: |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 122 | static ControlParameters |
| 123 | makeRegisterParameters(const Name& name, uint64_t faceId = 0, |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 124 | time::milliseconds expiry = time::milliseconds::max()) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 125 | { |
| 126 | return ControlParameters() |
| 127 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 128 | .setFaceId(faceId) |
| 129 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 130 | .setCost(10) |
| 131 | .setFlags(0) |
| 132 | .setExpirationPeriod(expiry); |
| 133 | } |
| 134 | |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 135 | static ControlParameters |
| 136 | makeUnregisterParameters(const Name& name, uint64_t faceId = 0) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 137 | { |
| 138 | return ControlParameters() |
| 139 | .setName(name) |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 140 | .setFaceId(faceId) |
| 141 | .setOrigin(ndn::nfd::ROUTE_ORIGIN_NLSR); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 144 | protected: |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 145 | ConfigurationStatus m_status; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 146 | |
Davide Pesavento | 9f8b10e | 2018-08-22 08:45:37 +0000 | [diff] [blame] | 147 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 148 | rib::Rib m_rib; |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 149 | rib::tests::MockFibUpdater m_fibUpdater; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 150 | RibManager m_manager; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 151 | }; |
| 152 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 153 | BOOST_AUTO_TEST_SUITE(Mgmt) |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 154 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 155 | |
| 156 | class AddTopPrefixFixture : public RibManagerFixture |
| 157 | { |
| 158 | public: |
| 159 | AddTopPrefixFixture() |
| 160 | : RibManagerFixture({true, true}, false) |
| 161 | { |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 162 | } |
| 163 | }; |
| 164 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 165 | BOOST_FIXTURE_TEST_CASE(AddTopPrefix, AddTopPrefixFixture) |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 166 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 167 | BOOST_CHECK_EQUAL(m_rib.size(), 2); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 168 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 169 | std::vector<Name> ribEntryNames; |
| 170 | for (auto&& entry : m_rib) { |
| 171 | ribEntryNames.push_back(entry.first); |
| 172 | } |
| 173 | BOOST_CHECK_EQUAL(ribEntryNames[0], "/localhop/nfd"); |
| 174 | BOOST_CHECK_EQUAL(ribEntryNames[1], "/localhost/nfd"); |
Steve DiBenedetto | cd4ee5f | 2014-12-08 16:09:11 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 177 | class UnauthorizedRibManagerFixture : public RibManagerFixture |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 178 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 179 | public: |
| 180 | UnauthorizedRibManagerFixture() |
| 181 | : RibManagerFixture({false, false}, true) |
| 182 | { |
| 183 | } |
| 184 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 185 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 186 | class LocalhostAuthorizedRibManagerFixture : public RibManagerFixture |
| 187 | { |
| 188 | public: |
| 189 | LocalhostAuthorizedRibManagerFixture() |
| 190 | : RibManagerFixture({true, false}, true) |
| 191 | { |
| 192 | } |
| 193 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 194 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 195 | class LocalhopAuthorizedRibManagerFixture : public RibManagerFixture |
| 196 | { |
| 197 | public: |
| 198 | LocalhopAuthorizedRibManagerFixture() |
| 199 | : RibManagerFixture({false, true}, true) |
| 200 | { |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | class AuthorizedRibManagerFixture : public RibManagerFixture |
| 205 | { |
| 206 | public: |
| 207 | AuthorizedRibManagerFixture() |
| 208 | : RibManagerFixture({true, true}, true) |
| 209 | { |
| 210 | } |
| 211 | }; |
| 212 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 213 | using AllFixtures = boost::mpl::vector< |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 214 | UnauthorizedRibManagerFixture, |
| 215 | LocalhostAuthorizedRibManagerFixture, |
| 216 | LocalhopAuthorizedRibManagerFixture, |
| 217 | AuthorizedRibManagerFixture |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 218 | >; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 219 | |
| 220 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(CommandAuthorization, T, AllFixtures, T) |
| 221 | { |
| 222 | auto parameters = this->makeRegisterParameters("/test-authorization", 9527); |
| 223 | auto commandHost = this->makeControlCommandRequest("/localhost/nfd/rib/register", parameters); |
| 224 | auto commandHop = this->makeControlCommandRequest("/localhop/nfd/rib/register", parameters); |
| 225 | auto successResp = this->makeResponse(200, "Success", parameters); |
| 226 | auto failureResp = ControlResponse(403, "authorization rejected"); |
| 227 | |
| 228 | BOOST_CHECK_EQUAL(this->m_responses.size(), 0); |
| 229 | this->receiveInterest(commandHost); |
| 230 | this->receiveInterest(commandHop); |
| 231 | |
| 232 | auto nExpectedResponses = this->m_status.isLocalhopConfigured ? 2 : 1; |
| 233 | auto expectedLocalhostResponse = this->m_status.isLocalhostConfigured ? successResp : failureResp; |
| 234 | auto expectedLocalhopResponse = this->m_status.isLocalhopConfigured ? successResp : failureResp; |
| 235 | |
| 236 | BOOST_REQUIRE_EQUAL(this->m_responses.size(), nExpectedResponses); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(this->checkResponse(0, commandHost.getName(), expectedLocalhostResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 238 | ManagerCommonFixture::CheckResponseResult::OK); |
| 239 | if (nExpectedResponses == 2) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 240 | BOOST_CHECK_EQUAL(this->checkResponse(1, commandHop.getName(), expectedLocalhopResponse), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 241 | ManagerCommonFixture::CheckResponseResult::OK); |
| 242 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 243 | } |
| 244 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 245 | BOOST_FIXTURE_TEST_SUITE(RegisterUnregister, LocalhostAuthorizedRibManagerFixture) |
| 246 | |
| 247 | BOOST_AUTO_TEST_CASE(Basic) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 248 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 249 | auto paramsRegister = makeRegisterParameters("/test-register-unregister", 9527); |
| 250 | auto paramsUnregister = makeUnregisterParameters("/test-register-unregister", 9527); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 251 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 252 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 253 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
| 254 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 255 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(1234)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 256 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 257 | receiveInterest(commandRegister); |
| 258 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 259 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 260 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 262 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 264 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 265 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 266 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 267 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 268 | rib::FibUpdate::createAddUpdate("/test-register-unregister", 9527, 10)); |
| 269 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 270 | rib::FibUpdate::createRemoveUpdate("/test-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 273 | BOOST_AUTO_TEST_CASE(SelfOperation) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 274 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 275 | auto paramsRegister = makeRegisterParameters("/test-self-register-unregister"); |
| 276 | auto paramsUnregister = makeUnregisterParameters("/test-self-register-unregister"); |
| 277 | BOOST_CHECK_EQUAL(paramsRegister.getFaceId(), 0); |
| 278 | BOOST_CHECK_EQUAL(paramsUnregister.getFaceId(), 0); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 279 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 280 | const uint64_t inFaceId = 9527; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 281 | auto commandRegister = makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister); |
| 282 | commandRegister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
| 283 | auto commandUnregister = makeControlCommandRequest("/localhost/nfd/rib/unregister", paramsUnregister); |
| 284 | commandUnregister.setTag(make_shared<lp::IncomingFaceIdTag>(inFaceId)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 285 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 286 | receiveInterest(commandRegister); |
| 287 | receiveInterest(commandUnregister); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 288 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 289 | paramsRegister.setFaceId(inFaceId); |
| 290 | paramsUnregister.setFaceId(inFaceId); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 291 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 292 | BOOST_REQUIRE_EQUAL(m_responses.size(), 2); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(checkResponse(0, commandRegister.getName(), makeResponse(200, "Success", paramsRegister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 294 | CheckResponseResult::OK); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL(checkResponse(1, commandUnregister.getName(), makeResponse(200, "Success", paramsUnregister)), |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 296 | CheckResponseResult::OK); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 297 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 298 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); |
| 299 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 300 | rib::FibUpdate::createAddUpdate("/test-self-register-unregister", 9527, 10)); |
| 301 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 302 | rib::FibUpdate::createRemoveUpdate("/test-self-register-unregister", 9527)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 303 | } |
| 304 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 305 | BOOST_AUTO_TEST_CASE(Expiration) |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 306 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 307 | auto paramsRegister = makeRegisterParameters("/test-expiry", 9527, 50_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 308 | auto paramsUnregister = makeRegisterParameters("/test-expiry", 9527); |
| 309 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 310 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 311 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 312 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 2); // the registered route has expired |
| 313 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 314 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
| 315 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.back(), |
| 316 | rib::FibUpdate::createRemoveUpdate("/test-expiry", 9527)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 317 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 318 | m_fibUpdater.updates.clear(); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 319 | paramsRegister.setExpirationPeriod(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 320 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", paramsRegister)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 321 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 322 | advanceClocks(55_ms); |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 323 | BOOST_REQUIRE_EQUAL(m_fibUpdater.updates.size(), 1); // the registered route is still active |
| 324 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.front(), |
| 325 | rib::FibUpdate::createAddUpdate("/test-expiry", 9527, 10)); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 328 | BOOST_AUTO_TEST_CASE(NameTooLong) |
| 329 | { |
| 330 | Name prefix; |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 331 | while (prefix.size() <= Fib::getMaxDepth()) { |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 332 | prefix.append("A"); |
| 333 | } |
| 334 | auto params = makeRegisterParameters(prefix, 2899); |
| 335 | auto command = makeControlCommandRequest("/localhost/nfd/rib/register", params); |
| 336 | receiveInterest(command); |
| 337 | |
| 338 | BOOST_REQUIRE_EQUAL(m_responses.size(), 1); |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(checkResponse(0, command.getName(), |
| 340 | ControlResponse(414, "Route prefix cannot exceed " + |
| 341 | to_string(Fib::getMaxDepth()) + " components")), |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 342 | CheckResponseResult::OK); |
| 343 | |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 344 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Junxiao Shi | 7530635 | 2018-02-01 21:59:44 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 347 | BOOST_AUTO_TEST_SUITE_END() // RegisterUnregister |
| 348 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 349 | BOOST_FIXTURE_TEST_CASE(RibDataset, UnauthorizedRibManagerFixture) |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 350 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 351 | uint64_t faceId = 0; |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 352 | auto generateRoute = [&faceId] () -> rib::Route { |
| 353 | rib::Route route; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 354 | route.faceId = ++faceId; |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 355 | route.cost = route.faceId * 10; |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 356 | route.expires = nullopt; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 357 | return route; |
| 358 | }; |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 359 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 360 | const size_t nEntries = 108; |
| 361 | std::set<Name> actualPrefixes; |
| 362 | for (size_t i = 0; i < nEntries; ++i) { |
| 363 | Name prefix = Name("/test-dataset").appendNumber(i); |
| 364 | actualPrefixes.insert(prefix); |
| 365 | m_rib.insert(prefix, generateRoute()); |
| 366 | if (i & 0x1) { |
| 367 | m_rib.insert(prefix, generateRoute()); |
| 368 | m_rib.insert(prefix, generateRoute()); |
| 369 | } |
| 370 | } |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 371 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 372 | receiveInterest(*makeInterest("/localhost/nfd/rib/list", true)); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 373 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 374 | Block content = concatenateResponses(); |
| 375 | content.parse(); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 376 | BOOST_REQUIRE_EQUAL(content.elements().size(), nEntries); |
| 377 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 378 | std::vector<ndn::nfd::RibEntry> receivedRecords, expectedRecords; |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 379 | for (size_t idx = 0; idx < nEntries; ++idx) { |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 380 | ndn::nfd::RibEntry decodedEntry(content.elements()[idx]); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 381 | receivedRecords.push_back(decodedEntry); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 382 | actualPrefixes.erase(decodedEntry.getName()); |
| 383 | |
| 384 | auto matchedEntryIt = m_rib.find(decodedEntry.getName()); |
| 385 | BOOST_REQUIRE(matchedEntryIt != m_rib.end()); |
| 386 | |
| 387 | auto matchedEntry = matchedEntryIt->second; |
| 388 | BOOST_REQUIRE(matchedEntry != nullptr); |
| 389 | |
Davide Pesavento | d2ea235 | 2017-03-12 20:38:09 -0400 | [diff] [blame] | 390 | expectedRecords.emplace_back(); |
| 391 | expectedRecords.back().setName(matchedEntry->getName()); |
| 392 | for (const auto& route : matchedEntry->getRoutes()) { |
| 393 | expectedRecords.back().addRoute(ndn::nfd::Route() |
| 394 | .setFaceId(route.faceId) |
| 395 | .setOrigin(route.origin) |
| 396 | .setCost(route.cost) |
| 397 | .setFlags(route.flags)); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 398 | } |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | BOOST_CHECK_EQUAL(actualPrefixes.size(), 0); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 402 | BOOST_CHECK_EQUAL_COLLECTIONS(receivedRecords.begin(), receivedRecords.end(), |
| 403 | expectedRecords.begin(), expectedRecords.end()); |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 404 | } |
| 405 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 406 | BOOST_FIXTURE_TEST_SUITE(FaceMonitor, LocalhostAuthorizedRibManagerFixture) |
| 407 | |
| 408 | BOOST_AUTO_TEST_CASE(FetchActiveFacesEvent) |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 409 | { |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 410 | BOOST_CHECK_EQUAL(m_fibUpdater.updates.size(), 0); |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 411 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 412 | advanceClocks(301_s); // RibManager::ACTIVE_FACE_FETCH_INTERVAL = 300s |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame^] | 413 | BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 2); |
| 414 | BOOST_CHECK_EQUAL(m_face.sentInterests[0].getName(), "/localhost/nfd/faces/events"); |
| 415 | BOOST_CHECK_EQUAL(m_face.sentInterests[1].getName(), "/localhost/nfd/faces/list"); |
Vince Lehman | cd16c83 | 2014-07-23 15:14:55 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 418 | BOOST_AUTO_TEST_CASE(RemoveInvalidFaces) |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 419 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 420 | auto parameters1 = makeRegisterParameters("/test-remove-invalid-faces-1"); |
| 421 | auto parameters2 = makeRegisterParameters("/test-remove-invalid-faces-2"); |
| 422 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(1))); |
| 423 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1.setFaceId(2))); |
| 424 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2.setFaceId(2))); |
| 425 | BOOST_REQUIRE_EQUAL(m_rib.size(), 3); |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 426 | |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 427 | ndn::nfd::FaceStatus status; |
| 428 | status.setFaceId(1); |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 429 | std::vector<ndn::nfd::FaceStatus> activeFaces; |
| 430 | activeFaces.push_back(status); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 431 | |
Weiwei Liu | 6e21cdb | 2016-09-29 15:16:23 -0700 | [diff] [blame] | 432 | m_manager.removeInvalidFaces(activeFaces); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 433 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 434 | BOOST_REQUIRE_EQUAL(m_rib.size(), 1); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 435 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 436 | auto it1 = m_rib.find("/test-remove-invalid-faces-1"); |
| 437 | auto it2 = m_rib.find("/test-remove-invalid-faces-2"); |
| 438 | BOOST_CHECK(it2 == m_rib.end()); |
| 439 | BOOST_REQUIRE(it1 != m_rib.end()); |
| 440 | BOOST_CHECK(it1->second->hasFaceId(1)); |
| 441 | BOOST_CHECK(!it1->second->hasFaceId(2)); |
Vince Lehman | 26b215c | 2014-08-17 15:00:41 -0500 | [diff] [blame] | 442 | } |
| 443 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 444 | BOOST_AUTO_TEST_CASE(OnNotification) |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 445 | { |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 446 | auto parameters1 = makeRegisterParameters("/test-face-event-notification-1", 1); |
| 447 | auto parameters2 = makeRegisterParameters("/test-face-event-notification-2", 1); |
| 448 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters1)); |
| 449 | receiveInterest(makeControlCommandRequest("/localhost/nfd/rib/register", parameters2)); |
| 450 | BOOST_REQUIRE_EQUAL(m_rib.size(), 2); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 451 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 452 | auto makeNotification = [] (ndn::nfd::FaceEventKind kind, uint64_t faceId) { |
| 453 | return ndn::nfd::FaceEventNotification().setKind(kind).setFaceId(faceId); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 454 | }; |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 455 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 456 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_DESTROYED, 1)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 457 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 458 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 459 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 460 | m_manager.onNotification(makeNotification(ndn::nfd::FaceEventKind::FACE_EVENT_CREATED, 2)); |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 461 | advanceClocks(100_ms); |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 462 | BOOST_CHECK_EQUAL(m_rib.size(), 0); |
Vince Lehman | 7c7d33a | 2015-01-20 17:40:26 -0600 | [diff] [blame] | 463 | } |
| 464 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 465 | BOOST_AUTO_TEST_SUITE_END() // FaceMonitor |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 466 | |
Yanbiao Li | cf0db02 | 2016-01-29 00:54:25 -0800 | [diff] [blame] | 467 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 468 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 469 | |
| 470 | } // namespace tests |
Vince Lehman | 72446ec | 2014-07-09 10:50:02 -0500 | [diff] [blame] | 471 | } // namespace nfd |