blob: 8d09666135e18bd927afd099824138ac09bc8a04 [file] [log] [blame]
Junxiao Shi65d00722014-02-17 10:50:20 -07001/* -*- 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"
HangZhangc85a23c2014-03-01 15:55:55 +080011#include "name-tree.hpp"
Junxiao Shi65d00722014-02-17 10:50:20 -070012
13namespace nfd {
14
HangZhangc85a23c2014-03-01 15:55:55 +080015namespace fib {
16class Entry;
17}
18
19namespace pit {
20class Entry;
21}
22
23
Junxiao Shi65d00722014-02-17 10:50:20 -070024/** \class Measurement
25 * \brief represents the Measurements table
26 */
27class Measurements : noncopyable
28{
29public:
HangZhangc85a23c2014-03-01 15:55:55 +080030 explicit
31 Measurements(NameTree& nametree);
Junxiao Shi65d00722014-02-17 10:50:20 -070032
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
HangZhangc85a23c2014-03-01 15:55:55 +080047 /** find or insert a Measurements entry for child's parent
Junxiao Shi65d00722014-02-17 10:50:20 -070048 *
49 * If child is the root entry, returns null.
50 */
51 shared_ptr<measurements::Entry>
52 getParent(shared_ptr<measurements::Entry> child);
53
HangZhangc85a23c2014-03-01 15:55:55 +080054 /// perform a longest prefix match
55 shared_ptr<measurements::Entry>
56 findLongestPrefixMatch(const Name& name) const;
Junxiao Shi65d00722014-02-17 10:50:20 -070057
HangZhangc85a23c2014-03-01 15:55:55 +080058 /// perform an exact match
59 shared_ptr<measurements::Entry>
60 findExactMatch(const Name& name) const;
61
62 /** extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -070063 *
64 * The entry will be kept until at least now()+lifetime.
65 */
66 void
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070067 extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
HangZhangc85a23c2014-03-01 15:55:55 +080068
69 size_t
70 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -070071
72private:
73 void
HangZhangc85a23c2014-03-01 15:55:55 +080074 cleanup(shared_ptr<measurements::Entry> entry);
Junxiao Shi65d00722014-02-17 10:50:20 -070075
HangZhangcb4fc832014-03-11 16:57:11 +080076 shared_ptr<measurements::Entry>
77 get(shared_ptr<name_tree::Entry> nameTreeEntry);
78
Junxiao Shi65d00722014-02-17 10:50:20 -070079private:
HangZhangc85a23c2014-03-01 15:55:55 +080080 NameTree& m_nameTree;
81 size_t m_nItems;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070082 static const time::nanoseconds s_defaultLifetime;
Junxiao Shi65d00722014-02-17 10:50:20 -070083};
84
HangZhangc85a23c2014-03-01 15:55:55 +080085inline size_t
86Measurements::size() const
87{
88 return m_nItems;
89}
90
Junxiao Shi65d00722014-02-17 10:50:20 -070091} // namespace nfd
92
93#endif // NFD_TABLE_MEASUREMENTS_HPP