Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 9a63bf2 | 2023-11-11 17:12:51 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, Regents of the University of California, |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 4 | * 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 Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 29 | #include "tests/daemon/global-io-fixture.hpp" |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 30 | |
Davide Pesavento | 9a63bf2 | 2023-11-11 17:12:51 -0500 | [diff] [blame^] | 31 | #include <ndn-cxx/lp/fields.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 35 | using namespace nfd::face; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 36 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 37 | class LpReassemblerFixture : public GlobalIoTimeFixture |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 38 | { |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 39 | protected: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 40 | LpReassemblerFixture() |
| 41 | { |
| 42 | reassembler.beforeTimeout.connect( |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 43 | [this] (const EndpointId& remoteEp, size_t nDroppedFragments) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 44 | timeoutHistory.emplace_back(remoteEp, nDroppedFragments); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 45 | }); |
| 46 | } |
| 47 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 48 | protected: |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 49 | LpReassembler reassembler{{}}; |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 50 | std::vector<std::pair<EndpointId, size_t>> timeoutHistory; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 51 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 52 | static constexpr uint8_t data[] = { |
| 53 | 0x06, 0x08, // Data |
| 54 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 55 | }; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 58 | BOOST_AUTO_TEST_SUITE(Face) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 59 | BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture) |
| 60 | |
| 61 | BOOST_AUTO_TEST_SUITE(SingleFragment) |
| 62 | |
| 63 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 77 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 78 | |
| 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 | |
| 85 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 98 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 99 | |
| 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 | |
| 105 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 118 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 119 | |
| 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 | |
| 125 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 137 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 138 | |
| 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 | |
| 144 | BOOST_AUTO_TEST_SUITE_END() // SingleFragment |
| 145 | |
| 146 | BOOST_AUTO_TEST_SUITE(MultiFragment) |
| 147 | |
| 148 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 177 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 178 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 180 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 181 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 182 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 183 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 184 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 185 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 186 | 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 | |
| 192 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 220 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 221 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 222 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 223 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 224 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 225 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 226 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 227 | 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 | |
| 232 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 259 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag2); |
| 260 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 261 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 262 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 263 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 264 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 265 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag1); |
| 266 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 281 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 282 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 283 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 284 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 285 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 306 | const EndpointId REMOTE_EP = ethernet::getDefaultMulticastAddress(); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 307 | bool isComplete = false; |
| 308 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 309 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 310 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 311 | BOOST_CHECK(timeoutHistory.empty()); |
| 312 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 313 | advanceClocks(1_ms, 600); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 314 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 315 | BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 316 | BOOST_CHECK(std::get<0>(timeoutHistory.back()) == REMOTE_EP); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 317 | BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1); |
| 318 | |
| 319 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 320 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 349 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 350 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 351 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 352 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 353 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 354 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 355 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 356 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 357 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 358 | advanceClocks(1_ms, 600); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 359 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 360 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 361 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 377 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 378 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 408 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 409 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 410 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 411 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 412 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 413 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 414 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 415 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 449 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 450 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 451 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 452 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 453 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 454 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 455 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 456 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | BOOST_AUTO_TEST_SUITE_END() // MultiFragment |
| 460 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 461 | BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints) |
| 462 | |
| 463 | BOOST_AUTO_TEST_CASE(Normal) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 464 | { |
| 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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 496 | 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 Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 501 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 502 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 503 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_2); |
| 504 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 505 | BOOST_CHECK_EQUAL(reassembler.size(), 2); |
| 506 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 507 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_2); |
| 508 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 509 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 510 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 511 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_1); |
| 512 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 513 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 514 | } |
| 515 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 516 | BOOST_AUTO_TEST_SUITE_END() // MultipleRemoteEndpoints |
| 517 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 518 | BOOST_AUTO_TEST_SUITE_END() // TestLpReassembler |
| 519 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 520 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 521 | } // namespace nfd::tests |