blob: 5f750c3df2a855b2a47a368f13aae18fb6c64096 [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/*
Eric Newberrya3c8bd12020-05-15 17:27:07 -07003 * Copyright (c) 2013-2020 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
28namespace ndn {
29namespace lp {
30namespace tests {
31
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;
Junxiao Shi974b81a2018-04-21 01:37:03 +000098 packet.add<FragmentField>(std::make_pair(buf.begin(), buf.end()));
99 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;
Junxiao Shic53df032019-01-14 23:33:25 +0000167 packet.add<FragmentField>(std::make_pair(frag.begin(), frag.end()));
168 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;
200 Block wire(inputBlock, sizeof(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);
Eric Newberry261dbc22015-07-22 23:18:18 -0700216 Buffer::const_iterator first, last;
Junxiao Shic53df032019-01-14 23:33:25 +0000217 std::tie(first, last) = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700218 BOOST_CHECK_EQUAL(2, last - first);
219 BOOST_CHECK_EQUAL(0x03, *first);
220 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
Eric Newberry261dbc22015-07-22 23:18:18 -0700221}
222
223BOOST_AUTO_TEST_CASE(DecodeIdle)
224{
225 static const uint8_t inputBlock[] = {
226 0x64, 0x06, // LpPacket
227 0x52, 0x01, // FragIndex
228 0x00,
229 0x53, 0x01, // FragCount
230 0x01,
231 };
232
233 Packet packet;
234 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000235 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700236 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
237 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
238 BOOST_CHECK_EQUAL(1, packet.count<FragCountField>());
239 BOOST_CHECK_EQUAL(0, packet.get<FragIndexField>(0));
240 BOOST_CHECK_EQUAL(1, packet.get<FragCountField>(0));
241}
242
243BOOST_AUTO_TEST_CASE(DecodeFragment)
244{
245 static const uint8_t inputBlock[] = {
246 0x64, 0x04, // LpPacket
247 0x50, 0x02, // Fragment
248 0x03, 0xe8,
249 };
250
251 Packet packet;
252 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000253 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700254 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
255 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
256 Buffer::const_iterator first, last;
Junxiao Shic53df032019-01-14 23:33:25 +0000257 std::tie(first, last) = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700258 BOOST_CHECK_EQUAL(2, last - first);
259 BOOST_CHECK_EQUAL(0x03, *first);
260 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
261}
262
Teng Liang02960742017-10-24 00:36:45 -0700263BOOST_AUTO_TEST_CASE(DecodeNonDiscoveryHeader)
264{
265 static const uint8_t inputBlock[] = {
266 0x64, 0x04, // LpPacket
267 0xfd, 0x03, 0x4c, 0x00, // NonDiscovery
268 };
269
270 Packet packet;
271 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000272 packet.wireDecode(wire);
Teng Liang02960742017-10-24 00:36:45 -0700273 BOOST_CHECK_EQUAL(true, packet.has<NonDiscoveryField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000274 packet.get<NonDiscoveryField>();
Teng Liang02960742017-10-24 00:36:45 -0700275}
276
Eric Newberry261dbc22015-07-22 23:18:18 -0700277BOOST_AUTO_TEST_CASE(DecodeEmpty)
278{
279 static const uint8_t inputBlock[] = {
280 0x64, 0x00, // LpPacket
281 };
282
283 Packet packet;
284 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000285 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700286 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
287 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
Teng Liang02960742017-10-24 00:36:45 -0700288 BOOST_CHECK_EQUAL(false, packet.has<NonDiscoveryField>());
Eric Newberry261dbc22015-07-22 23:18:18 -0700289}
290
291BOOST_AUTO_TEST_CASE(DecodeRepeatedNonRepeatableHeader)
292{
293 static const uint8_t inputBlock[] = {
294 0x64, 0x06, // LpPacket
295 0x52, 0x01, // FragIndex
296 0x00,
297 0x52, 0x01, // FragIndex
298 0x01,
299 };
300
301 Packet packet;
302 Block wire(inputBlock, sizeof(inputBlock));
303 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
304}
305
306BOOST_AUTO_TEST_CASE(DecodeRepeatedFragment)
307{
308 static const uint8_t inputBlock[] = {
309 0x64, 0x08, // LpPacket
310 0x50, 0x02, // Fragment
311 0x03, 0xe8,
312 0x50, 0x02, // Fragment
313 0x03, 0xe9,
314 };
315
316 Packet packet;
317 Block wire(inputBlock, sizeof(inputBlock));
318 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
319}
320
321BOOST_AUTO_TEST_CASE(DecodeWrongOrderAmongHeaders)
322{
323 static const uint8_t inputBlock[] = {
324 0x64, 0x0a, // LpPacket
325 0x53, 0x01, // FragCount
326 0x01,
327 0x52, 0x01, // FragIndex
328 0x00,
329 0x50, 0x02, // Fragment
330 0x03, 0xe8,
331 };
332
333 Packet packet;
334 Block wire(inputBlock, sizeof(inputBlock));
335 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
336}
337
338BOOST_AUTO_TEST_CASE(DecodeWrongOrderFragment)
339{
340 static const uint8_t inputBlock[] = {
341 0x64, 0x0a, // LpPacket
342 0x52, 0x01, // FragIndex
343 0x00,
344 0x50, 0x02, // Fragment
345 0x03, 0xe8,
346 0x53, 0x01, // FragCount
347 0x01,
348 };
349
350 Packet packet;
351 Block wire(inputBlock, sizeof(inputBlock));
352 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
353}
354
355BOOST_AUTO_TEST_CASE(DecodeIgnoredHeader)
356{
357 static const uint8_t inputBlock[] = {
358 0x64, 0x0c, // LpPacket
359 0x52, 0x01, // FragIndex
360 0x00,
Eric Newberry3ed62472016-12-11 22:11:38 -0700361 0xfd, 0x03, 0x24, 0x01, // unknown TLV-TYPE 804 (ignored)
Eric Newberry261dbc22015-07-22 23:18:18 -0700362 0x02,
363 0x50, 0x02, // Fragment
364 0x03, 0xe8,
365 };
366
367 Packet packet;
368 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000369 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700370 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
371 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
372}
373
374BOOST_AUTO_TEST_CASE(DecodeUnrecognizedHeader)
375{
376 static const uint8_t inputBlock[] = {
377 0x64, 0x0c, // LpPacket
378 0x52, 0x01, // FragIndex
379 0x00,
380 0xfd, 0x03, 0x22, 0x01, // unknown TLV-TYPE 802 (cannot ignore)
381 0x02,
382 0x50, 0x02, // Fragment
383 0x03, 0xe8,
384 };
385
386 Packet packet;
387 Block wire(inputBlock, sizeof(inputBlock));
388 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
389}
390
391BOOST_AUTO_TEST_CASE(DecodeBareNetworkLayerPacket)
392{
393 static const uint8_t inputBlock[] = {
394 0x05, 0x0a, // Interest
395 0x07, 0x02, // Name
396 0x03, 0xe8,
397 0x0a, 0x04, // Nonce
398 0x01, 0x02, 0x03, 0x04,
399 };
400
401 Packet packet;
402 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000403 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700404 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
405
Junxiao Shic53df032019-01-14 23:33:25 +0000406 Block encoded = packet.wireEncode();
Eric Newberry83872fd2015-08-06 17:01:24 -0700407 BOOST_CHECK_EQUAL_COLLECTIONS(inputBlock, inputBlock + sizeof(inputBlock),
Eric Newberry261dbc22015-07-22 23:18:18 -0700408 encoded.begin(), encoded.end());
409}
410
Junxiao Shic53df032019-01-14 23:33:25 +0000411BOOST_AUTO_TEST_CASE(DecodeSeqNum)
412{
413 Packet packet;
414
415 // Sequence number is fixed-width, not NonNegativeInteger
416 packet.wireDecode("640A 5104A4A5A6A7 5002FFFF"_block);
417 BOOST_CHECK_THROW(packet.get<SequenceField>(), ndn::tlv::Error);
418
419 packet.wireDecode("640E 5108A0A1A2A3A4A5A6A7 5002FFFF"_block);
420 BOOST_CHECK_EQUAL(packet.get<SequenceField>(), 0xA0A1A2A3A4A5A6A7);
421}
422
Eric Newberry43bf6bb2015-10-09 16:12:09 -0700423BOOST_AUTO_TEST_CASE(DecodeUnrecognizedTlvType)
424{
425 Packet packet;
426 Block wire = encoding::makeEmptyBlock(ndn::tlv::Name);
427 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
428}
429
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -0500430BOOST_FIXTURE_TEST_CASE(DecodePrefixAnnouncement, ndn::tests::KeyChainFixture)
Teng Liange3ecad72018-08-28 21:12:53 -0700431{
432 // Construct Data which prefix announcement is attached to
Davide Pesavento14c56cd2020-05-21 01:44:03 -0400433 auto data0 = ndn::tests::makeData("/edu/ua/cs/news/index.html");
Teng Liange3ecad72018-08-28 21:12:53 -0700434
Teng Liange3ecad72018-08-28 21:12:53 -0700435 Packet packet0;
Davide Pesavento14c56cd2020-05-21 01:44:03 -0400436 packet0.wireDecode(data0->wireEncode());
Teng Liange3ecad72018-08-28 21:12:53 -0700437
438 // Construct Prefix Announcement
439 PrefixAnnouncement pa;
440 pa.setAnnouncedName("/net/example");
441 pa.setExpiration(5_min);
442 pa.setValidityPeriod(security::ValidityPeriod(time::fromIsoString("20181030T000000"),
443 time::fromIsoString("20181124T235959")));
444 pa.toData(m_keyChain, signingWithSha256(), 1);
445 PrefixAnnouncementHeader pah0(pa);
Junxiao Shic53df032019-01-14 23:33:25 +0000446 packet0.add<PrefixAnnouncementField>(pah0);
447 Block encoded = packet0.wireEncode();
Teng Liange3ecad72018-08-28 21:12:53 -0700448
449 // check decoding
450 Packet packet1;
Junxiao Shic53df032019-01-14 23:33:25 +0000451 packet1.wireDecode(encoded);
Teng Liange3ecad72018-08-28 21:12:53 -0700452 BOOST_CHECK_EQUAL(true, packet1.has<PrefixAnnouncementField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000453 PrefixAnnouncementHeader pah1 = packet1.get<PrefixAnnouncementField>();
Teng Liange3ecad72018-08-28 21:12:53 -0700454 BOOST_CHECK_EQUAL(pah1.getPrefixAnn()->getAnnouncedName(), "/net/example");
455}
456
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100457BOOST_AUTO_TEST_SUITE_END() // TestPacket
458BOOST_AUTO_TEST_SUITE_END() // Lp
Eric Newberry261dbc22015-07-22 23:18:18 -0700459
460} // namespace tests
461} // namespace lp
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100462} // namespace ndn