Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -0700 | [diff] [blame] | 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. |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 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 | |
| 26 | #include "fw/best-route-strategy2.hpp" |
| 27 | #include "strategy-tester.hpp" |
| 28 | |
| 29 | #include "tests/test-common.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 30 | #include "tests/daemon/face/dummy-face.hpp" |
| 31 | |
| 32 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 33 | namespace fw { |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 36 | using namespace nfd::tests; |
| 37 | |
Junxiao Shi | 584a569 | 2014-12-13 21:55:28 -0700 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(FwBestRouteStrategy2, UnitTestTimeFixture) |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_CASE(Forward) |
| 41 | { |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 42 | Forwarder forwarder; |
| 43 | typedef StrategyTester<fw::BestRouteStrategy2> BestRouteStrategy2Tester; |
| 44 | BestRouteStrategy2Tester strategy(forwarder); |
| 45 | |
| 46 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 47 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 48 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 49 | shared_ptr<DummyFace> face4 = make_shared<DummyFace>(); |
| 50 | shared_ptr<DummyFace> face5 = make_shared<DummyFace>(); |
| 51 | forwarder.addFace(face1); |
| 52 | forwarder.addFace(face2); |
| 53 | forwarder.addFace(face3); |
| 54 | forwarder.addFace(face4); |
| 55 | forwarder.addFace(face5); |
| 56 | |
| 57 | Fib& fib = forwarder.getFib(); |
| 58 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 59 | fibEntry->addNextHop(face1, 10); |
| 60 | fibEntry->addNextHop(face2, 20); |
| 61 | fibEntry->addNextHop(face3, 30); |
| 62 | |
| 63 | shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA"); |
| 64 | Pit& pit = forwarder.getPit(); |
| 65 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 66 | |
Junxiao Shi | 584a569 | 2014-12-13 21:55:28 -0700 | [diff] [blame] | 67 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 68 | fw::RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL * 0.1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 70 | // first Interest goes to nexthop with lowest FIB cost, |
| 71 | // however face1 is downstream so it cannot be used |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 72 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 73 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 74 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 75 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face2); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 77 | // downstream retransmits frequently, but the strategy should not send Interests |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 78 | // more often than DEFAULT_MIN_RETX_INTERVAL |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 79 | scheduler::EventId retxFrom4Evt; |
| 80 | size_t nSentLast = strategy.m_sendInterestHistory.size(); |
| 81 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Junxiao Shi | 913806d | 2014-11-14 11:43:52 -0700 | [diff] [blame] | 82 | function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
| 83 | periodicalRetxFrom4 = [&] { |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 84 | pitEntry->insertOrUpdateInRecord(face4, *interest); |
| 85 | strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 87 | size_t nSent = strategy.m_sendInterestHistory.size(); |
| 88 | if (nSent > nSentLast) { |
| 89 | BOOST_CHECK_EQUAL(nSent - nSentLast, 1); |
| 90 | time::steady_clock::TimePoint timeSent = time::steady_clock::now(); |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 91 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 92 | nSentLast = nSent; |
| 93 | timeSentLast = timeSent; |
| 94 | } |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 95 | |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 96 | retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 97 | }; |
| 98 | periodicalRetxFrom4(); |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 99 | this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 16); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 100 | scheduler::cancel(retxFrom4Evt); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 101 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 102 | // nexthops for accepted retransmissions: follow FIB cost, |
| 103 | // later forward to an eligible upstream with earliest OutRecord |
| 104 | BOOST_REQUIRE_GE(strategy.m_sendInterestHistory.size(), 6); |
| 105 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[1].get<1>(), face1); |
| 106 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[2].get<1>(), face3); |
| 107 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[3].get<1>(), face2); |
| 108 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[4].get<1>(), face1); |
| 109 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory[5].get<1>(), face3); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 110 | |
| 111 | fibEntry->removeNextHop(face1); |
| 112 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 113 | strategy.m_sendInterestHistory.clear(); |
| 114 | for (int i = 0; i < 3; ++i) { |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 115 | this->advanceClocks(TICK, fw::RetxSuppressionExponential::DEFAULT_MAX_INTERVAL * 2); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 116 | pitEntry->insertOrUpdateInRecord(face5, *interest); |
| 117 | strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry); |
| 118 | } |
| 119 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 3); |
| 120 | BOOST_CHECK_NE(strategy.m_sendInterestHistory[0].get<1>(), face1); |
| 121 | BOOST_CHECK_NE(strategy.m_sendInterestHistory[1].get<1>(), face1); |
| 122 | BOOST_CHECK_NE(strategy.m_sendInterestHistory[2].get<1>(), face1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 123 | // face1 cannot be used because it's gone from FIB entry |
| 124 | } |
| 125 | |
| 126 | BOOST_AUTO_TEST_SUITE_END() |
| 127 | |
| 128 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 129 | } // namespace fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 130 | } // namespace nfd |