blob: 67e4d5594c3afbc38a3105559f85a0ea751a42c5 [file] [log] [blame]
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe4b22382018-06-10 14:37:24 -04002/*
Davide Pesavento9a63bf22023-11-11 17:12:51 -05003 * Copyright (c) 2014-2023, Regents of the University of California,
Eric Newberry4c3e6b82015-11-10 16:48:42 -07004 * 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 NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD 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 * NFD 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 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/lp-reassembler.hpp"
27
28#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/daemon/global-io-fixture.hpp"
Eric Newberry4c3e6b82015-11-10 16:48:42 -070030
Davide Pesavento9a63bf22023-11-11 17:12:51 -050031#include <ndn-cxx/lp/fields.hpp>
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::tests {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070034
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035using namespace nfd::face;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070036
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040037class LpReassemblerFixture : public GlobalIoTimeFixture
Eric Newberry4c3e6b82015-11-10 16:48:42 -070038{
Davide Pesavento97210d52016-10-14 15:45:48 +020039protected:
Eric Newberry4c3e6b82015-11-10 16:48:42 -070040 LpReassemblerFixture()
41 {
42 reassembler.beforeTimeout.connect(
Teng Liangd94b7b32022-07-10 21:29:37 +080043 [this] (const EndpointId& remoteEp, size_t nDroppedFragments) {
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040044 timeoutHistory.emplace_back(remoteEp, nDroppedFragments);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070045 });
46 }
47
Davide Pesavento97210d52016-10-14 15:45:48 +020048protected:
Davide Pesaventoe4b22382018-06-10 14:37:24 -040049 LpReassembler reassembler{{}};
ashiqopu77d0bfd2019-02-20 20:37:31 +000050 std::vector<std::pair<EndpointId, size_t>> timeoutHistory;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070051
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040052 static constexpr uint8_t data[] = {
53 0x06, 0x08, // Data
54 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
55 };
Eric Newberry4c3e6b82015-11-10 16:48:42 -070056};
57
Davide Pesavento97210d52016-10-14 15:45:48 +020058BOOST_AUTO_TEST_SUITE(Face)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070059BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture)
60
61BOOST_AUTO_TEST_SUITE(SingleFragment)
62
63BOOST_AUTO_TEST_CASE(Normal)
64{
65 ndn::Buffer dataBuffer(data, sizeof(data));
66
67 lp::Packet received;
68 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
69 received.add<lp::FragIndexField>(0);
70 received.add<lp::FragCountField>(1);
71 received.add<lp::SequenceField>(1000);
72 received.add<lp::NextHopFaceIdField>(200);
73
74 bool isComplete = false;
75 Block netPacket;
76 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +080077 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070078
79 BOOST_REQUIRE(isComplete);
80 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
81 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
82 BOOST_CHECK_EQUAL(reassembler.size(), 0);
83}
84
85BOOST_AUTO_TEST_CASE(OmitFragIndex)
86{
87 ndn::Buffer dataBuffer(data, sizeof(data));
88
89 lp::Packet received;
90 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
91 received.add<lp::FragCountField>(1);
92 received.add<lp::SequenceField>(1000);
93 received.add<lp::NextHopFaceIdField>(200);
94
95 bool isComplete = false;
96 Block netPacket;
97 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +080098 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070099
100 BOOST_REQUIRE(isComplete);
101 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
102 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
103}
104
105BOOST_AUTO_TEST_CASE(OmitFragCount)
106{
107 ndn::Buffer dataBuffer(data, sizeof(data));
108
109 lp::Packet received;
110 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
111 received.add<lp::FragIndexField>(0);
112 received.add<lp::SequenceField>(1000);
113 received.add<lp::NextHopFaceIdField>(200);
114
115 bool isComplete = false;
116 Block netPacket;
117 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +0800118 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700119
120 BOOST_REQUIRE(isComplete);
121 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
122 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
123}
124
125BOOST_AUTO_TEST_CASE(OmitFragIndexAndFragCount)
126{
127 ndn::Buffer dataBuffer(data, sizeof(data));
128
129 lp::Packet received;
130 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
131 received.add<lp::SequenceField>(1000);
132 received.add<lp::NextHopFaceIdField>(200);
133
134 bool isComplete = false;
135 Block netPacket;
136 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +0800137 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700138
139 BOOST_REQUIRE(isComplete);
140 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
141 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
142}
143
144BOOST_AUTO_TEST_SUITE_END() // SingleFragment
145
146BOOST_AUTO_TEST_SUITE(MultiFragment)
147
148BOOST_AUTO_TEST_CASE(Normal)
149{
150 ndn::Buffer data1Buffer(data, 4);
151 ndn::Buffer data2Buffer(data + 4, 4);
152 ndn::Buffer data3Buffer(data + 8, 2);
153
154 lp::Packet received1;
155 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
156 received1.add<lp::FragIndexField>(0);
157 received1.add<lp::FragCountField>(3);
158 received1.add<lp::SequenceField>(1000);
159 received1.add<lp::NextHopFaceIdField>(200);
160
161 lp::Packet received2;
162 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
163 received2.add<lp::FragIndexField>(1);
164 received2.add<lp::FragCountField>(3);
165 received2.add<lp::SequenceField>(1001);
166
167 lp::Packet received3;
168 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
169 received3.add<lp::FragIndexField>(2);
170 received3.add<lp::FragCountField>(3);
171 received3.add<lp::SequenceField>(1002);
172
173 bool isComplete = false;
174 Block netPacket;
175 lp::Packet packet;
176
Teng Liangd94b7b32022-07-10 21:29:37 +0800177 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
178 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700179 BOOST_CHECK_EQUAL(reassembler.size(), 1);
180
Teng Liangd94b7b32022-07-10 21:29:37 +0800181 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
182 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700183 BOOST_CHECK_EQUAL(reassembler.size(), 1);
184
Teng Liangd94b7b32022-07-10 21:29:37 +0800185 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700186 BOOST_REQUIRE(isComplete);
187 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
188 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
189 BOOST_CHECK_EQUAL(reassembler.size(), 0);
190}
191
192BOOST_AUTO_TEST_CASE(OmitFragIndex0)
193{
194 ndn::Buffer data1Buffer(data, 4);
195 ndn::Buffer data2Buffer(data + 4, 4);
196 ndn::Buffer data3Buffer(data + 8, 2);
197
198 lp::Packet received1;
199 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
200 received1.add<lp::FragCountField>(3);
201 received1.add<lp::SequenceField>(1000);
202 received1.add<lp::NextHopFaceIdField>(200);
203
204 lp::Packet received2;
205 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
206 received2.add<lp::FragIndexField>(1);
207 received2.add<lp::FragCountField>(3);
208 received2.add<lp::SequenceField>(1001);
209
210 lp::Packet received3;
211 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
212 received3.add<lp::FragIndexField>(2);
213 received3.add<lp::FragCountField>(3);
214 received3.add<lp::SequenceField>(1002);
215
216 bool isComplete = false;
217 Block netPacket;
218 lp::Packet packet;
219
Teng Liangd94b7b32022-07-10 21:29:37 +0800220 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
221 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700222
Teng Liangd94b7b32022-07-10 21:29:37 +0800223 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
224 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700225
Teng Liangd94b7b32022-07-10 21:29:37 +0800226 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700227 BOOST_REQUIRE(isComplete);
228 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
229 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
230}
231
232BOOST_AUTO_TEST_CASE(OutOfOrder)
233{
234 ndn::Buffer data0Buffer(data, 4);
235 ndn::Buffer data1Buffer(data + 4, 4);
236 ndn::Buffer data2Buffer(data + 8, 2);
237
238 lp::Packet frag0;
239 frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
240 frag0.add<lp::FragIndexField>(0);
241 frag0.add<lp::FragCountField>(3);
242 frag0.add<lp::SequenceField>(1000);
243 frag0.add<lp::NextHopFaceIdField>(200);
244
245 lp::Packet frag1;
246 frag1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
247 frag1.add<lp::FragIndexField>(1);
248 frag1.add<lp::FragCountField>(3);
249 frag1.add<lp::SequenceField>(1001);
250
251 lp::Packet frag2;
252 frag2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
253 frag2.add<lp::FragIndexField>(2);
254 frag2.add<lp::FragCountField>(3);
255 frag2.add<lp::SequenceField>(1002);
256
257 bool isComplete = false;
258
Teng Liangd94b7b32022-07-10 21:29:37 +0800259 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag2);
260 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700261
Teng Liangd94b7b32022-07-10 21:29:37 +0800262 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
263 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700264
Teng Liangd94b7b32022-07-10 21:29:37 +0800265 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag1);
266 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700267}
268
269BOOST_AUTO_TEST_CASE(Duplicate)
270{
271 ndn::Buffer data0Buffer(data, 5);
272
273 lp::Packet frag0;
274 frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
275 frag0.add<lp::FragIndexField>(0);
276 frag0.add<lp::FragCountField>(2);
277 frag0.add<lp::SequenceField>(1000);
278
279 bool isComplete = false;
280
Teng Liangd94b7b32022-07-10 21:29:37 +0800281 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
282 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700283
Teng Liangd94b7b32022-07-10 21:29:37 +0800284 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
285 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700286}
287
288BOOST_AUTO_TEST_CASE(Timeout)
289{
290 ndn::Buffer data1Buffer(data, 5);
291 ndn::Buffer data2Buffer(data + 5, 5);
292
293 lp::Packet received1;
294 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
295 received1.add<lp::FragIndexField>(0);
296 received1.add<lp::FragCountField>(2);
297 received1.add<lp::SequenceField>(1000);
298 received1.add<lp::NextHopFaceIdField>(200);
299
300 lp::Packet received2;
301 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
302 received2.add<lp::FragIndexField>(1);
303 received2.add<lp::FragCountField>(2);
304 received2.add<lp::SequenceField>(1001);
305
Teng Liangd94b7b32022-07-10 21:29:37 +0800306 const EndpointId REMOTE_EP = ethernet::getDefaultMulticastAddress();
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700307 bool isComplete = false;
308 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1);
Teng Liangd94b7b32022-07-10 21:29:37 +0800309 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700310 BOOST_CHECK_EQUAL(reassembler.size(), 1);
311 BOOST_CHECK(timeoutHistory.empty());
312
Davide Pesavento14e71f02019-03-28 17:35:25 -0400313 advanceClocks(1_ms, 600);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700314 BOOST_CHECK_EQUAL(reassembler.size(), 0);
315 BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1);
Teng Liangd94b7b32022-07-10 21:29:37 +0800316 BOOST_CHECK(std::get<0>(timeoutHistory.back()) == REMOTE_EP);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700317 BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1);
318
319 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2);
Teng Liangd94b7b32022-07-10 21:29:37 +0800320 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700321}
322
323BOOST_AUTO_TEST_CASE(MissingSequence)
324{
325 ndn::Buffer data1Buffer(data, 4);
326 ndn::Buffer data2Buffer(data + 4, 4);
327 ndn::Buffer data3Buffer(data + 8, 2);
328
329 lp::Packet received1;
330 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
331 received1.add<lp::FragIndexField>(0);
332 received1.add<lp::FragCountField>(3);
333 received1.add<lp::SequenceField>(1000);
334 received1.add<lp::NextHopFaceIdField>(200);
335
336 lp::Packet received2;
337 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
338 received2.add<lp::FragIndexField>(1);
339 received2.add<lp::FragCountField>(3);
340
341 lp::Packet received3;
342 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
343 received3.add<lp::FragIndexField>(2);
344 received3.add<lp::FragCountField>(3);
345 received3.add<lp::SequenceField>(1002);
346
347 bool isComplete = false;
348
Teng Liangd94b7b32022-07-10 21:29:37 +0800349 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
350 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700351
Teng Liangd94b7b32022-07-10 21:29:37 +0800352 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
353 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700354
Teng Liangd94b7b32022-07-10 21:29:37 +0800355 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
356 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700357
Davide Pesavento14e71f02019-03-28 17:35:25 -0400358 advanceClocks(1_ms, 600);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700359
Teng Liangd94b7b32022-07-10 21:29:37 +0800360 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
361 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700362}
363
364BOOST_AUTO_TEST_CASE(FragCountOverLimit)
365{
366 ndn::Buffer data1Buffer(data, sizeof(data));
367
368 lp::Packet received1;
369 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
370 received1.add<lp::FragIndexField>(0);
371 received1.add<lp::FragCountField>(256);
372 received1.add<lp::SequenceField>(1000);
373 received1.add<lp::NextHopFaceIdField>(200);
374
375 bool isComplete = false;
376
Teng Liangd94b7b32022-07-10 21:29:37 +0800377 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
378 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700379}
380
381BOOST_AUTO_TEST_CASE(MissingFragCount)
382{
383 ndn::Buffer data1Buffer(data, 4);
384 ndn::Buffer data2Buffer(data + 4, 4);
385 ndn::Buffer data3Buffer(data + 8, 2);
386
387 lp::Packet received1;
388 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
389 received1.add<lp::FragIndexField>(0);
390 received1.add<lp::FragCountField>(3);
391 received1.add<lp::SequenceField>(1000);
392 received1.add<lp::NextHopFaceIdField>(200);
393
394 lp::Packet received2;
395 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
396 received2.add<lp::FragIndexField>(1);
397 received2.add<lp::FragCountField>(50);
398 received2.add<lp::SequenceField>(1001);
399
400 lp::Packet received3;
401 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
402 received3.add<lp::FragIndexField>(2);
403 received3.add<lp::FragCountField>(3);
404 received3.add<lp::SequenceField>(1002);
405
406 bool isComplete = false;
407
Teng Liangd94b7b32022-07-10 21:29:37 +0800408 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
409 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700410
Teng Liangd94b7b32022-07-10 21:29:37 +0800411 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
412 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700413
Teng Liangd94b7b32022-07-10 21:29:37 +0800414 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
415 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700416}
417
418BOOST_AUTO_TEST_CASE(OverFragCount)
419{
420 LpReassembler::Options options;
421 options.nMaxFragments = 2;
422 reassembler.setOptions(options);
423
424 ndn::Buffer data1Buffer(data, 4);
425 ndn::Buffer data2Buffer(data + 4, 4);
426 ndn::Buffer data3Buffer(data + 8, 2);
427
428 lp::Packet received1;
429 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
430 received1.add<lp::FragIndexField>(0);
431 received1.add<lp::FragCountField>(3);
432 received1.add<lp::SequenceField>(1000);
433 received1.add<lp::NextHopFaceIdField>(200);
434
435 lp::Packet received2;
436 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
437 received2.add<lp::FragIndexField>(1);
438 received2.add<lp::FragCountField>(3);
439 received2.add<lp::SequenceField>(1001);
440
441 lp::Packet received3;
442 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
443 received3.add<lp::FragIndexField>(2);
444 received3.add<lp::FragCountField>(3);
445 received3.add<lp::SequenceField>(1002);
446
447 bool isComplete = false;
448
Teng Liangd94b7b32022-07-10 21:29:37 +0800449 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
450 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700451
Teng Liangd94b7b32022-07-10 21:29:37 +0800452 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
453 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700454
Teng Liangd94b7b32022-07-10 21:29:37 +0800455 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
456 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700457}
458
459BOOST_AUTO_TEST_SUITE_END() // MultiFragment
460
Davide Pesavento97210d52016-10-14 15:45:48 +0200461BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints)
462
463BOOST_AUTO_TEST_CASE(Normal)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700464{
465 ndn::Buffer data1Buffer(data, 5);
466 ndn::Buffer data2Buffer(data + 5, 5);
467
468 lp::Packet frag1_1;
469 frag1_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
470 frag1_1.add<lp::FragIndexField>(0);
471 frag1_1.add<lp::FragCountField>(2);
472 frag1_1.add<lp::SequenceField>(2000);
473 frag1_1.add<lp::NextHopFaceIdField>(200);
474
475 lp::Packet frag1_2;
476 frag1_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
477 frag1_2.add<lp::FragIndexField>(1);
478 frag1_2.add<lp::FragCountField>(2);
479 frag1_2.add<lp::SequenceField>(2001);
480
481 lp::Packet frag2_1;
482 frag2_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
483 frag2_1.add<lp::FragIndexField>(0);
484 frag2_1.add<lp::FragCountField>(2);
485 frag2_1.add<lp::SequenceField>(2000);
486 frag2_1.add<lp::NextHopFaceIdField>(200);
487
488 lp::Packet frag2_2;
489 frag2_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
490 frag2_2.add<lp::FragIndexField>(1);
491 frag2_2.add<lp::FragCountField>(2);
492 frag2_2.add<lp::SequenceField>(2001);
493
494 bool isComplete = false;
495
Teng Liangd94b7b32022-07-10 21:29:37 +0800496 const EndpointId REMOTE_EP_1 = ethernet::Address::fromString("11:22:33:45:67:89");
497 const EndpointId REMOTE_EP_2 = ethernet::Address::fromString("11:22:33:ab:cd:ef");
498
499 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_1);
500 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700501 BOOST_CHECK_EQUAL(reassembler.size(), 1);
502
Teng Liangd94b7b32022-07-10 21:29:37 +0800503 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_2);
504 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700505 BOOST_CHECK_EQUAL(reassembler.size(), 2);
506
Teng Liangd94b7b32022-07-10 21:29:37 +0800507 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_2);
508 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700509 BOOST_CHECK_EQUAL(reassembler.size(), 1);
510
Teng Liangd94b7b32022-07-10 21:29:37 +0800511 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_1);
512 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700513 BOOST_CHECK_EQUAL(reassembler.size(), 0);
514}
515
Davide Pesavento97210d52016-10-14 15:45:48 +0200516BOOST_AUTO_TEST_SUITE_END() // MultipleRemoteEndpoints
517
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700518BOOST_AUTO_TEST_SUITE_END() // TestLpReassembler
519BOOST_AUTO_TEST_SUITE_END() // Face
520
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400521} // namespace nfd::tests