blob: ee4b7265536481ca7c8384052e77963e0c08c14d [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/*
3 * Copyright (c) 2014-2018, 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"
27#include <algorithm>
28
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080029namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070030namespace pit {
31
32Entry::Entry(const Interest& interest)
Teng Liang6f09ab62018-03-01 20:04:08 -070033 : isSatisfied(false)
34 , dataFreshnessPeriod(0_ms)
35 , m_interest(interest.shared_from_this())
Junxiao Shi340d5532016-08-13 04:00:35 +000036 , m_nameTreeEntry(nullptr)
Junxiao Shicbba04c2014-01-26 14:21:22 -070037{
38}
39
Junxiao Shia2742922016-11-17 22:53:23 +000040bool
41Entry::canMatch(const Interest& interest, size_t nEqualNameComps) const
42{
43 BOOST_ASSERT(m_interest->getName().compare(0, nEqualNameComps,
44 interest.getName(), 0, nEqualNameComps) == 0);
45
46 return m_interest->getName().compare(nEqualNameComps, Name::npos,
47 interest.getName(), nEqualNameComps) == 0 &&
48 m_interest->getSelectors() == interest.getSelectors();
49 /// \todo #3162 match Link field
50}
51
Junxiao Shi4846f372016-04-05 13:39:30 -070052InRecordCollection::iterator
53Entry::getInRecord(const Face& face)
Junxiao Shicbba04c2014-01-26 14:21:22 -070054{
Junxiao Shi4846f372016-04-05 13:39:30 -070055 return std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000056 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070057}
58
Junxiao Shicbba04c2014-01-26 14:21:22 -070059InRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +000060Entry::insertOrUpdateInRecord(Face& face, 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(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000065 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070066 if (it == m_inRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070067 m_inRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070068 it = m_inRecords.begin();
69 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070070
Junxiao Shicbba04c2014-01-26 14:21:22 -070071 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070072 return it;
73}
74
75void
Junxiao Shi5e5e4452015-09-24 16:56:52 -070076Entry::deleteInRecord(const Face& face)
77{
78 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000079 [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
Junxiao Shi5e5e4452015-09-24 16:56:52 -070080 if (it != m_inRecords.end()) {
81 m_inRecords.erase(it);
82 }
83}
84
85void
Junxiao Shi4846f372016-04-05 13:39:30 -070086Entry::clearInRecords()
Junxiao Shicbba04c2014-01-26 14:21:22 -070087{
88 m_inRecords.clear();
89}
90
91OutRecordCollection::iterator
Junxiao Shi4846f372016-04-05 13:39:30 -070092Entry::getOutRecord(const Face& face)
93{
94 return std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +000095 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shi4846f372016-04-05 13:39:30 -070096}
97
98OutRecordCollection::iterator
Junxiao Shi9cff7792016-08-01 21:45:11 +000099Entry::insertOrUpdateOutRecord(Face& face, const Interest& interest)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700100{
Junxiao Shia2742922016-11-17 22:53:23 +0000101 BOOST_ASSERT(this->canMatch(interest));
102
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700103 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +0000104 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700105 if (it == m_outRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700106 m_outRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700107 it = m_outRecords.begin();
108 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -0700109
Junxiao Shicbba04c2014-01-26 14:21:22 -0700110 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -0700111 return it;
112}
113
114void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700115Entry::deleteOutRecord(const Face& face)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700116{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700117 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shi9cff7792016-08-01 21:45:11 +0000118 [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700119 if (it != m_outRecords.end()) {
120 m_outRecords.erase(it);
121 }
122}
123
Junxiao Shicbba04c2014-01-26 14:21:22 -0700124} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800125} // namespace nfd