Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, 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 | |
| 26 | #include "fw/best-route-strategy2.hpp" |
| 27 | #include "strategy-tester.hpp" |
| 28 | |
| 29 | #include "tests/test-common.hpp" |
| 30 | #include "tests/limited-io.hpp" |
| 31 | #include "tests/daemon/face/dummy-face.hpp" |
| 32 | |
| 33 | namespace nfd { |
| 34 | namespace tests { |
| 35 | |
| 36 | BOOST_FIXTURE_TEST_SUITE(FwBestRouteStrategy2, BaseFixture) |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(Forward) |
| 39 | { |
| 40 | LimitedIo limitedIo; |
| 41 | Forwarder forwarder; |
| 42 | typedef StrategyTester<fw::BestRouteStrategy2> BestRouteStrategy2Tester; |
| 43 | BestRouteStrategy2Tester strategy(forwarder); |
| 44 | |
| 45 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 46 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 47 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 48 | shared_ptr<DummyFace> face4 = make_shared<DummyFace>(); |
| 49 | shared_ptr<DummyFace> face5 = make_shared<DummyFace>(); |
| 50 | forwarder.addFace(face1); |
| 51 | forwarder.addFace(face2); |
| 52 | forwarder.addFace(face3); |
| 53 | forwarder.addFace(face4); |
| 54 | forwarder.addFace(face5); |
| 55 | |
| 56 | Fib& fib = forwarder.getFib(); |
| 57 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 58 | fibEntry->addNextHop(face1, 10); |
| 59 | fibEntry->addNextHop(face2, 20); |
| 60 | fibEntry->addNextHop(face3, 30); |
| 61 | |
| 62 | shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA"); |
| 63 | Pit& pit = forwarder.getPit(); |
| 64 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 65 | |
| 66 | const time::nanoseconds RETRANSMISSION60 = time::duration_cast<time::nanoseconds>( |
| 67 | fw::BestRouteStrategy2::MIN_RETRANSMISSION_INTERVAL * 0.6); // 60% |
| 68 | const time::nanoseconds RETRANSMISSION120 = time::duration_cast<time::nanoseconds>( |
| 69 | fw::BestRouteStrategy2::MIN_RETRANSMISSION_INTERVAL * 1.2); // 120% |
| 70 | |
| 71 | pitEntry->insertOrUpdateInRecord(face1, *interest); |
| 72 | strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry); |
| 73 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 74 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face2); |
| 75 | // face1 is downstream so it cannot be used at this time |
| 76 | |
| 77 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION60); |
| 78 | pitEntry->insertOrUpdateInRecord(face4, *interest); |
| 79 | strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry); |
| 80 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 1); |
| 81 | // ignored similar Interest |
| 82 | |
| 83 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION60); |
| 84 | pitEntry->insertOrUpdateInRecord(face4, *interest); |
| 85 | strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry); |
| 86 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 2); |
| 87 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face1); |
| 88 | // accepted retransmission, forward to an unused upstream |
| 89 | |
| 90 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION120); |
| 91 | pitEntry->insertOrUpdateInRecord(face5, *interest); |
| 92 | strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry); |
| 93 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 3); |
| 94 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face3); |
| 95 | // accepted similar Interest from new downstream, forward to an unused upstream |
| 96 | |
| 97 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION120); |
| 98 | pitEntry->insertOrUpdateInRecord(face4, *interest); |
| 99 | strategy.afterReceiveInterest(*face4, *interest, fibEntry, pitEntry); |
| 100 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 4); |
| 101 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face2); |
| 102 | // accepted retransmission, forward to an eligible upstream with earliest OutRecord |
| 103 | |
| 104 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION60); |
| 105 | pitEntry->insertOrUpdateInRecord(face5, *interest); |
| 106 | strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry); |
| 107 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 4); |
| 108 | // ignored retransmission |
| 109 | |
| 110 | fibEntry->removeNextHop(face1); |
| 111 | |
| 112 | limitedIo.run(LimitedIo::UNLIMITED_OPS, RETRANSMISSION60); |
| 113 | pitEntry->insertOrUpdateInRecord(face5, *interest); |
| 114 | strategy.afterReceiveInterest(*face5, *interest, fibEntry, pitEntry); |
| 115 | BOOST_REQUIRE_EQUAL(strategy.m_sendInterestHistory.size(), 5); |
| 116 | BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.back().get<1>(), face3); |
| 117 | // accepted retransmission, forward to an eligible upstream with earliest OutRecord |
| 118 | // face1 cannot be used because it's gone from FIB entry |
| 119 | } |
| 120 | |
| 121 | BOOST_AUTO_TEST_SUITE_END() |
| 122 | |
| 123 | } // namespace tests |
| 124 | } // namespace nfd |