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; -*- */
26 #include "pit-entry.hpp"
27 #include <algorithm>
28 
29 namespace nfd {
30 namespace pit {
31 
32 Entry::Entry(const Interest& interest)
33  : m_interest(interest.shared_from_this())
34  , m_nameTreeEntry(nullptr)
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 
52 {
53  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
54  [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
55 }
56 
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 
91 {
92  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
93  [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
94 }
95 
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 pit
123 } // namespace nfd
OutRecordCollection::iterator getOutRecord(const Face &face)
get the out-record for face
Definition: pit-entry.cpp:90
const Selectors & getSelectors() const
Definition: interest.hpp:234
void clearInRecords()
delete all in-records
Definition: pit-entry.cpp:84
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:51
static const size_t npos
indicates "until the end" in getSubName and compare
Definition: name.hpp:537
represents an Interest packet
Definition: interest.hpp:42
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:113
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:74
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:58
OutRecordCollection::iterator insertOrUpdateOutRecord(Face &face, const Interest &interest)
insert or update an out-record
Definition: pit-entry.cpp:97
contains information about an Interest toward an outgoing face
const Name & getName() const
Definition: interest.hpp:139