blob: 5e73c03ef4dd8c9aa6c4a8630c7e83e5eacf7ee5 [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");
Junxiao Shi9d727852019-05-14 13:44:22 -060059 interest.setCanBePrefix(false);
Eric Newberry41aba102017-11-01 16:42:13 -070060 lp::Packet pkt;
61 pkt.add<lp::FragmentField>(make_pair(interest.wireEncode().begin(), interest.wireEncode().end()));
62 m_reliability.handleOutgoing(frags, std::move(pkt), true);
Eric Newberry185ab292017-03-28 06:45:39 +000063 }
64
Eric Newberry7b0071e2017-07-03 17:33:31 +000065 for (lp::Packet frag : frags) {
ashiqopu075bb7d2019-03-10 01:38:21 +000066 this->sendLpPacket(std::move(frag), 0);
Eric Newberry185ab292017-03-28 06:45:39 +000067 }
68 }
69
70private:
71 void
ashiqopu075bb7d2019-03-10 01:38:21 +000072 doSendInterest(const Interest&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000073 {
74 BOOST_ASSERT(false);
75 }
76
77 void
ashiqopu075bb7d2019-03-10 01:38:21 +000078 doSendData(const Data&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000079 {
80 BOOST_ASSERT(false);
81 }
82
83 void
ashiqopu075bb7d2019-03-10 01:38:21 +000084 doSendNack(const lp::Nack&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000085 {
86 BOOST_ASSERT(false);
87 }
88
89 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040090 doReceivePacket(const Block&, const EndpointId&) final
Eric Newberry185ab292017-03-28 06:45:39 +000091 {
92 BOOST_ASSERT(false);
93 }
94};
95
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040096class LpReliabilityFixture : public GlobalIoTimeFixture
Eric Newberry185ab292017-03-28 06:45:39 +000097{
98public:
99 LpReliabilityFixture()
100 : linkService(make_unique<DummyLpReliabilityLinkService>())
101 , transport(make_unique<DummyTransport>())
102 , face(make_unique<DummyFace>())
103 {
104 linkService->setFaceAndTransport(*face, *transport);
105 transport->setFaceAndLinkService(*face, *linkService);
106
107 GenericLinkService::Options options;
108 options.reliabilityOptions.isEnabled = true;
109 linkService->setOptions(options);
110
111 reliability = linkService->getLpReliability();
Eric Newberry7b0071e2017-07-03 17:33:31 +0000112 reliability->m_lastTxSeqNo = 1;
113 }
114
115 static bool
116 netPktHasUnackedFrag(const shared_ptr<LpReliability::NetPkt>& netPkt, lp::Sequence txSeq)
117 {
118 return std::any_of(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(),
119 [txSeq] (const LpReliability::UnackedFrags::iterator& frag) {
120 return frag->first == txSeq;
121 });
122 }
123
Eric Newberry7b0071e2017-07-03 17:33:31 +0000124 /** \brief make an LpPacket with fragment of specified size
125 * \param pktNo packet identifier, which can be extracted with \p getPktNo
126 * \param payloadSize total payload size; if this is less than 4, 4 will be used
127 */
128 static lp::Packet
129 makeFrag(uint32_t pktNo, size_t payloadSize = 4)
130 {
131 payloadSize = std::max(payloadSize, static_cast<size_t>(4));
132 BOOST_ASSERT(payloadSize <= 255);
133
134 lp::Packet pkt;
135 ndn::Buffer buf(payloadSize);
Davide Pesavento6d1c1c32017-10-08 21:44:05 -0400136 std::memcpy(buf.data(), &pktNo, sizeof(pktNo));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000137 pkt.set<lp::FragmentField>(make_pair(buf.cbegin(), buf.cend()));
138 return pkt;
139 }
140
141 /** \brief extract packet identifier from LpPacket made with \p makeFrag
142 * \retval 0 packet identifier cannot be extracted
143 */
144 static uint32_t
145 getPktNo(const lp::Packet& pkt)
146 {
147 BOOST_ASSERT(pkt.has<lp::FragmentField>());
148
149 ndn::Buffer::const_iterator begin, end;
150 std::tie(begin, end) = pkt.get<lp::FragmentField>();
151 if (std::distance(begin, end) < 4) {
152 return 0;
153 }
154
155 uint32_t value = 0;
156 std::memcpy(&value, &*begin, sizeof(value));
157 return value;
Eric Newberry185ab292017-03-28 06:45:39 +0000158 }
159
Eric Newberry971d9622018-03-30 23:29:26 -0700160protected:
Eric Newberry185ab292017-03-28 06:45:39 +0000161 unique_ptr<DummyLpReliabilityLinkService> linkService;
162 unique_ptr<DummyTransport> transport;
163 unique_ptr<DummyFace> face;
164 LpReliability* reliability;
165};
166
167BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture)
168
169BOOST_AUTO_TEST_CASE(SendNoFragmentField)
170{
171 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000172
173 linkService->sendLpPackets({pkt});
174 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000175 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700176 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
177 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
178 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700179 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000180}
181
Eric Newberry7b0071e2017-07-03 17:33:31 +0000182BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000183{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000184 lp::Packet pkt1 = makeFrag(1024, 50);
185 lp::Packet pkt2 = makeFrag(3000, 30);
Eric Newberry185ab292017-03-28 06:45:39 +0000186
187 linkService->sendLpPackets({pkt1});
Eric Newberry971d9622018-03-30 23:29:26 -0700188 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000189 lp::Packet cached1(transport->sentPackets.front().packet);
190 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000191 BOOST_CHECK(!cached1.has<lp::SequenceField>());
192 lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>();
Eric Newberry971d9622018-03-30 23:29:26 -0700193 BOOST_CHECK_EQUAL(firstTxSeq, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000194 BOOST_CHECK_EQUAL(getPktNo(cached1), 1024);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700195 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
196 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
197 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700198 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000199
Eric Newberry185ab292017-03-28 06:45:39 +0000200 // T+500ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000201 // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400202 advanceClocks(1_ms, 500);
Eric Newberry185ab292017-03-28 06:45:39 +0000203 linkService->sendLpPackets({pkt2});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000204 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000205
Eric Newberry00d39fd2017-12-10 14:26:45 -0700206 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
207 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1);
208 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000209 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt);
210 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
211 BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt,
Eric Newberry971d9622018-03-30 23:29:26 -0700212 reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000213 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0);
214 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
215 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq);
216 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700217 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
218 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
219 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700220 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000221
222 // T+1250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000223 // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1
224 // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400225 advanceClocks(1_ms, 750);
Eric Newberry185ab292017-03-28 06:45:39 +0000226
Eric Newberry00d39fd2017-12-10 14:26:45 -0700227 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000228 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700229 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000230 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700231 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000232 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
233 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1);
234 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700235 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
236 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
237 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700238 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000239
240 // T+2250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000241 // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2
242 // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1
Davide Pesavento14e71f02019-03-28 17:35:25 -0400243 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000244
Eric Newberry00d39fd2017-12-10 14:26:45 -0700245 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000246 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0);
247 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700248 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000249 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700250 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000251 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1);
252 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3);
253 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700254 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
255 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
256 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700257 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000258
259 // T+3250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000260 // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3
261 // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2
Davide Pesavento14e71f02019-03-28 17:35:25 -0400262 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000263
Eric Newberry00d39fd2017-12-10 14:26:45 -0700264 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000265 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0);
266 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700267 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000268 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700269 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000270 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2);
271 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5);
272 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700273 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
274 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
275 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700276 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000277
278 // T+4250ms
279 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000280 // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3
Davide Pesavento14e71f02019-03-28 17:35:25 -0400281 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000282
Eric Newberry00d39fd2017-12-10 14:26:45 -0700283 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000284 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0);
285 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700286 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000287 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3);
288 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7);
289 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry185ab292017-03-28 06:45:39 +0000290
Eric Newberry00d39fd2017-12-10 14:26:45 -0700291 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
292 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
293 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700294 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
295
Eric Newberry185ab292017-03-28 06:45:39 +0000296 // T+4750ms
297 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000298 // 3000 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400299 advanceClocks(1_ms, 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000300
301 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000302 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
303 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700304 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
305 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
306 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 2);
Eric Newberry41aba102017-11-01 16:42:13 -0700307 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000308}
309
Eric Newberry7b0071e2017-07-03 17:33:31 +0000310BOOST_AUTO_TEST_CASE(SendFragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000311{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000312 lp::Packet pkt1 = makeFrag(2048, 30);
313 lp::Packet pkt2 = makeFrag(2049, 30);
314 lp::Packet pkt3 = makeFrag(2050, 10);
Eric Newberry185ab292017-03-28 06:45:39 +0000315
Eric Newberry7b0071e2017-07-03 17:33:31 +0000316 linkService->sendLpPackets({pkt1, pkt2, pkt3});
317 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000318
Eric Newberry7b0071e2017-07-03 17:33:31 +0000319 lp::Packet cached1(transport->sentPackets.at(0).packet);
320 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
321 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
322 BOOST_CHECK_EQUAL(getPktNo(cached1), 2048);
323 lp::Packet cached2(transport->sentPackets.at(1).packet);
324 BOOST_REQUIRE(cached2.has<lp::TxSequenceField>());
325 BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3);
326 BOOST_CHECK_EQUAL(getPktNo(cached2), 2049);
327 lp::Packet cached3(transport->sentPackets.at(2).packet);
328 BOOST_REQUIRE(cached3.has<lp::TxSequenceField>());
329 BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4);
330 BOOST_CHECK_EQUAL(getPktNo(cached3), 2050);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700331 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
332 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
333 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700334 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000335
Eric Newberry7b0071e2017-07-03 17:33:31 +0000336 // T+0ms
337 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
338 // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0
339 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000340
Eric Newberry00d39fd2017-12-10 14:26:45 -0700341 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
342 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1);
343 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000344 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
345 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049);
346 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
347 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
348 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
349 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
350 BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt);
351 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
352 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
353 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt);
354 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
355 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
356 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
357 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
358 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
359 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
360 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
361 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700362 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
363 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
364 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700365 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000366
Eric Newberry7b0071e2017-07-03 17:33:31 +0000367 // T+250ms
368 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
369 // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1
370 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400371 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700372 reliability->onLpPacketLost(3);
Eric Newberry185ab292017-03-28 06:45:39 +0000373
Eric Newberry00d39fd2017-12-10 14:26:45 -0700374 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000375 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700376 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 1);
377 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000378 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
379 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049);
380 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
381 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
382 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
383 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1);
384 BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt);
385 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
386 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
387 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt);
388 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
389 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
390 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
391 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
392 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
393 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
394 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
395 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700396 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
397 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
398 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700399 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000400
401 // T+500ms
402 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
403 // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2
404 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400405 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700406 reliability->onLpPacketLost(5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000407
Eric Newberry00d39fd2017-12-10 14:26:45 -0700408 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000409 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700410 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 1);
411 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000412 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
413 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049);
414 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
415 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
416 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
417 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2);
418 BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt);
419 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
420 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
421 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt);
422 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
423 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
424 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
425 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
426 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
427 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
428 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
429 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700430 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
431 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
432 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700433 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000434
435 // T+750ms
436 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
437 // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3
438 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Davide Pesavento14e71f02019-03-28 17:35:25 -0400439 advanceClocks(1_ms, 250);
Eric Newberry971d9622018-03-30 23:29:26 -0700440 reliability->onLpPacketLost(6);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000441
442 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
443 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700444 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(7), 1);
445 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000446 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
447 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049);
448 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
449 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
450 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
451 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3);
452 BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt);
453 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
454 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
455 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt);
456 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
457 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
458 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
459 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
460 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7));
461 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
462 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
463 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700464 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
465 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
466 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700467 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000468
469 // T+850ms
470 // 2048 rto: expired, removed
471 // 2049 rto: expired, removed
472 // 2050 rto: expired, removed
Davide Pesavento14e71f02019-03-28 17:35:25 -0400473 advanceClocks(1_ms, 100);
Eric Newberry971d9622018-03-30 23:29:26 -0700474 reliability->onLpPacketLost(7);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000475
476 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
477 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700478 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
479 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
480 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700481 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000482}
483
Eric Newberry00d39fd2017-12-10 14:26:45 -0700484BOOST_AUTO_TEST_CASE(AckUnknownTxSeq)
485{
486 linkService->sendLpPackets({makeFrag(1, 50)});
487
488 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
489 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
490 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
491 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
492 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
493 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
494 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
495 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
496 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
497
498 lp::Packet ackPkt;
499 ackPkt.add<lp::AckField>(10101010);
500 reliability->processIncomingPacket(ackPkt);
501
502 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
503 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
504 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
505 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
506 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
507 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
508 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
509 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
510 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
511}
512
Eric Newberry971d9622018-03-30 23:29:26 -0700513BOOST_AUTO_TEST_CASE(LossByGreaterAcks)
Eric Newberry7b0071e2017-07-03 17:33:31 +0000514{
Eric Newberry971d9622018-03-30 23:29:26 -0700515 // Detect loss by 3x greater Acks, also tests wraparound
516
Eric Newberry7b0071e2017-07-03 17:33:31 +0000517 reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE;
518
Eric Newberry971d9622018-03-30 23:29:26 -0700519 // Passed to sendLpPackets individually since they are
520 // from separate, non-fragmented network packets
Eric Newberry7b0071e2017-07-03 17:33:31 +0000521 linkService->sendLpPackets({makeFrag(1, 50)});
522 linkService->sendLpPackets({makeFrag(2, 50)});
523 linkService->sendLpPackets({makeFrag(3, 50)});
524 linkService->sendLpPackets({makeFrag(4, 50)});
525 linkService->sendLpPackets({makeFrag(5, 50)});
Eric Newberry185ab292017-03-28 06:45:39 +0000526
527 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000528 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
529 BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt);
530 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2
531 BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt);
532 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
533 BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt);
534 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
535 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
536 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
537 BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt);
Eric Newberry185ab292017-03-28 06:45:39 +0000538 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700539 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
540 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
541 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700542 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000543
544 lp::Packet ackPkt1;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000545 ackPkt1.add<lp::AckField>(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000546
547 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
548
549 reliability->processIncomingPacket(ackPkt1);
550
551 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700552 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000553 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
554 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000555 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700556 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000557 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
558 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700559 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
Eric Newberry7b0071e2017-07-03 17:33:31 +0000560 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
561 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700562 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000563 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
564 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000565 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000566 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700567 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
568 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
569 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700570 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000571
572 lp::Packet ackPkt2;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000573 ackPkt2.add<lp::AckField>(2);
574 ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored
Eric Newberry185ab292017-03-28 06:45:39 +0000575
576 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
577
578 reliability->processIncomingPacket(ackPkt2);
579
580 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000581 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000582 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
583 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000584 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700585 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000586 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
587 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700588 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
589 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000590 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
591 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
592 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000593 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000594 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700595 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 2);
596 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
597 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700598 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000599
600 lp::Packet ackPkt3;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000601 ackPkt3.add<lp::AckField>(1);
Eric Newberry185ab292017-03-28 06:45:39 +0000602
603 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
604
605 reliability->processIncomingPacket(ackPkt3);
606
607 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000608 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
609 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
610 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
611 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700612 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000613 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
614 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700615 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq
Eric Newberry7b0071e2017-07-03 17:33:31 +0000616 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1);
617 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0);
618 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000619 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry185ab292017-03-28 06:45:39 +0000620 lp::Packet sentRetxPkt(transport->sentPackets.back().packet);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000621 BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>());
622 BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4);
623 BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>());
624 BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700625 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
626 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
627 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700628 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000629
630 lp::Packet ackPkt4;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000631 ackPkt4.add<lp::AckField>(4);
Eric Newberry185ab292017-03-28 06:45:39 +0000632
633 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
634
635 reliability->processIncomingPacket(ackPkt4);
636
637 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000638 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
639 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
640 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
641 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700642 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000643 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
644 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1);
645 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq
646 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000647 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700648 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
649 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 1);
650 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
651 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
652}
653
Eric Newberry971d9622018-03-30 23:29:26 -0700654BOOST_AUTO_TEST_CASE(SkipFragmentsRemovedInRtt)
655{
656 auto opts = linkService->getOptions();
657 opts.reliabilityOptions.maxRetx = 0; // just to make the test case shorter
658 opts.reliabilityOptions.seqNumLossThreshold = 3;
659 linkService->setOptions(opts);
660
661 lp::Packet frag1 = makeFrag(5001);
662 lp::Packet frag2 = makeFrag(5002);
663 linkService->sendLpPackets({frag1, frag2}); // First packet has 2 fragments
664 linkService->sendLpPackets({makeFrag(5003)});
665 linkService->sendLpPackets({makeFrag(5004)});
666 linkService->sendLpPackets({makeFrag(5005)});
667
668 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
669 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
670
671 lp::Sequence firstTxSeq = reliability->m_firstUnackedFrag->first;
672
673 // Ack the last 2 packets
674 lp::Packet ackPkt1;
675 ackPkt1.add<lp::AckField>(firstTxSeq + 4);
676 ackPkt1.add<lp::AckField>(firstTxSeq + 3);
677 reliability->processIncomingPacket(ackPkt1);
678
679 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
680 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).nGreaterSeqAcks, 2);
681 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).nGreaterSeqAcks, 2);
682
683 // Ack the third packet (5003)
684 // This triggers a "loss by greater Acks" for packets 5001 and 5002
685 lp::Packet ackPkt2;
686 ackPkt2.add<lp::AckField>(firstTxSeq + 2);
687 reliability->processIncomingPacket(ackPkt2); // tests crash/assert reported in bug #4479
688
689 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
690}
691
Eric Newberry00d39fd2017-12-10 14:26:45 -0700692BOOST_AUTO_TEST_CASE(CancelLossNotificationOnAck)
693{
694 reliability->onDroppedInterest.connect([] (const Interest&) {
695 BOOST_FAIL("Packet loss timeout should be cancelled when packet acknowledged");
696 });
697
698 reliability->m_lastTxSeqNo = 0;
699
700 linkService->sendLpPackets({makeFrag(1, 50)});
701
Davide Pesavento14e71f02019-03-28 17:35:25 -0400702 advanceClocks(1_ms, 500);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700703
704 lp::Packet ackPkt;
705 ackPkt.add<lp::AckField>(1);
706 reliability->processIncomingPacket(ackPkt);
707
Davide Pesavento14e71f02019-03-28 17:35:25 -0400708 advanceClocks(1_ms, 1000);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700709
710 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
711 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
712 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700713 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000714}
715
Eric Newberry7b0071e2017-07-03 17:33:31 +0000716BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
717{
718 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
719 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
720
721 lp::Packet pkt1 = makeFrag(100, 40);
722 pkt1.add<lp::TxSequenceField>(765432);
723
724 reliability->processIncomingPacket(pkt1);
725
726 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
727 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1);
728 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
729
730 lp::Packet pkt2 = makeFrag(276, 40);
731 pkt2.add<lp::TxSequenceField>(234567);
732
733 reliability->processIncomingPacket(pkt2);
734
735 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
736 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2);
737 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
738 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567);
739
740 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400741 advanceClocks(1_ms, 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000742 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000743}
744
745BOOST_AUTO_TEST_CASE(PiggybackAcks)
746{
747 reliability->m_ackQueue.push(256);
748 reliability->m_ackQueue.push(257);
749 reliability->m_ackQueue.push(10);
750
751 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000752 linkService->sendLpPackets({pkt});
753
754 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
755 lp::Packet sentPkt(transport->sentPackets.front().packet);
756
757 BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3);
758 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256);
759 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257);
760 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000761 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000762
763 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
764}
765
766BOOST_AUTO_TEST_CASE(PiggybackAcksMtu)
767{
Junxiao Shi21e01932018-04-21 10:39:05 +0000768 // MTU is 1500, payload has 60 octets plus 6 octets for LpPacket and Fragment TL and 10 octets for
769 // TxSequence, leaving 1426 octets for piggybacking. Each Ack header is 12 octets, so each
770 // LpPacket can carry 118 Acks, and it takes 9 LpPackets for 1000 Acks.
Eric Newberry185ab292017-03-28 06:45:39 +0000771
Eric Newberry7b0071e2017-07-03 17:33:31 +0000772 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000773
Junxiao Shi21e01932018-04-21 10:39:05 +0000774 std::unordered_set<lp::Sequence> expectedAcks;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000775 for (lp::Sequence i = 1000; i < 2000; i++) {
776 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000777 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000778 }
Eric Newberry185ab292017-03-28 06:45:39 +0000779
Junxiao Shi21e01932018-04-21 10:39:05 +0000780 for (uint32_t i = 1; i <= 9; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000781 lp::Packet pkt = makeFrag(i, 60);
782 linkService->sendLpPackets({pkt});
Eric Newberry185ab292017-03-28 06:45:39 +0000783
Junxiao Shi21e01932018-04-21 10:39:05 +0000784 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000785 lp::Packet sentPkt(transport->sentPackets.back().packet);
786 BOOST_CHECK_EQUAL(getPktNo(sentPkt), i);
787 BOOST_CHECK(sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000788
789 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
790 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
791 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000792 }
Eric Newberry185ab292017-03-28 06:45:39 +0000793
Eric Newberry7b0071e2017-07-03 17:33:31 +0000794 BOOST_CHECK(reliability->m_ackQueue.empty());
Junxiao Shi21e01932018-04-21 10:39:05 +0000795 BOOST_CHECK(expectedAcks.empty());
Eric Newberry7b0071e2017-07-03 17:33:31 +0000796}
Eric Newberry185ab292017-03-28 06:45:39 +0000797
Eric Newberry7b0071e2017-07-03 17:33:31 +0000798BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace)
799{
Eric Newberry812d6152018-06-06 15:06:01 -0700800 // 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 +0000801 // TxSequence, leaving 6 octets for piggybacking. Each Ack header is 12 octets, so there's no room
802 // to piggyback any Ack in LpPacket.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000803
Eric Newberry812d6152018-06-06 15:06:01 -0700804 transport->setMtu(Transport::MIN_MTU);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000805
806 for (lp::Sequence i = 1000; i < 1100; i++) {
807 reliability->m_ackQueue.push(i);
808 }
809
Eric Newberry812d6152018-06-06 15:06:01 -0700810 lp::Packet pkt = makeFrag(1, 44);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000811 linkService->sendLpPackets({pkt});
812
Eric Newberry185ab292017-03-28 06:45:39 +0000813 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000814 lp::Packet sentPkt(transport->sentPackets.back().packet);
815 BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1);
816 BOOST_CHECK(!sentPkt.has<lp::AckField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000817
818 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000819}
Eric Newberry185ab292017-03-28 06:45:39 +0000820
Eric Newberry7b0071e2017-07-03 17:33:31 +0000821BOOST_AUTO_TEST_CASE(StartIdleAckTimer)
822{
823 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000824
Eric Newberry7b0071e2017-07-03 17:33:31 +0000825 lp::Packet pkt1 = makeFrag(1, 100);
826 pkt1.add<lp::TxSequenceField>(12);
827 reliability->processIncomingPacket({pkt1});
828 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000829
Eric Newberry7b0071e2017-07-03 17:33:31 +0000830 // T+1ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400831 advanceClocks(1_ms, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000832 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000833
Eric Newberry7b0071e2017-07-03 17:33:31 +0000834 lp::Packet pkt2 = makeFrag(2, 100);
835 pkt2.add<lp::TxSequenceField>(13);
836 reliability->processIncomingPacket({pkt2});
837 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000838
Eric Newberry7b0071e2017-07-03 17:33:31 +0000839 // T+5ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400840 advanceClocks(1_ms, 4);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000841 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000842
Eric Newberry7b0071e2017-07-03 17:33:31 +0000843 lp::Packet pkt3 = makeFrag(3, 100);
844 pkt3.add<lp::TxSequenceField>(15);
845 reliability->processIncomingPacket({pkt3});
846 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000847
Eric Newberry7b0071e2017-07-03 17:33:31 +0000848 // T+9ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400849 advanceClocks(1_ms, 4);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000850 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000851
Eric Newberry7b0071e2017-07-03 17:33:31 +0000852 // T+10ms
Davide Pesavento14e71f02019-03-28 17:35:25 -0400853 advanceClocks(1_ms, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000854 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000855}
856
857BOOST_AUTO_TEST_CASE(IdleAckTimer)
858{
Junxiao Shi21e01932018-04-21 10:39:05 +0000859 // T+0ms: populate ack queue and start idle ack timer
860 std::unordered_set<lp::Sequence> expectedAcks;
861 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000862 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000863 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000864 }
Eric Newberry185ab292017-03-28 06:45:39 +0000865 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
866 reliability->startIdleAckTimer();
867 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
868
Junxiao Shi21e01932018-04-21 10:39:05 +0000869 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400870 advanceClocks(1_ms, 4);
Eric Newberry185ab292017-03-28 06:45:39 +0000871 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000872 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000873 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
Junxiao Shi21e01932018-04-21 10:39:05 +0000874 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000875 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
876
Junxiao Shi21e01932018-04-21 10:39:05 +0000877 // T+5ms: idle ack timer expires, IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400878 advanceClocks(1_ms, 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000879 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000880 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000881 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000882
Junxiao Shi21e01932018-04-21 10:39:05 +0000883 lp::Packet sentPkt(transport->sentPackets.back().packet);
884 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
885 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
886 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000887 }
Junxiao Shi21e01932018-04-21 10:39:05 +0000888 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000889}
890
891BOOST_AUTO_TEST_CASE(IdleAckTimerMtu)
892{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000893 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000894
Junxiao Shi21e01932018-04-21 10:39:05 +0000895 // T+0ms: populate ack queue and start idle ack timer
896 std::unordered_set<lp::Sequence> expectedAcks;
897 for (lp::Sequence i = 1000; i < 1500; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000898 reliability->m_ackQueue.push(i);
Junxiao Shi21e01932018-04-21 10:39:05 +0000899 expectedAcks.insert(i);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000900 }
Eric Newberry185ab292017-03-28 06:45:39 +0000901 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
902 reliability->startIdleAckTimer();
903 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
904
Junxiao Shi21e01932018-04-21 10:39:05 +0000905 // T+4ms: idle ack timer has not yet expired, no IDLE packet generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400906 advanceClocks(1_ms, 4);
Eric Newberry185ab292017-03-28 06:45:39 +0000907 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000908 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 500);
909 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
910 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1499);
Eric Newberry185ab292017-03-28 06:45:39 +0000911 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
912
Junxiao Shi21e01932018-04-21 10:39:05 +0000913 // T+5ms: idle ack timer expires, IDLE packets generated
Davide Pesavento14e71f02019-03-28 17:35:25 -0400914 advanceClocks(1_ms, 1);
Eric Newberry185ab292017-03-28 06:45:39 +0000915 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Junxiao Shi21e01932018-04-21 10:39:05 +0000916 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000917
Junxiao Shi21e01932018-04-21 10:39:05 +0000918 // MTU is 1500. LpPacket TL occupies 4 octets. Each Ack header is 12 octets. There are room for
919 // 124 Acks per LpPacket, and it takes 5 LpPackets to carry 500 Acks.
Eric Newberry7b0071e2017-07-03 17:33:31 +0000920 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Junxiao Shi21e01932018-04-21 10:39:05 +0000921 for (size_t i = 0; i < 5; i++) {
Eric Newberry7b0071e2017-07-03 17:33:31 +0000922 lp::Packet sentPkt(transport->sentPackets[i].packet);
923 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Junxiao Shi21e01932018-04-21 10:39:05 +0000924 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), i == 4 ? 4 : 124);
925 for (lp::Sequence ack : sentPkt.list<lp::AckField>()) {
926 BOOST_CHECK_EQUAL(expectedAcks.erase(ack), 1);
927 }
Eric Newberry7b0071e2017-07-03 17:33:31 +0000928 }
929
Junxiao Shi21e01932018-04-21 10:39:05 +0000930 BOOST_CHECK(expectedAcks.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000931}
932
Eric Newberry7b0071e2017-07-03 17:33:31 +0000933BOOST_AUTO_TEST_SUITE_END() // TestLpReliability
Eric Newberry185ab292017-03-28 06:45:39 +0000934BOOST_AUTO_TEST_SUITE_END() // Face
935
936} // namespace tests
937} // namespace face
938} // namespace nfd