blob: 01cc05b79480c1a7e1a72b251b6de648166240b1 [file] [log] [blame]
Eric Newberry261dbc22015-07-22 23:18:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib6e276f2017-08-14 20:10:04 +00002/*
Davide Pesavento187e9f92023-03-20 22:46:22 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Eric Newberry261dbc22015-07-22 23:18:18 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/lp/packet.hpp"
23#include "ndn-cxx/prefix-announcement.hpp"
Eric Newberry261dbc22015-07-22 23:18:18 -070024
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050025#include "tests/key-chain-fixture.hpp"
26#include "tests/test-common.hpp"
Eric Newberry261dbc22015-07-22 23:18:18 -070027
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040028namespace ndn::tests {
29
30using namespace ndn::lp;
Eric Newberry261dbc22015-07-22 23:18:18 -070031
Davide Pesaventoeee3e822016-11-26 19:19:34 +010032BOOST_AUTO_TEST_SUITE(Lp)
33BOOST_AUTO_TEST_SUITE(TestPacket)
Eric Newberry261dbc22015-07-22 23:18:18 -070034
35BOOST_AUTO_TEST_CASE(FieldAccess)
36{
37 Packet packet;
38
Junxiao Shib6e276f2017-08-14 20:10:04 +000039 BOOST_CHECK(packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070040 BOOST_CHECK(!packet.has<FragIndexField>());
Junxiao Shic53df032019-01-14 23:33:25 +000041 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000042
43 packet.set<FragIndexField>(1234);
44 BOOST_CHECK(!packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070045 BOOST_CHECK(packet.has<FragIndexField>());
Davide Pesavento923ba442019-02-12 22:00:38 -050046 BOOST_CHECK_THROW(packet.add<FragIndexField>(5678), std::invalid_argument);
Junxiao Shic53df032019-01-14 23:33:25 +000047 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 1);
48 BOOST_CHECK_EQUAL(packet.get<FragIndexField>(0), 1234);
Eric Newberry261dbc22015-07-22 23:18:18 -070049 BOOST_CHECK_THROW(packet.get<FragIndexField>(1), std::out_of_range);
50 BOOST_CHECK_THROW(packet.remove<FragIndexField>(1), std::out_of_range);
Junxiao Shib6e276f2017-08-14 20:10:04 +000051
52 packet.remove<FragIndexField>(0);
Junxiao Shic53df032019-01-14 23:33:25 +000053 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000054
55 packet.add<FragIndexField>(832);
56 std::vector<uint64_t> fragIndexes = packet.list<FragIndexField>();
Junxiao Shic53df032019-01-14 23:33:25 +000057 BOOST_CHECK_EQUAL(fragIndexes.size(), 1);
58 BOOST_CHECK_EQUAL(fragIndexes.at(0), 832);
Junxiao Shib6e276f2017-08-14 20:10:04 +000059
60 packet.clear<FragIndexField>();
Junxiao Shic53df032019-01-14 23:33:25 +000061 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
62 BOOST_CHECK(packet.empty());
63
64 packet.add<AckField>(4001);
65 packet.add<AckField>(4002);
66 packet.add<AckField>(4003);
67 BOOST_CHECK_EQUAL(packet.count<AckField>(), 3);
68 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 4001);
69 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 4002);
70 BOOST_CHECK_EQUAL(packet.get<AckField>(2), 4003);
71
72 packet.remove<AckField>(1);
73 BOOST_CHECK_EQUAL(packet.count<AckField>(), 2);
74 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 4001);
75 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 4003);
76
77 packet.remove<AckField>(0);
78 packet.remove<AckField>(0);
79 BOOST_CHECK_EQUAL(packet.count<AckField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000080 BOOST_CHECK(packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070081}
82
Eric Newberry261dbc22015-07-22 23:18:18 -070083BOOST_AUTO_TEST_CASE(EncodeFragment)
84{
85 static const uint8_t expectedBlock[] = {
Junxiao Shi974b81a2018-04-21 01:37:03 +000086 0x64, 0x0e, // LpPacket
87 0x51, 0x08, // Sequence
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8,
Eric Newberry261dbc22015-07-22 23:18:18 -070089 0x50, 0x02, // Fragment
90 0x03, 0xe8,
91 };
92
93 Buffer buf(2);
94 buf[0] = 0x03;
95 buf[1] = 0xe8;
96
97 Packet packet;
Davide Pesavento258d51a2022-02-27 21:26:28 -050098 packet.add<FragmentField>({buf.begin(), buf.end()});
Junxiao Shi974b81a2018-04-21 01:37:03 +000099 packet.add<SequenceField>(1000);
100 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700101 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
102 wire.begin(), wire.end());
103}
104
105BOOST_AUTO_TEST_CASE(EncodeSubTlv)
106{
107 static const uint8_t expectedBlock[] = {
108 0x64, 0x09, // LpPacket
109 0xfd, 0x03, 0x20, 0x05, // Nack
110 0xfd, 0x03, 0x21, 0x01, // NackReason
111 0x64,
112 };
113
114 NackHeader nack;
115 nack.setReason(NackReason::DUPLICATE);
116
117 Packet packet;
Junxiao Shic53df032019-01-14 23:33:25 +0000118 packet.add<NackField>(nack);
119 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700120 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
121 wire.begin(), wire.end());
122}
123
Teng Liang02960742017-10-24 00:36:45 -0700124BOOST_AUTO_TEST_CASE(EncodeZeroLengthTlv)
125{
126 static const uint8_t expectedBlock[] = {
127 0x64, 0x04, // LpPacket
128 0xfd, 0x03, 0x4c, 0x00, // NonDiscovery
129 };
130
Junxiao Shic53df032019-01-14 23:33:25 +0000131 Packet packet1;
132 packet1.set<NonDiscoveryField>(EmptyValue{});
133 Block wire = packet1.wireEncode();
Teng Liang02960742017-10-24 00:36:45 -0700134 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
135 wire.begin(), wire.end());
136
Junxiao Shic53df032019-01-14 23:33:25 +0000137 Packet packet2;
138 packet2.add<NonDiscoveryField>(EmptyValue{});
139 wire = packet2.wireEncode();
Teng Liang02960742017-10-24 00:36:45 -0700140 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
141 wire.begin(), wire.end());
142}
143
Eric Newberry261dbc22015-07-22 23:18:18 -0700144BOOST_AUTO_TEST_CASE(EncodeSortOrder)
145{
146 static const uint8_t expectedBlock[] = {
Junxiao Shi974b81a2018-04-21 01:37:03 +0000147 0x64, 0x2e, // LpPacket
Eric Newberry261dbc22015-07-22 23:18:18 -0700148 0x52, 0x01, // FragIndex
149 0x00,
150 0x53, 0x01, // FragCount
151 0x01,
Junxiao Shi974b81a2018-04-21 01:37:03 +0000152 0xfd, 0x03, 0x44, 0x08, // Ack
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
154 0xfd, 0x03, 0x44, 0x08, // Ack
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
156 0xfd, 0x03, 0x44, 0x08, // Ack
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
Eric Newberry261dbc22015-07-22 23:18:18 -0700158 0x50, 0x02, // Fragment
159 0x03, 0xe8,
160 };
161
162 Buffer frag(2);
163 frag[0] = 0x03;
164 frag[1] = 0xe8;
165
166 Packet packet;
Davide Pesavento258d51a2022-02-27 21:26:28 -0500167 packet.add<FragmentField>({frag.begin(), frag.end()});
Junxiao Shic53df032019-01-14 23:33:25 +0000168 packet.add<FragIndexField>(0);
169 packet.add<AckField>(2);
170 packet.wireEncode();
171 packet.add<FragCountField>(1);
172 packet.wireEncode();
173 packet.add<AckField>(4);
174 packet.wireEncode();
175 packet.add<AckField>(3);
176 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700177 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
178 wire.begin(), wire.end());
179}
180
181BOOST_AUTO_TEST_CASE(DecodeNormal)
182{
183 static const uint8_t inputBlock[] = {
Junxiao Shic53df032019-01-14 23:33:25 +0000184 0x64, 0x2e, // LpPacket
Eric Newberry261dbc22015-07-22 23:18:18 -0700185 0x52, 0x01, // FragIndex
186 0x00,
187 0x53, 0x01, // FragCount
188 0x01,
Junxiao Shic53df032019-01-14 23:33:25 +0000189 0xfd, 0x03, 0x44, 0x08, // Ack
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
191 0xfd, 0x03, 0x44, 0x08, // Ack
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
193 0xfd, 0x03, 0x44, 0x08, // Ack
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
Eric Newberry261dbc22015-07-22 23:18:18 -0700195 0x50, 0x02, // Fragment
196 0x03, 0xe8,
197 };
198
199 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500200 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000201 packet.wireDecode(wire);
202
203 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 1);
204 BOOST_CHECK_EQUAL(packet.get<FragIndexField>(), 0);
205
206 BOOST_CHECK_EQUAL(packet.count<FragCountField>(), 1);
207 BOOST_CHECK_EQUAL(packet.get<FragCountField>(), 1);
208
209 BOOST_CHECK_EQUAL(packet.count<AckField>(), 3);
210 BOOST_CHECK_EQUAL(packet.get<AckField>(), 1);
211 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 1);
212 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 3);
213 BOOST_CHECK_EQUAL(packet.get<AckField>(2), 2);
214
215 BOOST_CHECK_EQUAL(packet.count<FragmentField>(), 1);
Davide Pesavento187e9f92023-03-20 22:46:22 -0400216 auto [first, last] = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700217 BOOST_CHECK_EQUAL(2, last - first);
218 BOOST_CHECK_EQUAL(0x03, *first);
219 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
Eric Newberry261dbc22015-07-22 23:18:18 -0700220}
221
222BOOST_AUTO_TEST_CASE(DecodeIdle)
223{
224 static const uint8_t inputBlock[] = {
225 0x64, 0x06, // LpPacket
226 0x52, 0x01, // FragIndex
227 0x00,
228 0x53, 0x01, // FragCount
229 0x01,
230 };
231
232 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500233 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000234 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700235 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
236 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
237 BOOST_CHECK_EQUAL(1, packet.count<FragCountField>());
238 BOOST_CHECK_EQUAL(0, packet.get<FragIndexField>(0));
239 BOOST_CHECK_EQUAL(1, packet.get<FragCountField>(0));
240}
241
242BOOST_AUTO_TEST_CASE(DecodeFragment)
243{
244 static const uint8_t inputBlock[] = {
245 0x64, 0x04, // LpPacket
246 0x50, 0x02, // Fragment
247 0x03, 0xe8,
248 };
249
250 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500251 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000252 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700253 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
254 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
Davide Pesavento187e9f92023-03-20 22:46:22 -0400255 auto [first, last] = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700256 BOOST_CHECK_EQUAL(2, last - first);
257 BOOST_CHECK_EQUAL(0x03, *first);
258 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
259}
260
Teng Liang02960742017-10-24 00:36:45 -0700261BOOST_AUTO_TEST_CASE(DecodeNonDiscoveryHeader)
262{
263 static const uint8_t inputBlock[] = {
264 0x64, 0x04, // LpPacket
265 0xfd, 0x03, 0x4c, 0x00, // NonDiscovery
266 };
267
268 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500269 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000270 packet.wireDecode(wire);
Teng Liang02960742017-10-24 00:36:45 -0700271 BOOST_CHECK_EQUAL(true, packet.has<NonDiscoveryField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000272 packet.get<NonDiscoveryField>();
Teng Liang02960742017-10-24 00:36:45 -0700273}
274
Eric Newberry261dbc22015-07-22 23:18:18 -0700275BOOST_AUTO_TEST_CASE(DecodeEmpty)
276{
277 static const uint8_t inputBlock[] = {
278 0x64, 0x00, // LpPacket
279 };
280
281 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500282 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000283 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700284 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
285 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
Teng Liang02960742017-10-24 00:36:45 -0700286 BOOST_CHECK_EQUAL(false, packet.has<NonDiscoveryField>());
Eric Newberry261dbc22015-07-22 23:18:18 -0700287}
288
289BOOST_AUTO_TEST_CASE(DecodeRepeatedNonRepeatableHeader)
290{
291 static const uint8_t inputBlock[] = {
292 0x64, 0x06, // LpPacket
293 0x52, 0x01, // FragIndex
294 0x00,
295 0x52, 0x01, // FragIndex
296 0x01,
297 };
298
299 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500300 Block wire(inputBlock);
Eric Newberry261dbc22015-07-22 23:18:18 -0700301 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
302}
303
304BOOST_AUTO_TEST_CASE(DecodeRepeatedFragment)
305{
306 static const uint8_t inputBlock[] = {
307 0x64, 0x08, // LpPacket
308 0x50, 0x02, // Fragment
309 0x03, 0xe8,
310 0x50, 0x02, // Fragment
311 0x03, 0xe9,
312 };
313
314 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500315 Block wire(inputBlock);
Eric Newberry261dbc22015-07-22 23:18:18 -0700316 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
317}
318
319BOOST_AUTO_TEST_CASE(DecodeWrongOrderAmongHeaders)
320{
321 static const uint8_t inputBlock[] = {
322 0x64, 0x0a, // LpPacket
323 0x53, 0x01, // FragCount
324 0x01,
325 0x52, 0x01, // FragIndex
326 0x00,
327 0x50, 0x02, // Fragment
328 0x03, 0xe8,
329 };
330
331 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500332 Block wire(inputBlock);
Eric Newberry261dbc22015-07-22 23:18:18 -0700333 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
334}
335
336BOOST_AUTO_TEST_CASE(DecodeWrongOrderFragment)
337{
338 static const uint8_t inputBlock[] = {
339 0x64, 0x0a, // LpPacket
340 0x52, 0x01, // FragIndex
341 0x00,
342 0x50, 0x02, // Fragment
343 0x03, 0xe8,
344 0x53, 0x01, // FragCount
345 0x01,
346 };
347
348 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500349 Block wire(inputBlock);
Eric Newberry261dbc22015-07-22 23:18:18 -0700350 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
351}
352
353BOOST_AUTO_TEST_CASE(DecodeIgnoredHeader)
354{
355 static const uint8_t inputBlock[] = {
356 0x64, 0x0c, // LpPacket
357 0x52, 0x01, // FragIndex
358 0x00,
Eric Newberry3ed62472016-12-11 22:11:38 -0700359 0xfd, 0x03, 0x24, 0x01, // unknown TLV-TYPE 804 (ignored)
Eric Newberry261dbc22015-07-22 23:18:18 -0700360 0x02,
361 0x50, 0x02, // Fragment
362 0x03, 0xe8,
363 };
364
365 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500366 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000367 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700368 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
369 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
370}
371
372BOOST_AUTO_TEST_CASE(DecodeUnrecognizedHeader)
373{
374 static const uint8_t inputBlock[] = {
375 0x64, 0x0c, // LpPacket
376 0x52, 0x01, // FragIndex
377 0x00,
378 0xfd, 0x03, 0x22, 0x01, // unknown TLV-TYPE 802 (cannot ignore)
379 0x02,
380 0x50, 0x02, // Fragment
381 0x03, 0xe8,
382 };
383
384 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500385 Block wire(inputBlock);
Eric Newberry261dbc22015-07-22 23:18:18 -0700386 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
387}
388
389BOOST_AUTO_TEST_CASE(DecodeBareNetworkLayerPacket)
390{
391 static const uint8_t inputBlock[] = {
392 0x05, 0x0a, // Interest
393 0x07, 0x02, // Name
394 0x03, 0xe8,
395 0x0a, 0x04, // Nonce
396 0x01, 0x02, 0x03, 0x04,
397 };
398
399 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500400 Block wire(inputBlock);
Junxiao Shic53df032019-01-14 23:33:25 +0000401 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700402 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
403
Junxiao Shic53df032019-01-14 23:33:25 +0000404 Block encoded = packet.wireEncode();
Eric Newberry83872fd2015-08-06 17:01:24 -0700405 BOOST_CHECK_EQUAL_COLLECTIONS(inputBlock, inputBlock + sizeof(inputBlock),
Eric Newberry261dbc22015-07-22 23:18:18 -0700406 encoded.begin(), encoded.end());
407}
408
Junxiao Shic53df032019-01-14 23:33:25 +0000409BOOST_AUTO_TEST_CASE(DecodeSeqNum)
410{
411 Packet packet;
412
413 // Sequence number is fixed-width, not NonNegativeInteger
414 packet.wireDecode("640A 5104A4A5A6A7 5002FFFF"_block);
415 BOOST_CHECK_THROW(packet.get<SequenceField>(), ndn::tlv::Error);
416
417 packet.wireDecode("640E 5108A0A1A2A3A4A5A6A7 5002FFFF"_block);
418 BOOST_CHECK_EQUAL(packet.get<SequenceField>(), 0xA0A1A2A3A4A5A6A7);
419}
420
Eric Newberry43bf6bb2015-10-09 16:12:09 -0700421BOOST_AUTO_TEST_CASE(DecodeUnrecognizedTlvType)
422{
423 Packet packet;
Davide Pesaventofbea4fc2022-02-08 07:26:04 -0500424 Block wire = makeEmptyBlock(ndn::tlv::Name);
Eric Newberry43bf6bb2015-10-09 16:12:09 -0700425 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
426}
427
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400428BOOST_FIXTURE_TEST_CASE(DecodePrefixAnnouncement, KeyChainFixture)
Teng Liange3ecad72018-08-28 21:12:53 -0700429{
430 // Construct Data which prefix announcement is attached to
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400431 auto data0 = makeData("/edu/ua/cs/news/index.html");
Teng Liange3ecad72018-08-28 21:12:53 -0700432
Teng Liange3ecad72018-08-28 21:12:53 -0700433 Packet packet0;
Davide Pesavento14c56cd2020-05-21 01:44:03 -0400434 packet0.wireDecode(data0->wireEncode());
Teng Liange3ecad72018-08-28 21:12:53 -0700435
436 // Construct Prefix Announcement
437 PrefixAnnouncement pa;
438 pa.setAnnouncedName("/net/example");
439 pa.setExpiration(5_min);
440 pa.setValidityPeriod(security::ValidityPeriod(time::fromIsoString("20181030T000000"),
441 time::fromIsoString("20181124T235959")));
442 pa.toData(m_keyChain, signingWithSha256(), 1);
443 PrefixAnnouncementHeader pah0(pa);
Junxiao Shic53df032019-01-14 23:33:25 +0000444 packet0.add<PrefixAnnouncementField>(pah0);
445 Block encoded = packet0.wireEncode();
Teng Liange3ecad72018-08-28 21:12:53 -0700446
447 // check decoding
448 Packet packet1;
Junxiao Shic53df032019-01-14 23:33:25 +0000449 packet1.wireDecode(encoded);
Teng Liange3ecad72018-08-28 21:12:53 -0700450 BOOST_CHECK_EQUAL(true, packet1.has<PrefixAnnouncementField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000451 PrefixAnnouncementHeader pah1 = packet1.get<PrefixAnnouncementField>();
Teng Liange3ecad72018-08-28 21:12:53 -0700452 BOOST_CHECK_EQUAL(pah1.getPrefixAnn()->getAnnouncedName(), "/net/example");
453}
454
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100455BOOST_AUTO_TEST_SUITE_END() // TestPacket
456BOOST_AUTO_TEST_SUITE_END() // Lp
Eric Newberry261dbc22015-07-22 23:18:18 -0700457
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400458} // namespace ndn::tests