pit-algorithm.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "pit-algorithm.hpp"
27 
28 namespace nfd {
29 namespace scope_prefix {
30 const Name LOCALHOST("ndn:/localhost");
31 const Name LOCALHOP("ndn:/localhop");
32 } // namespace scope_prefix
33 
34 namespace fw {
35 
36 bool
37 violatesScope(const pit::Entry& pitEntry, const Face& outFace)
38 {
39  if (outFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
40  return false;
41  }
42  BOOST_ASSERT(outFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL);
43 
44  if (scope_prefix::LOCALHOST.isPrefixOf(pitEntry.getName())) {
45  // face is non-local, violates localhost scope
46  return true;
47  }
48 
49  if (scope_prefix::LOCALHOP.isPrefixOf(pitEntry.getName())) {
50  // face is non-local, violates localhop scope unless PIT entry has local in-record
51  return std::none_of(pitEntry.in_begin(), pitEntry.in_end(),
52  [] (const pit::InRecord& inRecord) { return inRecord.getFace().getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
53  }
54 
55  // Name is not subject to scope control
56  return false;
57 }
58 
59 bool
60 canForwardToLegacy(const pit::Entry& pitEntry, const Face& face)
61 {
62  time::steady_clock::TimePoint now = time::steady_clock::now();
63 
64  bool hasUnexpiredOutRecord = std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
65  [&face, &now] (const pit::OutRecord& outRecord) {
66  return &outRecord.getFace() == &face && outRecord.getExpiry() >= now;
67  });
68  if (hasUnexpiredOutRecord) {
69  return false;
70  }
71 
72  bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.in_begin(), pitEntry.in_end(),
73  [&face, &now] (const pit::InRecord& inRecord) {
74  return &inRecord.getFace() != &face && inRecord.getExpiry() >= now;
75  });
76  if (!hasUnexpiredOtherInRecord) {
77  return false;
78  }
79 
80  return !violatesScope(pitEntry, face);
81 }
82 
83 int
84 findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face)
85 {
86  int dnw = DUPLICATE_NONCE_NONE;
87 
88  for (const pit::InRecord& inRecord : pitEntry.getInRecords()) {
89  if (inRecord.getLastNonce() == nonce) {
90  if (&inRecord.getFace() == &face) {
92  }
93  else {
95  }
96  }
97  }
98 
99  for (const pit::OutRecord& outRecord : pitEntry.getOutRecords()) {
100  if (outRecord.getLastNonce() == nonce) {
101  if (&outRecord.getFace() == &face) {
103  }
104  else {
106  }
107  }
108  }
109 
110  return dnw;
111 }
112 
113 bool
115 {
116  time::steady_clock::TimePoint now = time::steady_clock::now();
117  return std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
118  [&now] (const pit::OutRecord& outRecord) {
119  return outRecord.getExpiry() >= now &&
120  outRecord.getIncomingNack() == nullptr;
121  });
122 }
123 
124 } // namespace fw
125 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
const InRecordCollection & getInRecords() const
Definition: pit-entry.hpp:86
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
contains information about an Interest toward an outgoing face
in-record of same face
an Interest table entry
Definition: pit-entry.hpp:57
bool violatesScope(const pit::Entry &pitEntry, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
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
const Name LOCALHOP
ndn:/localhop
InRecordCollection::iterator in_end()
Definition: pit-entry.hpp:115
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
const Name LOCALHOST
ndn:/localhost
no duplicate Nonce is found
int findDuplicateNonce(const pit::Entry &pitEntry, uint32_t nonce, const Face &face)
determine whether pitEntry has duplicate Nonce nonce
OutRecordCollection::iterator out_begin()
Definition: pit-entry.hpp:170
in-record of other face
out-record of other face
OutRecordCollection::iterator out_end()
Definition: pit-entry.hpp:182
const OutRecordCollection & getOutRecords() const
Definition: pit-entry.hpp:152
const Name & getName() const
Definition: pit-entry.hpp:77
InRecordCollection::iterator in_begin()
Definition: pit-entry.hpp:103
out-record of same face