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/>. |
| 18 | **/ |
| 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 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 23 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 24 | #include "tests/io-fixture.hpp" |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 25 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 26 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 28 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 29 | namespace psync::tests { |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 30 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 31 | using ndn::Interest; |
| 32 | using ndn::Name; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 33 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 34 | class FullProducerFixture : public IoFixture, public KeyChainFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 35 | { |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 36 | protected: |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 37 | ndn::DummyClientFace m_face{m_io, m_keyChain, {true, true}}; |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 41 | |
| 42 | BOOST_AUTO_TEST_CASE(OnInterest) |
| 43 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 44 | Name syncPrefix("/psync"); |
| 45 | FullProducer::Options opts; |
| 46 | opts.ibfCount = 40; |
| 47 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 48 | |
| 49 | Name syncInterestName(syncPrefix); |
| 50 | syncInterestName.append("malicious-IBF"); |
| 51 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 52 | BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 55 | BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 56 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 57 | 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 Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 62 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 63 | advanceClocks(10_ms); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 64 | m_face.sentInterests.clear(); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 65 | |
| 66 | // full sync sends the next one in interest lifetime / 2 +- jitter |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 67 | advanceClocks(6_s); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 71 | BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure) |
| 72 | { |
Junxiao Shi | 69bcaef | 2023-12-27 02:29:59 +0000 | [diff] [blame] | 73 | Name syncPrefix("/psync"); |
| 74 | FullProducer::Options opts; |
| 75 | opts.ibfCount = 40; |
| 76 | FullProducer node(m_face, m_keyChain, syncPrefix, opts); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 77 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 78 | Name syncInterestName(syncPrefix); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 79 | node.m_iblt.appendToName(syncInterestName); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 80 | Interest syncInterest(syncInterestName); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 81 | |
Junxiao Shi | c5f5eb1 | 2023-08-11 08:05:23 +0000 | [diff] [blame] | 82 | auto badCompress = std::make_shared<const ndn::Buffer>(5); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 83 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 84 | |
| 85 | const uint8_t test[] = {'t', 'e', 's', 't'}; |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 86 | auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 87 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 88 | } |
| 89 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 90 | BOOST_AUTO_TEST_SUITE_END() |
| 91 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 92 | } // namespace psync::tests |