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 | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 28 | namespace nfd::tests { |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 29 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 30 | shared_ptr<Interest> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 31 | makeInterest(const Name& name, bool canBePrefix, std::optional<time::milliseconds> lifetime, |
| 32 | std::optional<Interest::Nonce> nonce) |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 33 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 34 | auto interest = std::make_shared<Interest>(name); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 35 | interest->setCanBePrefix(canBePrefix); |
| 36 | if (lifetime) { |
| 37 | interest->setInterestLifetime(*lifetime); |
| 38 | } |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 39 | interest->setNonce(nonce ? ndn::make_optional(*nonce) : ndn::nullopt); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 40 | return interest; |
| 41 | } |
| 42 | |
| 43 | shared_ptr<Data> |
| 44 | makeData(const Name& name) |
| 45 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 46 | auto data = std::make_shared<Data>(name); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 47 | return signData(data); |
| 48 | } |
| 49 | |
| 50 | Data& |
| 51 | signData(Data& data) |
| 52 | { |
Davide Pesavento | b7e72c3 | 2020-10-02 20:00:03 -0400 | [diff] [blame] | 53 | data.setSignatureInfo(ndn::SignatureInfo(tlv::NullSignature)); |
| 54 | data.setSignatureValue(std::make_shared<ndn::Buffer>()); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 55 | data.wireEncode(); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 56 | return data; |
| 57 | } |
| 58 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 59 | lp::Nack |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 60 | makeNack(Interest interest, lp::NackReason reason) |
| 61 | { |
| 62 | lp::Nack nack(std::move(interest)); |
| 63 | nack.setReason(reason); |
| 64 | return nack; |
| 65 | } |
| 66 | |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 67 | ndn::PrefixAnnouncement |
| 68 | makePrefixAnn(const Name& announcedName, time::milliseconds expiration, |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 69 | std::optional<ndn::security::ValidityPeriod> validity) |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 70 | { |
| 71 | ndn::PrefixAnnouncement pa; |
| 72 | pa.setAnnouncedName(announcedName); |
| 73 | pa.setExpiration(expiration); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 74 | pa.setValidityPeriod(validity ? ndn::make_optional(*validity) : ndn::nullopt); |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 75 | return pa; |
| 76 | } |
| 77 | |
| 78 | ndn::PrefixAnnouncement |
| 79 | makePrefixAnn(const Name& announcedName, time::milliseconds expiration, |
| 80 | std::pair<time::seconds, time::seconds> validityFromNow) |
| 81 | { |
| 82 | auto now = time::system_clock::now(); |
| 83 | return makePrefixAnn(announcedName, expiration, |
| 84 | ndn::security::ValidityPeriod(now + validityFromNow.first, now + validityFromNow.second)); |
| 85 | } |
| 86 | |
| 87 | ndn::PrefixAnnouncement |
| 88 | signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain, |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 89 | const ndn::security::SigningInfo& si, std::optional<uint64_t> version) |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 90 | { |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 91 | pa.toData(keyChain, si, version ? ndn::make_optional(*version) : ndn::nullopt); |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 92 | return std::move(pa); |
| 93 | } |
| 94 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 95 | } // namespace nfd::tests |