blob: 794f4a61795f9518065281a330d895ed0d4f7698 [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"
11#include "core/time.hpp"
HangZhangc85a23c2014-03-01 15:55:55 +080012#include "name-tree.hpp"
Junxiao Shi65d00722014-02-17 10:50:20 -070013
14namespace nfd {
15
HangZhangc85a23c2014-03-01 15:55:55 +080016namespace fib {
17class Entry;
18}
19
20namespace pit {
21class Entry;
22}
23
24
Junxiao Shi65d00722014-02-17 10:50:20 -070025/** \class Measurement
26 * \brief represents the Measurements table
27 */
28class Measurements : noncopyable
29{
30public:
HangZhangc85a23c2014-03-01 15:55:55 +080031 explicit
32 Measurements(NameTree& nametree);
Junxiao Shi65d00722014-02-17 10:50:20 -070033
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
HangZhangc85a23c2014-03-01 15:55:55 +080048 /** find or insert a Measurements entry for child's parent
Junxiao Shi65d00722014-02-17 10:50:20 -070049 *
50 * If child is the root entry, returns null.
51 */
52 shared_ptr<measurements::Entry>
53 getParent(shared_ptr<measurements::Entry> child);
54
HangZhangc85a23c2014-03-01 15:55:55 +080055 /// perform a longest prefix match
56 shared_ptr<measurements::Entry>
57 findLongestPrefixMatch(const Name& name) const;
Junxiao Shi65d00722014-02-17 10:50:20 -070058
HangZhangc85a23c2014-03-01 15:55:55 +080059 /// perform an exact match
60 shared_ptr<measurements::Entry>
61 findExactMatch(const Name& name) const;
62
63 /** extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -070064 *
65 * The entry will be kept until at least now()+lifetime.
66 */
67 void
HangZhangc85a23c2014-03-01 15:55:55 +080068 extendLifetime(measurements::Entry& entry, const time::Duration lifetime);
69
70 size_t
71 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -070072
73private:
74 void
HangZhangc85a23c2014-03-01 15:55:55 +080075 cleanup(shared_ptr<measurements::Entry> entry);
Junxiao Shi65d00722014-02-17 10:50:20 -070076
77private:
HangZhangc85a23c2014-03-01 15:55:55 +080078 NameTree& m_nameTree;
79 size_t m_nItems;
Junxiao Shi65d00722014-02-17 10:50:20 -070080 static const time::Duration s_defaultLifetime;
81};
82
HangZhangc85a23c2014-03-01 15:55:55 +080083inline size_t
84Measurements::size() const
85{
86 return m_nItems;
87}
88
Junxiao Shi65d00722014-02-17 10:50:20 -070089} // namespace nfd
90
91#endif // NFD_TABLE_MEASUREMENTS_HPP