NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 const Name Entry::LOCALHOST_NAME("ndn:/localhost");
33 const Name Entry::LOCALHOP_NAME("ndn:/localhop");
34 
35 Entry::Entry(const Interest& interest)
36  : m_interest(interest.shared_from_this())
37 {
38 }
39 
40 const Name&
42 {
43  return m_interest->getName();
44 }
45 
46 bool
48 {
49  return std::any_of(m_inRecords.begin(), m_inRecords.end(),
50  [] (const InRecord& inRecord) { return inRecord.getFace()->isLocal(); });
51 }
52 
53 bool
54 Entry::canForwardTo(const Face& face) const
55 {
57 
58  bool hasUnexpiredOutRecord = std::any_of(m_outRecords.begin(), m_outRecords.end(),
59  [&face, &now] (const OutRecord& outRecord) {
60  return outRecord.getFace().get() == &face && outRecord.getExpiry() >= now;
61  });
62  if (hasUnexpiredOutRecord) {
63  return false;
64  }
65 
66  bool hasUnexpiredOtherInRecord = std::any_of(m_inRecords.begin(), m_inRecords.end(),
67  [&face, &now] (const InRecord& inRecord) {
68  return inRecord.getFace().get() != &face && inRecord.getExpiry() >= now;
69  });
70  if (!hasUnexpiredOtherInRecord) {
71  return false;
72  }
73 
74  return !this->violatesScope(face);
75 }
76 
77 bool
78 Entry::violatesScope(const Face& face) const
79 {
80  // /localhost scope
81  bool isViolatingLocalhost = !face.isLocal() &&
82  LOCALHOST_NAME.isPrefixOf(this->getName());
83  if (isViolatingLocalhost) {
84  return true;
85  }
86 
87  // /localhop scope
88  bool isViolatingLocalhop = !face.isLocal() &&
89  LOCALHOP_NAME.isPrefixOf(this->getName()) &&
90  !this->hasLocalInRecord();
91  if (isViolatingLocalhop) {
92  return true;
93  }
94 
95  return false;
96 }
97 
98 int
99 Entry::findNonce(uint32_t nonce, const Face& face) const
100 {
101  // TODO should we ignore expired in/out records?
102 
103  int dnw = DUPLICATE_NONCE_NONE;
104 
105  for (const InRecord& inRecord : m_inRecords) {
106  if (inRecord.getLastNonce() == nonce) {
107  if (inRecord.getFace().get() == &face) {
109  }
110  else {
112  }
113  }
114  }
115 
116  for (const OutRecord& outRecord : m_outRecords) {
117  if (outRecord.getLastNonce() == nonce) {
118  if (outRecord.getFace().get() == &face) {
120  }
121  else {
123  }
124  }
125  }
126 
127  return dnw;
128 }
129 
131 Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
132 {
133  auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
134  [&face] (const InRecord& inRecord) { return inRecord.getFace() == face; });
135  if (it == m_inRecords.end()) {
136  m_inRecords.emplace_front(face);
137  it = m_inRecords.begin();
138  }
139 
140  it->update(interest);
141  return it;
142 }
143 
144 InRecordCollection::const_iterator
145 Entry::getInRecord(const Face& face) const
146 {
147  return std::find_if(m_inRecords.begin(), m_inRecords.end(),
148  [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
149 }
150 
151 void
153 {
154  m_inRecords.clear();
155 }
156 
158 Entry::insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest)
159 {
160  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
161  [&face] (const OutRecord& outRecord) { return outRecord.getFace() == face; });
162  if (it == m_outRecords.end()) {
163  m_outRecords.emplace_front(face);
164  it = m_outRecords.begin();
165  }
166 
167  it->update(interest);
168  return it;
169 }
170 
171 OutRecordCollection::const_iterator
172 Entry::getOutRecord(const Face& face) const
173 {
174  return std::find_if(m_outRecords.begin(), m_outRecords.end(),
175  [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
176 }
177 
178 void
180 {
181  auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
182  [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
183  if (it != m_outRecords.end()) {
184  m_outRecords.erase(it);
185  }
186 }
187 
188 bool
190 {
192 
193  return std::any_of(m_outRecords.begin(), m_outRecords.end(),
194  [&now] (const OutRecord& outRecord) { return outRecord.getExpiry() >= now; });
195 }
196 
197 } // namespace pit
198 } // namespace nfd
time_point TimePoint
Definition: time.hpp:108
in-record of other face
Definition: pit-entry.hpp:58
InRecordCollection::const_iterator getInRecord(const Face &face) const
get the InRecord for face
Definition: pit-entry.cpp:145
OutRecordCollection::const_iterator getOutRecord(const Face &face) const
get the OutRecord for face
Definition: pit-entry.cpp:172
static time_point now() noexcept
Definition: time.cpp:79
contains information about an Interest from an incoming face
bool canForwardTo(const Face &face) const
decides whether Interest can be forwarded to face
Definition: pit-entry.cpp:54
int findNonce(uint32_t nonce, const Face &face) const
finds where a duplicate Nonce appears
Definition: pit-entry.cpp:99
InRecordCollection::iterator insertOrUpdateInRecord(shared_ptr< Face > face, const Interest &interest)
inserts a InRecord for face, and updates it with interest
Definition: pit-entry.cpp:131
represents an Interest packet
Definition: interest.hpp:45
bool hasLocalInRecord() const
determines whether any InRecord is a local Face
Definition: pit-entry.cpp:47
represents a face
Definition: face.hpp:57
Table::const_iterator iterator
Definition: cs-internal.hpp:41
bool violatesScope(const Face &face) const
decides whether forwarding Interest to face would violate scope
Definition: pit-entry.cpp:78
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
out-record of same face
Definition: pit-entry.hpp:60
const Name & getName() const
Definition: pit-entry.cpp:41
void deleteOutRecord(const Face &face)
deletes one OutRecord for face if exists
Definition: pit-entry.cpp:179
Entry(const Interest &interest)
Definition: pit-entry.cpp:35
Name abstraction to represent an absolute name.
Definition: name.hpp:46
in-record of same face
Definition: pit-entry.hpp:56
void deleteInRecords()
deletes all InRecords
Definition: pit-entry.cpp:152
out-record of other face
Definition: pit-entry.hpp:62
contains information about an Interest toward an outgoing face
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Definition: name.cpp:320
OutRecordCollection::iterator insertOrUpdateOutRecord(shared_ptr< Face > face, const Interest &interest)
inserts a OutRecord for face, and updates it with interest
Definition: pit-entry.cpp:158
bool hasUnexpiredOutRecords() const
Definition: pit-entry.cpp:189
bool isLocal() const
Get whether face is connected to a local app.
Definition: face.hpp:245