Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TABLE_MEASUREMENTS_HPP |
| 8 | #define NFD_TABLE_MEASUREMENTS_HPP |
| 9 | |
| 10 | #include "measurements-entry.hpp" |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 11 | #include "name-tree.hpp" |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
| 14 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 15 | namespace fib { |
| 16 | class Entry; |
| 17 | } |
| 18 | |
| 19 | namespace pit { |
| 20 | class Entry; |
| 21 | } |
| 22 | |
| 23 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 24 | /** \class Measurement |
| 25 | * \brief represents the Measurements table |
| 26 | */ |
| 27 | class Measurements : noncopyable |
| 28 | { |
| 29 | public: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 30 | explicit |
| 31 | Measurements(NameTree& nametree); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 32 | |
| 33 | ~Measurements(); |
| 34 | |
| 35 | /// find or insert a Measurements entry for name |
| 36 | shared_ptr<measurements::Entry> |
| 37 | get(const Name& name); |
| 38 | |
| 39 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 40 | shared_ptr<measurements::Entry> |
| 41 | get(const fib::Entry& fibEntry); |
| 42 | |
| 43 | /// find or insert a Measurements entry for pitEntry->getName() |
| 44 | shared_ptr<measurements::Entry> |
| 45 | get(const pit::Entry& pitEntry); |
| 46 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 47 | /** find or insert a Measurements entry for child's parent |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 48 | * |
| 49 | * If child is the root entry, returns null. |
| 50 | */ |
| 51 | shared_ptr<measurements::Entry> |
| 52 | getParent(shared_ptr<measurements::Entry> child); |
| 53 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 54 | /// perform a longest prefix match |
| 55 | shared_ptr<measurements::Entry> |
| 56 | findLongestPrefixMatch(const Name& name) const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 57 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 58 | /// perform an exact match |
| 59 | shared_ptr<measurements::Entry> |
| 60 | findExactMatch(const Name& name) const; |
| 61 | |
| 62 | /** extend lifetime of an entry |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 63 | * |
| 64 | * The entry will be kept until at least now()+lifetime. |
| 65 | */ |
| 66 | void |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame^] | 67 | extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime); |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 68 | |
| 69 | size_t |
| 70 | size() const; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | void |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 74 | cleanup(shared_ptr<measurements::Entry> entry); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 75 | |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 76 | shared_ptr<measurements::Entry> |
| 77 | get(shared_ptr<name_tree::Entry> nameTreeEntry); |
| 78 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 79 | private: |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 80 | NameTree& m_nameTree; |
| 81 | size_t m_nItems; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame^] | 82 | static const time::nanoseconds s_defaultLifetime; |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 85 | inline size_t |
| 86 | Measurements::size() const |
| 87 | { |
| 88 | return m_nItems; |
| 89 | } |
| 90 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 91 | } // namespace nfd |
| 92 | |
| 93 | #endif // NFD_TABLE_MEASUREMENTS_HPP |