blob: b1c3e69d892bec04fd6458f874d4d42a191f039c [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080011 */
12
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080013#include "interest.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070014#include "data.hpp"
15#include "security/signature-sha256-with-rsa.hpp"
16#include "security/signature-sha256.hpp"
17
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070018#include "boost-test.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080019
20using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080021namespace ndn {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080022
23BOOST_AUTO_TEST_SUITE(TestInterest)
24
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070025BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
26BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Selectors>));
27
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080028const uint8_t Interest1[] = {
Junxiao Shib332e782014-03-31 14:23:46 -070029 0x05, 0x59, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080030 0x07, 0x14, // Name
31 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080032 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080033 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080034 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080035 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080036 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070037 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080038 0x0d, 0x1, 0x1, // MinSuffix
39 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070040 0x1c, 0x16, // KeyLocator
41 0x07, 0x14, // Name
42 0x08, 0x04,
43 0x74, 0x65, 0x73, 0x74,
44 0x08, 0x03,
45 0x6b, 0x65, 0x79,
46 0x08, 0x07,
47 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080048 0x10, 0x14, // Exclude
49 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080050 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080051 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080052 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080053 0x13, 0x0, // Any
54 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080055 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080056 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080057 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080058 0x0a, 0x1, // Nonce
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080059 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080060 0x0b, 0x1, // Scope
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080061 0x1,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080062 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080063 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080064};
65
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080066const uint8_t InterestWithLocalControlHeader[] = {
67 0x50, 0x22, 0x51, 0x01, 0x0a, 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61,
68 0x6c, 0x08, 0x03, 0x6e, 0x64, 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09,
69 0x02, 0x12, 0x00, 0x0a, 0x01, 0x01
70};
71
72const uint8_t InterestWithoutLocalControlHeader[] = {
73 0x05, 0x1d, 0x07, 0x14, 0x08, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x08, 0x03, 0x6e, 0x64,
74 0x6e, 0x08, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x09, 0x02, 0x12, 0x00, 0x0a, 0x01,
75 0x01
76};
77
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070078BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
79{
80 // Interest ::= INTEREST-TYPE TLV-LENGTH
81 // Name
82 // Selectors?
83 // Nonce
84 // Scope?
85 // InterestLifetime?
86
87 Interest a;
88 Interest b;
89
90 // if nonce is not set, it will be set to a random value
91 a.setNonce(1);
92 b.setNonce(1);
93
94 BOOST_CHECK_EQUAL(a == b, true);
95 BOOST_CHECK_EQUAL(a != b, false);
96
97 // check comparison on Name
98 a.setName("ndn:/A");
99 BOOST_CHECK_EQUAL(a == b, false);
100 BOOST_CHECK_EQUAL(a != b, true);
101
102 b.setName("ndn:/B");
103 BOOST_CHECK_EQUAL(a == b, false);
104 BOOST_CHECK_EQUAL(a != b, true);
105
106 b.setName("ndn:/A");
107 BOOST_CHECK_EQUAL(a == b, true);
108 BOOST_CHECK_EQUAL(a != b, false);
109
110 // check comparison on Selectors
111 a.setChildSelector(1);
112 BOOST_CHECK_EQUAL(a == b, false);
113 BOOST_CHECK_EQUAL(a != b, true);
114
115 b.setChildSelector(1);
116 BOOST_CHECK_EQUAL(a == b, true);
117 BOOST_CHECK_EQUAL(a != b, false);
118
119 // check comparison on Nonce
120 a.setNonce(100);
121 BOOST_CHECK_EQUAL(a == b, false);
122 BOOST_CHECK_EQUAL(a != b, true);
123
124 b.setNonce(100);
125 BOOST_CHECK_EQUAL(a == b, true);
126 BOOST_CHECK_EQUAL(a != b, false);
127
128 // check comparison on Nonce
129 a.setScope(1);
130 BOOST_CHECK_EQUAL(a == b, false);
131 BOOST_CHECK_EQUAL(a != b, true);
132
133 b.setScope(1);
134 BOOST_CHECK_EQUAL(a == b, true);
135 BOOST_CHECK_EQUAL(a != b, false);
136
137 // check comparison on InterestLifetime
138 a.setInterestLifetime(time::seconds(10));
139 BOOST_CHECK_EQUAL(a == b, false);
140 BOOST_CHECK_EQUAL(a != b, true);
141
142 b.setInterestLifetime(time::seconds(10));
143 BOOST_CHECK_EQUAL(a == b, true);
144 BOOST_CHECK_EQUAL(a != b, false);
145}
146
147BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
148{
149 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
150 // MinSuffixComponents?
151 // MaxSuffixComponents?
152 // PublisherPublicKeyLocator?
153 // Exclude?
154 // ChildSelector?
155 // MustBeFresh?
156
157 Selectors a;
158 Selectors b;
159 BOOST_CHECK_EQUAL(a == b, true);
160 BOOST_CHECK_EQUAL(a != b, false);
161
162 // MinSuffixComponents
163 a.setMinSuffixComponents(1);
164 BOOST_CHECK_EQUAL(a == b, false);
165 BOOST_CHECK_EQUAL(a != b, true);
166
167 b.setMinSuffixComponents(2);
168 BOOST_CHECK_EQUAL(a == b, false);
169 BOOST_CHECK_EQUAL(a != b, true);
170
171 b.setMinSuffixComponents(1);
172 BOOST_CHECK_EQUAL(a == b, true);
173 BOOST_CHECK_EQUAL(a != b, false);
174
175 // MaxSuffixComponents
176 a.setMaxSuffixComponents(10);
177 BOOST_CHECK_EQUAL(a == b, false);
178 BOOST_CHECK_EQUAL(a != b, true);
179
180 b.setMaxSuffixComponents(10);
181 BOOST_CHECK_EQUAL(a == b, true);
182 BOOST_CHECK_EQUAL(a != b, false);
183
184 // PublisherPublicKeyLocator
185 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
186 BOOST_CHECK_EQUAL(a == b, false);
187 BOOST_CHECK_EQUAL(a != b, true);
188
189 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
190 BOOST_CHECK_EQUAL(a == b, true);
191 BOOST_CHECK_EQUAL(a != b, false);
192
193 // Exclude
194 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
195 BOOST_CHECK_EQUAL(a == b, false);
196 BOOST_CHECK_EQUAL(a != b, true);
197
198 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
199 BOOST_CHECK_EQUAL(a == b, true);
200 BOOST_CHECK_EQUAL(a != b, false);
201
202 // ChildSelector
203 a.setChildSelector(1);
204 BOOST_CHECK_EQUAL(a == b, false);
205 BOOST_CHECK_EQUAL(a != b, true);
206
207 b.setChildSelector(1);
208 BOOST_CHECK_EQUAL(a == b, true);
209 BOOST_CHECK_EQUAL(a != b, false);
210
211 // MustBeFresh
212 a.setMustBeFresh(true);
213 BOOST_CHECK_EQUAL(a == b, false);
214 BOOST_CHECK_EQUAL(a != b, true);
215
216 b.setMustBeFresh(true);
217 BOOST_CHECK_EQUAL(a == b, true);
218 BOOST_CHECK_EQUAL(a != b, false);
219}
220
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700221BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800222{
223 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800224
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800225 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -0800226 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800227
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700228 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
229 BOOST_CHECK_EQUAL(i.getScope(), 1);
230 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
231 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
232 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
233 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
234 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
235 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
236 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
237 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
238 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
239 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800240}
241
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700242BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800243{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -0700244 boost::iostreams::stream<boost::iostreams::array_source> is(
245 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -0700246
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800247 Block interestBlock(is);
248
249 ndn::Interest i;
250 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
251
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700252 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
253 BOOST_CHECK_EQUAL(i.getScope(), 1);
254 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
255 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
256 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
257 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
258 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
259 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
260 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800261}
262
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700263BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800264{
265 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
266 i.setScope(1);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700267 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800268 i.setMinSuffixComponents(1);
269 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700270 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800271 i.setChildSelector(1);
272 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800273 Exclude exclude;
274 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800275 .excludeOne(name::Component("alex"))
276 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800277 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800278 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800279
280 const Block &wire = i.wireEncode();
Alexander Afanasyev809805d2014-02-17 17:20:33 -0800281
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700282 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800283 wire.begin(), wire.end());
284}
285
286
287BOOST_AUTO_TEST_CASE(EncodeWithLocalHeader)
288{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800289 ndn::Interest interest(ndn::Name("/local/ndn/prefix"));
290 interest.setMustBeFresh(true);
291 interest.setIncomingFaceId(10);
292 interest.setNonce(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700293
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800294 BOOST_CHECK(!interest.hasWire());
Junxiao Shib332e782014-03-31 14:23:46 -0700295
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800296 Block headerBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800297
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800298 BOOST_CHECK(interest.hasWire());
299 BOOST_CHECK(headerBlock.hasWire());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800300
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800301 BOOST_CHECK_NE(headerBlock.wire(), interest.wireEncode().wire());
302 BOOST_CHECK_NE(headerBlock.size(), interest.wireEncode().size());
303 BOOST_CHECK_EQUAL(headerBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800304
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800305 BOOST_CHECK_EQUAL_COLLECTIONS(InterestWithLocalControlHeader,
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700306 InterestWithLocalControlHeader + 5,
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800307 headerBlock.begin(), headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800308
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800309 interest.setNonce(1000);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800310
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800311 Block updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
312 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800313
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800314 // only length should have changed
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700315 BOOST_CHECK_EQUAL_COLLECTIONS(updatedHeaderBlock.begin() + 2, updatedHeaderBlock.end(),
316 headerBlock.begin() + 2, headerBlock.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800317
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800318 // updating IncomingFaceId that keeps the length
319 interest.setIncomingFaceId(100);
320 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
321 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700322 BOOST_CHECK_NE(*(updatedHeaderBlock.begin() + 4), *(headerBlock.begin() + 4));
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800323
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800324 // updating IncomingFaceId that increases the length by 2
325 interest.setIncomingFaceId(1000);
326 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
327 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800328
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800329 // adding NextHopId
330 interest.setNextHopFaceId(1);
331 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, true);
332 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 9);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800333
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800334 // masking IncomingFaceId
335 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, false, true);
336 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 5);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800337
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800338 // masking NextHopId
339 updatedHeaderBlock = interest.getLocalControlHeader().wireEncode(interest, true, false);
340 BOOST_CHECK_EQUAL(updatedHeaderBlock.size(), 6);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800341
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800342 // masking everything
343 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
344 nfd::LocalControlHeader::Error);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800345}
346
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800347
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700348BOOST_AUTO_TEST_CASE(DecodeWithLocalHeader)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800349{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800350 Block wireBlock(InterestWithLocalControlHeader, sizeof(InterestWithLocalControlHeader));
351 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
352 BOOST_REQUIRE_NE(&payload, &wireBlock);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800353
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700354 BOOST_CHECK_EQUAL(payload.type(), static_cast<uint32_t>(Tlv::Interest));
355 BOOST_CHECK_EQUAL(wireBlock.type(), static_cast<uint32_t>(tlv::nfd::LocalControlHeader));
Junxiao Shib332e782014-03-31 14:23:46 -0700356
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800357 Interest interest(payload);
358 BOOST_CHECK(!interest.getLocalControlHeader().hasIncomingFaceId());
359 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
360
361 BOOST_REQUIRE_NO_THROW(interest.getLocalControlHeader().wireDecode(wireBlock));
362
363 BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
Junxiao Shib332e782014-03-31 14:23:46 -0700364
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800365 BOOST_CHECK_EQUAL(interest.getIncomingFaceId(), 10);
366 BOOST_CHECK(!interest.getLocalControlHeader().hasNextHopFaceId());
367
368 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, false),
369 nfd::LocalControlHeader::Error);
370
371 BOOST_CHECK_THROW(interest.getLocalControlHeader().wireEncode(interest, false, true),
372 nfd::LocalControlHeader::Error);
373
374 BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, false));
375 BOOST_CHECK_NO_THROW(interest.getLocalControlHeader().wireEncode(interest, true, true));
Junxiao Shib332e782014-03-31 14:23:46 -0700376
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800377 BOOST_CHECK_NE((void*)interest.getLocalControlHeader().wireEncode(interest, true, true).wire(),
378 (void*)wireBlock.wire());
379
380 BOOST_CHECK_EQUAL(interest.getLocalControlHeader().wireEncode(interest, true, true).size(), 5);
381}
382
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700383BOOST_AUTO_TEST_CASE(DecodeWithoutLocalHeader)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800384{
385 Block wireBlock(InterestWithoutLocalControlHeader, sizeof(InterestWithoutLocalControlHeader));
386 const Block& payload = nfd::LocalControlHeader::getPayload(wireBlock);
387 BOOST_CHECK_EQUAL(&payload, &wireBlock);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800388}
389
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700390BOOST_AUTO_TEST_CASE(MatchesData)
391{
392 Interest interest;
393 interest.setName("ndn:/A")
394 .setMinSuffixComponents(2)
395 .setMaxSuffixComponents(2)
396 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
397 .setExclude(Exclude().excludeBefore(name::Component("C")));
398
399 Data data("ndn:/A/D");
400 SignatureSha256WithRsa signature;
401 signature.setKeyLocator(KeyLocator("ndn:/B"));
402 data.setSignature(signature);
403 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
404
405 Data data1 = data;
406 data1.setName("ndn:/A");// violates MinSuffixComponents
407 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
408
409 Data data2 = data;
410 data2.setName("ndn:/A/E/F");// violates MaxSuffixComponents
411 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
412
413 Data data3 = data;
414 SignatureSha256WithRsa signature3;
415 signature3.setKeyLocator(KeyLocator("ndn:/G"));// violates PublisherPublicKeyLocator
416 data3.setSignature(signature3);
417 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
418
419 Data data4 = data;
420 SignatureSha256 signature4;// violates PublisherPublicKeyLocator
421 data4.setSignature(signature4);
422 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
423
424 Data data5 = data;
425 data5.setName("ndn:/A/C");// violates Exclude
426 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
427
428 Data data6 = data;
429 data6.setName("ndn:/H/I");// violates Name
430 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
431}
432
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800433BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -0800434
435} // namespace ndn