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