blob: de4c2066996a851e2146ddc6c1362ffd44586291 [file] [log] [blame]
Junxiao Shi192af1f2015-01-13 23:19:39 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande90015992017-07-11 17:25:48 -05002/*
ashiqopud3ae85d2019-02-17 02:29:55 +00003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi192af1f2015-01-13 23:19:39 -07004 * 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
Ashlesh Gawande90015992017-07-11 17:25:48 -050026#include "fw/strategy.hpp"
Junxiao Shia788e252015-01-28 17:06:25 -070027#include "fw/retx-suppression-fixed.hpp"
Junxiao Shi73b909a2015-02-08 21:31:42 -070028#include "fw/retx-suppression-exponential.hpp"
Junxiao Shi192af1f2015-01-13 23:19:39 -070029
30#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040031#include "tests/daemon/global-io-fixture.hpp"
Junxiao Shi192af1f2015-01-13 23:19:39 -070032#include "tests/daemon/face/dummy-face.hpp"
33
34namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080035namespace fw {
Junxiao Shi192af1f2015-01-13 23:19:39 -070036namespace tests {
37
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080038using namespace nfd::tests;
Junxiao Shi192af1f2015-01-13 23:19:39 -070039
Davide Pesavento97210d52016-10-14 15:45:48 +020040BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, GlobalIoTimeFixture)
Junxiao Shi192af1f2015-01-13 23:19:39 -070042
Junxiao Shia788e252015-01-28 17:06:25 -070043BOOST_AUTO_TEST_CASE(Fixed)
Junxiao Shi192af1f2015-01-13 23:19:39 -070044{
45 Forwarder forwarder;
46 Pit& pit = forwarder.getPit();
Junxiao Shia788e252015-01-28 17:06:25 -070047 static const time::milliseconds MIN_RETX_INTERVAL(200);
48 RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
Junxiao Shi192af1f2015-01-13 23:19:39 -070049
50 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
51 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
52 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
53 forwarder.addFace(face1);
54 forwarder.addFace(face2);
55 forwarder.addFace(face3);
56
57 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
58 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
59
Junxiao Shia788e252015-01-28 17:06:25 -070060 const time::nanoseconds RETRANSMISSION_10P =
61 time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
Junxiao Shi192af1f2015-01-13 23:19:39 -070062
63 // @ time 0
ashiqopud3ae85d2019-02-17 02:29:55 +000064 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050065 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
ashiqopud3ae85d2019-02-17 02:29:55 +000066 pitEntry->insertOrUpdateOutRecord(*face3, 0, *interest);
Junxiao Shi192af1f2015-01-13 23:19:39 -070067
68 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000069 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050070 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
ashiqopud3ae85d2019-02-17 02:29:55 +000071 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050072 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070073
74 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000075 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050076 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070077 // but strategy decides not to forward
78
79 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000080 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050081 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070082 // retransmission suppress shall still give clearance for forwarding
ashiqopud3ae85d2019-02-17 02:29:55 +000083 pitEntry->insertOrUpdateOutRecord(*face3, 0, *interest); // and strategy forwards
Junxiao Shi192af1f2015-01-13 23:19:39 -070084
85 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000086 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050087 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
ashiqopud3ae85d2019-02-17 02:29:55 +000088 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050089 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070090}
91
Junxiao Shi73b909a2015-02-08 21:31:42 -070092BOOST_AUTO_TEST_CASE(Exponential)
93{
94 Forwarder forwarder;
95 Pit& pit = forwarder.getPit();
Davide Pesavento14e71f02019-03-28 17:35:25 -040096 RetxSuppressionExponential rs(10_ms, 3.0, 100_ms);
Junxiao Shi73b909a2015-02-08 21:31:42 -070097
98 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
99 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
100 forwarder.addFace(face1);
101 forwarder.addFace(face2);
102
103 shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
104 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
105
106 // @ 0ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000107 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500108 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
ashiqopud3ae85d2019-02-17 02:29:55 +0000109 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700110 // suppression interval is 10ms, until 10ms
111
Davide Pesavento14e71f02019-03-28 17:35:25 -0400112 this->advanceClocks(5_ms); // @ 5ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000113 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500114 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700115 // suppression interval is 10ms, until 10ms
116
Davide Pesavento14e71f02019-03-28 17:35:25 -0400117 this->advanceClocks(6_ms); // @ 11ms
Junxiao Shi73b909a2015-02-08 21:31:42 -0700118 // note: what happens at *exactly* 10ms does not matter so it's untested,
119 // because in reality network timing won't be exact:
120 // incoming Interest is processed either before or after 10ms point
ashiqopud3ae85d2019-02-17 02:29:55 +0000121 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500122 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000123 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700124 // suppression interval is 30ms, until 41ms
125
Davide Pesavento14e71f02019-03-28 17:35:25 -0400126 this->advanceClocks(25_ms); // @ 36ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000127 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500128 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700129 // suppression interval is 30ms, until 41ms
130
Davide Pesavento14e71f02019-03-28 17:35:25 -0400131 this->advanceClocks(6_ms); // @ 42ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000132 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500133 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700134 // strategy decides not to forward, but suppression interval is increased nevertheless
135 // suppression interval is 90ms, until 101ms
136
Davide Pesavento14e71f02019-03-28 17:35:25 -0400137 this->advanceClocks(58_ms); // @ 100ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000138 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500139 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700140 // suppression interval is 90ms, until 101ms
141
Davide Pesavento14e71f02019-03-28 17:35:25 -0400142 this->advanceClocks(3_ms); // @ 103ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000143 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500144 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000145 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700146 // suppression interval is 100ms, until 203ms
147
Davide Pesavento14e71f02019-03-28 17:35:25 -0400148 this->advanceClocks(99_ms); // @ 202ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000149 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500150 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700151 // suppression interval is 100ms, until 203ms
152
Davide Pesavento14e71f02019-03-28 17:35:25 -0400153 this->advanceClocks(2_ms); // @ 204ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000154 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500155 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000156 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700157 // suppression interval is 100ms, until 304ms
158}
159
Ashlesh Gawande90015992017-07-11 17:25:48 -0500160BOOST_AUTO_TEST_CASE(ExponentialPerUpstream)
161{
162 Forwarder forwarder;
163 Pit& pit = forwarder.getPit();
Davide Pesavento14e71f02019-03-28 17:35:25 -0400164 RetxSuppressionExponential rs(10_ms, 3.0, 100_ms);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500165
166 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
167 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
168 forwarder.addFace(face1);
169 forwarder.addFace(face2);
170
171 shared_ptr<Interest> interest = makeInterest("ndn:/covfefeW6q");
172 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
173
174 // @ 0ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000175 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500176 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::NEW);
177
178 // Simluate forwarding an interest to face2
ashiqopud3ae85d2019-02-17 02:29:55 +0000179 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400180 this->advanceClocks(5_ms); // @ 5ms
Ashlesh Gawande90015992017-07-11 17:25:48 -0500181
ashiqopud3ae85d2019-02-17 02:29:55 +0000182 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500183 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
184
185 // Return NEW since no outRecord for face1
ashiqopud3ae85d2019-02-17 02:29:55 +0000186 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500187 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face1) == RetxSuppressionResult::NEW);
188
Davide Pesavento14e71f02019-03-28 17:35:25 -0400189 this->advanceClocks(6_ms); // @ 11ms
Ashlesh Gawande90015992017-07-11 17:25:48 -0500190
ashiqopud3ae85d2019-02-17 02:29:55 +0000191 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500192 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD);
193 // Assume interest is sent and increment interval
ashiqopud3ae85d2019-02-17 02:29:55 +0000194 rs.incrementIntervalForOutRecord(*pitEntry->getOutRecord(*face2, 0));
Ashlesh Gawande90015992017-07-11 17:25:48 -0500195
ashiqopud3ae85d2019-02-17 02:29:55 +0000196 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500197 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
198}
199
Davide Pesavento97210d52016-10-14 15:45:48 +0200200BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression
201BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700202
203} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800204} // namespace fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700205} // namespace nfd