blob: 98fa18807b3eca898f966542a184f170487ba0a1 [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 Pesavento4ab5eed2020-03-12 20:50:04 -04003 * Copyright (c) 2014-2020, 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
28namespace ndn {
29namespace tests {
30
Junxiao Shi7809e302016-07-23 14:11:25 +000031shared_ptr<Interest>
Davide Pesavento66777622020-10-09 18:46:03 -040032makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime,
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040033 optional<Interest::Nonce> nonce)
Junxiao Shi7809e302016-07-23 14:11:25 +000034{
Davide Pesavento66777622020-10-09 18:46:03 -040035 auto interest = std::make_shared<Interest>(name);
Junxiao Shi20d5a0b2018-08-14 09:26:11 -060036 interest->setCanBePrefix(canBePrefix);
Davide Pesavento66777622020-10-09 18:46:03 -040037 if (lifetime) {
38 interest->setInterestLifetime(*lifetime);
39 }
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040040 interest->setNonce(nonce);
Junxiao Shi7809e302016-07-23 14:11:25 +000041 return interest;
42}
43
44shared_ptr<Data>
45makeData(const Name& name)
46{
Davide Pesavento66777622020-10-09 18:46:03 -040047 auto data = std::make_shared<Data>(name);
Junxiao Shi7809e302016-07-23 14:11:25 +000048 return signData(data);
49}
50
51Data&
52signData(Data& data)
53{
Davide Pesavento66777622020-10-09 18:46:03 -040054 data.setSignatureInfo(SignatureInfo(tlv::NullSignature));
55 data.setSignatureValue(std::make_shared<Buffer>());
Junxiao Shi7809e302016-07-23 14:11:25 +000056 data.wireEncode();
Junxiao Shi7809e302016-07-23 14:11:25 +000057 return data;
58}
59
Junxiao Shi7809e302016-07-23 14:11:25 +000060lp::Nack
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040061makeNack(Interest interest, lp::NackReason reason)
Zhuo Lib3558892016-08-12 15:51:12 -070062{
Davide Pesavento4ab5eed2020-03-12 20:50:04 -040063 lp::Nack nack(std::move(interest));
Zhuo Lib3558892016-08-12 15:51:12 -070064 nack.setReason(reason);
65 return nack;
66}
67
Junxiao Shi7809e302016-07-23 14:11:25 +000068} // namespace tests
69} // namespace ndn