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