blob: 1df3380a7639a2fc1abf100fc6ee7ac39cccf0c8 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi4370fde2016-02-24 12:20:46 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08004 * 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
29#include "pit-entry.hpp"
Junxiao Shi09cf13c2016-08-15 02:05:00 +000030#include "pit-iterator.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:
Junxiao Shi09cf13c2016-08-15 02:05:00 +000039 * iterator<shared_ptr<Entry>> begin()
40 * iterator<shared_ptr<Entry>> end()
Junxiao Shicbba04c2014-01-26 14:21:22 -070041 */
Junxiao Shi09cf13c2016-08-15 02:05:00 +000042typedef std::vector<shared_ptr<Entry>> DataMatchResult;
Junxiao Shicbba04c2014-01-26 14:21:22 -070043
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070044/** \brief represents the Interest Table
Junxiao Shicbba04c2014-01-26 14:21:22 -070045 */
46class Pit : noncopyable
47{
48public:
Haowei Yuan78c84d12014-02-27 15:35:13 -060049 explicit
50 Pit(NameTree& nameTree);
Haowei Yuane1079fc2014-03-08 14:41:25 -060051
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070052 /** \return number of entries
Haowei Yuan78c84d12014-02-27 15:35:13 -060053 */
Haowei Yuane1079fc2014-03-08 14:41:25 -060054 size_t
Junxiao Shi09cf13c2016-08-15 02:05:00 +000055 size() const
56 {
57 return m_nItems;
58 }
Haowei Yuane1079fc2014-03-08 14:41:25 -060059
Junxiao Shi5e5e4452015-09-24 16:56:52 -070060 /** \brief finds a PIT entry for Interest
61 * \param interest the Interest
62 * \return an existing entry with same Name and Selectors; otherwise nullptr
63 */
Junxiao Shi09cf13c2016-08-15 02:05:00 +000064 shared_ptr<Entry>
65 find(const Interest& interest) const
66 {
67 return const_cast<Pit*>(this)->findOrInsert(interest, false).first;
68 }
Junxiao Shi5e5e4452015-09-24 16:56:52 -070069
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070070 /** \brief inserts a PIT entry for Interest
Junxiao Shi5e5e4452015-09-24 16:56:52 -070071 * \param interest the Interest; must be created with make_shared
72 * \return a new or existing entry with same Name and Selectors,
73 * and true for new entry, false for existing entry
Junxiao Shicbba04c2014-01-26 14:21:22 -070074 */
Junxiao Shi09cf13c2016-08-15 02:05:00 +000075 std::pair<shared_ptr<Entry>, bool>
76 insert(const Interest& interest)
77 {
78 return this->findOrInsert(interest, true);
79 }
Haowei Yuane1079fc2014-03-08 14:41:25 -060080
Junxiao Shicbba04c2014-01-26 14:21:22 -070081 /** \brief performs a Data match
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070082 * \return an iterable of all PIT entries matching data
Junxiao Shicbba04c2014-01-26 14:21:22 -070083 */
Junxiao Shi09cf13c2016-08-15 02:05:00 +000084 DataMatchResult
Junxiao Shicbba04c2014-01-26 14:21:22 -070085 findAllDataMatches(const Data& data) const;
Haowei Yuane1079fc2014-03-08 14:41:25 -060086
Junxiao Shi09cf13c2016-08-15 02:05:00 +000087 /** \brief erases a PIT Entry
Haowei Yuane1079fc2014-03-08 14:41:25 -060088 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070089 void
Junxiao Shi09cf13c2016-08-15 02:05:00 +000090 erase(shared_ptr<Entry> entry)
91 {
92 this->erase(entry, true);
93 }
Junxiao Shi02b73f52016-07-28 01:48:27 +000094
95 /** \brief deletes in-record and out-record for face
96 */
97 void
Junxiao Shi09cf13c2016-08-15 02:05:00 +000098 deleteInOutRecords(shared_ptr<Entry> entry, const Face& face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070099
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800100public: // enumeration
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000101 typedef Iterator const_iterator;
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800102
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000103 /** \return an iterator to the beginning
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800104 * \note Iteration order is implementation-specific and is undefined
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000105 * \warning Undefine behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
106 * is inserted or deleted during PIT enumeration.
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800107 */
108 const_iterator
109 begin() const;
110
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000111 /** \return an iterator to the end
112 * \sa begin()
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800113 */
114 const_iterator
Junxiao Shi32482052016-08-15 02:05:17 +0000115 end() const
116 {
117 return Iterator();
118 }
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800119
Junxiao Shicbba04c2014-01-26 14:21:22 -0700120private:
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000121 /** \brief erases a PIT Entry
Junxiao Shi02b73f52016-07-28 01:48:27 +0000122 */
123 void
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000124 erase(shared_ptr<Entry> pitEntry, bool canDeleteNte);
Junxiao Shi02b73f52016-07-28 01:48:27 +0000125
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700126 /** \brief finds or inserts a PIT entry for Interest
127 * \param interest the Interest; must be created with make_shared if allowInsert
128 * \param allowInsert whether inserting new entry is allowed.
129 * \return if allowInsert, a new or existing entry with same Name+Selectors,
130 * and true for new entry, false for existing entry;
131 * if not allowInsert, an existing entry with same Name+Selectors and false,
132 * or {nullptr, true} if there's no existing entry
133 */
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000134 std::pair<shared_ptr<Entry>, bool>
Junxiao Shi5e5e4452015-09-24 16:56:52 -0700135 findOrInsert(const Interest& interest, bool allowInsert);
136
137private:
Haowei Yuan78c84d12014-02-27 15:35:13 -0600138 NameTree& m_nameTree;
139 size_t m_nItems;
Junxiao Shicbba04c2014-01-26 14:21:22 -0700140};
141
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000142} // namespace pit
Haowei Yuan78c84d12014-02-27 15:35:13 -0600143
Junxiao Shi09cf13c2016-08-15 02:05:00 +0000144using pit::Pit;
Alexander Afanasyev750fa1c2015-01-03 17:28:31 -0800145
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800146} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700147
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700148#endif // NFD_DAEMON_TABLE_PIT_HPP