blob: 3a2cf06e344eb3dd8fd1b7811d15343eb458b2bd [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/*
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -04003 * Copyright (c) 2014-2022, 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{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040045 FaceTable faceTable;
46 Forwarder forwarder(faceTable);
Junxiao Shi192af1f2015-01-13 23:19:39 -070047 Pit& pit = forwarder.getPit();
Junxiao Shia788e252015-01-28 17:06:25 -070048 static const time::milliseconds MIN_RETX_INTERVAL(200);
49 RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
Junxiao Shi192af1f2015-01-13 23:19:39 -070050
51 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
52 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
53 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040054 faceTable.add(face1);
55 faceTable.add(face2);
56 faceTable.add(face3);
Junxiao Shi192af1f2015-01-13 23:19:39 -070057
58 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
59 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
60
Junxiao Shia788e252015-01-28 17:06:25 -070061 const time::nanoseconds RETRANSMISSION_10P =
62 time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
Junxiao Shi192af1f2015-01-13 23:19:39 -070063
64 // @ time 0
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000065 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050066 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000067 pitEntry->insertOrUpdateOutRecord(*face3, *interest);
Junxiao Shi192af1f2015-01-13 23:19:39 -070068
69 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000070 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050071 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000072 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050073 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070074
75 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000076 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050077 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070078 // but strategy decides not to forward
79
80 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000081 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050082 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070083 // retransmission suppress shall still give clearance for forwarding
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000084 pitEntry->insertOrUpdateOutRecord(*face3, *interest); // and strategy forwards
Junxiao Shi192af1f2015-01-13 23:19:39 -070085
86 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000087 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050088 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000089 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050090 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070091}
92
Junxiao Shi73b909a2015-02-08 21:31:42 -070093BOOST_AUTO_TEST_CASE(Exponential)
94{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040095 FaceTable faceTable;
96 Forwarder forwarder(faceTable);
Junxiao Shi73b909a2015-02-08 21:31:42 -070097 Pit& pit = forwarder.getPit();
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040098 RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
Junxiao Shi73b909a2015-02-08 21:31:42 -070099
100 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
101 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400102 faceTable.add(face1);
103 faceTable.add(face2);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700104
105 shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
106 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
107
108 // @ 0ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000109 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500110 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000111 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700112 // suppression interval is 10ms, until 10ms
113
Davide Pesavento14e71f02019-03-28 17:35:25 -0400114 this->advanceClocks(5_ms); // @ 5ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000115 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500116 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700117 // suppression interval is 10ms, until 10ms
118
Davide Pesavento14e71f02019-03-28 17:35:25 -0400119 this->advanceClocks(6_ms); // @ 11ms
Junxiao Shi73b909a2015-02-08 21:31:42 -0700120 // note: what happens at *exactly* 10ms does not matter so it's untested,
121 // because in reality network timing won't be exact:
122 // incoming Interest is processed either before or after 10ms point
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000123 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500124 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000125 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700126 // suppression interval is 30ms, until 41ms
127
Davide Pesavento14e71f02019-03-28 17:35:25 -0400128 this->advanceClocks(25_ms); // @ 36ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000129 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500130 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700131 // suppression interval is 30ms, until 41ms
132
Davide Pesavento14e71f02019-03-28 17:35:25 -0400133 this->advanceClocks(6_ms); // @ 42ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000134 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500135 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700136 // strategy decides not to forward, but suppression interval is increased nevertheless
137 // suppression interval is 90ms, until 101ms
138
Davide Pesavento14e71f02019-03-28 17:35:25 -0400139 this->advanceClocks(58_ms); // @ 100ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000140 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500141 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700142 // suppression interval is 90ms, until 101ms
143
Davide Pesavento14e71f02019-03-28 17:35:25 -0400144 this->advanceClocks(3_ms); // @ 103ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000145 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500146 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000147 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700148 // suppression interval is 100ms, until 203ms
149
Davide Pesavento14e71f02019-03-28 17:35:25 -0400150 this->advanceClocks(99_ms); // @ 202ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000151 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500152 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700153 // suppression interval is 100ms, until 203ms
154
Davide Pesavento14e71f02019-03-28 17:35:25 -0400155 this->advanceClocks(2_ms); // @ 204ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000156 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500157 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000158 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700159 // suppression interval is 100ms, until 304ms
160}
161
Ashlesh Gawande90015992017-07-11 17:25:48 -0500162BOOST_AUTO_TEST_CASE(ExponentialPerUpstream)
163{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400164 FaceTable faceTable;
165 Forwarder forwarder(faceTable);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500166 Pit& pit = forwarder.getPit();
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400167 RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500168
169 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
170 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400171 faceTable.add(face1);
172 faceTable.add(face2);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500173
174 shared_ptr<Interest> interest = makeInterest("ndn:/covfefeW6q");
175 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
176
177 // @ 0ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000178 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500179 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::NEW);
180
181 // Simluate forwarding an interest to face2
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000182 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400183 this->advanceClocks(5_ms); // @ 5ms
Ashlesh Gawande90015992017-07-11 17:25:48 -0500184
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000185 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500186 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
187
188 // Return NEW since no outRecord for face1
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000189 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500190 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face1) == RetxSuppressionResult::NEW);
191
Davide Pesavento14e71f02019-03-28 17:35:25 -0400192 this->advanceClocks(6_ms); // @ 11ms
Ashlesh Gawande90015992017-07-11 17:25:48 -0500193
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000194 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500195 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD);
196 // Assume interest is sent and increment interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000197 rs.incrementIntervalForOutRecord(*pitEntry->getOutRecord(*face2));
Ashlesh Gawande90015992017-07-11 17:25:48 -0500198
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000199 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500200 BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS);
201}
202
Davide Pesavento97210d52016-10-14 15:45:48 +0200203BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression
204BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700205
206} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800207} // namespace fw
Junxiao Shi192af1f2015-01-13 23:19:39 -0700208} // namespace nfd