Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 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 | |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 26 | #include "fw/strategy.hpp" |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 27 | #include "fw/retx-suppression-fixed.hpp" |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 28 | #include "fw/retx-suppression-exponential.hpp" |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 29 | |
| 30 | #include "tests/test-common.hpp" |
| 31 | #include "tests/daemon/face/dummy-face.hpp" |
| 32 | |
| 33 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 34 | namespace fw { |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 37 | using namespace nfd::tests; |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Fw) |
| 40 | BOOST_FIXTURE_TEST_SUITE(TestRetxSuppression, UnitTestTimeFixture) |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 42 | BOOST_AUTO_TEST_CASE(Fixed) |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 43 | { |
| 44 | Forwarder forwarder; |
| 45 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 46 | static const time::milliseconds MIN_RETX_INTERVAL(200); |
| 47 | RetxSuppressionFixed rs(MIN_RETX_INTERVAL); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 48 | |
| 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 Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 59 | const time::nanoseconds RETRANSMISSION_10P = |
| 60 | time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 61 | |
| 62 | // @ time 0 |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 63 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 64 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 65 | pitEntry->insertOrUpdateOutRecord(*face3, *interest); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 66 | |
| 67 | this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 68 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 69 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 70 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 71 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 72 | |
| 73 | this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 74 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 75 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 76 | // but strategy decides not to forward |
| 77 | |
| 78 | this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 79 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 80 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 81 | // retransmission suppress shall still give clearance for forwarding |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 82 | pitEntry->insertOrUpdateOutRecord(*face3, *interest); // and strategy forwards |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 83 | |
| 84 | this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 85 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 86 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 87 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 88 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 91 | BOOST_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 |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 106 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 107 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::NEW); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 108 | pitEntry->insertOrUpdateOutRecord(*face2, *interest); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 109 | // suppression interval is 10ms, until 10ms |
| 110 | |
| 111 | this->advanceClocks(time::milliseconds(5)); // @ 5ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 112 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 113 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 114 | // 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 |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 120 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 121 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 122 | pitEntry->insertOrUpdateOutRecord(*face2, *interest); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 123 | // suppression interval is 30ms, until 41ms |
| 124 | |
| 125 | this->advanceClocks(time::milliseconds(25)); // @ 36ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 126 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 127 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 128 | // suppression interval is 30ms, until 41ms |
| 129 | |
| 130 | this->advanceClocks(time::milliseconds(6)); // @ 42ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 131 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 132 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 133 | // 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 |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 137 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 138 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 139 | // suppression interval is 90ms, until 101ms |
| 140 | |
| 141 | this->advanceClocks(time::milliseconds(3)); // @ 103ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 142 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 143 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 144 | pitEntry->insertOrUpdateOutRecord(*face2, *interest); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 145 | // suppression interval is 100ms, until 203ms |
| 146 | |
| 147 | this->advanceClocks(time::milliseconds(99)); // @ 202ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 148 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 149 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::SUPPRESS); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 150 | // suppression interval is 100ms, until 203ms |
| 151 | |
| 152 | this->advanceClocks(time::milliseconds(2)); // @ 204ms |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 153 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 154 | BOOST_CHECK(rs.decidePerPitEntry(*pitEntry) == RetxSuppressionResult::FORWARD); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 155 | pitEntry->insertOrUpdateOutRecord(*face2, *interest); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 156 | // suppression interval is 100ms, until 304ms |
| 157 | } |
| 158 | |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 159 | BOOST_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 |
| 174 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 175 | BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::NEW); |
| 176 | |
| 177 | // Simluate forwarding an interest to face2 |
| 178 | pitEntry->insertOrUpdateOutRecord(*face2, *interest); |
| 179 | this->advanceClocks(time::milliseconds(5)); // @ 5ms |
| 180 | |
| 181 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 182 | BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS); |
| 183 | |
| 184 | // Return NEW since no outRecord for face1 |
| 185 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
| 186 | BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face1) == RetxSuppressionResult::NEW); |
| 187 | |
| 188 | this->advanceClocks(time::milliseconds(6)); // @ 11ms |
| 189 | |
| 190 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
| 191 | BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::FORWARD); |
| 192 | // Assume interest is sent and increment interval |
| 193 | rs.incrementIntervalForOutRecord(*pitEntry->getOutRecord(*face2)); |
| 194 | |
| 195 | pitEntry->insertOrUpdateInRecord(*face2, *interest); |
| 196 | BOOST_CHECK(rs.decidePerUpstream(*pitEntry, *face2) == RetxSuppressionResult::SUPPRESS); |
| 197 | } |
| 198 | |
Davide Pesavento | 97210d5 | 2016-10-14 15:45:48 +0200 | [diff] [blame] | 199 | BOOST_AUTO_TEST_SUITE_END() // TestRetxSuppression |
| 200 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 201 | |
| 202 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 203 | } // namespace fw |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 204 | } // namespace nfd |