blob: c96ac67cfb55fa0a070c6201dceadde4f045bf6b [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"
31#include "tests/daemon/face/dummy-face.hpp"
32
33namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace fw {
Junxiao Shi192af1f2015-01-13 23:19:39 -070035namespace tests {
36
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080037using namespace nfd::tests;
Junxiao Shi192af1f2015-01-13 23:19:39 -070038
Davide Pesavento97210d52016-10-14 15:45:48 +020039BOOST_AUTO_TEST_SUITE(Fw)
40BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, UnitTestTimeFixture)
Junxiao Shi192af1f2015-01-13 23:19:39 -070041
Junxiao Shia788e252015-01-28 17:06:25 -070042BOOST_AUTO_TEST_CASE(Fixed)
Junxiao Shi192af1f2015-01-13 23:19:39 -070043{
44 Forwarder forwarder;
45 Pit& pit = forwarder.getPit();
Junxiao Shia788e252015-01-28 17:06:25 -070046 static const time::milliseconds MIN_RETX_INTERVAL(200);
47 RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
Junxiao Shi192af1f2015-01-13 23:19:39 -070048
49 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
50 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
51 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
52 forwarder.addFace(face1);
53 forwarder.addFace(face2);
54 forwarder.addFace(face3);
55
56 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
57 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
58
Junxiao Shia788e252015-01-28 17:06:25 -070059 const time::nanoseconds RETRANSMISSION_10P =
60 time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
Junxiao Shi192af1f2015-01-13 23:19:39 -070061
62 // @ time 0
ashiqopud3ae85d2019-02-17 02:29:55 +000063 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050064 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
ashiqopud3ae85d2019-02-17 02:29:55 +000065 pitEntry->insertOrUpdateOutRecord(*face3, 0, *interest);
Junxiao Shi192af1f2015-01-13 23:19:39 -070066
67 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000068 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050069 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
ashiqopud3ae85d2019-02-17 02:29:55 +000070 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050071 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070072
73 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000074 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050075 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070076 // but strategy decides not to forward
77
78 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000079 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050080 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070081 // retransmission suppress shall still give clearance for forwarding
ashiqopud3ae85d2019-02-17 02:29:55 +000082 pitEntry->insertOrUpdateOutRecord(*face3, 0, *interest); // and strategy forwards
Junxiao Shi192af1f2015-01-13 23:19:39 -070083
84 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
ashiqopud3ae85d2019-02-17 02:29:55 +000085 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050086 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
ashiqopud3ae85d2019-02-17 02:29:55 +000087 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050088 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070089}
90
Junxiao Shi73b909a2015-02-08 21:31:42 -070091BOOST_AUTO_TEST_CASE(Exponential)
92{
93 Forwarder forwarder;
94 Pit& pit = forwarder.getPit();
95 RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100));
96
97 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
98 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
99 forwarder.addFace(face1);
100 forwarder.addFace(face2);
101
102 shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
103 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
104
105 // @ 0ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000106 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500107 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
ashiqopud3ae85d2019-02-17 02:29:55 +0000108 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700109 // suppression interval is 10ms, until 10ms
110
111 this->advanceClocks(time::milliseconds(5)); // @ 5ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000112 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500113 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700114 // suppression interval is 10ms, until 10ms
115
116 this->advanceClocks(time::milliseconds(6)); // @ 11ms
117 // note: what happens at *exactly* 10ms does not matter so it's untested,
118 // because in reality network timing won't be exact:
119 // incoming Interest is processed either before or after 10ms point
ashiqopud3ae85d2019-02-17 02:29:55 +0000120 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500121 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000122 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700123 // suppression interval is 30ms, until 41ms
124
125 this->advanceClocks(time::milliseconds(25)); // @ 36ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000126 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500127 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700128 // suppression interval is 30ms, until 41ms
129
130 this->advanceClocks(time::milliseconds(6)); // @ 42ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000131 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500132 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700133 // strategy decides not to forward, but suppression interval is increased nevertheless
134 // suppression interval is 90ms, until 101ms
135
136 this->advanceClocks(time::milliseconds(58)); // @ 100ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000137 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500138 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700139 // suppression interval is 90ms, until 101ms
140
141 this->advanceClocks(time::milliseconds(3)); // @ 103ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000142 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500143 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000144 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700145 // suppression interval is 100ms, until 203ms
146
147 this->advanceClocks(time::milliseconds(99)); // @ 202ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000148 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500149 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700150 // suppression interval is 100ms, until 203ms
151
152 this->advanceClocks(time::milliseconds(2)); // @ 204ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000153 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500154 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
ashiqopud3ae85d2019-02-17 02:29:55 +0000155 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700156 // suppression interval is 100ms, until 304ms
157}
158
Ashlesh Gawande90015992017-07-11 17:25:48 -0500159BOOST_AUTO_TEST_CASE(ExponentialPerUpstream)
160{
161 Forwarder forwarder;
162 Pit& pit = forwarder.getPit();
163 RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100));
164
165 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
166 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
167 forwarder.addFace(face1);
168 forwarder.addFace(face2);
169
170 shared_ptr<Interest> interest = makeInterest("ndn:/covfefeW6q");
171 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
172
173 // @ 0ms
ashiqopud3ae85d2019-02-17 02:29:55 +0000174 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500175 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::NEW);
176
177 // Simluate forwarding an interest to face2
ashiqopud3ae85d2019-02-17 02:29:55 +0000178 pitEntry->insertOrUpdateOutRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500179 this->advanceClocks(time::milliseconds(5)); // @ 5ms
180
ashiqopud3ae85d2019-02-17 02:29:55 +0000181 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500182 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
183
184 // Return NEW since no outRecord for face1
ashiqopud3ae85d2019-02-17 02:29:55 +0000185 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500186 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face1) == RetxSuppressionResult::NEW);
187
188 this->advanceClocks(time::milliseconds(6)); // @ 11ms
189
ashiqopud3ae85d2019-02-17 02:29:55 +0000190 pitEntry->insertOrUpdateInRecord(*face1, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500191 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD);
192 // Assume interest is sent and increment interval
ashiqopud3ae85d2019-02-17 02:29:55 +0000193 rs.incrementIntervalForOutRecord(*pitEntry->getOutRecord(*face2, 0));
Ashlesh Gawande90015992017-07-11 17:25:48 -0500194
ashiqopud3ae85d2019-02-17 02:29:55 +0000195 pitEntry->insertOrUpdateInRecord(*face2, 0, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500196 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
197}
198
Davide Pesavento97210d52016-10-14 15:45:48 +0200199BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression
200BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700201
202} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800203} // namespace fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700204} // namespace nfd