Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame^] | 25 | #ifndef NFD_DAEMON_TABLE_MEASUREMENTS_HPP |
| 26 | #define NFD_DAEMON_TABLE_MEASUREMENTS_HPP |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 27 | |
| 28 | #include "measurements-entry.hpp" |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 29 | #include "name-tree.hpp" |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 33 | namespace fib { |
| 34 | class Entry; |
| 35 | } |
| 36 | |
| 37 | namespace pit { |
| 38 | class Entry; |
| 39 | } |
| 40 | |
| 41 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 42 | /** \class Measurement |
| 43 | * \brief represents the Measurements table |
| 44 | */ |
| 45 | class Measurements : noncopyable |
| 46 | { |
| 47 | public: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 48 | explicit |
| 49 | Measurements(NameTree& nametree); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 50 | |
| 51 | ~Measurements(); |
| 52 | |
| 53 | /// find or insert a Measurements entry for name |
| 54 | shared_ptr<measurements::Entry> |
| 55 | get(const Name& name); |
| 56 | |
| 57 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 58 | shared_ptr<measurements::Entry> |
| 59 | get(const fib::Entry& fibEntry); |
| 60 | |
| 61 | /// find or insert a Measurements entry for pitEntry->getName() |
| 62 | shared_ptr<measurements::Entry> |
| 63 | get(const pit::Entry& pitEntry); |
| 64 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 65 | /** find or insert a Measurements entry for child's parent |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 66 | * |
| 67 | * If child is the root entry, returns null. |
| 68 | */ |
| 69 | shared_ptr<measurements::Entry> |
| 70 | getParent(shared_ptr<measurements::Entry> child); |
| 71 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 72 | /// perform a longest prefix match |
| 73 | shared_ptr<measurements::Entry> |
| 74 | findLongestPrefixMatch(const Name& name) const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 75 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 76 | /// perform an exact match |
| 77 | shared_ptr<measurements::Entry> |
| 78 | findExactMatch(const Name& name) const; |
| 79 | |
| 80 | /** extend lifetime of an entry |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 81 | * |
| 82 | * The entry will be kept until at least now()+lifetime. |
| 83 | */ |
| 84 | void |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 85 | extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime); |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 86 | |
| 87 | size_t |
| 88 | size() const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | void |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 92 | cleanup(shared_ptr<measurements::Entry> entry); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 93 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 94 | shared_ptr<measurements::Entry> |
| 95 | get(shared_ptr<name_tree::Entry> nameTreeEntry); |
| 96 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 97 | private: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 98 | NameTree& m_nameTree; |
| 99 | size_t m_nItems; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 100 | static const time::nanoseconds s_defaultLifetime; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 103 | inline size_t |
| 104 | Measurements::size() const |
| 105 | { |
| 106 | return m_nItems; |
| 107 | } |
| 108 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 109 | } // namespace nfd |
| 110 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame^] | 111 | #endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP |