Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [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/>. |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 18 | */ |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/partial-producer.hpp" |
| 21 | #include "PSync/consumer.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 23 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 24 | #include "tests/io-fixture.hpp" |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 25 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 26 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 27 | #include <array> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
| 29 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 30 | namespace psync { |
| 31 | |
| 32 | using namespace ndn; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 33 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 34 | class PartialSyncFixture : public tests::IoFixture, public tests::KeyChainFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 35 | { |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 36 | protected: |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 37 | PartialSyncFixture() |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 38 | { |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 39 | producer = std::make_unique<PartialProducer>(face, m_keyChain, 40, syncPrefix, userPrefix); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 40 | addUserNodes("testUser", 10); |
| 41 | } |
| 42 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 43 | ~PartialSyncFixture() override |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 44 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 45 | for (const auto& consumer : consumers) { |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 46 | if (consumer) { |
| 47 | consumer->stop(); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 52 | void |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 53 | addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 54 | { |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 55 | consumerFaces[id] = std::make_unique<util::DummyClientFace>(m_io, m_keyChain, |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 56 | util::DummyClientFace::Options{true, true}); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 57 | if (linkToProducer) { |
| 58 | face.linkTo(*consumerFaces[id]); |
| 59 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 60 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 61 | consumers[id] = std::make_unique<Consumer>(syncPrefix, *consumerFaces[id], |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 62 | [&, id] (const auto& availableSubs) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 63 | numHelloDataRcvd++; |
Ashlesh Gawande | deb73f8 | 2018-08-09 11:08:02 -0500 | [diff] [blame] | 64 | BOOST_CHECK(checkSubList(availableSubs)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 65 | |
| 66 | checkIBFUpdated(id); |
| 67 | |
| 68 | for (const auto& sub : subscribeTo) { |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 69 | auto it = availableSubs.find(sub); |
| 70 | consumers[id]->addSubscription(sub, it->second); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 71 | } |
| 72 | consumers[id]->sendSyncInterest(); |
| 73 | }, |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 74 | [&, id] (const auto& updates) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 75 | numSyncDataRcvd++; |
| 76 | |
| 77 | checkIBFUpdated(id); |
| 78 | |
| 79 | for (const auto& update : updates) { |
| 80 | BOOST_CHECK(consumers[id]->isSubscribed(update.prefix)); |
| 81 | BOOST_CHECK_EQUAL(oldSeqMap.at(update.prefix) + 1, update.lowSeq); |
| 82 | BOOST_CHECK_EQUAL(producer->m_prefixes.at(update.prefix), update.highSeq); |
| 83 | BOOST_CHECK_EQUAL(consumers[id]->getSeqNo(update.prefix).value(), update.highSeq); |
| 84 | } |
| 85 | }, 40, 0.001); |
| 86 | |
| 87 | advanceClocks(ndn::time::milliseconds(10)); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | checkIBFUpdated(int id) |
| 92 | { |
| 93 | Name emptyName; |
| 94 | producer->m_iblt.appendToName(emptyName); |
| 95 | BOOST_CHECK_EQUAL(consumers[id]->m_iblt, emptyName); |
| 96 | } |
| 97 | |
| 98 | bool |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 99 | checkSubList(const std::map<Name, uint64_t>& availableSubs) const |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 100 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 101 | for (const auto& prefix : producer->m_prefixes) { |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 102 | auto it = availableSubs.find(prefix.first); |
| 103 | if (it == availableSubs.end()) { |
Ashlesh Gawande | deb73f8 | 2018-08-09 11:08:02 -0500 | [diff] [blame] | 104 | return false; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | addUserNodes(const std::string& prefix, int numOfUserNodes) |
| 112 | { |
| 113 | // zeroth is added through constructor |
| 114 | for (int i = 1; i < numOfUserNodes; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 115 | producer->addUserNode(prefix + "-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | publishUpdateFor(const std::string& prefix) |
| 121 | { |
| 122 | oldSeqMap = producer->m_prefixes; |
| 123 | producer->publishName(prefix); |
| 124 | advanceClocks(ndn::time::milliseconds(10)); |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | updateSeqFor(const std::string& prefix, uint64_t seq) |
| 129 | { |
| 130 | oldSeqMap = producer->m_prefixes; |
| 131 | producer->updateSeqNo(prefix, seq); |
| 132 | } |
| 133 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 134 | protected: |
| 135 | util::DummyClientFace face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 136 | const Name syncPrefix{"psync"}; |
| 137 | const Name userPrefix{"testUser-0"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 138 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 139 | std::unique_ptr<PartialProducer> producer; |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 140 | std::map<Name, uint64_t> oldSeqMap; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 141 | |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 142 | std::array<std::unique_ptr<Consumer>, 3> consumers; |
| 143 | std::array<std::unique_ptr<util::DummyClientFace>, 3> consumerFaces; |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 144 | int numHelloDataRcvd = 0; |
| 145 | int numSyncDataRcvd = 0; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 146 | }; |
| 147 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 148 | BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 149 | |
| 150 | BOOST_AUTO_TEST_CASE(Simple) |
| 151 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 152 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 153 | addConsumer(0, subscribeTo); |
| 154 | |
| 155 | consumers[0]->sendHelloInterest(); |
| 156 | advanceClocks(ndn::time::milliseconds(10)); |
| 157 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 158 | |
| 159 | publishUpdateFor("testUser-2"); |
| 160 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 161 | publishUpdateFor("testUser-3"); |
| 162 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 163 | publishUpdateFor("testUser-2"); |
| 164 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 165 | } |
| 166 | |
| 167 | BOOST_AUTO_TEST_CASE(MissedUpdate) |
| 168 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 169 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 170 | addConsumer(0, subscribeTo); |
| 171 | |
| 172 | consumers[0]->sendHelloInterest(); |
| 173 | advanceClocks(ndn::time::milliseconds(10)); |
| 174 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 175 | |
| 176 | updateSeqFor("testUser-2", 3); |
| 177 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 178 | |
| 179 | // The sync interest sent after hello will timeout |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 180 | advanceClocks(ndn::time::milliseconds(999)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 182 | |
| 183 | // Next sync interest will bring back the sync data |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 184 | advanceClocks(ndn::time::milliseconds(1)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 185 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 186 | } |
| 187 | |
| 188 | BOOST_AUTO_TEST_CASE(LateSubscription) |
| 189 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 190 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 191 | addConsumer(0, subscribeTo); |
| 192 | |
| 193 | consumers[0]->sendHelloInterest(); |
| 194 | advanceClocks(ndn::time::milliseconds(10)); |
| 195 | |
| 196 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 197 | publishUpdateFor("testUser-2"); |
| 198 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 199 | |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 200 | consumers[0]->addSubscription("testUser-3", 0); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 201 | consumers[0]->sendSyncInterest(); |
| 202 | publishUpdateFor("testUser-3"); |
| 203 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 204 | } |
| 205 | |
| 206 | BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout) |
| 207 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 208 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 209 | addConsumer(0, subscribeTo); |
| 210 | |
| 211 | consumers[0]->sendHelloInterest(); |
| 212 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 0); |
| 213 | advanceClocks(ndn::time::milliseconds(10)); |
| 214 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1); |
| 215 | advanceClocks(ndn::time::milliseconds(10), 100); |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 216 | // The next Interest is sent after the first one immediately |
| 217 | BOOST_CHECK_EQUAL(producer->m_pendingEntries.size(), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 218 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 219 | |
| 220 | int numSyncInterests = 0; |
| 221 | for (const auto& interest : consumerFaces[0]->sentInterests) { |
| 222 | if (interest.getName().getSubName(0, 2) == Name("/psync/sync")) { |
| 223 | numSyncInterests++; |
| 224 | } |
| 225 | } |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(numSyncInterests, 3); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 228 | } |
| 229 | |
| 230 | BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList) |
| 231 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 232 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 233 | addConsumer(0, subscribeTo); |
| 234 | addConsumer(1, subscribeTo); |
| 235 | addConsumer(2, subscribeTo); |
| 236 | |
| 237 | consumers[0]->sendHelloInterest(); |
| 238 | consumers[1]->sendHelloInterest(); |
| 239 | consumers[2]->sendHelloInterest(); |
| 240 | advanceClocks(ndn::time::milliseconds(10)); |
| 241 | |
| 242 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 3); |
| 243 | |
| 244 | publishUpdateFor("testUser-2"); |
| 245 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
| 246 | |
| 247 | publishUpdateFor("testUser-3"); |
| 248 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
| 249 | } |
| 250 | |
| 251 | BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList) |
| 252 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 253 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 254 | addConsumer(0, subscribeTo); |
| 255 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 256 | std::vector<std::string> subscribeTo1{"testUser-1", "testUser-3", "testUser-5"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 257 | addConsumer(1, subscribeTo1); |
| 258 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 259 | std::vector<std::string> subscribeTo2{"testUser-2", "testUser-3"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 260 | addConsumer(2, subscribeTo2); |
| 261 | |
| 262 | consumers[0]->sendHelloInterest(); |
| 263 | consumers[1]->sendHelloInterest(); |
| 264 | consumers[2]->sendHelloInterest(); |
| 265 | advanceClocks(ndn::time::milliseconds(10)); |
| 266 | |
| 267 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 3); |
| 268 | |
| 269 | publishUpdateFor("testUser-2"); |
| 270 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 271 | |
| 272 | numSyncDataRcvd = 0; |
| 273 | publishUpdateFor("testUser-3"); |
| 274 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(ReplicatedProducer) |
| 278 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 279 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 280 | addConsumer(0, subscribeTo); |
| 281 | |
| 282 | consumers[0]->sendHelloInterest(); |
| 283 | advanceClocks(ndn::time::milliseconds(10)); |
| 284 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 285 | |
| 286 | publishUpdateFor("testUser-2"); |
| 287 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 288 | |
| 289 | // Link to first producer goes down |
| 290 | face.unlink(); |
| 291 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 292 | util::DummyClientFace face2(m_io, m_keyChain, {true, true}); |
| 293 | PartialProducer replicatedProducer(face2, m_keyChain, 40, syncPrefix, userPrefix); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 294 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | 03426ef | 2022-09-23 19:49:10 -0400 | [diff] [blame^] | 295 | replicatedProducer.addUserNode("testUser-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 296 | } |
| 297 | advanceClocks(ndn::time::milliseconds(10)); |
| 298 | replicatedProducer.publishName("testUser-2"); |
| 299 | // Link to a replicated producer comes up |
| 300 | face2.linkTo(*consumerFaces[0]); |
| 301 | |
| 302 | BOOST_CHECK_EQUAL(face2.sentData.size(), 0); |
| 303 | |
| 304 | // Update in first producer as well so consumer on sync data |
| 305 | // callback checks still pass |
| 306 | publishUpdateFor("testUser-2"); |
| 307 | replicatedProducer.publishName("testUser-2"); |
| 308 | advanceClocks(ndn::time::milliseconds(15), 100); |
| 309 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
| 310 | BOOST_CHECK_EQUAL(face2.sentData.size(), 1); |
| 311 | } |
| 312 | |
| 313 | BOOST_AUTO_TEST_CASE(ApplicationNack) |
| 314 | { |
| 315 | // 50 is more than expected number of entries of 40 in the producer's IBF |
| 316 | addUserNodes("testUser", 50); |
| 317 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 318 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 319 | addConsumer(0, subscribeTo); |
| 320 | |
| 321 | consumers[0]->sendHelloInterest(); |
| 322 | advanceClocks(ndn::time::milliseconds(10)); |
| 323 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 324 | |
| 325 | publishUpdateFor("testUser-2"); |
| 326 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 327 | |
| 328 | oldSeqMap = producer->m_prefixes; |
| 329 | for (int i = 0; i < 50; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 330 | Name prefix("testUser-" + std::to_string(i)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 331 | producer->updateSeqNo(prefix, producer->getSeqNo(prefix).value() + 1); |
| 332 | } |
| 333 | // Next sync interest should trigger the nack |
| 334 | advanceClocks(ndn::time::milliseconds(15), 100); |
| 335 | |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 336 | // Application should have been notified that new data is available |
| 337 | // from the hello itself. |
| 338 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 2); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 339 | |
| 340 | bool nackRcvd = false; |
| 341 | for (const auto& data : face.sentData) { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 342 | if (data.getContentType() == tlv::ContentType_Nack) { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 343 | nackRcvd = true; |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | BOOST_CHECK(nackRcvd); |
| 348 | |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 349 | publishUpdateFor("testUser-4"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 350 | advanceClocks(ndn::time::milliseconds(10)); |
Ashlesh Gawande | a929647 | 2018-08-04 08:21:39 -0500 | [diff] [blame] | 351 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 3); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 354 | BOOST_AUTO_TEST_CASE(SegmentedHello) |
| 355 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 356 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 357 | addConsumer(0, subscribeTo); |
| 358 | |
| 359 | addUserNodes("testUser", 400); |
| 360 | |
| 361 | consumers[0]->sendHelloInterest(); |
| 362 | advanceClocks(ndn::time::milliseconds(10)); |
| 363 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 364 | |
| 365 | // Simulate sending delayed interest for second segment |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 366 | BOOST_REQUIRE(!face.sentData.empty()); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 367 | Name dataName = face.sentData.back().getName(); |
| 368 | face.sentData.clear(); |
| 369 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
| 370 | |
| 371 | advanceClocks(ndn::time::milliseconds(1000)); |
| 372 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0); |
| 373 | |
| 374 | producer->onHelloInterest(consumers[0]->m_helloInterestPrefix, Interest(dataName)); |
| 375 | advanceClocks(ndn::time::milliseconds(10)); |
| 376 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 377 | BOOST_REQUIRE(!face.sentData.empty()); |
| 378 | BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | BOOST_AUTO_TEST_CASE(SegmentedSync) |
| 382 | { |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 383 | Name longNameToExceedDataSize; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 384 | for (int i = 0; i < 100; i++) { |
| 385 | longNameToExceedDataSize.append("test-" + std::to_string(i)); |
| 386 | } |
| 387 | addUserNodes(longNameToExceedDataSize.toUri(), 10); |
| 388 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 389 | std::vector<std::string> subscribeTo; |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 390 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 391 | subscribeTo.push_back(longNameToExceedDataSize.toUri() + "-" + std::to_string(i)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 392 | } |
| 393 | addConsumer(0, subscribeTo); |
| 394 | |
| 395 | consumers[0]->sendHelloInterest(); |
| 396 | advanceClocks(ndn::time::milliseconds(10)); |
| 397 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 398 | |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 399 | // To be used later to simulate sending delayed segmented interest |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 400 | Name syncInterestName(consumers[0]->m_syncInterestPrefix); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 401 | consumers[0]->m_bloomFilter.appendToName(syncInterestName); |
| 402 | syncInterestName.append(consumers[0]->m_iblt); |
| 403 | syncInterestName.appendVersion(); |
| 404 | syncInterestName.appendSegment(1); |
| 405 | |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 406 | oldSeqMap = producer->m_prefixes; |
| 407 | for (int i = 1; i < 10; i++) { |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 408 | producer->updateSeqNo(longNameToExceedDataSize.toUri() + "-" + std::to_string(i), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 409 | } |
| 410 | |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 411 | advanceClocks(ndn::time::milliseconds(999)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 0); |
| 413 | |
Ashlesh Gawande | 8ab7572 | 2020-08-02 22:42:28 -0700 | [diff] [blame] | 414 | advanceClocks(ndn::time::milliseconds(1)); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 416 | |
| 417 | // Simulate sending delayed interest for second segment |
| 418 | face.sentData.clear(); |
| 419 | consumerFaces[0]->sentData.clear(); |
| 420 | |
| 421 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
| 422 | |
| 423 | advanceClocks(ndn::time::milliseconds(2000)); |
| 424 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 0); |
| 425 | |
| 426 | producer->onSyncInterest(consumers[0]->m_syncInterestPrefix, Interest(syncInterestName)); |
| 427 | advanceClocks(ndn::time::milliseconds(10)); |
| 428 | BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 429 | BOOST_REQUIRE(!face.sentData.empty()); |
| 430 | BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 431 | } |
| 432 | |
Ashlesh Gawande | cbdc012 | 2020-07-13 21:13:00 -0700 | [diff] [blame] | 433 | BOOST_AUTO_TEST_CASE(DelayedSubscription) // #5122 |
| 434 | { |
| 435 | publishUpdateFor("testUser-2"); |
| 436 | std::vector<std::string> subscribeTo{"testUser-2", "testUser-4"}; |
| 437 | addConsumer(0, subscribeTo); |
| 438 | |
| 439 | consumers[0]->sendHelloInterest(); |
| 440 | advanceClocks(ndn::time::milliseconds(10)); |
| 441 | BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); |
| 442 | |
| 443 | // Application came up late and subscribed to testUser-2 |
| 444 | // after Producer had already published the first update. |
| 445 | // So by default Consumer will let the application know that |
| 446 | // the prefix it subscribed to has already some updates |
| 447 | BOOST_CHECK_EQUAL(numSyncDataRcvd, 1); |
| 448 | } |
| 449 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 450 | BOOST_AUTO_TEST_SUITE_END() |
| 451 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 452 | } // namespace psync |