blob: 7478c58b0b25f7ff5f00463f8a57af47d45d4e07 [file] [log] [blame]
Junxiao Shi65d00722014-02-17 10:50:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi19838042014-06-21 00:34:01 -07003 * 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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi19838042014-06-21 00:34:01 -070024 */
Junxiao Shi65d00722014-02-17 10:50:20 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_MEASUREMENTS_HPP
27#define NFD_DAEMON_TABLE_MEASUREMENTS_HPP
Junxiao Shi65d00722014-02-17 10:50:20 -070028
29#include "measurements-entry.hpp"
HangZhangc85a23c2014-03-01 15:55:55 +080030#include "name-tree.hpp"
Junxiao Shi65d00722014-02-17 10:50:20 -070031
32namespace nfd {
33
HangZhangc85a23c2014-03-01 15:55:55 +080034namespace fib {
35class Entry;
36}
37
38namespace pit {
39class Entry;
40}
41
42
Junxiao Shi65d00722014-02-17 10:50:20 -070043/** \class Measurement
44 * \brief represents the Measurements table
45 */
46class Measurements : noncopyable
47{
48public:
HangZhangc85a23c2014-03-01 15:55:55 +080049 explicit
50 Measurements(NameTree& nametree);
Junxiao Shi65d00722014-02-17 10:50:20 -070051
52 ~Measurements();
53
54 /// find or insert a Measurements entry for name
55 shared_ptr<measurements::Entry>
56 get(const Name& name);
57
58 /// find or insert a Measurements entry for fibEntry->getPrefix()
59 shared_ptr<measurements::Entry>
60 get(const fib::Entry& fibEntry);
61
62 /// find or insert a Measurements entry for pitEntry->getName()
63 shared_ptr<measurements::Entry>
64 get(const pit::Entry& pitEntry);
65
HangZhangc85a23c2014-03-01 15:55:55 +080066 /** find or insert a Measurements entry for child's parent
Junxiao Shi65d00722014-02-17 10:50:20 -070067 *
68 * If child is the root entry, returns null.
69 */
70 shared_ptr<measurements::Entry>
71 getParent(shared_ptr<measurements::Entry> child);
72
HangZhangc85a23c2014-03-01 15:55:55 +080073 /// perform a longest prefix match
74 shared_ptr<measurements::Entry>
75 findLongestPrefixMatch(const Name& name) const;
Junxiao Shi65d00722014-02-17 10:50:20 -070076
HangZhangc85a23c2014-03-01 15:55:55 +080077 /// perform an exact match
78 shared_ptr<measurements::Entry>
79 findExactMatch(const Name& name) const;
80
Junxiao Shi19838042014-06-21 00:34:01 -070081 static time::nanoseconds
82 getInitialLifetime();
83
HangZhangc85a23c2014-03-01 15:55:55 +080084 /** extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -070085 *
86 * The entry will be kept until at least now()+lifetime.
87 */
88 void
Junxiao Shiee5a4442014-07-27 17:13:43 -070089 extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
HangZhangc85a23c2014-03-01 15:55:55 +080090
91 size_t
92 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -070093
94private:
95 void
HangZhangc85a23c2014-03-01 15:55:55 +080096 cleanup(shared_ptr<measurements::Entry> entry);
Junxiao Shi65d00722014-02-17 10:50:20 -070097
HangZhangcb4fc832014-03-11 16:57:11 +080098 shared_ptr<measurements::Entry>
99 get(shared_ptr<name_tree::Entry> nameTreeEntry);
100
Junxiao Shi65d00722014-02-17 10:50:20 -0700101private:
HangZhangc85a23c2014-03-01 15:55:55 +0800102 NameTree& m_nameTree;
103 size_t m_nItems;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700104 static const time::nanoseconds s_defaultLifetime;
Junxiao Shi65d00722014-02-17 10:50:20 -0700105};
106
Junxiao Shi19838042014-06-21 00:34:01 -0700107inline time::nanoseconds
108Measurements::getInitialLifetime()
109{
110 return time::seconds(4);
111}
112
HangZhangc85a23c2014-03-01 15:55:55 +0800113inline size_t
114Measurements::size() const
115{
116 return m_nItems;
117}
118
Junxiao Shi65d00722014-02-17 10:50:20 -0700119} // namespace nfd
120
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700121#endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP