blob: ace9847bd26b2e2b14b31bf688cbb0c473b32701 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 * Zhenkai Zhu
6 *
7 * BSD license, See the LICENSE file for more information
8 *
9 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
10 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
11 */
12
13#ifndef NDN_INTEREST_H
14#define NDN_INTEREST_H
15
16#include <ndn-cpp/common.h>
17#include <ndn-cpp/fields/name.h>
18#include <ndn-cpp/fields/exclude.h>
19#include <ndn-cpp/helpers/hash.h>
20
21namespace ndn {
22
Jeff Thompson4454bf72013-06-18 13:33:12 -070023class Interest;
Jeff Thompsonfa306642013-06-17 15:06:57 -070024/**
25 * @brief Class abstracting operations with Interests (constructing and getting access to Interest fields)
26 */
27class Interest
28{
29public:
30 /**
31 * @brief Default constructor, creates an interest for / prefix without any selectors
32 */
33 Interest ();
34
35 /**
36 * @brief Create an interest for the name
37 * @param name name of the data to request
38 */
39 Interest (const Name &name);
40
41 /**
42 * @brief Copy constructor
43 * @param interest interest to copy
44 */
45 Interest (const Interest &interest);
46
47 /**
Jeff Thompsonfa306642013-06-17 15:06:57 -070048 * @brief Set interest name
49 * @param name name of the interest
50 * @return reference to self (to allow method chaining)
51 *
52 * In some cases, a direct access to and manipulation of name using getName is more efficient
53 */
54 inline Interest &
55 setName (const Name &name);
56
57 /**
58 * @brief Get interest name (const reference)
59 * @returns name of the interest
60 */
61 inline const Name &
62 getName () const;
63
64 /**
65 * @brief Get interest name (reference)
66 * @returns name of the interest
67 */
68 inline Name &
69 getName ();
70
71 /**
72 * @brief Set interest lifetime (time_duration)
73 * @param interestLifetime interest lifetime specified as a time_duration value.
74 * Negative value means that InterestLifetime is not set.
75 * @return reference to self (to allow method chaining)
76 */
77 inline Interest &
78 setInterestLifetime (const TimeInterval &interestLifetime);
79
80 /**
81 * @brief Set interest lifetime (double)
82 * @param interestLifetime interest lifetime expressed in seconds, with possible fractional seconds (double).
83 * Negative value means that InterestLifetime is not set.
84 * @return reference to self (to allow method chaining)
85 */
86 inline Interest &
87 setInterestLifetime (double interestLifetimeSeconds);
88
89 /**
90 * @brief Get interest lifetime
91 * @return TimeInterval representing lifetime of the interest.
92 * Use time_duration::total_seconds () or time_duration::total_microseconds (),
93 * if you need interest lifetime as a plain number.
94 * @see http://www.boost.org/doc/libs/1_53_0/doc/html/date_time/posix_time.html
95 */
96 inline const TimeInterval &
97 getInterestLifetime () const;
98
99 /**
100 * @brief Set intended interest scope
101 * @param scope requested scope of the interest @see Scope
102 * @return reference to self (to allow method chaining)
103 */
104 inline Interest &
105 setScope (uint8_t scope);
106
107 /**
108 * @brief Get intended interest scope
109 * @return intended interest scope @see Scope
110 */
111 inline uint8_t
112 getScope () const;
113
114 ///////////////////////////////////////////////////////////////////////
115 // SELECTORS //
116 ///////////////////////////////////////////////////////////////////////
117
118 /**
119 * @brief Enum defining constants for AnswerOriginKind selector field
120 */
121 enum AnswerOriginKind
122 {
123 AOK_CS = 0x1, ///< @brief request item from the content store
124 AOK_NEW = 0x2, ///< @brief request item from the original producer
125 AOK_DEFAULT = 0x3, ///< @brief default: either from content store or original producer
126 AOK_STALE = 0x4, ///< @brief Allow stale data
127 AOK_EXPIRE = 0x10 ///< @brief Allow expired data (?)
128 };
129
130 /**
131 * @brief Enum defining constants for ChildSelector field
132 */
133 enum ChildSelector
134 {
135 CHILD_LEFT = 0, ///< @brief request left child
136 CHILD_RIGHT = 1, ///< @brief request right child
137 CHILD_DEFAULT = 2 ///< @brief do not specify which child is requested
138 };
139
140 /**
141 * @brief Enum defining constants for Scope field
142 */
143 enum Scope
144 {
145 NO_SCOPE = 255, ///< @brief Interest scope is not defined
146 SCOPE_LOCAL_CCND = 0, ///< @brief Interest scope is only toward local NDN daemon
147 SCOPE_LOCAL_HOST = 1, ///< @brief Interest scope is within local host (any local application only)
148 SCOPE_NEXT_HOST = 2 ///< @brief Interest scope is within local host and immediate neighboring node
149 };
150
151 /**
152 * @brief Set interest selector for maximum suffix components
153 * @param maxSuffixComponents maximum number of suffix components. If Interest::ncomps, then not restricted
154 * @return reference to self (to allow method chaining)
155 */
156 inline Interest &
157 setMaxSuffixComponents (uint32_t maxSuffixComponents);
158
159 /**
160 * \brief Get interest selector for maximum suffix components
161 *
162 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
163 * and counting the implicit digest, that may occur in the matching ContentObject.
164 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
165 **/
166 inline uint32_t
167 getMaxSuffixComponents () const;
168
169 /**
170 * @brief Set interest selector for minimum suffix components
171 * @param minSuffixComponents minimum number of suffix components. If Interest::ncomps, then not restricted
172 * @return reference to self (to allow method chaining)
173 */
174 inline Interest &
175 setMinSuffixComponents (uint32_t minSuffixComponents);
176
177 /**
178 * \brief Get interest selector for minimum suffix components
179 *
180 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
181 * and counting the implicit digest, that may occur in the matching ContentObject.
182 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
183 **/
184 inline uint32_t
185 getMinSuffixComponents () const;
186
187 /**
188 * @brief Set interest selector for answer origin kind
189 * @param answerOriginKind type of answer @see AnswerOriginKind
190 * @return reference to self (to allow method chaining)
191 */
192 inline Interest &
193 setAnswerOriginKind (uint32_t answerOriginKind);
194
195 /**
196 * @brief Get interest selector for answer origin kind
197 */
198 inline uint32_t
199 getAnswerOriginKind () const;
200
201 /**
202 * @brief Set interest selector for child selector
203 * @param child child selector @see ChildSelector
204 * @return reference to self (to allow method chaining)
205 *
206 * Often a given interest will match more than one ContentObject within a given content store.
207 * The ChildSelector provides a way of expressing a preference for which of these should be returned.
208 * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
209 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
210 */
211 inline Interest &
212 setChildSelector (uint8_t child);
213
214 /**
215 * @brief Get interest selector for child selector
216 */
217 inline uint8_t
218 getChildSelector () const;
219
220 /**
221 * @brief Set interest selector for publisher public key digest
222 * @param digest publisher public key digest
223 * @return reference to self (to allow method chaining)
224 *
225 * Currently, this method has no effect
226 * @todo Implement PublisherPublicKeyDigest
227 */
228 inline Interest &
229 setPublisherPublicKeyDigest(const Hash &digest);
230
231 /**
232 * @brief Get interest selector for publisher public key digest
233 *
234 * @todo Implement
235 */
236 inline const Hash&
237 getPublisherPublicKeyDigest () const;
238
239 /**
240 * @brief Set exclude filter
241 * @param exclude An exclude filter to set
242 *
243 * In some cases, a direct access to and manipulation of exclude filter using getExclude is more efficient
244 */
245 inline void
246 setExclude (const Exclude &exclude);
247
248 /**
249 * @brief Get exclude filter (const reference)
250 */
251 inline const Exclude &
252 getExclude () const;
253
254 /**
255 * @brief Get exclude filter (reference)
256 */
257 inline Exclude &
258 getExclude ();
259
260 ///////////////////////////////////////////////////////////////////////
261 // HELPERS //
262 ///////////////////////////////////////////////////////////////////////
263
264 /**
265 * @brief Compare equality of two interests
266 */
267 bool
268 operator== (const Interest &interest);
269
270public:
271 // Data Members (public):
272 /// @brief Value indicating that number of components parameter is invalid
273 const static uint32_t ncomps = static_cast<uint32_t> (-1);
274
275private:
276 Name m_name;
277 uint32_t m_maxSuffixComponents;
278 uint32_t m_minSuffixComponents;
279 uint32_t m_answerOriginKind;
280 TimeInterval m_interestLifetime; // lifetime in seconds
281
282 uint8_t m_scope;
283 uint8_t m_childSelector;
284 // not used now
285 Hash m_publisherPublicKeyDigest;
286 Exclude m_exclude;
287
Jeff Thompson29310402013-06-19 13:32:26 -0700288 ptr_lib::shared_ptr<Blob> m_wire;
Jeff Thompsonfa306642013-06-17 15:06:57 -0700289};
290
Jeff Thompsonfa306642013-06-17 15:06:57 -0700291namespace Error
292{
293/**
294 * @brief Exception that is thrown in case of error during interest construction or parsing
295 */
296struct Interest:
297 virtual boost::exception, virtual std::exception {};
298}
299
300
301
302inline Interest &
303Interest::setName (const Name &name)
304{
305 m_name = name;
306 return *this;
307}
308
309inline const Name &
310Interest::getName () const
311{
312 return m_name;
313}
314
315inline Name &
316Interest::getName ()
317{
318 return m_name;
319}
320
321inline Interest &
322Interest::setInterestLifetime (const TimeInterval &interestLifetime)
323{
324 m_interestLifetime = interestLifetime;
325 return *this;
326}
327
328inline Interest &
329Interest::setInterestLifetime (double interestLifetimeSeconds)
330{
331 m_interestLifetime = time::Seconds (interestLifetimeSeconds);
332 return *this;
333}
334
335inline const TimeInterval &
336Interest::getInterestLifetime () const
337{
338 return m_interestLifetime;
339}
340
341inline Interest &
342Interest::setScope (uint8_t scope)
343{
344 m_scope = scope;
345 return *this;
346}
347
348inline uint8_t
349Interest::getScope () const
350{
351 return m_scope;
352}
353
354///////////////////////////////////////////////////////////////////////
355// SELECTORS //
356///////////////////////////////////////////////////////////////////////
357
358
359inline Interest &
360Interest::setMaxSuffixComponents (uint32_t maxSuffixComponents)
361{
362 m_maxSuffixComponents = maxSuffixComponents;
363 return *this;
364}
365
366inline uint32_t
367Interest::getMaxSuffixComponents () const
368{
369 return m_maxSuffixComponents;
370}
371
372inline Interest &
373Interest::setMinSuffixComponents (uint32_t minSuffixComponents)
374{
375 m_minSuffixComponents = minSuffixComponents;
376 return *this;
377}
378
379inline uint32_t
380Interest::getMinSuffixComponents () const
381{
382 return m_minSuffixComponents;
383}
384
385inline Interest &
386Interest::setAnswerOriginKind (uint32_t answerOriginKind)
387{
388 m_answerOriginKind = answerOriginKind;
389 return *this;
390}
391
392inline uint32_t
393Interest::getAnswerOriginKind () const
394{
395 return m_answerOriginKind;
396}
397
398inline Interest &
399Interest::setChildSelector (uint8_t childSelector)
400{
401 m_childSelector = childSelector;
402 return *this;
403}
404
405inline uint8_t
406Interest::getChildSelector () const
407{
408 return m_childSelector;
409}
410
411inline Interest &
412Interest::setPublisherPublicKeyDigest(const Hash &publisherPublicKeyDigest)
413{
414 m_publisherPublicKeyDigest = publisherPublicKeyDigest;
415 return *this;
416}
417
418inline const Hash&
419Interest::getPublisherPublicKeyDigest () const
420{
421 return m_publisherPublicKeyDigest;
422}
423
424inline void
425Interest::setExclude (const Exclude &exclude)
426{
427 m_exclude = exclude;
428}
429
430/**
431 * @brief Get exclude filter (const reference)
432 */
433inline const Exclude &
434Interest::getExclude () const
435{
436 return m_exclude;
437}
438
439/**
440 * @brief Get exclude filter (reference)
441 */
442inline Exclude &
443Interest::getExclude ()
444{
445 return m_exclude;
446}
447
448
449} // ndn
450
451#endif // NDN_INTEREST_H