blob: 98ee12c125ab54696923e6dcee40834c169120cf [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/*
Davide Pesaventob124b8e2024-02-16 16:54:26 -05003 * Copyright (c) 2014-2024, 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
Junxiao Shia788e252015-01-28 17:06:25 -070026#include "fw/retx-suppression-fixed.hpp"
Junxiao Shi73b909a2015-02-08 21:31:42 -070027#include "fw/retx-suppression-exponential.hpp"
Junxiao Shi192af1f2015-01-13 23:19:39 -070028
29#include "tests/test-common.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/daemon/global-io-fixture.hpp"
Junxiao Shi192af1f2015-01-13 23:19:39 -070031#include "tests/daemon/face/dummy-face.hpp"
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::tests {
Junxiao Shi192af1f2015-01-13 23:19:39 -070034
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035using namespace nfd::fw;
Junxiao Shi192af1f2015-01-13 23:19:39 -070036
Davide Pesavento97210d52016-10-14 15:45:48 +020037BOOST_AUTO_TEST_SUITE(Fw)
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, GlobalIoTimeFixture)
Junxiao Shi192af1f2015-01-13 23:19:39 -070039
Junxiao Shia788e252015-01-28 17:06:25 -070040BOOST_AUTO_TEST_CASE(Fixed)
Junxiao Shi192af1f2015-01-13 23:19:39 -070041{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040042 FaceTable faceTable;
43 Forwarder forwarder(faceTable);
Junxiao Shi192af1f2015-01-13 23:19:39 -070044 Pit& pit = forwarder.getPit();
Junxiao Shia788e252015-01-28 17:06:25 -070045 static const time::milliseconds MIN_RETX_INTERVAL(200);
46 RetxSuppressionFixed rs(MIN_RETX_INTERVAL);
Junxiao Shi192af1f2015-01-13 23:19:39 -070047
48 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
49 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
50 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040051 faceTable.add(face1);
52 faceTable.add(face2);
53 faceTable.add(face3);
Junxiao Shi192af1f2015-01-13 23:19:39 -070054
55 shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8");
56 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
57
Junxiao Shia788e252015-01-28 17:06:25 -070058 const time::nanoseconds RETRANSMISSION_10P =
59 time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1);
Junxiao Shi192af1f2015-01-13 23:19:39 -070060
61 // @ time 0
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000062 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050063 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000064 pitEntry->insertOrUpdateOutRecord(*face3, *interest);
Junxiao Shi192af1f2015-01-13 23:19:39 -070065
66 this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000067 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050068 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000069 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050070 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070071
72 this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000073 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050074 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070075 // but strategy decides not to forward
76
77 this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000078 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050079 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Junxiao Shi192af1f2015-01-13 23:19:39 -070080 // retransmission suppress shall still give clearance for forwarding
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000081 pitEntry->insertOrUpdateOutRecord(*face3, *interest); // and strategy forwards
Junxiao Shi192af1f2015-01-13 23:19:39 -070082
83 this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000084 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050085 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000086 pitEntry->insertOrUpdateInRecord(*face2, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -050087 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS);
Junxiao Shi192af1f2015-01-13 23:19:39 -070088}
89
Junxiao Shi73b909a2015-02-08 21:31:42 -070090BOOST_AUTO_TEST_CASE(Exponential)
91{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040092 FaceTable faceTable;
93 Forwarder forwarder(faceTable);
Junxiao Shi73b909a2015-02-08 21:31:42 -070094 Pit& pit = forwarder.getPit();
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040095 RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
Junxiao Shi73b909a2015-02-08 21:31:42 -070096
97 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
98 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040099 faceTable.add(face1);
100 faceTable.add(face2);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700101
102 shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q");
103 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
104
105 // @ 0ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000106 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500107 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000108 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700109 // suppression interval is 10ms, until 10ms
110
Davide Pesavento14e71f02019-03-28 17:35:25 -0400111 this->advanceClocks(5_ms); // @ 5ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000112 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400116 this->advanceClocks(6_ms); // @ 11ms
Junxiao Shi73b909a2015-02-08 21:31:42 -0700117 // 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
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000120 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500121 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000122 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700123 // suppression interval is 30ms, until 41ms
124
Davide Pesavento14e71f02019-03-28 17:35:25 -0400125 this->advanceClocks(25_ms); // @ 36ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000126 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400130 this->advanceClocks(6_ms); // @ 42ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000131 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400136 this->advanceClocks(58_ms); // @ 100ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000137 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400141 this->advanceClocks(3_ms); // @ 103ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000142 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500143 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000144 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Junxiao Shi73b909a2015-02-08 21:31:42 -0700145 // suppression interval is 100ms, until 203ms
146
Davide Pesavento14e71f02019-03-28 17:35:25 -0400147 this->advanceClocks(99_ms); // @ 202ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000148 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesavento14e71f02019-03-28 17:35:25 -0400152 this->advanceClocks(2_ms); // @ 204ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000153 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500154 BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000155 pitEntry->insertOrUpdateOutRecord(*face2, *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{
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400161 FaceTable faceTable;
162 Forwarder forwarder(faceTable);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500163 Pit& pit = forwarder.getPit();
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400164 RetxSuppressionExponential rs(10_ms, 100_ms, 3.0);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500165
166 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
167 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
Davide Pesaventoa4abfb02019-10-06 16:02:56 -0400168 faceTable.add(face1);
169 faceTable.add(face2);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500170
171 shared_ptr<Interest> interest = makeInterest("ndn:/covfefeW6q");
172 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
173
174 // @ 0ms
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000175 pitEntry->insertOrUpdateInRecord(*face1, *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
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000179 pitEntry->insertOrUpdateOutRecord(*face2, *interest);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400180 this->advanceClocks(5_ms); // @ 5ms
Ashlesh Gawande90015992017-07-11 17:25:48 -0500181
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000182 pitEntry->insertOrUpdateInRecord(*face1, *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
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000186 pitEntry->insertOrUpdateInRecord(*face2, *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
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000191 pitEntry->insertOrUpdateInRecord(*face1, *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
Davide Pesaventob124b8e2024-02-16 16:54:26 -0500194 rs.incrementIntervalForOutRecord(*pitEntry->findOutRecord(*face2));
Ashlesh Gawande90015992017-07-11 17:25:48 -0500195
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000196 pitEntry->insertOrUpdateInRecord(*face2, *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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400203} // namespace nfd::tests