blob: 525ab979d89f2bd91679d0b09e2885266dc09cd9 [file] [log] [blame]
Eric Newberry185ab292017-03-28 06:45:39 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberry32f7eac2020-02-07 14:40:17 -08003 * Copyright (c) 2014-2020, Regents of the University of California,
Eric Newberry185ab292017-03-28 06:45:39 +00004 * 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 Newberry185ab292017-03-28 06:45:39 +000028#include "face/generic-link-service.hpp"
29
30#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040031#include "tests/daemon/global-io-fixture.hpp"
Eric Newberry185ab292017-03-28 06:45:39 +000032#include "dummy-face.hpp"
33#include "dummy-transport.hpp"
34
Eric Newberry7b0071e2017-07-03 17:33:31 +000035#include <cstring>
36
Eric Newberry185ab292017-03-28 06:45:39 +000037namespace nfd {
38namespace face {
39namespace tests {
40
41using namespace nfd::tests;
42
Eric Newberry185ab292017-03-28 06:45:39 +000043class DummyLpReliabilityLinkService : public GenericLinkService
44{
45public:
46 LpReliability*
47 getLpReliability()
48 {
49 return &m_reliability;
50 }
51
52 void
53 sendLpPackets(std::vector<lp::Packet> frags)
54 {
55 if (frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -070056 Interest interest("/test/prefix");
Junxiao Shi9d727852019-05-14 13:44:22 -060057 interest.setCanBePrefix(false);
Eric Newberry41aba102017-11-01 16:42:13 -070058 lp::Packet pkt;
Davide Pesaventof190cfa2019-07-17 20:14:11 -040059 pkt.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
Eric Newberry32f7eac2020-02-07 14:40:17 -080060 assignSequences(frags);
Eric Newberry41aba102017-11-01 16:42:13 -070061 m_reliability.handleOutgoing(frags, std::move(pkt), true);
Eric Newberry185ab292017-03-28 06:45:39 +000062 }
63
Davide Pesaventof190cfa2019-07-17 20:14:11 -040064 for (auto frag : frags) {
ashiqopu075bb7d2019-03-10 01:38:21 +000065 this->sendLpPacket(std::move(frag), 0);
Eric Newberry185ab292017-03-28 06:45:39 +000066 }
67 }
68
69private:
70 void
ashiqopu075bb7d2019-03-10 01:38:21 +000071 doSendInterest(const Interest&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000072 {
Davide Pesavento5a897692019-10-31 01:28:43 -040073 BOOST_FAIL("unexpected doSendInterest");
Eric Newberry185ab292017-03-28 06:45:39 +000074 }
75
76 void
ashiqopu075bb7d2019-03-10 01:38:21 +000077 doSendData(const Data&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000078 {
Davide Pesavento5a897692019-10-31 01:28:43 -040079 BOOST_FAIL("unexpected doSendData");
Eric Newberry185ab292017-03-28 06:45:39 +000080 }
81
82 void
ashiqopu075bb7d2019-03-10 01:38:21 +000083 doSendNack(const lp::Nack&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000084 {
Davide Pesavento5a897692019-10-31 01:28:43 -040085 BOOST_FAIL("unexpected doSendNack");
Eric Newberry185ab292017-03-28 06:45:39 +000086 }
87
88 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040089 doReceivePacket(const Block&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000090 {
Davide Pesavento5a897692019-10-31 01:28:43 -040091 BOOST_FAIL("unexpected doReceivePacket");
Eric Newberry185ab292017-03-28 06:45:39 +000092 }
93};
94
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040095class LpReliabilityFixture : public GlobalIoTimeFixture
Eric Newberry185ab292017-03-28 06:45:39 +000096{
97public:
98 LpReliabilityFixture()
99 : linkService(make_unique<DummyLpReliabilityLinkService>())
100 , transport(make_unique<DummyTransport>())
101 , face(make_unique<DummyFace>())
102 {
103 linkService->setFaceAndTransport(*face, *transport);
104 transport->setFaceAndLinkService(*face, *linkService);
105
106 GenericLinkService::Options options;
107 options.reliabilityOptions.isEnabled = true;
108 linkService->setOptions(options);
109
110 reliability = linkService->getLpReliability();
Eric Newberry7b0071e2017-07-03 17:33:31 +0000111 reliability->m_lastTxSeqNo = 1;
112 }
113
114 static bool
115 netPktHasUnackedFrag(const shared_ptr<LpReliability::NetPkt>& netPkt, lp::Sequence txSeq)
116 {
117 return std::any_of(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(),
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400118 [txSeq] (auto fragIt) { return fragIt->first == txSeq; });
Eric Newberry7b0071e2017-07-03 17:33:31 +0000119 }
120
Eric Newberry7b0071e2017-07-03 17:33:31 +0000121 /** \brief make an LpPacket with fragment of specified size
Eric Newberry32f7eac2020-02-07 14:40:17 -0800122 * \param pktNum packet identifier, which can be extracted with \p getPktNum
Davide Pesaventob93fb6c2020-04-12 14:10:45 -0400123 * \param payloadSize total payload size; must be >= 4 and <= 255
Eric Newberry7b0071e2017-07-03 17:33:31 +0000124 */
125 static lp::Packet
Eric Newberry32f7eac2020-02-07 14:40:17 -0800126 makeFrag(uint32_t pktNum, size_t payloadSize = 4)
Eric Newberry7b0071e2017-07-03 17:33:31 +0000127 {
Davide Pesaventob93fb6c2020-04-12 14:10:45 -0400128 BOOST_ASSERT(payloadSize >= 4 && payloadSize <= 255);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000129 lp::Packet pkt;
130 ndn::Buffer buf(payloadSize);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800131 std::memcpy(buf.data(), &pktNum, sizeof(pktNum));
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400132 pkt.set<lp::FragmentField>({buf.cbegin(), buf.cend()});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000133 return pkt;
134 }
135
136 /** \brief extract packet identifier from LpPacket made with \p makeFrag
137 * \retval 0 packet identifier cannot be extracted
138 */
139 static uint32_t
Eric Newberry32f7eac2020-02-07 14:40:17 -0800140 getPktNum(const lp::Packet& pkt)
Eric Newberry7b0071e2017-07-03 17:33:31 +0000141 {
Davide Pesaventob93fb6c2020-04-12 14:10:45 -0400142 BOOST_REQUIRE(pkt.has<lp::FragmentField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000143 ndn::Buffer::const_iterator begin, end;
144 std::tie(begin, end) = pkt.get<lp::FragmentField>();
145 if (std::distance(begin, end) < 4) {
146 return 0;
147 }
148
149 uint32_t value = 0;
150 std::memcpy(&value, &*begin, sizeof(value));
151 return value;
Eric Newberry185ab292017-03-28 06:45:39 +0000152 }
153
Eric Newberry971d9622018-03-30 23:29:26 -0700154protected:
Eric Newberry185ab292017-03-28 06:45:39 +0000155 unique_ptr<DummyLpReliabilityLinkService> linkService;
156 unique_ptr<DummyTransport> transport;
157 unique_ptr<DummyFace> face;
158 LpReliability* reliability;
159};
160
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400161BOOST_AUTO_TEST_SUITE(Face)
Eric Newberry185ab292017-03-28 06:45:39 +0000162BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture)
163
164BOOST_AUTO_TEST_CASE(SendNoFragmentField)
165{
166 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000167
168 linkService->sendLpPackets({pkt});
169 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000170 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700171 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
172 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
173 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700174 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000175}
176
Eric Newberry7b0071e2017-07-03 17:33:31 +0000177BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000178{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000179 lp::Packet pkt1 = makeFrag(1024, 50);
180 lp::Packet pkt2 = makeFrag(3000, 30);
Eric Newberry185ab292017-03-28 06:45:39 +0000181
182 linkService->sendLpPackets({pkt1});
Eric Newberry971d9622018-03-30 23:29:26 -0700183 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000184 lp::Packet cached1(transport->sentPackets.front().packet);
185 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
Eric Newberry32f7eac2020-02-07 14:40:17 -0800186 BOOST_CHECK(cached1.has<lp::SequenceField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000187 lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>();
Eric Newberry971d9622018-03-30 23:29:26 -0700188 BOOST_CHECK_EQUAL(firstTxSeq, 2);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800189 BOOST_CHECK_EQUAL(getPktNum(cached1), 1024);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700190 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
191 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
192 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700193 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000194
Eric Newberry185ab292017-03-28 06:45:39 +0000195 // T+500ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000196 // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400197 advanceClocks(1_ms, 500);
Eric Newberry185ab292017-03-28 06:45:39 +0000198 linkService->sendLpPackets({pkt2});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000199 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000200
Eric Newberry00d39fd2017-12-10 14:26:45 -0700201 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
202 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1);
203 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000204 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt);
205 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
206 BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt,
Eric Newberry971d9622018-03-30 23:29:26 -0700207 reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000208 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0);
209 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
210 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq);
211 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700212 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
213 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
214 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700215 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000216
217 // T+1250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000218 // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1
219 // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400220 advanceClocks(1_ms, 750);
Eric Newberry185ab292017-03-28 06:45:39 +0000221
Eric Newberry00d39fd2017-12-10 14:26:45 -0700222 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000223 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700224 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000225 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700226 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000227 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
228 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1);
229 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700230 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
231 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
232 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700233 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000234
235 // T+2250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000236 // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2
237 // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1
Davide Pesavento14e71f02019-03-28 17:35:25 -0400238 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000239
Eric Newberry00d39fd2017-12-10 14:26:45 -0700240 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000241 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0);
242 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700243 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000244 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700245 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000246 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1);
247 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3);
248 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700249 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
250 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
251 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700252 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000253
254 // T+3250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000255 // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3
256 // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2
Davide Pesavento14e71f02019-03-28 17:35:25 -0400257 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000258
Eric Newberry00d39fd2017-12-10 14:26:45 -0700259 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000260 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0);
261 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700262 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000263 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700264 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000265 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2);
266 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5);
267 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700268 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
269 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
270 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700271 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000272
273 // T+4250ms
274 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000275 // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3
Davide Pesavento14e71f02019-03-28 17:35:25 -0400276 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000277
Eric Newberry00d39fd2017-12-10 14:26:45 -0700278 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000279 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0);
280 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700281 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000282 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3);
283 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7);
284 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry185ab292017-03-28 06:45:39 +0000285
Eric Newberry00d39fd2017-12-10 14:26:45 -0700286 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
287 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
288 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700289 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700290
Eric Newberry185ab292017-03-28 06:45:39 +0000291 // T+4750ms
292 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000293 // 3000 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400294 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000295
296 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000297 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
298 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700299 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
300 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
301 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 2);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700302 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000303}
304
Eric Newberry7b0071e2017-07-03 17:33:31 +0000305BOOST_AUTO_TEST_CASE(SendFragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000306{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000307 lp::Packet pkt1 = makeFrag(2048, 30);
308 lp::Packet pkt2 = makeFrag(2049, 30);
309 lp::Packet pkt3 = makeFrag(2050, 10);
Eric Newberry185ab292017-03-28 06:45:39 +0000310
Eric Newberry7b0071e2017-07-03 17:33:31 +0000311 linkService->sendLpPackets({pkt1, pkt2, pkt3});
312 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000313
Eric Newberry7b0071e2017-07-03 17:33:31 +0000314 lp::Packet cached1(transport->sentPackets.at(0).packet);
315 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
316 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800317 BOOST_CHECK(cached1.has<lp::SequenceField>());
318 BOOST_CHECK_EQUAL(getPktNum(cached1), 2048);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000319 lp::Packet cached2(transport->sentPackets.at(1).packet);
320 BOOST_REQUIRE(cached2.has<lp::TxSequenceField>());
321 BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800322 BOOST_CHECK(cached2.has<lp::SequenceField>());
323 BOOST_CHECK_EQUAL(getPktNum(cached2), 2049);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000324 lp::Packet cached3(transport->sentPackets.at(2).packet);
325 BOOST_REQUIRE(cached3.has<lp::TxSequenceField>());
326 BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800327 BOOST_CHECK(cached3.has<lp::SequenceField>());
328 BOOST_CHECK_EQUAL(getPktNum(cached3), 2050);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700329 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
330 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
331 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700332 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000333
Eric Newberry7b0071e2017-07-03 17:33:31 +0000334 // 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 Newberry185ab292017-03-28 06:45:39 +0000338
Eric Newberry00d39fd2017-12-10 14:26:45 -0700339 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 Newberry32f7eac2020-02-07 14:40:17 -0800342 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(2).pkt), 2048);
343 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(3).pkt), 2049);
344 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(4).pkt), 2050);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000345 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 Newberry00d39fd2017-12-10 14:26:45 -0700360 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
361 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
362 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700363 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000364
Eric Newberry7b0071e2017-07-03 17:33:31 +0000365 // 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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400369 advanceClocks(1_ms, 250);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800370 reliability->onLpPacketLost(3, true);
Eric Newberry185ab292017-03-28 06:45:39 +0000371
Eric Newberry00d39fd2017-12-10 14:26:45 -0700372 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000373 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700374 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 1);
375 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800376 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(2).pkt), 2048);
377 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(5).pkt), 2049);
378 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(4).pkt), 2050);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000379 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 Newberry00d39fd2017-12-10 14:26:45 -0700394 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
395 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
396 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700397 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000398
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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400403 advanceClocks(1_ms, 250);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800404 reliability->onLpPacketLost(5, true);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000405
Eric Newberry00d39fd2017-12-10 14:26:45 -0700406 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000407 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700408 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 1);
409 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800410 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(2).pkt), 2048);
411 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(6).pkt), 2049);
412 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(4).pkt), 2050);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000413 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 Newberry00d39fd2017-12-10 14:26:45 -0700428 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
429 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
430 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700431 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000432
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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400437 advanceClocks(1_ms, 250);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800438 reliability->onLpPacketLost(6, true);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000439
440 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
441 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700442 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(7), 1);
443 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800444 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(2).pkt), 2048);
445 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(7).pkt), 2049);
446 BOOST_CHECK_EQUAL(getPktNum(reliability->m_unackedFrags.at(4).pkt), 2050);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000447 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 Newberry00d39fd2017-12-10 14:26:45 -0700462 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
463 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
464 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700465 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000466
467 // T+850ms
468 // 2048 rto: expired, removed
469 // 2049 rto: expired, removed
470 // 2050 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400471 advanceClocks(1_ms, 100);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800472 reliability->onLpPacketLost(7, true);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000473
474 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
475 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700476 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
477 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
478 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700479 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000480}
481
Eric Newberry00d39fd2017-12-10 14:26:45 -0700482BOOST_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);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700494 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700495
496 lp::Packet ackPkt;
497 ackPkt.add<lp::AckField>(10101010);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800498 BOOST_CHECK(reliability->processIncomingPacket(ackPkt));
Eric Newberry00d39fd2017-12-10 14:26:45 -0700499
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);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700508 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700509}
510
Eric Newberry971d9622018-03-30 23:29:26 -0700511BOOST_AUTO_TEST_CASE(LossByGreaterAcks)
Eric Newberry7b0071e2017-07-03 17:33:31 +0000512{
Eric Newberry971d9622018-03-30 23:29:26 -0700513 // Detect loss by 3x greater Acks, also tests wraparound
514
Eric Newberry7b0071e2017-07-03 17:33:31 +0000515 reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE;
516
Eric Newberry971d9622018-03-30 23:29:26 -0700517 // Passed to sendLpPackets individually since they are
518 // from separate, non-fragmented network packets
Eric Newberry7b0071e2017-07-03 17:33:31 +0000519 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 Newberry185ab292017-03-28 06:45:39 +0000524
525 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000526 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 Newberry185ab292017-03-28 06:45:39 +0000536 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700537 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
538 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
539 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700540 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000541
542 lp::Packet ackPkt1;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000543 ackPkt1.add<lp::AckField>(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000544
545 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
546
Eric Newberry32f7eac2020-02-07 14:40:17 -0800547 BOOST_CHECK(reliability->processIncomingPacket(ackPkt1));
Eric Newberry185ab292017-03-28 06:45:39 +0000548
549 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700550 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000551 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
552 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000553 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700554 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000555 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
556 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700557 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
Eric Newberry7b0071e2017-07-03 17:33:31 +0000558 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
559 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700560 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000561 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
562 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000563 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000564 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700565 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
566 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
567 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700568 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000569
570 lp::Packet ackPkt2;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000571 ackPkt2.add<lp::AckField>(2);
572 ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored
Eric Newberry185ab292017-03-28 06:45:39 +0000573
574 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
575
Eric Newberry32f7eac2020-02-07 14:40:17 -0800576 BOOST_CHECK(reliability->processIncomingPacket(ackPkt2));
Eric Newberry185ab292017-03-28 06:45:39 +0000577
578 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000579 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000580 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
581 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000582 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700583 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000584 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
585 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700586 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
587 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000588 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 Newberry185ab292017-03-28 06:45:39 +0000591 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000592 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700593 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 2);
594 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
595 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700596 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000597
598 lp::Packet ackPkt3;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000599 ackPkt3.add<lp::AckField>(1);
Eric Newberry185ab292017-03-28 06:45:39 +0000600
601 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
602
Eric Newberry32f7eac2020-02-07 14:40:17 -0800603 BOOST_CHECK(reliability->processIncomingPacket(ackPkt3));
Eric Newberry185ab292017-03-28 06:45:39 +0000604
605 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000606 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 Newberry00d39fd2017-12-10 14:26:45 -0700610 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000611 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
612 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700613 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq
Eric Newberry7b0071e2017-07-03 17:33:31 +0000614 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 Newberry185ab292017-03-28 06:45:39 +0000617 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry185ab292017-03-28 06:45:39 +0000618 lp::Packet sentRetxPkt(transport->sentPackets.back().packet);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000619 BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>());
620 BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800621 BOOST_CHECK_EQUAL(getPktNum(sentRetxPkt), 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700622 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
623 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
624 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700625 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000626
627 lp::Packet ackPkt4;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000628 ackPkt4.add<lp::AckField>(4);
Eric Newberry185ab292017-03-28 06:45:39 +0000629
630 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
631
Eric Newberry32f7eac2020-02-07 14:40:17 -0800632 BOOST_CHECK(reliability->processIncomingPacket(ackPkt4));
Eric Newberry185ab292017-03-28 06:45:39 +0000633
634 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000635 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
636 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
637 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
638 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700639 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000640 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
641 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1);
642 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq
643 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000644 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700645 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
646 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 1);
647 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700648 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700649}
650
Eric Newberry971d9622018-03-30 23:29:26 -0700651BOOST_AUTO_TEST_CASE(SkipFragmentsRemovedInRtt)
652{
653 auto opts = linkService->getOptions();
654 opts.reliabilityOptions.maxRetx = 0; // just to make the test case shorter
655 opts.reliabilityOptions.seqNumLossThreshold = 3;
656 linkService->setOptions(opts);
657
658 lp::Packet frag1 = makeFrag(5001);
659 lp::Packet frag2 = makeFrag(5002);
660 linkService->sendLpPackets({frag1, frag2}); // First packet has 2 fragments
661 linkService->sendLpPackets({makeFrag(5003)});
662 linkService->sendLpPackets({makeFrag(5004)});
663 linkService->sendLpPackets({makeFrag(5005)});
664
665 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
666 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
667
668 lp::Sequence firstTxSeq = reliability->m_firstUnackedFrag->first;
669
670 // Ack the last 2 packets
671 lp::Packet ackPkt1;
672 ackPkt1.add<lp::AckField>(firstTxSeq + 4);
673 ackPkt1.add<lp::AckField>(firstTxSeq + 3);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800674 BOOST_CHECK(reliability->processIncomingPacket(ackPkt1));
Eric Newberry971d9622018-03-30 23:29:26 -0700675
676 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
677 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).nGreaterSeqAcks, 2);
678 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).nGreaterSeqAcks, 2);
679
680 // Ack the third packet (5003)
681 // This triggers a "loss by greater Acks" for packets 5001 and 5002
682 lp::Packet ackPkt2;
683 ackPkt2.add<lp::AckField>(firstTxSeq + 2);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800684 BOOST_CHECK(reliability->processIncomingPacket(ackPkt2)); // tests crash/assert reported in bug #4479
Eric Newberry971d9622018-03-30 23:29:26 -0700685
686 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
687}
688
Eric Newberry00d39fd2017-12-10 14:26:45 -0700689BOOST_AUTO_TEST_CASE(CancelLossNotificationOnAck)
690{
691 reliability->onDroppedInterest.connect([] (const Interest&) {
692 BOOST_FAIL("Packet loss timeout should be cancelled when packet acknowledged");
693 });
694
695 reliability->m_lastTxSeqNo = 0;
696
697 linkService->sendLpPackets({makeFrag(1, 50)});
698
Davide Pesavento14e71f02019-03-28 17:35:25 -0400699 advanceClocks(1_ms, 500);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700700
701 lp::Packet ackPkt;
702 ackPkt.add<lp::AckField>(1);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800703 BOOST_CHECK(reliability->processIncomingPacket(ackPkt));
Eric Newberry00d39fd2017-12-10 14:26:45 -0700704
Davide Pesavento14e71f02019-03-28 17:35:25 -0400705 advanceClocks(1_ms, 1000);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700706
707 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
708 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
709 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry9d283ad2020-04-12 23:37:17 -0700710 BOOST_CHECK_EQUAL(linkService->getCounters().nInterestsExceededRetx, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000711}
712
Eric Newberry7b0071e2017-07-03 17:33:31 +0000713BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
714{
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400715 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000716 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
717
718 lp::Packet pkt1 = makeFrag(100, 40);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800719 pkt1.add<lp::SequenceField>(123456);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000720 pkt1.add<lp::TxSequenceField>(765432);
721
Eric Newberry32f7eac2020-02-07 14:40:17 -0800722 BOOST_CHECK(reliability->processIncomingPacket(pkt1));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000723
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400724 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000725 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1);
726 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800727 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 1);
728 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(123456), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000729
730 lp::Packet pkt2 = makeFrag(276, 40);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800731 pkt2.add<lp::SequenceField>(654321);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000732 pkt2.add<lp::TxSequenceField>(234567);
733
Eric Newberry32f7eac2020-02-07 14:40:17 -0800734 BOOST_CHECK(reliability->processIncomingPacket(pkt2));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000735
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400736 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000737 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2);
738 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
739 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800740 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 2);
741 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(123456), 1);
742 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(654321), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000743
744 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400745 advanceClocks(1_ms, 5);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400746 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000747}
748
749BOOST_AUTO_TEST_CASE(PiggybackAcks)
750{
751 reliability->m_ackQueue.push(256);
752 reliability->m_ackQueue.push(257);
753 reliability->m_ackQueue.push(10);
754
755 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000756 linkService->sendLpPackets({pkt});
757
758 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
759 lp::Packet sentPkt(transport->sentPackets.front().packet);
760
761 BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3);
762 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256);
763 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257);
764 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000765 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000766
767 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
768}
769
770BOOST_AUTO_TEST_CASE(PiggybackAcksMtu)
771{
Eric Newberry32f7eac2020-02-07 14:40:17 -0800772 // MTU is 1500, payload has 60 octets plus 6 octets for LpPacket and Fragment TL and 10 octets
773 // each for Sequence and TxSequence, leaving 1414 octets for piggybacking. Each Ack header is 12
774 // octets, so each LpPacket can carry 117 Acks, and it takes 9 LpPackets for 1000 Acks.
Eric Newberry185ab292017-03-28 06:45:39 +0000775
Eric Newberry7b0071e2017-07-03 17:33:31 +0000776 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000777
Junxiao Shi21e01932018-04-21 10:39:05 +0000778 std::unordered_set<lp::Sequence> expectedAcks;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000779 for (lp::Sequence i = 1000; i < 2000; i++) {
780 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000781 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000782 }
Eric Newberry185ab292017-03-28 06:45:39 +0000783
Junxiao Shi21e01932018-04-21 10:39:05 +0000784 for (uint32_t i = 1; i <= 9; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000785 lp::Packet pkt = makeFrag(i, 60);
786 linkService->sendLpPackets({pkt});
Eric Newberry185ab292017-03-28 06:45:39 +0000787
Junxiao Shi21e01932018-04-21 10:39:05 +0000788 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000789 lp::Packet sentPkt(transport->sentPackets.back().packet);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800790 BOOST_CHECK_EQUAL(getPktNum(sentPkt), i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000791 BOOST_CHECK(sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000792
793 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
794 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
795 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000796 }
Eric Newberry185ab292017-03-28 06:45:39 +0000797
Eric Newberry7b0071e2017-07-03 17:33:31 +0000798 BOOST_CHECK(reliability->m_ackQueue.empty());
Junxiao Shi21e01932018-04-21 10:39:05 +0000799 BOOST_CHECK(expectedAcks.empty());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000800}
Eric Newberry185ab292017-03-28 06:45:39 +0000801
Eric Newberry7b0071e2017-07-03 17:33:31 +0000802BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace)
803{
Eric Newberry32f7eac2020-02-07 14:40:17 -0800804 // MTU is 64, payload has 34 octets plus 4 octets for LpPacket and Fragment TL and 10 octets each
805 // for Sequence and TxSequence, leaving 6 octets for piggybacking. Each Ack header is 12 octets,
806 // so there's no room to piggyback any Ack in LpPacket.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000807
Eric Newberrycb6551e2020-03-02 14:12:16 -0800808 transport->setMtu(MIN_MTU);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000809
810 for (lp::Sequence i = 1000; i < 1100; i++) {
811 reliability->m_ackQueue.push(i);
812 }
813
Eric Newberry32f7eac2020-02-07 14:40:17 -0800814 lp::Packet pkt = makeFrag(1, 34);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000815 linkService->sendLpPackets({pkt});
816
Eric Newberry185ab292017-03-28 06:45:39 +0000817 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000818 lp::Packet sentPkt(transport->sentPackets.back().packet);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800819 BOOST_CHECK_EQUAL(getPktNum(sentPkt), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000820 BOOST_CHECK(!sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000821
822 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000823}
Eric Newberry185ab292017-03-28 06:45:39 +0000824
Eric Newberry7b0071e2017-07-03 17:33:31 +0000825BOOST_AUTO_TEST_CASE(StartIdleAckTimer)
826{
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400827 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000828
Eric Newberry7b0071e2017-07-03 17:33:31 +0000829 lp::Packet pkt1 = makeFrag(1, 100);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800830 pkt1.add<lp::SequenceField>(1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000831 pkt1.add<lp::TxSequenceField>(12);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800832 BOOST_CHECK(reliability->processIncomingPacket({pkt1}));
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400833 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000834
Eric Newberry7b0071e2017-07-03 17:33:31 +0000835 // T+1ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400836 advanceClocks(1_ms, 1);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400837 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000838
Eric Newberry7b0071e2017-07-03 17:33:31 +0000839 lp::Packet pkt2 = makeFrag(2, 100);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800840 pkt2.add<lp::SequenceField>(2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000841 pkt2.add<lp::TxSequenceField>(13);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800842 BOOST_CHECK(reliability->processIncomingPacket({pkt2}));
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400843 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000844
Eric Newberry7b0071e2017-07-03 17:33:31 +0000845 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400846 advanceClocks(1_ms, 4);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400847 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000848
Eric Newberry7b0071e2017-07-03 17:33:31 +0000849 lp::Packet pkt3 = makeFrag(3, 100);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800850 pkt3.add<lp::SequenceField>(3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000851 pkt3.add<lp::TxSequenceField>(15);
Eric Newberry32f7eac2020-02-07 14:40:17 -0800852 BOOST_CHECK(reliability->processIncomingPacket({pkt3}));
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400853 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000854
Eric Newberry7b0071e2017-07-03 17:33:31 +0000855 // T+9ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400856 advanceClocks(1_ms, 4);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400857 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000858
Eric Newberry7b0071e2017-07-03 17:33:31 +0000859 // T+10ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400860 advanceClocks(1_ms, 1);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400861 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000862}
863
864BOOST_AUTO_TEST_CASE(IdleAckTimer)
865{
Junxiao Shi21e01932018-04-21 10:39:05 +0000866 // T+0ms: populate ack queue and start idle ack timer
867 std::unordered_set<lp::Sequence> expectedAcks;
868 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000869 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000870 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000871 }
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400872 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000873 reliability->startIdleAckTimer();
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400874 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000875
Junxiao Shi21e01932018-04-21 10:39:05 +0000876 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400877 advanceClocks(1_ms, 4);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400878 BOOST_CHECK(reliability->m_idleAckTimer);
Junxiao Shi21e01932018-04-21 10:39:05 +0000879 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000880 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
Junxiao Shi21e01932018-04-21 10:39:05 +0000881 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000882 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
883
Junxiao Shi21e01932018-04-21 10:39:05 +0000884 // T+5ms: idle ack timer expires, IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400885 advanceClocks(1_ms, 1);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400886 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000887 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000888 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000889
Junxiao Shi21e01932018-04-21 10:39:05 +0000890 lp::Packet sentPkt(transport->sentPackets.back().packet);
891 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
892 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
893 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000894 }
Junxiao Shi21e01932018-04-21 10:39:05 +0000895 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000896}
897
898BOOST_AUTO_TEST_CASE(IdleAckTimerMtu)
899{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000900 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000901
Junxiao Shi21e01932018-04-21 10:39:05 +0000902 // T+0ms: populate ack queue and start idle ack timer
903 std::unordered_set<lp::Sequence> expectedAcks;
904 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000905 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000906 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000907 }
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400908 BOOST_CHECK(!reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000909 reliability->startIdleAckTimer();
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400910 BOOST_CHECK(reliability->m_idleAckTimer);
Eric Newberry185ab292017-03-28 06:45:39 +0000911
Junxiao Shi21e01932018-04-21 10:39:05 +0000912 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400913 advanceClocks(1_ms, 4);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400914 BOOST_CHECK(reliability->m_idleAckTimer);
Junxiao Shi21e01932018-04-21 10:39:05 +0000915 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
916 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
917 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000918 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
919
Junxiao Shi21e01932018-04-21 10:39:05 +0000920 // T+5ms: idle ack timer expires, IDLE packets generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400921 advanceClocks(1_ms, 1);
Davide Pesaventof190cfa2019-07-17 20:14:11 -0400922 BOOST_CHECK(!reliability->m_idleAckTimer);
Junxiao Shi21e01932018-04-21 10:39:05 +0000923 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000924
Junxiao Shi21e01932018-04-21 10:39:05 +0000925 // MTU is 1500. LpPacket TL occupies 4 octets. Each Ack header is 12 octets. There are room for
926 // 124 Acks per LpPacket, and it takes 5 LpPackets to carry 500 Acks.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000927 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Junxiao Shi21e01932018-04-21 10:39:05 +0000928 for (size_t i = 0; i < 5; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000929 lp::Packet sentPkt(transport->sentPackets[i].packet);
930 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000931 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), i == 4 ? 4 : 124);
932 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
933 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
934 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000935 }
936
Junxiao Shi21e01932018-04-21 10:39:05 +0000937 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000938}
939
Eric Newberry32f7eac2020-02-07 14:40:17 -0800940BOOST_AUTO_TEST_CASE(TrackRecentReceivedLpPackets)
941{
942 lp::Packet pkt1 = makeFrag(1, 100);
943 pkt1.add<lp::SequenceField>(7);
944 pkt1.add<lp::TxSequenceField>(12);
945 BOOST_CHECK(reliability->processIncomingPacket({pkt1}));
946 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.size(), 1);
947 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.front(), 7);
948 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 1);
949 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(7), 1);
950
951 // T+500ms
952 // Estimated RTO starts at 1000ms and we are not adding any measurements, so it should remain
953 // this value throughout the test case
954 advanceClocks(500_ms, 1);
955 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 1);
956 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(7), 1);
957 lp::Packet pkt2 = makeFrag(1, 100);
958 pkt2.add<lp::SequenceField>(23);
959 pkt2.add<lp::TxSequenceField>(13);
960 BOOST_CHECK(reliability->processIncomingPacket({pkt2}));
961 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.size(), 2);
962 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.front(), 7);
963 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 2);
964 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(7), 1);
965 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(23), 1);
966
967 // T+1250ms
968 // First received sequence should be removed after next received packet, but second should remain
969 advanceClocks(750_ms, 1);
970 lp::Packet pkt3 = makeFrag(1, 100);
971 pkt3.add<lp::SequenceField>(24);
972 pkt3.add<lp::TxSequenceField>(14);
973 BOOST_CHECK(reliability->processIncomingPacket({pkt3}));
974 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.size(), 2);
975 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.front(), 23);
976 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 2);
977 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(23), 1);
978 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(24), 1);
979
980 // T+1750ms
981 // Second received sequence should be removed
982 advanceClocks(500_ms, 1);
983 lp::Packet pkt4 = makeFrag(1, 100);
984 pkt4.add<lp::SequenceField>(25);
985 pkt4.add<lp::TxSequenceField>(15);
986 BOOST_CHECK(reliability->processIncomingPacket({pkt4}));
987 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.size(), 2);
988 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqsQueue.front(), 24);
989 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 2);
990 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(24), 1);
991 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(25), 1);
992}
993
994BOOST_AUTO_TEST_CASE(DropDuplicateReceivedSequence)
995{
996 Interest interest("/test/prefix");
997 interest.setCanBePrefix(false);
998 lp::Packet pkt1;
999 pkt1.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
1000 pkt1.add<lp::SequenceField>(7);
1001 pkt1.add<lp::TxSequenceField>(12);
1002 BOOST_CHECK(reliability->processIncomingPacket({pkt1}));
1003 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 1);
1004 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(7), 1);
1005
1006 lp::Packet pkt2;
1007 pkt2.add<lp::FragmentField>({interest.wireEncode().begin(), interest.wireEncode().end()});
1008 pkt2.add<lp::SequenceField>(7);
1009 pkt2.add<lp::TxSequenceField>(13);
1010 BOOST_CHECK(!reliability->processIncomingPacket({pkt2}));
1011 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.size(), 1);
1012 BOOST_CHECK_EQUAL(reliability->m_recentRecvSeqs.count(7), 1);
1013}
1014
1015BOOST_AUTO_TEST_CASE(DropDuplicateAckForRetx)
1016{
1017 lp::Packet pkt1 = makeFrag(1024, 50);
1018 linkService->sendLpPackets({pkt1});
1019
1020 // Will send out a single fragment
1021 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
1022 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
1023 lp::Sequence firstTxSeq = reliability->m_firstUnackedFrag->first;
1024
1025 // RTO is initially 1 second, so will time out and retx
1026 advanceClocks(1250_ms, 1);
1027 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
1028 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
1029
1030 // Acknowledge first transmission (RTO underestimation)
1031 // Ack will be dropped because unknown
1032 lp::Packet ackPkt1;
1033 ackPkt1.add<lp::AckField>(firstTxSeq);
1034 reliability->processIncomingPacket(ackPkt1);
1035 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 1); // Required because collection used below
1036
1037 // Acknowledge second transmission
1038 // Ack will acknowledge retx and remove unacked frag
1039 lp::Packet ackPkt2;
1040 ackPkt2.add<lp::AckField>(reliability->m_firstUnackedFrag->first);
1041 reliability->processIncomingPacket(ackPkt2);
1042 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
1043}
1044
Eric Newberry7b0071e2017-07-03 17:33:31 +00001045BOOST_AUTO_TEST_SUITE_END() // TestLpReliability
Eric Newberry185ab292017-03-28 06:45:39 +00001046BOOST_AUTO_TEST_SUITE_END() // Face
1047
1048} // namespace tests
1049} // namespace face
1050} // namespace nfd