Commit 6753f9e8 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2097] set value fields of RdataSet

parent c9b0c400
......@@ -12,18 +12,31 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <dns/rrtype.h>
#include <dns/rrset.h>
#include "rdataset.h"
#include "rdata_encoder.h"
#include <cstring>
#include <new> // for the placement new
using namespace isc::dns;
namespace isc {
namespace datasrc {
namespace memory {
RdataSet*
RdataSet::create(util::MemorySegment& mem_sgmt) {
RdataSet::create(util::MemorySegment& mem_sgmt, RdataEncoder& /*encoder*/,
dns::ConstRRsetPtr rrset, dns::ConstRRsetPtr sig_rrset)
{
void* p = mem_sgmt.allocate(sizeof(RdataSet));
RdataSet* rdataset = new(p) RdataSet();
RdataSet* rdataset = new(p) RdataSet(rrset->getType(),
rrset->getRdataCount(),
sig_rrset ?
sig_rrset->getRdataCount() : 0,
rrset->getTTL());
return (rdataset);
}
......@@ -33,6 +46,31 @@ RdataSet::destroy(util::MemorySegment& mem_sgmt, RdataSet* rdataset) {
mem_sgmt.deallocate(rdataset, sizeof(RdataSet));
}
namespace {
// Convert the given RRTTL into the corresponding 32-bit unsigned integer,
// in the network byte order. We do not use htonl() to be as portable as
// possible.
uint32_t
convertTTL(RRTTL ttl) {
const uint32_t ttl_val = ttl.getValue();
uint8_t buf[4];
buf[0] = (ttl_val & 0xff000000) >> 24;
buf[1] = (ttl_val & 0x00ff0000) >> 16;
buf[2] = (ttl_val & 0x0000ff00) >> 8;
buf[3] = (ttl_val & 0x000000ff);
uint32_t ret;
std::memcpy(&ret, buf, sizeof(ret));
return (ret);
}
}
RdataSet::RdataSet(RRType type_param, size_t rdata_count_param,
size_t sig_rdata_count_param, RRTTL ttl_param) :
type(type_param), sig_rdata_count(sig_rdata_count_param),
rdata_count(rdata_count_param), ttl(convertTTL(ttl_param))
{
}
} // namespace memory
} // namespace datasrc
} // datasrc isc
......@@ -17,16 +17,32 @@
#include <util/memory_segment.h>
#include <dns/rrtype.h>
#include <dns/rrset.h>
#include <dns/rrttl.h>
#include <stdint.h>
namespace isc {
namespace datasrc {
namespace memory {
class RdataEncoder;
struct RdataSet {
static RdataSet* create(util::MemorySegment& mem_sgmt);
static RdataSet* create(util::MemorySegment& mem_sgmt,
RdataEncoder& encoder,
dns::ConstRRsetPtr rrset,
dns::ConstRRsetPtr sig_rrset);
static void destroy(util::MemorySegment& mem_sgmt, RdataSet* rdataset);
const dns::RRType type;
const uint16_t sig_rdata_count : 3;
const uint16_t rdata_count : 13;
const uint32_t ttl; ///< TTL of the RdataSet, net byte order
private:
RdataSet() {}
RdataSet(dns::RRType type, size_t rdata_count, size_t sig_rdata_count,
dns::RRTTL ttl);
~RdataSet() {}
};
......
......@@ -28,6 +28,8 @@ run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(builddir)/../libdatasrc_memory.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libb10-dns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
run_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libb10-testutils.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
run_unittests_LDADD += $(GTEST_LDADD)
endif
......
......@@ -12,29 +12,54 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <util/buffer.h>
#include <util/memory_segment_local.h>
#include <dns/rrset.h>
#include <dns/rrttl.h>
#include <datasrc/memory/rdata_encoder.h>
#include <datasrc/memory/rdataset.h>
#include <testutils/dnsmessage_test.h>
#include <gtest/gtest.h>
using namespace isc::dns;
using namespace isc::datasrc::memory;
using namespace isc::testutils;
namespace {
class RdataSetTest : public ::testing::Test {
protected:
RdataSetTest() {}
RdataSetTest() :
// 1076895760 = 0x40302010. Use this so we fill in all 8-bit "field"
// of the 32-bit TTL
a_rrset_(textToRRset("www.example.com. 1076895760 IN A 192.0.2.1"))
{}
void TearDown() {
EXPECT_TRUE(mem_sgmt_.allMemoryDeallocated());
}
ConstRRsetPtr a_rrset_;
isc::util::MemorySegmentLocal mem_sgmt_;
RdataEncoder encoder_;
};
RRTTL
restoreTTL(uint32_t net_ttl) {
isc::util::InputBuffer b(&net_ttl, sizeof(net_ttl));
return (RRTTL(b));
}
TEST_F(RdataSetTest, create) {
RdataSet* rdataset = RdataSet::create(mem_sgmt_);
EXPECT_NE(static_cast<RdataSet*>(NULL), rdataset);
RdataSet* rdataset = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
ConstRRsetPtr());
EXPECT_EQ(RRType::A(), rdataset->type);
EXPECT_EQ(RRTTL(1076895760), restoreTTL(rdataset->ttl));
EXPECT_EQ(1, rdataset->rdata_count);
EXPECT_EQ(0, rdataset->sig_rdata_count);
RdataSet::destroy(mem_sgmt_, rdataset);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment