blob: 3ebe7f1838f2b7c3145023412382fe96a36aaaf5 [file] [log] [blame]
Junxiao Shi986b8492014-08-20 12:07:14 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi99540072017-01-27 19:57:33 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi192af1f2015-01-13 23:19:39 -07004 * 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 Shi986b8492014-08-20 12:07:14 -070010 *
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"
Junxiao Shi986b8492014-08-20 12:07:14 -070027
28#include "tests/test-common.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070029#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi5e5e4452015-09-24 16:56:52 -070030#include "strategy-tester.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070031
32namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080033namespace fw {
Junxiao Shi986b8492014-08-20 12:07:14 -070034namespace tests {
35
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080036using namespace nfd::tests;
37
Junxiao Shi890afe92016-12-15 14:34:34 +000038typedef StrategyTester<BestRouteStrategy2> BestRouteStrategy2Tester;
39NFD_REGISTER_STRATEGY(BestRouteStrategy2Tester);
40
Junxiao Shi5e5e4452015-09-24 16:56:52 -070041BOOST_AUTO_TEST_SUITE(Fw)
42
43class BestRouteStrategy2Fixture : public UnitTestTimeFixture
44{
45protected:
46 BestRouteStrategy2Fixture()
47 : strategy(forwarder)
48 , fib(forwarder.getFib())
49 , pit(forwarder.getPit())
50 , face1(make_shared<DummyFace>())
51 , face2(make_shared<DummyFace>())
52 , face3(make_shared<DummyFace>())
53 , face4(make_shared<DummyFace>())
54 , face5(make_shared<DummyFace>())
55 {
56 forwarder.addFace(face1);
57 forwarder.addFace(face2);
58 forwarder.addFace(face3);
59 forwarder.addFace(face4);
60 forwarder.addFace(face5);
61 }
62
63public:
64 Forwarder forwarder;
Junxiao Shi890afe92016-12-15 14:34:34 +000065 BestRouteStrategy2Tester strategy;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070066 Fib& fib;
67 Pit& pit;
68
69 shared_ptr<DummyFace> face1;
70 shared_ptr<DummyFace> face2;
71 shared_ptr<DummyFace> face3;
72 shared_ptr<DummyFace> face4;
73 shared_ptr<DummyFace> face5;
74};
75
76BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture)
Junxiao Shi986b8492014-08-20 12:07:14 -070077
78BOOST_AUTO_TEST_CASE(Forward)
79{
Junxiao Shia6de4292016-07-12 02:08:10 +000080 fib::Entry& fibEntry = *fib.insert(Name()).first;
81 fibEntry.addNextHop(*face1, 10);
82 fibEntry.addNextHop(*face2, 20);
83 fibEntry.addNextHop(*face3, 30);
Junxiao Shi986b8492014-08-20 12:07:14 -070084
85 shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
Junxiao Shi986b8492014-08-20 12:07:14 -070086 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
87
Junxiao Shi584a5692014-12-13 21:55:28 -070088 const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>(
Junxiao Shi52e85402015-11-11 06:06:58 -070089 BestRouteStrategy2::RETX_SUPPRESSION_INITIAL * 0.1);
Junxiao Shi986b8492014-08-20 12:07:14 -070090
Junxiao Shi1f30aac2014-11-04 18:45:56 -070091 // first Interest goes to nexthop with lowest FIB cost,
92 // however face1 is downstream so it cannot be used
Junxiao Shi9cff7792016-08-01 21:45:11 +000093 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +000094 strategy.afterReceiveInterest(*face1, *interest, pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070095 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
96 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -070097
Junxiao Shi1f30aac2014-11-04 18:45:56 -070098 // downstream retransmits frequently, but the strategy should not send Interests
Junxiao Shia788e252015-01-28 17:06:25 -070099 // more often than DEFAULT_MIN_RETX_INTERVAL
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700100 scheduler::EventId retxFrom4Evt;
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700101 size_t nSentLast = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700102 time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
Junxiao Shi913806d2014-11-14 11:43:52 -0700103 function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
104 periodicalRetxFrom4 = [&] {
Junxiao Shi9cff7792016-08-01 21:45:11 +0000105 pitEntry->insertOrUpdateInRecord(*face4, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +0000106 strategy.afterReceiveInterest(*face4, *interest, pitEntry);
Junxiao Shi986b8492014-08-20 12:07:14 -0700107
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700108 size_t nSent = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700109 if (nSent > nSentLast) {
110 BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
111 time::steady_clock::TimePoint timeSent = time::steady_clock::now();
Junxiao Shi684fa0f2015-02-23 21:39:57 -0700112 BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700113 nSentLast = nSent;
114 timeSentLast = timeSent;
115 }
Junxiao Shi986b8492014-08-20 12:07:14 -0700116
Junxiao Shi684fa0f2015-02-23 21:39:57 -0700117 retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700118 };
119 periodicalRetxFrom4();
Junxiao Shi52e85402015-11-11 06:06:58 -0700120 this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 16);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700121 scheduler::cancel(retxFrom4Evt);
Junxiao Shi986b8492014-08-20 12:07:14 -0700122
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700123 // nexthops for accepted retransmissions: follow FIB cost,
Junxiao Shi4846f372016-04-05 13:39:30 -0700124 // later forward to an eligible upstream with earliest out-record
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700125 BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6);
126 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId());
127 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId());
128 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId());
129 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
130 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700131
Junxiao Shia6de4292016-07-12 02:08:10 +0000132 fibEntry.removeNextHop(*face1);
Junxiao Shi986b8492014-08-20 12:07:14 -0700133
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700134 strategy.sendInterestHistory.clear();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700135 for (int i = 0; i < 3; ++i) {
Junxiao Shi52e85402015-11-11 06:06:58 -0700136 this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 2);
Junxiao Shi9cff7792016-08-01 21:45:11 +0000137 pitEntry->insertOrUpdateInRecord(*face5, *interest);
Junxiao Shi8d843142016-07-11 22:42:42 +0000138 strategy.afterReceiveInterest(*face5, *interest, pitEntry);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700139 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700140 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3);
141 BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId());
142 BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId());
143 BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700144 // face1 cannot be used because it's gone from FIB entry
145}
146
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700147BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2
148BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700149
150} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800151} // namespace fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700152} // namespace nfd