Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 51cf75c | 2020-03-11 22:21:13 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, Regents of the University of California, |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +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 NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD 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 | * NFD 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 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Davide Pesavento | b7703ad | 2019-03-23 21:12:56 -0400 | [diff] [blame] | 26 | #include "tests/test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 27 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 28 | namespace nfd { |
| 29 | namespace tests { |
| 30 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 31 | shared_ptr<Interest> |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 32 | makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime, |
Davide Pesavento | 51cf75c | 2020-03-11 22:21:13 -0400 | [diff] [blame] | 33 | optional<Interest::Nonce> nonce) |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 34 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 35 | auto interest = std::make_shared<Interest>(name); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 36 | interest->setCanBePrefix(canBePrefix); |
| 37 | if (lifetime) { |
| 38 | interest->setInterestLifetime(*lifetime); |
| 39 | } |
Davide Pesavento | 51cf75c | 2020-03-11 22:21:13 -0400 | [diff] [blame] | 40 | interest->setNonce(nonce); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 41 | return interest; |
| 42 | } |
| 43 | |
| 44 | shared_ptr<Data> |
| 45 | makeData(const Name& name) |
| 46 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 47 | auto data = std::make_shared<Data>(name); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 48 | return signData(data); |
| 49 | } |
| 50 | |
| 51 | Data& |
| 52 | signData(Data& data) |
| 53 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 54 | data.setSignatureInfo(ndn::SignatureInfo(tlv::NullSignature)); |
| 55 | data.setSignatureValue(std::make_shared<ndn::Buffer>()); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 56 | data.wireEncode(); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 57 | return data; |
| 58 | } |
| 59 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 60 | lp::Nack |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 61 | makeNack(Interest interest, lp::NackReason reason) |
| 62 | { |
| 63 | lp::Nack nack(std::move(interest)); |
| 64 | nack.setReason(reason); |
| 65 | return nack; |
| 66 | } |
| 67 | |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 68 | ndn::PrefixAnnouncement |
| 69 | makePrefixAnn(const Name& announcedName, time::milliseconds expiration, |
| 70 | optional<ndn::security::ValidityPeriod> validity) |
| 71 | { |
| 72 | ndn::PrefixAnnouncement pa; |
| 73 | pa.setAnnouncedName(announcedName); |
| 74 | pa.setExpiration(expiration); |
| 75 | pa.setValidityPeriod(validity); |
| 76 | return pa; |
| 77 | } |
| 78 | |
| 79 | ndn::PrefixAnnouncement |
| 80 | makePrefixAnn(const Name& announcedName, time::milliseconds expiration, |
| 81 | std::pair<time::seconds, time::seconds> validityFromNow) |
| 82 | { |
| 83 | auto now = time::system_clock::now(); |
| 84 | return makePrefixAnn(announcedName, expiration, |
| 85 | ndn::security::ValidityPeriod(now + validityFromNow.first, now + validityFromNow.second)); |
| 86 | } |
| 87 | |
| 88 | ndn::PrefixAnnouncement |
| 89 | signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain, |
| 90 | const ndn::security::SigningInfo& si, optional<uint64_t> version) |
| 91 | { |
| 92 | pa.toData(keyChain, si, version); |
| 93 | return std::move(pa); |
| 94 | } |
| 95 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 96 | } // namespace tests |
| 97 | } // namespace nfd |