blob: 7494c4bd35e2654c28c59338c3ce7b09d60c37ce [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
Junxiao Shid23de8b2016-07-23 20:05:42 +000028namespace nfd {
29namespace tests {
30
Junxiao Shid23de8b2016-07-23 20:05:42 +000031shared_ptr<Interest>
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040032makeInterest(const Name& name, bool canBePrefix, std::optional<time::milliseconds> lifetime,
33 std::optional<Interest::Nonce> nonce)
Junxiao Shid23de8b2016-07-23 20:05:42 +000034{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040035 auto interest = std::make_shared<Interest>(name);
Junxiao Shi9d727852019-05-14 13:44:22 -060036 interest->setCanBePrefix(canBePrefix);
37 if (lifetime) {
38 interest->setInterestLifetime(*lifetime);
39 }
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040040 interest->setNonce(nonce ? ndn::make_optional(*nonce) : ndn::nullopt);
Junxiao Shid23de8b2016-07-23 20:05:42 +000041 return interest;
42}
43
44shared_ptr<Data>
45makeData(const Name& name)
46{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040047 auto data = std::make_shared<Data>(name);
Junxiao Shid23de8b2016-07-23 20:05:42 +000048 return signData(data);
49}
50
51Data&
52signData(Data& data)
53{
Davide Pesaventob7e72c32020-10-02 20:00:03 -040054 data.setSignatureInfo(ndn::SignatureInfo(tlv::NullSignature));
55 data.setSignatureValue(std::make_shared<ndn::Buffer>());
Junxiao Shid23de8b2016-07-23 20:05:42 +000056 data.wireEncode();
Junxiao Shid23de8b2016-07-23 20:05:42 +000057 return data;
58}
59
Junxiao Shid23de8b2016-07-23 20:05:42 +000060lp::Nack
Junxiao Shi99540072017-01-27 19:57:33 +000061makeNack(Interest interest, lp::NackReason reason)
62{
63 lp::Nack nack(std::move(interest));
64 nack.setReason(reason);
65 return nack;
66}
67
Junxiao Shid47cd632018-09-11 03:10:00 +000068ndn::PrefixAnnouncement
69makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040070 std::optional<ndn::security::ValidityPeriod> validity)
Junxiao Shid47cd632018-09-11 03:10:00 +000071{
72 ndn::PrefixAnnouncement pa;
73 pa.setAnnouncedName(announcedName);
74 pa.setExpiration(expiration);
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040075 pa.setValidityPeriod(validity ? ndn::make_optional(*validity) : ndn::nullopt);
Junxiao Shid47cd632018-09-11 03:10:00 +000076 return pa;
77}
78
79ndn::PrefixAnnouncement
80makePrefixAnn(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
88ndn::PrefixAnnouncement
89signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040090 const ndn::security::SigningInfo& si, std::optional<uint64_t> version)
Junxiao Shid47cd632018-09-11 03:10:00 +000091{
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040092 pa.toData(keyChain, si, version ? ndn::make_optional(*version) : ndn::nullopt);
Junxiao Shid47cd632018-09-11 03:10:00 +000093 return std::move(pa);
94}
95
Junxiao Shid23de8b2016-07-23 20:05:42 +000096} // namespace tests
97} // namespace nfd