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