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-2018, 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 #include <algorithm>
28 
29 namespace nfd {
30 namespace pit {
31 
32 Entry::Entry(const Interest& interest)
33  : isSatisfied(false)
34  , dataFreshnessPeriod(0_ms)
35  , m_interest(interest.shared_from_this())
36  , m_nameTreeEntry(nullptr)
37 {
38 }
39 
40 bool
41 Entry::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();
50 }
51 
54 {
55  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
56  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
57 }
58 
61 {
62  BOOST_ASSERT(this->canMatch(interest));
63 
64  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
65  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
66  if (it == m_inRecords.end()) {
67  m_inRecords.emplace_front(face);
68  it = m_inRecords.begin();
69  }
70 
71  it->update(interest);
72  return it;
73 }
74 
75 void
77 {
78  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
79  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
80  if (it != m_inRecords.end()) {
81  m_inRecords.erase(it);
82  }
83 }
84 
85 void
87 {
88  m_inRecords.clear();
89 }
90 
93 {
94  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
95  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
96 }
97 
100 {
101  BOOST_ASSERT(this->canMatch(interest));
102 
103  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
104  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
105  if (it == m_outRecords.end()) {
106  m_outRecords.emplace_front(face);
107  it = m_outRecords.begin();
108  }
109 
110  it->update(interest);
111  return it;
112 }
113 
114 void
116 {
117  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
118  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
119  if (it != m_outRecords.end()) {
120  m_outRecords.erase(it);
121  }
122 }
123 
124 } // namespace pit
125 } // namespace nfd
OutRecordCollection::iterator getOutRecord(const Face &face)
get the out-record for face
Definition: pit-entry.cpp:92
const Selectors & getSelectors() const
Definition: interest.hpp:347
void clearInRecords()
delete all in-records
Definition: pit-entry.cpp:86
generalization of a network interface
Definition: face.hpp:67
contains information about an Interest from an incoming face
InRecordCollection::iterator getInRecord(const Face &face)
get the in-record for face
Definition: pit-entry.cpp:53
static const size_t npos
indicates "until the end" in getSubName and compare
Definition: name.hpp:534
Represents an Interest packet.
Definition: interest.hpp:44
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void deleteOutRecord(const Face &face)
delete the out-record for face if it exists
Definition: pit-entry.cpp:115
Entry(const Interest &interest)
Definition: pit-entry.cpp:32
void deleteInRecord(const Face &face)
delete the in-record for face if it exists
Definition: pit-entry.cpp:76
bool canMatch(const Interest &interest, size_t nEqualNameComps=0) const
Definition: pit-entry.cpp:41
InRecordCollection::iterator insertOrUpdateInRecord(Face &face, const Interest &interest)
insert or update an in-record
Definition: pit-entry.cpp:60
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, const Interest &interest)
insert or update an out-record
Definition: pit-entry.cpp:99
contains information about an Interest toward an outgoing face
const Name & getName() const
Definition: interest.hpp:134