blob: 073c3db71e0b8cdfd32c5f4d07ba1d9fded26b8a [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 Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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 Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070032
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033using namespace nfd::face;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070034
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040035class LpReassemblerFixture : public GlobalIoTimeFixture
Eric Newberry4c3e6b82015-11-10 16:48:42 -070036{
Davide Pesavento97210d52016-10-14 15:45:48 +020037protected:
Eric Newberry4c3e6b82015-11-10 16:48:42 -070038 LpReassemblerFixture()
39 {
40 reassembler.beforeTimeout.connect(
Teng Liangd94b7b32022-07-10 21:29:37 +080041 [this] (const EndpointId& remoteEp, size_t nDroppedFragments) {
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040042 timeoutHistory.emplace_back(remoteEp, nDroppedFragments);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070043 });
44 }
45
Davide Pesavento97210d52016-10-14 15:45:48 +020046protected:
Davide Pesaventoe4b22382018-06-10 14:37:24 -040047 LpReassembler reassembler{{}};
ashiqopu77d0bfd2019-02-20 20:37:31 +000048 std::vector<std::pair<EndpointId, size_t>> timeoutHistory;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070049
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040050 static constexpr uint8_t data[] = {
51 0x06, 0x08, // Data
52 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
53 };
Eric Newberry4c3e6b82015-11-10 16:48:42 -070054};
55
Davide Pesavento97210d52016-10-14 15:45:48 +020056BOOST_AUTO_TEST_SUITE(Face)
Eric Newberry4c3e6b82015-11-10 16:48:42 -070057BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture)
58
59BOOST_AUTO_TEST_SUITE(SingleFragment)
60
61BOOST_AUTO_TEST_CASE(Normal)
62{
63 ndn::Buffer dataBuffer(data, sizeof(data));
64
65 lp::Packet received;
66 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
67 received.add<lp::FragIndexField>(0);
68 received.add<lp::FragCountField>(1);
69 received.add<lp::SequenceField>(1000);
70 received.add<lp::NextHopFaceIdField>(200);
71
72 bool isComplete = false;
73 Block netPacket;
74 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +080075 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070076
77 BOOST_REQUIRE(isComplete);
78 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
79 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
80 BOOST_CHECK_EQUAL(reassembler.size(), 0);
81}
82
83BOOST_AUTO_TEST_CASE(OmitFragIndex)
84{
85 ndn::Buffer dataBuffer(data, sizeof(data));
86
87 lp::Packet received;
88 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
89 received.add<lp::FragCountField>(1);
90 received.add<lp::SequenceField>(1000);
91 received.add<lp::NextHopFaceIdField>(200);
92
93 bool isComplete = false;
94 Block netPacket;
95 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +080096 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070097
98 BOOST_REQUIRE(isComplete);
99 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
100 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
101}
102
103BOOST_AUTO_TEST_CASE(OmitFragCount)
104{
105 ndn::Buffer dataBuffer(data, sizeof(data));
106
107 lp::Packet received;
108 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
109 received.add<lp::FragIndexField>(0);
110 received.add<lp::SequenceField>(1000);
111 received.add<lp::NextHopFaceIdField>(200);
112
113 bool isComplete = false;
114 Block netPacket;
115 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +0800116 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700117
118 BOOST_REQUIRE(isComplete);
119 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
120 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
121}
122
123BOOST_AUTO_TEST_CASE(OmitFragIndexAndFragCount)
124{
125 ndn::Buffer dataBuffer(data, sizeof(data));
126
127 lp::Packet received;
128 received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end()));
129 received.add<lp::SequenceField>(1000);
130 received.add<lp::NextHopFaceIdField>(200);
131
132 bool isComplete = false;
133 Block netPacket;
134 lp::Packet packet;
Teng Liangd94b7b32022-07-10 21:29:37 +0800135 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700136
137 BOOST_REQUIRE(isComplete);
138 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
139 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
140}
141
142BOOST_AUTO_TEST_SUITE_END() // SingleFragment
143
144BOOST_AUTO_TEST_SUITE(MultiFragment)
145
146BOOST_AUTO_TEST_CASE(Normal)
147{
148 ndn::Buffer data1Buffer(data, 4);
149 ndn::Buffer data2Buffer(data + 4, 4);
150 ndn::Buffer data3Buffer(data + 8, 2);
151
152 lp::Packet received1;
153 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
154 received1.add<lp::FragIndexField>(0);
155 received1.add<lp::FragCountField>(3);
156 received1.add<lp::SequenceField>(1000);
157 received1.add<lp::NextHopFaceIdField>(200);
158
159 lp::Packet received2;
160 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
161 received2.add<lp::FragIndexField>(1);
162 received2.add<lp::FragCountField>(3);
163 received2.add<lp::SequenceField>(1001);
164
165 lp::Packet received3;
166 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
167 received3.add<lp::FragIndexField>(2);
168 received3.add<lp::FragCountField>(3);
169 received3.add<lp::SequenceField>(1002);
170
171 bool isComplete = false;
172 Block netPacket;
173 lp::Packet packet;
174
Teng Liangd94b7b32022-07-10 21:29:37 +0800175 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
176 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700177 BOOST_CHECK_EQUAL(reassembler.size(), 1);
178
Teng Liangd94b7b32022-07-10 21:29:37 +0800179 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
180 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700181 BOOST_CHECK_EQUAL(reassembler.size(), 1);
182
Teng Liangd94b7b32022-07-10 21:29:37 +0800183 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700184 BOOST_REQUIRE(isComplete);
185 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
186 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
187 BOOST_CHECK_EQUAL(reassembler.size(), 0);
188}
189
190BOOST_AUTO_TEST_CASE(OmitFragIndex0)
191{
192 ndn::Buffer data1Buffer(data, 4);
193 ndn::Buffer data2Buffer(data + 4, 4);
194 ndn::Buffer data3Buffer(data + 8, 2);
195
196 lp::Packet received1;
197 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
198 received1.add<lp::FragCountField>(3);
199 received1.add<lp::SequenceField>(1000);
200 received1.add<lp::NextHopFaceIdField>(200);
201
202 lp::Packet received2;
203 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
204 received2.add<lp::FragIndexField>(1);
205 received2.add<lp::FragCountField>(3);
206 received2.add<lp::SequenceField>(1001);
207
208 lp::Packet received3;
209 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
210 received3.add<lp::FragIndexField>(2);
211 received3.add<lp::FragCountField>(3);
212 received3.add<lp::SequenceField>(1002);
213
214 bool isComplete = false;
215 Block netPacket;
216 lp::Packet packet;
217
Teng Liangd94b7b32022-07-10 21:29:37 +0800218 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
219 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700220
Teng Liangd94b7b32022-07-10 21:29:37 +0800221 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
222 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700223
Teng Liangd94b7b32022-07-10 21:29:37 +0800224 std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700225 BOOST_REQUIRE(isComplete);
226 BOOST_CHECK(packet.has<lp::NextHopFaceIdField>());
227 BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end());
228}
229
230BOOST_AUTO_TEST_CASE(OutOfOrder)
231{
232 ndn::Buffer data0Buffer(data, 4);
233 ndn::Buffer data1Buffer(data + 4, 4);
234 ndn::Buffer data2Buffer(data + 8, 2);
235
236 lp::Packet frag0;
237 frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
238 frag0.add<lp::FragIndexField>(0);
239 frag0.add<lp::FragCountField>(3);
240 frag0.add<lp::SequenceField>(1000);
241 frag0.add<lp::NextHopFaceIdField>(200);
242
243 lp::Packet frag1;
244 frag1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
245 frag1.add<lp::FragIndexField>(1);
246 frag1.add<lp::FragCountField>(3);
247 frag1.add<lp::SequenceField>(1001);
248
249 lp::Packet frag2;
250 frag2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
251 frag2.add<lp::FragIndexField>(2);
252 frag2.add<lp::FragCountField>(3);
253 frag2.add<lp::SequenceField>(1002);
254
255 bool isComplete = false;
256
Teng Liangd94b7b32022-07-10 21:29:37 +0800257 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag2);
258 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700259
Teng Liangd94b7b32022-07-10 21:29:37 +0800260 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
261 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700262
Teng Liangd94b7b32022-07-10 21:29:37 +0800263 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag1);
264 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700265}
266
267BOOST_AUTO_TEST_CASE(Duplicate)
268{
269 ndn::Buffer data0Buffer(data, 5);
270
271 lp::Packet frag0;
272 frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end()));
273 frag0.add<lp::FragIndexField>(0);
274 frag0.add<lp::FragCountField>(2);
275 frag0.add<lp::SequenceField>(1000);
276
277 bool isComplete = false;
278
Teng Liangd94b7b32022-07-10 21:29:37 +0800279 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
280 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700281
Teng Liangd94b7b32022-07-10 21:29:37 +0800282 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0);
283 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700284}
285
286BOOST_AUTO_TEST_CASE(Timeout)
287{
288 ndn::Buffer data1Buffer(data, 5);
289 ndn::Buffer data2Buffer(data + 5, 5);
290
291 lp::Packet received1;
292 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
293 received1.add<lp::FragIndexField>(0);
294 received1.add<lp::FragCountField>(2);
295 received1.add<lp::SequenceField>(1000);
296 received1.add<lp::NextHopFaceIdField>(200);
297
298 lp::Packet received2;
299 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
300 received2.add<lp::FragIndexField>(1);
301 received2.add<lp::FragCountField>(2);
302 received2.add<lp::SequenceField>(1001);
303
Teng Liangd94b7b32022-07-10 21:29:37 +0800304 const EndpointId REMOTE_EP = ethernet::getDefaultMulticastAddress();
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700305 bool isComplete = false;
306 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1);
Teng Liangd94b7b32022-07-10 21:29:37 +0800307 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700308 BOOST_CHECK_EQUAL(reassembler.size(), 1);
309 BOOST_CHECK(timeoutHistory.empty());
310
Davide Pesavento14e71f02019-03-28 17:35:25 -0400311 advanceClocks(1_ms, 600);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700312 BOOST_CHECK_EQUAL(reassembler.size(), 0);
313 BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1);
Teng Liangd94b7b32022-07-10 21:29:37 +0800314 BOOST_CHECK(std::get<0>(timeoutHistory.back()) == REMOTE_EP);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700315 BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1);
316
317 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2);
Teng Liangd94b7b32022-07-10 21:29:37 +0800318 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700319}
320
321BOOST_AUTO_TEST_CASE(MissingSequence)
322{
323 ndn::Buffer data1Buffer(data, 4);
324 ndn::Buffer data2Buffer(data + 4, 4);
325 ndn::Buffer data3Buffer(data + 8, 2);
326
327 lp::Packet received1;
328 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
329 received1.add<lp::FragIndexField>(0);
330 received1.add<lp::FragCountField>(3);
331 received1.add<lp::SequenceField>(1000);
332 received1.add<lp::NextHopFaceIdField>(200);
333
334 lp::Packet received2;
335 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
336 received2.add<lp::FragIndexField>(1);
337 received2.add<lp::FragCountField>(3);
338
339 lp::Packet received3;
340 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
341 received3.add<lp::FragIndexField>(2);
342 received3.add<lp::FragCountField>(3);
343 received3.add<lp::SequenceField>(1002);
344
345 bool isComplete = false;
346
Teng Liangd94b7b32022-07-10 21:29:37 +0800347 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
348 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700349
Teng Liangd94b7b32022-07-10 21:29:37 +0800350 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
351 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700352
Teng Liangd94b7b32022-07-10 21:29:37 +0800353 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
354 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700355
Davide Pesavento14e71f02019-03-28 17:35:25 -0400356 advanceClocks(1_ms, 600);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700357
Teng Liangd94b7b32022-07-10 21:29:37 +0800358 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
359 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700360}
361
362BOOST_AUTO_TEST_CASE(FragCountOverLimit)
363{
364 ndn::Buffer data1Buffer(data, sizeof(data));
365
366 lp::Packet received1;
367 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
368 received1.add<lp::FragIndexField>(0);
369 received1.add<lp::FragCountField>(256);
370 received1.add<lp::SequenceField>(1000);
371 received1.add<lp::NextHopFaceIdField>(200);
372
373 bool isComplete = false;
374
Teng Liangd94b7b32022-07-10 21:29:37 +0800375 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
376 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700377}
378
379BOOST_AUTO_TEST_CASE(MissingFragCount)
380{
381 ndn::Buffer data1Buffer(data, 4);
382 ndn::Buffer data2Buffer(data + 4, 4);
383 ndn::Buffer data3Buffer(data + 8, 2);
384
385 lp::Packet received1;
386 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
387 received1.add<lp::FragIndexField>(0);
388 received1.add<lp::FragCountField>(3);
389 received1.add<lp::SequenceField>(1000);
390 received1.add<lp::NextHopFaceIdField>(200);
391
392 lp::Packet received2;
393 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
394 received2.add<lp::FragIndexField>(1);
395 received2.add<lp::FragCountField>(50);
396 received2.add<lp::SequenceField>(1001);
397
398 lp::Packet received3;
399 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
400 received3.add<lp::FragIndexField>(2);
401 received3.add<lp::FragCountField>(3);
402 received3.add<lp::SequenceField>(1002);
403
404 bool isComplete = false;
405
Teng Liangd94b7b32022-07-10 21:29:37 +0800406 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
407 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700408
Teng Liangd94b7b32022-07-10 21:29:37 +0800409 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
410 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700411
Teng Liangd94b7b32022-07-10 21:29:37 +0800412 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
413 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700414}
415
416BOOST_AUTO_TEST_CASE(OverFragCount)
417{
418 LpReassembler::Options options;
419 options.nMaxFragments = 2;
420 reassembler.setOptions(options);
421
422 ndn::Buffer data1Buffer(data, 4);
423 ndn::Buffer data2Buffer(data + 4, 4);
424 ndn::Buffer data3Buffer(data + 8, 2);
425
426 lp::Packet received1;
427 received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
428 received1.add<lp::FragIndexField>(0);
429 received1.add<lp::FragCountField>(3);
430 received1.add<lp::SequenceField>(1000);
431 received1.add<lp::NextHopFaceIdField>(200);
432
433 lp::Packet received2;
434 received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
435 received2.add<lp::FragIndexField>(1);
436 received2.add<lp::FragCountField>(3);
437 received2.add<lp::SequenceField>(1001);
438
439 lp::Packet received3;
440 received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end()));
441 received3.add<lp::FragIndexField>(2);
442 received3.add<lp::FragCountField>(3);
443 received3.add<lp::SequenceField>(1002);
444
445 bool isComplete = false;
446
Teng Liangd94b7b32022-07-10 21:29:37 +0800447 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1);
448 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700449
Teng Liangd94b7b32022-07-10 21:29:37 +0800450 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2);
451 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700452
Teng Liangd94b7b32022-07-10 21:29:37 +0800453 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3);
454 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700455}
456
457BOOST_AUTO_TEST_SUITE_END() // MultiFragment
458
Davide Pesavento97210d52016-10-14 15:45:48 +0200459BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints)
460
461BOOST_AUTO_TEST_CASE(Normal)
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700462{
463 ndn::Buffer data1Buffer(data, 5);
464 ndn::Buffer data2Buffer(data + 5, 5);
465
466 lp::Packet frag1_1;
467 frag1_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
468 frag1_1.add<lp::FragIndexField>(0);
469 frag1_1.add<lp::FragCountField>(2);
470 frag1_1.add<lp::SequenceField>(2000);
471 frag1_1.add<lp::NextHopFaceIdField>(200);
472
473 lp::Packet frag1_2;
474 frag1_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
475 frag1_2.add<lp::FragIndexField>(1);
476 frag1_2.add<lp::FragCountField>(2);
477 frag1_2.add<lp::SequenceField>(2001);
478
479 lp::Packet frag2_1;
480 frag2_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end()));
481 frag2_1.add<lp::FragIndexField>(0);
482 frag2_1.add<lp::FragCountField>(2);
483 frag2_1.add<lp::SequenceField>(2000);
484 frag2_1.add<lp::NextHopFaceIdField>(200);
485
486 lp::Packet frag2_2;
487 frag2_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end()));
488 frag2_2.add<lp::FragIndexField>(1);
489 frag2_2.add<lp::FragCountField>(2);
490 frag2_2.add<lp::SequenceField>(2001);
491
492 bool isComplete = false;
493
Teng Liangd94b7b32022-07-10 21:29:37 +0800494 const EndpointId REMOTE_EP_1 = ethernet::Address::fromString("11:22:33:45:67:89");
495 const EndpointId REMOTE_EP_2 = ethernet::Address::fromString("11:22:33:ab:cd:ef");
496
497 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_1);
498 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700499 BOOST_CHECK_EQUAL(reassembler.size(), 1);
500
Teng Liangd94b7b32022-07-10 21:29:37 +0800501 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_2);
502 BOOST_TEST(!isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700503 BOOST_CHECK_EQUAL(reassembler.size(), 2);
504
Teng Liangd94b7b32022-07-10 21:29:37 +0800505 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_2);
506 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700507 BOOST_CHECK_EQUAL(reassembler.size(), 1);
508
Teng Liangd94b7b32022-07-10 21:29:37 +0800509 std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_1);
510 BOOST_TEST(isComplete);
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700511 BOOST_CHECK_EQUAL(reassembler.size(), 0);
512}
513
Davide Pesavento97210d52016-10-14 15:45:48 +0200514BOOST_AUTO_TEST_SUITE_END() // MultipleRemoteEndpoints
515
Eric Newberry4c3e6b82015-11-10 16:48:42 -0700516BOOST_AUTO_TEST_SUITE_END() // TestLpReassembler
517BOOST_AUTO_TEST_SUITE_END() // Face
518
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400519} // namespace nfd::tests