NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
cs-entry.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "cs-entry.hpp"
27 
28 namespace nfd {
29 namespace cs {
30 
31 void
32 Entry::setData(shared_ptr<const Data> data, bool isUnsolicited)
33 {
34  m_data = data;
35  m_isUnsolicited = isUnsolicited;
36 
38 }
39 
40 bool
42 {
43  BOOST_ASSERT(this->hasData());
44  return m_staleTime < time::steady_clock::now();
45 }
46 
47 void
49 {
50  BOOST_ASSERT(this->hasData());
51  if (m_data->getFreshnessPeriod() >= time::milliseconds::zero()) {
52  m_staleTime = time::steady_clock::now() + time::milliseconds(m_data->getFreshnessPeriod());
53  }
54  else {
55  m_staleTime = time::steady_clock::TimePoint::max();
56  }
57 }
58 
59 bool
60 Entry::canSatisfy(const Interest& interest) const
61 {
62  BOOST_ASSERT(this->hasData());
63  if (!interest.matchesData(*m_data)) {
64  return false;
65  }
66 
67  if (interest.getMustBeFresh() == static_cast<int>(true) && this->isStale()) {
68  return false;
69  }
70 
71  return true;
72 }
73 
74 void
76 {
77  m_data.reset();
78  m_isUnsolicited = false;
79  m_staleTime = time::steady_clock::TimePoint();
80 }
81 
82 } // namespace cs
83 } // namespace nfd
void reset()
clears the entry
Definition: cs-entry.cpp:75
time_point TimePoint
Definition: time.hpp:120
bool isUnsolicited() const
Definition: cs-entry.hpp:73
int getMustBeFresh() const
Definition: interest.hpp:370
static time_point now() noexcept
Definition: time.cpp:79
void setData(shared_ptr< const Data > data, bool isUnsolicited)
replaces the stored Data
Definition: cs-entry.cpp:32
represents an Interest packet
Definition: interest.hpp:42
bool isStale() const
checks if the stored Data is stale now
Definition: cs-entry.cpp:41
bool hasData() const
Definition: cs-entry.hpp:107
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:132
void updateStaleTime()
refreshes stale time relative to current time
Definition: cs-entry.cpp:48
bool canSatisfy(const Interest &interest) const
determines whether Interest can be satisified by the stored Data
Definition: cs-entry.cpp:60