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