blob: 106fbf095df6b4bf16efe5e602b73f93bc6ecf88 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08002/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080020 */
21
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080022#include "interest.hpp"
Junxiao Shi2af905b2014-11-27 13:10:54 -070023#include "interest-filter.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070024#include "data.hpp"
25#include "security/signature-sha256-with-rsa.hpp"
Yingdi Yubf6a2812014-06-17 15:32:11 -070026#include "security/digest-sha256.hpp"
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -070027#include "security/key-chain.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070028#include "encoding/buffer-stream.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070029
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030#include "boost-test.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080031
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080032namespace ndn {
Alexander Afanasyev90164962014-03-06 08:29:59 +000033namespace tests {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080034
35BOOST_AUTO_TEST_SUITE(TestInterest)
36
37const uint8_t Interest1[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070038 0x05, 0x59, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080039 0x07, 0x14, // Name
40 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080041 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080042 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080043 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080044 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080045 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070046 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080047 0x0d, 0x1, 0x1, // MinSuffix
48 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070049 0x1c, 0x16, // KeyLocator
50 0x07, 0x14, // Name
51 0x08, 0x04,
52 0x74, 0x65, 0x73, 0x74,
53 0x08, 0x03,
54 0x6b, 0x65, 0x79,
55 0x08, 0x07,
56 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080057 0x10, 0x14, // Exclude
58 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080059 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080060 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080061 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080062 0x13, 0x0, // Any
63 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080064 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080065 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080066 0x1,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030067 0x0a, 0x4, // Nonce
68 0x1, 0x0, 0x0, 0x00,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030069 0x0c, // InterestLifetime
70 0x2, 0x3, 0xe8
71};
72
73const uint8_t Interest2[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070074 0x05, 0x59, // NDN Interest
Alexander Afanasyeve881e932014-06-08 14:47:03 +030075 0x07, 0x14, // Name
76 0x08, 0x5, // NameComponent
77 0x6c, 0x6f, 0x63, 0x61, 0x6c,
78 0x08, 0x3, // NameComponent
79 0x6e, 0x64, 0x6e,
80 0x08, 0x6, // NameComponent
81 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
82 0x09, 0x37, // Selectors
83 0x0d, 0x1, 0x1, // MinSuffix
84 0x0e, 0x1, 0x1, // MaxSuffix
85 0x1c, 0x16, // KeyLocator
86 0x07, 0x14, // Name
87 0x08, 0x04,
88 0x74, 0x65, 0x73, 0x74,
89 0x08, 0x03,
90 0x6b, 0x65, 0x79,
91 0x08, 0x07,
92 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
93 0x10, 0x14, // Exclude
94 0x08, 0x4, // NameComponent
95 0x61, 0x6c, 0x65, 0x78,
96 0x08, 0x4, // NameComponent
97 0x78, 0x78, 0x78, 0x78,
98 0x13, 0x0, // Any
99 0x08, 0x4, // NameComponent
100 0x79, 0x79, 0x79, 0x79,
101 0x11, 0x1, // ChildSelector
102 0x1,
103 0x0a, 0x4, // Nonce
104 0x2, 0x0, 0x0, 0x00,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800105 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800106 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800107};
108
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700109const uint8_t InterestWithLink[] = {
110 0x05, 0xfb, // Interest
111 0x07, 0x14, // Name
112 0x08, 0x5, // NameComponent
113 0x6c, 0x6f, 0x63, 0x61, 0x6c,
114 0x08, 0x3, // NameComponent
115 0x6e, 0x64, 0x6e,
116 0x08, 0x6, // NameComponent
117 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
118 0x0a, 0x4, // Nonce
119 0x1, 0x0, 0x0, 0x00,
120 0x06, 0xda, // Data
121 0x07, 0x14, // Name
122 0x08, 0x05,
123 0x6c, 0x6f, 0x63, 0x61, 0x6c,
124 0x08, 0x03,
125 0x6e, 0x64, 0x6e,
126 0x08, 0x06,
127 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
128 0x14, 0x07, // MetaInfo
129 0x18, 0x01, // ContentType
130 0x01,
131 0x19, 0x02, // FreshnessPeriod
132 0x27, 0x10,
133 0x15, 0x1a, // Content
134 0x1f, 0x0c, // LinkDelegation
135 0x1e, 0x01, // LinkPreference
136 0x0a,
137 0x07, 0x07, // Name
138 0x08, 0x05,
139 0x6c, 0x6f, 0x63, 0x61, 0x6c,
140 0x1f, 0x0a, // LinkDelegation
141 0x1e, 0x01, // LinkPreference
142 0x14,
143 0x07, 0x05, // Name
144 0x08, 0x03,
145 0x6e, 0x64, 0x6e,
146 0x16, 0x1b, // SignatureInfo
147 0x1b, 0x01, // SignatureType
148 0x01,
149 0x1c, 0x16, // KeyLocator
150 0x07, 0x14, // Name
151 0x08, 0x04,
152 0x74, 0x65, 0x73, 0x74,
153 0x08, 0x03,
154 0x6b, 0x65, 0x79,
155 0x08, 0x07,
156 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
157 0x17, 0x80, // SignatureValue
158 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
159 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
160 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
161 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
162 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
163 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
164 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
165 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
166 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
167 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
168 0x20, 0x01, // SelectedDelegation
169 0x00
170};
171
172const uint8_t InterestWithLinkMissingContentType[] = {
173 0x05, 0xf8, // Interest
174 0x07, 0x14, // Name
175 0x08, 0x5, // NameComponent
176 0x6c, 0x6f, 0x63, 0x61, 0x6c,
177 0x08, 0x3, // NameComponent
178 0x6e, 0x64, 0x6e,
179 0x08, 0x6, // NameComponent
180 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
181 0x0a, 0x4, // Nonce
182 0x1, 0x0, 0x0, 0x00,
183 0x06, 0xd7, // Data
184 0x07, 0x14, // Name
185 0x08, 0x05,
186 0x6c, 0x6f, 0x63, 0x61, 0x6c,
187 0x08, 0x03,
188 0x6e, 0x64, 0x6e,
189 0x08, 0x06,
190 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
191 0x14, 0x04, // MetaInfo
192 0x19, 0x02, // FreshnessPeriod
193 0x27, 0x10,
194 0x15, 0x1a, // Content
195 0x1f, 0x0c, // LinkDelegation
196 0x1e, 0x01, // LinkPreference
197 0x0a,
198 0x07, 0x07, // Name
199 0x08, 0x05,
200 0x6c, 0x6f, 0x63, 0x61, 0x6c,
201 0x1f, 0x0a, // LinkDelegation
202 0x1e, 0x01, // LinkPreference
203 0x14,
204 0x07, 0x05, // Name
205 0x08, 0x03,
206 0x6e, 0x64, 0x6e,
207 0x16, 0x1b, // SignatureInfo
208 0x1b, 0x01, // SignatureType
209 0x01,
210 0x1c, 0x16, // KeyLocator
211 0x07, 0x14, // Name
212 0x08, 0x04,
213 0x74, 0x65, 0x73, 0x74,
214 0x08, 0x03,
215 0x6b, 0x65, 0x79,
216 0x08, 0x07,
217 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
218 0x17, 0x80, // SignatureValue
219 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
220 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
221 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
222 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
223 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
224 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
225 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
226 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
227 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
228 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
229 0x20, 0x01, // SelectedDelegation
230 0x00
231};
232
233const uint8_t InterestWithLinkNoMetaInfo[] = {
234 0x05, 0xf2, // Interest
235 0x07, 0x14, // Name
236 0x08, 0x5, // NameComponent
237 0x6c, 0x6f, 0x63, 0x61, 0x6c,
238 0x08, 0x3, // NameComponent
239 0x6e, 0x64, 0x6e,
240 0x08, 0x6, // NameComponent
241 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
242 0x0a, 0x4, // Nonce
243 0x1, 0x0, 0x0, 0x00,
244 0x06, 0xd1, // Data
245 0x07, 0x14, // Name
246 0x08, 0x05,
247 0x6c, 0x6f, 0x63, 0x61, 0x6c,
248 0x08, 0x03,
249 0x6e, 0x64, 0x6e,
250 0x08, 0x06,
251 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
252 0x15, 0x1a, // Content
253 0x1f, 0x0c, // LinkDelegation
254 0x1e, 0x01, // LinkPreference
255 0x0a,
256 0x07, 0x07, // Name
257 0x08, 0x05,
258 0x6c, 0x6f, 0x63, 0x61, 0x6c,
259 0x1f, 0x0a, // LinkPreference
260 0x1e, 0x01, // LinkPreference
261 0x14,
262 0x07, 0x05, // Name
263 0x08, 0x03,
264 0x6e, 0x64, 0x6e,
265 0x16, 0x1b, // SignatureInfo
266 0x1b, 0x01, // SignatureType
267 0x01,
268 0x1c, 0x16, // KeyLocator
269 0x07, 0x14, // Name
270 0x08, 0x04,
271 0x74, 0x65, 0x73, 0x74,
272 0x08, 0x03,
273 0x6b, 0x65, 0x79,
274 0x08, 0x07,
275 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
276 0x17, 0x80, // SignatureValue
277 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
278 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
279 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
280 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
281 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
282 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
283 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
284 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
285 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
286 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
287 0x20, 0x01, // SelectedDelegation
288 0x00
289};
290
291const uint8_t InterestWithLinkWrongContentType[] = {
292 0x05, 0xfb, // Interest
293 0x07, 0x14, // Name
294 0x08, 0x5, // NameComponent
295 0x6c, 0x6f, 0x63, 0x61, 0x6c,
296 0x08, 0x3, // NameComponent
297 0x6e, 0x64, 0x6e,
298 0x08, 0x6, // NameComponent
299 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
300 0x0a, 0x4, // Nonce
301 0x1, 0x0, 0x0, 0x00,
302 0x06, 0xda, // Data
303 0x07, 0x14, // Name
304 0x08, 0x05,
305 0x6c, 0x6f, 0x63, 0x61, 0x6c,
306 0x08, 0x03,
307 0x6e, 0x64, 0x6e,
308 0x08, 0x06,
309 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
310 0x14, 0x07, // MetaInfo
311 0x18, 0x01, // ContentType
312 0x00,
313 0x19, 0x02, // FreshnessPeriod
314 0x27, 0x10,
315 0x15, 0x1a, // Content
316 0x1f, 0x0c, // LinkDelegation
317 0x1e, 0x01, // LinkPreference
318 0x0a,
319 0x07, 0x07, // Name
320 0x08, 0x05,
321 0x6c, 0x6f, 0x63, 0x61, 0x6c,
322 0x1f, 0x0a, // LinkDelegation
323 0x1e, 0x01, // LinkPreference
324 0x14,
325 0x07, 0x05, // Name
326 0x08, 0x03,
327 0x6e, 0x64, 0x6e,
328 0x16, 0x1b, // SignatureInfo
329 0x1b, 0x01, // SignatureType
330 0x01,
331 0x1c, 0x16, // KeyLocator
332 0x07, 0x14, // Name
333 0x08, 0x04,
334 0x74, 0x65, 0x73, 0x74,
335 0x08, 0x03,
336 0x6b, 0x65, 0x79,
337 0x08, 0x07,
338 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
339 0x17, 0x80, // SignatureValue
340 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
341 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
342 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
343 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
344 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
345 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
346 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
347 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
348 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
349 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
350 0x20, 0x01, // SelectedDelegation
351 0x00
352};
353
354const uint8_t InterestWithSelectedDelegationButNoLink[] = {
355 0x05, 0x1f, // Interest
356 0x07, 0x14, // Name
357 0x08, 0x5, // NameComponent
358 0x6c, 0x6f, 0x63, 0x61, 0x6c,
359 0x08, 0x3, // NameComponent
360 0x6e, 0x64, 0x6e,
361 0x08, 0x6, // NameComponent
362 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
363 0x0a, 0x4, // Nonce
364 0x1, 0x0, 0x0, 0x00,
365 0x20, 0x01, // SelectedDelegation
366 0x00
367};
368
369const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
370 0x05, 0xfb, // Interest
371 0x07, 0x14, // Name
372 0x08, 0x5, // NameComponent
373 0x6c, 0x6f, 0x63, 0x61, 0x6c,
374 0x08, 0x3, // NameComponent
375 0x6e, 0x64, 0x6e,
376 0x08, 0x6, // NameComponent
377 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
378 0x0a, 0x4, // Nonce
379 0x1, 0x0, 0x0, 0x00,
380 0x06, 0xda, // Data
381 0x07, 0x14, // Name
382 0x08, 0x05,
383 0x6c, 0x6f, 0x63, 0x61, 0x6c,
384 0x08, 0x03,
385 0x6e, 0x64, 0x6e,
386 0x08, 0x06,
387 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
388 0x14, 0x07, // MetaInfo
389 0x18, 0x01, // ContentType
390 0x01,
391 0x19, 0x02, // FreshnessPeriod
392 0x27, 0x10,
393 0x15, 0x1a, // Content
394 0x1f, 0x0c, // LinkDelegation
395 0x1e, 0x01, // LinkPreference
396 0x0a,
397 0x07, 0x07, // Name
398 0x08, 0x05,
399 0x6c, 0x6f, 0x63, 0x61, 0x6c,
400 0x1f, 0x0a, // LinkDelegation
401 0x1e, 0x01, // LinkPreference
402 0x14,
403 0x07, 0x05, // Name
404 0x08, 0x03,
405 0x6e, 0x64, 0x6e,
406 0x16, 0x1b, // SignatureInfo
407 0x1b, 0x01, // SignatureType
408 0x01,
409 0x1c, 0x16, // KeyLocator
410 0x07, 0x14, // Name
411 0x08, 0x04,
412 0x74, 0x65, 0x73, 0x74,
413 0x08, 0x03,
414 0x6b, 0x65, 0x79,
415 0x08, 0x07,
416 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
417 0x17, 0x78, // SignatureValue
418 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
419 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
420 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
421 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
422 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
423 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
424 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
425 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
426 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
427 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
428 0x20, 0x03, // SelectedDelegation
429 0xAA, 0xAA, 0xAA
430};
431
432const uint8_t InterestWithLinkNonDecreasingOrder[] = {
433 0x05, 0xfb, // Interest
434 0x07, 0x14, // Name
435 0x08, 0x5, // NameComponent
436 0x6c, 0x6f, 0x63, 0x61, 0x6c,
437 0x08, 0x3, // NameComponent
438 0x6e, 0x64, 0x6e,
439 0x08, 0x6, // NameComponent
440 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
441 0x0a, 0x4, // Nonce
442 0x1, 0x0, 0x0, 0x00,
443 0x06, 0xda, // Data
444 0x07, 0x14, // Name
445 0x08, 0x05,
446 0x6c, 0x6f, 0x63, 0x61, 0x6c,
447 0x08, 0x03,
448 0x6e, 0x64, 0x6e,
449 0x08, 0x06,
450 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
451 0x14, 0x07, // MetaInfo
452 0x18, 0x01, // ContentType
453 0x01,
454 0x19, 0x02, // FreshnessPeriod
455 0x27, 0x10,
456 0x15, 0x1a, // Content
457 0x1f, 0x0c, // LinkDelegation
458 0x1e, 0x01, // LinkPreference
459 0x14,
460 0x07, 0x07, // Name
461 0x08, 0x05,
462 0x6c, 0x6f, 0x63, 0x61, 0x6c,
463 0x1f, 0x0a, // LinkDelegation
464 0x1e, 0x01, // LinkPreference
465 0x0a,
466 0x07, 0x05, // Name
467 0x08, 0x03,
468 0x6e, 0x64, 0x6e,
469 0x16, 0x1b, // SignatureInfo
470 0x1b, 0x01, // SignatureType
471 0x01,
472 0x1c, 0x16, // KeyLocator
473 0x07, 0x14, // Name
474 0x08, 0x04,
475 0x74, 0x65, 0x73, 0x74,
476 0x08, 0x03,
477 0x6b, 0x65, 0x79,
478 0x08, 0x07,
479 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
480 0x17, 0x80, // SignatureValue
481 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
482 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
483 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
484 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
485 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
486 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
487 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
488 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
489 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
490 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
491 0x20, 0x01, // SelectedDelegation
492 0x01
493};
494
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800495const uint8_t InterestWithLocalControlHeader[] = {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300496 0x50, 0x25, 0x51, 0x01, 0x0a,
497 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
498 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
499 0x01, 0x00, 0x00, 0x00
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800500};
501
502const uint8_t InterestWithoutLocalControlHeader[] = {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300503 0x05, 0x20, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
504 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x04,
505 0x01, 0x00, 0x00, 0x00
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800506};
507
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700508BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
509{
510 // Interest ::= INTEREST-TYPE TLV-LENGTH
511 // Name
512 // Selectors?
513 // Nonce
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700514 // InterestLifetime?
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700515 // Link?
516 // SelectedDelegation?
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700517
518 Interest a;
519 Interest b;
520
521 // if nonce is not set, it will be set to a random value
522 a.setNonce(1);
523 b.setNonce(1);
524
525 BOOST_CHECK_EQUAL(a == b, true);
526 BOOST_CHECK_EQUAL(a != b, false);
527
528 // check comparison on Name
529 a.setName("ndn:/A");
530 BOOST_CHECK_EQUAL(a == b, false);
531 BOOST_CHECK_EQUAL(a != b, true);
532
533 b.setName("ndn:/B");
534 BOOST_CHECK_EQUAL(a == b, false);
535 BOOST_CHECK_EQUAL(a != b, true);
536
537 b.setName("ndn:/A");
538 BOOST_CHECK_EQUAL(a == b, true);
539 BOOST_CHECK_EQUAL(a != b, false);
540
541 // check comparison on Selectors
542 a.setChildSelector(1);
543 BOOST_CHECK_EQUAL(a == b, false);
544 BOOST_CHECK_EQUAL(a != b, true);
545
546 b.setChildSelector(1);
547 BOOST_CHECK_EQUAL(a == b, true);
548 BOOST_CHECK_EQUAL(a != b, false);
549
550 // check comparison on Nonce
551 a.setNonce(100);
552 BOOST_CHECK_EQUAL(a == b, false);
553 BOOST_CHECK_EQUAL(a != b, true);
554
555 b.setNonce(100);
556 BOOST_CHECK_EQUAL(a == b, true);
557 BOOST_CHECK_EQUAL(a != b, false);
558
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700559 // check comparison on InterestLifetime
560 a.setInterestLifetime(time::seconds(10));
561 BOOST_CHECK_EQUAL(a == b, false);
562 BOOST_CHECK_EQUAL(a != b, true);
563
564 b.setInterestLifetime(time::seconds(10));
565 BOOST_CHECK_EQUAL(a == b, true);
566 BOOST_CHECK_EQUAL(a != b, false);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700567
568 // Link object
569 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
570 KeyChain keyChain;
571 keyChain.sign(link);
572 Block wire = link.wireEncode();
573
574 a.setLink(wire);
575 BOOST_CHECK_EQUAL(a == b, false);
576 BOOST_CHECK_EQUAL(a != b, true);
577
578 b.setLink(wire);
579 BOOST_CHECK_EQUAL(a == b, true);
580 BOOST_CHECK_EQUAL(a != b, false);
581
582 // Selected Delegation
583 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
584 BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
585
586 a.setSelectedDelegation(Name("test2"));
587 BOOST_CHECK_EQUAL(a == b, false);
588 BOOST_CHECK_EQUAL(a != b, true);
589
590 b.setSelectedDelegation(Name("test2"));
591 BOOST_CHECK_EQUAL(a == b, true);
592 BOOST_CHECK_EQUAL(a != b, false);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700593}
594
595BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
596{
597 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
598 // MinSuffixComponents?
599 // MaxSuffixComponents?
600 // PublisherPublicKeyLocator?
601 // Exclude?
602 // ChildSelector?
603 // MustBeFresh?
604
605 Selectors a;
606 Selectors b;
607 BOOST_CHECK_EQUAL(a == b, true);
608 BOOST_CHECK_EQUAL(a != b, false);
609
610 // MinSuffixComponents
611 a.setMinSuffixComponents(1);
612 BOOST_CHECK_EQUAL(a == b, false);
613 BOOST_CHECK_EQUAL(a != b, true);
614
615 b.setMinSuffixComponents(2);
616 BOOST_CHECK_EQUAL(a == b, false);
617 BOOST_CHECK_EQUAL(a != b, true);
618
619 b.setMinSuffixComponents(1);
620 BOOST_CHECK_EQUAL(a == b, true);
621 BOOST_CHECK_EQUAL(a != b, false);
622
623 // MaxSuffixComponents
624 a.setMaxSuffixComponents(10);
625 BOOST_CHECK_EQUAL(a == b, false);
626 BOOST_CHECK_EQUAL(a != b, true);
627
628 b.setMaxSuffixComponents(10);
629 BOOST_CHECK_EQUAL(a == b, true);
630 BOOST_CHECK_EQUAL(a != b, false);
631
632 // PublisherPublicKeyLocator
633 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
634 BOOST_CHECK_EQUAL(a == b, false);
635 BOOST_CHECK_EQUAL(a != b, true);
636
637 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
638 BOOST_CHECK_EQUAL(a == b, true);
639 BOOST_CHECK_EQUAL(a != b, false);
640
641 // Exclude
642 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
643 BOOST_CHECK_EQUAL(a == b, false);
644 BOOST_CHECK_EQUAL(a != b, true);
645
646 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
647 BOOST_CHECK_EQUAL(a == b, true);
648 BOOST_CHECK_EQUAL(a != b, false);
649
650 // ChildSelector
651 a.setChildSelector(1);
652 BOOST_CHECK_EQUAL(a == b, false);
653 BOOST_CHECK_EQUAL(a != b, true);
654
655 b.setChildSelector(1);
656 BOOST_CHECK_EQUAL(a == b, true);
657 BOOST_CHECK_EQUAL(a != b, false);
658
659 // MustBeFresh
660 a.setMustBeFresh(true);
661 BOOST_CHECK_EQUAL(a == b, false);
662 BOOST_CHECK_EQUAL(a != b, true);
663
664 b.setMustBeFresh(true);
665 BOOST_CHECK_EQUAL(a == b, true);
666 BOOST_CHECK_EQUAL(a != b, false);
667}
668
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700669BOOST_AUTO_TEST_CASE(LinkObject)
670{
671 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
672 KeyChain keyChain;
673 keyChain.sign(link1);
674 Block wire = link1.wireEncode();
675
676 Interest a;
677 BOOST_REQUIRE_NO_THROW(a.setLink(wire));
678
679 BOOST_REQUIRE_NO_THROW(a.getLink());
680
681 Link link2 = a.getLink();
682 Name name = link2.getName();
683 BOOST_CHECK_EQUAL(Name("test"), name);
684 BOOST_CHECK_EQUAL(a.hasLink(), true);
685 Link::DelegationSet delegations;
686 delegations = link2.getDelegations();
687
688 auto i = delegations.begin();
689 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
690 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
691 ++i;
692 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
693 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
694 ++i;
695 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
696 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
697
698 a.unsetLink();
699 BOOST_CHECK_EQUAL(a.hasLink(), false);
700}
701
702BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
703{
704 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
705 KeyChain keyChain;
706 keyChain.sign(link);
707 Block wire = link.wireEncode();
708
709 Interest a;
710 a.setLink(wire);
711 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
712
713 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
714 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
715
716 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
717 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
718
719 a.unsetSelectedDelegation();
720 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
721}
722
723BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
724{
725 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
726 KeyChain keyChain;
727 keyChain.sign(link1);
728 Block wire = link1.wireEncode();
729
730 Interest a;
731 a.setName("/Test/Encode/Decode/With/Link");
732 a.setChildSelector(1);
733 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700734 a.setInterestLifetime(time::seconds(10));
735 a.setLink(wire);
736
737 Block interestBlock = a.wireEncode();
738 Interest b(interestBlock);
739
740 BOOST_CHECK_EQUAL(a == b, true);
741
742 Link link2 = b.getLink();
743 Link::DelegationSet delegations;
744 delegations = link2.getDelegations();
745
746 auto i = delegations.begin();
747 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
748 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
749 ++i;
750 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
751 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
752 ++i;
753 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
754 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
755
756}
757
758BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
759{
760 Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
761
762 ndn::Interest i;
763 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
764 Link link = i.getLink();
765 BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
766 Link::DelegationSet delegations = link.getDelegations();
767
768 auto it = delegations.begin();
769 BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
770 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
771 ++it;
772 BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
773 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
774
775 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
776 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
777}
778
779BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
780{
781 Block interestBlock(InterestWithLinkNonDecreasingOrder,
782 sizeof(InterestWithLinkNonDecreasingOrder));
783
784 ndn::Interest i;
785 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
786 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
787 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
788}
789
790BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType)
791{
792 Block interestBlock(InterestWithLinkMissingContentType,
793 sizeof(InterestWithLinkMissingContentType));
794
795 ndn::Interest i;
796 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
797 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
798}
799
800BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo)
801{
802 Block interestBlock(InterestWithLinkNoMetaInfo,
803 sizeof(InterestWithLinkNoMetaInfo));
804
805 ndn::Interest i;
806 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
807 BOOST_REQUIRE_THROW(i.getLink(), Block::Error);
808}
809
810BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType)
811{
812 Block interestBlock(InterestWithLinkWrongContentType,
813 sizeof(InterestWithLinkWrongContentType));
814
815 ndn::Interest i;
816 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
817 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
818}
819
820BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
821{
822 Block interestBlock(InterestWithSelectedDelegationButNoLink,
823 sizeof(InterestWithSelectedDelegationButNoLink));
824
825 ndn::Interest i;
826 BOOST_REQUIRE_THROW(i.wireDecode(interestBlock), Interest::Error);
827}
828
829BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
830{
831 Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
832 sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
833
834 ndn::Interest i;
835 BOOST_REQUIRE_THROW(i.wireDecode(interestBlock), tlv::Error);
836}
837
838BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
839{
840 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
841 KeyChain keyChain;
842 keyChain.sign(link1);
843 Block wire = link1.wireEncode();
844
845 Interest a;
846 a.setName("/Test/Encode/Decode/With/Link");
847 a.setChildSelector(1);
848 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700849 a.setInterestLifetime(time::seconds(10));
850 a.setLink(wire);
851 BOOST_REQUIRE_THROW(a.setSelectedDelegation(3), Interest::Error);
852}
853
854BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
855{
856 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
857 KeyChain keyChain;
858 keyChain.sign(link1);
859 Block wire = link1.wireEncode();
860
861 Interest a;
862 a.setName("/Test/Encode/Decode/With/Link");
863 a.setChildSelector(1);
864 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700865 a.setInterestLifetime(time::seconds(10));
866 a.setLink(wire);
867 BOOST_REQUIRE_THROW(a.setSelectedDelegation(4), Interest::Error);
868}
869
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700870BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800871{
872 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800873
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800874 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -0800875 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800876
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700877 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700878 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
879 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
880 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
881 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
882 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
883 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
884 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
885 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
886 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
887 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800888}
889
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700890BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800891{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -0700892 boost::iostreams::stream<boost::iostreams::array_source> is(
893 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -0700894
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700895 Block interestBlock = Block::fromStream(is);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800896
897 ndn::Interest i;
898 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
899
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700900 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700901 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
902 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
903 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
904 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
905 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
906 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
907 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800908}
909
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700910BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800911{
912 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700913 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800914 i.setMinSuffixComponents(1);
915 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700916 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800917 i.setChildSelector(1);
918 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800919 Exclude exclude;
920 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800921 .excludeOne(name::Component("alex"))
922 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800923 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800924 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800925
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300926 BOOST_CHECK_EQUAL(i.hasWire(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800927 const Block &wire = i.wireEncode();
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300928 BOOST_CHECK_EQUAL(i.hasWire(), true);
Alexander Afanasyev809805d2014-02-17 17:20:33 -0800929
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700930 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800931 wire.begin(), wire.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800932
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300933 const uint8_t* originalWire = wire.wire();
934 i.setNonce(2);
935 BOOST_CHECK_EQUAL(i.hasWire(), true);
936 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
937 BOOST_CHECK_EQUAL(i.hasWire(), true);
938
939 BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
940 wire.begin(), wire.end());
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700941
942 std::ostringstream strStream;
943 BOOST_CHECK_NO_THROW(strStream << i);
944
945 BOOST_CHECK_EQUAL(strStream.str(),
946 "/local/ndn/prefix?"
947 "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&"
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -0700948 "ndn.ChildSelector=1&"
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700949 "ndn.InterestLifetime=1000&"
950 "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy");
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700951
952 i.refreshNonce();
953 BOOST_CHECK_EQUAL(i.hasWire(), true);
954 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
955 BOOST_CHECK_NE(i.getNonce(), 2);
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300956}
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800957
958BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
959{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800960 ndn::Interest interest(ndn::Name("/local/ndn/prefix"));
961 interest.setMustBeFresh(true);
962 interest.setIncomingFaceId(10);
963 interest.setNonce(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700964
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800965 BOOST_CHECK(!interest.hasWire());
Junxiao Shib332e782014-03-31 14:23:46 -0700966
Jiewen Tanc759a202015-01-29 23:31:09 -0800967 Block headerBlock =
968 interest.getLocalControlHeader()
969 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
970 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800971
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800972 BOOST_CHECK(interest.hasWire());
973 BOOST_CHECK(headerBlock.hasWire());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800974
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800975 BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire());
976 BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size());
977 BOOST_CHECK_EQUAL(headerBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800978
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800979 BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700980 InterestWithLocalControlHeader + 5,
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800981 headerBlock.begin(), headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800982
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800983 interest.setNonce(1000);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800984
Jiewen Tanc759a202015-01-29 23:31:09 -0800985 Block updatedHeaderBlock =
986 interest.getLocalControlHeader()
987 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
988 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800989 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800990
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800991 // only length should have changed
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700992 BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(),
993 headerBlock.begin() + 2, headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800994
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800995 // updating IncomingFaceId that keeps the length
996 interest.setIncomingFaceId(100);
Jiewen Tanc759a202015-01-29 23:31:09 -0800997 updatedHeaderBlock =
998 interest.getLocalControlHeader()
999 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1000 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001001 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001002 BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4));
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001003
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001004 // updating IncomingFaceId that increases the length by 2
1005 interest.setIncomingFaceId(1000);
Jiewen Tanc759a202015-01-29 23:31:09 -08001006 updatedHeaderBlock =
1007 interest.getLocalControlHeader()
1008 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1009 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001010 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001011
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001012 // adding NextHopId
1013 interest.setNextHopFaceId(1);
Jiewen Tanc759a202015-01-29 23:31:09 -08001014 updatedHeaderBlock =
1015 interest.getLocalControlHeader()
1016 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1017 nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001018 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001019
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001020 // masking IncomingFaceId
Jiewen Tanc759a202015-01-29 23:31:09 -08001021 updatedHeaderBlock = interest.getLocalControlHeader()
1022 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001023 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001024
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001025 // masking NextHopId
Jiewen Tanc759a202015-01-29 23:31:09 -08001026 updatedHeaderBlock =
1027 interest.getLocalControlHeader()
1028 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001029 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001030
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001031 // masking everything
Jiewen Tanc759a202015-01-29 23:31:09 -08001032 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1033 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001034 nfd::LocalControlHeader::Error);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001035}
1036
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001037
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001038BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001039{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001040 Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader));
1041 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
1042 BOOST_REQUIRE_NE(&payload, &wireBlock);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001043
Steve DiBenedetto54ce6682014-07-22 13:22:57 -06001044 BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(tlv::Interest));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001045 BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader));
Junxiao Shib332e782014-03-31 14:23:46 -07001046
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001047 Interest interest(payload);
1048 BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId());
1049 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
1050
1051 BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock));
1052
Jiewen Tanc759a202015-01-29 23:31:09 -08001053 BOOST_CHECK_EQUAL(
1054 interest.getLocalControlHeader()
1055 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1056 nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
1057 5);
Junxiao Shib332e782014-03-31 14:23:46 -07001058
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001059 BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10);
1060 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
1061
Jiewen Tanc759a202015-01-29 23:31:09 -08001062 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1063 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NONE),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001064 nfd::LocalControlHeader::Error);
1065
Jiewen Tanc759a202015-01-29 23:31:09 -08001066 BOOST_CHECK_THROW(interest.getLocalControlHeader()
1067 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_NEXT_HOP),
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001068 nfd::LocalControlHeader::Error);
1069
Jiewen Tanc759a202015-01-29 23:31:09 -08001070 BOOST_CHECK_NO_THROW(
1071 interest.getLocalControlHeader()
1072 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID));
1073 BOOST_CHECK_NO_THROW(
1074 interest.getLocalControlHeader()
1075 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1076 nfd::LocalControlHeader::ENCODE_NEXT_HOP));
Junxiao Shib332e782014-03-31 14:23:46 -07001077
Jiewen Tanc759a202015-01-29 23:31:09 -08001078 BOOST_CHECK_NE(
1079 (void*)interest.getLocalControlHeader()
1080 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1081 nfd::LocalControlHeader::ENCODE_NEXT_HOP)
1082 .wire(),
1083 (void*)wireBlock.wire());
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001084
Jiewen Tanc759a202015-01-29 23:31:09 -08001085 BOOST_CHECK_EQUAL(interest.getLocalControlHeader()
1086 .wireEncode(interest, nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID |
1087 nfd::LocalControlHeader::ENCODE_NEXT_HOP).size(),
1088 5);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001089}
1090
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001091BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08001092{
1093 Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader));
1094 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
1095 BOOST_CHECK_EQUAL(&payload, &wireBlock);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001096}
1097
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001098BOOST_AUTO_TEST_CASE(MatchesData)
1099{
1100 Interest interest;
1101 interest.setName("ndn:/A")
1102 .setMinSuffixComponents(2)
1103 .setMaxSuffixComponents(2)
1104 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
1105 .setExclude(Exclude().excludeBefore(name::Component("C")));
1106
1107 Data data("ndn:/A/D");
Yingdi Yu4a557052014-07-09 16:40:37 -07001108 SignatureSha256WithRsa signature(KeyLocator("ndn:/B"));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001109 data.setSignature(signature);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001110 data.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001111 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
1112
1113 Data data1 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001114 data1.setName("ndn:/A"); // violates MinSuffixComponents
1115 data1.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001116 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
1117
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001118 interest.setMinSuffixComponents(1);
1119 BOOST_CHECK_EQUAL(interest.matchesData(data1), true);
1120 interest.setMinSuffixComponents(2);
1121
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001122 Data data2 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001123 data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents
1124 data2.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001125 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
1126
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001127 interest.setMaxSuffixComponents(3);
1128 BOOST_CHECK_EQUAL(interest.matchesData(data2), true);
1129 interest.setMaxSuffixComponents(2);
1130
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001131 Data data3 = data;
Yingdi Yu4a557052014-07-09 16:40:37 -07001132 SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001133 data3.setSignature(signature3);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001134 data3.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001135 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
1136
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001137 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/G"));
1138 BOOST_CHECK_EQUAL(interest.matchesData(data3), true);
1139 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1140
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001141 Data data4 = data;
Yingdi Yubf6a2812014-06-17 15:32:11 -07001142 DigestSha256 signature4; // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001143 data4.setSignature(signature4);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001144 data4.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001145 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
1146
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001147 interest.setPublisherPublicKeyLocator(KeyLocator());
1148 BOOST_CHECK_EQUAL(interest.matchesData(data4), true);
1149 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1150
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001151 Data data5 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001152 data5.setName("ndn:/A/C"); // violates Exclude
1153 data5.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001154 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
1155
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001156 interest.setExclude(Exclude().excludeBefore(name::Component("A")));
1157 BOOST_CHECK_EQUAL(interest.matchesData(data5), true);
1158 interest.setExclude(Exclude().excludeBefore(name::Component("C")));
1159
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001160 Data data6 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001161 data6.setName("ndn:/H/I"); // violates Name
1162 data6.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001163 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001164
1165 Data data7 = data;
1166 data7.setName("ndn:/A/B");
1167 data7.wireEncode();
1168
1169 interest = Interest()
Alexander Afanasyev56860f52014-11-07 11:51:17 -08001170 .setName("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2");
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001171 BOOST_CHECK_EQUAL(interest.matchesData(data7), true);
1172
1173 interest = Interest()
1174 .setName("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"
1175 "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00");
1176 BOOST_CHECK_EQUAL(interest.matchesData(data7), false); // violates implicit digest
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001177}
1178
Alexander Afanasyev90164962014-03-06 08:29:59 +00001179BOOST_AUTO_TEST_CASE(InterestFilterMatching)
1180{
1181 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
1182 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
1183 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
1184
1185 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
1186 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
1187
1188 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
1189 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
1190
1191 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
1192 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
1193 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
1194 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
1195 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
1196}
1197
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001198BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001199
Alexander Afanasyev90164962014-03-06 08:29:59 +00001200} // namespace tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001201} // namespace ndn