blob: 0373e60d22efc86691eb7b15048108cf84ccdd63 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -07003 * 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 Moiseenko76cf77a2014-03-05 14:35:51 -080010 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070011 * 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 Afanasyev4b3fc862014-06-19 14:57:57 -070025 * \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 Shi0fcb41e2014-01-24 10:29:43 -070028 */
29
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070030#ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP
31#define NFD_DAEMON_TABLE_CS_ENTRY_HPP
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080032
33#include "common.hpp"
34
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080035namespace nfd {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070036namespace cs {
37
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080038class Entry;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070039
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080040/** \brief represents a CS entry
41 */
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080042class Entry : noncopyable
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070043{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080044public:
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040045 typedef std::map<int, std::list<Entry*>::iterator > LayerIterators;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080046
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040047 Entry();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040049 /** \brief releases reference counts on shared objects
50 */
51 void
52 release();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080053
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 Afanasyev4b3fc862014-06-19 14:57:57 -070060 /** \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 Moiseenko76cf77a2014-03-05 14:35:51 -080067 /** \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 Moiseenko76cf77a2014-03-05 14:35:51 -080074 /** \brief returns the absolute time when Data becomes expired
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070075 * \return{ Time (resolution up to time::milliseconds) }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080076 */
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070077 const time::steady_clock::TimePoint&
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080078 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 Moiseenko96b80bb2014-04-05 20:53:27 -040088 setData(const Data& data, bool isUnsolicited);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080089
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080090 /** \brief refreshes the time when Data becomes expired
91 * according to the current absolute time.
92 */
93 void
94 updateStaleTime();
95
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080096 /** \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
111private:
112 /** \brief prints <layer, iterator> pairs.
113 */
114 void
115 printIterators() const;
116
117private:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700118 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800119 shared_ptr<const Data> m_dataPacket;
120
121 bool m_isUnsolicited;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800122
123 LayerIterators m_layerIterators;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700124};
125
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400126inline
127Entry::Entry()
128{
129}
130
131inline const Name&
132Entry::getName() const
133{
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -0700134 return m_dataPacket->getName();
135}
136
137inline const Name&
138Entry::getFullName() const
139{
140 return m_dataPacket->getFullName();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400141}
142
143inline const Data&
144Entry::getData() const
145{
146 return *m_dataPacket;
147}
148
149inline bool
150Entry::isUnsolicited() const
151{
152 return m_isUnsolicited;
153}
154
155inline const time::steady_clock::TimePoint&
156Entry::getStaleTime() const
157{
158 return m_staleAt;
159}
160
161inline const Entry::LayerIterators&
162Entry::getIterators() const
163{
164 return m_layerIterators;
165}
166
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800167} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800168} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800169
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700170#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP