blob: 1b9f382b0462e29fca132a9849b10328bdd437f7 [file] [log] [blame]
Junxiao Shi65d00722014-02-17 10:50:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shi65d00722014-02-17 10:50:20 -070024
25#ifndef NFD_TABLE_MEASUREMENTS_HPP
26#define NFD_TABLE_MEASUREMENTS_HPP
27
28#include "measurements-entry.hpp"
HangZhangc85a23c2014-03-01 15:55:55 +080029#include "name-tree.hpp"
Junxiao Shi65d00722014-02-17 10:50:20 -070030
31namespace nfd {
32
HangZhangc85a23c2014-03-01 15:55:55 +080033namespace fib {
34class Entry;
35}
36
37namespace pit {
38class Entry;
39}
40
41
Junxiao Shi65d00722014-02-17 10:50:20 -070042/** \class Measurement
43 * \brief represents the Measurements table
44 */
45class Measurements : noncopyable
46{
47public:
HangZhangc85a23c2014-03-01 15:55:55 +080048 explicit
49 Measurements(NameTree& nametree);
Junxiao Shi65d00722014-02-17 10:50:20 -070050
51 ~Measurements();
52
53 /// find or insert a Measurements entry for name
54 shared_ptr<measurements::Entry>
55 get(const Name& name);
56
57 /// find or insert a Measurements entry for fibEntry->getPrefix()
58 shared_ptr<measurements::Entry>
59 get(const fib::Entry& fibEntry);
60
61 /// find or insert a Measurements entry for pitEntry->getName()
62 shared_ptr<measurements::Entry>
63 get(const pit::Entry& pitEntry);
64
HangZhangc85a23c2014-03-01 15:55:55 +080065 /** find or insert a Measurements entry for child's parent
Junxiao Shi65d00722014-02-17 10:50:20 -070066 *
67 * If child is the root entry, returns null.
68 */
69 shared_ptr<measurements::Entry>
70 getParent(shared_ptr<measurements::Entry> child);
71
HangZhangc85a23c2014-03-01 15:55:55 +080072 /// perform a longest prefix match
73 shared_ptr<measurements::Entry>
74 findLongestPrefixMatch(const Name& name) const;
Junxiao Shi65d00722014-02-17 10:50:20 -070075
HangZhangc85a23c2014-03-01 15:55:55 +080076 /// perform an exact match
77 shared_ptr<measurements::Entry>
78 findExactMatch(const Name& name) const;
79
80 /** extend lifetime of an entry
Junxiao Shi65d00722014-02-17 10:50:20 -070081 *
82 * The entry will be kept until at least now()+lifetime.
83 */
84 void
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070085 extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
HangZhangc85a23c2014-03-01 15:55:55 +080086
87 size_t
88 size() const;
Junxiao Shi65d00722014-02-17 10:50:20 -070089
90private:
91 void
HangZhangc85a23c2014-03-01 15:55:55 +080092 cleanup(shared_ptr<measurements::Entry> entry);
Junxiao Shi65d00722014-02-17 10:50:20 -070093
HangZhangcb4fc832014-03-11 16:57:11 +080094 shared_ptr<measurements::Entry>
95 get(shared_ptr<name_tree::Entry> nameTreeEntry);
96
Junxiao Shi65d00722014-02-17 10:50:20 -070097private:
HangZhangc85a23c2014-03-01 15:55:55 +080098 NameTree& m_nameTree;
99 size_t m_nItems;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700100 static const time::nanoseconds s_defaultLifetime;
Junxiao Shi65d00722014-02-17 10:50:20 -0700101};
102
HangZhangc85a23c2014-03-01 15:55:55 +0800103inline size_t
104Measurements::size() const
105{
106 return m_nItems;
107}
108
Junxiao Shi65d00722014-02-17 10:50:20 -0700109} // namespace nfd
110
111#endif // NFD_TABLE_MEASUREMENTS_HPP