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 | d51690a | 2019-11-11 22:51:06 -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/>. |
| 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" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 23 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 25 | #include "tests/io-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 26 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 27 | #include <ndn-cxx/name.hpp> |
| 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 | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 34 | class FullSyncFixture : public tests::IoFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 35 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 36 | protected: |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 37 | void |
| 38 | addNode(int id) |
| 39 | { |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 40 | BOOST_ASSERT(id >= 0 && id <= 3); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame^] | 41 | |
| 42 | faces[id] = std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true}); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 43 | userPrefixes[id] = Name("userPrefix" + to_string(id)); |
| 44 | nodes[id] = make_shared<FullProducer>(40, *faces[id], syncPrefix, userPrefixes[id], |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 45 | [] (const auto&) {}); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 48 | protected: |
| 49 | const Name syncPrefix = "/psync"; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 50 | shared_ptr<util::DummyClientFace> faces[4]; |
| 51 | Name userPrefixes[4]; |
| 52 | shared_ptr<FullProducer> nodes[4]; |
| 53 | }; |
| 54 | |
Ashlesh Gawande | 6a5157f | 2019-12-09 11:49:07 -0600 | [diff] [blame] | 55 | BOOST_FIXTURE_TEST_SUITE(TestFullSync, FullSyncFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 56 | |
| 57 | BOOST_AUTO_TEST_CASE(TwoNodesSimple) |
| 58 | { |
| 59 | addNode(0); |
| 60 | addNode(1); |
| 61 | |
| 62 | faces[0]->linkTo(*faces[1]); |
| 63 | advanceClocks(ndn::time::milliseconds(10)); |
| 64 | |
| 65 | nodes[0]->publishName(userPrefixes[0]); |
| 66 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 67 | |
| 68 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 69 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 70 | |
| 71 | nodes[1]->publishName(userPrefixes[1]); |
| 72 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 73 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), 1); |
| 74 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[1]).value_or(-1), 1); |
| 75 | |
| 76 | nodes[1]->publishName(userPrefixes[1]); |
| 77 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 78 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), 2); |
| 79 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[1]).value_or(-1), 2); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_CASE(TwoNodesForceSeqNo) |
| 83 | { |
| 84 | addNode(0); |
| 85 | addNode(1); |
| 86 | |
| 87 | faces[0]->linkTo(*faces[1]); |
| 88 | advanceClocks(ndn::time::milliseconds(10)); |
| 89 | |
| 90 | nodes[0]->publishName(userPrefixes[0], 3); |
| 91 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 92 | |
| 93 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(-1), 3); |
| 94 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 3); |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_CASE(TwoNodesWithMultipleUserNodes) |
| 98 | { |
| 99 | addNode(0); |
| 100 | addNode(1); |
| 101 | |
| 102 | faces[0]->linkTo(*faces[1]); |
| 103 | advanceClocks(ndn::time::milliseconds(10)); |
| 104 | |
| 105 | Name nodeZeroExtraUser("userPrefix0-1"); |
| 106 | Name nodeOneExtraUser("userPrefix1-1"); |
| 107 | |
| 108 | nodes[0]->addUserNode(nodeZeroExtraUser); |
| 109 | nodes[1]->addUserNode(nodeOneExtraUser); |
| 110 | |
| 111 | nodes[0]->publishName(userPrefixes[0]); |
| 112 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 113 | |
| 114 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 115 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 116 | |
| 117 | nodes[0]->publishName(nodeZeroExtraUser); |
| 118 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 119 | |
| 120 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(nodeZeroExtraUser).value_or(-1), 1); |
| 121 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(nodeZeroExtraUser).value_or(-1), 1); |
| 122 | |
| 123 | nodes[1]->publishName(nodeOneExtraUser); |
| 124 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 125 | |
| 126 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(nodeOneExtraUser).value_or(-1), 1); |
| 127 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(nodeOneExtraUser).value_or(-1), 1); |
| 128 | } |
| 129 | |
| 130 | BOOST_AUTO_TEST_CASE(MultipleNodes) |
| 131 | { |
| 132 | for (int i = 0; i < 4; i++) { |
| 133 | addNode(i); |
| 134 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 135 | for (int i = 0; i < 3; i++) { |
| 136 | faces[i]->linkTo(*faces[i + 1]); |
| 137 | } |
| 138 | |
| 139 | nodes[0]->publishName(userPrefixes[0]); |
| 140 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 141 | for (int i = 0; i < 4; i++) { |
| 142 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 143 | } |
| 144 | |
| 145 | nodes[1]->publishName(userPrefixes[1]); |
| 146 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 147 | for (int i = 0; i < 4; i++) { |
| 148 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[1]).value_or(-1), 1); |
| 149 | } |
| 150 | |
| 151 | nodes[1]->publishName(userPrefixes[1]); |
| 152 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 153 | for (int i = 0; i < 4; i++) { |
| 154 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[1]).value_or(-1), 2); |
| 155 | } |
| 156 | } |
| 157 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 158 | BOOST_AUTO_TEST_CASE(MultipleNodesSimultaneousPublish) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 159 | { |
| 160 | for (int i = 0; i < 4; i++) { |
| 161 | addNode(i); |
| 162 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 163 | for (int i = 0; i < 3; i++) { |
| 164 | faces[i]->linkTo(*faces[i + 1]); |
| 165 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 166 | for (int i = 0; i < 4; i++) { |
| 167 | nodes[i]->publishName(userPrefixes[i]); |
| 168 | } |
| 169 | |
| 170 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 171 | for (int i = 0; i < 4; i++) { |
| 172 | for (int j = 0; j < 4; j++) { |
| 173 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(-1), 1); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | for (int i = 0; i < 4; i++) { |
| 178 | nodes[i]->publishName(userPrefixes[i], 4); |
| 179 | } |
| 180 | |
| 181 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 182 | for (int i = 0; i < 4; i++) { |
| 183 | for (int j = 0; j < 4; j++) { |
| 184 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(-1), 4); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | BOOST_AUTO_TEST_CASE(NetworkPartition) |
| 190 | { |
| 191 | for (int i = 0; i < 4; i++) { |
| 192 | addNode(i); |
| 193 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 194 | for (int i = 0; i < 3; i++) { |
| 195 | faces[i]->linkTo(*faces[i + 1]); |
| 196 | } |
| 197 | |
| 198 | nodes[0]->publishName(userPrefixes[0]); |
| 199 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 200 | for (int i = 0; i < 4; i++) { |
| 201 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 202 | } |
| 203 | |
| 204 | for (int i = 0; i < 3; i++) { |
| 205 | faces[i]->unlink(); |
| 206 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 207 | faces[0]->linkTo(*faces[1]); |
| 208 | faces[2]->linkTo(*faces[3]); |
| 209 | |
| 210 | nodes[0]->publishName(userPrefixes[0]); |
| 211 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 212 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 2); |
| 213 | BOOST_CHECK_EQUAL(nodes[2]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 214 | BOOST_CHECK_EQUAL(nodes[3]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 215 | |
| 216 | nodes[1]->publishName(userPrefixes[1], 2); |
| 217 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 218 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), 2); |
| 219 | |
| 220 | nodes[2]->publishName(userPrefixes[2], 2); |
| 221 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 222 | BOOST_CHECK_EQUAL(nodes[3]->getSeqNo(userPrefixes[2]).value_or(-1), 2); |
| 223 | |
| 224 | nodes[3]->publishName(userPrefixes[3], 2); |
| 225 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 226 | BOOST_CHECK_EQUAL(nodes[2]->getSeqNo(userPrefixes[3]).value_or(-1), 2); |
| 227 | |
| 228 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[3]).value_or(-1), -1); |
| 229 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[3]).value_or(-1), -1); |
| 230 | |
| 231 | for (int i = 0; i < 3; i++) { |
| 232 | faces[i]->unlink(); |
| 233 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 234 | for (int i = 0; i < 3; i++) { |
| 235 | faces[i]->linkTo(*faces[i + 1]); |
| 236 | } |
| 237 | |
| 238 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 239 | for (int i = 0; i < 4; i++) { |
| 240 | for (int j = 0; j < 4; j++) { |
| 241 | BOOST_CHECK_EQUAL(nodes[i]->getSeqNo(userPrefixes[j]).value_or(-1), 2); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(IBFOverflow) |
| 247 | { |
| 248 | addNode(0); |
| 249 | addNode(1); |
| 250 | |
| 251 | faces[0]->linkTo(*faces[1]); |
| 252 | advanceClocks(ndn::time::milliseconds(10)); |
| 253 | |
| 254 | // 50 > 40 (expected number of entries in IBF) |
| 255 | for (int i = 0; i < 50; i++) { |
| 256 | nodes[0]->addUserNode(Name("userNode0-" + to_string(i))); |
| 257 | } |
| 258 | |
| 259 | for (int i = 0; i < 20; i++) { |
| 260 | // Suppose all sync data were lost for these: |
| 261 | nodes[0]->updateSeqNo(Name("userNode0-" + to_string(i)), 1); |
| 262 | } |
| 263 | nodes[0]->publishName(Name("userNode0-" + to_string(20))); |
| 264 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 265 | |
| 266 | for (int i = 0; i <= 20; i++) { |
| 267 | Name userPrefix("userNode0-" + to_string(i)); |
| 268 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefix).value_or(-1), 1); |
| 269 | } |
| 270 | |
| 271 | for (int i = 21; i < 49; i++) { |
| 272 | nodes[0]->updateSeqNo(Name("userNode0-" + to_string(i)), 1); |
| 273 | } |
| 274 | nodes[0]->publishName(Name("userNode0-49")); |
| 275 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 276 | |
| 277 | for (int i = 21; i < 49; i++) { |
| 278 | Name userPrefix("userNode0-" + to_string(i)); |
| 279 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefix).value_or(-1), 1); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureSimple) |
| 284 | { |
| 285 | addNode(0); |
| 286 | addNode(1); |
| 287 | |
| 288 | faces[0]->linkTo(*faces[1]); |
| 289 | advanceClocks(ndn::time::milliseconds(10)); |
| 290 | |
| 291 | // Lowest number that triggers a decode failure for IBF size of 40 |
| 292 | int totalUpdates = 47; |
| 293 | |
| 294 | for (int i = 0; i <= totalUpdates; i++) { |
| 295 | nodes[0]->addUserNode(Name("userNode0-" + to_string(i))); |
| 296 | if (i != totalUpdates) { |
| 297 | nodes[0]->updateSeqNo(Name("userNode0-" + to_string(i)), 1); |
| 298 | } |
| 299 | } |
| 300 | nodes[0]->publishName(Name("userNode0-" + to_string(totalUpdates))); |
| 301 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 302 | |
| 303 | // No mechanism to recover yet |
| 304 | for (int i = 0; i <= totalUpdates; i++) { |
| 305 | Name userPrefix("userNode0-" + to_string(i)); |
| 306 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefix).value_or(-1), 1); |
| 307 | } |
| 308 | |
| 309 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), -1); |
| 310 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), -1); |
| 311 | |
| 312 | nodes[1]->publishName(userPrefixes[1]); |
| 313 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 314 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), 1); |
| 315 | |
| 316 | nodes[0]->publishName(userPrefixes[0]); |
| 317 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 318 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 319 | } |
| 320 | |
| 321 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureSimpleSegmentedRecovery) |
| 322 | { |
| 323 | addNode(0); |
| 324 | addNode(1); |
Ashlesh Gawande | ec43b36 | 2018-08-01 15:15:01 -0500 | [diff] [blame] | 325 | faces[0]->linkTo(*faces[1]); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 326 | |
| 327 | advanceClocks(ndn::time::milliseconds(10)); |
| 328 | |
| 329 | // Lowest number that triggers a decode failure for IBF size of 40 |
| 330 | int totalUpdates = 270; |
| 331 | |
| 332 | for (int i = 0; i <= totalUpdates; i++) { |
| 333 | nodes[0]->addUserNode(Name("userNode0-" + to_string(i))); |
| 334 | if (i != totalUpdates) { |
| 335 | nodes[0]->updateSeqNo(Name("userNode0-" + to_string(i)), 1); |
| 336 | } |
| 337 | } |
| 338 | nodes[0]->publishName(Name("userNode0-" + to_string(totalUpdates))); |
| 339 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 340 | |
| 341 | // No mechanism to recover yet |
| 342 | for (int i = 0; i <= totalUpdates; i++) { |
| 343 | Name userPrefix("userNode0-" + to_string(i)); |
| 344 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefix).value_or(-1), 1); |
| 345 | } |
| 346 | |
| 347 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), -1); |
| 348 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), -1); |
| 349 | |
| 350 | nodes[1]->publishName(userPrefixes[1]); |
| 351 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 352 | BOOST_CHECK_EQUAL(nodes[0]->getSeqNo(userPrefixes[1]).value_or(-1), 1); |
| 353 | |
| 354 | nodes[0]->publishName(userPrefixes[0]); |
| 355 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 356 | BOOST_CHECK_EQUAL(nodes[1]->getSeqNo(userPrefixes[0]).value_or(-1), 1); |
| 357 | } |
| 358 | |
| 359 | BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureMultipleNodes) |
| 360 | { |
| 361 | for (int i = 0; i < 4; i++) { |
| 362 | addNode(i); |
| 363 | } |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 364 | for (int i = 0; i < 3; i++) { |
| 365 | faces[i]->linkTo(*faces[i + 1]); |
| 366 | } |
| 367 | |
| 368 | // Lowest number that triggers a decode failure for IBF size of 40 |
| 369 | int totalUpdates = 47; |
| 370 | |
| 371 | for (int i = 0; i <= totalUpdates; i++) { |
| 372 | nodes[0]->addUserNode(Name("userNode0-" + to_string(i))); |
| 373 | if (i != totalUpdates) { |
| 374 | nodes[0]->updateSeqNo(Name("userNode0-" + to_string(i)), 1); |
| 375 | } |
| 376 | } |
| 377 | nodes[0]->publishName(Name("userNode0-" + to_string(totalUpdates))); |
| 378 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 379 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 380 | for (int i = 0; i <= totalUpdates; i++) { |
| 381 | Name userPrefix("userNode0-" + to_string(i)); |
| 382 | for (int j = 0; j < 4; j++) { |
| 383 | BOOST_CHECK_EQUAL(nodes[j]->getSeqNo(userPrefix).value_or(-1), 1); |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 388 | BOOST_AUTO_TEST_CASE(DelayedSecondSegment) |
| 389 | { |
| 390 | addNode(0); |
| 391 | |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 392 | int i = 0; |
| 393 | State state; |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 394 | std::shared_ptr<Buffer> compressed; |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 395 | do { |
| 396 | Name prefixToPublish("userNode0-" + to_string(i++)); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 397 | nodes[0]->addUserNode(prefixToPublish); |
| 398 | nodes[0]->publishName(prefixToPublish); |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 399 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 400 | state.addContent(Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish])); |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 401 | |
| 402 | auto block = state.wireEncode(); |
| 403 | compressed = compress(nodes[0]->m_contentCompression, block.wire(), block.size()); |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 404 | } while (compressed->size() < (MAX_NDN_PACKET_SIZE >> 1)); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 405 | |
| 406 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 407 | |
| 408 | Name syncInterestName(syncPrefix); |
Ashlesh Gawande | e23b53b | 2020-02-16 13:47:38 -0800 | [diff] [blame] | 409 | IBLT iblt(40, nodes[0]->m_ibltCompression); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 410 | iblt.appendToName(syncInterestName); |
| 411 | |
| 412 | nodes[0]->onSyncInterest(syncPrefix, Interest(syncInterestName)); |
| 413 | |
| 414 | advanceClocks(ndn::time::milliseconds(10)); |
| 415 | |
| 416 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 2); |
| 417 | // Expire contents from segmentPublisher |
| 418 | advanceClocks(ndn::time::milliseconds(10), 100); |
| 419 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 0); |
| 420 | |
| 421 | // 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] | 422 | BOOST_REQUIRE(!faces[0]->sentData.empty()); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 423 | Name dataName = faces[0]->sentData.front().getName(); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 424 | Name interestName = dataName.getSubName(0, dataName.size() - 2); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 425 | interestName.appendSegment(1); |
| 426 | faces[0]->sentData.clear(); |
| 427 | |
| 428 | nodes[0]->onSyncInterest(syncPrefix, Interest(interestName)); |
| 429 | advanceClocks(ndn::time::milliseconds(10)); |
| 430 | |
| 431 | // Should have repopulated SegmentPublisher |
| 432 | BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 2); |
| 433 | // Should have received the second data segment this time |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 434 | BOOST_REQUIRE(!faces[0]->sentData.empty()); |
| 435 | BOOST_CHECK_EQUAL(faces[0]->sentData.front().getName().at(-1).toSegment(), 1); |
Ashlesh Gawande | 2e82df1 | 2018-12-08 21:42:29 -0600 | [diff] [blame] | 436 | } |
| 437 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 438 | BOOST_AUTO_TEST_SUITE_END() |
| 439 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 440 | } // namespace psync |