blob: da6c2e3cb50caf9515ce35b8914884ac01eac923 [file] [log] [blame]
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08003 * See COPYING for copyright and distribution information.
4 */
5
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08006#include "interest.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07007#include "data.hpp"
8#include "security/signature-sha256-with-rsa.hpp"
9#include "security/signature-sha256.hpp"
10
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070011#include "boost-test.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080012
13using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080014namespace ndn {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080015
16BOOST_AUTO_TEST_SUITE(TestInterest)
17
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070018BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
19BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Selectors>));
20
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080021const uint8_t Interest1[] = {
Junxiao Shib332e782014-03-31 14:23:46 -070022 0x05, 0x59, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080023 0x07, 0x14, // Name
24 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080025 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080026 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080027 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080028 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080029 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070030 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080031 0x0d, 0x1, 0x1, // MinSuffix
32 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070033 0x1c, 0x16, // KeyLocator
34 0x07, 0x14, // Name
35 0x08, 0x04,
36 0x74, 0x65, 0x73, 0x74,
37 0x08, 0x03,
38 0x6b, 0x65, 0x79,
39 0x08, 0x07,
40 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080041 0x10, 0x14, // Exclude
42 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080043 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080044 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080045 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080046 0x13, 0x0, // Any
47 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080048 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080049 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080050 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080051 0x0a, 0x1, // Nonce
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080052 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080053 0x0b, 0x1, // Scope
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080054 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080055 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080056 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080057};
58
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080059const uint8_t InterestWithLocalControlHeader[] = {
60 0x50, 0x22, 0x51, 0x01, 0x0a, 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61,
61 0x6c, 0x08, 0x03, 0x6e, 0x64, 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09,
62 0x02, 0x12, 0x00, 0x0a, 0x01, 0x01
63};
64
65const uint8_t InterestWithoutLocalControlHeader[] = {
66 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
67 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x01,
68 0x01
69};
70
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070071BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
72{
73 // Interest ::= INTEREST-TYPE TLV-LENGTH
74 // Name
75 // Selectors?
76 // Nonce
77 // Scope?
78 // InterestLifetime?
79
80 Interest a;
81 Interest b;
82
83 // if nonce is not set, it will be set to a random value
84 a.setNonce(1);
85 b.setNonce(1);
86
87 BOOST_CHECK_EQUAL(a == b, true);
88 BOOST_CHECK_EQUAL(a != b, false);
89
90 // check comparison on Name
91 a.setName("ndn:/A");
92 BOOST_CHECK_EQUAL(a == b, false);
93 BOOST_CHECK_EQUAL(a != b, true);
94
95 b.setName("ndn:/B");
96 BOOST_CHECK_EQUAL(a == b, false);
97 BOOST_CHECK_EQUAL(a != b, true);
98
99 b.setName("ndn:/A");
100 BOOST_CHECK_EQUAL(a == b, true);
101 BOOST_CHECK_EQUAL(a != b, false);
102
103 // check comparison on Selectors
104 a.setChildSelector(1);
105 BOOST_CHECK_EQUAL(a == b, false);
106 BOOST_CHECK_EQUAL(a != b, true);
107
108 b.setChildSelector(1);
109 BOOST_CHECK_EQUAL(a == b, true);
110 BOOST_CHECK_EQUAL(a != b, false);
111
112 // check comparison on Nonce
113 a.setNonce(100);
114 BOOST_CHECK_EQUAL(a == b, false);
115 BOOST_CHECK_EQUAL(a != b, true);
116
117 b.setNonce(100);
118 BOOST_CHECK_EQUAL(a == b, true);
119 BOOST_CHECK_EQUAL(a != b, false);
120
121 // check comparison on Nonce
122 a.setScope(1);
123 BOOST_CHECK_EQUAL(a == b, false);
124 BOOST_CHECK_EQUAL(a != b, true);
125
126 b.setScope(1);
127 BOOST_CHECK_EQUAL(a == b, true);
128 BOOST_CHECK_EQUAL(a != b, false);
129
130 // check comparison on InterestLifetime
131 a.setInterestLifetime(time::seconds(10));
132 BOOST_CHECK_EQUAL(a == b, false);
133 BOOST_CHECK_EQUAL(a != b, true);
134
135 b.setInterestLifetime(time::seconds(10));
136 BOOST_CHECK_EQUAL(a == b, true);
137 BOOST_CHECK_EQUAL(a != b, false);
138}
139
140BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
141{
142 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
143 // MinSuffixComponents?
144 // MaxSuffixComponents?
145 // PublisherPublicKeyLocator?
146 // Exclude?
147 // ChildSelector?
148 // MustBeFresh?
149
150 Selectors a;
151 Selectors b;
152 BOOST_CHECK_EQUAL(a == b, true);
153 BOOST_CHECK_EQUAL(a != b, false);
154
155 // MinSuffixComponents
156 a.setMinSuffixComponents(1);
157 BOOST_CHECK_EQUAL(a == b, false);
158 BOOST_CHECK_EQUAL(a != b, true);
159
160 b.setMinSuffixComponents(2);
161 BOOST_CHECK_EQUAL(a == b, false);
162 BOOST_CHECK_EQUAL(a != b, true);
163
164 b.setMinSuffixComponents(1);
165 BOOST_CHECK_EQUAL(a == b, true);
166 BOOST_CHECK_EQUAL(a != b, false);
167
168 // MaxSuffixComponents
169 a.setMaxSuffixComponents(10);
170 BOOST_CHECK_EQUAL(a == b, false);
171 BOOST_CHECK_EQUAL(a != b, true);
172
173 b.setMaxSuffixComponents(10);
174 BOOST_CHECK_EQUAL(a == b, true);
175 BOOST_CHECK_EQUAL(a != b, false);
176
177 // PublisherPublicKeyLocator
178 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
179 BOOST_CHECK_EQUAL(a == b, false);
180 BOOST_CHECK_EQUAL(a != b, true);
181
182 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
183 BOOST_CHECK_EQUAL(a == b, true);
184 BOOST_CHECK_EQUAL(a != b, false);
185
186 // Exclude
187 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
188 BOOST_CHECK_EQUAL(a == b, false);
189 BOOST_CHECK_EQUAL(a != b, true);
190
191 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
192 BOOST_CHECK_EQUAL(a == b, true);
193 BOOST_CHECK_EQUAL(a != b, false);
194
195 // ChildSelector
196 a.setChildSelector(1);
197 BOOST_CHECK_EQUAL(a == b, false);
198 BOOST_CHECK_EQUAL(a != b, true);
199
200 b.setChildSelector(1);
201 BOOST_CHECK_EQUAL(a == b, true);
202 BOOST_CHECK_EQUAL(a != b, false);
203
204 // MustBeFresh
205 a.setMustBeFresh(true);
206 BOOST_CHECK_EQUAL(a == b, false);
207 BOOST_CHECK_EQUAL(a != b, true);
208
209 b.setMustBeFresh(true);
210 BOOST_CHECK_EQUAL(a == b, true);
211 BOOST_CHECK_EQUAL(a != b, false);
212}
213
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700214BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800215{
216 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800217
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800218 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -0800219 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800220
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700221 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
222 BOOST_CHECK_EQUAL(i.getScope(), 1);
223 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
224 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
225 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
226 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
227 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
228 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
229 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
230 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
231 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
232 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800233}
234
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700235BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800236{
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700237 boost::iostreams::stream<boost::iostreams::array_source> is(reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -0700238
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800239 Block interestBlock(is);
240
241 ndn::Interest i;
242 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
243
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700244 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
245 BOOST_CHECK_EQUAL(i.getScope(), 1);
246 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
247 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
248 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
249 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
250 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
251 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
252 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800253}
254
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700255BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800256{
257 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
258 i.setScope(1);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700259 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800260 i.setMinSuffixComponents(1);
261 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700262 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800263 i.setChildSelector(1);
264 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800265 Exclude exclude;
266 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800267 .excludeOne(name::Component("alex"))
268 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800269 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800270 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800271
272 const Block &wire = i.wireEncode();
Alexander Afanasyev809805d2014-02-17 17:20:33 -0800273
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700274 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800275 wire.begin(), wire.end());
276}
277
278
279BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
280{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800281 ndn::Interest interest(ndn::Name("/local/ndn/prefix"));
282 interest.setMustBeFresh(true);
283 interest.setIncomingFaceId(10);
284 interest.setNonce(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700285
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800286 BOOST_CHECK(!interest.hasWire());
Junxiao Shib332e782014-03-31 14:23:46 -0700287
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800288 Block headerBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800289
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800290 BOOST_CHECK(interest.hasWire());
291 BOOST_CHECK(headerBlock.hasWire());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800292
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800293 BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire());
294 BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size());
295 BOOST_CHECK_EQUAL(headerBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800296
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800297 BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700298 InterestWithLocalControlHeader + 5,
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800299 headerBlock.begin(), headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800300
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800301 interest.setNonce(1000);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800302
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800303 Block updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
304 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800305
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800306 // only length should have changed
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700307 BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(),
308 headerBlock.begin() + 2, headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800309
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800310 // updating IncomingFaceId that keeps the length
311 interest.setIncomingFaceId(100);
312 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
313 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700314 BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4));
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800315
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800316 // updating IncomingFaceId that increases the length by 2
317 interest.setIncomingFaceId(1000);
318 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
319 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800320
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800321 // adding NextHopId
322 interest.setNextHopFaceId(1);
323 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
324 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800325
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800326 // masking IncomingFaceId
327 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, false, true);
328 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800329
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800330 // masking NextHopId
331 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, false);
332 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800333
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800334 // masking everything
335 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
336 nfd::LocalControlHeader::Error);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800337}
338
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800339
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700340BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800341{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800342 Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader));
343 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
344 BOOST_REQUIRE_NE(&payload, &wireBlock);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800345
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700346 BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(Tlv::Interest));
347 BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader));
Junxiao Shib332e782014-03-31 14:23:46 -0700348
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800349 Interest interest(payload);
350 BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId());
351 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
352
353 BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock));
354
355 BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
Junxiao Shib332e782014-03-31 14:23:46 -0700356
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800357 BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10);
358 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
359
360 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
361 nfd::LocalControlHeader::Error);
362
363 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, true),
364 nfd::LocalControlHeader::Error);
365
366 BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, false));
367 BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, true));
Junxiao Shib332e782014-03-31 14:23:46 -0700368
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800369 BOOST_CHECK_NE((void*)interest.getLocalControlHeader().wireEncode(interest, true, true).wire(),
370 (void*)wireBlock.wire());
371
372 BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
373}
374
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700375BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800376{
377 Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader));
378 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
379 BOOST_CHECK_EQUAL(&payload, &wireBlock);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800380}
381
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700382BOOST_AUTO_TEST_CASE(MatchesData)
383{
384 Interest interest;
385 interest.setName("ndn:/A")
386 .setMinSuffixComponents(2)
387 .setMaxSuffixComponents(2)
388 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
389 .setExclude(Exclude().excludeBefore(name::Component("C")));
390
391 Data data("ndn:/A/D");
392 SignatureSha256WithRsa signature;
393 signature.setKeyLocator(KeyLocator("ndn:/B"));
394 data.setSignature(signature);
395 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
396
397 Data data1 = data;
398 data1.setName("ndn:/A");// violates MinSuffixComponents
399 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
400
401 Data data2 = data;
402 data2.setName("ndn:/A/E/F");// violates MaxSuffixComponents
403 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
404
405 Data data3 = data;
406 SignatureSha256WithRsa signature3;
407 signature3.setKeyLocator(KeyLocator("ndn:/G"));// violates PublisherPublicKeyLocator
408 data3.setSignature(signature3);
409 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
410
411 Data data4 = data;
412 SignatureSha256 signature4;// violates PublisherPublicKeyLocator
413 data4.setSignature(signature4);
414 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
415
416 Data data5 = data;
417 data5.setName("ndn:/A/C");// violates Exclude
418 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
419
420 Data data6 = data;
421 data6.setName("ndn:/H/I");// violates Name
422 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
423}
424
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800425BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800426
427} // namespace ndn