blob: 71d8db58ab2274ff68b33bc4f34e1c1550a68d30 [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
Junxiao Shie368d992014-12-02 23:44:31 -070052 /** \brief find or insert a Measurements entry for name
53 */
Junxiao Shi65d00722014-02-17 10:50:20 -070054 shared_ptr<measurements::Entry>
55 get(const Name& name);
56
Junxiao Shie368d992014-12-02 23:44:31 -070057 /** \brief find or insert a Measurements entry for fibEntry->getPrefix()
58 */
Junxiao Shi65d00722014-02-17 10:50:20 -070059 shared_ptr<measurements::Entry>
60 get(const fib::Entry& fibEntry);
61
Junxiao Shie368d992014-12-02 23:44:31 -070062 /** \brief find or insert a Measurements entry for pitEntry->getName()
63 */
Junxiao Shi65d00722014-02-17 10:50:20 -070064 shared_ptr<measurements::Entry>
65 get(const pit::Entry& pitEntry);
66
Junxiao Shie368d992014-12-02 23:44:31 -070067 /** \brief find or insert a Measurements entry for child's parent
68 * \retval nullptr if child is the root entry
Junxiao Shi65d00722014-02-17 10:50:20 -070069 */
70 shared_ptr<measurements::Entry>
Junxiao Shie368d992014-12-02 23:44:31 -070071 getParent(const measurements::Entry& child);
Junxiao Shi65d00722014-02-17 10:50:20 -070072
Junxiao Shie368d992014-12-02 23:44:31 -070073 /** \brief perform a longest prefix match
74 */
HangZhangc85a23c2014-03-01 15:55:55 +080075 shared_ptr<measurements::Entry>
76 findLongestPrefixMatch(const Name& name) const;
Junxiao Shi65d00722014-02-17 10:50:20 -070077
Junxiao Shie368d992014-12-02 23:44:31 -070078 /** \brief perform an exact match
79 */
HangZhangc85a23c2014-03-01 15:55:55 +080080 shared_ptr<measurements::Entry>
81 findExactMatch(const Name& name) const;
82
Junxiao Shi19838042014-06-21 00:34:01 -070083 static time::nanoseconds
84 getInitialLifetime();
85
Junxiao Shie368d992014-12-02 23:44:31 -070086 /** \brief extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -070087 *
88 * The entry will be kept until at least now()+lifetime.
89 */
90 void
Junxiao Shie368d992014-12-02 23:44:31 -070091 extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
HangZhangc85a23c2014-03-01 15:55:55 +080092
93 size_t
94 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -070095
96private:
97 void
Junxiao Shie368d992014-12-02 23:44:31 -070098 cleanup(measurements::Entry& entry);
Junxiao Shi65d00722014-02-17 10:50:20 -070099
HangZhangcb4fc832014-03-11 16:57:11 +0800100 shared_ptr<measurements::Entry>
Junxiao Shie368d992014-12-02 23:44:31 -0700101 get(name_tree::Entry& nte);
HangZhangcb4fc832014-03-11 16:57:11 +0800102
Junxiao Shi65d00722014-02-17 10:50:20 -0700103private:
HangZhangc85a23c2014-03-01 15:55:55 +0800104 NameTree& m_nameTree;
105 size_t m_nItems;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700106 static const time::nanoseconds s_defaultLifetime;
Junxiao Shi65d00722014-02-17 10:50:20 -0700107};
108
Junxiao Shi19838042014-06-21 00:34:01 -0700109inline time::nanoseconds
110Measurements::getInitialLifetime()
111{
112 return time::seconds(4);
113}
114
HangZhangc85a23c2014-03-01 15:55:55 +0800115inline size_t
116Measurements::size() const
117{
118 return m_nItems;
119}
120
Junxiao Shi65d00722014-02-17 10:50:20 -0700121} // namespace nfd
122
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700123#endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP