Commit 949291a4 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2098] added base definition of TreeNodeRRset and some simple methods.

parent d5db8b95
......@@ -12,6 +12,7 @@ noinst_LTLIBRARIES = libdatasrc_memory.la
libdatasrc_memory_la_SOURCES = domaintree.h
libdatasrc_memory_la_SOURCES += rdataset.h rdataset.cc
libdatasrc_memory_la_SOURCES += treenode_rrset.h treenode_rrset.cc
libdatasrc_memory_la_SOURCES += rdata_serialization.h rdata_serialization.cc
libdatasrc_memory_la_SOURCES += zone_data.h zone_data.cc
libdatasrc_memory_la_SOURCES += zone_table.h zone_table.cc
......
......@@ -21,6 +21,7 @@ run_unittests_SOURCES = run_unittests.cc
run_unittests_SOURCES += rdata_serialization_unittest.cc
run_unittests_SOURCES += rdataset_unittest.cc
run_unittests_SOURCES += domaintree_unittest.cc
run_unittests_SOURCES += treenode_rrset_unittest.cc
run_unittests_SOURCES += zone_table_unittest.cc
run_unittests_SOURCES += zone_data_unittest.cc
run_unittests_SOURCES += memory_segment_test.h
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <util/memory_segment_local.h>
#include <datasrc/memory/treenode_rrset.h>
#include <datasrc/memory/rdataset.h>
#include <datasrc/memory/rdata_serialization.h>
#include <testutils/dnsmessage_test.h>
#include <gtest/gtest.h>
using namespace isc::dns;
using namespace isc::dns::rdata;
using namespace isc::datasrc::memory;
using namespace isc::testutils;
namespace {
class TreeNodeRRsetTest : public ::testing::Test {
protected:
TreeNodeRRsetTest() :
name_("www.example.com"),
a_rrset_(textToRRset("www.example.com. 3600 IN A 192.0.2.1")),
rrsig_rrset_(textToRRset("www.example.com. 3600 IN RRSIG "
"A 5 2 3600 20120814220826 20120715220826 "
"1234 example.com. FAKE"))
{
tree_ = ZoneTree::create(mem_sgmt_, true);
tree_->insert(mem_sgmt_, name_, &zone_node_);
rdataset_ = RdataSet::create(mem_sgmt_, encoder_, a_rrset_,
rrsig_rrset_);
zone_node_->setData(mem_sgmt_, rdataset_);
}
void TearDown() {
ZoneTree::destroy(mem_sgmt_, tree_);
// detect any memory leak
EXPECT_TRUE(mem_sgmt_.allMemoryDeallocated());
}
const Name name_;
isc::util::MemorySegmentLocal mem_sgmt_;
RdataEncoder encoder_;
ConstRRsetPtr a_rrset_, rrsig_rrset_;
ZoneTree* tree_;
ZoneNode* zone_node_;
RdataSet* rdataset_;
};
TEST_F(TreeNodeRRsetTest, create) {
const TreeNodeRRset rrset1(RRClass::IN(), zone_node_, rdataset_, true);
EXPECT_EQ(RRClass::IN(), rrset1.getClass());
EXPECT_EQ(RRType::A(), rrset1.getType());
EXPECT_EQ(1, rrset1.getRdataCount());
EXPECT_EQ(1, rrset1.getRRsigDataCount());
const TreeNodeRRset rrset2(RRClass::IN(), zone_node_, rdataset_, false);
EXPECT_EQ(RRClass::IN(), rrset2.getClass());
EXPECT_EQ(1, rrset2.getRdataCount());
EXPECT_EQ(0, rrset2.getRRsigDataCount());
}
}
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <exceptions/exceptions.h>
#include <util/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <dns/rrttl.h>
#include <dns/rdata.h>
#include <dns/rrset.h>
#include "treenode_rrset.h"
#include <string>
using namespace isc::dns;
using namespace isc::dns::rdata;
namespace isc {
namespace datasrc {
namespace memory {
const Name&
TreeNodeRRset::getName() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
const RRTTL&
TreeNodeRRset::getTTL() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::setName(const Name&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::setTTL(const RRTTL&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
// needed
std::string
TreeNodeRRset::toText() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
// needed
unsigned int
TreeNodeRRset::toWire(AbstractMessageRenderer& /*renderer*/) const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
unsigned int
TreeNodeRRset::toWire(isc::util::OutputBuffer& /*buffer*/) const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRdata(rdata::ConstRdataPtr) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRdata(const rdata::Rdata&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
// needed
RdataIteratorPtr
TreeNodeRRset::getRdataIterator() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
RRsetPtr
TreeNodeRRset::getRRsig() const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRRsig(const rdata::ConstRdataPtr&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRRsig(const rdata::RdataPtr&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRRsig(const AbstractRRset&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRRsig(const ConstRRsetPtr&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::addRRsig(const RRsetPtr&) {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
void
TreeNodeRRset::removeRRsig() {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
// needed
bool
TreeNodeRRset::isSameKind(const AbstractRRset& /*other*/) const {
isc_throw(Unexpected, "unexpected method called on TreeNodeRRset");
}
} // namespace memory
} // namespace datasrc
} // datasrc isc
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef DATASRC_MEMORY_TREENODE_RRSET_H
#define DATASRC_MEMORY_TREENODE_RRSET_H 1
#include <util/buffer.h>
#include <util/memory_segment.h>
#include <dns/messagerenderer.h>
#include <dns/name.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <dns/rrttl.h>
#include <dns/rdata.h>
#include <dns/rrset.h>
#include <datasrc/memory/domaintree.h>
#include <datasrc/memory/zone_data.h>
#include <datasrc/memory/rdataset.h>
#include <string>
namespace isc {
namespace datasrc {
namespace memory {
class RdataSetDeleter {
public:
RdataSetDeleter() {}
void operator()(util::MemorySegment& mem_sgmt,
RdataSet* rdataset_head) const
{
for (RdataSet* rdataset = rdataset_head;
rdataset != NULL;
rdataset = rdataset->next.get()) {
RdataSet::destroy(mem_sgmt, dns::RRClass::IN(), rdataset);
}
}
};
typedef DomainTree<RdataSet, RdataSetDeleter> ZoneTree;
typedef DomainTreeNode<RdataSet, RdataSetDeleter> ZoneNode;
class TreeNodeRRset : public dns::AbstractRRset {
public:
TreeNodeRRset(dns::RRClass rrclass, const ZoneNode* node,
const RdataSet* rdataset, bool dnssec_ok) :
node_(node), rdataset_(rdataset), rrclass_(rrclass),
dnssec_ok_(dnssec_ok)
{}
virtual ~TreeNodeRRset() {}
virtual unsigned int getRdataCount() const {
return (rdataset_->getRdataCount());
}
// needed
virtual const dns::Name& getName() const;
virtual const dns::RRClass& getClass() const {
return (rrclass_);
}
virtual const dns::RRType& getType() const {
return (rdataset_->type);
}
virtual const dns::RRTTL& getTTL() const;
virtual void setName(const dns::Name& name);
virtual void setTTL(const dns::RRTTL& ttl);
// needed
virtual std::string toText() const;
// needed
virtual unsigned int toWire(dns::AbstractMessageRenderer& renderer) const;
virtual unsigned int toWire(util::OutputBuffer& buffer) const;
virtual void addRdata(dns::rdata::ConstRdataPtr rdata);
virtual void addRdata(const dns::rdata::Rdata& rdata);
// needed
virtual dns::RdataIteratorPtr getRdataIterator() const;
virtual dns::RRsetPtr getRRsig() const;
virtual unsigned int getRRsigDataCount() const {
return (dnssec_ok_ ? rdataset_->getSigRdataCount() : 0);
}
virtual void addRRsig(const dns::rdata::ConstRdataPtr& rdata);
virtual void addRRsig(const dns::rdata::RdataPtr& rdata);
virtual void addRRsig(const dns::AbstractRRset& sigs);
virtual void addRRsig(const dns::ConstRRsetPtr& sigs);
virtual void addRRsig(const dns::RRsetPtr& sigs);
virtual void removeRRsig();
// needed
virtual bool isSameKind(const dns::AbstractRRset& other) const;
private:
const ZoneNode* node_;
const RdataSet* rdataset_;
const dns::RRClass rrclass_;
const bool dnssec_ok_;
};
} // namespace memory
} // namespace datasrc
} // namespace isc
#endif // DATASRC_MEMORY_TREENODE_RRSET_H
// Local Variables:
// mode: c++
// End:
Markdown is supported
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