NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
algorithm.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "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 wouldViolateScope(const Face& inFace, const Interest& interest, const Face& outFace)
38 {
39  if (outFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
40  // forwarding to a local face is always allowed
41  return false;
42  }
43 
44  if (scope_prefix::LOCALHOST.isPrefixOf(interest.getName())) {
45  // localhost Interests cannot be forwarded to a non-local face
46  return true;
47  }
48 
49  if (scope_prefix::LOCALHOP.isPrefixOf(interest.getName())) {
50  // localhop Interests can be forwarded to a non-local face only if it comes from a local face
51  return inFace.getScope() != ndn::nfd::FACE_SCOPE_LOCAL;
52  }
53 
54  // Interest name is not subject to scope control
55  return false;
56 }
57 
58 bool
59 violatesScope(const pit::Entry& pitEntry, const Face& outFace)
60 {
61  if (outFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
62  return false;
63  }
64  BOOST_ASSERT(outFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL);
65 
66  if (scope_prefix::LOCALHOST.isPrefixOf(pitEntry.getName())) {
67  // face is non-local, violates localhost scope
68  return true;
69  }
70 
71  if (scope_prefix::LOCALHOP.isPrefixOf(pitEntry.getName())) {
72  // face is non-local, violates localhop scope unless PIT entry has local in-record
73  return std::none_of(pitEntry.in_begin(), pitEntry.in_end(),
74  [] (const pit::InRecord& inRecord) { return inRecord.getFace().getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
75  }
76 
77  // Name is not subject to scope control
78  return false;
79 }
80 
81 bool
82 canForwardToLegacy(const pit::Entry& pitEntry, const Face& face)
83 {
85 
86  bool hasUnexpiredOutRecord = std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
87  [&face, &now] (const pit::OutRecord& outRecord) {
88  return &outRecord.getFace() == &face && outRecord.getExpiry() >= now;
89  });
90  if (hasUnexpiredOutRecord) {
91  return false;
92  }
93 
94  bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.in_begin(), pitEntry.in_end(),
95  [&face, &now] (const pit::InRecord& inRecord) {
96  return &inRecord.getFace() != &face && inRecord.getExpiry() >= now;
97  });
98  if (!hasUnexpiredOtherInRecord) {
99  return false;
100  }
101 
102  return true;
103 }
104 
105 int
106 findDuplicateNonce(const pit::Entry& pitEntry, uint32_t nonce, const Face& face)
107 {
108  int dnw = DUPLICATE_NONCE_NONE;
109 
110  for (const pit::InRecord& inRecord : pitEntry.getInRecords()) {
111  if (inRecord.getLastNonce() == nonce) {
112  if (&inRecord.getFace() == &face) {
114  }
115  else {
117  }
118  }
119  }
120 
121  for (const pit::OutRecord& outRecord : pitEntry.getOutRecords()) {
122  if (outRecord.getLastNonce() == nonce) {
123  if (&outRecord.getFace() == &face) {
125  }
126  else {
128  }
129  }
130  }
131 
132  return dnw;
133 }
134 
135 bool
137 {
139  return std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
140  [&now] (const pit::OutRecord& outRecord) {
141  return outRecord.getExpiry() >= now &&
142  outRecord.getIncomingNack() == nullptr;
143  });
144 }
145 
146 } // namespace fw
147 } // namespace nfd
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
Definition: algorithm.cpp:82
time_point TimePoint
Definition: time.hpp:120
const InRecordCollection & getInRecords() const
Definition: pit-entry.hpp:93
const Name LOCALHOST("ndn:/localhost")
ndn:/localhost
Definition: algorithm.hpp:50
generalization of a network interface
Definition: face.hpp:67
static time_point now() noexcept
Definition: time.cpp:79
contains information about an Interest from an incoming face
OutRecordCollection::iterator out_end()
Definition: pit-entry.hpp:189
represents an Interest packet
Definition: interest.hpp:42
OutRecordCollection::iterator out_begin()
Definition: pit-entry.hpp:177
in-record of same face
Definition: algorithm.hpp:101
bool violatesScope(const pit::Entry &pitEntry, const Face &outFace)
Definition: algorithm.cpp:59
InRecordCollection::iterator in_end()
Definition: pit-entry.hpp:122
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:265
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const Name LOCALHOP("ndn:/localhop")
ndn:/localhop
Definition: algorithm.hpp:64
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
Definition: algorithm.cpp:136
no duplicate Nonce is found
Definition: algorithm.hpp:100
int findDuplicateNonce(const pit::Entry &pitEntry, uint32_t nonce, const Face &face)
determine whether pitEntry has duplicate Nonce nonce
Definition: algorithm.cpp:106
InRecordCollection::iterator in_begin()
Definition: pit-entry.hpp:110
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
const Name & getName() const
Definition: pit-entry.hpp:77
contains information about an Interest toward an outgoing face
in-record of other face
Definition: algorithm.hpp:102
out-record of other face
Definition: algorithm.hpp:104
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
Definition: algorithm.cpp:37
const OutRecordCollection & getOutRecords() const
Definition: pit-entry.hpp:159
const Name & getName() const
Definition: interest.hpp:215
out-record of same face
Definition: algorithm.hpp:103