Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, 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" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame^] | 22 | #include "tests/boost-test.hpp" |
| 23 | #include "tests/unit-test-time-fixture.hpp" |
| 24 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 25 | #include <ndn-cxx/name.hpp> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 26 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
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 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | namespace psync { |
| 30 | |
| 31 | using namespace ndn; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(TestFullProducer) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(Constructor) |
| 36 | { |
| 37 | util::DummyClientFace face({true, true}); |
| 38 | BOOST_REQUIRE_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr)); |
| 39 | } |
| 40 | |
| 41 | BOOST_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 Gawande | 40970d6 | 2018-11-01 11:24:17 -0500 | [diff] [blame] | 51 | BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame^] | 54 | BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 55 | { |
| 56 | Name syncPrefix("/psync"), userNode("/testUser"); |
| 57 | util::DummyClientFace face(io, {true, true}); |
| 58 | |
| 59 | FullProducer node(40, face, syncPrefix, userNode, nullptr, ndn::time::milliseconds(8000)); |
| 60 | advanceClocks(ndn::time::milliseconds(10)); |
| 61 | face.sentInterests.clear(); |
| 62 | |
| 63 | // full sync sends the next one in interest lifetime / 2 +- jitter |
| 64 | advanceClocks(ndn::time::milliseconds(6000)); |
| 65 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 66 | } |
| 67 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 68 | BOOST_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 | |
| 75 | ndn::Name syncInterestName(syncPrefix); |
| 76 | node.m_iblt.appendToName(syncInterestName); |
| 77 | ndn::Interest syncInterest(syncInterestName); |
| 78 | |
| 79 | auto badCompress = std::make_shared<const ndn::Buffer>(5); |
| 80 | |
| 81 | BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, badCompress)); |
| 82 | |
| 83 | const uint8_t test[] = {'t', 'e', 's', 't'}; |
| 84 | auto goodCompressBadBlock = compress(node.m_contentCompression, &test[0], sizeof(test)); |
| 85 | BOOST_REQUIRE_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock)); |
| 86 | } |
| 87 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 88 | BOOST_AUTO_TEST_SUITE_END() |
| 89 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame^] | 90 | } // namespace psync |