blob: ba8260ccf6ed43bc4a4e0042dcc01ce981c8b306 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Junxiao Shic5f5eb12023-08-11 08:05:23 +00003 * Copyright (c) 2014-2023, 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
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029namespace psync {
30
Junxiao Shic5f5eb12023-08-11 08:05:23 +000031using ndn::Interest;
32using ndn::Name;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050033
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040034class FullProducerFixture : public tests::IoFixture, public tests::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{
44 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040045 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050046
47 Name syncInterestName(syncPrefix);
48 syncInterestName.append("malicious-IBF");
49
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040050 BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050051}
52
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040053BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070054{
55 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040056 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070057
Davide Pesaventof91d1df2020-11-25 14:50:41 -050058 advanceClocks(10_ms);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040059 m_face.sentInterests.clear();
Ashlesh Gawande584e1202019-05-19 16:15:33 -070060
61 // full sync sends the next one in interest lifetime / 2 +- jitter
Davide Pesaventof91d1df2020-11-25 14:50:41 -050062 advanceClocks(6_s);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040063 BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070064}
65
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060066BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
67{
68 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040069 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060070
Davide Pesaventof91d1df2020-11-25 14:50:41 -050071 Name syncInterestName(syncPrefix);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060072 node.m_iblt.appendToName(syncInterestName);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050073 Interest syncInterest(syncInterestName);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060074
Junxiao Shic5f5eb12023-08-11 08:05:23 +000075 auto badCompress = std::make_shared<const ndn::Buffer>(5);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050076 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060077
78 const uint8_t test[] = {'t', 'e', 's', 't'};
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040079 auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050080 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060081}
82
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050083BOOST_AUTO_TEST_SUITE_END()
84
Davide Pesavento5b3cf762020-04-03 16:20:04 -040085} // namespace psync