blob: 820dbd21c504d9c7b3eddfd421af2b463bb0b35d [file] [log] [blame]
Shock Jiangcde28712014-10-19 21:17:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shibbf7ac82016-07-14 14:45:15 +00003 * Copyright (c) 2014-2016, Regents of the University of California.
Shock Jiangcde28712014-10-19 21:17:20 -07004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Shock Jiangcde28712014-10-19 21:17:20 -070020#include "daemon/name-server.hpp"
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080021#include "daemon/db-mgr.hpp"
Shock Jiangcde28712014-10-19 21:17:20 -070022#include "clients/response.hpp"
23#include "clients/query.hpp"
Shock Jiangcde28712014-10-19 21:17:20 -070024
Alexander Afanasyevfde570c2016-12-19 16:02:55 -080025#include "test-common.hpp"
26#include "unit/database-test-data.hpp"
Shock Jiangcde28712014-10-19 21:17:20 -070027
28namespace ndn {
29namespace ndns {
30namespace tests {
31
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070032NDNS_LOG_INIT("NameServerTest")
Shock Jiangcde28712014-10-19 21:17:20 -070033
34class NameServerFixture : public DbTestData
35{
36public:
37 NameServerFixture()
Junxiao Shibbf7ac82016-07-14 14:45:15 +000038 : face({false, true})
Shock Jiange1a81fd2014-11-20 20:25:49 -080039 , zone(m_root.getName())
Junxiao Shibbf7ac82016-07-14 14:45:15 +000040 , validator(face)
41 , server(zone, m_certName, face, m_session, m_keyChain, validator)
Shock Jiangcde28712014-10-19 21:17:20 -070042 {
43 // ensure prefix is registered
44 run();
45 }
46
47 void
48 run()
49 {
Junxiao Shibbf7ac82016-07-14 14:45:15 +000050 face.getIoService().poll();
51 face.getIoService().reset();
Shock Jiangcde28712014-10-19 21:17:20 -070052 }
53
54public:
Junxiao Shibbf7ac82016-07-14 14:45:15 +000055 ndn::util::DummyClientFace face;
Shock Jiangcde28712014-10-19 21:17:20 -070056 Name hint;
57 const Name& zone;
58 Validator validator;
59 ndns::NameServer server;
60};
61
62BOOST_FIXTURE_TEST_SUITE(NameServer, NameServerFixture)
63
64BOOST_AUTO_TEST_CASE(NdnsQuery)
65{
66 Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -080067 q.setRrLabel(Name("net"));
Shock Jiangcde28712014-10-19 21:17:20 -070068 q.setRrType(ndns::label::NS_RR_TYPE);
69
70 bool hasDataBack = false;
71
Junxiao Shibbf7ac82016-07-14 14:45:15 +000072 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -070073 hasDataBack = true;
74 NDNS_LOG_TRACE("get Data back");
75 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
76
77 Response resp;
78 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
79 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070080 });
Shock Jiangcde28712014-10-19 21:17:20 -070081
Junxiao Shibbf7ac82016-07-14 14:45:15 +000082 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -070083
84 run();
85
86 BOOST_CHECK_EQUAL(hasDataBack, true);
87}
88
89BOOST_AUTO_TEST_CASE(KeyQuery)
90{
91 Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY);
92 q.setQueryType(ndns::label::NDNS_CERT_QUERY);
93 q.setRrType(ndns::label::CERT_RR_TYPE);
94
95 size_t nDataBack = 0;
96
97 // will ask for non-existing record
Junxiao Shibbf7ac82016-07-14 14:45:15 +000098 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -070099 ++nDataBack;
100 NDNS_LOG_TRACE("get Data back");
101 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
102
103 Response resp;
104 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
105 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_NACK);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700106 });
Shock Jiangcde28712014-10-19 21:17:20 -0700107
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000108 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700109 run();
110
111 // will ask for the existing record (will have type NDNS_RAW, as it is certificate)
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000112 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700113 ++nDataBack;
114 NDNS_LOG_TRACE("get Data back");
115 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
116
117 Response resp;
118 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
119 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RAW);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700120 });
Shock Jiangcde28712014-10-19 21:17:20 -0700121
Shock Jiange1a81fd2014-11-20 20:25:49 -0800122 q.setRrLabel("dsk-1");
Shock Jiangcde28712014-10-19 21:17:20 -0700123
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000124 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700125 run();
126
127 BOOST_CHECK_EQUAL(nDataBack, 2);
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800128
129 // explicit interest with correct version
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000130 face.receive(Interest("/test19/KEY/dsk-1/ID-CERT/%FDd"));
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800131
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000132 face.onSendData.connectSingleShot([&] (const Data& data) {
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800133 ++nDataBack;
134
135 Response resp;
136 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
137 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RAW);
138 });
139
140 run();
141 BOOST_CHECK_EQUAL(nDataBack, 3);
142
143 // explicit interest with wrong version
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000144 face.receive(Interest("/test19/KEY/dsk-1/ID-CERT/%FD010101010"));
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800145
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000146 face.onSendData.connectSingleShot([&] (const Data& data) {
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800147 ++nDataBack;
148
149 Response resp;
150 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
151 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_NACK);
152 });
153
154 run();
155 BOOST_CHECK_EQUAL(nDataBack, 4);
Shock Jiangcde28712014-10-19 21:17:20 -0700156}
157
158BOOST_AUTO_TEST_CASE(UpdateReplaceRr)
159{
160 Response re;
161 re.setZone(zone);
162 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -0800163 re.setRrLabel(Name("net"));
Shock Jiangcde28712014-10-19 21:17:20 -0700164 re.setRrType(label::NS_RR_TYPE);
165 re.setNdnsType(NDNS_RESP);
166
167 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000168 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700169 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000170 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700171
172 shared_ptr<Data> data = re.toData();
173 m_keyChain.sign(*data, m_certName);
174
175 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
176 const Block& block = data->wireEncode();
177 Name name;
178 name.append(block);
179
180 q.setRrLabel(name);
181 q.setRrType(label::NDNS_UPDATE_LABEL);
182
183 bool hasDataBack = false;
184
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000185 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700186 hasDataBack = true;
187 NDNS_LOG_TRACE("get Data back");
188 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
189 Response resp;
190
191 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiangcde28712014-10-19 21:17:20 -0700192 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
193 BOOST_CHECK_GT(resp.getRrs().size(), 0);
194 Block block = resp.getRrs()[0];
195 block.parse();
196 int ret = -1;
197 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
198 Block::element_const_iterator val = block.elements_begin();
199 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
200 ret = readNonNegativeInteger(*val);
201 BOOST_CHECK_EQUAL(ret, 0);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700202 });
Shock Jiangcde28712014-10-19 21:17:20 -0700203
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000204 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700205 run();
206
207 BOOST_CHECK_EQUAL(hasDataBack, true);
208}
209
210BOOST_AUTO_TEST_CASE(UpdateInsertNewRr)
211{
212 Response re;
213 re.setZone(zone);
214 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -0800215 re.setRrLabel(Name("net-XYZ")); // insert new records
Shock Jiangcde28712014-10-19 21:17:20 -0700216 re.setRrType(label::NS_RR_TYPE);
217 re.setNdnsType(NDNS_RESP);
218
219 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000220 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700221 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000222 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700223
224 shared_ptr<Data> data = re.toData();
225 m_keyChain.sign(*data, m_certName);
226
227 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
228 const Block& block = data->wireEncode();
229 Name name;
230 name.append(block);
231
232 q.setRrLabel(name);
233 q.setRrType(label::NDNS_UPDATE_LABEL);
234
235 bool hasDataBack = false;
236
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000237 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700238 hasDataBack = true;
239 NDNS_LOG_TRACE("get Data back");
240 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
241 Response resp;
242
243 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiangcde28712014-10-19 21:17:20 -0700244 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
245 BOOST_CHECK_GT(resp.getRrs().size(), 0);
246 Block block = resp.getRrs()[0];
247 block.parse();
248 int ret = -1;
249 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
250 Block::element_const_iterator val = block.elements_begin();
251 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
252 ret = readNonNegativeInteger(*val);
253 BOOST_CHECK_EQUAL(ret, 0);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700254 });
Shock Jiangcde28712014-10-19 21:17:20 -0700255
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000256 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700257 run();
258
259 BOOST_CHECK_EQUAL(hasDataBack, true);
260}
261
Shock Jiange1a81fd2014-11-20 20:25:49 -0800262BOOST_AUTO_TEST_CASE(UpdateValidatorCannotFetchCert)
263{
264 Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false);
265 std::vector<CertificateSubjectDescription> desc;
266 time::system_clock::TimePoint notBefore = time::system_clock::now();
267 time::system_clock::TimePoint notAfter = notBefore + time::days(365);
268 shared_ptr<IdentityCertificate> dskCert =
269 m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName,
270 notBefore, notAfter, desc);
271
272 m_keyChain.sign(*dskCert, m_certName);
273 m_keyChain.addCertificateAsKeyDefault(*dskCert);
274 NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: "
275 << dskCert->getSignature().getKeyLocator().getName());
276
277 Rrset rrset(&m_root);
278 Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1);
279 rrset.setLabel(label);
280 rrset.setType(label::CERT_RR_TYPE);
281 rrset.setVersion(dskCert->getName().get(-1));
282 rrset.setTtl(m_root.getTtl());
283 rrset.setData(dskCert->wireEncode());
284 m_session.insert(rrset);
285 NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name="
286 << dskCert->getName() << " rrLabel=" << label);
287
288 Response re;
289 re.setZone(zone);
290 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
291 re.setRrLabel(Name("ndnsim-XYZ")); // insert new records
292 re.setRrType(label::NS_RR_TYPE);
293 re.setNdnsType(NDNS_RESP);
294
295 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000296 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800297 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000298 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800299
300 shared_ptr<Data> data = re.toData();
301 m_keyChain.sign(*data, dskCert->getName());
302
303 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
304 const Block& block = data->wireEncode();
305 Name name;
306 name.append(block);
307
308 q.setRrLabel(name);
309 q.setRrType(label::NDNS_UPDATE_LABEL);
310
311 bool hasDataBack = false;
312
313 // no data back, since the Update cannot pass verification
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000314 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800315 hasDataBack = true;
316 BOOST_FAIL("UNEXPECTED");
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700317 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800318
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000319 face.receive(q.toInterest());
Shock Jiange1a81fd2014-11-20 20:25:49 -0800320 run();
321
322 BOOST_CHECK_EQUAL(hasDataBack, false);
323}
324
325class NameServerFixture2 : public DbTestData
326{
327public:
328 NameServerFixture2()
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000329 : face(io, m_keyChain, {false, true})
330 , validatorFace(io, m_keyChain, {false, true})
Shock Jiange1a81fd2014-11-20 20:25:49 -0800331 , zone(m_root.getName())
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000332 , validator(validatorFace) // different face for validator
333 , server(zone, m_certName, face, m_session, m_keyChain, validator)
Shock Jiange1a81fd2014-11-20 20:25:49 -0800334 {
335 // ensure prefix is registered
336 run();
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700337
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000338 validatorFace.onSendInterest.connect([this] (const Interest& interest) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800339 NDNS_LOG_TRACE("validatorFace get Interest: " << interest.getName());
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700340
341 shared_ptr<const Interest> i = interest.shared_from_this();
342 io.post([i, this] {
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000343 face.receive(*i);
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700344 });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700345 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800346 }
347
348 void
349 run()
350 {
351 io.poll();
352 io.reset();
353 }
354
355public:
356 boost::asio::io_service io;
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000357 ndn::util::DummyClientFace face;
358 ndn::util::DummyClientFace validatorFace;
Shock Jiange1a81fd2014-11-20 20:25:49 -0800359 Name hint;
360 const Name& zone;
361 Validator validator;
362 ndns::NameServer server;
363};
364
365BOOST_FIXTURE_TEST_CASE(UpdateValidatorFetchCert, NameServerFixture2)
366{
367 Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false);
368 std::vector<CertificateSubjectDescription> desc;
369 time::system_clock::TimePoint notBefore = time::system_clock::now();
370 time::system_clock::TimePoint notAfter = notBefore + time::days(365);
371 shared_ptr<IdentityCertificate> dskCert =
372 m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName,
373 notBefore, notAfter, desc);
374
375 m_keyChain.sign(*dskCert, m_certName);
376 m_keyChain.addCertificateAsKeyDefault(*dskCert);
377 NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: "
378 << dskCert->getSignature().getKeyLocator().getName());
379
380 Rrset rrset(&m_root);
381 Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1);
382 rrset.setLabel(label);
383 rrset.setType(label::CERT_RR_TYPE);
384 rrset.setVersion(dskCert->getName().get(-1));
385 rrset.setTtl(m_root.getTtl());
386 rrset.setData(dskCert->wireEncode());
387 m_session.insert(rrset);
388 NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name="
389 << dskCert->getName() << " rrLabel=" << label);
390
391 Response re;
392 re.setZone(zone);
393 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
394 re.setRrLabel(Name("ndnsim-XYZ")); // insert new records
395 re.setRrType(label::NS_RR_TYPE);
396 re.setNdnsType(NDNS_RESP);
397
398 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000399 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800400 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000401 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800402
403 shared_ptr<Data> data = re.toData();
404 m_keyChain.sign(*data, dskCert->getName());
405
406 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
407 const Block& block = data->wireEncode();
408 Name name;
409 name.append(block);
410
411 q.setRrLabel(name);
412 q.setRrType(label::NDNS_UPDATE_LABEL);
413
414 bool hasDataBack = false;
415
416 shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT><>");
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000417 face.onSendData.connect([&] (const Data& data) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800418 if (regex->match(data.getName())) {
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700419 shared_ptr<const Data> d = data.shared_from_this();
420 io.post([d, this] {
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000421 validatorFace.receive(*d); // It's data requested by validator
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700422 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800423 }
424 else {
425 // cert is requested by validator
426 hasDataBack = true;
427 NDNS_LOG_TRACE("get Data back");
428 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
429 Response resp;
430
431 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800432 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
433 BOOST_CHECK_GT(resp.getRrs().size(), 0);
434 Block block = resp.getRrs()[0];
435 block.parse();
436 int ret = -1;
437 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
438 Block::element_const_iterator val = block.elements_begin();
439 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
440 ret = readNonNegativeInteger(*val);
441 BOOST_CHECK_EQUAL(ret, 0);
442 }
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700443 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800444
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000445 face.receive(q.toInterest());
Shock Jiange1a81fd2014-11-20 20:25:49 -0800446 run();
447
448 BOOST_CHECK_EQUAL(hasDataBack, true);
449}
450
Shock Jiangcde28712014-10-19 21:17:20 -0700451BOOST_AUTO_TEST_SUITE_END()
452
453} // namespace tests
454} // namespace ndns
455} // namespace ndn