blob: 6a9be9781adcfc71e2aaa8a26baabfca0a8837cf [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
20#include "daemon/db-mgr.hpp"
21#include "daemon/name-server.hpp"
22#include "clients/response.hpp"
23#include "clients/query.hpp"
24#include "logger.hpp"
25
26#include "../database-test-data.hpp"
27#include "../../boost-test.hpp"
28
29#include <boost/filesystem.hpp>
30#include <ndn-cxx/face.hpp>
31#include <ndn-cxx/util/dummy-client-face.hpp>
32
33namespace ndn {
34namespace ndns {
35namespace tests {
36
Alexander Afanasyevc7c99002015-10-09 17:27:30 -070037NDNS_LOG_INIT("NameServerTest")
Shock Jiangcde28712014-10-19 21:17:20 -070038
39class NameServerFixture : public DbTestData
40{
41public:
42 NameServerFixture()
Junxiao Shibbf7ac82016-07-14 14:45:15 +000043 : face({false, true})
Shock Jiange1a81fd2014-11-20 20:25:49 -080044 , zone(m_root.getName())
Junxiao Shibbf7ac82016-07-14 14:45:15 +000045 , validator(face)
46 , server(zone, m_certName, face, m_session, m_keyChain, validator)
Shock Jiangcde28712014-10-19 21:17:20 -070047 {
48 // ensure prefix is registered
49 run();
50 }
51
52 void
53 run()
54 {
Junxiao Shibbf7ac82016-07-14 14:45:15 +000055 face.getIoService().poll();
56 face.getIoService().reset();
Shock Jiangcde28712014-10-19 21:17:20 -070057 }
58
59public:
Junxiao Shibbf7ac82016-07-14 14:45:15 +000060 ndn::util::DummyClientFace face;
Shock Jiangcde28712014-10-19 21:17:20 -070061 Name hint;
62 const Name& zone;
63 Validator validator;
64 ndns::NameServer server;
65};
66
67BOOST_FIXTURE_TEST_SUITE(NameServer, NameServerFixture)
68
69BOOST_AUTO_TEST_CASE(NdnsQuery)
70{
71 Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -080072 q.setRrLabel(Name("net"));
Shock Jiangcde28712014-10-19 21:17:20 -070073 q.setRrType(ndns::label::NS_RR_TYPE);
74
75 bool hasDataBack = false;
76
Junxiao Shibbf7ac82016-07-14 14:45:15 +000077 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -070078 hasDataBack = true;
79 NDNS_LOG_TRACE("get Data back");
80 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
81
82 Response resp;
83 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
84 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -070085 });
Shock Jiangcde28712014-10-19 21:17:20 -070086
Junxiao Shibbf7ac82016-07-14 14:45:15 +000087 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -070088
89 run();
90
91 BOOST_CHECK_EQUAL(hasDataBack, true);
92}
93
94BOOST_AUTO_TEST_CASE(KeyQuery)
95{
96 Query q(hint, zone, ndns::label::NDNS_ITERATIVE_QUERY);
97 q.setQueryType(ndns::label::NDNS_CERT_QUERY);
98 q.setRrType(ndns::label::CERT_RR_TYPE);
99
100 size_t nDataBack = 0;
101
102 // will ask for non-existing record
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000103 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700104 ++nDataBack;
105 NDNS_LOG_TRACE("get Data back");
106 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
107
108 Response resp;
109 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
110 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_NACK);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700111 });
Shock Jiangcde28712014-10-19 21:17:20 -0700112
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000113 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700114 run();
115
116 // will ask for the existing record (will have type NDNS_RAW, as it is certificate)
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000117 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700118 ++nDataBack;
119 NDNS_LOG_TRACE("get Data back");
120 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
121
122 Response resp;
123 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
124 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RAW);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700125 });
Shock Jiangcde28712014-10-19 21:17:20 -0700126
Shock Jiange1a81fd2014-11-20 20:25:49 -0800127 q.setRrLabel("dsk-1");
Shock Jiangcde28712014-10-19 21:17:20 -0700128
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000129 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700130 run();
131
132 BOOST_CHECK_EQUAL(nDataBack, 2);
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800133
134 // explicit interest with correct version
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000135 face.receive(Interest("/test19/KEY/dsk-1/ID-CERT/%FDd"));
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800136
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000137 face.onSendData.connectSingleShot([&] (const Data& data) {
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800138 ++nDataBack;
139
140 Response resp;
141 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
142 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RAW);
143 });
144
145 run();
146 BOOST_CHECK_EQUAL(nDataBack, 3);
147
148 // explicit interest with wrong version
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000149 face.receive(Interest("/test19/KEY/dsk-1/ID-CERT/%FD010101010"));
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800150
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000151 face.onSendData.connectSingleShot([&] (const Data& data) {
Alexander Afanasyevaa46c272016-03-09 12:54:12 -0800152 ++nDataBack;
153
154 Response resp;
155 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
156 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_NACK);
157 });
158
159 run();
160 BOOST_CHECK_EQUAL(nDataBack, 4);
Shock Jiangcde28712014-10-19 21:17:20 -0700161}
162
163BOOST_AUTO_TEST_CASE(UpdateReplaceRr)
164{
165 Response re;
166 re.setZone(zone);
167 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -0800168 re.setRrLabel(Name("net"));
Shock Jiangcde28712014-10-19 21:17:20 -0700169 re.setRrType(label::NS_RR_TYPE);
170 re.setNdnsType(NDNS_RESP);
171
172 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000173 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700174 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000175 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700176
177 shared_ptr<Data> data = re.toData();
178 m_keyChain.sign(*data, m_certName);
179
180 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
181 const Block& block = data->wireEncode();
182 Name name;
183 name.append(block);
184
185 q.setRrLabel(name);
186 q.setRrType(label::NDNS_UPDATE_LABEL);
187
188 bool hasDataBack = false;
189
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000190 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700191 hasDataBack = true;
192 NDNS_LOG_TRACE("get Data back");
193 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
194 Response resp;
195
196 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiangcde28712014-10-19 21:17:20 -0700197 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
198 BOOST_CHECK_GT(resp.getRrs().size(), 0);
199 Block block = resp.getRrs()[0];
200 block.parse();
201 int ret = -1;
202 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
203 Block::element_const_iterator val = block.elements_begin();
204 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
205 ret = readNonNegativeInteger(*val);
206 BOOST_CHECK_EQUAL(ret, 0);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700207 });
Shock Jiangcde28712014-10-19 21:17:20 -0700208
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000209 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700210 run();
211
212 BOOST_CHECK_EQUAL(hasDataBack, true);
213}
214
215BOOST_AUTO_TEST_CASE(UpdateInsertNewRr)
216{
217 Response re;
218 re.setZone(zone);
219 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
Shock Jiange1a81fd2014-11-20 20:25:49 -0800220 re.setRrLabel(Name("net-XYZ")); // insert new records
Shock Jiangcde28712014-10-19 21:17:20 -0700221 re.setRrType(label::NS_RR_TYPE);
222 re.setNdnsType(NDNS_RESP);
223
224 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000225 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700226 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000227 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiangcde28712014-10-19 21:17:20 -0700228
229 shared_ptr<Data> data = re.toData();
230 m_keyChain.sign(*data, m_certName);
231
232 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
233 const Block& block = data->wireEncode();
234 Name name;
235 name.append(block);
236
237 q.setRrLabel(name);
238 q.setRrType(label::NDNS_UPDATE_LABEL);
239
240 bool hasDataBack = false;
241
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000242 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiangcde28712014-10-19 21:17:20 -0700243 hasDataBack = true;
244 NDNS_LOG_TRACE("get Data back");
245 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
246 Response resp;
247
248 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiangcde28712014-10-19 21:17:20 -0700249 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
250 BOOST_CHECK_GT(resp.getRrs().size(), 0);
251 Block block = resp.getRrs()[0];
252 block.parse();
253 int ret = -1;
254 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
255 Block::element_const_iterator val = block.elements_begin();
256 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
257 ret = readNonNegativeInteger(*val);
258 BOOST_CHECK_EQUAL(ret, 0);
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700259 });
Shock Jiangcde28712014-10-19 21:17:20 -0700260
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000261 face.receive(q.toInterest());
Shock Jiangcde28712014-10-19 21:17:20 -0700262 run();
263
264 BOOST_CHECK_EQUAL(hasDataBack, true);
265}
266
Shock Jiange1a81fd2014-11-20 20:25:49 -0800267BOOST_AUTO_TEST_CASE(UpdateValidatorCannotFetchCert)
268{
269 Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false);
270 std::vector<CertificateSubjectDescription> desc;
271 time::system_clock::TimePoint notBefore = time::system_clock::now();
272 time::system_clock::TimePoint notAfter = notBefore + time::days(365);
273 shared_ptr<IdentityCertificate> dskCert =
274 m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName,
275 notBefore, notAfter, desc);
276
277 m_keyChain.sign(*dskCert, m_certName);
278 m_keyChain.addCertificateAsKeyDefault(*dskCert);
279 NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: "
280 << dskCert->getSignature().getKeyLocator().getName());
281
282 Rrset rrset(&m_root);
283 Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1);
284 rrset.setLabel(label);
285 rrset.setType(label::CERT_RR_TYPE);
286 rrset.setVersion(dskCert->getName().get(-1));
287 rrset.setTtl(m_root.getTtl());
288 rrset.setData(dskCert->wireEncode());
289 m_session.insert(rrset);
290 NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name="
291 << dskCert->getName() << " rrLabel=" << label);
292
293 Response re;
294 re.setZone(zone);
295 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
296 re.setRrLabel(Name("ndnsim-XYZ")); // insert new records
297 re.setRrType(label::NS_RR_TYPE);
298 re.setNdnsType(NDNS_RESP);
299
300 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000301 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800302 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000303 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800304
305 shared_ptr<Data> data = re.toData();
306 m_keyChain.sign(*data, dskCert->getName());
307
308 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
309 const Block& block = data->wireEncode();
310 Name name;
311 name.append(block);
312
313 q.setRrLabel(name);
314 q.setRrType(label::NDNS_UPDATE_LABEL);
315
316 bool hasDataBack = false;
317
318 // no data back, since the Update cannot pass verification
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000319 face.onSendData.connectSingleShot([&] (const Data& data) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800320 hasDataBack = true;
321 BOOST_FAIL("UNEXPECTED");
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700322 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800323
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000324 face.receive(q.toInterest());
Shock Jiange1a81fd2014-11-20 20:25:49 -0800325 run();
326
327 BOOST_CHECK_EQUAL(hasDataBack, false);
328}
329
330class NameServerFixture2 : public DbTestData
331{
332public:
333 NameServerFixture2()
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000334 : face(io, m_keyChain, {false, true})
335 , validatorFace(io, m_keyChain, {false, true})
Shock Jiange1a81fd2014-11-20 20:25:49 -0800336 , zone(m_root.getName())
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000337 , validator(validatorFace) // different face for validator
338 , server(zone, m_certName, face, m_session, m_keyChain, validator)
Shock Jiange1a81fd2014-11-20 20:25:49 -0800339 {
340 // ensure prefix is registered
341 run();
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700342
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000343 validatorFace.onSendInterest.connect([this] (const Interest& interest) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800344 NDNS_LOG_TRACE("validatorFace get Interest: " << interest.getName());
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700345
346 shared_ptr<const Interest> i = interest.shared_from_this();
347 io.post([i, this] {
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000348 face.receive(*i);
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700349 });
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700350 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800351 }
352
353 void
354 run()
355 {
356 io.poll();
357 io.reset();
358 }
359
360public:
361 boost::asio::io_service io;
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000362 ndn::util::DummyClientFace face;
363 ndn::util::DummyClientFace validatorFace;
Shock Jiange1a81fd2014-11-20 20:25:49 -0800364 Name hint;
365 const Name& zone;
366 Validator validator;
367 ndns::NameServer server;
368};
369
370BOOST_FIXTURE_TEST_CASE(UpdateValidatorFetchCert, NameServerFixture2)
371{
372 Name dskName = m_keyChain.generateRsaKeyPair(TEST_IDENTITY_NAME, false);
373 std::vector<CertificateSubjectDescription> desc;
374 time::system_clock::TimePoint notBefore = time::system_clock::now();
375 time::system_clock::TimePoint notAfter = notBefore + time::days(365);
376 shared_ptr<IdentityCertificate> dskCert =
377 m_keyChain.prepareUnsignedIdentityCertificate(dskName, m_certName,
378 notBefore, notAfter, desc);
379
380 m_keyChain.sign(*dskCert, m_certName);
381 m_keyChain.addCertificateAsKeyDefault(*dskCert);
382 NDNS_LOG_TRACE("KeyChain: add cert: " << dskCert->getName() << ". KeyLocator: "
383 << dskCert->getSignature().getKeyLocator().getName());
384
385 Rrset rrset(&m_root);
386 Name label = dskCert->getName().getPrefix(-2).getSubName(m_root.getName().size() + 1);
387 rrset.setLabel(label);
388 rrset.setType(label::CERT_RR_TYPE);
389 rrset.setVersion(dskCert->getName().get(-1));
390 rrset.setTtl(m_root.getTtl());
391 rrset.setData(dskCert->wireEncode());
392 m_session.insert(rrset);
393 NDNS_LOG_TRACE("DB: zone " << m_root << " add a ID-CERT RR with name="
394 << dskCert->getName() << " rrLabel=" << label);
395
396 Response re;
397 re.setZone(zone);
398 re.setQueryType(label::NDNS_ITERATIVE_QUERY);
399 re.setRrLabel(Name("ndnsim-XYZ")); // insert new records
400 re.setRrType(label::NS_RR_TYPE);
401 re.setNdnsType(NDNS_RESP);
402
403 std::string str = "ns1.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000404 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800405 str = "ns2.ndnsim.net";
Junxiao Shi767f35c2016-07-23 01:54:42 +0000406 re.addRr(makeBinaryBlock(ndns::tlv::RrData, str.c_str(), str.size()));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800407
408 shared_ptr<Data> data = re.toData();
409 m_keyChain.sign(*data, dskCert->getName());
410
411 Query q(Name(hint), Name(zone), ndns::label::NDNS_ITERATIVE_QUERY);
412 const Block& block = data->wireEncode();
413 Name name;
414 name.append(block);
415
416 q.setRrLabel(name);
417 q.setRrType(label::NDNS_UPDATE_LABEL);
418
419 bool hasDataBack = false;
420
421 shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT><>");
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000422 face.onSendData.connect([&] (const Data& data) {
Shock Jiange1a81fd2014-11-20 20:25:49 -0800423 if (regex->match(data.getName())) {
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700424 shared_ptr<const Data> d = data.shared_from_this();
425 io.post([d, this] {
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000426 validatorFace.receive(*d); // It's data requested by validator
Alexander Afanasyeva81266c2015-05-10 20:18:57 -0700427 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800428 }
429 else {
430 // cert is requested by validator
431 hasDataBack = true;
432 NDNS_LOG_TRACE("get Data back");
433 BOOST_CHECK_EQUAL(data.getName().getPrefix(-1), q.toInterest().getName());
434 Response resp;
435
436 BOOST_CHECK_NO_THROW(resp.fromData(hint, zone, data));
Shock Jiange1a81fd2014-11-20 20:25:49 -0800437 BOOST_CHECK_EQUAL(resp.getNdnsType(), NDNS_RESP); // by default NDNS_RAW is enough
438 BOOST_CHECK_GT(resp.getRrs().size(), 0);
439 Block block = resp.getRrs()[0];
440 block.parse();
441 int ret = -1;
442 BOOST_CHECK_EQUAL(block.type(), ndns::tlv::RrData);
443 Block::element_const_iterator val = block.elements_begin();
444 BOOST_CHECK_EQUAL(val->type(), ndns::tlv::UpdateReturnCode); // the first must be return code
445 ret = readNonNegativeInteger(*val);
446 BOOST_CHECK_EQUAL(ret, 0);
447 }
Junxiao Shi8f5be2a2015-01-06 10:06:43 -0700448 });
Shock Jiange1a81fd2014-11-20 20:25:49 -0800449
Junxiao Shibbf7ac82016-07-14 14:45:15 +0000450 face.receive(q.toInterest());
Shock Jiange1a81fd2014-11-20 20:25:49 -0800451 run();
452
453 BOOST_CHECK_EQUAL(hasDataBack, true);
454}
455
Shock Jiangcde28712014-10-19 21:17:20 -0700456BOOST_AUTO_TEST_SUITE_END()
457
458} // namespace tests
459} // namespace ndns
460} // namespace ndn