blob: 4f6f3f4d9a130df111501114e10c1630f7079c38 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Teng Liang6f09ab62018-03-01 20:04:08 -07002/*
ashiqopud3ae85d2019-02-17 02:29:55 +00003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -07004 * 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/>.
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
26#include "pit-entry.hpp"
Davide Pesavento50a6af32019-02-21 00:04:40 -050027
Junxiao Shicbba04c2014-01-26 14:21:22 -070028#include <algorithm>
29
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080030namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070031namespace pit {
32
33Entry::Entry(const Interest& interest)
Davide Pesavento50a6af32019-02-21 00:04:40 -050034 : m_interest(interest.shared_from_this())
Junxiao Shicbba04c2014-01-26 14:21:22 -070035{
36}
37
Junxiao Shia2742922016-11-17 22:53:23 +000038bool
39Entry::canMatch(const Interest& interest, size_t nEqualNameComps) const
40{
41 BOOST_ASSERT(m_interest->getName().compare(0, nEqualNameComps,
42 interest.getName(), 0, nEqualNameComps) == 0);
43
44 return m_interest->getName().compare(nEqualNameComps, Name::npos,
45 interest.getName(), nEqualNameComps) == 0 &&
46 m_interest->getSelectors() == interest.getSelectors();
47 /// \todo #3162 match Link field
48}
49
Junxiao Shi4846f372016-04-05 13:39:30 -070050InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +000051Entry::getInRecord(const Face& face, EndpointId endpointId)
Junxiao Shicbba04c2014-01-26 14:21:22 -070052{
Junxiao Shi4846f372016-04-05 13:39:30 -070053 return std::find_if(m_inRecords.begin(), m_inRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +000054 [&face, endpointId] (const InRecord& inRecord) {
55 return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
56 });
Junxiao Shicbba04c2014-01-26 14:21:22 -070057}
58
Junxiao Shicbba04c2014-01-26 14:21:22 -070059InRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +000060Entry::insertOrUpdateInRecord(Face& face, EndpointId endpointId, const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -070061{
Junxiao Shia2742922016-11-17 22:53:23 +000062 BOOST_ASSERT(this->canMatch(interest));
63
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070064 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +000065 [&face, endpointId] (const InRecord& inRecord) {
66 return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
67 });
Junxiao Shicbba04c2014-01-26 14:21:22 -070068 if (it == m_inRecords.end()) {
ashiqopud3ae85d2019-02-17 02:29:55 +000069 m_inRecords.emplace_front(face, endpointId);
Junxiao Shicbba04c2014-01-26 14:21:22 -070070 it = m_inRecords.begin();
71 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070072
Junxiao Shicbba04c2014-01-26 14:21:22 -070073 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070074 return it;
75}
76
77void
ashiqopu77d0bfd2019-02-20 20:37:31 +000078Entry::deleteInRecord(const Face& face, EndpointId endpointId)
Junxiao Shi5e5e4452015-09-24 16:56:52 -070079{
80 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +000081 [&face, endpointId] (const InRecord& inRecord) {
82 return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
83 });
Junxiao Shi5e5e4452015-09-24 16:56:52 -070084 if (it != m_inRecords.end()) {
85 m_inRecords.erase(it);
86 }
87}
88
89void
Junxiao Shi4846f372016-04-05 13:39:30 -070090Entry::clearInRecords()
Junxiao Shicbba04c2014-01-26 14:21:22 -070091{
92 m_inRecords.clear();
93}
94
95OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +000096Entry::getOutRecord(const Face& face, EndpointId endpointId)
Junxiao Shi4846f372016-04-05 13:39:30 -070097{
98 return std::find_if(m_outRecords.begin(), m_outRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +000099 [&face, endpointId] (const OutRecord& outRecord) {
100 return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
101 });
Junxiao Shi4846f372016-04-05 13:39:30 -0700102}
103
104OutRecordCollection::iterator
ashiqopu77d0bfd2019-02-20 20:37:31 +0000105Entry::insertOrUpdateOutRecord(Face& face, EndpointId endpointId, const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106{
Junxiao Shia2742922016-11-17 22:53:23 +0000107 BOOST_ASSERT(this->canMatch(interest));
108
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700109 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +0000110 [&face, endpointId] (const OutRecord& outRecord) {
111 return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
112 });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700113 if (it == m_outRecords.end()) {
ashiqopud3ae85d2019-02-17 02:29:55 +0000114 m_outRecords.emplace_front(face, endpointId);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700115 it = m_outRecords.begin();
116 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -0700117
Junxiao Shicbba04c2014-01-26 14:21:22 -0700118 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700119 return it;
120}
121
122void
ashiqopu77d0bfd2019-02-20 20:37:31 +0000123Entry::deleteOutRecord(const Face& face, EndpointId endpointId)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700124{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700125 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
ashiqopud3ae85d2019-02-17 02:29:55 +0000126 [&face, endpointId] (const OutRecord& outRecord) {
127 return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
128 });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700129 if (it != m_outRecords.end()) {
130 m_outRecords.erase(it);
131 }
132}
133
ashiqopud3ae85d2019-02-17 02:29:55 +0000134void
135Entry::deleteInOutRecordsByFace(const Face& face)
136{
137 m_inRecords.remove_if([&face] (const InRecord& inRecord) {
138 return &inRecord.getFace() == &face;
139 });
140 m_outRecords.remove_if([&face] (const OutRecord& outRecord) {
141 return &outRecord.getFace() == &face;
142 });
143}
144
Junxiao Shicbba04c2014-01-26 14:21:22 -0700145} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800146} // namespace nfd