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