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 | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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 | d83af52 | 2023-07-14 14:37:18 -0500 | [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/full-producer.hpp" |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 21 | #include "PSync/detail/util.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | |
Ashlesh Gawande | d83af52 | 2023-07-14 14:37:18 -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 | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 26 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 27 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 28 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 30 | namespace psync::tests { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 31 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 32 | using ndn::Interest; |
| 33 | using ndn::Name; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 34 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 35 | class FullProducerFixture : public IoFixture, public KeyChainFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 36 | { |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 37 | protected: |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 38 | ndn::DummyClientFace m_face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 42 | |
| 43 | BOOST_AUTO_TEST_CASE(OnInterest) |
| 44 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 45 | Name syncPrefix("/psync"); |
| 46 | FullProducer::Options opts; |
| 47 | opts.ibfCount = 40; |
| 48 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 49 | |
| 50 | Name syncInterestName(syncPrefix); |
| 51 | syncInterestName.append("malicious-IBF"); |
| 52 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 53 | BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 56 | BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 57 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 58 | Name syncPrefix("/psync"); |
| 59 | FullProducer::Options opts; |
| 60 | opts.ibfCount = 40; |
| 61 | opts.syncInterestLifetime = 8_s; |
| 62 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 63 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 64 | advanceClocks(10_ms); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 65 | m_face.sentInterests.clear(); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 66 | |
| 67 | // full sync sends the next one in interest lifetime / 2 +- jitter |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 68 | advanceClocks(6_s); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 72 | BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure) |
| 73 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 74 | Name syncPrefix("/psync"); |
| 75 | FullProducer::Options opts; |
| 76 | opts.ibfCount = 40; |
| 77 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 78 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 79 | Name syncInterestName(syncPrefix); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 80 | node.m_iblt.appendToName(syncInterestName); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 81 | Interest syncInterest(syncInterestName); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 82 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 83 | auto badCompress = std::make_shared<const ndn::Buffer>(5); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 84 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 85 | |
| 86 | const uint8_t test[] = {'t', 'e', 's', 't'}; |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 87 | auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 88 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 89 | } |
| 90 | |
Ashlesh Gawande | d83af52 | 2023-07-14 14:37:18 -0500 | [diff] [blame] | 91 | BOOST_AUTO_TEST_CASE(SatisfyPendingInterestsBehavior) |
| 92 | { |
| 93 | Name syncPrefix("/psync"); |
| 94 | FullProducer::Options opts; |
| 95 | opts.ibfCount = 6; |
| 96 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
| 97 | |
| 98 | Name syncInterestName(syncPrefix); |
| 99 | node.m_iblt.appendToName(syncInterestName); |
| 100 | syncInterestName.appendNumber(1); |
| 101 | Interest syncInterest(syncInterestName); |
| 102 | |
| 103 | node.addUserNode(syncPrefix); |
| 104 | |
| 105 | node.onSyncInterest(syncPrefix, syncInterest); |
| 106 | |
| 107 | BOOST_CHECK_EQUAL(node.m_pendingEntries.size(), 1); |
| 108 | |
| 109 | // Test whether data is still sent if IBF diff is greater than default threshhold. |
| 110 | auto prefix1 = Name("/test/alice").appendNumber(1); |
| 111 | uint32_t newHash1 = psync::detail::murmurHash3(42, prefix1); |
| 112 | node.m_iblt.insert(newHash1); |
| 113 | |
| 114 | auto prefix2 = Name("/test/bob").appendNumber(1); |
| 115 | uint32_t newHash2 = psync::detail::murmurHash3(42, prefix2); |
| 116 | node.m_iblt.insert(newHash2); |
| 117 | |
| 118 | auto prefix3 = Name("/test/carol").appendNumber(1); |
| 119 | uint32_t newHash3 = psync::detail::murmurHash3(42, prefix3); |
| 120 | node.m_iblt.insert(newHash3); |
| 121 | |
| 122 | auto prefix4 = Name("/test/david").appendNumber(1); |
| 123 | uint32_t newHash4 = psync::detail::murmurHash3(42, prefix4); |
| 124 | node.m_iblt.insert(newHash4); |
| 125 | |
| 126 | auto prefix5 = Name("/test/erin").appendNumber(1); |
| 127 | uint32_t newHash5 = psync::detail::murmurHash3(42, prefix5); |
| 128 | node.m_iblt.insert(newHash5); |
| 129 | |
| 130 | node.publishName(syncPrefix); |
| 131 | |
| 132 | advanceClocks(10_ms); |
| 133 | |
| 134 | BOOST_CHECK_EQUAL(m_face.sentData.size(), 1); |
| 135 | |
| 136 | BOOST_CHECK_EQUAL(node.m_pendingEntries.empty(), true); |
| 137 | } |
| 138 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 139 | BOOST_AUTO_TEST_SUITE_END() |
| 140 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 141 | } // namespace psync::tests |