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 | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::tests { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | using namespace nfd::face; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 35 | class LpReassemblerFixture : public GlobalIoTimeFixture |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 36 | { |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 37 | protected: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 38 | LpReassemblerFixture() |
| 39 | { |
| 40 | reassembler.beforeTimeout.connect( |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 41 | [this] (const EndpointId& remoteEp, size_t nDroppedFragments) { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 42 | timeoutHistory.emplace_back(remoteEp, nDroppedFragments); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 43 | }); |
| 44 | } |
| 45 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 46 | protected: |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 47 | LpReassembler reassembler{{}}; |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 48 | std::vector<std::pair<EndpointId, size_t>> timeoutHistory; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 49 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 50 | static constexpr uint8_t data[] = { |
| 51 | 0x06, 0x08, // Data |
| 52 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 53 | }; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 56 | BOOST_AUTO_TEST_SUITE(Face) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 57 | BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture) |
| 58 | |
| 59 | BOOST_AUTO_TEST_SUITE(SingleFragment) |
| 60 | |
| 61 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 75 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 76 | |
| 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 | |
| 83 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 96 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 97 | |
| 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 | |
| 103 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 116 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 117 | |
| 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 | |
| 123 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 135 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 136 | |
| 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 | |
| 142 | BOOST_AUTO_TEST_SUITE_END() // SingleFragment |
| 143 | |
| 144 | BOOST_AUTO_TEST_SUITE(MultiFragment) |
| 145 | |
| 146 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 175 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 176 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 178 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 179 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 180 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 182 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 183 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 184 | 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 | |
| 190 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 218 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 219 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 220 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 221 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 222 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 223 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 224 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment({}, received3); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 225 | 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 | |
| 230 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 257 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag2); |
| 258 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 259 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 260 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 261 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 262 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 263 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag1); |
| 264 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 279 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 280 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 281 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 282 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, frag0); |
| 283 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 304 | const EndpointId REMOTE_EP = ethernet::getDefaultMulticastAddress(); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 305 | bool isComplete = false; |
| 306 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 307 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 309 | BOOST_CHECK(timeoutHistory.empty()); |
| 310 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 311 | advanceClocks(1_ms, 600); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 312 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 313 | BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 314 | BOOST_CHECK(std::get<0>(timeoutHistory.back()) == REMOTE_EP); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 315 | BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1); |
| 316 | |
| 317 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 318 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 347 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 348 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 349 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 350 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 351 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 352 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 353 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 354 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 355 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 356 | advanceClocks(1_ms, 600); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 357 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 358 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 359 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 375 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 376 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 406 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 407 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 408 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 409 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 410 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 411 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 412 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 413 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | BOOST_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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 447 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received1); |
| 448 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 449 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 450 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received2); |
| 451 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 452 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 453 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment({}, received3); |
| 454 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | BOOST_AUTO_TEST_SUITE_END() // MultiFragment |
| 458 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 459 | BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints) |
| 460 | |
| 461 | BOOST_AUTO_TEST_CASE(Normal) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 462 | { |
| 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 Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 494 | 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 Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 499 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 500 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 501 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_2); |
| 502 | BOOST_TEST(!isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 503 | BOOST_CHECK_EQUAL(reassembler.size(), 2); |
| 504 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 505 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_1, frag1_2); |
| 506 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 507 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 508 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame^] | 509 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP_2, frag2_1); |
| 510 | BOOST_TEST(isComplete); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 511 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 512 | } |
| 513 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 514 | BOOST_AUTO_TEST_SUITE_END() // MultipleRemoteEndpoints |
| 515 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 516 | BOOST_AUTO_TEST_SUITE_END() // TestLpReassembler |
| 517 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 518 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 519 | } // namespace nfd::tests |