Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 3 | * Copyright (c) 2014-2016, 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" |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace face { |
| 32 | namespace tests { |
| 33 | |
| 34 | using namespace nfd::tests; |
| 35 | |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 36 | class LpReassemblerFixture : public UnitTestTimeFixture |
| 37 | { |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 38 | protected: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 39 | LpReassemblerFixture() |
| 40 | { |
| 41 | reassembler.beforeTimeout.connect( |
| 42 | [this] (Transport::EndpointId remoteEp, size_t nDroppedFragments) { |
| 43 | timeoutHistory.push_back(std::make_tuple(remoteEp, nDroppedFragments)); |
| 44 | }); |
| 45 | } |
| 46 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 47 | protected: |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 48 | LpReassembler reassembler; |
| 49 | std::vector<std::tuple<Transport::EndpointId, size_t>> timeoutHistory; |
| 50 | |
| 51 | static const uint8_t data[10]; |
| 52 | }; |
| 53 | |
| 54 | const uint8_t LpReassemblerFixture::data[10] = { |
| 55 | 0x06, 0x08, // Data |
| 56 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 57 | }; |
| 58 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 59 | BOOST_AUTO_TEST_SUITE(Face) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 60 | BOOST_FIXTURE_TEST_SUITE(TestLpReassembler, LpReassemblerFixture) |
| 61 | |
| 62 | BOOST_AUTO_TEST_SUITE(SingleFragment) |
| 63 | |
| 64 | BOOST_AUTO_TEST_CASE(Normal) |
| 65 | { |
| 66 | ndn::Buffer dataBuffer(data, sizeof(data)); |
| 67 | |
| 68 | lp::Packet received; |
| 69 | received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end())); |
| 70 | received.add<lp::FragIndexField>(0); |
| 71 | received.add<lp::FragCountField>(1); |
| 72 | received.add<lp::SequenceField>(1000); |
| 73 | received.add<lp::NextHopFaceIdField>(200); |
| 74 | |
| 75 | bool isComplete = false; |
| 76 | Block netPacket; |
| 77 | lp::Packet packet; |
| 78 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received); |
| 79 | |
| 80 | BOOST_REQUIRE(isComplete); |
| 81 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 82 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 83 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 84 | } |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(OmitFragIndex) |
| 87 | { |
| 88 | ndn::Buffer dataBuffer(data, sizeof(data)); |
| 89 | |
| 90 | lp::Packet received; |
| 91 | received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end())); |
| 92 | received.add<lp::FragCountField>(1); |
| 93 | received.add<lp::SequenceField>(1000); |
| 94 | received.add<lp::NextHopFaceIdField>(200); |
| 95 | |
| 96 | bool isComplete = false; |
| 97 | Block netPacket; |
| 98 | lp::Packet packet; |
| 99 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received); |
| 100 | |
| 101 | BOOST_REQUIRE(isComplete); |
| 102 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 103 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 104 | } |
| 105 | |
| 106 | BOOST_AUTO_TEST_CASE(OmitFragCount) |
| 107 | { |
| 108 | ndn::Buffer dataBuffer(data, sizeof(data)); |
| 109 | |
| 110 | lp::Packet received; |
| 111 | received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end())); |
| 112 | received.add<lp::FragIndexField>(0); |
| 113 | received.add<lp::SequenceField>(1000); |
| 114 | received.add<lp::NextHopFaceIdField>(200); |
| 115 | |
| 116 | bool isComplete = false; |
| 117 | Block netPacket; |
| 118 | lp::Packet packet; |
| 119 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received); |
| 120 | |
| 121 | BOOST_REQUIRE(isComplete); |
| 122 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 123 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_CASE(OmitFragIndexAndFragCount) |
| 127 | { |
| 128 | ndn::Buffer dataBuffer(data, sizeof(data)); |
| 129 | |
| 130 | lp::Packet received; |
| 131 | received.add<lp::FragmentField>(std::make_pair(dataBuffer.begin(), dataBuffer.end())); |
| 132 | received.add<lp::SequenceField>(1000); |
| 133 | received.add<lp::NextHopFaceIdField>(200); |
| 134 | |
| 135 | bool isComplete = false; |
| 136 | Block netPacket; |
| 137 | lp::Packet packet; |
| 138 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received); |
| 139 | |
| 140 | BOOST_REQUIRE(isComplete); |
| 141 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 142 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 143 | } |
| 144 | |
| 145 | BOOST_AUTO_TEST_SUITE_END() // SingleFragment |
| 146 | |
| 147 | BOOST_AUTO_TEST_SUITE(MultiFragment) |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(Normal) |
| 150 | { |
| 151 | ndn::Buffer data1Buffer(data, 4); |
| 152 | ndn::Buffer data2Buffer(data + 4, 4); |
| 153 | ndn::Buffer data3Buffer(data + 8, 2); |
| 154 | |
| 155 | lp::Packet received1; |
| 156 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 157 | received1.add<lp::FragIndexField>(0); |
| 158 | received1.add<lp::FragCountField>(3); |
| 159 | received1.add<lp::SequenceField>(1000); |
| 160 | received1.add<lp::NextHopFaceIdField>(200); |
| 161 | |
| 162 | lp::Packet received2; |
| 163 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 164 | received2.add<lp::FragIndexField>(1); |
| 165 | received2.add<lp::FragCountField>(3); |
| 166 | received2.add<lp::SequenceField>(1001); |
| 167 | |
| 168 | lp::Packet received3; |
| 169 | received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end())); |
| 170 | received3.add<lp::FragIndexField>(2); |
| 171 | received3.add<lp::FragCountField>(3); |
| 172 | received3.add<lp::SequenceField>(1002); |
| 173 | |
| 174 | bool isComplete = false; |
| 175 | Block netPacket; |
| 176 | lp::Packet packet; |
| 177 | |
| 178 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 179 | BOOST_REQUIRE(!isComplete); |
| 180 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 181 | |
| 182 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 183 | BOOST_REQUIRE(!isComplete); |
| 184 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 185 | |
| 186 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received3); |
| 187 | BOOST_REQUIRE(isComplete); |
| 188 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 189 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 190 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 191 | } |
| 192 | |
| 193 | BOOST_AUTO_TEST_CASE(OmitFragIndex0) |
| 194 | { |
| 195 | ndn::Buffer data1Buffer(data, 4); |
| 196 | ndn::Buffer data2Buffer(data + 4, 4); |
| 197 | ndn::Buffer data3Buffer(data + 8, 2); |
| 198 | |
| 199 | lp::Packet received1; |
| 200 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 201 | received1.add<lp::FragCountField>(3); |
| 202 | received1.add<lp::SequenceField>(1000); |
| 203 | received1.add<lp::NextHopFaceIdField>(200); |
| 204 | |
| 205 | lp::Packet received2; |
| 206 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 207 | received2.add<lp::FragIndexField>(1); |
| 208 | received2.add<lp::FragCountField>(3); |
| 209 | received2.add<lp::SequenceField>(1001); |
| 210 | |
| 211 | lp::Packet received3; |
| 212 | received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end())); |
| 213 | received3.add<lp::FragIndexField>(2); |
| 214 | received3.add<lp::FragCountField>(3); |
| 215 | received3.add<lp::SequenceField>(1002); |
| 216 | |
| 217 | bool isComplete = false; |
| 218 | Block netPacket; |
| 219 | lp::Packet packet; |
| 220 | |
| 221 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 222 | BOOST_REQUIRE(!isComplete); |
| 223 | |
| 224 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 225 | BOOST_REQUIRE(!isComplete); |
| 226 | |
| 227 | std::tie(isComplete, netPacket, packet) = reassembler.receiveFragment(0, received3); |
| 228 | BOOST_REQUIRE(isComplete); |
| 229 | BOOST_CHECK(packet.has<lp::NextHopFaceIdField>()); |
| 230 | BOOST_CHECK_EQUAL_COLLECTIONS(data, data + sizeof(data), netPacket.begin(), netPacket.end()); |
| 231 | } |
| 232 | |
| 233 | BOOST_AUTO_TEST_CASE(OutOfOrder) |
| 234 | { |
| 235 | ndn::Buffer data0Buffer(data, 4); |
| 236 | ndn::Buffer data1Buffer(data + 4, 4); |
| 237 | ndn::Buffer data2Buffer(data + 8, 2); |
| 238 | |
| 239 | lp::Packet frag0; |
| 240 | frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end())); |
| 241 | frag0.add<lp::FragIndexField>(0); |
| 242 | frag0.add<lp::FragCountField>(3); |
| 243 | frag0.add<lp::SequenceField>(1000); |
| 244 | frag0.add<lp::NextHopFaceIdField>(200); |
| 245 | |
| 246 | lp::Packet frag1; |
| 247 | frag1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 248 | frag1.add<lp::FragIndexField>(1); |
| 249 | frag1.add<lp::FragCountField>(3); |
| 250 | frag1.add<lp::SequenceField>(1001); |
| 251 | |
| 252 | lp::Packet frag2; |
| 253 | frag2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 254 | frag2.add<lp::FragIndexField>(2); |
| 255 | frag2.add<lp::FragCountField>(3); |
| 256 | frag2.add<lp::SequenceField>(1002); |
| 257 | |
| 258 | bool isComplete = false; |
| 259 | |
| 260 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag2); |
| 261 | BOOST_REQUIRE(!isComplete); |
| 262 | |
| 263 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag0); |
| 264 | BOOST_REQUIRE(!isComplete); |
| 265 | |
| 266 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag1); |
| 267 | BOOST_REQUIRE(isComplete); |
| 268 | } |
| 269 | |
| 270 | BOOST_AUTO_TEST_CASE(Duplicate) |
| 271 | { |
| 272 | ndn::Buffer data0Buffer(data, 5); |
| 273 | |
| 274 | lp::Packet frag0; |
| 275 | frag0.add<lp::FragmentField>(std::make_pair(data0Buffer.begin(), data0Buffer.end())); |
| 276 | frag0.add<lp::FragIndexField>(0); |
| 277 | frag0.add<lp::FragCountField>(2); |
| 278 | frag0.add<lp::SequenceField>(1000); |
| 279 | |
| 280 | bool isComplete = false; |
| 281 | |
| 282 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, frag0); |
| 283 | BOOST_REQUIRE(!isComplete); |
| 284 | |
| 285 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(1, frag0); |
| 286 | BOOST_REQUIRE(!isComplete); |
| 287 | } |
| 288 | |
| 289 | BOOST_AUTO_TEST_CASE(Timeout) |
| 290 | { |
| 291 | ndn::Buffer data1Buffer(data, 5); |
| 292 | ndn::Buffer data2Buffer(data + 5, 5); |
| 293 | |
| 294 | lp::Packet received1; |
| 295 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 296 | received1.add<lp::FragIndexField>(0); |
| 297 | received1.add<lp::FragCountField>(2); |
| 298 | received1.add<lp::SequenceField>(1000); |
| 299 | received1.add<lp::NextHopFaceIdField>(200); |
| 300 | |
| 301 | lp::Packet received2; |
| 302 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 303 | received2.add<lp::FragIndexField>(1); |
| 304 | received2.add<lp::FragCountField>(2); |
| 305 | received2.add<lp::SequenceField>(1001); |
| 306 | |
| 307 | const Transport::EndpointId REMOTE_EP = 11028; |
| 308 | bool isComplete = false; |
| 309 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received1); |
| 310 | BOOST_REQUIRE(!isComplete); |
| 311 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 312 | BOOST_CHECK(timeoutHistory.empty()); |
| 313 | |
| 314 | advanceClocks(time::milliseconds(1), 600); |
| 315 | BOOST_CHECK_EQUAL(reassembler.size(), 0); |
| 316 | BOOST_REQUIRE_EQUAL(timeoutHistory.size(), 1); |
| 317 | BOOST_CHECK_EQUAL(std::get<0>(timeoutHistory.back()), REMOTE_EP); |
| 318 | BOOST_CHECK_EQUAL(std::get<1>(timeoutHistory.back()), 1); |
| 319 | |
| 320 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(REMOTE_EP, received2); |
| 321 | BOOST_REQUIRE(!isComplete); |
| 322 | } |
| 323 | |
| 324 | BOOST_AUTO_TEST_CASE(MissingSequence) |
| 325 | { |
| 326 | ndn::Buffer data1Buffer(data, 4); |
| 327 | ndn::Buffer data2Buffer(data + 4, 4); |
| 328 | ndn::Buffer data3Buffer(data + 8, 2); |
| 329 | |
| 330 | lp::Packet received1; |
| 331 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 332 | received1.add<lp::FragIndexField>(0); |
| 333 | received1.add<lp::FragCountField>(3); |
| 334 | received1.add<lp::SequenceField>(1000); |
| 335 | received1.add<lp::NextHopFaceIdField>(200); |
| 336 | |
| 337 | lp::Packet received2; |
| 338 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 339 | received2.add<lp::FragIndexField>(1); |
| 340 | received2.add<lp::FragCountField>(3); |
| 341 | |
| 342 | lp::Packet received3; |
| 343 | received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end())); |
| 344 | received3.add<lp::FragIndexField>(2); |
| 345 | received3.add<lp::FragCountField>(3); |
| 346 | received3.add<lp::SequenceField>(1002); |
| 347 | |
| 348 | bool isComplete = false; |
| 349 | |
| 350 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 351 | BOOST_REQUIRE(!isComplete); |
| 352 | |
| 353 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 354 | BOOST_REQUIRE(!isComplete); |
| 355 | |
| 356 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3); |
| 357 | BOOST_REQUIRE(!isComplete); |
| 358 | |
| 359 | advanceClocks(time::milliseconds(1), 600); |
| 360 | |
| 361 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 362 | BOOST_REQUIRE(!isComplete); |
| 363 | } |
| 364 | |
| 365 | BOOST_AUTO_TEST_CASE(FragCountOverLimit) |
| 366 | { |
| 367 | ndn::Buffer data1Buffer(data, sizeof(data)); |
| 368 | |
| 369 | lp::Packet received1; |
| 370 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 371 | received1.add<lp::FragIndexField>(0); |
| 372 | received1.add<lp::FragCountField>(256); |
| 373 | received1.add<lp::SequenceField>(1000); |
| 374 | received1.add<lp::NextHopFaceIdField>(200); |
| 375 | |
| 376 | bool isComplete = false; |
| 377 | |
| 378 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 379 | BOOST_REQUIRE(!isComplete); |
| 380 | } |
| 381 | |
| 382 | BOOST_AUTO_TEST_CASE(MissingFragCount) |
| 383 | { |
| 384 | ndn::Buffer data1Buffer(data, 4); |
| 385 | ndn::Buffer data2Buffer(data + 4, 4); |
| 386 | ndn::Buffer data3Buffer(data + 8, 2); |
| 387 | |
| 388 | lp::Packet received1; |
| 389 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 390 | received1.add<lp::FragIndexField>(0); |
| 391 | received1.add<lp::FragCountField>(3); |
| 392 | received1.add<lp::SequenceField>(1000); |
| 393 | received1.add<lp::NextHopFaceIdField>(200); |
| 394 | |
| 395 | lp::Packet received2; |
| 396 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 397 | received2.add<lp::FragIndexField>(1); |
| 398 | received2.add<lp::FragCountField>(50); |
| 399 | received2.add<lp::SequenceField>(1001); |
| 400 | |
| 401 | lp::Packet received3; |
| 402 | received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end())); |
| 403 | received3.add<lp::FragIndexField>(2); |
| 404 | received3.add<lp::FragCountField>(3); |
| 405 | received3.add<lp::SequenceField>(1002); |
| 406 | |
| 407 | bool isComplete = false; |
| 408 | |
| 409 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 410 | BOOST_REQUIRE(!isComplete); |
| 411 | |
| 412 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 413 | BOOST_REQUIRE(!isComplete); |
| 414 | |
| 415 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3); |
| 416 | BOOST_REQUIRE(!isComplete); |
| 417 | } |
| 418 | |
| 419 | BOOST_AUTO_TEST_CASE(OverFragCount) |
| 420 | { |
| 421 | LpReassembler::Options options; |
| 422 | options.nMaxFragments = 2; |
| 423 | reassembler.setOptions(options); |
| 424 | |
| 425 | ndn::Buffer data1Buffer(data, 4); |
| 426 | ndn::Buffer data2Buffer(data + 4, 4); |
| 427 | ndn::Buffer data3Buffer(data + 8, 2); |
| 428 | |
| 429 | lp::Packet received1; |
| 430 | received1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 431 | received1.add<lp::FragIndexField>(0); |
| 432 | received1.add<lp::FragCountField>(3); |
| 433 | received1.add<lp::SequenceField>(1000); |
| 434 | received1.add<lp::NextHopFaceIdField>(200); |
| 435 | |
| 436 | lp::Packet received2; |
| 437 | received2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 438 | received2.add<lp::FragIndexField>(1); |
| 439 | received2.add<lp::FragCountField>(3); |
| 440 | received2.add<lp::SequenceField>(1001); |
| 441 | |
| 442 | lp::Packet received3; |
| 443 | received3.add<lp::FragmentField>(std::make_pair(data3Buffer.begin(), data3Buffer.end())); |
| 444 | received3.add<lp::FragIndexField>(2); |
| 445 | received3.add<lp::FragCountField>(3); |
| 446 | received3.add<lp::SequenceField>(1002); |
| 447 | |
| 448 | bool isComplete = false; |
| 449 | |
| 450 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received1); |
| 451 | BOOST_REQUIRE(!isComplete); |
| 452 | |
| 453 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received2); |
| 454 | BOOST_REQUIRE(!isComplete); |
| 455 | |
| 456 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(0, received3); |
| 457 | BOOST_REQUIRE(!isComplete); |
| 458 | } |
| 459 | |
| 460 | BOOST_AUTO_TEST_SUITE_END() // MultiFragment |
| 461 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame^] | 462 | BOOST_AUTO_TEST_SUITE(MultipleRemoteEndpoints) |
| 463 | |
| 464 | BOOST_AUTO_TEST_CASE(Normal) |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 465 | { |
| 466 | ndn::Buffer data1Buffer(data, 5); |
| 467 | ndn::Buffer data2Buffer(data + 5, 5); |
| 468 | |
| 469 | lp::Packet frag1_1; |
| 470 | frag1_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 471 | frag1_1.add<lp::FragIndexField>(0); |
| 472 | frag1_1.add<lp::FragCountField>(2); |
| 473 | frag1_1.add<lp::SequenceField>(2000); |
| 474 | frag1_1.add<lp::NextHopFaceIdField>(200); |
| 475 | |
| 476 | lp::Packet frag1_2; |
| 477 | frag1_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 478 | frag1_2.add<lp::FragIndexField>(1); |
| 479 | frag1_2.add<lp::FragCountField>(2); |
| 480 | frag1_2.add<lp::SequenceField>(2001); |
| 481 | |
| 482 | lp::Packet frag2_1; |
| 483 | frag2_1.add<lp::FragmentField>(std::make_pair(data1Buffer.begin(), data1Buffer.end())); |
| 484 | frag2_1.add<lp::FragIndexField>(0); |
| 485 | frag2_1.add<lp::FragCountField>(2); |
| 486 | frag2_1.add<lp::SequenceField>(2000); |
| 487 | frag2_1.add<lp::NextHopFaceIdField>(200); |
| 488 | |
| 489 | lp::Packet frag2_2; |
| 490 | frag2_2.add<lp::FragmentField>(std::make_pair(data2Buffer.begin(), data2Buffer.end())); |
| 491 | frag2_2.add<lp::FragIndexField>(1); |
| 492 | frag2_2.add<lp::FragCountField>(2); |
| 493 | frag2_2.add<lp::SequenceField>(2001); |
| 494 | |
| 495 | bool isComplete = false; |
| 496 | |
| 497 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(1, frag1_1); |
| 498 | BOOST_REQUIRE(!isComplete); |
| 499 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 500 | |
| 501 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(2, frag2_2); |
| 502 | BOOST_REQUIRE(!isComplete); |
| 503 | BOOST_CHECK_EQUAL(reassembler.size(), 2); |
| 504 | |
| 505 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(1, frag1_2); |
| 506 | BOOST_REQUIRE(isComplete); |
| 507 | BOOST_CHECK_EQUAL(reassembler.size(), 1); |
| 508 | |
| 509 | std::tie(isComplete, std::ignore, std::ignore) = reassembler.receiveFragment(2, frag2_1); |
| 510 | BOOST_REQUIRE(isComplete); |
| 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 | |
| 519 | } // namespace tests |
| 520 | } // namespace face |
| 521 | } // namespace nfd |