blob: 84347f59a237e66d7710136056e5f0d120d68665 [file] [log] [blame]
Klaus Schneidercf1d0c02019-08-31 19:05:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2019, 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/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
33namespace nfd {
34namespace fw {
35namespace tests {
36
37using RandomStrategyTester = StrategyTester<RandomStrategy>;
38NFD_REGISTER_STRATEGY(RandomStrategyTester);
39
40BOOST_AUTO_TEST_SUITE(Fw)
41
42class RandomStrategyFixture : public GlobalIoTimeFixture
43{
44protected:
45 RandomStrategyFixture()
46 : strategy(forwarder)
47 , fib(forwarder.getFib())
48 , pit(forwarder.getPit())
49 , face1(make_shared<DummyFace>())
50 , face2(make_shared<DummyFace>())
51 , face3(make_shared<DummyFace>())
52 , face4(make_shared<DummyFace>())
53 {
54 forwarder.addFace(face1);
55 forwarder.addFace(face2);
56 forwarder.addFace(face3);
57 forwarder.addFace(face4);
58 }
59
60public:
61 Forwarder forwarder;
62 RandomStrategyTester strategy;
63 Fib& fib;
64 Pit& pit;
65
66 shared_ptr<DummyFace> face1;
67 shared_ptr<DummyFace> face2;
68 shared_ptr<DummyFace> face3;
69 shared_ptr<DummyFace> face4;
70};
71
72BOOST_FIXTURE_TEST_SUITE(TestRandomStrategy, RandomStrategyFixture)
73
74BOOST_AUTO_TEST_CASE(Forward)
75{
76 fib::Entry& fibEntry = *fib.insert(Name()).first;
77 fib.addOrUpdateNextHop(fibEntry, *face2, 10);
78 fib.addOrUpdateNextHop(fibEntry, *face3, 20);
79 fib.addOrUpdateNextHop(fibEntry, *face4, 30);
80
81 // Send 1000 Interests
82 for (int i = 0; i < 1000; ++i) {
83 shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA" + std::to_string(i));
84 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
85
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000086 pitEntry->insertOrUpdateInRecord(*face1, *interest);
Klaus Schneidercf1d0c02019-08-31 19:05:40 -070087 strategy.afterReceiveInterest(FaceEndpoint(*face1, 0), *interest, pitEntry);
88 }
89
90 // Map outFaceId -> SentInterests.
91 std::unordered_map<int, int> faceInterestMap;
92 for (const auto& i : strategy.sendInterestHistory) {
93 faceInterestMap[i.outFaceId]++;
94 }
95
96 // Check that all faces received at least 10 Interest
97 for (const auto& x : faceInterestMap) {
98 BOOST_CHECK_GE(x.second, 10);
99 }
100}
101
102BOOST_AUTO_TEST_SUITE_END() // TestRandomStrategy
103BOOST_AUTO_TEST_SUITE_END() // Fw
104
105} // namespace tests
106} // namespace fw
107} // namespace nfd