Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2023, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 5 | * This file is part of PSync. |
| 6 | * See AUTHORS.md for complete list of PSync authors and contributors. |
| 7 | * |
| 8 | * PSync is free software: you can redistribute it and/or modify it under the terms |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/full-producer.hpp" |
| 21 | #include "PSync/consumer.hpp" |
| 22 | #include "PSync/detail/state.hpp" |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 23 | #include "PSync/detail/util.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 24 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 25 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 26 | #include "tests/io-fixture.hpp" |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 27 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 28 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 29 | #include <array> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 30 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 31 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 32 | namespace psync { |
| 33 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 34 | using ndn::Interest; |
| 35 | using ndn::Name; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 36 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 37 | class FullSyncFixture : public tests::IoFixture, public tests::KeyChainFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 38 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 39 | protected: |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 40 | void |
| 41 | addNode(int id) |
| 42 | { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 43 | BOOST_ASSERT(id >= 0 && id < MAX_NODES); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 44 | userPrefixes[id] = "/userPrefix" + std::to_string(id); |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 45 | faces[id] = std::make_unique<ndn::DummyClientFace>(m_io, m_keyChain, |
| 46 | ndn::DummyClientFace::Options{true, true}); |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame^] | 47 | FullProducer::Options opts; |
| 48 | opts.ibfCount = 40; |
| 49 | nodes[id] = std::make_unique<FullProducer>(*faces[id], m_keyChain, syncPrefix, opts); |
| 50 | nodes[id]->addUserNode(userPrefixes[id]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 51 | } |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 52 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 53 | void |
| 54 | clearNodes() |
| 55 | { |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 56 | nodes = {}; |
| 57 | faces = {}; |
| 58 | userPrefixes = {}; |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @brief Return a user prefix in the form /userNode<id>-<i>. |
| 63 | * @param id update originator node index. |
| 64 | * @param i user prefix index. |
| 65 | */ |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 66 | static Name |
| 67 | makeSubPrefix(int id, int i) |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 68 | { |
| 69 | return "/userNode" + std::to_string(id) + "-" + std::to_string(i); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @brief Publish a batch of updates. |
| 74 | * @param id node index. |
| 75 | * @param min minimum user prefix index. |
| 76 | * @param min maximum user prefix index. |
| 77 | * @param seq update sequence number. |
| 78 | * @post nodes[id] has user nodes /userNode<id>-<i> āiā[min,max] , with sequence number |
| 79 | * set to @p seq ; only one sync Data may be sent after the last update. |
| 80 | */ |
| 81 | void |
| 82 | batchUpdate(int id, int min, int max, uint64_t seq) |
| 83 | { |
| 84 | FullProducer& node = *nodes.at(id); |
| 85 | for (int i = min; i <= max; i++) { |
| 86 | auto userPrefix = makeSubPrefix(id, i); |
| 87 | node.addUserNode(userPrefix); |
| 88 | if (i < max) { |
| 89 | node.updateSeqNo(userPrefix, seq); |
| 90 | } |
| 91 | else { |
| 92 | node.publishName(userPrefix, seq); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @brief Check sequence number on a batch of user prefixes. |
| 99 | * @param id node index where the check is performed. |
| 100 | * @param origin update originator node index for deriving user prefixes. |
| 101 | * @param min minimum user prefix index. |
| 102 | * @param max maximum user prefix index. |
| 103 | * @param seq expected sequence number. |
| 104 | */ |
| 105 | void |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 106 | batchCheck(int id, int origin, int min, int max, std::optional<uint64_t> seq) |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 107 | { |
| 108 | uint64_t expected = seq.value_or(NOT_EXIST); |
| 109 | FullProducer& node = *nodes.at(id); |
| 110 | for (int i = min; i <= max; i++) { |
| 111 | auto userPrefix = makeSubPrefix(origin, i); |
| 112 | BOOST_TEST_CONTEXT("node=" << id << " userPrefix=" << userPrefix) { |
| 113 | BOOST_CHECK_EQUAL(node.getSeqNo(userPrefix).value_or(NOT_EXIST), expected); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | struct IbfDecodeFailureCounts |
| 119 | { |
| 120 | size_t aboveThreshold = 0; |
| 121 | size_t belowThreshold = 0; |
| 122 | }; |
| 123 | |
| 124 | /** |
| 125 | * @brief Return the sum of IBF decode failure counters among created nodes. |
| 126 | */ |
| 127 | IbfDecodeFailureCounts |
| 128 | countIbfDecodeFailures() const |
| 129 | { |
| 130 | IbfDecodeFailureCounts result; |
| 131 | for (const auto& node : nodes) { |
| 132 | if (node == nullptr) { |
| 133 | continue; |
| 134 | } |
| 135 | result.aboveThreshold += node->nIbfDecodeFailuresAboveThreshold; |
| 136 | result.belowThreshold += node->nIbfDecodeFailuresBelowThreshold; |
| 137 | } |
| 138 | return result; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @brief Repeat a test function until there are IBF decode failures. |
| 143 | * @param minTotalUpdates minimum totalUpdates parameter. |
| 144 | * @param maxTotalUpdates maximum totalUpdates parameter. |
| 145 | * @param f test function. |
| 146 | * |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 147 | * This method searches for totalUpdates ā [minTotalUpdates,maxTotalUpdates] until |
| 148 | * there is at least one execution that caused an IBF decode failure above threshold. |
| 149 | * If such an execution never occurs within the range, the test case fails. |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 150 | * |
| 151 | * Current FullSync logic cannot reliably recover from an IBF decode failure below threshold. |
| 152 | * Hence, that condition is not tested. |
| 153 | */ |
| 154 | void |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 155 | searchIbfDecodeFailures(int minTotalUpdates, int maxTotalUpdates, |
| 156 | const std::function<void(int totalUpdates)>& f) |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 157 | { |
| 158 | bool hasAboveThreshold = false; |
| 159 | for (int totalUpdates = minTotalUpdates; totalUpdates <= maxTotalUpdates; ++totalUpdates) { |
| 160 | clearNodes(); |
| 161 | BOOST_TEST_CONTEXT("totalUpdates=" << totalUpdates) { |
| 162 | f(totalUpdates); |
| 163 | |
| 164 | auto cnt = countIbfDecodeFailures(); |
| 165 | BOOST_TEST_MESSAGE("aboveThreshold=" << cnt.aboveThreshold << " " |
| 166 | "belowThreshold=" << cnt.belowThreshold); |
| 167 | hasAboveThreshold = hasAboveThreshold || cnt.aboveThreshold > 0; |
| 168 | if (hasAboveThreshold) { |
| 169 | return; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | BOOST_TEST_FAIL("cannot find viable totalUpdates for IBF decode failures"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 176 | protected: |
| 177 | const Name syncPrefix = "/psync"; |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 178 | static constexpr int MAX_NODES = 4; |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 179 | std::array<Name, MAX_NODES> userPrefixes; |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 180 | std::array<std::unique_ptr<ndn::DummyClientFace>, MAX_NODES> faces; |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 181 | std::array<std::unique_ptr<FullProducer>, MAX_NODES> nodes; |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 182 | static constexpr uint64_t NOT_EXIST = std::numeric_limits<uint64_t>::max(); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 183 | }; |
| 184 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 185 | BOOST_FIXTURE_TEST_SUITE(TestFullSync, FullSyncFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 186 | |
| 187 | BOOST_AUTO_TEST_CASE(TwoNodesSimple) |
| 188 | { |
| 189 | addNode(0); |
| 190 | addNode(1); |
| 191 | |
| 192 | faces[0]->linkTo(*faces[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 193 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 194 | |
| 195 | nodes[0]->publishName(userPrefixes[0]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 196 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 197 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
| 199 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 200 | |
| 201 | nodes[1]->publishName(userPrefixes[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 202 | advanceClocks(10_ms, 100); |
| 203 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 1); |
| 204 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 205 | |
| 206 | nodes[1]->publishName(userPrefixes[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 207 | advanceClocks(10_ms, 100); |
| 208 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 2); |
| 209 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | BOOST_AUTO_TEST_CASE(TwoNodesForceSeqNo) |
| 213 | { |
| 214 | addNode(0); |
| 215 | addNode(1); |
| 216 | |
| 217 | faces[0]->linkTo(*faces[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 218 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 219 | |
| 220 | nodes[0]->publishName(userPrefixes[0], 3); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 221 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 222 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 223 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 3); |
| 224 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 3); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | BOOST_AUTO_TEST_CASE(TwoNodesWithMultipleUserNodes) |
| 228 | { |
| 229 | addNode(0); |
| 230 | addNode(1); |
| 231 | |
| 232 | faces[0]->linkTo(*faces[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 233 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 234 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 235 | Name nodeZeroExtraUser("/userPrefix0-1"); |
| 236 | Name nodeOneExtraUser("/userPrefix1-1"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 237 | |
| 238 | nodes[0]->addUserNode(nodeZeroExtraUser); |
| 239 | nodes[1]->addUserNode(nodeOneExtraUser); |
| 240 | |
| 241 | nodes[0]->publishName(userPrefixes[0]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 242 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 243 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 244 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
| 245 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 246 | |
| 247 | nodes[0]->publishName(nodeZeroExtraUser); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 248 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 249 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 250 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(nodeZeroExtraUser).value_or(NOT_EXIST), 1); |
| 251 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(nodeZeroExtraUser).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 252 | |
| 253 | nodes[1]->publishName(nodeOneExtraUser); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 254 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 255 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 256 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(nodeOneExtraUser).value_or(NOT_EXIST), 1); |
| 257 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(nodeOneExtraUser).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | BOOST_AUTO_TEST_CASE(MultipleNodes) |
| 261 | { |
| 262 | for (int i = 0; i < 4; i++) { |
| 263 | addNode(i); |
| 264 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 265 | for (int i = 0; i < 3; i++) { |
| 266 | faces[i]->linkTo(*faces[i + 1]); |
| 267 | } |
| 268 | |
| 269 | nodes[0]->publishName(userPrefixes[0]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 270 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 271 | for (int i = 0; i < 4; i++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 272 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | nodes[1]->publishName(userPrefixes[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 276 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 277 | for (int i = 0; i < 4; i++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | nodes[1]->publishName(userPrefixes[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 282 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 283 | for (int i = 0; i < 4; i++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 284 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 288 | BOOST_AUTO_TEST_CASE(MultipleNodesSimultaneousPublish) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 289 | { |
| 290 | for (int i = 0; i < 4; i++) { |
| 291 | addNode(i); |
| 292 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 293 | for (int i = 0; i < 3; i++) { |
| 294 | faces[i]->linkTo(*faces[i + 1]); |
| 295 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 296 | for (int i = 0; i < 4; i++) { |
| 297 | nodes[i]->publishName(userPrefixes[i]); |
| 298 | } |
| 299 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 300 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 301 | for (int i = 0; i < 4; i++) { |
| 302 | for (int j = 0; j < 4; j++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 303 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | for (int i = 0; i < 4; i++) { |
| 308 | nodes[i]->publishName(userPrefixes[i], 4); |
| 309 | } |
| 310 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 311 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 312 | for (int i = 0; i < 4; i++) { |
| 313 | for (int j = 0; j < 4; j++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(NOT_EXIST), 4); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | BOOST_AUTO_TEST_CASE(NetworkPartition) |
| 320 | { |
| 321 | for (int i = 0; i < 4; i++) { |
| 322 | addNode(i); |
| 323 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 324 | for (int i = 0; i < 3; i++) { |
| 325 | faces[i]->linkTo(*faces[i + 1]); |
| 326 | } |
| 327 | |
| 328 | nodes[0]->publishName(userPrefixes[0]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 329 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 330 | for (int i = 0; i < 4; i++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 331 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | for (int i = 0; i < 3; i++) { |
| 335 | faces[i]->unlink(); |
| 336 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 337 | faces[0]->linkTo(*faces[1]); |
| 338 | faces[2]->linkTo(*faces[3]); |
| 339 | |
| 340 | nodes[0]->publishName(userPrefixes[0]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 341 | advanceClocks(10_ms, 100); |
| 342 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 2); |
| 343 | BOOST_CHECK_EQUAL(nodes[2]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
| 344 | BOOST_CHECK_EQUAL(nodes[3]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 345 | |
| 346 | nodes[1]->publishName(userPrefixes[1], 2); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 347 | advanceClocks(10_ms, 100); |
| 348 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 349 | |
| 350 | nodes[2]->publishName(userPrefixes[2], 2); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 351 | advanceClocks(10_ms, 100); |
| 352 | BOOST_CHECK_EQUAL(nodes[3]->getSeqNo(userPrefixes[2]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 353 | |
| 354 | nodes[3]->publishName(userPrefixes[3], 2); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 355 | advanceClocks(10_ms, 100); |
| 356 | BOOST_CHECK_EQUAL(nodes[2]->getSeqNo(userPrefixes[3]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 357 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 358 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[3]).value_or(NOT_EXIST), NOT_EXIST); |
| 359 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[3]).value_or(NOT_EXIST), NOT_EXIST); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 360 | |
| 361 | for (int i = 0; i < 3; i++) { |
| 362 | faces[i]->unlink(); |
| 363 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 364 | for (int i = 0; i < 3; i++) { |
| 365 | faces[i]->linkTo(*faces[i + 1]); |
| 366 | } |
| 367 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 368 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 369 | for (int i = 0; i < 4; i++) { |
| 370 | for (int j = 0; j < 4; j++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(NOT_EXIST), 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | BOOST_AUTO_TEST_CASE(IBFOverflow) |
| 377 | { |
| 378 | addNode(0); |
| 379 | addNode(1); |
| 380 | |
| 381 | faces[0]->linkTo(*faces[1]); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 382 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 383 | |
| 384 | // 50 > 40 (expected number of entries in IBF) |
| 385 | for (int i = 0; i < 50; i++) { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 386 | nodes[0]->addUserNode(makeSubPrefix(0, i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 387 | } |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 388 | batchUpdate(0, 0, 20, 1); |
| 389 | advanceClocks(10_ms, 100); |
| 390 | batchCheck(1, 0, 0, 20, 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 391 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 392 | batchUpdate(0, 21, 49, 1); |
| 393 | advanceClocks(10_ms, 100); |
| 394 | batchCheck(1, 0, 21, 49, 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureSimple) |
| 398 | { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 399 | searchIbfDecodeFailures(46, 52, [this] (int totalUpdates) { |
| 400 | addNode(0); |
| 401 | addNode(1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 402 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 403 | faces[0]->linkTo(*faces[1]); |
| 404 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 405 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 406 | batchUpdate(0, 0, totalUpdates, 1); |
| 407 | advanceClocks(10_ms, 100); |
| 408 | batchCheck(1, 0, 0, totalUpdates, 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 409 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 410 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), NOT_EXIST); |
| 411 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), NOT_EXIST); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 412 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 413 | nodes[1]->publishName(userPrefixes[1]); |
| 414 | advanceClocks(10_ms, 100); |
| 415 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 416 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 417 | nodes[0]->publishName(userPrefixes[0]); |
| 418 | advanceClocks(10_ms, 100); |
| 419 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
| 420 | }); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureSimpleSegmentedRecovery) |
| 424 | { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 425 | searchIbfDecodeFailures(46, 52, [this] (int totalUpdates) { |
| 426 | addNode(0); |
| 427 | addNode(1); |
| 428 | faces[0]->linkTo(*faces[1]); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 429 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 430 | advanceClocks(10_ms); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 431 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 432 | batchUpdate(0, 0, totalUpdates, 1); |
| 433 | advanceClocks(10_ms, 100); |
| 434 | batchCheck(1, 0, 0, totalUpdates, 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 435 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), NOT_EXIST); |
| 437 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), NOT_EXIST); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 438 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 439 | nodes[1]->publishName(userPrefixes[1]); |
| 440 | advanceClocks(10_ms, 100); |
| 441 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(NOT_EXIST), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 442 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 443 | nodes[0]->publishName(userPrefixes[0]); |
| 444 | advanceClocks(10_ms, 100); |
| 445 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(NOT_EXIST), 1); |
| 446 | }); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureMultipleNodes) |
| 450 | { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 451 | searchIbfDecodeFailures(46, 52, [this] (int totalUpdates) { |
| 452 | for (int i = 0; i < 4; i++) { |
| 453 | addNode(i); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 454 | } |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 455 | for (int i = 0; i < 3; i++) { |
| 456 | faces[i]->linkTo(*faces[i + 1]); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 457 | } |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 458 | |
| 459 | batchUpdate(0, 0, totalUpdates, 1); |
| 460 | advanceClocks(10_ms, 100); |
| 461 | for (int i = 0; i < 4; i++) { |
| 462 | batchCheck(i, 0, 0, totalUpdates, 1); |
| 463 | } |
| 464 | }); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 465 | } |
| 466 | |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 467 | BOOST_AUTO_TEST_CASE(DelayedSecondSegment) |
| 468 | { |
| 469 | addNode(0); |
| 470 | |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 471 | int i = 0; |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 472 | detail::State state; |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 473 | std::shared_ptr<ndn::Buffer> compressed; |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 474 | do { |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 475 | auto prefixToPublish = makeSubPrefix(0, i++); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 476 | nodes[0]->addUserNode(prefixToPublish); |
| 477 | nodes[0]->publishName(prefixToPublish); |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 478 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 479 | state.addContent(Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish])); |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 480 | |
| 481 | auto block = state.wireEncode(); |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 482 | compressed = detail::compress(nodes[0]->m_contentCompression, block); |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 483 | } while (compressed->size() < (ndn::MAX_NDN_PACKET_SIZE >> 1)); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 484 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 485 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 486 | |
| 487 | Name syncInterestName(syncPrefix); |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 488 | detail::IBLT iblt(40, nodes[0]->m_ibltCompression); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 489 | iblt.appendToName(syncInterestName); |
| 490 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 491 | nodes[0]->onSyncInterest(syncPrefix, Interest(syncInterestName)); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 492 | |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 493 | advanceClocks(10_ms); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 494 | |
| 495 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 2); |
| 496 | // Expire contents from segmentPublisher |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 497 | advanceClocks(10_ms, 100); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 498 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 0); |
| 499 | |
| 500 | // Get data name from face and increase segment number to form next interest |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 501 | BOOST_REQUIRE(!faces[0]->sentData.empty()); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 502 | Name dataName = faces[0]->sentData.front().getName(); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 503 | Name interestName = dataName.getSubName(0, dataName.size() - 2); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 504 | interestName.appendSegment(1); |
| 505 | faces[0]->sentData.clear(); |
| 506 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame] | 507 | nodes[0]->onSyncInterest(syncPrefix, Interest(interestName)); |
Junxiao Shi | fadcde5 | 2022-02-28 00:38:45 +0000 | [diff] [blame] | 508 | advanceClocks(10_ms); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 509 | |
| 510 | // Should have repopulated SegmentPublisher |
| 511 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 2); |
| 512 | // Should have received the second data segment this time |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 513 | BOOST_REQUIRE(!faces[0]->sentData.empty()); |
| 514 | BOOST_CHECK_EQUAL(faces[0]->sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 515 | } |
| 516 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 517 | BOOST_AUTO_TEST_SUITE_END() |
| 518 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 519 | } // namespace psync |