blob: 1ea3119d7d21b05a8b80ad45c46b8584cbc0fa6e [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -04003 * Copyright (c) 2014-2022, 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 Pesavento5b3cf762020-04-03 16:20:04 -040025
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050026#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
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
31using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050032
33BOOST_AUTO_TEST_SUITE(TestFullProducer)
34
35BOOST_AUTO_TEST_CASE(Constructor)
36{
37 util::DummyClientFace face({true, true});
Davide Pesaventof91d1df2020-11-25 14:50:41 -050038 BOOST_CHECK_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050039}
40
41BOOST_AUTO_TEST_CASE(OnInterest)
42{
43 Name syncPrefix("/psync"), userNode("/testUser");
44 util::DummyClientFace face({true, true});
45
46 FullProducer node(40, face, syncPrefix, userNode, nullptr);
47
48 Name syncInterestName(syncPrefix);
49 syncInterestName.append("malicious-IBF");
50
Ashlesh Gawande40970d62018-11-01 11:24:17 -050051 BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050052}
53
Davide Pesaventof91d1df2020-11-25 14:50:41 -050054BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070055{
56 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventof91d1df2020-11-25 14:50:41 -050057 util::DummyClientFace face(m_io, {true, true});
Ashlesh Gawande584e1202019-05-19 16:15:33 -070058
Davide Pesaventof91d1df2020-11-25 14:50:41 -050059 FullProducer node(40, face, syncPrefix, userNode, nullptr, 8_s);
60 advanceClocks(10_ms);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070061 face.sentInterests.clear();
62
63 // full sync sends the next one in interest lifetime / 2 +- jitter
Davide Pesaventof91d1df2020-11-25 14:50:41 -050064 advanceClocks(6_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070065 BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
66}
67
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060068BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
69{
70 Name syncPrefix("/psync"), userNode("/testUser");
71 util::DummyClientFace face({true, true});
72
73 FullProducer node(40, face, syncPrefix, userNode, nullptr);
74
Davide Pesaventof91d1df2020-11-25 14:50:41 -050075 Name syncInterestName(syncPrefix);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060076 node.m_iblt.appendToName(syncInterestName);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050077 Interest syncInterest(syncInterestName);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060078
Davide Pesaventof91d1df2020-11-25 14:50:41 -050079 auto badCompress = std::make_shared<const Buffer>(5);
80 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060081
82 const uint8_t test[] = {'t', 'e', 's', 't'};
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040083 auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050084 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060085}
86
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050087BOOST_AUTO_TEST_SUITE_END()
88
Davide Pesavento5b3cf762020-04-03 16:20:04 -040089} // namespace psync