blob: ae34b036118df92368b3b2561a675a07c274c505 [file] [log] [blame]
Klaus Schneidercf1d0c02019-08-31 19:05:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Klaus Schneidercf1d0c02019-08-31 19:05:40 -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.
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/random-strategy.hpp"
27#include "common/global.hpp"
28
29#include "tests/test-common.hpp"
30#include "tests/daemon/face/dummy-face.hpp"
31#include "strategy-tester.hpp"
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::tests {
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070034
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035using RandomStrategyTester = StrategyTester<fw::RandomStrategy>;
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070036NFD_REGISTER_STRATEGY(RandomStrategyTester);
37
38BOOST_AUTO_TEST_SUITE(Fw)
39
40class RandomStrategyFixture : public GlobalIoTimeFixture
41{
42protected:
43 RandomStrategyFixture()
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040044 : face1(make_shared<DummyFace>())
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070045 , face2(make_shared<DummyFace>())
46 , face3(make_shared<DummyFace>())
47 , face4(make_shared<DummyFace>())
48 {
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040049 faceTable.add(face1);
50 faceTable.add(face2);
51 faceTable.add(face3);
52 faceTable.add(face4);
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070053 }
54
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040055protected:
56 FaceTable faceTable;
57 Forwarder forwarder{faceTable};
58 RandomStrategyTester strategy{forwarder};
59 Fib& fib{forwarder.getFib()};
60 Pit& pit{forwarder.getPit()};
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070061
62 shared_ptr<DummyFace> face1;
63 shared_ptr<DummyFace> face2;
64 shared_ptr<DummyFace> face3;
65 shared_ptr<DummyFace> face4;
66};
67
68BOOST_FIXTURE_TEST_SUITE(TestRandomStrategy, RandomStrategyFixture)
69
70BOOST_AUTO_TEST_CASE(Forward)
71{
72 fib::Entry& fibEntry = *fib.insert(Name()).first;
73 fib.addOrUpdateNextHop(fibEntry, *face2, 10);
74 fib.addOrUpdateNextHop(fibEntry, *face3, 20);
75 fib.addOrUpdateNextHop(fibEntry, *face4, 30);
76
77 // Send 1000 Interests
78 for (int i = 0; i < 1000; ++i) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040079 auto interest = makeInterest("ndn:/BzgFBchqA" + std::to_string(i));
80 auto pitEntry = pit.insert(*interest).first;
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070081
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000082 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Teng Liangd94b7b32022-07-10 21:29:37 +080083 strategy.afterReceiveInterest(*interest, FaceEndpoint(*face1), pitEntry);
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070084 }
85
Davide Pesavento0498ce82021-06-14 02:02:21 -040086 // Map outFaceId -> SentInterests
87 std::unordered_map<FaceId, int> faceInterestMap;
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070088 for (const auto& i : strategy.sendInterestHistory) {
89 faceInterestMap[i.outFaceId]++;
90 }
91
92 // Check that all faces received at least 10 Interest
93 for (const auto& x : faceInterestMap) {
Davide Pesavento0498ce82021-06-14 02:02:21 -040094 BOOST_TEST(x.second >= 10);
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070095 }
96}
97
98BOOST_AUTO_TEST_SUITE_END() // TestRandomStrategy
99BOOST_AUTO_TEST_SUITE_END() // Fw
100
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400101} // namespace nfd::tests