blob: 5c7bc27d032e70a032157974d35a67bc6a117dde [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 Newberry41aba102017-11-01 16:42:13 -0700182 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000183}
184
Eric Newberry7b0071e2017-07-03 17:33:31 +0000185BOOST_AUTO_TEST_CASE(SendUnfragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000186{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000187 lp::Packet pkt1 = makeFrag(1024, 50);
188 lp::Packet pkt2 = makeFrag(3000, 30);
Eric Newberry185ab292017-03-28 06:45:39 +0000189
190 linkService->sendLpPackets({pkt1});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000191 lp::Packet cached1(transport->sentPackets.front().packet);
192 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
193 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
194 BOOST_CHECK(!cached1.has<lp::SequenceField>());
195 lp::Sequence firstTxSeq = cached1.get<lp::TxSequenceField>();
196 BOOST_CHECK_EQUAL(getPktNo(cached1), 1024);
Eric Newberry41aba102017-11-01 16:42:13 -0700197 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000198
Eric Newberry185ab292017-03-28 06:45:39 +0000199 // T+500ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000200 // 1024 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000201 advanceClocks(time::milliseconds(1), 500);
202 linkService->sendLpPackets({pkt2});
Eric Newberry7b0071e2017-07-03 17:33:31 +0000203 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000204
Eric Newberry7b0071e2017-07-03 17:33:31 +0000205 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2);
206 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 1);
207 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
208 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq).netPkt);
209 BOOST_CHECK(reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
210 BOOST_CHECK_NE(reliability->m_unackedFrags.at(firstTxSeq).netPkt,
211 reliability->m_unackedFrags.at(firstTxSeq + 1).netPkt);
212 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq).retxCount, 0);
213 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
214 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq);
215 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700216 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000217
218 // T+1250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000219 // 1024 rto: 1000ms, txSeq: 4, started T+1000ms, retx 1
220 // 3000 rto: 1000ms, txSeq: 3, started T+500ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000221 advanceClocks(time::milliseconds(1), 750);
222
Eric Newberry7b0071e2017-07-03 17:33:31 +0000223 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2);
224 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq), 0);
225 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 1);
226 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 2).retxCount, 1);
227 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 1);
228 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 1).retxCount, 0);
229 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 1);
230 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry41aba102017-11-01 16:42:13 -0700231 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000232
233 // T+2250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000234 // 1024 rto: 1000ms, txSeq: 6, started T+2000ms, retx 2
235 // 3000 rto: 1000ms, txSeq: 5, started T+1500ms, retx 1
Eric Newberry185ab292017-03-28 06:45:39 +0000236 advanceClocks(time::milliseconds(1), 1000);
237
Eric Newberry7b0071e2017-07-03 17:33:31 +0000238 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2);
239 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 1), 0);
240 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 2), 0);
241 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 1);
242 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 4).retxCount, 2);
243 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 1);
244 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 3).retxCount, 1);
245 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 3);
246 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry41aba102017-11-01 16:42:13 -0700247 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000248
249 // T+3250ms
Eric Newberry7b0071e2017-07-03 17:33:31 +0000250 // 1024 rto: 1000ms, txSeq: 8, started T+3000ms, retx 3
251 // 3000 rto: 1000ms, txSeq: 7, started T+2500ms, retx 2
Eric Newberry185ab292017-03-28 06:45:39 +0000252 advanceClocks(time::milliseconds(1), 1000);
253
Eric Newberry7b0071e2017-07-03 17:33:31 +0000254 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 2);
255 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 3), 0);
256 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 4), 0);
257 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 1);
258 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 6).retxCount, 3);
259 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 1);
260 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 5).retxCount, 2);
261 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 5);
262 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 7);
Eric Newberry41aba102017-11-01 16:42:13 -0700263 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000264
265 // T+4250ms
266 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000267 // 3000 rto: 1000ms, txSeq: 9, started T+3500ms, retx 3
Eric Newberry185ab292017-03-28 06:45:39 +0000268 advanceClocks(time::milliseconds(1), 1000);
269
Eric Newberry7b0071e2017-07-03 17:33:31 +0000270 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.size(), 1);
271 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 5), 0);
272 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 6), 0);
273 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(firstTxSeq + 7), 1);
274 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(firstTxSeq + 7).retxCount, 3);
275 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, firstTxSeq + 7);
276 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry185ab292017-03-28 06:45:39 +0000277
Eric Newberry41aba102017-11-01 16:42:13 -0700278 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
279
Eric Newberry185ab292017-03-28 06:45:39 +0000280 // T+4750ms
281 // 1024 rto: expired, removed
Eric Newberry7b0071e2017-07-03 17:33:31 +0000282 // 3000 rto: expired, removed
Eric Newberry185ab292017-03-28 06:45:39 +0000283 advanceClocks(time::milliseconds(1), 1000);
284
285 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000286 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
287 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 8);
Eric Newberry41aba102017-11-01 16:42:13 -0700288 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 2);
Eric Newberry185ab292017-03-28 06:45:39 +0000289}
290
Eric Newberry7b0071e2017-07-03 17:33:31 +0000291BOOST_AUTO_TEST_CASE(SendFragmentedRetx)
Eric Newberry185ab292017-03-28 06:45:39 +0000292{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000293 lp::Packet pkt1 = makeFrag(2048, 30);
294 lp::Packet pkt2 = makeFrag(2049, 30);
295 lp::Packet pkt3 = makeFrag(2050, 10);
Eric Newberry185ab292017-03-28 06:45:39 +0000296
Eric Newberry7b0071e2017-07-03 17:33:31 +0000297 linkService->sendLpPackets({pkt1, pkt2, pkt3});
298 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000299
Eric Newberry7b0071e2017-07-03 17:33:31 +0000300 lp::Packet cached1(transport->sentPackets.at(0).packet);
301 BOOST_REQUIRE(cached1.has<lp::TxSequenceField>());
302 BOOST_CHECK_EQUAL(cached1.get<lp::TxSequenceField>(), 2);
303 BOOST_CHECK_EQUAL(getPktNo(cached1), 2048);
304 lp::Packet cached2(transport->sentPackets.at(1).packet);
305 BOOST_REQUIRE(cached2.has<lp::TxSequenceField>());
306 BOOST_CHECK_EQUAL(cached2.get<lp::TxSequenceField>(), 3);
307 BOOST_CHECK_EQUAL(getPktNo(cached2), 2049);
308 lp::Packet cached3(transport->sentPackets.at(2).packet);
309 BOOST_REQUIRE(cached3.has<lp::TxSequenceField>());
310 BOOST_CHECK_EQUAL(cached3.get<lp::TxSequenceField>(), 4);
311 BOOST_CHECK_EQUAL(getPktNo(cached3), 2050);
Eric Newberry41aba102017-11-01 16:42:13 -0700312 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000313
Eric Newberry7b0071e2017-07-03 17:33:31 +0000314 // T+0ms
315 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
316 // 2049 rto: 1000ms, txSeq: 3, started T+0ms, retx 0
317 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
Eric Newberry185ab292017-03-28 06:45:39 +0000318
Eric Newberry7b0071e2017-07-03 17:33:31 +0000319 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
320 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1);
321 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1);
322 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
323 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(3).pkt), 2049);
324 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
325 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
326 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
327 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
328 BOOST_REQUIRE(reliability->m_unackedFrags.at(3).netPkt);
329 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
330 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
331 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(3).netPkt);
332 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
333 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
334 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
335 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
336 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
337 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
338 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
339 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 3);
Eric Newberry41aba102017-11-01 16:42:13 -0700340 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000341
Eric Newberry7b0071e2017-07-03 17:33:31 +0000342 // T+250ms
343 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
344 // 2049 rto: 1000ms, txSeq: 5, started T+250ms, retx 1
345 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
346 advanceClocks(time::milliseconds(1), 250);
347 reliability->onLpPacketLost(getIteratorFromTxSeq(3));
Eric Newberry185ab292017-03-28 06:45:39 +0000348
Eric Newberry7b0071e2017-07-03 17:33:31 +0000349 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
350 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 0);
351 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(5), 1);
352 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1);
353 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
354 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(5).pkt), 2049);
355 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
356 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
357 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
358 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(5).retxCount, 1);
359 BOOST_REQUIRE(reliability->m_unackedFrags.at(5).netPkt);
360 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
361 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
362 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(5).netPkt);
363 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
364 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
365 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
366 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 3));
367 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
368 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
369 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
370 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 4);
Eric Newberry41aba102017-11-01 16:42:13 -0700371 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000372
373 // T+500ms
374 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
375 // 2049 rto: 1000ms, txSeq: 6, started T+500ms, retx 2
376 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
377 advanceClocks(time::milliseconds(1), 250);
378 reliability->onLpPacketLost(getIteratorFromTxSeq(5));
379
380 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
381 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(5), 0);
382 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(6), 1);
383 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1);
384 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
385 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(6).pkt), 2049);
386 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
387 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
388 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
389 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(6).retxCount, 2);
390 BOOST_REQUIRE(reliability->m_unackedFrags.at(6).netPkt);
391 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
392 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
393 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(6).netPkt);
394 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
395 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
396 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
397 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 5));
398 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
399 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
400 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
401 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry41aba102017-11-01 16:42:13 -0700402 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000403
404 // T+750ms
405 // 2048 rto: 1000ms, txSeq: 2, started T+0ms, retx 0
406 // 2049 rto: 1000ms, txSeq: 7, started T+750ms, retx 3
407 // 2050 rto: 1000ms, txSeq: 4, started T+0ms, retx 0
408 advanceClocks(time::milliseconds(1), 250);
409 reliability->onLpPacketLost(getIteratorFromTxSeq(6));
410
411 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1);
412 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(6), 0);
413 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(7), 1);
414 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1);
415 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(2).pkt), 2048);
416 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(7).pkt), 2049);
417 BOOST_CHECK_EQUAL(getPktNo(reliability->m_unackedFrags.at(4).pkt), 2050);
418 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
419 BOOST_REQUIRE(reliability->m_unackedFrags.at(2).netPkt);
420 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(7).retxCount, 3);
421 BOOST_REQUIRE(reliability->m_unackedFrags.at(7).netPkt);
422 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 0);
423 BOOST_REQUIRE(reliability->m_unackedFrags.at(4).netPkt);
424 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(7).netPkt);
425 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt, reliability->m_unackedFrags.at(4).netPkt);
426 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).netPkt->unackedFrags.size(), 3);
427 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 2));
428 BOOST_CHECK(!netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 6));
429 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 7));
430 BOOST_CHECK(netPktHasUnackedFrag(reliability->m_unackedFrags.at(2).netPkt, 4));
431 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 2);
432 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
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+850ms
436 // 2048 rto: expired, removed
437 // 2049 rto: expired, removed
438 // 2050 rto: expired, removed
439 advanceClocks(time::milliseconds(1), 100);
440 reliability->onLpPacketLost(getIteratorFromTxSeq(7));
441
442 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 0);
443 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry41aba102017-11-01 16:42:13 -0700444 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000445}
446
447BOOST_AUTO_TEST_CASE(LossByGreaterAcks) // detect loss by 3x greater Acks, also tests wraparound
448{
449 reliability->m_lastTxSeqNo = 0xFFFFFFFFFFFFFFFE;
450
451 // Passed to sendLpPackets individually since they are from separate, non-fragmented network packets
452 linkService->sendLpPackets({makeFrag(1, 50)});
453 linkService->sendLpPackets({makeFrag(2, 50)});
454 linkService->sendLpPackets({makeFrag(3, 50)});
455 linkService->sendLpPackets({makeFrag(4, 50)});
456 linkService->sendLpPackets({makeFrag(5, 50)});
Eric Newberry185ab292017-03-28 06:45:39 +0000457
458 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 5);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000459 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
460 BOOST_CHECK(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).netPkt);
461 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 1); // pkt2
462 BOOST_CHECK(reliability->m_unackedFrags.at(0).netPkt);
463 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
464 BOOST_CHECK(reliability->m_unackedFrags.at(1).netPkt);
465 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
466 BOOST_CHECK(reliability->m_unackedFrags.at(2).netPkt);
467 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
468 BOOST_CHECK(reliability->m_unackedFrags.at(3).netPkt);
Eric Newberry185ab292017-03-28 06:45:39 +0000469 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry41aba102017-11-01 16:42:13 -0700470 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000471
472 lp::Packet ackPkt1;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000473 ackPkt1.add<lp::AckField>(0);
Eric Newberry185ab292017-03-28 06:45:39 +0000474
475 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
476
477 reliability->processIncomingPacket(ackPkt1);
478
479 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 4);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000480 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000481 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
482 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000483 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
484 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
485 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
486 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 0);
487 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 1); // pkt4
488 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).retxCount, 0);
489 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(2).nGreaterSeqAcks, 0);
490 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
491 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
492 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000493 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000494 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry41aba102017-11-01 16:42:13 -0700495 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000496
497 lp::Packet ackPkt2;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000498 ackPkt2.add<lp::AckField>(2);
499 ackPkt1.add<lp::AckField>(101010); // Unknown TxSequence number - ignored
Eric Newberry185ab292017-03-28 06:45:39 +0000500
501 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
502
503 reliability->processIncomingPacket(ackPkt2);
504
505 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 3);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000506 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 1); // pkt1
Eric Newberry185ab292017-03-28 06:45:39 +0000507 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).retxCount, 0);
508 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(0xFFFFFFFFFFFFFFFF).nGreaterSeqAcks, 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000509 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
510 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(1), 1); // pkt3
511 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).retxCount, 0);
512 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(1).nGreaterSeqAcks, 1);
513 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
514 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
515 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
516 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
517 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(101010), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000518 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 0xFFFFFFFFFFFFFFFF);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000519 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
Eric Newberry41aba102017-11-01 16:42:13 -0700520 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000521
522 lp::Packet ackPkt3;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000523 ackPkt3.add<lp::AckField>(1);
Eric Newberry185ab292017-03-28 06:45:39 +0000524
525 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
526
527 reliability->processIncomingPacket(ackPkt3);
528
529 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 2);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000530 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
531 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
532 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
533 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
534 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
535 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
536 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 0);
537 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(4), 1); // pkt1 new TxSeq
538 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).retxCount, 1);
539 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(4).nGreaterSeqAcks, 0);
540 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000541 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry185ab292017-03-28 06:45:39 +0000542 lp::Packet sentRetxPkt(transport->sentPackets.back().packet);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000543 BOOST_REQUIRE(sentRetxPkt.has<lp::TxSequenceField>());
544 BOOST_CHECK_EQUAL(sentRetxPkt.get<lp::TxSequenceField>(), 4);
545 BOOST_REQUIRE(sentRetxPkt.has<lp::FragmentField>());
546 BOOST_CHECK_EQUAL(getPktNo(sentRetxPkt), 1);
Eric Newberry41aba102017-11-01 16:42:13 -0700547 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000548
549 lp::Packet ackPkt4;
Eric Newberry7b0071e2017-07-03 17:33:31 +0000550 ackPkt4.add<lp::AckField>(4);
Eric Newberry185ab292017-03-28 06:45:39 +0000551
552 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
553
554 reliability->processIncomingPacket(ackPkt4);
555
556 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000557 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0xFFFFFFFFFFFFFFFF), 0); // pkt1 old TxSeq
558 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(0), 0); // pkt2
559 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(1), 0); // pkt3
560 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(2), 0); // pkt4
561 BOOST_REQUIRE_EQUAL(reliability->m_unackedFrags.count(3), 1); // pkt5
562 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).retxCount, 0);
563 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.at(3).nGreaterSeqAcks, 1);
564 BOOST_CHECK_EQUAL(reliability->m_unackedFrags.count(4), 0); // pkt1 new TxSeq
565 BOOST_CHECK_EQUAL(reliability->m_firstUnackedFrag->first, 3);
Eric Newberry185ab292017-03-28 06:45:39 +0000566 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 6);
Eric Newberry41aba102017-11-01 16:42:13 -0700567 BOOST_CHECK_EQUAL(linkService->getCounters().nDroppedInterests, 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000568}
569
570BOOST_AUTO_TEST_SUITE_END() // Sender
571
572BOOST_AUTO_TEST_SUITE(Receiver)
573
574BOOST_AUTO_TEST_CASE(ProcessIncomingPacket)
575{
576 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
577 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
578
579 lp::Packet pkt1 = makeFrag(100, 40);
580 pkt1.add<lp::TxSequenceField>(765432);
581
582 reliability->processIncomingPacket(pkt1);
583
584 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
585 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 1);
586 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
587
588 lp::Packet pkt2 = makeFrag(276, 40);
589 pkt2.add<lp::TxSequenceField>(234567);
590
591 reliability->processIncomingPacket(pkt2);
592
593 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
594 BOOST_REQUIRE_EQUAL(reliability->m_ackQueue.size(), 2);
595 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 765432);
596 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 234567);
597
598 // T+5ms
599 advanceClocks(time::milliseconds(1), 5);
600 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000601}
602
603BOOST_AUTO_TEST_CASE(PiggybackAcks)
604{
605 reliability->m_ackQueue.push(256);
606 reliability->m_ackQueue.push(257);
607 reliability->m_ackQueue.push(10);
608
609 lp::Packet pkt;
Eric Newberry185ab292017-03-28 06:45:39 +0000610 linkService->sendLpPackets({pkt});
611
612 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
613 lp::Packet sentPkt(transport->sentPackets.front().packet);
614
615 BOOST_REQUIRE_EQUAL(sentPkt.count<lp::AckField>(), 3);
616 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(0), 256);
617 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(1), 257);
618 BOOST_CHECK_EQUAL(sentPkt.get<lp::AckField>(2), 10);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000619 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000620
621 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
622}
623
624BOOST_AUTO_TEST_CASE(PiggybackAcksMtu)
625{
626 // This test case tests for piggybacking Acks when there is an MTU on the link.
627
Eric Newberry7b0071e2017-07-03 17:33:31 +0000628 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000629
Eric Newberry7b0071e2017-07-03 17:33:31 +0000630 for (lp::Sequence i = 1000; i < 2000; i++) {
631 reliability->m_ackQueue.push(i);
632 }
Eric Newberry185ab292017-03-28 06:45:39 +0000633
Eric Newberry7b0071e2017-07-03 17:33:31 +0000634 BOOST_CHECK(!reliability->m_ackQueue.empty());
Eric Newberry185ab292017-03-28 06:45:39 +0000635
Eric Newberry7b0071e2017-07-03 17:33:31 +0000636 for (int i = 0; i < 5; i++) {
637 lp::Packet pkt = makeFrag(i, 60);
638 linkService->sendLpPackets({pkt});
Eric Newberry185ab292017-03-28 06:45:39 +0000639
Eric Newberry7b0071e2017-07-03 17:33:31 +0000640 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), i + 1);
641 lp::Packet sentPkt(transport->sentPackets.back().packet);
642 BOOST_CHECK_EQUAL(getPktNo(sentPkt), i);
643 BOOST_CHECK(sentPkt.has<lp::AckField>());
644 }
Eric Newberry185ab292017-03-28 06:45:39 +0000645
Eric Newberry7b0071e2017-07-03 17:33:31 +0000646 BOOST_CHECK(reliability->m_ackQueue.empty());
647}
Eric Newberry185ab292017-03-28 06:45:39 +0000648
Eric Newberry7b0071e2017-07-03 17:33:31 +0000649BOOST_AUTO_TEST_CASE(PiggybackAcksMtuNoSpace)
650{
651 // This test case tests for piggybacking Acks when there is an MTU on the link, resulting in no
652 // space for Acks (and negative remainingSpace in the piggyback function).
653
654 transport->setMtu(250);
655
656 for (lp::Sequence i = 1000; i < 1100; i++) {
657 reliability->m_ackQueue.push(i);
658 }
659
660 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
661
662 lp::Packet pkt = makeFrag(1, 240);
663 linkService->sendLpPackets({pkt});
664
665 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 100);
Eric Newberry185ab292017-03-28 06:45:39 +0000666
667 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000668 lp::Packet sentPkt(transport->sentPackets.back().packet);
669 BOOST_CHECK_EQUAL(getPktNo(sentPkt), 1);
670 BOOST_CHECK(!sentPkt.has<lp::AckField>());
671}
Eric Newberry185ab292017-03-28 06:45:39 +0000672
Eric Newberry7b0071e2017-07-03 17:33:31 +0000673BOOST_AUTO_TEST_CASE(StartIdleAckTimer)
674{
675 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000676
Eric Newberry7b0071e2017-07-03 17:33:31 +0000677 lp::Packet pkt1 = makeFrag(1, 100);
678 pkt1.add<lp::TxSequenceField>(12);
679 reliability->processIncomingPacket({pkt1});
680 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000681
Eric Newberry7b0071e2017-07-03 17:33:31 +0000682 // T+1ms
683 advanceClocks(time::milliseconds(1), 1);
684 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000685
Eric Newberry7b0071e2017-07-03 17:33:31 +0000686 lp::Packet pkt2 = makeFrag(2, 100);
687 pkt2.add<lp::TxSequenceField>(13);
688 reliability->processIncomingPacket({pkt2});
689 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000690
Eric Newberry7b0071e2017-07-03 17:33:31 +0000691 // T+5ms
692 advanceClocks(time::milliseconds(1), 4);
693 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000694
Eric Newberry7b0071e2017-07-03 17:33:31 +0000695 lp::Packet pkt3 = makeFrag(3, 100);
696 pkt3.add<lp::TxSequenceField>(15);
697 reliability->processIncomingPacket({pkt3});
698 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000699
Eric Newberry7b0071e2017-07-03 17:33:31 +0000700 // T+9ms
701 advanceClocks(time::milliseconds(1), 4);
702 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000703
Eric Newberry7b0071e2017-07-03 17:33:31 +0000704 // T+10ms
705 advanceClocks(time::milliseconds(1), 1);
706 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000707}
708
709BOOST_AUTO_TEST_CASE(IdleAckTimer)
710{
711 // T+1ms
712 advanceClocks(time::milliseconds(1), 1);
713
Eric Newberry7b0071e2017-07-03 17:33:31 +0000714 for (lp::Sequence i = 1000; i < 2000; i++) {
715 reliability->m_ackQueue.push(i);
716 }
717
718 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000719 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
720 reliability->startIdleAckTimer();
721 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
722
723 // T+5ms
724 advanceClocks(time::milliseconds(1), 4);
725 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000726 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
727 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 1000);
728 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 1999);
Eric Newberry185ab292017-03-28 06:45:39 +0000729 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
730
731 // T+6ms
732 advanceClocks(time::milliseconds(1), 1);
733
734 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000735 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000736 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 1);
737 lp::Packet sentPkt1(transport->sentPackets.back().packet);
738
Eric Newberry7b0071e2017-07-03 17:33:31 +0000739 BOOST_CHECK(!sentPkt1.has<lp::TxSequenceField>());
740 BOOST_CHECK_EQUAL(sentPkt1.count<lp::AckField>(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000741
Eric Newberry7b0071e2017-07-03 17:33:31 +0000742 for (lp::Sequence i = 10000; i < 11000; i++) {
743 reliability->m_ackQueue.push(i);
744 }
745
Eric Newberry185ab292017-03-28 06:45:39 +0000746 reliability->startIdleAckTimer();
747 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000748 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
749 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 10000);
750 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 10999);
Eric Newberry185ab292017-03-28 06:45:39 +0000751
752 // T+10ms
753 advanceClocks(time::milliseconds(1), 4);
754 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
755 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 1);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000756 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000757
758 // T+11ms
759 advanceClocks(time::milliseconds(1), 1);
760
761 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000762 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry185ab292017-03-28 06:45:39 +0000763 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 2);
764 lp::Packet sentPkt2(transport->sentPackets.back().packet);
765
Eric Newberry7b0071e2017-07-03 17:33:31 +0000766 BOOST_REQUIRE_EQUAL(sentPkt2.count<lp::AckField>(), 1000);
767 BOOST_CHECK(!sentPkt2.has<lp::TxSequenceField>());
Eric Newberry185ab292017-03-28 06:45:39 +0000768
769 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000770 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000771
772 // T+16ms
773 advanceClocks(time::milliseconds(1), 5);
774
775 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
776 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 2);
777 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
778}
779
780BOOST_AUTO_TEST_CASE(IdleAckTimerMtu)
781{
Eric Newberry7b0071e2017-07-03 17:33:31 +0000782 transport->setMtu(1500);
Eric Newberry185ab292017-03-28 06:45:39 +0000783
784 // T+1ms
785 advanceClocks(time::milliseconds(1), 1);
786
Eric Newberry7b0071e2017-07-03 17:33:31 +0000787 for (lp::Sequence i = 1000; i < 2000; i++) {
788 reliability->m_ackQueue.push(i);
789 }
790
791 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000792 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
793 reliability->startIdleAckTimer();
794 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
795
796 // T+5ms
797 advanceClocks(time::milliseconds(1), 4);
798 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000799 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000800 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 0);
801
802 // T+6ms
803 advanceClocks(time::milliseconds(1), 1);
804
805 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
806
Eric Newberry7b0071e2017-07-03 17:33:31 +0000807 for (lp::Sequence i = 5000; i < 6000; i++) {
808 reliability->m_ackQueue.push(i);
809 }
810
Eric Newberry185ab292017-03-28 06:45:39 +0000811 reliability->startIdleAckTimer();
812 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
813
Eric Newberry7b0071e2017-07-03 17:33:31 +0000814 // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet
815 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 5);
816 for (int i = 0; i < 4; i++) {
817 lp::Packet sentPkt(transport->sentPackets[i].packet);
818 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
819 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249);
820 }
821 lp::Packet sentPkt(transport->sentPackets[4].packet);
822 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
823 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249);
Eric Newberry185ab292017-03-28 06:45:39 +0000824
Eric Newberry7b0071e2017-07-03 17:33:31 +0000825 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
826 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 5000);
827 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 5999);
Eric Newberry185ab292017-03-28 06:45:39 +0000828
829 // T+10ms
830 advanceClocks(time::milliseconds(1), 4);
831 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000832 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 5);
833 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000834
835 // T+11ms
836 advanceClocks(time::milliseconds(1), 1);
837
838 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
839
Eric Newberry7b0071e2017-07-03 17:33:31 +0000840 for (lp::Sequence i = 100000; i < 101000; i++) {
841 reliability->m_ackQueue.push(i);
842 }
843
Eric Newberry185ab292017-03-28 06:45:39 +0000844 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000845 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry185ab292017-03-28 06:45:39 +0000846
Eric Newberry7b0071e2017-07-03 17:33:31 +0000847 // given Ack of size 6 and MTU of 1500, 249 Acks/IDLE packet
848 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 10);
849 for (int i = 5; i < 9; i++) {
850 lp::Packet sentPkt(transport->sentPackets[i].packet);
851 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
852 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 249);
853 }
854 sentPkt.wireDecode(transport->sentPackets[9].packet);
855 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
856 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 249);
857
858 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
859 BOOST_CHECK_EQUAL(reliability->m_ackQueue.front(), 100000);
860 BOOST_CHECK_EQUAL(reliability->m_ackQueue.back(), 100999);
Eric Newberry185ab292017-03-28 06:45:39 +0000861 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
862
863 // T+15ms
864 advanceClocks(time::milliseconds(1), 4);
865 BOOST_CHECK(reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000866 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 10);
867 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 1000);
Eric Newberry185ab292017-03-28 06:45:39 +0000868
869 // T+16ms
870 advanceClocks(time::milliseconds(1), 1);
871
Eric Newberry7b0071e2017-07-03 17:33:31 +0000872 // given Ack of size 8 and MTU of 1500, approx 187 Acks/IDLE packet
Eric Newberry185ab292017-03-28 06:45:39 +0000873 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000874 BOOST_REQUIRE_EQUAL(transport->sentPackets.size(), 16);
875 for (int i = 10; i < 15; i++) {
876 lp::Packet sentPkt(transport->sentPackets[i].packet);
877 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
878 BOOST_CHECK_EQUAL(sentPkt.count<lp::AckField>(), 187);
879 }
880 sentPkt.wireDecode(transport->sentPackets[15].packet);
881 BOOST_CHECK(!sentPkt.has<lp::TxSequenceField>());
882 BOOST_CHECK_LE(sentPkt.count<lp::AckField>(), 187);
Eric Newberry185ab292017-03-28 06:45:39 +0000883
884 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000885 reliability->startIdleAckTimer();
Eric Newberry185ab292017-03-28 06:45:39 +0000886
887 // T+21ms
888 advanceClocks(time::milliseconds(1), 5);
889
890 BOOST_CHECK(!reliability->m_isIdleAckTimerRunning);
Eric Newberry7b0071e2017-07-03 17:33:31 +0000891 BOOST_CHECK_EQUAL(transport->sentPackets.size(), 16);
Eric Newberry185ab292017-03-28 06:45:39 +0000892 BOOST_CHECK_EQUAL(reliability->m_ackQueue.size(), 0);
893}
894
Eric Newberry7b0071e2017-07-03 17:33:31 +0000895BOOST_AUTO_TEST_SUITE_END() // Receiver
Eric Newberry185ab292017-03-28 06:45:39 +0000896
Eric Newberry7b0071e2017-07-03 17:33:31 +0000897BOOST_AUTO_TEST_SUITE_END() // TestLpReliability
Eric Newberry185ab292017-03-28 06:45:39 +0000898BOOST_AUTO_TEST_SUITE_END() // Face
899
900} // namespace tests
901} // namespace face
902} // namespace nfd