Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +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 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 26 | #include "mgmt/rib-manager.hpp" |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 27 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Davide Pesavento | 1d12d2f | 2019-03-22 12:44:14 -0400 | [diff] [blame] | 29 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 30 | #include "tests/daemon/global-io-fixture.hpp" |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 31 | #include "tests/daemon/rib/fib-updates-common.hpp" |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 32 | |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 33 | #include <ndn-cxx/security/transform/base64-encode.hpp> |
| 34 | #include <ndn-cxx/security/transform/buffer-source.hpp> |
| 35 | #include <ndn-cxx/security/transform/stream-sink.hpp> |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 36 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 37 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 38 | #include <boost/property_tree/info_parser.hpp> |
| 39 | |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 40 | namespace nfd { |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 41 | namespace tests { |
| 42 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 43 | using rib::Route; |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 44 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 45 | static ConfigSection |
| 46 | makeSection(const std::string& config) |
| 47 | { |
| 48 | std::istringstream inputStream(config); |
| 49 | ConfigSection section; |
| 50 | boost::property_tree::read_info(inputStream, section); |
| 51 | return section; |
| 52 | } |
| 53 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 54 | class RibManagerSlAnnounceFixture : public GlobalIoTimeFixture, public KeyChainFixture |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 55 | { |
| 56 | public: |
| 57 | using SlAnnounceResult = RibManager::SlAnnounceResult; |
| 58 | |
| 59 | RibManagerSlAnnounceFixture() |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 60 | : m_face(g_io, m_keyChain) |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 61 | , m_nfdController(m_face, m_keyChain) |
| 62 | , m_dispatcher(m_face, m_keyChain) |
| 63 | , m_fibUpdater(rib, m_nfdController) |
| 64 | , m_trustedSigner(m_keyChain.createIdentity("/trusted", ndn::RsaKeyParams())) |
| 65 | , m_untrustedSigner(m_keyChain.createIdentity("/untrusted", ndn::RsaKeyParams())) |
| 66 | { |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 67 | // Face, Controller, Dispatcher are irrelevant to SlAnnounce functions but required by |
| 68 | // RibManager construction, so they are private. RibManager is a pointer to avoid code style |
| 69 | // rule 1.4 violation. |
Davide Pesavento | 0a71dd3 | 2019-03-17 20:36:18 -0400 | [diff] [blame] | 70 | manager = make_unique<RibManager>(rib, m_face, m_keyChain, m_nfdController, m_dispatcher); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 71 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 72 | loadDefaultPaConfig(); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | template<typename ...T> |
| 76 | ndn::PrefixAnnouncement |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 77 | makeTrustedAnn(T&&... args) |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 78 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 79 | return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_trustedSigner); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | template<typename ...T> |
| 83 | ndn::PrefixAnnouncement |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 84 | makeUntrustedAnn(T&&... args) |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 85 | { |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 86 | return signPrefixAnn(makePrefixAnn(std::forward<T>(args)...), m_keyChain, m_untrustedSigner); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** \brief Invoke manager->slAnnounce and wait for result. |
| 90 | */ |
| 91 | SlAnnounceResult |
| 92 | slAnnounceSync(const ndn::PrefixAnnouncement& pa, uint64_t faceId, time::milliseconds maxLifetime) |
| 93 | { |
| 94 | optional<SlAnnounceResult> result; |
| 95 | manager->slAnnounce(pa, faceId, maxLifetime, |
| 96 | [&] (RibManager::SlAnnounceResult res) { |
| 97 | BOOST_CHECK(!result); |
| 98 | result = res; |
| 99 | }); |
| 100 | |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 101 | g_io.poll(); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 102 | BOOST_CHECK(result); |
| 103 | return result.value_or(SlAnnounceResult::ERROR); |
| 104 | } |
| 105 | |
| 106 | /** \brief Invoke manager->slRenew and wait for result. |
| 107 | */ |
| 108 | SlAnnounceResult |
| 109 | slRenewSync(const Name& name, uint64_t faceId, time::milliseconds maxLifetime) |
| 110 | { |
| 111 | optional<SlAnnounceResult> result; |
| 112 | manager->slRenew(name, faceId, maxLifetime, |
| 113 | [&] (RibManager::SlAnnounceResult res) { |
| 114 | BOOST_CHECK(!result); |
| 115 | result = res; |
| 116 | }); |
| 117 | |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 118 | g_io.poll(); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 119 | BOOST_CHECK(result); |
| 120 | return result.value_or(SlAnnounceResult::ERROR); |
| 121 | } |
| 122 | |
| 123 | /** \brief Invoke manager->slFindAnn and wait for result. |
| 124 | */ |
| 125 | optional<ndn::PrefixAnnouncement> |
| 126 | slFindAnnSync(const Name& name) |
| 127 | { |
| 128 | optional<optional<ndn::PrefixAnnouncement>> result; |
| 129 | manager->slFindAnn(name, |
| 130 | [&] (optional<ndn::PrefixAnnouncement> found) { |
| 131 | BOOST_CHECK(!result); |
| 132 | result = found; |
| 133 | }); |
| 134 | |
Davide Pesavento | e1bdc08 | 2018-10-11 21:20:23 -0400 | [diff] [blame] | 135 | g_io.poll(); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 136 | BOOST_CHECK(result); |
| 137 | return result.value_or(nullopt); |
| 138 | } |
| 139 | |
| 140 | /** \brief Lookup a route with PREFIXANN origin. |
| 141 | */ |
| 142 | Route* |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 143 | findAnnRoute(const Name& name, uint64_t faceId) const |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 144 | { |
| 145 | Route routeQuery; |
| 146 | routeQuery.faceId = faceId; |
| 147 | routeQuery.origin = ndn::nfd::ROUTE_ORIGIN_PREFIXANN; |
| 148 | return rib.find(name, routeQuery); |
| 149 | } |
| 150 | |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 151 | /** \brief Retrieve an identity certificate as a base64 string. |
| 152 | */ |
| 153 | std::string |
| 154 | getIdentityCertificateBase64(const Name& identity) const |
| 155 | { |
| 156 | auto cert = m_keyChain.getPib().getIdentity(identity).getDefaultKey().getDefaultCertificate(); |
| 157 | const auto& block = cert.wireEncode(); |
| 158 | |
| 159 | namespace tr = ndn::security::transform; |
| 160 | std::ostringstream oss; |
| 161 | tr::bufferSource(block.wire(), block.size()) >> tr::base64Encode(false) >> tr::streamSink(oss); |
| 162 | |
| 163 | return oss.str(); |
| 164 | } |
| 165 | |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 166 | private: |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 167 | void |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 168 | loadDefaultPaConfig() |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 169 | { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 170 | const std::string CONFIG = R"CONFIG( |
| 171 | trust-anchor |
| 172 | { |
| 173 | type any |
| 174 | } |
| 175 | )CONFIG"; |
| 176 | manager->applyPaConfig(makeSection(CONFIG), "default"); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Davide Pesavento | 2135375 | 2020-11-20 00:43:44 -0500 | [diff] [blame] | 179 | protected: |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 180 | rib::Rib rib; |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 181 | unique_ptr<RibManager> manager; |
| 182 | |
| 183 | private: |
| 184 | ndn::util::DummyClientFace m_face; |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 185 | ndn::nfd::Controller m_nfdController; |
Davide Pesavento | 78ddcab | 2019-02-28 22:00:03 -0500 | [diff] [blame] | 186 | Dispatcher m_dispatcher; |
Junxiao Shi | df1dc65 | 2019-08-30 19:03:19 +0000 | [diff] [blame] | 187 | rib::tests::MockFibUpdater m_fibUpdater; |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 188 | |
| 189 | ndn::security::SigningInfo m_trustedSigner; |
| 190 | ndn::security::SigningInfo m_untrustedSigner; |
| 191 | }; |
| 192 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 193 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 194 | BOOST_AUTO_TEST_SUITE(TestRibManager) |
| 195 | BOOST_FIXTURE_TEST_SUITE(SlAnnounce, RibManagerSlAnnounceFixture) |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 196 | |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(AnnounceWithDefaultConfig) |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 198 | { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 199 | auto pa = makeTrustedAnn("/fMXN7UeB", 1_h); |
| 200 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3275, 1_h), SlAnnounceResult::OK); |
| 201 | BOOST_CHECK(findAnnRoute("/fMXN7UeB", 3275) != nullptr); |
| 202 | |
| 203 | auto pa2 = makeUntrustedAnn("/1nzAe0Y4", 1_h); |
| 204 | BOOST_CHECK_EQUAL(slAnnounceSync(pa2, 2959, 1_h), SlAnnounceResult::OK); |
| 205 | BOOST_CHECK(findAnnRoute("/1nzAe0Y4", 2959) != nullptr); |
| 206 | } |
| 207 | |
| 208 | BOOST_AUTO_TEST_CASE(AnnounceWithEmptyConfig) |
| 209 | { |
| 210 | manager->applyPaConfig(makeSection(""), "empty"); |
| 211 | |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 212 | auto pa = makeTrustedAnn("/fMXN7UeB", 1_h); |
| 213 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3275, 1_h), SlAnnounceResult::VALIDATION_FAILURE); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 214 | BOOST_CHECK(findAnnRoute("/fMXN7UeB", 3275) == nullptr); |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 215 | |
| 216 | auto pa2 = makeUntrustedAnn("/1nzAe0Y4", 1_h); |
| 217 | BOOST_CHECK_EQUAL(slAnnounceSync(pa2, 2959, 1_h), SlAnnounceResult::VALIDATION_FAILURE); |
| 218 | BOOST_CHECK(findAnnRoute("/1nzAe0Y4", 2959) == nullptr); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | BOOST_AUTO_TEST_CASE(AnnounceValidationError) |
| 222 | { |
Teng Liang | 18c2b29 | 2019-10-18 14:31:04 -0700 | [diff] [blame] | 223 | ConfigSection section; |
| 224 | section.put("rule.id", "PA"); |
| 225 | section.put("rule.for", "data"); |
| 226 | section.put("rule.checker.type", "customized"); |
| 227 | section.put("rule.checker.sig-type", "rsa-sha256"); |
| 228 | section.put("rule.checker.key-locator.type", "name"); |
| 229 | section.put("rule.checker.key-locator.name", "/trusted"); |
| 230 | section.put("rule.checker.key-locator.relation", "is-prefix-of"); |
| 231 | section.put("trust-anchor.type", "base64"); |
| 232 | section.put("trust-anchor.base64-string", getIdentityCertificateBase64("/trusted")); |
| 233 | manager->applyPaConfig(section, "trust-schema.section"); |
| 234 | |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 235 | auto pa = makeUntrustedAnn("/1nzAe0Y4", 1_h); |
| 236 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2959, 1_h), SlAnnounceResult::VALIDATION_FAILURE); |
| 237 | |
| 238 | BOOST_CHECK(findAnnRoute("/1nzAe0Y4", 2959) == nullptr); |
| 239 | } |
| 240 | |
| 241 | BOOST_AUTO_TEST_CASE(AnnounceInsert_AnnLifetime) |
| 242 | { |
| 243 | auto pa = makeTrustedAnn("/EHJYmJz9", 1_h); |
| 244 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1641, 2_h), SlAnnounceResult::OK); |
| 245 | |
| 246 | Route* route = findAnnRoute("/EHJYmJz9", 1641); |
| 247 | BOOST_REQUIRE(route != nullptr); |
| 248 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 1_h); |
| 249 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h); |
| 250 | } |
| 251 | |
| 252 | BOOST_AUTO_TEST_CASE(AnnounceInsert_ArgLifetime) |
| 253 | { |
| 254 | auto pa = makeTrustedAnn("/BU9Fec9E", 2_h); |
| 255 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1282, 1_h), SlAnnounceResult::OK); |
| 256 | |
| 257 | Route* route = findAnnRoute("/BU9Fec9E", 1282); |
| 258 | BOOST_REQUIRE(route != nullptr); |
| 259 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 2_h); |
| 260 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h); |
| 261 | } |
| 262 | |
| 263 | BOOST_AUTO_TEST_CASE(AnnounceReplace) |
| 264 | { |
| 265 | auto pa = makeTrustedAnn("/HsBFGvL3", 1_h); |
| 266 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2813, 1_h), SlAnnounceResult::OK); |
| 267 | |
| 268 | pa = makeTrustedAnn("/HsBFGvL3", 2_h); |
| 269 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2813, 2_h), SlAnnounceResult::OK); |
| 270 | |
| 271 | Route* route = findAnnRoute("/HsBFGvL3", 2813); |
| 272 | BOOST_REQUIRE(route != nullptr); |
| 273 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 2_h); |
| 274 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 2_h); |
| 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(AnnounceExpired) |
| 278 | { |
| 279 | auto pa = makeTrustedAnn("/awrVv6V7", 1_h, std::make_pair(-3_h, -1_h)); |
| 280 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 9087, 1_h), SlAnnounceResult::EXPIRED); |
| 281 | |
| 282 | BOOST_CHECK(findAnnRoute("/awrVv6V7", 9087) == nullptr); |
| 283 | } |
| 284 | |
| 285 | BOOST_AUTO_TEST_CASE(RenewNotFound) |
| 286 | { |
| 287 | BOOST_CHECK_EQUAL(slRenewSync("IAYigN73", 1070, 1_h), SlAnnounceResult::NOT_FOUND); |
| 288 | |
| 289 | BOOST_CHECK(findAnnRoute("/IAYigN73", 1070) == nullptr); |
| 290 | } |
| 291 | |
| 292 | BOOST_AUTO_TEST_CASE(RenewProlong_ArgLifetime) |
| 293 | { |
| 294 | auto pa = makeTrustedAnn("/P2IYFqtr", 4_h); |
| 295 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 4506, 2_h), SlAnnounceResult::OK); |
| 296 | advanceClocks(1_h); // Route has 1_h remaining lifetime |
| 297 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(slRenewSync("/P2IYFqtr/2321", 4506, 2_h), SlAnnounceResult::OK); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 299 | |
| 300 | Route* route = findAnnRoute("/P2IYFqtr", 4506); |
| 301 | BOOST_REQUIRE(route != nullptr); |
| 302 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h); |
| 303 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 2_h); // set by slRenew |
| 304 | } |
| 305 | |
| 306 | BOOST_AUTO_TEST_CASE(RenewProlong_AnnLifetime) |
| 307 | { |
| 308 | auto pa = makeTrustedAnn("/be01Yiba", 4_h); |
| 309 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1589, 2_h), SlAnnounceResult::OK); |
| 310 | advanceClocks(1_h); // Route has 1_h remaining lifetime |
| 311 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 312 | BOOST_CHECK_EQUAL(slRenewSync("/be01Yiba/4324", 1589, 5_h), SlAnnounceResult::OK); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 313 | |
| 314 | Route* route = findAnnRoute("/be01Yiba", 1589); |
| 315 | BOOST_REQUIRE(route != nullptr); |
| 316 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h); |
| 317 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 3_h); // capped by annExpires |
| 318 | } |
| 319 | |
| 320 | BOOST_AUTO_TEST_CASE(RenewShorten) |
| 321 | { |
| 322 | auto pa = makeTrustedAnn("/5XCHYCAd", 4_h); |
| 323 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3851, 4_h), SlAnnounceResult::OK); |
| 324 | advanceClocks(1_h); // Route has 3_h remaining lifetime |
| 325 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(slRenewSync("/5XCHYCAd/98934", 3851, 1_h), SlAnnounceResult::OK); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 327 | |
| 328 | Route* route = findAnnRoute("/5XCHYCAd", 3851); |
| 329 | BOOST_REQUIRE(route != nullptr); |
| 330 | BOOST_CHECK_EQUAL(route->annExpires, time::steady_clock::now() + 3_h); |
| 331 | BOOST_CHECK_EQUAL(route->expires.value(), time::steady_clock::now() + 1_h); // set by slRenew |
| 332 | } |
| 333 | |
| 334 | BOOST_AUTO_TEST_CASE(RenewShorten_Zero) |
| 335 | { |
| 336 | auto pa = makeTrustedAnn("/cdQ7KPNw", 4_h); |
| 337 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 8031, 4_h), SlAnnounceResult::OK); |
| 338 | advanceClocks(1_h); // Route has 3_h remaining lifetime |
| 339 | |
Teng Liang | a4e6ec3 | 2018-10-21 09:25:00 -0700 | [diff] [blame] | 340 | BOOST_CHECK_EQUAL(slRenewSync("/cdQ7KPNw/8023", 8031, 0_s), SlAnnounceResult::EXPIRED); |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 341 | |
| 342 | BOOST_CHECK(findAnnRoute("/cdQ7KPNw", 8031) == nullptr); |
| 343 | } |
| 344 | |
| 345 | BOOST_AUTO_TEST_CASE(FindExisting) |
| 346 | { |
| 347 | auto pa = makeTrustedAnn("/JHugsjjr", 1_h); |
| 348 | BOOST_CHECK_EQUAL(slAnnounceSync(pa, 2363, 1_h), SlAnnounceResult::OK); |
| 349 | |
| 350 | auto found = slFindAnnSync("/JHugsjjr"); |
| 351 | BOOST_REQUIRE(found); |
| 352 | BOOST_CHECK_EQUAL(found->getAnnouncedName(), "/JHugsjjr"); |
| 353 | BOOST_CHECK(found->getData()); |
| 354 | |
| 355 | auto found2 = slFindAnnSync("/JHugsjjr/StvXhKR5"); |
| 356 | BOOST_CHECK(found == found2); |
| 357 | } |
| 358 | |
| 359 | BOOST_AUTO_TEST_CASE(FindNew) |
| 360 | { |
| 361 | Route route; |
| 362 | route.faceId = 1367; |
| 363 | route.origin = ndn::nfd::ROUTE_ORIGIN_APP; |
| 364 | rib.insert("/dLY1pRhR", route); |
| 365 | |
| 366 | auto pa = slFindAnnSync("/dLY1pRhR/3qNK9Ngn"); |
| 367 | BOOST_REQUIRE(pa); |
| 368 | BOOST_CHECK_EQUAL(pa->getAnnouncedName(), "/dLY1pRhR"); |
| 369 | } |
| 370 | |
| 371 | BOOST_AUTO_TEST_CASE(FindNone) |
| 372 | { |
| 373 | auto pa = slFindAnnSync("/2YNeYuV2"); |
| 374 | BOOST_CHECK(!pa); |
| 375 | } |
| 376 | |
Davide Pesavento | 8a05c7f | 2019-02-28 02:26:19 -0500 | [diff] [blame] | 377 | BOOST_AUTO_TEST_SUITE_END() // SlAnnounce |
| 378 | BOOST_AUTO_TEST_SUITE_END() // TestRibManager |
| 379 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 380 | |
| 381 | } // namespace tests |
Junxiao Shi | 5ba7dfc | 2018-09-26 14:24:05 +0000 | [diff] [blame] | 382 | } // namespace nfd |