blob: 6a994b07a0466bea8055c82b4a013d869ae4b9ea [file] [log] [blame]
Junxiao Shi7809e302016-07-23 14:11:25 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi20d5a0b2018-08-14 09:26:11 -06002/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi7809e302016-07-23 14:11:25 +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 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
Davide Pesavento66777622020-10-09 18:46:03 -040026#include "tests/test-common.hpp"
Junxiao Shi7809e302016-07-23 14:11:25 +000027
Davide Pesaventob3570c62022-02-19 19:19:00 -050028namespace ndn::tests {
Junxiao Shi7809e302016-07-23 14:11:25 +000029
Junxiao Shi7809e302016-07-23 14:11:25 +000030shared_ptr<Interest>
Davide Pesavento66777622020-10-09 18:46:03 -040031makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime,
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040032 optional<Interest::Nonce> nonce)
Junxiao Shi7809e302016-07-23 14:11:25 +000033{
Davide Pesavento66777622020-10-09 18:46:03 -040034 auto interest = std::make_shared<Interest>(name);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060035 interest->setCanBePrefix(canBePrefix);
Davide Pesavento66777622020-10-09 18:46:03 -040036 if (lifetime) {
37 interest->setInterestLifetime(*lifetime);
38 }
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040039 interest->setNonce(nonce);
Junxiao Shi7809e302016-07-23 14:11:25 +000040 return interest;
41}
42
43shared_ptr<Data>
44makeData(const Name& name)
45{
Davide Pesavento66777622020-10-09 18:46:03 -040046 auto data = std::make_shared<Data>(name);
Junxiao Shi7809e302016-07-23 14:11:25 +000047 return signData(data);
48}
49
50Data&
51signData(Data& data)
52{
Davide Pesavento66777622020-10-09 18:46:03 -040053 data.setSignatureInfo(SignatureInfo(tlv::NullSignature));
54 data.setSignatureValue(std::make_shared<Buffer>());
Junxiao Shi7809e302016-07-23 14:11:25 +000055 data.wireEncode();
Junxiao Shi7809e302016-07-23 14:11:25 +000056 return data;
57}
58
Junxiao Shi7809e302016-07-23 14:11:25 +000059lp::Nack
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040060makeNack(Interest interest, lp::NackReason reason)
Zhuo Lib3558892016-08-12 15:51:12 -070061{
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040062 lp::Nack nack(std::move(interest));
Zhuo Lib3558892016-08-12 15:51:12 -070063 nack.setReason(reason);
64 return nack;
65}
66
Davide Pesaventob3570c62022-02-19 19:19:00 -050067} // namespace ndn::tests