Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 2 | /* |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
| 26 | #include "pit-entry.hpp" |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 27 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | #include <algorithm> |
| 29 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 30 | namespace nfd { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 31 | namespace pit { |
| 32 | |
| 33 | Entry::Entry(const Interest& interest) |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 34 | : m_interest(interest.shared_from_this()) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 38 | bool |
| 39 | Entry::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 && |
Junxiao Shi | 25d9728 | 2019-05-14 13:44:46 -0600 | [diff] [blame] | 46 | m_interest->getCanBePrefix() == interest.getCanBePrefix() && |
| 47 | m_interest->getMustBeFresh() == interest.getMustBeFresh(); |
| 48 | /// \todo #3162 match ForwardingHint field |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 51 | InRecordCollection::iterator |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 52 | Entry::getInRecord(const Face& face, EndpointId endpointId) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 53 | { |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 54 | return std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 55 | [&face, endpointId] (const InRecord& inRecord) { |
| 56 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 57 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 60 | InRecordCollection::iterator |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 61 | Entry::insertOrUpdateInRecord(Face& face, EndpointId endpointId, const Interest& interest) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 62 | { |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 63 | BOOST_ASSERT(this->canMatch(interest)); |
| 64 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 65 | auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 66 | [&face, endpointId] (const InRecord& inRecord) { |
| 67 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 68 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 69 | if (it == m_inRecords.end()) { |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 70 | m_inRecords.emplace_front(face, endpointId); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 71 | it = m_inRecords.begin(); |
| 72 | } |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 74 | it->update(interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 75 | return it; |
| 76 | } |
| 77 | |
| 78 | void |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 79 | Entry::deleteInRecord(const Face& face, EndpointId endpointId) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 80 | { |
| 81 | auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 82 | [&face, endpointId] (const InRecord& inRecord) { |
| 83 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 84 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 85 | if (it != m_inRecords.end()) { |
| 86 | m_inRecords.erase(it); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 91 | Entry::clearInRecords() |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 92 | { |
| 93 | m_inRecords.clear(); |
| 94 | } |
| 95 | |
| 96 | OutRecordCollection::iterator |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 97 | Entry::getOutRecord(const Face& face, EndpointId endpointId) |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 98 | { |
| 99 | return std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 100 | [&face, endpointId] (const OutRecord& outRecord) { |
| 101 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 102 | }); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | OutRecordCollection::iterator |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 106 | Entry::insertOrUpdateOutRecord(Face& face, EndpointId endpointId, const Interest& interest) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 107 | { |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 108 | BOOST_ASSERT(this->canMatch(interest)); |
| 109 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 110 | auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 111 | [&face, endpointId] (const OutRecord& outRecord) { |
| 112 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 113 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 114 | if (it == m_outRecords.end()) { |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 115 | m_outRecords.emplace_front(face, endpointId); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 116 | it = m_outRecords.begin(); |
| 117 | } |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 118 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 119 | it->update(interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 120 | return it; |
| 121 | } |
| 122 | |
| 123 | void |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 124 | Entry::deleteOutRecord(const Face& face, EndpointId endpointId) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 125 | { |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 126 | auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 127 | [&face, endpointId] (const OutRecord& outRecord) { |
| 128 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 129 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 130 | if (it != m_outRecords.end()) { |
| 131 | m_outRecords.erase(it); |
| 132 | } |
| 133 | } |
| 134 | |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 135 | void |
| 136 | Entry::deleteInOutRecordsByFace(const Face& face) |
| 137 | { |
| 138 | m_inRecords.remove_if([&face] (const InRecord& inRecord) { |
| 139 | return &inRecord.getFace() == &face; |
| 140 | }); |
| 141 | m_outRecords.remove_if([&face] (const OutRecord& outRecord) { |
| 142 | return &outRecord.getFace() == &face; |
| 143 | }); |
| 144 | } |
| 145 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 146 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 147 | } // namespace nfd |