Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 2 | /* |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 12 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 13 | * |
| 14 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "test-common.hpp" |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 27 | |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/security/signature-sha256-with-rsa.hpp> |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace tests { |
| 32 | |
| 33 | UnitTestTimeFixture::UnitTestTimeFixture() |
| 34 | : steadyClock(make_shared<time::UnitTestSteadyClock>()) |
| 35 | , systemClock(make_shared<time::UnitTestSystemClock>()) |
| 36 | { |
| 37 | time::setCustomClocks(steadyClock, systemClock); |
| 38 | } |
| 39 | |
| 40 | UnitTestTimeFixture::~UnitTestTimeFixture() |
| 41 | { |
| 42 | time::setCustomClocks(nullptr, nullptr); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | UnitTestTimeFixture::advanceClocks(boost::asio::io_service& io, |
| 47 | time::nanoseconds tick, size_t nTicks) |
| 48 | { |
| 49 | this->advanceClocks(io, tick, tick * nTicks); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | UnitTestTimeFixture::advanceClocks(boost::asio::io_service& io, |
| 54 | time::nanoseconds tick, time::nanoseconds total) |
| 55 | { |
| 56 | BOOST_ASSERT(tick > time::nanoseconds::zero()); |
| 57 | BOOST_ASSERT(total >= time::nanoseconds::zero()); |
| 58 | |
| 59 | time::nanoseconds remaining = total; |
| 60 | while (remaining > time::nanoseconds::zero()) { |
| 61 | if (remaining >= tick) { |
| 62 | steadyClock->advance(tick); |
| 63 | systemClock->advance(tick); |
| 64 | remaining -= tick; |
| 65 | } |
| 66 | else { |
| 67 | steadyClock->advance(remaining); |
| 68 | systemClock->advance(remaining); |
| 69 | remaining = time::nanoseconds::zero(); |
| 70 | } |
| 71 | |
| 72 | if (io.stopped()) |
| 73 | io.reset(); |
| 74 | io.poll(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | shared_ptr<Interest> |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 79 | makeInterest(const Name& name, bool canBePrefix, time::milliseconds lifetime, |
| 80 | optional<Interest::Nonce> nonce) |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 81 | { |
Junxiao Shi | 20d5a0b | 2018-08-14 09:26:11 -0600 | [diff] [blame] | 82 | auto interest = make_shared<Interest>(name, lifetime); |
| 83 | interest->setCanBePrefix(canBePrefix); |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 84 | interest->setNonce(nonce); |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 85 | return interest; |
| 86 | } |
| 87 | |
| 88 | shared_ptr<Data> |
| 89 | makeData(const Name& name) |
| 90 | { |
| 91 | auto data = make_shared<Data>(name); |
| 92 | return signData(data); |
| 93 | } |
| 94 | |
| 95 | Data& |
| 96 | signData(Data& data) |
| 97 | { |
| 98 | ndn::SignatureSha256WithRsa fakeSignature; |
| 99 | fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); |
| 100 | data.setSignature(fakeSignature); |
| 101 | data.wireEncode(); |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 102 | return data; |
| 103 | } |
| 104 | |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 105 | lp::Nack |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 106 | makeNack(Interest interest, lp::NackReason reason) |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 107 | { |
Davide Pesavento | 4ab5eed | 2020-03-12 20:50:04 -0400 | [diff] [blame^] | 108 | lp::Nack nack(std::move(interest)); |
Zhuo Li | b355889 | 2016-08-12 15:51:12 -0700 | [diff] [blame] | 109 | nack.setReason(reason); |
| 110 | return nack; |
| 111 | } |
| 112 | |
Junxiao Shi | 7809e30 | 2016-07-23 14:11:25 +0000 | [diff] [blame] | 113 | } // namespace tests |
| 114 | } // namespace ndn |