blob: 210f8c65e4dbeea2bf674b05ddd8e95fbe7dd002 [file] [log] [blame]
Yumin Xiad72f0922016-03-30 22:19:14 +08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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 "table/pit.hpp"
27#include "table/fib.hpp"
28
29#include "tests/test-common.hpp"
30
31namespace nfd {
32namespace tests {
33
34class PitFibBenchmarkFixture : public BaseFixture
35{
36protected:
37 PitFibBenchmarkFixture()
38 : m_fib(m_nameTree)
39 , m_pit(m_nameTree)
40 {
41 }
42
43 void
44 generatePacketsAndPopulateFib(size_t nPackets,
45 size_t nFibEntries,
46 size_t fibPrefixLength,
47 size_t interestNameLength,
48 size_t dataNameLength)
49 {
50 BOOST_ASSERT(1 <= fibPrefixLength);
51 BOOST_ASSERT(fibPrefixLength <= interestNameLength);
52 BOOST_ASSERT(interestNameLength <= dataNameLength);
53
54 for (size_t i = 0; i < nPackets; i++) {
55 Name prefix(to_string(i / nFibEntries));
56 extendName(prefix, fibPrefixLength - 1);
57
58 Name interestName = prefix;
59 if (nPackets > nFibEntries) {
60 interestName.append(to_string(i));
61 }
62 extendName(interestName, interestNameLength);
63 interests.push_back(make_shared<Interest>(interestName));
64
65 Name dataName = interestName;
66 extendName(dataName, dataNameLength);
67 data.push_back(make_shared<Data>(dataName));
68
69 m_fib.insert(prefix);
70 }
71 }
72
73private:
74 static void
75 extendName(Name& name, size_t length)
76 {
77 BOOST_ASSERT(length >= name.size());
78 for (size_t i = name.size(); i < length; i++) {
79 name.append("dup");
80 }
81 }
82
83protected:
84 std::vector<shared_ptr<Interest>> interests;
85 std::vector<shared_ptr<Data>> data;
86 std::vector<shared_ptr<pit::Entry>> pitEntries;
87
88protected:
89 NameTree m_nameTree;
90 Fib m_fib;
91 Pit m_pit;
92};
93
94// This test case models PIT and FIB operations with simple Interest-Data exchanges.
95// A total of nRoundTrip Interests are received and forwarded, and the same number of Data are returned.
96BOOST_FIXTURE_TEST_CASE(SimpleExchanges, PitFibBenchmarkFixture)
97{
98 // number of Interest-Data exchanges
99 const size_t nRoundTrip = 1000000;
100 // number of iterations between processing incoming Interest and processing incoming Data
101 const size_t gap3 = 20000;
102 // number of iterations between processing incoming Data and deleting PIT entry
103 const size_t gap4 = 30000;
104 // total amount of FIB entires
105 // packet names are homogeneously extended from these FIB entries
106 const size_t nFibEntries = 2000;
107 // length of fibPrefix, must be >= 1
108 const size_t fibPrefixLength = 1;
109 // length of Interest Name >= fibPrefixLength
110 const size_t interestNameLength= 2;
111 // length of Data Name >= Interest Name
112 const size_t dataNameLength = 3;
113
114 generatePacketsAndPopulateFib(nRoundTrip, nFibEntries, fibPrefixLength,
115 interestNameLength, dataNameLength);
116
117 auto t1 = time::steady_clock::now();
118
119 for (size_t i = 0; i < nRoundTrip + gap3 + gap4; ++i) {
120 if (i < nRoundTrip) {
121 // process incoming Interest
122 shared_ptr<pit::Entry> pitEntry = m_pit.insert(*interests[i]).first;
123 pitEntries.push_back(pitEntry);
124 m_fib.findLongestPrefixMatch(*pitEntry);
125 }
126 if (i >= gap3 && i < nRoundTrip + gap3) {
127 // process incoming Data
128 m_pit.findAllDataMatches(*data[i - gap3]);
129 }
130 if (i >= gap3 + gap4) {
131 // delete PIT entry
132 m_pit.erase(pitEntries[i - gap3 - gap4]);
133 }
134 }
135
136 auto t2 = time::steady_clock::now();
137 BOOST_TEST_MESSAGE(time::duration_cast<time::microseconds>(t2 - t1));
138}
139
140} // namespace tests
141} // namespace nfd