Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 26 | #include "fw/retx-suppression.hpp" |
| 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 | #include "strategy-tester.hpp" |
| 30 | |
| 31 | #include "tests/test-common.hpp" |
| 32 | #include "tests/daemon/face/dummy-face.hpp" |
| 33 | |
| 34 | namespace nfd { |
| 35 | namespace tests { |
| 36 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 37 | using fw::RetxSuppression; |
| 38 | using fw::RetxSuppressionFixed; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 39 | using fw::RetxSuppressionExponential; |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 41 | BOOST_FIXTURE_TEST_SUITE(FwRetxSuppression, UnitTestTimeFixture) |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 42 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 43 | BOOST_AUTO_TEST_CASE(Fixed) |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 44 | { |
| 45 | Forwarder forwarder; |
| 46 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 47 | static const time::milliseconds MIN_RETX_INTERVAL(200); |
| 48 | RetxSuppressionFixed rs(MIN_RETX_INTERVAL); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 49 | |
| 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 Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 60 | const time::nanoseconds RETRANSMISSION_10P = |
| 61 | time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 62 | |
| 63 | // @ time 0 |
| 64 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 66 | pitEntry->insertOrUpdateOutRecord(face3, *interest); |
| 67 | |
| 68 | this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval |
| 69 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 71 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 73 | |
| 74 | this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval |
| 75 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 77 | // but strategy decides not to forward |
| 78 | |
| 79 | this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval |
| 80 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 82 | // retransmission suppress shall still give clearance for forwarding |
| 83 | pitEntry->insertOrUpdateOutRecord(face3, *interest); // and strategy forwards |
| 84 | |
| 85 | this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval |
| 86 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 88 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(Exponential) |
| 93 | { |
| 94 | Forwarder forwarder; |
| 95 | Pit& pit = forwarder.getPit(); |
| 96 | RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100)); |
| 97 | |
| 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 |
| 107 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 108 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); |
| 109 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 110 | // suppression interval is 10ms, until 10ms |
| 111 | |
| 112 | this->advanceClocks(time::milliseconds(5)); // @ 5ms |
| 113 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 114 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 115 | // suppression interval is 10ms, until 10ms |
| 116 | |
| 117 | this->advanceClocks(time::milliseconds(6)); // @ 11ms |
| 118 | // 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 |
| 121 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 122 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 123 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 124 | // suppression interval is 30ms, until 41ms |
| 125 | |
| 126 | this->advanceClocks(time::milliseconds(25)); // @ 36ms |
| 127 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 128 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 129 | // suppression interval is 30ms, until 41ms |
| 130 | |
| 131 | this->advanceClocks(time::milliseconds(6)); // @ 42ms |
| 132 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 133 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 134 | // strategy decides not to forward, but suppression interval is increased nevertheless |
| 135 | // suppression interval is 90ms, until 101ms |
| 136 | |
| 137 | this->advanceClocks(time::milliseconds(58)); // @ 100ms |
| 138 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 139 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 140 | // suppression interval is 90ms, until 101ms |
| 141 | |
| 142 | this->advanceClocks(time::milliseconds(3)); // @ 103ms |
| 143 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 144 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 145 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 146 | // suppression interval is 100ms, until 203ms |
| 147 | |
| 148 | this->advanceClocks(time::milliseconds(99)); // @ 202ms |
| 149 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 150 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 151 | // suppression interval is 100ms, until 203ms |
| 152 | |
| 153 | this->advanceClocks(time::milliseconds(2)); // @ 204ms |
| 154 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 155 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 156 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 157 | // suppression interval is 100ms, until 304ms |
| 158 | } |
| 159 | |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 160 | BOOST_AUTO_TEST_SUITE_END() |
| 161 | |
| 162 | } // namespace tests |
| 163 | } // namespace nfd |