Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, 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. |
| 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-reliability.hpp" |
| 27 | #include "face/face.hpp" |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 28 | #include "face/generic-link-service.hpp" |
| 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | #include "dummy-face.hpp" |
| 32 | #include "dummy-transport.hpp" |
| 33 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 34 | #include <cstring> |
| 35 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 36 | namespace nfd { |
| 37 | namespace face { |
| 38 | namespace tests { |
| 39 | |
| 40 | using namespace nfd::tests; |
| 41 | |
| 42 | BOOST_AUTO_TEST_SUITE(Face) |
| 43 | |
| 44 | class DummyLpReliabilityLinkService : public GenericLinkService |
| 45 | { |
| 46 | public: |
| 47 | LpReliability* |
| 48 | getLpReliability() |
| 49 | { |
| 50 | return &m_reliability; |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | sendLpPackets(std::vector<lp::Packet> frags) |
| 55 | { |
| 56 | if (frags.front().has<lp::FragmentField>()) { |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 57 | Interest interest("/test/prefix"); |
| 58 | lp::Packet pkt; |
| 59 | pkt.add<lp::FragmentField>(make_pair(interest.wireEncode().begin(), interest.wireEncode().end())); |
| 60 | m_reliability.handleOutgoing(frags, std::move(pkt), true); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 63 | for (lp::Packet frag : frags) { |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 64 | this->sendLpPacket(std::move(frag)); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | void |
| 70 | doSendInterest(const Interest& interest) override |
| 71 | { |
| 72 | BOOST_ASSERT(false); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | doSendData(const Data& data) override |
| 77 | { |
| 78 | BOOST_ASSERT(false); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | doSendNack(const lp::Nack& nack) override |
| 83 | { |
| 84 | BOOST_ASSERT(false); |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | doReceivePacket(Transport::Packet&& packet) override |
| 89 | { |
| 90 | BOOST_ASSERT(false); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | class LpReliabilityFixture : public UnitTestTimeFixture |
| 95 | { |
| 96 | public: |
| 97 | LpReliabilityFixture() |
| 98 | : linkService(make_unique<DummyLpReliabilityLinkService>()) |
| 99 | , transport(make_unique<DummyTransport>()) |
| 100 | , face(make_unique<DummyFace>()) |
| 101 | { |
| 102 | linkService->setFaceAndTransport(*face, *transport); |
| 103 | transport->setFaceAndLinkService(*face, *linkService); |
| 104 | |
| 105 | GenericLinkService::Options options; |
| 106 | options.reliabilityOptions.isEnabled = true; |
| 107 | linkService->setOptions(options); |
| 108 | |
| 109 | reliability = linkService->getLpReliability(); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 110 | reliability->m_lastTxSeqNo = 1; |
| 111 | } |
| 112 | |
| 113 | static bool |
| 114 | netPktHasUnackedFrag(const shared_ptr<LpReliability::NetPkt>& netPkt, lp::Sequence txSeq) |
| 115 | { |
| 116 | return std::any_of(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(), |
| 117 | [txSeq] (const LpReliability::UnackedFrags::iterator& frag) { |
| 118 | return frag->first == txSeq; |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | LpReliability::UnackedFrags::iterator |
| 123 | getIteratorFromTxSeq(lp::Sequence txSeq) |
| 124 | { |
| 125 | return reliability->m_unackedFrags.find(txSeq); |
| 126 | } |
| 127 | |
| 128 | /** \brief make an LpPacket with fragment of specified size |
| 129 | * \param pktNo packet identifier, which can be extracted with \p getPktNo |
| 130 | * \param payloadSize total payload size; if this is less than 4, 4 will be used |
| 131 | */ |
| 132 | static lp::Packet |
| 133 | makeFrag(uint32_t pktNo, size_t payloadSize = 4) |
| 134 | { |
| 135 | payloadSize = std::max(payloadSize, static_cast<size_t>(4)); |
| 136 | BOOST_ASSERT(payloadSize <= 255); |
| 137 | |
| 138 | lp::Packet pkt; |
| 139 | ndn::Buffer buf(payloadSize); |
Davide Pesavento | 6d1c1c3 | 2017-10-08 21:44:05 -0400 | [diff] [blame] | 140 | std::memcpy(buf.data(), &pktNo, sizeof(pktNo)); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 141 | pkt.set<lp::FragmentField>(make_pair(buf.cbegin(), buf.cend())); |
| 142 | return pkt; |
| 143 | } |
| 144 | |
| 145 | /** \brief extract packet identifier from LpPacket made with \p makeFrag |
| 146 | * \retval 0 packet identifier cannot be extracted |
| 147 | */ |
| 148 | static uint32_t |
| 149 | getPktNo(const lp::Packet& pkt) |
| 150 | { |
| 151 | BOOST_ASSERT(pkt.has<lp::FragmentField>()); |
| 152 | |
| 153 | ndn::Buffer::const_iterator begin, end; |
| 154 | std::tie(begin, end) = pkt.get<lp::FragmentField>(); |
| 155 | if (std::distance(begin, end) < 4) { |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | uint32_t value = 0; |
| 160 | std::memcpy(&value, &*begin, sizeof(value)); |
| 161 | return value; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | public: |
| 165 | unique_ptr<DummyLpReliabilityLinkService> linkService; |
| 166 | unique_ptr<DummyTransport> transport; |
| 167 | unique_ptr<DummyFace> face; |
| 168 | LpReliability* reliability; |
| 169 | }; |
| 170 | |
| 171 | BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture) |
| 172 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 173 | BOOST_AUTO_TEST_SUITE(Sender) |
| 174 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 175 | BOOST_AUTO_TEST_CASE(SendNoFragmentField) |
| 176 | { |
| 177 | lp::Packet pkt; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 178 | |
| 179 | linkService->sendLpPackets({pkt}); |
| 180 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 181 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 182 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 185 | BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 186 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 187 | lp::Packet pkt1 = makeFrag(1024, 50); |
| 188 | lp::Packet pkt2 = makeFrag(3000, 30); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 189 | |
| 190 | linkService->sendLpPackets({pkt1}); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 191 | lp::Packet cached1(transport->sentPackets.front().packet); |
| 192 | BOOST_REQUIRE(cached1.has<lp::TxSequenceField>()); |
| 193 | BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2); |
| 194 | BOOST_CHECK(!cached1.has<lp::SequenceField>()); |
| 195 | lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>(); |
| 196 | BOOST_CHECK_EQUAL(getPktNo(cached1), 1024); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 197 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 198 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 199 | // T+500ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 200 | // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 201 | advanceClocks(time::milliseconds(1), 500); |
| 202 | linkService->sendLpPackets({pkt2}); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 203 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 204 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 205 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2); |
| 206 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1); |
| 207 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1); |
| 208 | BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt); |
| 209 | BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt); |
| 210 | BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt, |
| 211 | reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt); |
| 212 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0); |
| 213 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0); |
| 214 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq); |
| 215 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 216 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 217 | |
| 218 | // T+1250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 219 | // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1 |
| 220 | // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 221 | advanceClocks(time::milliseconds(1), 750); |
| 222 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 223 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2); |
| 224 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0); |
| 225 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1); |
| 226 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1); |
| 227 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1); |
| 228 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0); |
| 229 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1); |
| 230 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 231 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 232 | |
| 233 | // T+2250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 234 | // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2 |
| 235 | // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 236 | advanceClocks(time::milliseconds(1), 1000); |
| 237 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 238 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2); |
| 239 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0); |
| 240 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0); |
| 241 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1); |
| 242 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2); |
| 243 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1); |
| 244 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1); |
| 245 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3); |
| 246 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 248 | |
| 249 | // T+3250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 250 | // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3 |
| 251 | // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 252 | advanceClocks(time::milliseconds(1), 1000); |
| 253 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 254 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2); |
| 255 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0); |
| 256 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0); |
| 257 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1); |
| 258 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3); |
| 259 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1); |
| 260 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2); |
| 261 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5); |
| 262 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 264 | |
| 265 | // T+4250ms |
| 266 | // 1024 rto: expired, removed |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 267 | // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 268 | advanceClocks(time::milliseconds(1), 1000); |
| 269 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 270 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 1); |
| 271 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0); |
| 272 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0); |
| 273 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1); |
| 274 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3); |
| 275 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7); |
| 276 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 277 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1); |
| 279 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 280 | // T+4750ms |
| 281 | // 1024 rto: expired, removed |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 282 | // 3000 rto: expired, removed |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 283 | advanceClocks(time::milliseconds(1), 1000); |
| 284 | |
| 285 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 286 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 287 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 291 | BOOST_AUTO_TEST_CASE(SendFragmentedRetx) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 292 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 293 | lp::Packet pkt1 = makeFrag(2048, 30); |
| 294 | lp::Packet pkt2 = makeFrag(2049, 30); |
| 295 | lp::Packet pkt3 = makeFrag(2050, 10); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 296 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 297 | linkService->sendLpPackets({pkt1, pkt2, pkt3}); |
| 298 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 299 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 300 | lp::Packet cached1(transport->sentPackets.at(0).packet); |
| 301 | BOOST_REQUIRE(cached1.has<lp::TxSequenceField>()); |
| 302 | BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2); |
| 303 | BOOST_CHECK_EQUAL(getPktNo(cached1), 2048); |
| 304 | lp::Packet cached2(transport->sentPackets.at(1).packet); |
| 305 | BOOST_REQUIRE(cached2.has<lp::TxSequenceField>()); |
| 306 | BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3); |
| 307 | BOOST_CHECK_EQUAL(getPktNo(cached2), 2049); |
| 308 | lp::Packet cached3(transport->sentPackets.at(2).packet); |
| 309 | BOOST_REQUIRE(cached3.has<lp::TxSequenceField>()); |
| 310 | BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4); |
| 311 | BOOST_CHECK_EQUAL(getPktNo(cached3), 2050); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 312 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 313 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 314 | // T+0ms |
| 315 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 316 | // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0 |
| 317 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 318 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 319 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 320 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); |
| 321 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); |
| 322 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 323 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049); |
| 324 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 325 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 326 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 327 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 328 | BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt); |
| 329 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 330 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 331 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt); |
| 332 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 333 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 334 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 335 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3)); |
| 336 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 337 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 338 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 339 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 340 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 341 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 342 | // T+250ms |
| 343 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 344 | // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1 |
| 345 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 346 | advanceClocks(time::milliseconds(1), 250); |
| 347 | reliability->onLpPacketLost(getIteratorFromTxSeq(3)); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 348 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 349 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 350 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0); |
| 351 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(5), 1); |
| 352 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); |
| 353 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 354 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049); |
| 355 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 356 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 357 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 358 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1); |
| 359 | BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt); |
| 360 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 361 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 362 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt); |
| 363 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 364 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 365 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 366 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3)); |
| 367 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5)); |
| 368 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 369 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 370 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 372 | |
| 373 | // T+500ms |
| 374 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 375 | // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2 |
| 376 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 377 | advanceClocks(time::milliseconds(1), 250); |
| 378 | reliability->onLpPacketLost(getIteratorFromTxSeq(5)); |
| 379 | |
| 380 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 381 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0); |
| 382 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(6), 1); |
| 383 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); |
| 384 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 385 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049); |
| 386 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 387 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 388 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 389 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2); |
| 390 | BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt); |
| 391 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 392 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 393 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt); |
| 394 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 395 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 396 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 397 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5)); |
| 398 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6)); |
| 399 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 400 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 401 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 402 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 403 | |
| 404 | // T+750ms |
| 405 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 406 | // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3 |
| 407 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 408 | advanceClocks(time::milliseconds(1), 250); |
| 409 | reliability->onLpPacketLost(getIteratorFromTxSeq(6)); |
| 410 | |
| 411 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 412 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0); |
| 413 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(7), 1); |
| 414 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); |
| 415 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 416 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049); |
| 417 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 418 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 419 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 420 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3); |
| 421 | BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt); |
| 422 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 423 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 424 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt); |
| 425 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 426 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 427 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 428 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6)); |
| 429 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7)); |
| 430 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 431 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 432 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 433 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 434 | |
| 435 | // T+850ms |
| 436 | // 2048 rto: expired, removed |
| 437 | // 2049 rto: expired, removed |
| 438 | // 2050 rto: expired, removed |
| 439 | advanceClocks(time::milliseconds(1), 100); |
| 440 | reliability->onLpPacketLost(getIteratorFromTxSeq(7)); |
| 441 | |
| 442 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
| 443 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 444 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | BOOST_AUTO_TEST_CASE(LossByGreaterAcks) // detect loss by 3x greater Acks, also tests wraparound |
| 448 | { |
| 449 | reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE; |
| 450 | |
| 451 | // Passed to sendLpPackets individually since they are from separate, non-fragmented network packets |
| 452 | linkService->sendLpPackets({makeFrag(1, 50)}); |
| 453 | linkService->sendLpPackets({makeFrag(2, 50)}); |
| 454 | linkService->sendLpPackets({makeFrag(3, 50)}); |
| 455 | linkService->sendLpPackets({makeFrag(4, 50)}); |
| 456 | linkService->sendLpPackets({makeFrag(5, 50)}); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 457 | |
| 458 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 459 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
| 460 | BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt); |
| 461 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2 |
| 462 | BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt); |
| 463 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
| 464 | BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt); |
| 465 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4 |
| 466 | BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt); |
| 467 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 468 | BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 469 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 470 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 471 | |
| 472 | lp::Packet ackPkt1; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 473 | ackPkt1.add<lp::AckField>(0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 474 | |
| 475 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 476 | |
| 477 | reliability->processIncomingPacket(ackPkt1); |
| 478 | |
| 479 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 480 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 481 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0); |
| 482 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 483 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 484 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
| 485 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0); |
| 486 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0); |
| 487 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4 |
| 488 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 489 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0); |
| 490 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 491 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 492 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 493 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 494 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 495 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 496 | |
| 497 | lp::Packet ackPkt2; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 498 | ackPkt2.add<lp::AckField>(2); |
| 499 | ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 500 | |
| 501 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 502 | |
| 503 | reliability->processIncomingPacket(ackPkt2); |
| 504 | |
| 505 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 506 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 507 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0); |
| 508 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 509 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 510 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
| 511 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0); |
| 512 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1); |
| 513 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
| 514 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 515 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 516 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
| 517 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 518 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 519 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 520 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 521 | |
| 522 | lp::Packet ackPkt3; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 523 | ackPkt3.add<lp::AckField>(1); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 524 | |
| 525 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 526 | |
| 527 | reliability->processIncomingPacket(ackPkt3); |
| 528 | |
| 529 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 530 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq |
| 531 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 532 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3 |
| 533 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
| 534 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 535 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 536 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
| 537 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq |
| 538 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1); |
| 539 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0); |
| 540 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 541 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 542 | lp::Packet sentRetxPkt(transport->sentPackets.back().packet); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 543 | BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>()); |
| 544 | BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4); |
| 545 | BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>()); |
| 546 | BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 547 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 548 | |
| 549 | lp::Packet ackPkt4; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 550 | ackPkt4.add<lp::AckField>(4); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 551 | |
| 552 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
| 553 | |
| 554 | reliability->processIncomingPacket(ackPkt4); |
| 555 | |
| 556 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq |
| 558 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 559 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3 |
| 560 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
| 561 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 562 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 563 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1); |
| 564 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq |
| 565 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 566 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 567 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | BOOST_AUTO_TEST_SUITE_END() // Sender |
| 571 | |
| 572 | BOOST_AUTO_TEST_SUITE(Receiver) |
| 573 | |
| 574 | BOOST_AUTO_TEST_CASE(ProcessIncomingPacket) |
| 575 | { |
| 576 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 577 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 578 | |
| 579 | lp::Packet pkt1 = makeFrag(100, 40); |
| 580 | pkt1.add<lp::TxSequenceField>(765432); |
| 581 | |
| 582 | reliability->processIncomingPacket(pkt1); |
| 583 | |
| 584 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 585 | BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1); |
| 586 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432); |
| 587 | |
| 588 | lp::Packet pkt2 = makeFrag(276, 40); |
| 589 | pkt2.add<lp::TxSequenceField>(234567); |
| 590 | |
| 591 | reliability->processIncomingPacket(pkt2); |
| 592 | |
| 593 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 594 | BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2); |
| 595 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432); |
| 596 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567); |
| 597 | |
| 598 | // T+5ms |
| 599 | advanceClocks(time::milliseconds(1), 5); |
| 600 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | BOOST_AUTO_TEST_CASE(PiggybackAcks) |
| 604 | { |
| 605 | reliability->m_ackQueue.push(256); |
| 606 | reliability->m_ackQueue.push(257); |
| 607 | reliability->m_ackQueue.push(10); |
| 608 | |
| 609 | lp::Packet pkt; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 610 | linkService->sendLpPackets({pkt}); |
| 611 | |
| 612 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 613 | lp::Packet sentPkt(transport->sentPackets.front().packet); |
| 614 | |
| 615 | BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3); |
| 616 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256); |
| 617 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257); |
| 618 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 619 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 620 | |
| 621 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 622 | } |
| 623 | |
| 624 | BOOST_AUTO_TEST_CASE(PiggybackAcksMtu) |
| 625 | { |
| 626 | // This test case tests for piggybacking Acks when there is an MTU on the link. |
| 627 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 628 | transport->setMtu(1500); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 629 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 630 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 631 | reliability->m_ackQueue.push(i); |
| 632 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 633 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 634 | BOOST_CHECK(!reliability->m_ackQueue.empty()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 635 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 636 | for (int i = 0; i < 5; i++) { |
| 637 | lp::Packet pkt = makeFrag(i, 60); |
| 638 | linkService->sendLpPackets({pkt}); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 639 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 640 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i + 1); |
| 641 | lp::Packet sentPkt(transport->sentPackets.back().packet); |
| 642 | BOOST_CHECK_EQUAL(getPktNo(sentPkt), i); |
| 643 | BOOST_CHECK(sentPkt.has<lp::AckField>()); |
| 644 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 645 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 646 | BOOST_CHECK(reliability->m_ackQueue.empty()); |
| 647 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 648 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 649 | BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace) |
| 650 | { |
| 651 | // This test case tests for piggybacking Acks when there is an MTU on the link, resulting in no |
| 652 | // space for Acks (and negative remainingSpace in the piggyback function). |
| 653 | |
| 654 | transport->setMtu(250); |
| 655 | |
| 656 | for (lp::Sequence i = 1000; i < 1100; i++) { |
| 657 | reliability->m_ackQueue.push(i); |
| 658 | } |
| 659 | |
| 660 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100); |
| 661 | |
| 662 | lp::Packet pkt = makeFrag(1, 240); |
| 663 | linkService->sendLpPackets({pkt}); |
| 664 | |
| 665 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 666 | |
| 667 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 668 | lp::Packet sentPkt(transport->sentPackets.back().packet); |
| 669 | BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1); |
| 670 | BOOST_CHECK(!sentPkt.has<lp::AckField>()); |
| 671 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 672 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 673 | BOOST_AUTO_TEST_CASE(StartIdleAckTimer) |
| 674 | { |
| 675 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 676 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 677 | lp::Packet pkt1 = makeFrag(1, 100); |
| 678 | pkt1.add<lp::TxSequenceField>(12); |
| 679 | reliability->processIncomingPacket({pkt1}); |
| 680 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 681 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 682 | // T+1ms |
| 683 | advanceClocks(time::milliseconds(1), 1); |
| 684 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 685 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 686 | lp::Packet pkt2 = makeFrag(2, 100); |
| 687 | pkt2.add<lp::TxSequenceField>(13); |
| 688 | reliability->processIncomingPacket({pkt2}); |
| 689 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 690 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 691 | // T+5ms |
| 692 | advanceClocks(time::milliseconds(1), 4); |
| 693 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 694 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 695 | lp::Packet pkt3 = makeFrag(3, 100); |
| 696 | pkt3.add<lp::TxSequenceField>(15); |
| 697 | reliability->processIncomingPacket({pkt3}); |
| 698 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 699 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 700 | // T+9ms |
| 701 | advanceClocks(time::milliseconds(1), 4); |
| 702 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 703 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 704 | // T+10ms |
| 705 | advanceClocks(time::milliseconds(1), 1); |
| 706 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | BOOST_AUTO_TEST_CASE(IdleAckTimer) |
| 710 | { |
| 711 | // T+1ms |
| 712 | advanceClocks(time::milliseconds(1), 1); |
| 713 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 714 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 715 | reliability->m_ackQueue.push(i); |
| 716 | } |
| 717 | |
| 718 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 719 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 720 | reliability->startIdleAckTimer(); |
| 721 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 722 | |
| 723 | // T+5ms |
| 724 | advanceClocks(time::milliseconds(1), 4); |
| 725 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 726 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 727 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000); |
| 728 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 729 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 730 | |
| 731 | // T+6ms |
| 732 | advanceClocks(time::milliseconds(1), 1); |
| 733 | |
| 734 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 735 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 736 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 737 | lp::Packet sentPkt1(transport->sentPackets.back().packet); |
| 738 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 739 | BOOST_CHECK(!sentPkt1.has<lp::TxSequenceField>()); |
| 740 | BOOST_CHECK_EQUAL(sentPkt1.count<lp::AckField>(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 741 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 742 | for (lp::Sequence i = 10000; i < 11000; i++) { |
| 743 | reliability->m_ackQueue.push(i); |
| 744 | } |
| 745 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 746 | reliability->startIdleAckTimer(); |
| 747 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 748 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 749 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 10000); |
| 750 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 10999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 751 | |
| 752 | // T+10ms |
| 753 | advanceClocks(time::milliseconds(1), 4); |
| 754 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 755 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 756 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 757 | |
| 758 | // T+11ms |
| 759 | advanceClocks(time::milliseconds(1), 1); |
| 760 | |
| 761 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 762 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 763 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
| 764 | lp::Packet sentPkt2(transport->sentPackets.back().packet); |
| 765 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 766 | BOOST_REQUIRE_EQUAL(sentPkt2.count<lp::AckField>(), 1000); |
| 767 | BOOST_CHECK(!sentPkt2.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 768 | |
| 769 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 770 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 771 | |
| 772 | // T+16ms |
| 773 | advanceClocks(time::milliseconds(1), 5); |
| 774 | |
| 775 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 776 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2); |
| 777 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 778 | } |
| 779 | |
| 780 | BOOST_AUTO_TEST_CASE(IdleAckTimerMtu) |
| 781 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 782 | transport->setMtu(1500); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 783 | |
| 784 | // T+1ms |
| 785 | advanceClocks(time::milliseconds(1), 1); |
| 786 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 787 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 788 | reliability->m_ackQueue.push(i); |
| 789 | } |
| 790 | |
| 791 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 792 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 793 | reliability->startIdleAckTimer(); |
| 794 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 795 | |
| 796 | // T+5ms |
| 797 | advanceClocks(time::milliseconds(1), 4); |
| 798 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 799 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 800 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 801 | |
| 802 | // T+6ms |
| 803 | advanceClocks(time::milliseconds(1), 1); |
| 804 | |
| 805 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 806 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 807 | for (lp::Sequence i = 5000; i < 6000; i++) { |
| 808 | reliability->m_ackQueue.push(i); |
| 809 | } |
| 810 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 811 | reliability->startIdleAckTimer(); |
| 812 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 813 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 814 | // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet |
| 815 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
| 816 | for (int i = 0; i < 4; i++) { |
| 817 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 818 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 819 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249); |
| 820 | } |
| 821 | lp::Packet sentPkt(transport->sentPackets[4].packet); |
| 822 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 823 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 824 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 825 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 826 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 5000); |
| 827 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 5999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 828 | |
| 829 | // T+10ms |
| 830 | advanceClocks(time::milliseconds(1), 4); |
| 831 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 832 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 833 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 834 | |
| 835 | // T+11ms |
| 836 | advanceClocks(time::milliseconds(1), 1); |
| 837 | |
| 838 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 839 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 840 | for (lp::Sequence i = 100000; i < 101000; i++) { |
| 841 | reliability->m_ackQueue.push(i); |
| 842 | } |
| 843 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 844 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 845 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 846 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 847 | // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet |
| 848 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
| 849 | for (int i = 5; i < 9; i++) { |
| 850 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 851 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 852 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249); |
| 853 | } |
| 854 | sentPkt.wireDecode(transport->sentPackets[9].packet); |
| 855 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 856 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249); |
| 857 | |
| 858 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 859 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 100000); |
| 860 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 100999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 861 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 862 | |
| 863 | // T+15ms |
| 864 | advanceClocks(time::milliseconds(1), 4); |
| 865 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 866 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 10); |
| 867 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 868 | |
| 869 | // T+16ms |
| 870 | advanceClocks(time::milliseconds(1), 1); |
| 871 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 872 | // given Ack of size 8 and MTU of 1500, approx 187 Acks/IDLE packet |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 873 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 874 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16); |
| 875 | for (int i = 10; i < 15; i++) { |
| 876 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 877 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 878 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 187); |
| 879 | } |
| 880 | sentPkt.wireDecode(transport->sentPackets[15].packet); |
| 881 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 882 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 187); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 883 | |
| 884 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 885 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 886 | |
| 887 | // T+21ms |
| 888 | advanceClocks(time::milliseconds(1), 5); |
| 889 | |
| 890 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 891 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 16); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 892 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 893 | } |
| 894 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 895 | BOOST_AUTO_TEST_SUITE_END() // Receiver |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 896 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 897 | BOOST_AUTO_TEST_SUITE_END() // TestLpReliability |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 898 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 899 | |
| 900 | } // namespace tests |
| 901 | } // namespace face |
| 902 | } // namespace nfd |