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-2019, 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 {
31 namespace pit {
32 
33 Entry::Entry(const Interest& interest)
34  : m_interest(interest.shared_from_this())
35 {
36 }
37 
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 &&
46  m_interest->getSelectors() == interest.getSelectors();
48 }
49 
51 Entry::getInRecord(const Face& face, EndpointId endpointId)
52 {
53  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
54  [&face, endpointId] (const InRecord& inRecord) {
55  return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
56  });
57 }
58 
60 Entry::insertOrUpdateInRecord(Face& face, EndpointId endpointId, const Interest& interest)
61 {
62  BOOST_ASSERT(this->canMatch(interest));
63 
64  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
65  [&face, endpointId] (const InRecord& inRecord) {
66  return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
67  });
68  if (it == m_inRecords.end()) {
69  m_inRecords.emplace_front(face, endpointId);
70  it = m_inRecords.begin();
71  }
72 
73  it->update(interest);
74  return it;
75 }
76 
77 void
78 Entry::deleteInRecord(const Face& face, EndpointId endpointId)
79 {
80  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
81  [&face, endpointId] (const InRecord& inRecord) {
82  return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
83  });
84  if (it != m_inRecords.end()) {
85  m_inRecords.erase(it);
86  }
87 }
88 
89 void
91 {
92  m_inRecords.clear();
93 }
94 
96 Entry::getOutRecord(const Face& face, EndpointId endpointId)
97 {
98  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
99  [&face, endpointId] (const OutRecord& outRecord) {
100  return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
101  });
102 }
103 
105 Entry::insertOrUpdateOutRecord(Face& face, EndpointId endpointId, const Interest& interest)
106 {
107  BOOST_ASSERT(this->canMatch(interest));
108 
109  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
110  [&face, endpointId] (const OutRecord& outRecord) {
111  return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
112  });
113  if (it == m_outRecords.end()) {
114  m_outRecords.emplace_front(face, endpointId);
115  it = m_outRecords.begin();
116  }
117 
118  it->update(interest);
119  return it;
120 }
121 
122 void
123 Entry::deleteOutRecord(const Face& face, EndpointId endpointId)
124 {
125  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
126  [&face, endpointId] (const OutRecord& outRecord) {
127  return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
128  });
129  if (it != m_outRecords.end()) {
130  m_outRecords.erase(it);
131  }
132 }
133 
134 void
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 
145 } // namespace pit
146 } // namespace nfd
InRecordCollection::iterator insertOrUpdateInRecord(Face &face, EndpointId endpointId, const Interest &interest)
insert or update an in-record
Definition: pit-entry.cpp:60
Contains information about an Interest toward an outgoing face.
OutRecordCollection::iterator getOutRecord(const Face &face, EndpointId endpointId)
get the out-record for face and endpointId
Definition: pit-entry.cpp:96
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, EndpointId endpointId, const Interest &interest)
insert or update an out-record
Definition: pit-entry.cpp:105
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void clearInRecords()
delete all in-records
Definition: pit-entry.cpp:90
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:38
bool canMatch(const Interest &interest, size_t nEqualNameComps=0) const
Definition: pit-entry.cpp:39
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
Contains information about an Interest from an incoming face.
InRecordCollection::iterator getInRecord(const Face &face, EndpointId endpointId)
get the in-record for face and endpointId
Definition: pit-entry.cpp:51
Face & getFace() const
Entry(const Interest &interest)
Definition: pit-entry.cpp:33
void deleteOutRecord(const Face &face, EndpointId endpointId)
delete the out-record for face and endpointId if it exists
Definition: pit-entry.cpp:123
void deleteInRecord(const Face &face, EndpointId endpointId)
delete the in-record for face and endpointId if it exists
Definition: pit-entry.cpp:78
void deleteInOutRecordsByFace(const Face &face)
delete all in-records and out-records for face if it exists
Definition: pit-entry.cpp:135