blob: a8b58198f2d17fcfb6c48a409de422e2a7d530e2 [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/*
Junxiao Shic53df032019-01-14 23:33:25 +00003 * Copyright (c) 2013-2019 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"
24#include "ndn-cxx/security/signature-sha256-with-rsa.hpp"
Eric Newberry261dbc22015-07-22 23:18:18 -070025
Davide Pesavento7e780642018-11-24 15:51:34 -050026#include "tests/boost-test.hpp"
27#include "tests/identity-management-fixture.hpp"
Eric Newberry261dbc22015-07-22 23:18:18 -070028
29namespace ndn {
30namespace lp {
31namespace tests {
32
Davide Pesaventoeee3e822016-11-26 19:19:34 +010033BOOST_AUTO_TEST_SUITE(Lp)
34BOOST_AUTO_TEST_SUITE(TestPacket)
Eric Newberry261dbc22015-07-22 23:18:18 -070035
36BOOST_AUTO_TEST_CASE(FieldAccess)
37{
38 Packet packet;
39
Junxiao Shib6e276f2017-08-14 20:10:04 +000040 BOOST_CHECK(packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070041 BOOST_CHECK(!packet.has<FragIndexField>());
Junxiao Shic53df032019-01-14 23:33:25 +000042 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000043
44 packet.set<FragIndexField>(1234);
45 BOOST_CHECK(!packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070046 BOOST_CHECK(packet.has<FragIndexField>());
47 BOOST_CHECK_THROW(packet.add<FragIndexField>(5678), std::length_error);
Junxiao Shic53df032019-01-14 23:33:25 +000048 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 1);
49 BOOST_CHECK_EQUAL(packet.get<FragIndexField>(0), 1234);
Eric Newberry261dbc22015-07-22 23:18:18 -070050 BOOST_CHECK_THROW(packet.get<FragIndexField>(1), std::out_of_range);
51 BOOST_CHECK_THROW(packet.remove<FragIndexField>(1), std::out_of_range);
Junxiao Shib6e276f2017-08-14 20:10:04 +000052
53 packet.remove<FragIndexField>(0);
Junxiao Shic53df032019-01-14 23:33:25 +000054 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000055
56 packet.add<FragIndexField>(832);
57 std::vector<uint64_t> fragIndexes = packet.list<FragIndexField>();
Junxiao Shic53df032019-01-14 23:33:25 +000058 BOOST_CHECK_EQUAL(fragIndexes.size(), 1);
59 BOOST_CHECK_EQUAL(fragIndexes.at(0), 832);
Junxiao Shib6e276f2017-08-14 20:10:04 +000060
61 packet.clear<FragIndexField>();
Junxiao Shic53df032019-01-14 23:33:25 +000062 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 0);
63 BOOST_CHECK(packet.empty());
64
65 packet.add<AckField>(4001);
66 packet.add<AckField>(4002);
67 packet.add<AckField>(4003);
68 BOOST_CHECK_EQUAL(packet.count<AckField>(), 3);
69 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 4001);
70 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 4002);
71 BOOST_CHECK_EQUAL(packet.get<AckField>(2), 4003);
72
73 packet.remove<AckField>(1);
74 BOOST_CHECK_EQUAL(packet.count<AckField>(), 2);
75 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 4001);
76 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 4003);
77
78 packet.remove<AckField>(0);
79 packet.remove<AckField>(0);
80 BOOST_CHECK_EQUAL(packet.count<AckField>(), 0);
Junxiao Shib6e276f2017-08-14 20:10:04 +000081 BOOST_CHECK(packet.empty());
Eric Newberry261dbc22015-07-22 23:18:18 -070082}
83
Eric Newberry261dbc22015-07-22 23:18:18 -070084BOOST_AUTO_TEST_CASE(EncodeFragment)
85{
86 static const uint8_t expectedBlock[] = {
Junxiao Shi974b81a2018-04-21 01:37:03 +000087 0x64, 0x0e, // LpPacket
88 0x51, 0x08, // Sequence
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8,
Eric Newberry261dbc22015-07-22 23:18:18 -070090 0x50, 0x02, // Fragment
91 0x03, 0xe8,
92 };
93
94 Buffer buf(2);
95 buf[0] = 0x03;
96 buf[1] = 0xe8;
97
98 Packet packet;
Junxiao Shi974b81a2018-04-21 01:37:03 +000099 packet.add<FragmentField>(std::make_pair(buf.begin(), buf.end()));
100 packet.add<SequenceField>(1000);
101 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700102 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
103 wire.begin(), wire.end());
104}
105
106BOOST_AUTO_TEST_CASE(EncodeSubTlv)
107{
108 static const uint8_t expectedBlock[] = {
109 0x64, 0x09, // LpPacket
110 0xfd, 0x03, 0x20, 0x05, // Nack
111 0xfd, 0x03, 0x21, 0x01, // NackReason
112 0x64,
113 };
114
115 NackHeader nack;
116 nack.setReason(NackReason::DUPLICATE);
117
118 Packet packet;
Junxiao Shic53df032019-01-14 23:33:25 +0000119 packet.add<NackField>(nack);
120 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700121 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
122 wire.begin(), wire.end());
123}
124
Teng Liang02960742017-10-24 00:36:45 -0700125BOOST_AUTO_TEST_CASE(EncodeZeroLengthTlv)
126{
127 static const uint8_t expectedBlock[] = {
128 0x64, 0x04, // LpPacket
129 0xfd, 0x03, 0x4c, 0x00, // NonDiscovery
130 };
131
Junxiao Shic53df032019-01-14 23:33:25 +0000132 Packet packet1;
133 packet1.set<NonDiscoveryField>(EmptyValue{});
134 Block wire = packet1.wireEncode();
Teng Liang02960742017-10-24 00:36:45 -0700135 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
136 wire.begin(), wire.end());
137
Junxiao Shic53df032019-01-14 23:33:25 +0000138 Packet packet2;
139 packet2.add<NonDiscoveryField>(EmptyValue{});
140 wire = packet2.wireEncode();
Teng Liang02960742017-10-24 00:36:45 -0700141 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
142 wire.begin(), wire.end());
143}
144
Eric Newberry261dbc22015-07-22 23:18:18 -0700145BOOST_AUTO_TEST_CASE(EncodeSortOrder)
146{
147 static const uint8_t expectedBlock[] = {
Junxiao Shi974b81a2018-04-21 01:37:03 +0000148 0x64, 0x2e, // LpPacket
Eric Newberry261dbc22015-07-22 23:18:18 -0700149 0x52, 0x01, // FragIndex
150 0x00,
151 0x53, 0x01, // FragCount
152 0x01,
Junxiao Shi974b81a2018-04-21 01:37:03 +0000153 0xfd, 0x03, 0x44, 0x08, // Ack
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
155 0xfd, 0x03, 0x44, 0x08, // Ack
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
157 0xfd, 0x03, 0x44, 0x08, // Ack
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
Eric Newberry261dbc22015-07-22 23:18:18 -0700159 0x50, 0x02, // Fragment
160 0x03, 0xe8,
161 };
162
163 Buffer frag(2);
164 frag[0] = 0x03;
165 frag[1] = 0xe8;
166
167 Packet packet;
Junxiao Shic53df032019-01-14 23:33:25 +0000168 packet.add<FragmentField>(std::make_pair(frag.begin(), frag.end()));
169 packet.add<FragIndexField>(0);
170 packet.add<AckField>(2);
171 packet.wireEncode();
172 packet.add<FragCountField>(1);
173 packet.wireEncode();
174 packet.add<AckField>(4);
175 packet.wireEncode();
176 packet.add<AckField>(3);
177 Block wire = packet.wireEncode();
Eric Newberry261dbc22015-07-22 23:18:18 -0700178 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
179 wire.begin(), wire.end());
180}
181
182BOOST_AUTO_TEST_CASE(DecodeNormal)
183{
184 static const uint8_t inputBlock[] = {
Junxiao Shic53df032019-01-14 23:33:25 +0000185 0x64, 0x2e, // LpPacket
Eric Newberry261dbc22015-07-22 23:18:18 -0700186 0x52, 0x01, // FragIndex
187 0x00,
188 0x53, 0x01, // FragCount
189 0x01,
Junxiao Shic53df032019-01-14 23:33:25 +0000190 0xfd, 0x03, 0x44, 0x08, // Ack
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
192 0xfd, 0x03, 0x44, 0x08, // Ack
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
194 0xfd, 0x03, 0x44, 0x08, // Ack
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
Eric Newberry261dbc22015-07-22 23:18:18 -0700196 0x50, 0x02, // Fragment
197 0x03, 0xe8,
198 };
199
200 Packet packet;
201 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000202 packet.wireDecode(wire);
203
204 BOOST_CHECK_EQUAL(packet.count<FragIndexField>(), 1);
205 BOOST_CHECK_EQUAL(packet.get<FragIndexField>(), 0);
206
207 BOOST_CHECK_EQUAL(packet.count<FragCountField>(), 1);
208 BOOST_CHECK_EQUAL(packet.get<FragCountField>(), 1);
209
210 BOOST_CHECK_EQUAL(packet.count<AckField>(), 3);
211 BOOST_CHECK_EQUAL(packet.get<AckField>(), 1);
212 BOOST_CHECK_EQUAL(packet.get<AckField>(0), 1);
213 BOOST_CHECK_EQUAL(packet.get<AckField>(1), 3);
214 BOOST_CHECK_EQUAL(packet.get<AckField>(2), 2);
215
216 BOOST_CHECK_EQUAL(packet.count<FragmentField>(), 1);
Eric Newberry261dbc22015-07-22 23:18:18 -0700217 Buffer::const_iterator first, last;
Junxiao Shic53df032019-01-14 23:33:25 +0000218 std::tie(first, last) = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700219 BOOST_CHECK_EQUAL(2, last - first);
220 BOOST_CHECK_EQUAL(0x03, *first);
221 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
Eric Newberry261dbc22015-07-22 23:18:18 -0700222}
223
224BOOST_AUTO_TEST_CASE(DecodeIdle)
225{
226 static const uint8_t inputBlock[] = {
227 0x64, 0x06, // LpPacket
228 0x52, 0x01, // FragIndex
229 0x00,
230 0x53, 0x01, // FragCount
231 0x01,
232 };
233
234 Packet packet;
235 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000236 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700237 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
238 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
239 BOOST_CHECK_EQUAL(1, packet.count<FragCountField>());
240 BOOST_CHECK_EQUAL(0, packet.get<FragIndexField>(0));
241 BOOST_CHECK_EQUAL(1, packet.get<FragCountField>(0));
242}
243
244BOOST_AUTO_TEST_CASE(DecodeFragment)
245{
246 static const uint8_t inputBlock[] = {
247 0x64, 0x04, // LpPacket
248 0x50, 0x02, // Fragment
249 0x03, 0xe8,
250 };
251
252 Packet packet;
253 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000254 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700255 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
256 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
257 Buffer::const_iterator first, last;
Junxiao Shic53df032019-01-14 23:33:25 +0000258 std::tie(first, last) = packet.get<FragmentField>(0);
Eric Newberry261dbc22015-07-22 23:18:18 -0700259 BOOST_CHECK_EQUAL(2, last - first);
260 BOOST_CHECK_EQUAL(0x03, *first);
261 BOOST_CHECK_EQUAL(0xe8, *(last - 1));
262}
263
Teng Liang02960742017-10-24 00:36:45 -0700264BOOST_AUTO_TEST_CASE(DecodeNonDiscoveryHeader)
265{
266 static const uint8_t inputBlock[] = {
267 0x64, 0x04, // LpPacket
268 0xfd, 0x03, 0x4c, 0x00, // NonDiscovery
269 };
270
271 Packet packet;
272 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000273 packet.wireDecode(wire);
Teng Liang02960742017-10-24 00:36:45 -0700274 BOOST_CHECK_EQUAL(true, packet.has<NonDiscoveryField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000275 packet.get<NonDiscoveryField>();
Teng Liang02960742017-10-24 00:36:45 -0700276}
277
Eric Newberry261dbc22015-07-22 23:18:18 -0700278BOOST_AUTO_TEST_CASE(DecodeEmpty)
279{
280 static const uint8_t inputBlock[] = {
281 0x64, 0x00, // LpPacket
282 };
283
284 Packet packet;
285 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000286 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700287 BOOST_CHECK_EQUAL(0, packet.count<FragmentField>());
288 BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
Teng Liang02960742017-10-24 00:36:45 -0700289 BOOST_CHECK_EQUAL(false, packet.has<NonDiscoveryField>());
Eric Newberry261dbc22015-07-22 23:18:18 -0700290}
291
292BOOST_AUTO_TEST_CASE(DecodeRepeatedNonRepeatableHeader)
293{
294 static const uint8_t inputBlock[] = {
295 0x64, 0x06, // LpPacket
296 0x52, 0x01, // FragIndex
297 0x00,
298 0x52, 0x01, // FragIndex
299 0x01,
300 };
301
302 Packet packet;
303 Block wire(inputBlock, sizeof(inputBlock));
304 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
305}
306
307BOOST_AUTO_TEST_CASE(DecodeRepeatedFragment)
308{
309 static const uint8_t inputBlock[] = {
310 0x64, 0x08, // LpPacket
311 0x50, 0x02, // Fragment
312 0x03, 0xe8,
313 0x50, 0x02, // Fragment
314 0x03, 0xe9,
315 };
316
317 Packet packet;
318 Block wire(inputBlock, sizeof(inputBlock));
319 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
320}
321
322BOOST_AUTO_TEST_CASE(DecodeWrongOrderAmongHeaders)
323{
324 static const uint8_t inputBlock[] = {
325 0x64, 0x0a, // LpPacket
326 0x53, 0x01, // FragCount
327 0x01,
328 0x52, 0x01, // FragIndex
329 0x00,
330 0x50, 0x02, // Fragment
331 0x03, 0xe8,
332 };
333
334 Packet packet;
335 Block wire(inputBlock, sizeof(inputBlock));
336 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
337}
338
339BOOST_AUTO_TEST_CASE(DecodeWrongOrderFragment)
340{
341 static const uint8_t inputBlock[] = {
342 0x64, 0x0a, // LpPacket
343 0x52, 0x01, // FragIndex
344 0x00,
345 0x50, 0x02, // Fragment
346 0x03, 0xe8,
347 0x53, 0x01, // FragCount
348 0x01,
349 };
350
351 Packet packet;
352 Block wire(inputBlock, sizeof(inputBlock));
353 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
354}
355
356BOOST_AUTO_TEST_CASE(DecodeIgnoredHeader)
357{
358 static const uint8_t inputBlock[] = {
359 0x64, 0x0c, // LpPacket
360 0x52, 0x01, // FragIndex
361 0x00,
Eric Newberry3ed62472016-12-11 22:11:38 -0700362 0xfd, 0x03, 0x24, 0x01, // unknown TLV-TYPE 804 (ignored)
Eric Newberry261dbc22015-07-22 23:18:18 -0700363 0x02,
364 0x50, 0x02, // Fragment
365 0x03, 0xe8,
366 };
367
368 Packet packet;
369 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000370 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700371 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
372 BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
373}
374
375BOOST_AUTO_TEST_CASE(DecodeUnrecognizedHeader)
376{
377 static const uint8_t inputBlock[] = {
378 0x64, 0x0c, // LpPacket
379 0x52, 0x01, // FragIndex
380 0x00,
381 0xfd, 0x03, 0x22, 0x01, // unknown TLV-TYPE 802 (cannot ignore)
382 0x02,
383 0x50, 0x02, // Fragment
384 0x03, 0xe8,
385 };
386
387 Packet packet;
388 Block wire(inputBlock, sizeof(inputBlock));
389 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
390}
391
392BOOST_AUTO_TEST_CASE(DecodeBareNetworkLayerPacket)
393{
394 static const uint8_t inputBlock[] = {
395 0x05, 0x0a, // Interest
396 0x07, 0x02, // Name
397 0x03, 0xe8,
398 0x0a, 0x04, // Nonce
399 0x01, 0x02, 0x03, 0x04,
400 };
401
402 Packet packet;
403 Block wire(inputBlock, sizeof(inputBlock));
Junxiao Shic53df032019-01-14 23:33:25 +0000404 packet.wireDecode(wire);
Eric Newberry261dbc22015-07-22 23:18:18 -0700405 BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
406
Junxiao Shic53df032019-01-14 23:33:25 +0000407 Block encoded = packet.wireEncode();
Eric Newberry83872fd2015-08-06 17:01:24 -0700408 BOOST_CHECK_EQUAL_COLLECTIONS(inputBlock, inputBlock + sizeof(inputBlock),
Eric Newberry261dbc22015-07-22 23:18:18 -0700409 encoded.begin(), encoded.end());
410}
411
Junxiao Shic53df032019-01-14 23:33:25 +0000412BOOST_AUTO_TEST_CASE(DecodeSeqNum)
413{
414 Packet packet;
415
416 // Sequence number is fixed-width, not NonNegativeInteger
417 packet.wireDecode("640A 5104A4A5A6A7 5002FFFF"_block);
418 BOOST_CHECK_THROW(packet.get<SequenceField>(), ndn::tlv::Error);
419
420 packet.wireDecode("640E 5108A0A1A2A3A4A5A6A7 5002FFFF"_block);
421 BOOST_CHECK_EQUAL(packet.get<SequenceField>(), 0xA0A1A2A3A4A5A6A7);
422}
423
Eric Newberry43bf6bb2015-10-09 16:12:09 -0700424BOOST_AUTO_TEST_CASE(DecodeUnrecognizedTlvType)
425{
426 Packet packet;
427 Block wire = encoding::makeEmptyBlock(ndn::tlv::Name);
428 BOOST_CHECK_THROW(packet.wireDecode(wire), Packet::Error);
429}
430
Teng Liange3ecad72018-08-28 21:12:53 -0700431BOOST_FIXTURE_TEST_CASE(DecodePrefixAnnouncement, ndn::tests::IdentityManagementFixture)
432{
433 // Construct Data which prefix announcement is attached to
434 Data data0("/edu/ua/cs/news/index.html");
435 ndn::SignatureSha256WithRsa fakeSignature;
436 fakeSignature.setValue(ndn::encoding::makeEmptyBlock(ndn::tlv::SignatureValue));
437 data0.setSignature(fakeSignature);
438
439 Block wire;
440 wire = data0.wireEncode();
441 Packet packet0;
442 packet0.wireDecode(wire);
443
444 // Construct Prefix Announcement
445 PrefixAnnouncement pa;
446 pa.setAnnouncedName("/net/example");
447 pa.setExpiration(5_min);
448 pa.setValidityPeriod(security::ValidityPeriod(time::fromIsoString("20181030T000000"),
449 time::fromIsoString("20181124T235959")));
450 pa.toData(m_keyChain, signingWithSha256(), 1);
451 PrefixAnnouncementHeader pah0(pa);
Junxiao Shic53df032019-01-14 23:33:25 +0000452 packet0.add<PrefixAnnouncementField>(pah0);
453 Block encoded = packet0.wireEncode();
Teng Liange3ecad72018-08-28 21:12:53 -0700454
455 // check decoding
456 Packet packet1;
Junxiao Shic53df032019-01-14 23:33:25 +0000457 packet1.wireDecode(encoded);
Teng Liange3ecad72018-08-28 21:12:53 -0700458 BOOST_CHECK_EQUAL(true, packet1.has<PrefixAnnouncementField>());
Junxiao Shic53df032019-01-14 23:33:25 +0000459 PrefixAnnouncementHeader pah1 = packet1.get<PrefixAnnouncementField>();
Teng Liange3ecad72018-08-28 21:12:53 -0700460 BOOST_CHECK_EQUAL(pah1.getPrefixAnn()->getAnnouncedName(), "/net/example");
461}
462
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100463BOOST_AUTO_TEST_SUITE_END() // TestPacket
464BOOST_AUTO_TEST_SUITE_END() // Lp
Eric Newberry261dbc22015-07-22 23:18:18 -0700465
466} // namespace tests
467} // namespace lp
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100468} // namespace ndn