blob: 00d90ca187af811d776df75f4a784c88536f600f [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shib2bcbcd2014-11-08 09:30:28 -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 Shib2bcbcd2014-11-08 09:30:28 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_PIT_HPP
27#define NFD_DAEMON_TABLE_PIT_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070028
Haowei Yuan78c84d12014-02-27 15:35:13 -060029#include "name-tree.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070030#include "pit-entry.hpp"
Haowei Yuan78c84d12014-02-27 15:35:13 -060031
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080032namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070033namespace pit {
34
35/** \class DataMatchResult
36 * \brief an unordered iterable of all PIT entries matching Data
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070037 *
Junxiao Shicbba04c2014-01-26 14:21:22 -070038 * This type shall support:
39 * iterator<shared_ptr<pit::Entry>> begin()
40 * iterator<shared_ptr<pit::Entry>> end()
41 */
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070042typedef std::vector<shared_ptr<pit::Entry>> DataMatchResult;
Junxiao Shicbba04c2014-01-26 14:21:22 -070043
44} // namespace pit
45
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070046/** \brief represents the Interest Table
Junxiao Shicbba04c2014-01-26 14:21:22 -070047 */
48class Pit : noncopyable
49{
50public:
Haowei Yuan78c84d12014-02-27 15:35:13 -060051 explicit
52 Pit(NameTree& nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -060053
Junxiao Shicbba04c2014-01-26 14:21:22 -070054 ~Pit();
Haowei Yuan78c84d12014-02-27 15:35:13 -060055
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070056 /** \return number of entries
Haowei Yuan78c84d12014-02-27 15:35:13 -060057 */
Haowei Yuane1079fc2014-03-08 14:41:25 -060058 size_t
Haowei Yuan78c84d12014-02-27 15:35:13 -060059 size() const;
Haowei Yuane1079fc2014-03-08 14:41:25 -060060
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070061 /** \brief inserts a PIT entry for Interest
62 *
Junxiao Shi66f91f82014-05-10 17:28:58 -070063 * If an entry for exact same name and selectors exists, that entry is returned.
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070064 * \return the entry, and true for new entry, false for existing entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070065 */
66 std::pair<shared_ptr<pit::Entry>, bool>
67 insert(const Interest& interest);
Haowei Yuane1079fc2014-03-08 14:41:25 -060068
Junxiao Shicbba04c2014-01-26 14:21:22 -070069 /** \brief performs a Data match
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070070 * \return an iterable of all PIT entries matching data
Junxiao Shicbba04c2014-01-26 14:21:22 -070071 */
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070072 pit::DataMatchResult
Junxiao Shicbba04c2014-01-26 14:21:22 -070073 findAllDataMatches(const Data& data) const;
Haowei Yuane1079fc2014-03-08 14:41:25 -060074
Haowei Yuan78c84d12014-02-27 15:35:13 -060075 /**
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070076 * \brief erases a PIT Entry
Haowei Yuane1079fc2014-03-08 14:41:25 -060077 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070078 void
Haowei Yuan78c84d12014-02-27 15:35:13 -060079 erase(shared_ptr<pit::Entry> pitEntry);
Junxiao Shicbba04c2014-01-26 14:21:22 -070080
81private:
Haowei Yuan78c84d12014-02-27 15:35:13 -060082 NameTree& m_nameTree;
83 size_t m_nItems;
Junxiao Shicbba04c2014-01-26 14:21:22 -070084};
85
Haowei Yuan78c84d12014-02-27 15:35:13 -060086inline size_t
87Pit::size() const
88{
89 return m_nItems;
90}
91
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080092} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -070093
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070094#endif // NFD_DAEMON_TABLE_PIT_HPP