Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 25 | * \author Ilya Moiseenko <http://ilyamoiseenko.com/> |
| 26 | * \author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/> |
| 27 | * \author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 28 | */ |
| 29 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 30 | #ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP |
| 31 | #define NFD_DAEMON_TABLE_CS_ENTRY_HPP |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 32 | |
| 33 | #include "common.hpp" |
| 34 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 35 | namespace nfd { |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 36 | namespace cs { |
| 37 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 38 | class Entry; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 39 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 40 | /** \brief represents a CS entry |
| 41 | */ |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 42 | class Entry : noncopyable |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 43 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 44 | public: |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 45 | typedef std::map<int, std::list<Entry*>::iterator > LayerIterators; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 46 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 47 | Entry(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 48 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 49 | /** \brief releases reference counts on shared objects |
| 50 | */ |
| 51 | void |
| 52 | release(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 53 | |
| 54 | /** \brief returns the name of the Data packet stored in the CS entry |
| 55 | * \return{ NDN name } |
| 56 | */ |
| 57 | const Name& |
| 58 | getName() const; |
| 59 | |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 60 | /** \brief returns the full name (including implicit digest) of the Data packet stored |
| 61 | * in the CS entry |
| 62 | * \return{ NDN name } |
| 63 | */ |
| 64 | const Name& |
| 65 | getFullName() const; |
| 66 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 67 | /** \brief Data packet is unsolicited if this particular NDN node |
| 68 | * did not receive an Interest packet for it, or the Interest packet has already expired |
| 69 | * \return{ True if the Data packet is unsolicited; otherwise False } |
| 70 | */ |
| 71 | bool |
| 72 | isUnsolicited() const; |
| 73 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 74 | /** \brief returns the absolute time when Data becomes expired |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 75 | * \return{ Time (resolution up to time::milliseconds) } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 76 | */ |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 77 | const time::steady_clock::TimePoint& |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 78 | getStaleTime() const; |
| 79 | |
| 80 | /** \brief returns the Data packet stored in the CS entry |
| 81 | */ |
| 82 | const Data& |
| 83 | getData() const; |
| 84 | |
| 85 | /** \brief changes the content of CS entry and recomputes digest |
| 86 | */ |
| 87 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 88 | setData(const Data& data, bool isUnsolicited); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 89 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 90 | /** \brief refreshes the time when Data becomes expired |
| 91 | * according to the current absolute time. |
| 92 | */ |
| 93 | void |
| 94 | updateStaleTime(); |
| 95 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 96 | /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list |
| 97 | */ |
| 98 | void |
| 99 | setIterator(int layer, const LayerIterators::mapped_type& layerIterator); |
| 100 | |
| 101 | /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list |
| 102 | */ |
| 103 | void |
| 104 | removeIterator(int layer); |
| 105 | |
| 106 | /** \brief returns the table containing <layer, iterator> pairs. |
| 107 | */ |
| 108 | const LayerIterators& |
| 109 | getIterators() const; |
| 110 | |
| 111 | private: |
| 112 | /** \brief prints <layer, iterator> pairs. |
| 113 | */ |
| 114 | void |
| 115 | printIterators() const; |
| 116 | |
| 117 | private: |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 118 | time::steady_clock::TimePoint m_staleAt; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 119 | shared_ptr<const Data> m_dataPacket; |
| 120 | |
| 121 | bool m_isUnsolicited; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 122 | |
| 123 | LayerIterators m_layerIterators; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 126 | inline |
| 127 | Entry::Entry() |
| 128 | { |
| 129 | } |
| 130 | |
| 131 | inline const Name& |
| 132 | Entry::getName() const |
| 133 | { |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 134 | return m_dataPacket->getName(); |
| 135 | } |
| 136 | |
| 137 | inline const Name& |
| 138 | Entry::getFullName() const |
| 139 | { |
| 140 | return m_dataPacket->getFullName(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | inline const Data& |
| 144 | Entry::getData() const |
| 145 | { |
| 146 | return *m_dataPacket; |
| 147 | } |
| 148 | |
| 149 | inline bool |
| 150 | Entry::isUnsolicited() const |
| 151 | { |
| 152 | return m_isUnsolicited; |
| 153 | } |
| 154 | |
| 155 | inline const time::steady_clock::TimePoint& |
| 156 | Entry::getStaleTime() const |
| 157 | { |
| 158 | return m_staleAt; |
| 159 | } |
| 160 | |
| 161 | inline const Entry::LayerIterators& |
| 162 | Entry::getIterators() const |
| 163 | { |
| 164 | return m_layerIterators; |
| 165 | } |
| 166 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 167 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 168 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 169 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 170 | #endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP |