blob: 4d19f344da3adb7f097bafe53f512c73c032bab2 [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;
Junxiao Shib30c7b02015-01-07 15:45:54 -070036} // namespace fib
HangZhangc85a23c2014-03-01 15:55:55 +080037
38namespace pit {
39class Entry;
Junxiao Shib30c7b02015-01-07 15:45:54 -070040} // namespace pit
HangZhangc85a23c2014-03-01 15:55:55 +080041
Junxiao Shib30c7b02015-01-07 15:45:54 -070042namespace measurements {
HangZhangc85a23c2014-03-01 15:55:55 +080043
Junxiao Shib30c7b02015-01-07 15:45:54 -070044/** \brief a predicate that accepts or rejects a \p Entry
45 */
46typedef std::function<bool(const Entry&)> EntryPredicate;
47
48/** \brief an \p EntryPredicate that accepts any \p Entry
49 */
50class AnyEntry
51{
52public:
53 bool
54 operator()(const Entry& entry)
55 {
56 return true;
57 }
58};
59
60template<typename T>
61class EntryWithStrategyInfo
62{
63public:
64 bool
65 operator()(const Entry& entry)
66 {
67 return entry.getStrategyInfo<T>() != nullptr;
68 }
69};
70
71} // namespace measurements
72
73/** \brief represents the Measurements table
Junxiao Shi65d00722014-02-17 10:50:20 -070074 */
75class Measurements : noncopyable
76{
77public:
HangZhangc85a23c2014-03-01 15:55:55 +080078 explicit
79 Measurements(NameTree& nametree);
Junxiao Shi65d00722014-02-17 10:50:20 -070080
Junxiao Shie368d992014-12-02 23:44:31 -070081 /** \brief find or insert a Measurements entry for name
82 */
Junxiao Shi65d00722014-02-17 10:50:20 -070083 shared_ptr<measurements::Entry>
84 get(const Name& name);
85
Junxiao Shie368d992014-12-02 23:44:31 -070086 /** \brief find or insert a Measurements entry for fibEntry->getPrefix()
87 */
Junxiao Shi65d00722014-02-17 10:50:20 -070088 shared_ptr<measurements::Entry>
89 get(const fib::Entry& fibEntry);
90
Junxiao Shie368d992014-12-02 23:44:31 -070091 /** \brief find or insert a Measurements entry for pitEntry->getName()
92 */
Junxiao Shi65d00722014-02-17 10:50:20 -070093 shared_ptr<measurements::Entry>
94 get(const pit::Entry& pitEntry);
95
Junxiao Shie368d992014-12-02 23:44:31 -070096 /** \brief find or insert a Measurements entry for child's parent
97 * \retval nullptr if child is the root entry
Junxiao Shi65d00722014-02-17 10:50:20 -070098 */
99 shared_ptr<measurements::Entry>
Junxiao Shie368d992014-12-02 23:44:31 -0700100 getParent(const measurements::Entry& child);
Junxiao Shi65d00722014-02-17 10:50:20 -0700101
Junxiao Shie368d992014-12-02 23:44:31 -0700102 /** \brief perform a longest prefix match
103 */
HangZhangc85a23c2014-03-01 15:55:55 +0800104 shared_ptr<measurements::Entry>
Junxiao Shib30c7b02015-01-07 15:45:54 -0700105 findLongestPrefixMatch(const Name& name,
106 const measurements::EntryPredicate& pred =
107 measurements::AnyEntry()) const;
Junxiao Shi65d00722014-02-17 10:50:20 -0700108
Junxiao Shie368d992014-12-02 23:44:31 -0700109 /** \brief perform an exact match
110 */
HangZhangc85a23c2014-03-01 15:55:55 +0800111 shared_ptr<measurements::Entry>
112 findExactMatch(const Name& name) const;
113
Junxiao Shi19838042014-06-21 00:34:01 -0700114 static time::nanoseconds
115 getInitialLifetime();
116
Junxiao Shie368d992014-12-02 23:44:31 -0700117 /** \brief extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -0700118 *
119 * The entry will be kept until at least now()+lifetime.
120 */
121 void
Junxiao Shie368d992014-12-02 23:44:31 -0700122 extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
HangZhangc85a23c2014-03-01 15:55:55 +0800123
124 size_t
125 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -0700126
127private:
128 void
Junxiao Shie368d992014-12-02 23:44:31 -0700129 cleanup(measurements::Entry& entry);
Junxiao Shi65d00722014-02-17 10:50:20 -0700130
HangZhangcb4fc832014-03-11 16:57:11 +0800131 shared_ptr<measurements::Entry>
Junxiao Shie368d992014-12-02 23:44:31 -0700132 get(name_tree::Entry& nte);
HangZhangcb4fc832014-03-11 16:57:11 +0800133
Junxiao Shi65d00722014-02-17 10:50:20 -0700134private:
HangZhangc85a23c2014-03-01 15:55:55 +0800135 NameTree& m_nameTree;
136 size_t m_nItems;
Junxiao Shi65d00722014-02-17 10:50:20 -0700137};
138
Junxiao Shi19838042014-06-21 00:34:01 -0700139inline time::nanoseconds
140Measurements::getInitialLifetime()
141{
142 return time::seconds(4);
143}
144
HangZhangc85a23c2014-03-01 15:55:55 +0800145inline size_t
146Measurements::size() const
147{
148 return m_nItems;
149}
150
Junxiao Shi65d00722014-02-17 10:50:20 -0700151} // namespace nfd
152
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700153#endif // NFD_DAEMON_TABLE_MEASUREMENTS_HPP