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