blob: c833181cb318b9fd6b814f688976f5309d061950 [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/>.
18 **/
19
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
Davide Pesavento5b3cf762020-04-03 16:20:04 -040023#include "tests/boost-test.hpp"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050024#include "tests/io-fixture.hpp"
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040025#include "tests/key-chain-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040026
Davide Pesavento5b3cf762020-04-03 16:20:04 -040027#include <ndn-cxx/util/dummy-client-face.hpp>
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050028
Davide Pesavento47eb6d92024-02-12 20:25:51 -050029namespace psync::tests {
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050030
Junxiao Shic5f5eb12023-08-11 08:05:23 +000031using ndn::Interest;
32using ndn::Name;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033
Davide Pesavento47eb6d92024-02-12 20:25:51 -050034class FullProducerFixture : public IoFixture, public KeyChainFixture
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050035{
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040036protected:
Junxiao Shic5f5eb12023-08-11 08:05:23 +000037 ndn::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040038};
39
40BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050041
42BOOST_AUTO_TEST_CASE(OnInterest)
43{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000044 Name syncPrefix("/psync");
45 FullProducer::Options opts;
46 opts.ibfCount = 40;
47 FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050048
49 Name syncInterestName(syncPrefix);
50 syncInterestName.append("malicious-IBF");
51
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040052 BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050053}
54
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040055BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070056{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000057 Name syncPrefix("/psync");
58 FullProducer::Options opts;
59 opts.ibfCount = 40;
60 opts.syncInterestLifetime = 8_s;
61 FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070062
Davide Pesaventof91d1df2020-11-25 14:50:41 -050063 advanceClocks(10_ms);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040064 m_face.sentInterests.clear();
Ashlesh Gawande584e1202019-05-19 16:15:33 -070065
66 // full sync sends the next one in interest lifetime / 2 +- jitter
Davide Pesaventof91d1df2020-11-25 14:50:41 -050067 advanceClocks(6_s);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040068 BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070069}
70
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060071BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
72{
Junxiao Shi69bcaef2023-12-27 02:29:59 +000073 Name syncPrefix("/psync");
74 FullProducer::Options opts;
75 opts.ibfCount = 40;
76 FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060077
Davide Pesaventof91d1df2020-11-25 14:50:41 -050078 Name syncInterestName(syncPrefix);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060079 node.m_iblt.appendToName(syncInterestName);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050080 Interest syncInterest(syncInterestName);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060081
Junxiao Shic5f5eb12023-08-11 08:05:23 +000082 auto badCompress = std::make_shared<const ndn::Buffer>(5);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050083 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060084
85 const uint8_t test[] = {'t', 'e', 's', 't'};
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040086 auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050087 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060088}
89
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050090BOOST_AUTO_TEST_SUITE_END()
91
Davide Pesavento47eb6d92024-02-12 20:25:51 -050092} // namespace psync::tests