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 | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [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-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 |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 70 | doSendInterest(const Interest&) final |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 71 | { |
| 72 | BOOST_ASSERT(false); |
| 73 | } |
| 74 | |
| 75 | void |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 76 | doSendData(const Data&) final |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 77 | { |
| 78 | BOOST_ASSERT(false); |
| 79 | } |
| 80 | |
| 81 | void |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 82 | doSendNack(const lp::Nack&) final |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 83 | { |
| 84 | BOOST_ASSERT(false); |
| 85 | } |
| 86 | |
| 87 | void |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 88 | doReceivePacket(Transport::Packet&&) final |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 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 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 122 | /** \brief make an LpPacket with fragment of specified size |
| 123 | * \param pktNo packet identifier, which can be extracted with \p getPktNo |
| 124 | * \param payloadSize total payload size; if this is less than 4, 4 will be used |
| 125 | */ |
| 126 | static lp::Packet |
| 127 | makeFrag(uint32_t pktNo, size_t payloadSize = 4) |
| 128 | { |
| 129 | payloadSize = std::max(payloadSize, static_cast<size_t>(4)); |
| 130 | BOOST_ASSERT(payloadSize <= 255); |
| 131 | |
| 132 | lp::Packet pkt; |
| 133 | ndn::Buffer buf(payloadSize); |
Davide Pesavento | 6d1c1c3 | 2017-10-08 21:44:05 -0400 | [diff] [blame] | 134 | std::memcpy(buf.data(), &pktNo, sizeof(pktNo)); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 135 | pkt.set<lp::FragmentField>(make_pair(buf.cbegin(), buf.cend())); |
| 136 | return pkt; |
| 137 | } |
| 138 | |
| 139 | /** \brief extract packet identifier from LpPacket made with \p makeFrag |
| 140 | * \retval 0 packet identifier cannot be extracted |
| 141 | */ |
| 142 | static uint32_t |
| 143 | getPktNo(const lp::Packet& pkt) |
| 144 | { |
| 145 | BOOST_ASSERT(pkt.has<lp::FragmentField>()); |
| 146 | |
| 147 | ndn::Buffer::const_iterator begin, end; |
| 148 | std::tie(begin, end) = pkt.get<lp::FragmentField>(); |
| 149 | if (std::distance(begin, end) < 4) { |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | uint32_t value = 0; |
| 154 | std::memcpy(&value, &*begin, sizeof(value)); |
| 155 | return value; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 158 | protected: |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 159 | unique_ptr<DummyLpReliabilityLinkService> linkService; |
| 160 | unique_ptr<DummyTransport> transport; |
| 161 | unique_ptr<DummyFace> face; |
| 162 | LpReliability* reliability; |
| 163 | }; |
| 164 | |
| 165 | BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture) |
| 166 | |
| 167 | BOOST_AUTO_TEST_CASE(SendNoFragmentField) |
| 168 | { |
| 169 | lp::Packet pkt; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 170 | |
| 171 | linkService->sendLpPackets({pkt}); |
| 172 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 173 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 174 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 175 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 176 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 177 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 180 | BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 181 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 182 | lp::Packet pkt1 = makeFrag(1024, 50); |
| 183 | lp::Packet pkt2 = makeFrag(3000, 30); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 184 | |
| 185 | linkService->sendLpPackets({pkt1}); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 186 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 187 | lp::Packet cached1(transport->sentPackets.front().packet); |
| 188 | BOOST_REQUIRE(cached1.has<lp::TxSequenceField>()); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 189 | BOOST_CHECK(!cached1.has<lp::SequenceField>()); |
| 190 | lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>(); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 191 | BOOST_CHECK_EQUAL(firstTxSeq, 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 192 | BOOST_CHECK_EQUAL(getPktNo(cached1), 1024); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 193 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 194 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 195 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 197 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 198 | // T+500ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 199 | // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 200 | advanceClocks(time::milliseconds(1), 500); |
| 201 | linkService->sendLpPackets({pkt2}); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 202 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 203 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
| 205 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1); |
| 206 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 207 | BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt); |
| 208 | BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt); |
| 209 | BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt, |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 210 | reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 211 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0); |
| 212 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0); |
| 213 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq); |
| 214 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 216 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 217 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 219 | |
| 220 | // T+1250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 221 | // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1 |
| 222 | // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 223 | advanceClocks(time::milliseconds(1), 750); |
| 224 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 229 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 230 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0); |
| 231 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1); |
| 232 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 234 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 235 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 236 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 237 | |
| 238 | // T+2250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 239 | // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2 |
| 240 | // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 241 | advanceClocks(time::milliseconds(1), 1000); |
| 242 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 244 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0); |
| 245 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 246 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 248 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 249 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1); |
| 250 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3); |
| 251 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 252 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 253 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 254 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 255 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 256 | |
| 257 | // T+3250ms |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 258 | // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3 |
| 259 | // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 260 | advanceClocks(time::milliseconds(1), 1000); |
| 261 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 262 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0); |
| 264 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 265 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 266 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 268 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2); |
| 269 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5); |
| 270 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 271 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 272 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 273 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 275 | |
| 276 | // T+4250ms |
| 277 | // 1024 rto: expired, removed |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 278 | // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 279 | advanceClocks(time::milliseconds(1), 1000); |
| 280 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 281 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 282 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0); |
| 283 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 284 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 285 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3); |
| 286 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7); |
| 287 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 288 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 290 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 291 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 292 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1); |
| 293 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 294 | // T+4750ms |
| 295 | // 1024 rto: expired, removed |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 296 | // 3000 rto: expired, removed |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 297 | advanceClocks(time::milliseconds(1), 1000); |
| 298 | |
| 299 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 300 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 301 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 302 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 303 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 304 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 2); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 308 | BOOST_AUTO_TEST_CASE(SendFragmentedRetx) |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 309 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 310 | lp::Packet pkt1 = makeFrag(2048, 30); |
| 311 | lp::Packet pkt2 = makeFrag(2049, 30); |
| 312 | lp::Packet pkt3 = makeFrag(2050, 10); |
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 | linkService->sendLpPackets({pkt1, pkt2, pkt3}); |
| 315 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 316 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 317 | lp::Packet cached1(transport->sentPackets.at(0).packet); |
| 318 | BOOST_REQUIRE(cached1.has<lp::TxSequenceField>()); |
| 319 | BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2); |
| 320 | BOOST_CHECK_EQUAL(getPktNo(cached1), 2048); |
| 321 | lp::Packet cached2(transport->sentPackets.at(1).packet); |
| 322 | BOOST_REQUIRE(cached2.has<lp::TxSequenceField>()); |
| 323 | BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3); |
| 324 | BOOST_CHECK_EQUAL(getPktNo(cached2), 2049); |
| 325 | lp::Packet cached3(transport->sentPackets.at(2).packet); |
| 326 | BOOST_REQUIRE(cached3.has<lp::TxSequenceField>()); |
| 327 | BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4); |
| 328 | BOOST_CHECK_EQUAL(getPktNo(cached3), 2050); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 330 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 331 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 332 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 333 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 334 | // T+0ms |
| 335 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 336 | // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0 |
| 337 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 338 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 340 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); |
| 341 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 343 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049); |
| 344 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 345 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 346 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 347 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 348 | BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt); |
| 349 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 350 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 351 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt); |
| 352 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 353 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 354 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 355 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3)); |
| 356 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 357 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 358 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 359 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 360 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 361 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 362 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 363 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 364 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 365 | // T+250ms |
| 366 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 367 | // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1 |
| 368 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 369 | advanceClocks(time::milliseconds(1), 250); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 370 | reliability->onLpPacketLost(3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 371 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 372 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 373 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 374 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 1); |
| 375 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 376 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 377 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049); |
| 378 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 379 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 380 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 381 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1); |
| 382 | BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt); |
| 383 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 384 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 385 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt); |
| 386 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 387 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 388 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 389 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3)); |
| 390 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5)); |
| 391 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 392 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 393 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 394 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 395 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 396 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 397 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 398 | |
| 399 | // T+500ms |
| 400 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 401 | // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2 |
| 402 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 403 | advanceClocks(time::milliseconds(1), 250); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 404 | reliability->onLpPacketLost(5); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 405 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 406 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 407 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 408 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 1); |
| 409 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 410 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 411 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049); |
| 412 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 413 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 414 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 415 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2); |
| 416 | BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt); |
| 417 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 418 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 419 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt); |
| 420 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 421 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 422 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 423 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5)); |
| 424 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6)); |
| 425 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 426 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 427 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 428 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 429 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 430 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 431 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 432 | |
| 433 | // T+750ms |
| 434 | // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0 |
| 435 | // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3 |
| 436 | // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0 |
| 437 | advanceClocks(time::milliseconds(1), 250); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 438 | reliability->onLpPacketLost(6); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 439 | |
| 440 | BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 441 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 442 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(7), 1); |
| 443 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 444 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048); |
| 445 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049); |
| 446 | BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050); |
| 447 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 448 | BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt); |
| 449 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3); |
| 450 | BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt); |
| 451 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0); |
| 452 | BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt); |
| 453 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt); |
| 454 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt); |
| 455 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3); |
| 456 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2)); |
| 457 | BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6)); |
| 458 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7)); |
| 459 | BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4)); |
| 460 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 461 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 462 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 463 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 464 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 465 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 466 | |
| 467 | // T+850ms |
| 468 | // 2048 rto: expired, removed |
| 469 | // 2049 rto: expired, removed |
| 470 | // 2050 rto: expired, removed |
| 471 | advanceClocks(time::milliseconds(1), 100); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 472 | reliability->onLpPacketLost(7); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 473 | |
| 474 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
| 475 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 476 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 477 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 478 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 479 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 482 | BOOST_AUTO_TEST_CASE(AckUnknownTxSeq) |
| 483 | { |
| 484 | linkService->sendLpPackets({makeFrag(1, 50)}); |
| 485 | |
| 486 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1); |
| 487 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 488 | BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt); |
| 489 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 490 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 491 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 492 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 493 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
| 494 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
| 495 | |
| 496 | lp::Packet ackPkt; |
| 497 | ackPkt.add<lp::AckField>(10101010); |
| 498 | reliability->processIncomingPacket(ackPkt); |
| 499 | |
| 500 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1); |
| 501 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); |
| 502 | BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt); |
| 503 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2); |
| 504 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
| 505 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 506 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 507 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
| 508 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
| 509 | } |
| 510 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 511 | BOOST_AUTO_TEST_CASE(LossByGreaterAcks) |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 512 | { |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 513 | // Detect loss by 3x greater Acks, also tests wraparound |
| 514 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 515 | reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE; |
| 516 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 517 | // Passed to sendLpPackets individually since they are |
| 518 | // from separate, non-fragmented network packets |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 519 | linkService->sendLpPackets({makeFrag(1, 50)}); |
| 520 | linkService->sendLpPackets({makeFrag(2, 50)}); |
| 521 | linkService->sendLpPackets({makeFrag(3, 50)}); |
| 522 | linkService->sendLpPackets({makeFrag(4, 50)}); |
| 523 | linkService->sendLpPackets({makeFrag(5, 50)}); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 524 | |
| 525 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 526 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
| 527 | BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt); |
| 528 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2 |
| 529 | BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt); |
| 530 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
| 531 | BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt); |
| 532 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4 |
| 533 | BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt); |
| 534 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
| 535 | BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 536 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 537 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0); |
| 538 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 539 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 540 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 541 | |
| 542 | lp::Packet ackPkt1; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 543 | ackPkt1.add<lp::AckField>(0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 544 | |
| 545 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 546 | |
| 547 | reliability->processIncomingPacket(ackPkt1); |
| 548 | |
| 549 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 550 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 551 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0); |
| 552 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 553 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 554 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 555 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0); |
| 556 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 558 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0); |
| 559 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 560 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 561 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 562 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 563 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 564 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 565 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1); |
| 566 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 567 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 568 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 569 | |
| 570 | lp::Packet ackPkt2; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 571 | ackPkt2.add<lp::AckField>(2); |
| 572 | ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 573 | |
| 574 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 575 | |
| 576 | reliability->processIncomingPacket(ackPkt2); |
| 577 | |
| 578 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 579 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1 |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 580 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0); |
| 581 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 582 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 583 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 584 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0); |
| 585 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 586 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
| 587 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 588 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 589 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
| 590 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 591 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 592 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 593 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 2); |
| 594 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 595 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 596 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 597 | |
| 598 | lp::Packet ackPkt3; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 599 | ackPkt3.add<lp::AckField>(1); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 600 | |
| 601 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 602 | |
| 603 | reliability->processIncomingPacket(ackPkt3); |
| 604 | |
| 605 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 606 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq |
| 607 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 608 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3 |
| 609 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 610 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 611 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 612 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 613 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 614 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1); |
| 615 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0); |
| 616 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 617 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 618 | lp::Packet sentRetxPkt(transport->sentPackets.back().packet); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 619 | BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>()); |
| 620 | BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4); |
| 621 | BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>()); |
| 622 | BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 623 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3); |
| 624 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 625 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 626 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 627 | |
| 628 | lp::Packet ackPkt4; |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 629 | ackPkt4.add<lp::AckField>(4); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 630 | |
| 631 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
| 632 | |
| 633 | reliability->processIncomingPacket(ackPkt4); |
| 634 | |
| 635 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 636 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq |
| 637 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2 |
| 638 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3 |
| 639 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4 |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 640 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5 |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 641 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0); |
| 642 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1); |
| 643 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq |
| 644 | BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 645 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6); |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 646 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3); |
| 647 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 1); |
| 648 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
| 649 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
| 650 | } |
| 651 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 652 | BOOST_AUTO_TEST_CASE(SkipFragmentsRemovedInRtt) |
| 653 | { |
| 654 | auto opts = linkService->getOptions(); |
| 655 | opts.reliabilityOptions.maxRetx = 0; // just to make the test case shorter |
| 656 | opts.reliabilityOptions.seqNumLossThreshold = 3; |
| 657 | linkService->setOptions(opts); |
| 658 | |
| 659 | lp::Packet frag1 = makeFrag(5001); |
| 660 | lp::Packet frag2 = makeFrag(5002); |
| 661 | linkService->sendLpPackets({frag1, frag2}); // First packet has 2 fragments |
| 662 | linkService->sendLpPackets({makeFrag(5003)}); |
| 663 | linkService->sendLpPackets({makeFrag(5004)}); |
| 664 | linkService->sendLpPackets({makeFrag(5005)}); |
| 665 | |
| 666 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 667 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5); |
| 668 | |
| 669 | lp::Sequence firstTxSeq = reliability->m_firstUnackedFrag->first; |
| 670 | |
| 671 | // Ack the last 2 packets |
| 672 | lp::Packet ackPkt1; |
| 673 | ackPkt1.add<lp::AckField>(firstTxSeq + 4); |
| 674 | ackPkt1.add<lp::AckField>(firstTxSeq + 3); |
| 675 | reliability->processIncomingPacket(ackPkt1); |
| 676 | |
| 677 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3); |
| 678 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).nGreaterSeqAcks, 2); |
| 679 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).nGreaterSeqAcks, 2); |
| 680 | |
| 681 | // Ack the third packet (5003) |
| 682 | // This triggers a "loss by greater Acks" for packets 5001 and 5002 |
| 683 | lp::Packet ackPkt2; |
| 684 | ackPkt2.add<lp::AckField>(firstTxSeq + 2); |
| 685 | reliability->processIncomingPacket(ackPkt2); // tests crash/assert reported in bug #4479 |
| 686 | |
| 687 | BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0); |
| 688 | } |
| 689 | |
Eric Newberry | 00d39fd | 2017-12-10 14:26:45 -0700 | [diff] [blame] | 690 | BOOST_AUTO_TEST_CASE(CancelLossNotificationOnAck) |
| 691 | { |
| 692 | reliability->onDroppedInterest.connect([] (const Interest&) { |
| 693 | BOOST_FAIL("Packet loss timeout should be cancelled when packet acknowledged"); |
| 694 | }); |
| 695 | |
| 696 | reliability->m_lastTxSeqNo = 0; |
| 697 | |
| 698 | linkService->sendLpPackets({makeFrag(1, 50)}); |
| 699 | |
| 700 | advanceClocks(time::milliseconds(1), 500); |
| 701 | |
| 702 | lp::Packet ackPkt; |
| 703 | ackPkt.add<lp::AckField>(1); |
| 704 | reliability->processIncomingPacket(ackPkt); |
| 705 | |
| 706 | advanceClocks(time::milliseconds(1), 1000); |
| 707 | |
| 708 | BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1); |
| 709 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0); |
| 710 | BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0); |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 711 | BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 714 | BOOST_AUTO_TEST_CASE(ProcessIncomingPacket) |
| 715 | { |
| 716 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 717 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 718 | |
| 719 | lp::Packet pkt1 = makeFrag(100, 40); |
| 720 | pkt1.add<lp::TxSequenceField>(765432); |
| 721 | |
| 722 | reliability->processIncomingPacket(pkt1); |
| 723 | |
| 724 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 725 | BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1); |
| 726 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432); |
| 727 | |
| 728 | lp::Packet pkt2 = makeFrag(276, 40); |
| 729 | pkt2.add<lp::TxSequenceField>(234567); |
| 730 | |
| 731 | reliability->processIncomingPacket(pkt2); |
| 732 | |
| 733 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 734 | BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2); |
| 735 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432); |
| 736 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567); |
| 737 | |
| 738 | // T+5ms |
| 739 | advanceClocks(time::milliseconds(1), 5); |
| 740 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | BOOST_AUTO_TEST_CASE(PiggybackAcks) |
| 744 | { |
| 745 | reliability->m_ackQueue.push(256); |
| 746 | reliability->m_ackQueue.push(257); |
| 747 | reliability->m_ackQueue.push(10); |
| 748 | |
| 749 | lp::Packet pkt; |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 750 | linkService->sendLpPackets({pkt}); |
| 751 | |
| 752 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 753 | lp::Packet sentPkt(transport->sentPackets.front().packet); |
| 754 | |
| 755 | BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3); |
| 756 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256); |
| 757 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257); |
| 758 | BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 759 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 760 | |
| 761 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 762 | } |
| 763 | |
| 764 | BOOST_AUTO_TEST_CASE(PiggybackAcksMtu) |
| 765 | { |
| 766 | // This test case tests for piggybacking Acks when there is an MTU on the link. |
| 767 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 768 | transport->setMtu(1500); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 769 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 770 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 771 | reliability->m_ackQueue.push(i); |
| 772 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 773 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 774 | BOOST_CHECK(!reliability->m_ackQueue.empty()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 775 | |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 776 | for (uint32_t i = 0; i < 5; i++) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 777 | lp::Packet pkt = makeFrag(i, 60); |
| 778 | linkService->sendLpPackets({pkt}); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 779 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 780 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i + 1); |
| 781 | lp::Packet sentPkt(transport->sentPackets.back().packet); |
| 782 | BOOST_CHECK_EQUAL(getPktNo(sentPkt), i); |
| 783 | BOOST_CHECK(sentPkt.has<lp::AckField>()); |
| 784 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 785 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 786 | BOOST_CHECK(reliability->m_ackQueue.empty()); |
| 787 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 788 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 789 | BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace) |
| 790 | { |
| 791 | // This test case tests for piggybacking Acks when there is an MTU on the link, resulting in no |
| 792 | // space for Acks (and negative remainingSpace in the piggyback function). |
| 793 | |
| 794 | transport->setMtu(250); |
| 795 | |
| 796 | for (lp::Sequence i = 1000; i < 1100; i++) { |
| 797 | reliability->m_ackQueue.push(i); |
| 798 | } |
| 799 | |
| 800 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100); |
| 801 | |
| 802 | lp::Packet pkt = makeFrag(1, 240); |
| 803 | linkService->sendLpPackets({pkt}); |
| 804 | |
| 805 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 806 | |
| 807 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 808 | lp::Packet sentPkt(transport->sentPackets.back().packet); |
| 809 | BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1); |
| 810 | BOOST_CHECK(!sentPkt.has<lp::AckField>()); |
| 811 | } |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 812 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 813 | BOOST_AUTO_TEST_CASE(StartIdleAckTimer) |
| 814 | { |
| 815 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 816 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 817 | lp::Packet pkt1 = makeFrag(1, 100); |
| 818 | pkt1.add<lp::TxSequenceField>(12); |
| 819 | reliability->processIncomingPacket({pkt1}); |
| 820 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 821 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 822 | // T+1ms |
| 823 | advanceClocks(time::milliseconds(1), 1); |
| 824 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 825 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 826 | lp::Packet pkt2 = makeFrag(2, 100); |
| 827 | pkt2.add<lp::TxSequenceField>(13); |
| 828 | reliability->processIncomingPacket({pkt2}); |
| 829 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 830 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 831 | // T+5ms |
| 832 | advanceClocks(time::milliseconds(1), 4); |
| 833 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 834 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 835 | lp::Packet pkt3 = makeFrag(3, 100); |
| 836 | pkt3.add<lp::TxSequenceField>(15); |
| 837 | reliability->processIncomingPacket({pkt3}); |
| 838 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 839 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 840 | // T+9ms |
| 841 | advanceClocks(time::milliseconds(1), 4); |
| 842 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 843 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 844 | // T+10ms |
| 845 | advanceClocks(time::milliseconds(1), 1); |
| 846 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | BOOST_AUTO_TEST_CASE(IdleAckTimer) |
| 850 | { |
| 851 | // T+1ms |
| 852 | advanceClocks(time::milliseconds(1), 1); |
| 853 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 854 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 855 | reliability->m_ackQueue.push(i); |
| 856 | } |
| 857 | |
| 858 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 859 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 860 | reliability->startIdleAckTimer(); |
| 861 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 862 | |
| 863 | // T+5ms |
| 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(reliability->m_ackQueue.size(), 1000); |
| 867 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000); |
| 868 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 869 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 870 | |
| 871 | // T+6ms |
| 872 | advanceClocks(time::milliseconds(1), 1); |
| 873 | |
| 874 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 875 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 876 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1); |
| 877 | lp::Packet sentPkt1(transport->sentPackets.back().packet); |
| 878 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 879 | BOOST_CHECK(!sentPkt1.has<lp::TxSequenceField>()); |
| 880 | BOOST_CHECK_EQUAL(sentPkt1.count<lp::AckField>(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 881 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 882 | for (lp::Sequence i = 10000; i < 11000; i++) { |
| 883 | reliability->m_ackQueue.push(i); |
| 884 | } |
| 885 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 886 | reliability->startIdleAckTimer(); |
| 887 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 888 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 889 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 10000); |
| 890 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 10999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 891 | |
| 892 | // T+10ms |
| 893 | advanceClocks(time::milliseconds(1), 4); |
| 894 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 895 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 896 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 897 | |
| 898 | // T+11ms |
| 899 | advanceClocks(time::milliseconds(1), 1); |
| 900 | |
| 901 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 902 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 903 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2); |
| 904 | lp::Packet sentPkt2(transport->sentPackets.back().packet); |
| 905 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 906 | BOOST_REQUIRE_EQUAL(sentPkt2.count<lp::AckField>(), 1000); |
| 907 | BOOST_CHECK(!sentPkt2.has<lp::TxSequenceField>()); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 908 | |
| 909 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 910 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 911 | |
| 912 | // T+16ms |
| 913 | advanceClocks(time::milliseconds(1), 5); |
| 914 | |
| 915 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 916 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2); |
| 917 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 918 | } |
| 919 | |
| 920 | BOOST_AUTO_TEST_CASE(IdleAckTimerMtu) |
| 921 | { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 922 | transport->setMtu(1500); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 923 | |
| 924 | // T+1ms |
| 925 | advanceClocks(time::milliseconds(1), 1); |
| 926 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 927 | for (lp::Sequence i = 1000; i < 2000; i++) { |
| 928 | reliability->m_ackQueue.push(i); |
| 929 | } |
| 930 | |
| 931 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 932 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 933 | reliability->startIdleAckTimer(); |
| 934 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 935 | |
| 936 | // T+5ms |
| 937 | advanceClocks(time::milliseconds(1), 4); |
| 938 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 939 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 940 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0); |
| 941 | |
| 942 | // T+6ms |
| 943 | advanceClocks(time::milliseconds(1), 1); |
| 944 | |
| 945 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 946 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 947 | for (lp::Sequence i = 5000; i < 6000; i++) { |
| 948 | reliability->m_ackQueue.push(i); |
| 949 | } |
| 950 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 951 | reliability->startIdleAckTimer(); |
| 952 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 953 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 954 | // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet |
| 955 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 956 | for (size_t i = 0; i < 4; i++) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 957 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 958 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 959 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249); |
| 960 | } |
| 961 | lp::Packet sentPkt(transport->sentPackets[4].packet); |
| 962 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 963 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 964 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 965 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 966 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 5000); |
| 967 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 5999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 968 | |
| 969 | // T+10ms |
| 970 | advanceClocks(time::milliseconds(1), 4); |
| 971 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 972 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5); |
| 973 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 974 | |
| 975 | // T+11ms |
| 976 | advanceClocks(time::milliseconds(1), 1); |
| 977 | |
| 978 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
| 979 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 980 | for (lp::Sequence i = 100000; i < 101000; i++) { |
| 981 | reliability->m_ackQueue.push(i); |
| 982 | } |
| 983 | |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 984 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 985 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 986 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 987 | // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet |
| 988 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 989 | for (size_t i = 5; i < 9; i++) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 990 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 991 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 992 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249); |
| 993 | } |
| 994 | sentPkt.wireDecode(transport->sentPackets[9].packet); |
| 995 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 996 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249); |
| 997 | |
| 998 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
| 999 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 100000); |
| 1000 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 100999); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1001 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
| 1002 | |
| 1003 | // T+15ms |
| 1004 | advanceClocks(time::milliseconds(1), 4); |
| 1005 | BOOST_CHECK(reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1006 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 10); |
| 1007 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1008 | |
| 1009 | // T+16ms |
| 1010 | advanceClocks(time::milliseconds(1), 1); |
| 1011 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1012 | // 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] | 1013 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1014 | BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16); |
Eric Newberry | 971d962 | 2018-03-30 23:29:26 -0700 | [diff] [blame] | 1015 | for (size_t i = 10; i < 15; i++) { |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1016 | lp::Packet sentPkt(transport->sentPackets[i].packet); |
| 1017 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 1018 | BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 187); |
| 1019 | } |
| 1020 | sentPkt.wireDecode(transport->sentPackets[15].packet); |
| 1021 | BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>()); |
| 1022 | BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 187); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1023 | |
| 1024 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1025 | reliability->startIdleAckTimer(); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1026 | |
| 1027 | // T+21ms |
| 1028 | advanceClocks(time::milliseconds(1), 5); |
| 1029 | |
| 1030 | BOOST_CHECK(!reliability->m_isIdleAckTimerRunning); |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1031 | BOOST_CHECK_EQUAL(transport->sentPackets.size(), 16); |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1032 | BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0); |
| 1033 | } |
| 1034 | |
Eric Newberry | 7b0071e | 2017-07-03 17:33:31 +0000 | [diff] [blame] | 1035 | BOOST_AUTO_TEST_SUITE_END() // TestLpReliability |
Eric Newberry | 185ab29 | 2017-03-28 06:45:39 +0000 | [diff] [blame] | 1036 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 1037 | |
| 1038 | } // namespace tests |
| 1039 | } // namespace face |
| 1040 | } // namespace nfd |