blob: 4baeb6bc2a76b1e79385ee0fdbaaa65a089b0d2f [file] [log] [blame]
Eric Newberry185ab292017-03-28 06:45:39 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry7b0071e2017-07-03 17:33:31 +00002/*
Eric Newberry185ab292017-03-28 06:45:39 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/lp-reliability.hpp"
27#include "face/face.hpp"
Eric Newberry185ab292017-03-28 06:45:39 +000028#include "face/generic-link-service.hpp"
29
30#include "tests/test-common.hpp"
31#include "dummy-face.hpp"
32#include "dummy-transport.hpp"
33
Eric Newberry7b0071e2017-07-03 17:33:31 +000034#include <cstring>
35
Eric Newberry185ab292017-03-28 06:45:39 +000036namespace nfd {
37namespace face {
38namespace tests {
39
40using namespace nfd::tests;
41
42BOOST_AUTO_TEST_SUITE(Face)
43
44class DummyLpReliabilityLinkService : public GenericLinkService
45{
46public:
47 LpReliability*
48 getLpReliability()
49 {
50 return &m_reliability;
51 }
52
53 void
54 sendLpPackets(std::vector<lp::Packet> frags)
55 {
56 if (frags.front().has<lp::FragmentField>()) {
Eric Newberry41aba102017-11-01 16:42:13 -070057 Interest interest("/test/prefix");
58 lp::Packet pkt;
59 pkt.add<lp::FragmentField>(make_pair(interest.wireEncode().begin(), interest.wireEncode().end()));
60 m_reliability.handleOutgoing(frags, std::move(pkt), true);
Eric Newberry185ab292017-03-28 06:45:39 +000061 }
62
Eric Newberry7b0071e2017-07-03 17:33:31 +000063 for (lp::Packet frag : frags) {
Eric Newberry185ab292017-03-28 06:45:39 +000064 this->sendLpPacket(std::move(frag));
65 }
66 }
67
68private:
69 void
70 doSendInterest(const Interest& interest) override
71 {
72 BOOST_ASSERT(false);
73 }
74
75 void
76 doSendData(const Data& data) override
77 {
78 BOOST_ASSERT(false);
79 }
80
81 void
82 doSendNack(const lp::Nack& nack) override
83 {
84 BOOST_ASSERT(false);
85 }
86
87 void
88 doReceivePacket(Transport::Packet&& packet) override
89 {
90 BOOST_ASSERT(false);
91 }
92};
93
94class LpReliabilityFixture : public UnitTestTimeFixture
95{
96public:
97 LpReliabilityFixture()
98 : linkService(make_unique<DummyLpReliabilityLinkService>())
99 , transport(make_unique<DummyTransport>())
100 , face(make_unique<DummyFace>())
101 {
102 linkService->setFaceAndTransport(*face, *transport);
103 transport->setFaceAndLinkService(*face, *linkService);
104
105 GenericLinkService::Options options;
106 options.reliabilityOptions.isEnabled = true;
107 linkService->setOptions(options);
108
109 reliability = linkService->getLpReliability();
Eric Newberry7b0071e2017-07-03 17:33:31 +0000110 reliability->m_lastTxSeqNo = 1;
111 }
112
113 static bool
114 netPktHasUnackedFrag(const shared_ptr<LpReliability::NetPkt>& netPkt, lp::Sequence txSeq)
115 {
116 return std::any_of(netPkt->unackedFrags.begin(), netPkt->unackedFrags.end(),
117 [txSeq] (const LpReliability::UnackedFrags::iterator& frag) {
118 return frag->first == txSeq;
119 });
120 }
121
122 LpReliability::UnackedFrags::iterator
123 getIteratorFromTxSeq(lp::Sequence txSeq)
124 {
125 return reliability->m_unackedFrags.find(txSeq);
126 }
127
128 /** \brief make an LpPacket with fragment of specified size
129 * \param pktNo packet identifier, which can be extracted with \p getPktNo
130 * \param payloadSize total payload size; if this is less than 4, 4 will be used
131 */
132 static lp::Packet
133 makeFrag(uint32_t pktNo, size_t payloadSize = 4)
134 {
135 payloadSize = std::max(payloadSize, static_cast<size_t>(4));
136 BOOST_ASSERT(payloadSize <= 255);
137
138 lp::Packet pkt;
139 ndn::Buffer buf(payloadSize);
Davide Pesavento6d1c1c32017-10-08 21:44:05 -0400140 std::memcpy(buf.data(), &pktNo, sizeof(pktNo));
Eric Newberry7b0071e2017-07-03 17:33:31 +0000141 pkt.set<lp::FragmentField>(make_pair(buf.cbegin(), buf.cend()));
142 return pkt;
143 }
144
145 /** \brief extract packet identifier from LpPacket made with \p makeFrag
146 * \retval 0 packet identifier cannot be extracted
147 */
148 static uint32_t
149 getPktNo(const lp::Packet& pkt)
150 {
151 BOOST_ASSERT(pkt.has<lp::FragmentField>());
152
153 ndn::Buffer::const_iterator begin, end;
154 std::tie(begin, end) = pkt.get<lp::FragmentField>();
155 if (std::distance(begin, end) < 4) {
156 return 0;
157 }
158
159 uint32_t value = 0;
160 std::memcpy(&value, &*begin, sizeof(value));
161 return value;
Eric Newberry185ab292017-03-28 06:45:39 +0000162 }
163
164public:
165 unique_ptr<DummyLpReliabilityLinkService> linkService;
166 unique_ptr<DummyTransport> transport;
167 unique_ptr<DummyFace> face;
168 LpReliability* reliability;
169};
170
171BOOST_FIXTURE_TEST_SUITE(TestLpReliability, LpReliabilityFixture)
172
Eric Newberry7b0071e2017-07-03 17:33:31 +0000173BOOST_AUTO_TEST_SUITE(Sender)
174
Eric Newberry185ab292017-03-28 06:45:39 +0000175BOOST_AUTO_TEST_CASE(SendNoFragmentField)
176{
177 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000178
179 linkService->sendLpPackets({pkt});
180 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000181 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700182 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
183 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
184 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700185 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000186}
187
Eric Newberry7b0071e2017-07-03 17:33:31 +0000188BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000189{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000190 lp::Packet pkt1 = makeFrag(1024, 50);
191 lp::Packet pkt2 = makeFrag(3000, 30);
Eric Newberry185ab292017-03-28 06:45:39 +0000192
193 linkService->sendLpPackets({pkt1});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000194 lp::Packet cached1(transport->sentPackets.front().packet);
195 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
196 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
197 BOOST_CHECK(!cached1.has<lp::SequenceField>());
198 lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>();
199 BOOST_CHECK_EQUAL(getPktNo(cached1), 1024);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700200 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
201 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
202 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700203 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000204
Eric Newberry185ab292017-03-28 06:45:39 +0000205 // T+500ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000206 // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000207 advanceClocks(time::milliseconds(1), 500);
208 linkService->sendLpPackets({pkt2});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000209 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000210
Eric Newberry00d39fd2017-12-10 14:26:45 -0700211 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
212 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1);
213 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000214 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt);
215 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
216 BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt,
217 reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
218 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0);
219 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
220 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq);
221 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700222 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
223 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
224 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700225 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000226
227 // T+1250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000228 // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1
229 // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000230 advanceClocks(time::milliseconds(1), 750);
231
Eric Newberry00d39fd2017-12-10 14:26:45 -0700232 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000233 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700234 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000235 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700236 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000237 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
238 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1);
239 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700240 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
241 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
242 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700243 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000244
245 // T+2250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000246 // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2
247 // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1
Eric Newberry185ab292017-03-28 06:45:39 +0000248 advanceClocks(time::milliseconds(1), 1000);
249
Eric Newberry00d39fd2017-12-10 14:26:45 -0700250 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000251 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0);
252 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700253 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000254 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700255 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000256 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1);
257 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3);
258 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700259 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
260 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
261 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700262 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000263
264 // T+3250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000265 // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3
266 // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2
Eric Newberry185ab292017-03-28 06:45:39 +0000267 advanceClocks(time::milliseconds(1), 1000);
268
Eric Newberry00d39fd2017-12-10 14:26:45 -0700269 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000270 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0);
271 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700272 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000273 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700274 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000275 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2);
276 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5);
277 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700278 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
279 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
280 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700281 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000282
283 // T+4250ms
284 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000285 // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3
Eric Newberry185ab292017-03-28 06:45:39 +0000286 advanceClocks(time::milliseconds(1), 1000);
287
Eric Newberry00d39fd2017-12-10 14:26:45 -0700288 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000289 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0);
290 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700291 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000292 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3);
293 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7);
294 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry185ab292017-03-28 06:45:39 +0000295
Eric Newberry00d39fd2017-12-10 14:26:45 -0700296 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
297 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
298 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700299 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
300
Eric Newberry185ab292017-03-28 06:45:39 +0000301 // T+4750ms
302 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000303 // 3000 rto: expired, removed
Eric Newberry185ab292017-03-28 06:45:39 +0000304 advanceClocks(time::milliseconds(1), 1000);
305
306 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000307 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
308 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700309 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
310 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
311 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 2);
Eric Newberry41aba102017-11-01 16:42:13 -0700312 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000313}
314
Eric Newberry7b0071e2017-07-03 17:33:31 +0000315BOOST_AUTO_TEST_CASE(SendFragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000316{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000317 lp::Packet pkt1 = makeFrag(2048, 30);
318 lp::Packet pkt2 = makeFrag(2049, 30);
319 lp::Packet pkt3 = makeFrag(2050, 10);
Eric Newberry185ab292017-03-28 06:45:39 +0000320
Eric Newberry7b0071e2017-07-03 17:33:31 +0000321 linkService->sendLpPackets({pkt1, pkt2, pkt3});
322 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000323
Eric Newberry7b0071e2017-07-03 17:33:31 +0000324 lp::Packet cached1(transport->sentPackets.at(0).packet);
325 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
326 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
327 BOOST_CHECK_EQUAL(getPktNo(cached1), 2048);
328 lp::Packet cached2(transport->sentPackets.at(1).packet);
329 BOOST_REQUIRE(cached2.has<lp::TxSequenceField>());
330 BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3);
331 BOOST_CHECK_EQUAL(getPktNo(cached2), 2049);
332 lp::Packet cached3(transport->sentPackets.at(2).packet);
333 BOOST_REQUIRE(cached3.has<lp::TxSequenceField>());
334 BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4);
335 BOOST_CHECK_EQUAL(getPktNo(cached3), 2050);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700336 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
337 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
338 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700339 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000340
Eric Newberry7b0071e2017-07-03 17:33:31 +0000341 // T+0ms
342 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
343 // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0
344 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000345
Eric Newberry00d39fd2017-12-10 14:26:45 -0700346 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
347 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1);
348 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000349 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
350 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049);
351 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
352 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
353 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
354 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
355 BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt);
356 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
357 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
358 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt);
359 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
360 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
361 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
362 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
363 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
364 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
365 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
366 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700367 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
368 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
369 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700370 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000371
Eric Newberry7b0071e2017-07-03 17:33:31 +0000372 // T+250ms
373 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
374 // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1
375 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
376 advanceClocks(time::milliseconds(1), 250);
377 reliability->onLpPacketLost(getIteratorFromTxSeq(3));
Eric Newberry185ab292017-03-28 06:45:39 +0000378
Eric Newberry00d39fd2017-12-10 14:26:45 -0700379 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000380 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700381 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 1);
382 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000383 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
384 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049);
385 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
386 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
387 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
388 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1);
389 BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt);
390 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
391 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
392 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt);
393 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
394 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
395 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
396 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
397 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
398 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
399 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
400 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700401 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
402 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
403 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700404 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000405
406 // T+500ms
407 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
408 // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2
409 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
410 advanceClocks(time::milliseconds(1), 250);
411 reliability->onLpPacketLost(getIteratorFromTxSeq(5));
412
Eric Newberry00d39fd2017-12-10 14:26:45 -0700413 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000414 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700415 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 1);
416 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000417 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
418 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049);
419 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
420 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
421 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
422 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2);
423 BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt);
424 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
425 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
426 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt);
427 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
428 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
429 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
430 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
431 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
432 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
433 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
434 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700435 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
436 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
437 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700438 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000439
440 // T+750ms
441 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
442 // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3
443 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
444 advanceClocks(time::milliseconds(1), 250);
445 reliability->onLpPacketLost(getIteratorFromTxSeq(6));
446
447 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
448 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700449 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(7), 1);
450 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000451 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
452 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049);
453 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
454 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
455 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
456 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3);
457 BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt);
458 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
459 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
460 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt);
461 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
462 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
463 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
464 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
465 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7));
466 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
467 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
468 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700469 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
470 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
471 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700472 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000473
474 // T+850ms
475 // 2048 rto: expired, removed
476 // 2049 rto: expired, removed
477 // 2050 rto: expired, removed
478 advanceClocks(time::milliseconds(1), 100);
479 reliability->onLpPacketLost(getIteratorFromTxSeq(7));
480
481 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
482 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700483 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
484 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
485 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700486 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000487}
488
Eric Newberry00d39fd2017-12-10 14:26:45 -0700489BOOST_AUTO_TEST_CASE(AckUnknownTxSeq)
490{
491 linkService->sendLpPackets({makeFrag(1, 50)});
492
493 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
494 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
495 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
496 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
497 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
498 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
499 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
500 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
501 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
502
503 lp::Packet ackPkt;
504 ackPkt.add<lp::AckField>(10101010);
505 reliability->processIncomingPacket(ackPkt);
506
507 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
508 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1);
509 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
510 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
511 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
512 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
513 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
514 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
515 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
516}
517
Eric Newberry7b0071e2017-07-03 17:33:31 +0000518BOOST_AUTO_TEST_CASE(LossByGreaterAcks) // detect loss by 3x greater Acks, also tests wraparound
519{
520 reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE;
521
522 // Passed to sendLpPackets individually since they are from separate, non-fragmented network packets
523 linkService->sendLpPackets({makeFrag(1, 50)});
524 linkService->sendLpPackets({makeFrag(2, 50)});
525 linkService->sendLpPackets({makeFrag(3, 50)});
526 linkService->sendLpPackets({makeFrag(4, 50)});
527 linkService->sendLpPackets({makeFrag(5, 50)});
Eric Newberry185ab292017-03-28 06:45:39 +0000528
529 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000530 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
531 BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt);
532 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2
533 BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt);
534 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
535 BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt);
536 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
537 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
538 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
539 BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt);
Eric Newberry185ab292017-03-28 06:45:39 +0000540 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700541 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 0);
542 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
543 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700544 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000545
546 lp::Packet ackPkt1;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000547 ackPkt1.add<lp::AckField>(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000548
549 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
550
551 reliability->processIncomingPacket(ackPkt1);
552
553 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700554 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000555 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
556 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000557 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700558 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000559 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
560 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700561 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
Eric Newberry7b0071e2017-07-03 17:33:31 +0000562 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
563 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700564 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000565 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
566 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000567 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000568 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700569 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
570 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
571 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700572 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000573
574 lp::Packet ackPkt2;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000575 ackPkt2.add<lp::AckField>(2);
576 ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored
Eric Newberry185ab292017-03-28 06:45:39 +0000577
578 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
579
580 reliability->processIncomingPacket(ackPkt2);
581
582 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000583 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000584 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
585 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000586 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
Eric Newberry00d39fd2017-12-10 14:26:45 -0700587 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
Eric Newberry7b0071e2017-07-03 17:33:31 +0000588 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
589 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700590 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
591 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000592 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
593 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
594 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000595 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000596 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700597 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 2);
598 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
599 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700600 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000601
602 lp::Packet ackPkt3;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000603 ackPkt3.add<lp::AckField>(1);
Eric Newberry185ab292017-03-28 06:45:39 +0000604
605 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
606
607 reliability->processIncomingPacket(ackPkt3);
608
609 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000610 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
611 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
612 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
613 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700614 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000615 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
616 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700617 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq
Eric Newberry7b0071e2017-07-03 17:33:31 +0000618 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1);
619 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0);
620 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000621 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry185ab292017-03-28 06:45:39 +0000622 lp::Packet sentRetxPkt(transport->sentPackets.back().packet);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000623 BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>());
624 BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4);
625 BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>());
626 BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700627 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
628 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
629 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700630 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000631
632 lp::Packet ackPkt4;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000633 ackPkt4.add<lp::AckField>(4);
Eric Newberry185ab292017-03-28 06:45:39 +0000634
635 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
636
637 reliability->processIncomingPacket(ackPkt4);
638
639 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000640 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
641 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
642 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
643 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
Eric Newberry00d39fd2017-12-10 14:26:45 -0700644 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
Eric Newberry7b0071e2017-07-03 17:33:31 +0000645 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
646 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1);
647 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq
648 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000649 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry00d39fd2017-12-10 14:26:45 -0700650 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 3);
651 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 1);
652 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
653 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
654}
655
656BOOST_AUTO_TEST_CASE(CancelLossNotificationOnAck)
657{
658 reliability->onDroppedInterest.connect([] (const Interest&) {
659 BOOST_FAIL("Packet loss timeout should be cancelled when packet acknowledged");
660 });
661
662 reliability->m_lastTxSeqNo = 0;
663
664 linkService->sendLpPackets({makeFrag(1, 50)});
665
666 advanceClocks(time::milliseconds(1), 500);
667
668 lp::Packet ackPkt;
669 ackPkt.add<lp::AckField>(1);
670 reliability->processIncomingPacket(ackPkt);
671
672 advanceClocks(time::milliseconds(1), 1000);
673
674 BOOST_CHECK_EQUAL(linkService->getCounters().nAcknowledged, 1);
675 BOOST_CHECK_EQUAL(linkService->getCounters().nRetransmitted, 0);
676 BOOST_CHECK_EQUAL(linkService->getCounters().nRetxExhausted, 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700677 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000678}
679
680BOOST_AUTO_TEST_SUITE_END() // Sender
681
682BOOST_AUTO_TEST_SUITE(Receiver)
683
684BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
685{
686 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
687 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
688
689 lp::Packet pkt1 = makeFrag(100, 40);
690 pkt1.add<lp::TxSequenceField>(765432);
691
692 reliability->processIncomingPacket(pkt1);
693
694 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
695 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1);
696 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
697
698 lp::Packet pkt2 = makeFrag(276, 40);
699 pkt2.add<lp::TxSequenceField>(234567);
700
701 reliability->processIncomingPacket(pkt2);
702
703 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
704 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2);
705 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
706 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567);
707
708 // T+5ms
709 advanceClocks(time::milliseconds(1), 5);
710 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000711}
712
713BOOST_AUTO_TEST_CASE(PiggybackAcks)
714{
715 reliability->m_ackQueue.push(256);
716 reliability->m_ackQueue.push(257);
717 reliability->m_ackQueue.push(10);
718
719 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000720 linkService->sendLpPackets({pkt});
721
722 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
723 lp::Packet sentPkt(transport->sentPackets.front().packet);
724
725 BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3);
726 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256);
727 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257);
728 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000729 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000730
731 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
732}
733
734BOOST_AUTO_TEST_CASE(PiggybackAcksMtu)
735{
736 // This test case tests for piggybacking Acks when there is an MTU on the link.
737
Eric Newberry7b0071e2017-07-03 17:33:31 +0000738 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000739
Eric Newberry7b0071e2017-07-03 17:33:31 +0000740 for (lp::Sequence i = 1000; i < 2000; i++) {
741 reliability->m_ackQueue.push(i);
742 }
Eric Newberry185ab292017-03-28 06:45:39 +0000743
Eric Newberry7b0071e2017-07-03 17:33:31 +0000744 BOOST_CHECK(!reliability->m_ackQueue.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000745
Eric Newberry7b0071e2017-07-03 17:33:31 +0000746 for (int i = 0; i < 5; i++) {
747 lp::Packet pkt = makeFrag(i, 60);
748 linkService->sendLpPackets({pkt});
Eric Newberry185ab292017-03-28 06:45:39 +0000749
Eric Newberry7b0071e2017-07-03 17:33:31 +0000750 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i + 1);
751 lp::Packet sentPkt(transport->sentPackets.back().packet);
752 BOOST_CHECK_EQUAL(getPktNo(sentPkt), i);
753 BOOST_CHECK(sentPkt.has<lp::AckField>());
754 }
Eric Newberry185ab292017-03-28 06:45:39 +0000755
Eric Newberry7b0071e2017-07-03 17:33:31 +0000756 BOOST_CHECK(reliability->m_ackQueue.empty());
757}
Eric Newberry185ab292017-03-28 06:45:39 +0000758
Eric Newberry7b0071e2017-07-03 17:33:31 +0000759BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace)
760{
761 // This test case tests for piggybacking Acks when there is an MTU on the link, resulting in no
762 // space for Acks (and negative remainingSpace in the piggyback function).
763
764 transport->setMtu(250);
765
766 for (lp::Sequence i = 1000; i < 1100; i++) {
767 reliability->m_ackQueue.push(i);
768 }
769
770 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
771
772 lp::Packet pkt = makeFrag(1, 240);
773 linkService->sendLpPackets({pkt});
774
775 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
Eric Newberry185ab292017-03-28 06:45:39 +0000776
777 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000778 lp::Packet sentPkt(transport->sentPackets.back().packet);
779 BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1);
780 BOOST_CHECK(!sentPkt.has<lp::AckField>());
781}
Eric Newberry185ab292017-03-28 06:45:39 +0000782
Eric Newberry7b0071e2017-07-03 17:33:31 +0000783BOOST_AUTO_TEST_CASE(StartIdleAckTimer)
784{
785 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000786
Eric Newberry7b0071e2017-07-03 17:33:31 +0000787 lp::Packet pkt1 = makeFrag(1, 100);
788 pkt1.add<lp::TxSequenceField>(12);
789 reliability->processIncomingPacket({pkt1});
790 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000791
Eric Newberry7b0071e2017-07-03 17:33:31 +0000792 // T+1ms
793 advanceClocks(time::milliseconds(1), 1);
794 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000795
Eric Newberry7b0071e2017-07-03 17:33:31 +0000796 lp::Packet pkt2 = makeFrag(2, 100);
797 pkt2.add<lp::TxSequenceField>(13);
798 reliability->processIncomingPacket({pkt2});
799 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000800
Eric Newberry7b0071e2017-07-03 17:33:31 +0000801 // T+5ms
802 advanceClocks(time::milliseconds(1), 4);
803 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000804
Eric Newberry7b0071e2017-07-03 17:33:31 +0000805 lp::Packet pkt3 = makeFrag(3, 100);
806 pkt3.add<lp::TxSequenceField>(15);
807 reliability->processIncomingPacket({pkt3});
808 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000809
Eric Newberry7b0071e2017-07-03 17:33:31 +0000810 // T+9ms
811 advanceClocks(time::milliseconds(1), 4);
812 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000813
Eric Newberry7b0071e2017-07-03 17:33:31 +0000814 // T+10ms
815 advanceClocks(time::milliseconds(1), 1);
816 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000817}
818
819BOOST_AUTO_TEST_CASE(IdleAckTimer)
820{
821 // T+1ms
822 advanceClocks(time::milliseconds(1), 1);
823
Eric Newberry7b0071e2017-07-03 17:33:31 +0000824 for (lp::Sequence i = 1000; i < 2000; i++) {
825 reliability->m_ackQueue.push(i);
826 }
827
828 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000829 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
830 reliability->startIdleAckTimer();
831 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
832
833 // T+5ms
834 advanceClocks(time::milliseconds(1), 4);
835 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000836 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
837 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
838 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1999);
Eric Newberry185ab292017-03-28 06:45:39 +0000839 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
840
841 // T+6ms
842 advanceClocks(time::milliseconds(1), 1);
843
844 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000845 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000846 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
847 lp::Packet sentPkt1(transport->sentPackets.back().packet);
848
Eric Newberry7b0071e2017-07-03 17:33:31 +0000849 BOOST_CHECK(!sentPkt1.has<lp::TxSequenceField>());
850 BOOST_CHECK_EQUAL(sentPkt1.count<lp::AckField>(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000851
Eric Newberry7b0071e2017-07-03 17:33:31 +0000852 for (lp::Sequence i = 10000; i < 11000; i++) {
853 reliability->m_ackQueue.push(i);
854 }
855
Eric Newberry185ab292017-03-28 06:45:39 +0000856 reliability->startIdleAckTimer();
857 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000858 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
859 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 10000);
860 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 10999);
Eric Newberry185ab292017-03-28 06:45:39 +0000861
862 // T+10ms
863 advanceClocks(time::milliseconds(1), 4);
864 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
865 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000866 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000867
868 // T+11ms
869 advanceClocks(time::milliseconds(1), 1);
870
871 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000872 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000873 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
874 lp::Packet sentPkt2(transport->sentPackets.back().packet);
875
Eric Newberry7b0071e2017-07-03 17:33:31 +0000876 BOOST_REQUIRE_EQUAL(sentPkt2.count<lp::AckField>(), 1000);
877 BOOST_CHECK(!sentPkt2.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000878
879 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000880 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000881
882 // T+16ms
883 advanceClocks(time::milliseconds(1), 5);
884
885 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
886 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
887 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
888}
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
894 // T+1ms
895 advanceClocks(time::milliseconds(1), 1);
896
Eric Newberry7b0071e2017-07-03 17:33:31 +0000897 for (lp::Sequence i = 1000; i < 2000; i++) {
898 reliability->m_ackQueue.push(i);
899 }
900
901 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000902 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
903 reliability->startIdleAckTimer();
904 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
905
906 // T+5ms
907 advanceClocks(time::milliseconds(1), 4);
908 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000909 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000910 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
911
912 // T+6ms
913 advanceClocks(time::milliseconds(1), 1);
914
915 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
916
Eric Newberry7b0071e2017-07-03 17:33:31 +0000917 for (lp::Sequence i = 5000; i < 6000; i++) {
918 reliability->m_ackQueue.push(i);
919 }
920
Eric Newberry185ab292017-03-28 06:45:39 +0000921 reliability->startIdleAckTimer();
922 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
923
Eric Newberry7b0071e2017-07-03 17:33:31 +0000924 // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet
925 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
926 for (int i = 0; i < 4; i++) {
927 lp::Packet sentPkt(transport->sentPackets[i].packet);
928 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
929 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249);
930 }
931 lp::Packet sentPkt(transport->sentPackets[4].packet);
932 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
933 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249);
Eric Newberry185ab292017-03-28 06:45:39 +0000934
Eric Newberry7b0071e2017-07-03 17:33:31 +0000935 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
936 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 5000);
937 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 5999);
Eric Newberry185ab292017-03-28 06:45:39 +0000938
939 // T+10ms
940 advanceClocks(time::milliseconds(1), 4);
941 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000942 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
943 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000944
945 // T+11ms
946 advanceClocks(time::milliseconds(1), 1);
947
948 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
949
Eric Newberry7b0071e2017-07-03 17:33:31 +0000950 for (lp::Sequence i = 100000; i < 101000; i++) {
951 reliability->m_ackQueue.push(i);
952 }
953
Eric Newberry185ab292017-03-28 06:45:39 +0000954 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000955 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000956
Eric Newberry7b0071e2017-07-03 17:33:31 +0000957 // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet
958 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
959 for (int i = 5; i < 9; i++) {
960 lp::Packet sentPkt(transport->sentPackets[i].packet);
961 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
962 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249);
963 }
964 sentPkt.wireDecode(transport->sentPackets[9].packet);
965 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
966 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249);
967
968 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
969 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 100000);
970 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 100999);
Eric Newberry185ab292017-03-28 06:45:39 +0000971 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
972
973 // T+15ms
974 advanceClocks(time::milliseconds(1), 4);
975 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000976 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 10);
977 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000978
979 // T+16ms
980 advanceClocks(time::milliseconds(1), 1);
981
Eric Newberry7b0071e2017-07-03 17:33:31 +0000982 // given Ack of size 8 and MTU of 1500, approx 187 Acks/IDLE packet
Eric Newberry185ab292017-03-28 06:45:39 +0000983 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000984 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
985 for (int i = 10; i < 15; i++) {
986 lp::Packet sentPkt(transport->sentPackets[i].packet);
987 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
988 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 187);
989 }
990 sentPkt.wireDecode(transport->sentPackets[15].packet);
991 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
992 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 187);
Eric Newberry185ab292017-03-28 06:45:39 +0000993
994 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000995 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000996
997 // T+21ms
998 advanceClocks(time::milliseconds(1), 5);
999
1000 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +00001001 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 16);
Eric Newberry185ab292017-03-28 06:45:39 +00001002 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
1003}
1004
Eric Newberry7b0071e2017-07-03 17:33:31 +00001005BOOST_AUTO_TEST_SUITE_END() // Receiver
Eric Newberry185ab292017-03-28 06:45:39 +00001006
Eric Newberry7b0071e2017-07-03 17:33:31 +00001007BOOST_AUTO_TEST_SUITE_END() // TestLpReliability
Eric Newberry185ab292017-03-28 06:45:39 +00001008BOOST_AUTO_TEST_SUITE_END() // Face
1009
1010} // namespace tests
1011} // namespace face
1012} // namespace nfd