blob: bcb753a91fe1e5def6fce47339aeca1ea6602745 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47eb6d92024-02-12 20:25:51 -05003 * Copyright (c) 2014-2024, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
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 Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * 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 Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawanded83af522023-07-14 14:37:18 -050018 */
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050019
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/full-producer.hpp"
Davide Pesaventodb789562020-12-19 23:01:08 -050021#include "PSync/detail/util.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022
Ashlesh Gawanded83af522023-07-14 14:37:18 -050023
Davide Pesavento5b3cf762020-04-03 16:20:04 -040024#include "tests/boost-test.hpp"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050025#include "tests/io-fixture.hpp"
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040026#include "tests/key-chain-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040027
Davide Pesavento5b3cf762020-04-03 16:20:04 -040028#include <ndn-cxx/util/dummy-client-face.hpp>
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029
Davide Pesavento47eb6d92024-02-12 20:25:51 -050030namespace psync::tests {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050031
Junxiao Shic5f5eb12023-08-11 08:05:23 +000032using ndn::Interest;
33using ndn::Name;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050034
Davide Pesavento47eb6d92024-02-12 20:25:51 -050035class FullProducerFixture : public IoFixture, public KeyChainFixture
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050036{
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040037protected:
Junxiao Shic5f5eb12023-08-11 08:05:23 +000038 ndn::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040039};
40
41BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050042
43BOOST_AUTO_TEST_CASE(OnInterest)
44{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000045 Name syncPrefix("/psync");
46 FullProducer::Options opts;
47 opts.ibfCount = 40;
48 FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050049
50 Name syncInterestName(syncPrefix);
51 syncInterestName.append("malicious-IBF");
52
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040053 BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050054}
55
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040056BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070057{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000058 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 Gawande584e1202019-05-19 16:15:33 -070063
Davide Pesaventof91d1df2020-11-25 14:50:41 -050064 advanceClocks(10_ms);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040065 m_face.sentInterests.clear();
Ashlesh Gawande584e1202019-05-19 16:15:33 -070066
67 // full sync sends the next one in interest lifetime / 2 +- jitter
Davide Pesaventof91d1df2020-11-25 14:50:41 -050068 advanceClocks(6_s);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040069 BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070070}
71
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060072BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
73{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000074 Name syncPrefix("/psync");
75 FullProducer::Options opts;
76 opts.ibfCount = 40;
77 FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060078
Davide Pesaventof91d1df2020-11-25 14:50:41 -050079 Name syncInterestName(syncPrefix);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060080 node.m_iblt.appendToName(syncInterestName);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050081 Interest syncInterest(syncInterestName);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060082
Junxiao Shic5f5eb12023-08-11 08:05:23 +000083 auto badCompress = std::make_shared<const ndn::Buffer>(5);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050084 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060085
86 const uint8_t test[] = {'t', 'e', 's', 't'};
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040087 auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050088 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060089}
90
Ashlesh Gawanded83af522023-07-14 14:37:18 -050091BOOST_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 Gawande0b2897e2018-06-20 14:40:47 -0500139BOOST_AUTO_TEST_SUITE_END()
140
Davide Pesavento47eb6d92024-02-12 20:25:51 -0500141} // namespace psync::tests