Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, 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 |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_MEASUREMENTS_HPP |
| 27 | #define NFD_DAEMON_TABLE_MEASUREMENTS_HPP |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 28 | |
| 29 | #include "measurements-entry.hpp" |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 30 | #include "name-tree.hpp" |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 34 | namespace fib { |
| 35 | class Entry; |
| 36 | } |
| 37 | |
| 38 | namespace pit { |
| 39 | class Entry; |
| 40 | } |
| 41 | |
| 42 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 43 | /** \class Measurement |
| 44 | * \brief represents the Measurements table |
| 45 | */ |
| 46 | class Measurements : noncopyable |
| 47 | { |
| 48 | public: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 49 | explicit |
| 50 | Measurements(NameTree& nametree); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 51 | |
| 52 | ~Measurements(); |
| 53 | |
| 54 | /// find or insert a Measurements entry for name |
| 55 | shared_ptr<measurements::Entry> |
| 56 | get(const Name& name); |
| 57 | |
| 58 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 59 | shared_ptr<measurements::Entry> |
| 60 | get(const fib::Entry& fibEntry); |
| 61 | |
| 62 | /// find or insert a Measurements entry for pitEntry->getName() |
| 63 | shared_ptr<measurements::Entry> |
| 64 | get(const pit::Entry& pitEntry); |
| 65 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 66 | /** find or insert a Measurements entry for child's parent |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 67 | * |
| 68 | * If child is the root entry, returns null. |
| 69 | */ |
| 70 | shared_ptr<measurements::Entry> |
| 71 | getParent(shared_ptr<measurements::Entry> child); |
| 72 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 73 | /// perform a longest prefix match |
| 74 | shared_ptr<measurements::Entry> |
| 75 | findLongestPrefixMatch(const Name& name) const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 76 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 77 | /// perform an exact match |
| 78 | shared_ptr<measurements::Entry> |
| 79 | findExactMatch(const Name& name) const; |
| 80 | |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame] | 81 | static time::nanoseconds |
| 82 | getInitialLifetime(); |
| 83 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 84 | /** extend lifetime of an entry |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 85 | * |
| 86 | * The entry will be kept until at least now()+lifetime. |
| 87 | */ |
| 88 | void |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 89 | extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime); |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 90 | |
| 91 | size_t |
| 92 | size() const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 93 | |
| 94 | private: |
| 95 | void |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 96 | cleanup(shared_ptr<measurements::Entry> entry); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 97 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 98 | shared_ptr<measurements::Entry> |
| 99 | get(shared_ptr<name_tree::Entry> nameTreeEntry); |
| 100 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 101 | private: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 102 | NameTree& m_nameTree; |
| 103 | size_t m_nItems; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 104 | static const time::nanoseconds s_defaultLifetime; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame] | 107 | inline time::nanoseconds |
| 108 | Measurements::getInitialLifetime() |
| 109 | { |
| 110 | return time::seconds(4); |
| 111 | } |
| 112 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 113 | inline size_t |
| 114 | Measurements::size() const |
| 115 | { |
| 116 | return m_nItems; |
| 117 | } |
| 118 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 119 | } // namespace nfd |
| 120 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 121 | #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP |