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