blob: 0a7c7f693d6c57ac077b8ce562cd75eea0a33012 [file] [log] [blame]
Junxiao Shid23de8b2016-07-23 20:05:42 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shifc2e13d2017-07-25 02:08:48 +00002/*
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shid23de8b2016-07-23 20:05:42 +00004 * 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 Pesaventob7703ad2019-03-23 21:12:56 -040026#include "tests/test-common.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060027
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040028namespace nfd::tests {
Junxiao Shid23de8b2016-07-23 20:05:42 +000029
Junxiao Shid23de8b2016-07-23 20:05:42 +000030shared_ptr<Interest>
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040031makeInterest(const Name& name, bool canBePrefix, std::optional<time::milliseconds> lifetime,
32 std::optional<Interest::Nonce> nonce)
Junxiao Shid23de8b2016-07-23 20:05:42 +000033{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040034 auto interest = std::make_shared<Interest>(name);
Junxiao Shi9d727852019-05-14 13:44:22 -060035 interest->setCanBePrefix(canBePrefix);
36 if (lifetime) {
37 interest->setInterestLifetime(*lifetime);
38 }
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040039 interest->setNonce(nonce ? ndn::make_optional(*nonce) : ndn::nullopt);
Junxiao Shid23de8b2016-07-23 20:05:42 +000040 return interest;
41}
42
43shared_ptr<Data>
44makeData(const Name& name)
45{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040046 auto data = std::make_shared<Data>(name);
Junxiao Shid23de8b2016-07-23 20:05:42 +000047 return signData(data);
48}
49
50Data&
51signData(Data& data)
52{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040053 data.setSignatureInfo(ndn::SignatureInfo(tlv::NullSignature));
54 data.setSignatureValue(std::make_shared<ndn::Buffer>());
Junxiao Shid23de8b2016-07-23 20:05:42 +000055 data.wireEncode();
Junxiao Shid23de8b2016-07-23 20:05:42 +000056 return data;
57}
58
Junxiao Shid23de8b2016-07-23 20:05:42 +000059lp::Nack
Junxiao Shi99540072017-01-27 19:57:33 +000060makeNack(Interest interest, lp::NackReason reason)
61{
62 lp::Nack nack(std::move(interest));
63 nack.setReason(reason);
64 return nack;
65}
66
Junxiao Shid47cd632018-09-11 03:10:00 +000067ndn::PrefixAnnouncement
68makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040069 std::optional<ndn::security::ValidityPeriod> validity)
Junxiao Shid47cd632018-09-11 03:10:00 +000070{
71 ndn::PrefixAnnouncement pa;
72 pa.setAnnouncedName(announcedName);
73 pa.setExpiration(expiration);
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040074 pa.setValidityPeriod(validity ? ndn::make_optional(*validity) : ndn::nullopt);
Junxiao Shid47cd632018-09-11 03:10:00 +000075 return pa;
76}
77
78ndn::PrefixAnnouncement
79makePrefixAnn(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
87ndn::PrefixAnnouncement
88signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040089 const ndn::security::SigningInfo& si, std::optional<uint64_t> version)
Junxiao Shid47cd632018-09-11 03:10:00 +000090{
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040091 pa.toData(keyChain, si, version ? ndn::make_optional(*version) : ndn::nullopt);
Junxiao Shid47cd632018-09-11 03:10:00 +000092 return std::move(pa);
93}
94
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040095} // namespace nfd::tests