blob: a4ec6d30aa0397be7e1292d59842c940f95e8011 [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/*
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04003 * Copyright (c) 2014-2019, 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
43BOOST_AUTO_TEST_SUITE(Face)
44
45class DummyLpReliabilityLinkService : public GenericLinkService
46{
47public:
48 LpReliability*
49 getLpReliability()
50 {
51 return &m_reliability;
52 }
53
54 void
55 sendLpPackets(std::vector<lp::Packet> frags)
56 {
57 if (frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -070058 Interest interest("/test/prefix");
59 lp::Packet pkt;
60 pkt.add<lp::FragmentField>(make_pair(interest.wireEncode().begin(), interest.wireEncode().end()));
61 m_reliability.handleOutgoing(frags, std::move(pkt), true);
Eric Newberry185ab292017-03-28 06:45:39 +000062 }
63
Eric Newberry7b0071e2017-07-03 17:33:31 +000064 for (lp::Packet 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 {
73 BOOST_ASSERT(false);
74 }
75
76 void
ashiqopu075bb7d2019-03-10 01:38:21 +000077 doSendData(const Data&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000078 {
79 BOOST_ASSERT(false);
80 }
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 {
85 BOOST_ASSERT(false);
86 }
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 {
91 BOOST_ASSERT(false);
92 }
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(),
118 [txSeq] (const LpReliability::UnackedFrags::iterator& frag) {
119 return frag->first == txSeq;
120 });
121 }
122
Eric Newberry7b0071e2017-07-03 17:33:31 +0000123 /** \brief make an LpPacket with fragment of specified size
124 * \param pktNo packet identifier, which can be extracted with \p getPktNo
125 * \param payloadSize total payload size; if this is less than 4, 4 will be used
126 */
127 static lp::Packet
128 makeFrag(uint32_t pktNo, size_t payloadSize = 4)
129 {
130 payloadSize = std::max(payloadSize, static_cast<size_t>(4));
131 BOOST_ASSERT(payloadSize <= 255);
132
133 lp::Packet pkt;
134 ndn::Buffer buf(payloadSize);
Davide Pesavento6d1c1c32017-10-08 21:44:05 -0400135 std::memcpy(buf.data(), &pktNo, sizeof(pktNo));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000136 pkt.set<lp::FragmentField>(make_pair(buf.cbegin(), buf.cend()));
137 return pkt;
138 }
139
140 /** \brief extract packet identifier from LpPacket made with \p makeFrag
141 * \retval 0 packet identifier cannot be extracted
142 */
143 static uint32_t
144 getPktNo(const lp::Packet& pkt)
145 {
146 BOOST_ASSERT(pkt.has<lp::FragmentField>());
147
148 ndn::Buffer::const_iterator begin, end;
149 std::tie(begin, end) = pkt.get<lp::FragmentField>();
150 if (std::distance(begin, end) < 4) {
151 return 0;
152 }
153
154 uint32_t value = 0;
155 std::memcpy(&value, &*begin, sizeof(value));
156 return value;
Eric Newberry185ab292017-03-28 06:45:39 +0000157 }
158
Eric Newberry971d9622018-03-30 23:29:26 -0700159protected:
Eric Newberry185ab292017-03-28 06:45:39 +0000160 unique_ptr<DummyLpReliabilityLinkService> linkService;
161 unique_ptr<DummyTransport> transport;
162 unique_ptr<DummyFace> face;
163 LpReliability* reliability;
164};
165
166BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture)
167
168BOOST_AUTO_TEST_CASE(SendNoFragmentField)
169{
170 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000171
172 linkService->sendLpPackets({pkt});
173 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000174 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700175 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
176 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
177 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700178 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000179}
180
Eric Newberry7b0071e2017-07-03 17:33:31 +0000181BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000182{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000183 lp::Packet pkt1 = makeFrag(1024, 50);
184 lp::Packet pkt2 = makeFrag(3000, 30);
Eric Newberry185ab292017-03-28 06:45:39 +0000185
186 linkService->sendLpPackets({pkt1});
Eric Newberry971d9622018-03-30 23:29:26 -0700187 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000188 lp::Packet cached1(transport->sentPackets.front().packet);
189 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000190 BOOST_CHECK(!cached1.has<lp::SequenceField>());
191 lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>();
Eric Newberry971d9622018-03-30 23:29:26 -0700192 BOOST_CHECK_EQUAL(firstTxSeq, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000193 BOOST_CHECK_EQUAL(getPktNo(cached1), 1024);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700194 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
195 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
196 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700197 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000198
Eric Newberry185ab292017-03-28 06:45:39 +0000199 // T+500ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000200 // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400201 advanceClocks(1_ms, 500);
Eric Newberry185ab292017-03-28 06:45:39 +0000202 linkService->sendLpPackets({pkt2});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000203 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000204
Eric Newberry00d39fd2017-12-10 14:26:45 -0700205 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
206 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1);
207 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000208 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt);
209 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
210 BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt,
Eric Newberry971d9622018-03-30 23:29:26 -0700211 reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000212 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0);
213 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
214 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq);
215 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700216 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
217 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
218 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700219 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000220
221 // T+1250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000222 // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1
223 // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400224 advanceClocks(1_ms, 750);
Eric Newberry185ab292017-03-28 06:45:39 +0000225
Eric Newberry00d39fd2017-12-10 14:26:45 -0700226 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000227 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700228 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000229 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700230 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000231 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
232 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1);
233 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700234 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
235 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
236 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700237 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000238
239 // T+2250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000240 // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2
241 // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1
Davide Pesavento14e71f02019-03-28 17:35:25 -0400242 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000243
Eric Newberry00d39fd2017-12-10 14:26:45 -0700244 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000245 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0);
246 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700247 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000248 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700249 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000250 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1);
251 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3);
252 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700253 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
254 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
255 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700256 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000257
258 // T+3250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000259 // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3
260 // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2
Davide Pesavento14e71f02019-03-28 17:35:25 -0400261 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000262
Eric Newberry00d39fd2017-12-10 14:26:45 -0700263 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000264 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0);
265 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700266 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000267 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700268 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000269 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2);
270 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5);
271 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700272 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
273 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
274 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700275 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000276
277 // T+4250ms
278 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000279 // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3
Davide Pesavento14e71f02019-03-28 17:35:25 -0400280 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000281
Eric Newberry00d39fd2017-12-10 14:26:45 -0700282 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000283 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0);
284 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700285 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000286 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3);
287 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7);
288 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry185ab292017-03-28 06:45:39 +0000289
Eric Newberry00d39fd2017-12-10 14:26:45 -0700290 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
291 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
292 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700293 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
294
Eric Newberry185ab292017-03-28 06:45:39 +0000295 // T+4750ms
296 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000297 // 3000 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400298 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000299
300 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000301 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
302 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700303 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
304 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
305 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 2);
Eric Newberry41aba102017-11-01 16:42:13 -0700306 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000307}
308
Eric Newberry7b0071e2017-07-03 17:33:31 +0000309BOOST_AUTO_TEST_CASE(SendFragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000310{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000311 lp::Packet pkt1 = makeFrag(2048, 30);
312 lp::Packet pkt2 = makeFrag(2049, 30);
313 lp::Packet pkt3 = makeFrag(2050, 10);
Eric Newberry185ab292017-03-28 06:45:39 +0000314
Eric Newberry7b0071e2017-07-03 17:33:31 +0000315 linkService->sendLpPackets({pkt1, pkt2, pkt3});
316 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000317
Eric Newberry7b0071e2017-07-03 17:33:31 +0000318 lp::Packet cached1(transport->sentPackets.at(0).packet);
319 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
320 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
321 BOOST_CHECK_EQUAL(getPktNo(cached1), 2048);
322 lp::Packet cached2(transport->sentPackets.at(1).packet);
323 BOOST_REQUIRE(cached2.has<lp::TxSequenceField>());
324 BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3);
325 BOOST_CHECK_EQUAL(getPktNo(cached2), 2049);
326 lp::Packet cached3(transport->sentPackets.at(2).packet);
327 BOOST_REQUIRE(cached3.has<lp::TxSequenceField>());
328 BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4);
329 BOOST_CHECK_EQUAL(getPktNo(cached3), 2050);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700330 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
331 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
332 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700333 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000334
Eric Newberry7b0071e2017-07-03 17:33:31 +0000335 // T+0ms
336 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
337 // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0
338 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000339
Eric Newberry00d39fd2017-12-10 14:26:45 -0700340 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
341 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1);
342 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000343 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
344 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049);
345 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
346 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
347 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
348 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
349 BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt);
350 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
351 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
352 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt);
353 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
354 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
355 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
356 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
357 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
358 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
359 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
360 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700361 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
362 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
363 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700364 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000365
Eric Newberry7b0071e2017-07-03 17:33:31 +0000366 // T+250ms
367 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
368 // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1
369 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400370 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700371 reliability->onLpPacketLost(3);
Eric Newberry185ab292017-03-28 06:45:39 +0000372
Eric Newberry00d39fd2017-12-10 14:26:45 -0700373 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000374 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700375 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 1);
376 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000377 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
378 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049);
379 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
380 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
381 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
382 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1);
383 BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt);
384 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
385 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
386 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt);
387 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
388 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
389 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
390 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
391 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
392 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
393 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
394 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700395 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
396 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
397 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700398 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000399
400 // T+500ms
401 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
402 // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2
403 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400404 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700405 reliability->onLpPacketLost(5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000406
Eric Newberry00d39fd2017-12-10 14:26:45 -0700407 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000408 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700409 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 1);
410 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000411 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
412 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049);
413 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
414 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
415 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
416 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2);
417 BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt);
418 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
419 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
420 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt);
421 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
422 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
423 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
424 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
425 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
426 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
427 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
428 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700429 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
430 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
431 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700432 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000433
434 // T+750ms
435 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
436 // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3
437 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400438 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700439 reliability->onLpPacketLost(6);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000440
441 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
442 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700443 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(7), 1);
444 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000445 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
446 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049);
447 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
448 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
449 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
450 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3);
451 BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt);
452 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
453 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
454 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt);
455 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
456 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
457 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
458 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
459 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7));
460 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
461 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
462 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700463 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
464 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
465 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700466 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000467
468 // T+850ms
469 // 2048 rto: expired, removed
470 // 2049 rto: expired, removed
471 // 2050 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400472 advanceClocks(1_ms, 100);
Eric Newberry971d9622018-03-30 23:29:26 -0700473 reliability->onLpPacketLost(7);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000474
475 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
476 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700477 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
478 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
479 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700480 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000481}
482
Eric Newberry00d39fd2017-12-10 14:26:45 -0700483BOOST_AUTO_TEST_CASE(AckUnknownTxSeq)
484{
485 linkService->sendLpPackets({makeFrag(1, 50)});
486
487 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
488 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
489 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
490 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
491 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
492 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
493 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
494 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
495 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
496
497 lp::Packet ackPkt;
498 ackPkt.add<lp::AckField>(10101010);
499 reliability->processIncomingPacket(ackPkt);
500
501 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
502 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
503 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
504 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
505 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
506 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
507 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
508 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
509 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
510}
511
Eric Newberry971d9622018-03-30 23:29:26 -0700512BOOST_AUTO_TEST_CASE(LossByGreaterAcks)
Eric Newberry7b0071e2017-07-03 17:33:31 +0000513{
Eric Newberry971d9622018-03-30 23:29:26 -0700514 // Detect loss by 3x greater Acks, also tests wraparound
515
Eric Newberry7b0071e2017-07-03 17:33:31 +0000516 reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE;
517
Eric Newberry971d9622018-03-30 23:29:26 -0700518 // Passed to sendLpPackets individually since they are
519 // from separate, non-fragmented network packets
Eric Newberry7b0071e2017-07-03 17:33:31 +0000520 linkService->sendLpPackets({makeFrag(1, 50)});
521 linkService->sendLpPackets({makeFrag(2, 50)});
522 linkService->sendLpPackets({makeFrag(3, 50)});
523 linkService->sendLpPackets({makeFrag(4, 50)});
524 linkService->sendLpPackets({makeFrag(5, 50)});
Eric Newberry185ab292017-03-28 06:45:39 +0000525
526 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000527 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
528 BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt);
529 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2
530 BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt);
531 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
532 BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt);
533 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
534 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
535 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
536 BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt);
Eric Newberry185ab292017-03-28 06:45:39 +0000537 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700538 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
539 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
540 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700541 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000542
543 lp::Packet ackPkt1;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000544 ackPkt1.add<lp::AckField>(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000545
546 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
547
548 reliability->processIncomingPacket(ackPkt1);
549
550 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700551 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000552 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
553 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000554 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700555 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000556 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
557 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700558 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
Eric Newberry7b0071e2017-07-03 17:33:31 +0000559 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
560 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700561 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000562 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
563 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000564 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000565 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700566 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
567 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
568 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700569 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000570
571 lp::Packet ackPkt2;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000572 ackPkt2.add<lp::AckField>(2);
573 ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored
Eric Newberry185ab292017-03-28 06:45:39 +0000574
575 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
576
577 reliability->processIncomingPacket(ackPkt2);
578
579 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000580 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000581 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
582 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000583 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700584 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000585 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
586 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700587 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
588 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000589 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
590 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
591 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000592 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000593 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700594 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 2);
595 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
596 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700597 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000598
599 lp::Packet ackPkt3;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000600 ackPkt3.add<lp::AckField>(1);
Eric Newberry185ab292017-03-28 06:45:39 +0000601
602 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
603
604 reliability->processIncomingPacket(ackPkt3);
605
606 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000607 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
608 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
609 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
610 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700611 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000612 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
613 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700614 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq
Eric Newberry7b0071e2017-07-03 17:33:31 +0000615 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1);
616 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0);
617 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000618 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry185ab292017-03-28 06:45:39 +0000619 lp::Packet sentRetxPkt(transport->sentPackets.back().packet);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000620 BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>());
621 BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4);
622 BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>());
623 BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700624 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
625 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
626 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700627 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000628
629 lp::Packet ackPkt4;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000630 ackPkt4.add<lp::AckField>(4);
Eric Newberry185ab292017-03-28 06:45:39 +0000631
632 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
633
634 reliability->processIncomingPacket(ackPkt4);
635
636 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000637 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
638 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
639 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
640 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700641 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000642 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
643 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1);
644 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq
645 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000646 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700647 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
648 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 1);
649 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
650 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
651}
652
Eric Newberry971d9622018-03-30 23:29:26 -0700653BOOST_AUTO_TEST_CASE(SkipFragmentsRemovedInRtt)
654{
655 auto opts = linkService->getOptions();
656 opts.reliabilityOptions.maxRetx = 0; // just to make the test case shorter
657 opts.reliabilityOptions.seqNumLossThreshold = 3;
658 linkService->setOptions(opts);
659
660 lp::Packet frag1 = makeFrag(5001);
661 lp::Packet frag2 = makeFrag(5002);
662 linkService->sendLpPackets({frag1, frag2}); // First packet has 2 fragments
663 linkService->sendLpPackets({makeFrag(5003)});
664 linkService->sendLpPackets({makeFrag(5004)});
665 linkService->sendLpPackets({makeFrag(5005)});
666
667 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
668 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
669
670 lp::Sequence firstTxSeq = reliability->m_firstUnackedFrag->first;
671
672 // Ack the last 2 packets
673 lp::Packet ackPkt1;
674 ackPkt1.add<lp::AckField>(firstTxSeq + 4);
675 ackPkt1.add<lp::AckField>(firstTxSeq + 3);
676 reliability->processIncomingPacket(ackPkt1);
677
678 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
679 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).nGreaterSeqAcks, 2);
680 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).nGreaterSeqAcks, 2);
681
682 // Ack the third packet (5003)
683 // This triggers a "loss by greater Acks" for packets 5001 and 5002
684 lp::Packet ackPkt2;
685 ackPkt2.add<lp::AckField>(firstTxSeq + 2);
686 reliability->processIncomingPacket(ackPkt2); // tests crash/assert reported in bug #4479
687
688 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
689}
690
Eric Newberry00d39fd2017-12-10 14:26:45 -0700691BOOST_AUTO_TEST_CASE(CancelLossNotificationOnAck)
692{
693 reliability->onDroppedInterest.connect([] (const Interest&) {
694 BOOST_FAIL("Packet loss timeout should be cancelled when packet acknowledged");
695 });
696
697 reliability->m_lastTxSeqNo = 0;
698
699 linkService->sendLpPackets({makeFrag(1, 50)});
700
Davide Pesavento14e71f02019-03-28 17:35:25 -0400701 advanceClocks(1_ms, 500);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700702
703 lp::Packet ackPkt;
704 ackPkt.add<lp::AckField>(1);
705 reliability->processIncomingPacket(ackPkt);
706
Davide Pesavento14e71f02019-03-28 17:35:25 -0400707 advanceClocks(1_ms, 1000);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700708
709 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
710 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
711 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700712 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000713}
714
Eric Newberry7b0071e2017-07-03 17:33:31 +0000715BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
716{
717 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
718 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
719
720 lp::Packet pkt1 = makeFrag(100, 40);
721 pkt1.add<lp::TxSequenceField>(765432);
722
723 reliability->processIncomingPacket(pkt1);
724
725 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
726 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1);
727 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
728
729 lp::Packet pkt2 = makeFrag(276, 40);
730 pkt2.add<lp::TxSequenceField>(234567);
731
732 reliability->processIncomingPacket(pkt2);
733
734 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
735 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2);
736 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
737 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567);
738
739 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400740 advanceClocks(1_ms, 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000741 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000742}
743
744BOOST_AUTO_TEST_CASE(PiggybackAcks)
745{
746 reliability->m_ackQueue.push(256);
747 reliability->m_ackQueue.push(257);
748 reliability->m_ackQueue.push(10);
749
750 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000751 linkService->sendLpPackets({pkt});
752
753 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
754 lp::Packet sentPkt(transport->sentPackets.front().packet);
755
756 BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3);
757 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256);
758 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257);
759 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000760 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000761
762 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
763}
764
765BOOST_AUTO_TEST_CASE(PiggybackAcksMtu)
766{
Junxiao Shi21e01932018-04-21 10:39:05 +0000767 // MTU is 1500, payload has 60 octets plus 6 octets for LpPacket and Fragment TL and 10 octets for
768 // TxSequence, leaving 1426 octets for piggybacking. Each Ack header is 12 octets, so each
769 // LpPacket can carry 118 Acks, and it takes 9 LpPackets for 1000 Acks.
Eric Newberry185ab292017-03-28 06:45:39 +0000770
Eric Newberry7b0071e2017-07-03 17:33:31 +0000771 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000772
Junxiao Shi21e01932018-04-21 10:39:05 +0000773 std::unordered_set<lp::Sequence> expectedAcks;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000774 for (lp::Sequence i = 1000; i < 2000; i++) {
775 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000776 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000777 }
Eric Newberry185ab292017-03-28 06:45:39 +0000778
Junxiao Shi21e01932018-04-21 10:39:05 +0000779 for (uint32_t i = 1; i <= 9; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000780 lp::Packet pkt = makeFrag(i, 60);
781 linkService->sendLpPackets({pkt});
Eric Newberry185ab292017-03-28 06:45:39 +0000782
Junxiao Shi21e01932018-04-21 10:39:05 +0000783 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000784 lp::Packet sentPkt(transport->sentPackets.back().packet);
785 BOOST_CHECK_EQUAL(getPktNo(sentPkt), i);
786 BOOST_CHECK(sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000787
788 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
789 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
790 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000791 }
Eric Newberry185ab292017-03-28 06:45:39 +0000792
Eric Newberry7b0071e2017-07-03 17:33:31 +0000793 BOOST_CHECK(reliability->m_ackQueue.empty());
Junxiao Shi21e01932018-04-21 10:39:05 +0000794 BOOST_CHECK(expectedAcks.empty());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000795}
Eric Newberry185ab292017-03-28 06:45:39 +0000796
Eric Newberry7b0071e2017-07-03 17:33:31 +0000797BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace)
798{
Eric Newberry812d6152018-06-06 15:06:01 -0700799 // MTU is 64, payload has 44 octets plus 4 octets for LpPacket and Fragment TL and 10 octets for
Junxiao Shi21e01932018-04-21 10:39:05 +0000800 // TxSequence, leaving 6 octets for piggybacking. Each Ack header is 12 octets, so there's no room
801 // to piggyback any Ack in LpPacket.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000802
Eric Newberry812d6152018-06-06 15:06:01 -0700803 transport->setMtu(Transport::MIN_MTU);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000804
805 for (lp::Sequence i = 1000; i < 1100; i++) {
806 reliability->m_ackQueue.push(i);
807 }
808
Eric Newberry812d6152018-06-06 15:06:01 -0700809 lp::Packet pkt = makeFrag(1, 44);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000810 linkService->sendLpPackets({pkt});
811
Eric Newberry185ab292017-03-28 06:45:39 +0000812 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000813 lp::Packet sentPkt(transport->sentPackets.back().packet);
814 BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1);
815 BOOST_CHECK(!sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000816
817 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000818}
Eric Newberry185ab292017-03-28 06:45:39 +0000819
Eric Newberry7b0071e2017-07-03 17:33:31 +0000820BOOST_AUTO_TEST_CASE(StartIdleAckTimer)
821{
822 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000823
Eric Newberry7b0071e2017-07-03 17:33:31 +0000824 lp::Packet pkt1 = makeFrag(1, 100);
825 pkt1.add<lp::TxSequenceField>(12);
826 reliability->processIncomingPacket({pkt1});
827 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000828
Eric Newberry7b0071e2017-07-03 17:33:31 +0000829 // T+1ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400830 advanceClocks(1_ms, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000831 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000832
Eric Newberry7b0071e2017-07-03 17:33:31 +0000833 lp::Packet pkt2 = makeFrag(2, 100);
834 pkt2.add<lp::TxSequenceField>(13);
835 reliability->processIncomingPacket({pkt2});
836 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000837
Eric Newberry7b0071e2017-07-03 17:33:31 +0000838 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400839 advanceClocks(1_ms, 4);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000840 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000841
Eric Newberry7b0071e2017-07-03 17:33:31 +0000842 lp::Packet pkt3 = makeFrag(3, 100);
843 pkt3.add<lp::TxSequenceField>(15);
844 reliability->processIncomingPacket({pkt3});
845 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000846
Eric Newberry7b0071e2017-07-03 17:33:31 +0000847 // T+9ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400848 advanceClocks(1_ms, 4);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000849 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000850
Eric Newberry7b0071e2017-07-03 17:33:31 +0000851 // T+10ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400852 advanceClocks(1_ms, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000853 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000854}
855
856BOOST_AUTO_TEST_CASE(IdleAckTimer)
857{
Junxiao Shi21e01932018-04-21 10:39:05 +0000858 // T+0ms: populate ack queue and start idle ack timer
859 std::unordered_set<lp::Sequence> expectedAcks;
860 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000861 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000862 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000863 }
Eric Newberry185ab292017-03-28 06:45:39 +0000864 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
865 reliability->startIdleAckTimer();
866 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
867
Junxiao Shi21e01932018-04-21 10:39:05 +0000868 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400869 advanceClocks(1_ms, 4);
Eric Newberry185ab292017-03-28 06:45:39 +0000870 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000871 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000872 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
Junxiao Shi21e01932018-04-21 10:39:05 +0000873 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000874 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
875
Junxiao Shi21e01932018-04-21 10:39:05 +0000876 // T+5ms: idle ack timer expires, IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400877 advanceClocks(1_ms, 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000878 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000879 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000880 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000881
Junxiao Shi21e01932018-04-21 10:39:05 +0000882 lp::Packet sentPkt(transport->sentPackets.back().packet);
883 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
884 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
885 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000886 }
Junxiao Shi21e01932018-04-21 10:39:05 +0000887 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000888}
889
890BOOST_AUTO_TEST_CASE(IdleAckTimerMtu)
891{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000892 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000893
Junxiao Shi21e01932018-04-21 10:39:05 +0000894 // T+0ms: populate ack queue and start idle ack timer
895 std::unordered_set<lp::Sequence> expectedAcks;
896 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000897 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000898 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000899 }
Eric Newberry185ab292017-03-28 06:45:39 +0000900 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
901 reliability->startIdleAckTimer();
902 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
903
Junxiao Shi21e01932018-04-21 10:39:05 +0000904 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400905 advanceClocks(1_ms, 4);
Eric Newberry185ab292017-03-28 06:45:39 +0000906 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000907 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
908 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
909 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000910 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
911
Junxiao Shi21e01932018-04-21 10:39:05 +0000912 // T+5ms: idle ack timer expires, IDLE packets generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400913 advanceClocks(1_ms, 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000914 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000915 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000916
Junxiao Shi21e01932018-04-21 10:39:05 +0000917 // MTU is 1500. LpPacket TL occupies 4 octets. Each Ack header is 12 octets. There are room for
918 // 124 Acks per LpPacket, and it takes 5 LpPackets to carry 500 Acks.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000919 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Junxiao Shi21e01932018-04-21 10:39:05 +0000920 for (size_t i = 0; i < 5; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000921 lp::Packet sentPkt(transport->sentPackets[i].packet);
922 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000923 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), i == 4 ? 4 : 124);
924 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
925 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
926 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000927 }
928
Junxiao Shi21e01932018-04-21 10:39:05 +0000929 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000930}
931
Eric Newberry7b0071e2017-07-03 17:33:31 +0000932BOOST_AUTO_TEST_SUITE_END() // TestLpReliability
Eric Newberry185ab292017-03-28 06:45:39 +0000933BOOST_AUTO_TEST_SUITE_END() // Face
934
935} // namespace tests
936} // namespace face
937} // namespace nfd