blob: 5066cca0080c62b363d12dbe0a7eb281edf1b61d [file] [log] [blame]
Junxiao Shi986b8492014-08-20 12:07:14 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento87fc0f82018-04-11 23:43:51 -04002/*
Davide Pesavento7922d122021-03-05 22:41:23 -05003 * Copyright (c) 2014-2021, 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
Davide Pesavento7922d122021-03-05 22:41:23 -050026#include "fw/best-route-strategy.hpp"
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040027#include "common/global.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070028
29#include "tests/test-common.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070030#include "tests/daemon/face/dummy-face.hpp"
Junxiao Shi5e5e4452015-09-24 16:56:52 -070031#include "strategy-tester.hpp"
Junxiao Shi986b8492014-08-20 12:07:14 -070032
33namespace nfd {
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -080034namespace fw {
Junxiao Shi986b8492014-08-20 12:07:14 -070035namespace tests {
36
Davide Pesavento7922d122021-03-05 22:41:23 -050037using BestRouteStrategyTester = StrategyTester<BestRouteStrategy>;
38NFD_REGISTER_STRATEGY(BestRouteStrategyTester);
Junxiao Shi890afe92016-12-15 14:34:34 +000039
Junxiao Shi5e5e4452015-09-24 16:56:52 -070040BOOST_AUTO_TEST_SUITE(Fw)
41
Davide Pesavento7922d122021-03-05 22:41:23 -050042class BestRouteStrategyFixture : public GlobalIoTimeFixture
Junxiao Shi5e5e4452015-09-24 16:56:52 -070043{
44protected:
Davide Pesavento7922d122021-03-05 22:41:23 -050045 BestRouteStrategyFixture()
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040046 : face1(make_shared<DummyFace>())
Junxiao Shi5e5e4452015-09-24 16:56:52 -070047 , face2(make_shared<DummyFace>())
48 , face3(make_shared<DummyFace>())
49 , face4(make_shared<DummyFace>())
50 , face5(make_shared<DummyFace>())
51 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040052 faceTable.add(face1);
53 faceTable.add(face2);
54 faceTable.add(face3);
55 faceTable.add(face4);
56 faceTable.add(face5);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070057 }
58
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040059protected:
60 FaceTable faceTable;
61 Forwarder forwarder{faceTable};
Davide Pesavento7922d122021-03-05 22:41:23 -050062 BestRouteStrategyTester strategy{forwarder};
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040063 Fib& fib{forwarder.getFib()};
64 Pit& pit{forwarder.getPit()};
Junxiao Shi5e5e4452015-09-24 16:56:52 -070065
66 shared_ptr<DummyFace> face1;
67 shared_ptr<DummyFace> face2;
68 shared_ptr<DummyFace> face3;
69 shared_ptr<DummyFace> face4;
70 shared_ptr<DummyFace> face5;
71};
72
Davide Pesavento7922d122021-03-05 22:41:23 -050073BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy, BestRouteStrategyFixture)
Junxiao Shi986b8492014-08-20 12:07:14 -070074
75BOOST_AUTO_TEST_CASE(Forward)
76{
Junxiao Shia6de4292016-07-12 02:08:10 +000077 fib::Entry& fibEntry = *fib.insert(Name()).first;
Ju Pand8315bf2019-07-31 06:59:07 +000078 fib.addOrUpdateNextHop(fibEntry, *face1, 10);
79 fib.addOrUpdateNextHop(fibEntry, *face2, 20);
80 fib.addOrUpdateNextHop(fibEntry, *face3, 30);
Junxiao Shi986b8492014-08-20 12:07:14 -070081
82 shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA");
Junxiao Shi986b8492014-08-20 12:07:14 -070083 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
84
Davide Pesavento7922d122021-03-05 22:41:23 -050085 const auto TICK = time::duration_cast<time::nanoseconds>(
86 BestRouteStrategy::RETX_SUPPRESSION_INITIAL * 0.1);
Junxiao Shi986b8492014-08-20 12:07:14 -070087
Junxiao Shi1f30aac2014-11-04 18:45:56 -070088 // first Interest goes to nexthop with lowest FIB cost,
89 // however face1 is downstream so it cannot be used
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000090 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Davide Pesavento0498ce82021-06-14 02:02:21 -040091 strategy.afterReceiveInterest(*interest, FaceEndpoint(*face1, 0), pitEntry);
Junxiao Shi5e5e4452015-09-24 16:56:52 -070092 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1);
93 BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -070094
Junxiao Shi1f30aac2014-11-04 18:45:56 -070095 // downstream retransmits frequently, but the strategy should not send Interests
Junxiao Shia788e252015-01-28 17:06:25 -070096 // more often than DEFAULT_MIN_RETX_INTERVAL
Junxiao Shi1f30aac2014-11-04 18:45:56 -070097 scheduler::EventId retxFrom4Evt;
Junxiao Shi5e5e4452015-09-24 16:56:52 -070098 size_t nSentLast = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -070099 time::steady_clock::TimePoint timeSentLast = time::steady_clock::now();
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400100 std::function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself
Junxiao Shi913806d2014-11-14 11:43:52 -0700101 periodicalRetxFrom4 = [&] {
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000102 pitEntry->insertOrUpdateInRecord(*face4, *interest);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400103 strategy.afterReceiveInterest(*interest, FaceEndpoint(*face4, 0), pitEntry);
Junxiao Shi986b8492014-08-20 12:07:14 -0700104
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700105 size_t nSent = strategy.sendInterestHistory.size();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700106 if (nSent > nSentLast) {
107 BOOST_CHECK_EQUAL(nSent - nSentLast, 1);
Davide Pesavento3dade002019-03-19 11:29:56 -0600108 auto timeSent = time::steady_clock::now();
Junxiao Shi684fa0f2015-02-23 21:39:57 -0700109 BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700110 nSentLast = nSent;
111 timeSentLast = timeSent;
112 }
Junxiao Shi986b8492014-08-20 12:07:14 -0700113
Davide Pesavento3dade002019-03-19 11:29:56 -0600114 retxFrom4Evt = getScheduler().schedule(TICK * 5, periodicalRetxFrom4);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700115 };
116 periodicalRetxFrom4();
Davide Pesavento7922d122021-03-05 22:41:23 -0500117 this->advanceClocks(TICK, BestRouteStrategy::RETX_SUPPRESSION_MAX * 16);
Davide Pesavento3dade002019-03-19 11:29:56 -0600118 retxFrom4Evt.cancel();
Junxiao Shi986b8492014-08-20 12:07:14 -0700119
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700120 // nexthops for accepted retransmissions: follow FIB cost,
Junxiao Shi4846f372016-04-05 13:39:30 -0700121 // later forward to an eligible upstream with earliest out-record
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700122 BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6);
123 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId());
124 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId());
125 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId());
126 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId());
127 BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700128
Ju Pand8315bf2019-07-31 06:59:07 +0000129 fib.removeNextHop(fibEntry, *face1);
Junxiao Shi986b8492014-08-20 12:07:14 -0700130
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700131 strategy.sendInterestHistory.clear();
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700132 for (int i = 0; i < 3; ++i) {
Davide Pesavento7922d122021-03-05 22:41:23 -0500133 this->advanceClocks(TICK, BestRouteStrategy::RETX_SUPPRESSION_MAX * 2);
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000134 pitEntry->insertOrUpdateInRecord(*face5, *interest);
Davide Pesavento0498ce82021-06-14 02:02:21 -0400135 strategy.afterReceiveInterest(*interest, FaceEndpoint(*face5, 0), pitEntry);
Junxiao Shi1f30aac2014-11-04 18:45:56 -0700136 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700137 BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3);
138 BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId());
139 BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId());
140 BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId());
Junxiao Shi986b8492014-08-20 12:07:14 -0700141 // face1 cannot be used because it's gone from FIB entry
142}
143
Davide Pesavento7922d122021-03-05 22:41:23 -0500144BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700145BOOST_AUTO_TEST_SUITE_END() // Fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700146
147} // namespace tests
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -0800148} // namespace fw
Junxiao Shi986b8492014-08-20 12:07:14 -0700149} // namespace nfd