pit-entry.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, 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.
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/>.
24  */
25 
26 #include "pit-entry.hpp"
27 
28 #include <algorithm>
29 
30 namespace nfd::pit {
31 
32 Entry::Entry(const Interest& interest)
33  : m_interest(interest.shared_from_this())
34 {
35 }
36 
37 bool
38 Entry::canMatch(const Interest& interest, size_t nEqualNameComps) const
39 {
40  BOOST_ASSERT(m_interest->getName().compare(0, nEqualNameComps,
41  interest.getName(), 0, nEqualNameComps) == 0);
42 
43  return m_interest->getName().compare(nEqualNameComps, Name::npos,
44  interest.getName(), nEqualNameComps) == 0 &&
45  m_interest->getCanBePrefix() == interest.getCanBePrefix() &&
46  m_interest->getMustBeFresh() == interest.getMustBeFresh();
48 }
49 
50 InRecordCollection::iterator
52 {
53  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
54  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
55 }
56 
57 InRecordCollection::iterator
58 Entry::insertOrUpdateInRecord(Face& face, const Interest& interest)
59 {
60  BOOST_ASSERT(this->canMatch(interest));
61 
62  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
63  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
64  if (it == m_inRecords.end()) {
65  m_inRecords.emplace_front(face);
66  it = m_inRecords.begin();
67  }
68 
69  it->update(interest);
70  return it;
71 }
72 
73 void
75 {
76  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
77  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
78  if (it != m_inRecords.end()) {
79  m_inRecords.erase(it);
80  }
81 }
82 
83 void
85 {
86  m_inRecords.clear();
87 }
88 
89 OutRecordCollection::iterator
91 {
92  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
93  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
94 }
95 
96 OutRecordCollection::iterator
97 Entry::insertOrUpdateOutRecord(Face& face, const Interest& interest)
98 {
99  BOOST_ASSERT(this->canMatch(interest));
100 
101  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
102  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
103  if (it == m_outRecords.end()) {
104  m_outRecords.emplace_front(face);
105  it = m_outRecords.begin();
106  }
107 
108  it->update(interest);
109  return it;
110 }
111 
112 void
114 {
115  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
116  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
117  if (it != m_outRecords.end()) {
118  m_outRecords.erase(it);
119  }
120 }
121 
122 } // namespace nfd::pit
Generalization of a network interface.
Definition: face.hpp:56
bool canMatch(const Interest &interest, size_t nEqualNameComps=0) const
Definition: pit-entry.cpp:38
InRecordCollection::iterator getInRecord(const Face &face)
Get the in-record for face.
Definition: pit-entry.cpp:51
void deleteInRecord(const Face &face)
Delete the in-record for face if it exists.
Definition: pit-entry.cpp:74
Entry(const Interest &interest)
Definition: pit-entry.cpp:32
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, const Interest &interest)
Insert or update an out-record.
Definition: pit-entry.cpp:97
void clearInRecords()
Delete all in-records.
Definition: pit-entry.cpp:84
InRecordCollection::iterator insertOrUpdateInRecord(Face &face, const Interest &interest)
Insert or update an in-record.
Definition: pit-entry.cpp:58
OutRecordCollection::iterator getOutRecord(const Face &face)
Get the out-record for face.
Definition: pit-entry.cpp:90
void deleteOutRecord(const Face &face)
Delete the out-record for face if it exists.
Definition: pit-entry.cpp:113
Contains information about an Interest from an incoming face.
Contains information about an Interest toward an outgoing face.
Definition: fib.hpp:40