Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face/ndnlp-sequence-generator.hpp" |
| 27 | #include "face/ndnlp-slicer.hpp" |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 28 | #include "face/ndnlp-partial-message-store.hpp" |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 30 | #include "tests/test-common.hpp" |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 31 | |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 32 | #include <boost/scoped_array.hpp> |
| 33 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 34 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 35 | namespace ndnlp { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 36 | namespace tests { |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 37 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 38 | using namespace nfd::tests; |
| 39 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 40 | BOOST_FIXTURE_TEST_SUITE(FaceNdnlp, BaseFixture) |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 41 | |
| 42 | BOOST_AUTO_TEST_CASE(SequenceBlock) |
| 43 | { |
| 44 | ndnlp::SequenceBlock sb(0x8000, 2); |
| 45 | BOOST_CHECK_EQUAL(sb.count(), 2); |
| 46 | BOOST_CHECK_EQUAL(sb[0], 0x8000); |
| 47 | BOOST_CHECK_EQUAL(sb[1], 0x8001); |
| 48 | BOOST_CHECK_THROW(sb[2], std::out_of_range); |
| 49 | } |
| 50 | |
| 51 | // sequence number can safely wrap around |
| 52 | BOOST_AUTO_TEST_CASE(SequenceBlockWrap) |
| 53 | { |
| 54 | ndnlp::SequenceBlock sb(std::numeric_limits<uint64_t>::max(), 2); |
| 55 | BOOST_CHECK_EQUAL(sb[0], std::numeric_limits<uint64_t>::max()); |
| 56 | BOOST_CHECK_EQUAL(sb[1], std::numeric_limits<uint64_t>::min()); |
| 57 | BOOST_CHECK_EQUAL(sb[1] - sb[0], 1); |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_CASE(SequenceGenerator) |
| 61 | { |
| 62 | ndnlp::SequenceGenerator seqgen; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 64 | ndnlp::SequenceBlock sb1 = seqgen.nextBlock(2); |
| 65 | BOOST_CHECK_EQUAL(sb1.count(), 2); |
| 66 | |
| 67 | ndnlp::SequenceBlock sb2 = seqgen.nextBlock(1); |
| 68 | BOOST_CHECK_NE(sb1[0], sb2[0]); |
| 69 | BOOST_CHECK_NE(sb1[1], sb2[0]); |
| 70 | } |
| 71 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 72 | // slice a Block to one fragment |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 73 | BOOST_AUTO_TEST_CASE(Slice1) |
| 74 | { |
| 75 | uint8_t blockValue[60]; |
| 76 | memset(blockValue, 0xcc, sizeof(blockValue)); |
| 77 | Block block = ndn::dataBlock(0x01, blockValue, sizeof(blockValue)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 79 | ndnlp::Slicer slicer(9000); |
| 80 | ndnlp::PacketArray pa = slicer.slice(block); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 81 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 82 | BOOST_REQUIRE_EQUAL(pa->size(), 1); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 84 | const Block& pkt = pa->at(0); |
| 85 | BOOST_CHECK_EQUAL(pkt.type(), static_cast<uint32_t>(tlv::NdnlpData)); |
| 86 | pkt.parse(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 87 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 88 | const Block::element_container& elements = pkt.elements(); |
| 89 | BOOST_REQUIRE_EQUAL(elements.size(), 2); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 90 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 91 | const Block& sequenceElement = elements[0]; |
| 92 | BOOST_CHECK_EQUAL(sequenceElement.type(), static_cast<uint32_t>(tlv::NdnlpSequence)); |
| 93 | BOOST_REQUIRE_EQUAL(sequenceElement.value_size(), sizeof(uint64_t)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 95 | const Block& payloadElement = elements[1]; |
| 96 | BOOST_CHECK_EQUAL(payloadElement.type(), static_cast<uint32_t>(tlv::NdnlpPayload)); |
| 97 | size_t payloadSize = payloadElement.value_size(); |
| 98 | BOOST_CHECK_EQUAL(payloadSize, block.size()); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 99 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL_COLLECTIONS(payloadElement.value_begin(), payloadElement.value_end(), |
| 101 | block.begin(), block.end()); |
| 102 | } |
| 103 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 104 | // slice a Block to four fragments |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 105 | BOOST_AUTO_TEST_CASE(Slice4) |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 106 | { |
| 107 | uint8_t blockValue[5050]; |
| 108 | memset(blockValue, 0xcc, sizeof(blockValue)); |
| 109 | Block block = ndn::dataBlock(0x01, blockValue, sizeof(blockValue)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 110 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 111 | ndnlp::Slicer slicer(1500); |
| 112 | ndnlp::PacketArray pa = slicer.slice(block); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 113 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 114 | BOOST_REQUIRE_EQUAL(pa->size(), 4); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 115 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 116 | uint64_t seq0 = 0xdddd; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 118 | size_t totalPayloadSize = 0; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 119 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 120 | for (size_t i = 0; i < 4; ++i) { |
| 121 | const Block& pkt = pa->at(i); |
| 122 | BOOST_CHECK_EQUAL(pkt.type(), static_cast<uint32_t>(tlv::NdnlpData)); |
| 123 | pkt.parse(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 124 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 125 | const Block::element_container& elements = pkt.elements(); |
| 126 | BOOST_REQUIRE_EQUAL(elements.size(), 4); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 127 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 128 | const Block& sequenceElement = elements[0]; |
| 129 | BOOST_CHECK_EQUAL(sequenceElement.type(), static_cast<uint32_t>(tlv::NdnlpSequence)); |
| 130 | BOOST_REQUIRE_EQUAL(sequenceElement.value_size(), sizeof(uint64_t)); |
| 131 | uint64_t seq = be64toh(*reinterpret_cast<const uint64_t*>( |
| 132 | &*sequenceElement.value_begin())); |
| 133 | if (i == 0) { |
| 134 | seq0 = seq; |
| 135 | } |
| 136 | BOOST_CHECK_EQUAL(seq, seq0 + i); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 137 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 138 | const Block& fragIndexElement = elements[1]; |
| 139 | BOOST_CHECK_EQUAL(fragIndexElement.type(), static_cast<uint32_t>(tlv::NdnlpFragIndex)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 140 | uint64_t fragIndex = ndn::readNonNegativeInteger(fragIndexElement); |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 141 | BOOST_CHECK_EQUAL(fragIndex, i); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 142 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 143 | const Block& fragCountElement = elements[2]; |
| 144 | BOOST_CHECK_EQUAL(fragCountElement.type(), static_cast<uint32_t>(tlv::NdnlpFragCount)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 145 | uint64_t fragCount = ndn::readNonNegativeInteger(fragCountElement); |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 146 | BOOST_CHECK_EQUAL(fragCount, 4); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 147 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 148 | const Block& payloadElement = elements[3]; |
| 149 | BOOST_CHECK_EQUAL(payloadElement.type(), static_cast<uint32_t>(tlv::NdnlpPayload)); |
| 150 | size_t payloadSize = payloadElement.value_size(); |
| 151 | totalPayloadSize += payloadSize; |
| 152 | } |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 153 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 154 | BOOST_CHECK_EQUAL(totalPayloadSize, block.size()); |
| 155 | } |
| 156 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 157 | class ReassembleFixture : protected UnitTestTimeFixture |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 158 | { |
| 159 | protected: |
| 160 | ReassembleFixture() |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 161 | : slicer(1500) |
| 162 | , pms(time::milliseconds(100)) |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 163 | { |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 164 | pms.onReceive.connect([this] (const Block& block) { |
| 165 | received.push_back(block); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 166 | }); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | Block |
| 170 | makeBlock(size_t valueLength) |
| 171 | { |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 172 | boost::scoped_array<uint8_t> blockValue(new uint8_t[valueLength]); |
| 173 | memset(blockValue.get(), 0xcc, valueLength); |
| 174 | return ndn::dataBlock(0x01, blockValue.get(), valueLength); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 175 | } |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 176 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 177 | void |
| 178 | receiveNdnlpData(const Block& block) |
| 179 | { |
| 180 | bool isOk = false; |
| 181 | ndnlp::NdnlpData pkt; |
| 182 | std::tie(isOk, pkt) = ndnlp::NdnlpData::fromBlock(block); |
| 183 | BOOST_REQUIRE(isOk); |
| 184 | pms.receive(pkt); |
| 185 | } |
| 186 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 187 | protected: |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 188 | ndnlp::Slicer slicer; |
| 189 | ndnlp::PartialMessageStore pms; |
| 190 | |
| 191 | static const time::nanoseconds IDLE_DURATION; |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 192 | |
| 193 | // received network layer packets |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 194 | std::vector<Block> received; |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 197 | // reassemble one fragment into one Block |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 198 | BOOST_FIXTURE_TEST_CASE(Reassemble1, ReassembleFixture) |
| 199 | { |
| 200 | Block block = makeBlock(60); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 201 | ndnlp::PacketArray pa = slicer.slice(block); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 202 | BOOST_REQUIRE_EQUAL(pa->size(), 1); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 203 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(received.size(), 0); |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 205 | this->receiveNdnlpData(pa->at(0)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 206 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 207 | BOOST_REQUIRE_EQUAL(received.size(), 1); |
| 208 | BOOST_CHECK_EQUAL_COLLECTIONS(received.at(0).begin(), received.at(0).end(), |
| 209 | block.begin(), block.end()); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 212 | // reassemble four and two fragments into two Blocks |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 213 | BOOST_FIXTURE_TEST_CASE(Reassemble4and2, ReassembleFixture) |
| 214 | { |
| 215 | Block block = makeBlock(5050); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 216 | ndnlp::PacketArray pa = slicer.slice(block); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 217 | BOOST_REQUIRE_EQUAL(pa->size(), 4); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 218 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 219 | Block block2 = makeBlock(2000); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 220 | ndnlp::PacketArray pa2 = slicer.slice(block2); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 221 | BOOST_REQUIRE_EQUAL(pa2->size(), 2); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 222 | |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 223 | BOOST_CHECK_EQUAL(received.size(), 0); |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 224 | this->receiveNdnlpData(pa->at(0)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 226 | this->advanceClocks(time::milliseconds(40)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 227 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 228 | this->receiveNdnlpData(pa->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 229 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 230 | this->advanceClocks(time::milliseconds(40)); |
| 231 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 232 | this->receiveNdnlpData(pa2->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 234 | this->advanceClocks(time::milliseconds(40)); |
| 235 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 236 | this->receiveNdnlpData(pa->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 237 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 238 | this->advanceClocks(time::milliseconds(40)); |
| 239 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 240 | this->receiveNdnlpData(pa2->at(0)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 241 | BOOST_CHECK_EQUAL(received.size(), 1); |
| 242 | this->advanceClocks(time::milliseconds(40)); |
| 243 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 244 | this->receiveNdnlpData(pa->at(3)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(received.size(), 1); |
| 246 | this->advanceClocks(time::milliseconds(40)); |
| 247 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 248 | this->receiveNdnlpData(pa->at(2)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 249 | |
| 250 | BOOST_REQUIRE_EQUAL(received.size(), 2); |
| 251 | BOOST_CHECK_EQUAL_COLLECTIONS(received.at(1).begin(), received.at(1).end(), |
| 252 | block.begin(), block.end()); |
| 253 | BOOST_CHECK_EQUAL_COLLECTIONS(received.at(0).begin(), received.at(0).end(), |
| 254 | block2.begin(), block2.end()); |
| 255 | } |
| 256 | |
| 257 | // reassemble four fragments into one Block, but another two fragments are expired |
| 258 | BOOST_FIXTURE_TEST_CASE(ReassembleTimeout, ReassembleFixture) |
| 259 | { |
| 260 | Block block = makeBlock(5050); |
| 261 | ndnlp::PacketArray pa = slicer.slice(block); |
| 262 | BOOST_REQUIRE_EQUAL(pa->size(), 4); |
| 263 | |
| 264 | Block block2 = makeBlock(2000); |
| 265 | ndnlp::PacketArray pa2 = slicer.slice(block2); |
| 266 | BOOST_REQUIRE_EQUAL(pa2->size(), 2); |
| 267 | |
| 268 | BOOST_CHECK_EQUAL(received.size(), 0); |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 269 | this->receiveNdnlpData(pa->at(0)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 271 | this->advanceClocks(time::milliseconds(40)); |
| 272 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 273 | this->receiveNdnlpData(pa->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 275 | this->advanceClocks(time::milliseconds(40)); |
| 276 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 277 | this->receiveNdnlpData(pa2->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 279 | this->advanceClocks(time::milliseconds(40)); |
| 280 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 281 | this->receiveNdnlpData(pa->at(1)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 282 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 283 | this->advanceClocks(time::milliseconds(40)); |
| 284 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 285 | this->receiveNdnlpData(pa->at(3)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 286 | BOOST_CHECK_EQUAL(received.size(), 0); |
| 287 | this->advanceClocks(time::milliseconds(40)); |
| 288 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 289 | this->receiveNdnlpData(pa->at(2)); |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(received.size(), 1); |
| 291 | this->advanceClocks(time::milliseconds(40)); |
| 292 | |
Junxiao Shi | 083f778 | 2015-02-21 12:06:26 -0700 | [diff] [blame] | 293 | this->receiveNdnlpData(pa2->at(0)); // last fragment was received 160ms ago, expired |
Junxiao Shi | a37405d | 2015-01-26 10:50:58 -0700 | [diff] [blame] | 294 | BOOST_CHECK_EQUAL(received.size(), 1); |
| 295 | this->advanceClocks(time::milliseconds(40)); |
| 296 | |
| 297 | BOOST_REQUIRE_EQUAL(received.size(), 1); |
| 298 | BOOST_CHECK_EQUAL_COLLECTIONS(received.at(0).begin(), received.at(0).end(), |
| 299 | block.begin(), block.end()); |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 302 | BOOST_AUTO_TEST_SUITE_END() |
| 303 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 304 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 305 | } // namespace ndnlp |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 306 | } // namespace nfd |