From: Mukund Sivaraman Date: Mon, 7 Jan 2013 14:21:27 +0000 (+0530) Subject: [2435] Implement datasrc version of RRsetCollection X-Git-Tag: bind10-1.0.0-rc-release~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70cb4d4886e27554e9a9e8751089ba8bd4678701;p=thirdparty%2Fkea.git [2435] Implement datasrc version of RRsetCollection --- diff --git a/src/lib/datasrc/Makefile.am b/src/lib/datasrc/Makefile.am index a4edd4e564..ea70d9264b 100644 --- a/src/lib/datasrc/Makefile.am +++ b/src/lib/datasrc/Makefile.am @@ -38,6 +38,7 @@ libb10_datasrc_la_SOURCES += client_list.h client_list.cc libb10_datasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc libb10_datasrc_la_SOURCES += master_loader_callbacks.h libb10_datasrc_la_SOURCES += master_loader_callbacks.cc +libb10_datasrc_la_SOURCES += rrset_collection.h rrset_collection.cc libb10_datasrc_la_SOURCES += zone_loader.h zone_loader.cc nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1 diff --git a/src/lib/datasrc/rrset_collection.cc b/src/lib/datasrc/rrset_collection.cc new file mode 100644 index 0000000000..e9a5fd8271 --- /dev/null +++ b/src/lib/datasrc/rrset_collection.cc @@ -0,0 +1,51 @@ +// 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 +#include + +using namespace isc; +using namespace isc::dns; + +namespace isc { +namespace datasrc { + +ConstRRsetPtr +RRsetCollection::find(const isc::dns::Name& name, + const isc::dns::RRClass&, + const isc::dns::RRType& rrtype) const +{ + // TODO: RRClass needs to be checked here to see if it is as + // expected. + + ZoneFinder& finder = updater_->getFinder(); + ZoneFinderContextPtr result = + finder.find(name, rrtype, + ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK); + + return (result->rrset); +} + +RRsetCollectionBase::IterPtr +RRsetCollection::getBeginning() { + isc_throw(NotImplemented, "This method is not implemented."); +} + +RRsetCollectionBase::IterPtr +RRsetCollection::getEnd() { + isc_throw(NotImplemented, "This method is not implemented."); +} + +} // end of namespace datasrc +} // end of namespace isc diff --git a/src/lib/datasrc/rrset_collection.h b/src/lib/datasrc/rrset_collection.h new file mode 100644 index 0000000000..c8a6add4e9 --- /dev/null +++ b/src/lib/datasrc/rrset_collection.h @@ -0,0 +1,89 @@ +// 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 RRSET_COLLECTION_DATASRC_H +#define RRSET_COLLECTION_DATASRC_H 1 + +#include +#include +#include + +namespace isc { +namespace datasrc { + +/// \brief datasrc implementation of RRsetCollectionBase. +class RRsetCollection : public isc::dns::RRsetCollectionBase { +public: + /// \brief Constructor. + /// \param updater The ZoneUpdater to wrap around. + RRsetCollection(ZoneUpdaterPtr updater) : + updater_(updater) + {} + + /// \brief Destructor + virtual ~RRsetCollection() {} + + /// \brief Find a matching RRset in the collection. + /// + /// Returns the RRset in the collection that exactly matches the + /// given \c name, \c rrclass and \c rrtype. If no matching RRset + /// is found, \c NULL is returned. + /// + /// \param name The name of the RRset to search for. + /// \param rrclass The class of the RRset to search for. + /// \param rrtype The type of the RRset to search for. + /// \returns The RRset if found, \c NULL otherwise. + virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name& name, + const isc::dns::RRClass& rrclass, + const isc::dns::RRType& rrtype) const; + +private: + ZoneUpdaterPtr updater_; + +protected: + class DsIter : public RRsetCollectionBase::Iter { + public: + DsIter() + {} + + virtual const isc::dns::AbstractRRset& getValue() { + isc_throw(isc::NotImplemented, "This method is not implemented."); + } + + virtual IterPtr getNext() { + isc_throw(isc::NotImplemented, "This method is not implemented."); + } + + virtual bool equals(Iter& other) { + const DsIter* other_real = dynamic_cast(&other); + if (other_real == NULL) { + return (false); + } + + isc_throw(isc::NotImplemented, "This method is not implemented."); + } + }; + + virtual RRsetCollectionBase::IterPtr getBeginning(); + virtual RRsetCollectionBase::IterPtr getEnd(); +}; + +} // end of namespace datasrc +} // end of namespace isc + +#endif // RRSET_COLLECTION_DATASRC_H + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc index 174da0442c..9d81f5e2d2 100644 --- a/src/lib/datasrc/tests/database_unittest.cc +++ b/src/lib/datasrc/tests/database_unittest.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -4151,4 +4152,43 @@ TYPED_TEST(DatabaseClientTest, createZoneRollbackOnExists) { ASSERT_TRUE(this->client_->createZone(new_name)); } +class RRsetCollectionTest : public DatabaseClientTest { +public: + RRsetCollectionTest() : + DatabaseClientTest(), + collection(this->client_->getUpdater(this->zname_, false)) + {} + + RRsetCollection collection; +}; + +TEST_F(RRsetCollectionTest, find) { + // Test the find() that returns ConstRRsetPtr + ConstRRsetPtr rrset = collection.find(Name("www.example.org."), + RRClass::IN(), RRType::A()); + ASSERT_TRUE(rrset); + EXPECT_EQ(RRType::A(), rrset->getType()); + EXPECT_EQ(RRTTL(3600), rrset->getTTL()); + EXPECT_EQ(RRClass("IN"), rrset->getClass()); + EXPECT_EQ(Name("www.example.org"), rrset->getName()); + + // foo.example.org doesn't exist + rrset = collection.find(Name("foo.example.org"), qclass_, RRType::A()); + EXPECT_FALSE(rrset); + + // www.example.org exists, but not with MX + rrset = collection.find(Name("www.example.org"), qclass_, RRType::MX()); + EXPECT_FALSE(rrset); + + // www.example.org exists, with AAAA + rrset = collection.find(Name("www.example.org"), qclass_, RRType::AAAA()); + EXPECT_TRUE(rrset); +} + +TEST_F(RRsetCollectionTest, iteratorTest) { + // Iterators are currently not implemented. + EXPECT_THROW(collection.begin(), isc::NotImplemented); + EXPECT_THROW(collection.end(), isc::NotImplemented); +} + }