NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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->getCanBePrefix() == interest.getCanBePrefix() &&
47  m_interest->getMustBeFresh() == interest.getMustBeFresh();
49 }
50 
51 InRecordCollection::iterator
53 {
54  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
55  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
56 }
57 
58 InRecordCollection::iterator
60 {
61  BOOST_ASSERT(this->canMatch(interest));
62 
63  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
64  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
65  if (it == m_inRecords.end()) {
66  m_inRecords.emplace_front(face);
67  it = m_inRecords.begin();
68  }
69 
70  it->update(interest);
71  return it;
72 }
73 
74 void
76 {
77  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
78  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
79  if (it != m_inRecords.end()) {
80  m_inRecords.erase(it);
81  }
82 }
83 
84 void
86 {
87  m_inRecords.clear();
88 }
89 
90 OutRecordCollection::iterator
92 {
93  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
94  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
95 }
96 
97 OutRecordCollection::iterator
99 {
100  BOOST_ASSERT(this->canMatch(interest));
101 
102  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
103  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
104  if (it == m_outRecords.end()) {
105  m_outRecords.emplace_front(face);
106  it = m_outRecords.begin();
107  }
108 
109  it->update(interest);
110  return it;
111 }
112 
113 void
115 {
116  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
117  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
118  if (it != m_outRecords.end()) {
119  m_outRecords.erase(it);
120  }
121 }
122 
123 } // namespace pit
124 } // namespace nfd
bool getMustBeFresh() const noexcept
Check whether the MustBeFresh element is present.
Definition: interest.hpp:205
OutRecordCollection::iterator getOutRecord(const Face &face)
get the out-record for face
Definition: pit-entry.cpp:91
void clearInRecords()
delete all in-records
Definition: pit-entry.cpp:85
Contains information about an Interest from an incoming face.
bool getCanBePrefix() const noexcept
Check whether the CanBePrefix element is present.
Definition: interest.hpp:186
InRecordCollection::iterator getInRecord(const Face &face)
get the in-record for face
Definition: pit-entry.cpp:52
static const size_t npos
Indicates "until the end" in getSubName() and compare().
Definition: name.hpp:696
Represents an Interest packet.
Definition: interest.hpp:48
ndn Face
Definition: face-impl.hpp:42
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
void deleteOutRecord(const Face &face)
delete the out-record for face if it exists
Definition: pit-entry.cpp:114
Entry(const Interest &interest)
Definition: pit-entry.cpp:33
void deleteInRecord(const Face &face)
delete the in-record for face if it exists
Definition: pit-entry.cpp:75
bool canMatch(const Interest &interest, size_t nEqualNameComps=0) const
Definition: pit-entry.cpp:39
InRecordCollection::iterator insertOrUpdateInRecord(Face &face, const Interest &interest)
insert or update an in-record
Definition: pit-entry.cpp:59
const Name & getName() const noexcept
Definition: interest.hpp:172
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, const Interest &interest)
insert or update an out-record
Definition: pit-entry.cpp:98
Contains information about an Interest toward an outgoing face.