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 | |
| 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 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 39 | BOOST_FIXTURE_TEST_SUITE(FwRetxSuppression, UnitTestTimeFixture) |
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_AUTO_TEST_CASE(Fixed) |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 42 | { |
| 43 | Forwarder forwarder; |
| 44 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 45 | static const time::milliseconds MIN_RETX_INTERVAL(200); |
| 46 | RetxSuppressionFixed rs(MIN_RETX_INTERVAL); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 47 | |
| 48 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 49 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 50 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 51 | forwarder.addFace(face1); |
| 52 | forwarder.addFace(face2); |
| 53 | forwarder.addFace(face3); |
| 54 | |
| 55 | shared_ptr<Interest> interest = makeInterest("ndn:/0JiimvmxK8"); |
| 56 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 57 | |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 58 | const time::nanoseconds RETRANSMISSION_10P = |
| 59 | time::duration_cast<time::nanoseconds>(MIN_RETX_INTERVAL * 0.1); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 60 | |
| 61 | // @ time 0 |
| 62 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 63 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 64 | pitEntry->insertOrUpdateOutRecord(face3, *interest); |
| 65 | |
| 66 | this->advanceClocks(RETRANSMISSION_10P, 5); // @ time 0.5 interval |
| 67 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 69 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 71 | |
| 72 | this->advanceClocks(RETRANSMISSION_10P, 6); // @ time 1.1 interval |
| 73 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 75 | // but strategy decides not to forward |
| 76 | |
| 77 | this->advanceClocks(RETRANSMISSION_10P, 1); // @ time 1.2 interval |
| 78 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 80 | // retransmission suppress shall still give clearance for forwarding |
| 81 | pitEntry->insertOrUpdateOutRecord(face3, *interest); // and strategy forwards |
| 82 | |
| 83 | this->advanceClocks(RETRANSMISSION_10P, 2); // @ time 1.4 interval |
| 84 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 85 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 86 | pitEntry->insertOrUpdateInRecord(face2, *interest); |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(rs.decide(*face2, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 90 | BOOST_AUTO_TEST_CASE(Exponential) |
| 91 | { |
| 92 | Forwarder forwarder; |
| 93 | Pit& pit = forwarder.getPit(); |
| 94 | RetxSuppressionExponential rs(time::milliseconds(10), 3.0, time::milliseconds(100)); |
| 95 | |
| 96 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 97 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 98 | forwarder.addFace(face1); |
| 99 | forwarder.addFace(face2); |
| 100 | |
| 101 | shared_ptr<Interest> interest = makeInterest("ndn:/smuVeQSW6q"); |
| 102 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 103 | |
| 104 | // @ 0ms |
| 105 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 106 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::NEW); |
| 107 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 108 | // suppression interval is 10ms, until 10ms |
| 109 | |
| 110 | this->advanceClocks(time::milliseconds(5)); // @ 5ms |
| 111 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 112 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 113 | // suppression interval is 10ms, until 10ms |
| 114 | |
| 115 | this->advanceClocks(time::milliseconds(6)); // @ 11ms |
| 116 | // note: what happens at *exactly* 10ms does not matter so it's untested, |
| 117 | // because in reality network timing won't be exact: |
| 118 | // incoming Interest is processed either before or after 10ms point |
| 119 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 120 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 121 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 122 | // suppression interval is 30ms, until 41ms |
| 123 | |
| 124 | this->advanceClocks(time::milliseconds(25)); // @ 36ms |
| 125 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 126 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 127 | // suppression interval is 30ms, until 41ms |
| 128 | |
| 129 | this->advanceClocks(time::milliseconds(6)); // @ 42ms |
| 130 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 131 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 132 | // strategy decides not to forward, but suppression interval is increased nevertheless |
| 133 | // suppression interval is 90ms, until 101ms |
| 134 | |
| 135 | this->advanceClocks(time::milliseconds(58)); // @ 100ms |
| 136 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 137 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 138 | // suppression interval is 90ms, until 101ms |
| 139 | |
| 140 | this->advanceClocks(time::milliseconds(3)); // @ 103ms |
| 141 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 142 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 143 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 144 | // suppression interval is 100ms, until 203ms |
| 145 | |
| 146 | this->advanceClocks(time::milliseconds(99)); // @ 202ms |
| 147 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 148 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::SUPPRESS); |
| 149 | // suppression interval is 100ms, until 203ms |
| 150 | |
| 151 | this->advanceClocks(time::milliseconds(2)); // @ 204ms |
| 152 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 153 | BOOST_CHECK_EQUAL(rs.decide(*face1, *interest, *pitEntry), RetxSuppression::FORWARD); |
| 154 | pitEntry->insertOrUpdateOutRecord(face2, *interest); |
| 155 | // suppression interval is 100ms, until 304ms |
| 156 | } |
| 157 | |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 158 | BOOST_AUTO_TEST_SUITE_END() |
| 159 | |
| 160 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 161 | } // namespace fw |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 162 | } // namespace nfd |