blob: 0fa24e03f857b766e1b0f88806a794284aa34cf2 [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"
Junxiao Shidbe71732014-02-21 22:23:28 -070011#include "fib-entry.hpp"
12#include "pit-entry.hpp"
Junxiao Shi65d00722014-02-17 10:50:20 -070013#include "core/time.hpp"
14
15namespace nfd {
16
Junxiao Shi65d00722014-02-17 10:50:20 -070017/** \class Measurement
18 * \brief represents the Measurements table
19 */
20class Measurements : noncopyable
21{
22public:
23 explicit
24 Measurements(boost::asio::io_service& ioService);
25
26 ~Measurements();
27
28 /// find or insert a Measurements entry for name
29 shared_ptr<measurements::Entry>
30 get(const Name& name);
31
32 /// find or insert a Measurements entry for fibEntry->getPrefix()
33 shared_ptr<measurements::Entry>
34 get(const fib::Entry& fibEntry);
35
36 /// find or insert a Measurements entry for pitEntry->getName()
37 shared_ptr<measurements::Entry>
38 get(const pit::Entry& pitEntry);
39
40 /** \brief find or insert a Measurements entry for child's parent
41 *
42 * If child is the root entry, returns null.
43 */
44 shared_ptr<measurements::Entry>
45 getParent(shared_ptr<measurements::Entry> child);
46
47// /// perform a longest prefix match
48// shared_ptr<fib::Entry>
49// findLongestPrefixMatch(const Name& name) const;
50//
51// /// perform an exact match
52// shared_ptr<fib::Entry>
53// findExactMatch(const Name& name) const;
54
55 /** \brief extend lifetime of an entry
56 *
57 * The entry will be kept until at least now()+lifetime.
58 */
59 void
Junxiao Shidbe71732014-02-21 22:23:28 -070060 extendLifetime(measurements::Entry& entry, const time::Duration& lifetime);
Junxiao Shi65d00722014-02-17 10:50:20 -070061
62private:
63 void
64 extendLifetimeInternal(
65 std::map<Name, shared_ptr<measurements::Entry> >::iterator it,
Junxiao Shidbe71732014-02-21 22:23:28 -070066 const time::Duration& lifetime);
Junxiao Shi65d00722014-02-17 10:50:20 -070067
68 void
69 cleanup(std::map<Name, shared_ptr<measurements::Entry> >::iterator it);
70
71private:
72 std::map<Name, shared_ptr<measurements::Entry> > m_table;
73
74 Scheduler m_scheduler;
75 static const time::Duration s_defaultLifetime;
76};
77
78} // namespace nfd
79
80#endif // NFD_TABLE_MEASUREMENTS_HPP