Commit 7eee1221 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2432] Add RRClass too in the RRsetCollection key, and make find() search for them

This commit also changes the base class's find() prototype to include
the RRClass as an argument. Otherwise, we don't know what RRClass to
look for. The arguments for the base class's find() method are in a
different order from those of the find() methods in the RRsetCollection
implementation as there's no way to overload the method when only its
return value is different.
parent b5aa1d1b
......@@ -39,7 +39,8 @@ RRsetCollection::addRRset(const Name& name, const RRClass& rrclass,
void
RRsetCollection::addRRset(RRsetPtr rrset) {
const CollectionKey key(rrset->getName(), rrset->getType());
const CollectionKey key(rrset->getClass(), rrset->getType(),
rrset->getName());
rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
}
......@@ -57,8 +58,9 @@ RRsetCollection::RRsetCollection(const char* filename, const Name& origin,
}
const AbstractRRset*
RRsetCollection::find(const Name& name, const RRType& rrtype) const {
const CollectionKey key(name, rrtype);
RRsetCollection::find(const Name& name, const RRType& rrtype,
const RRClass& rrclass) const {
const CollectionKey key(rrclass, rrtype, name);
CollectionMap::const_iterator it = rrsets_.find(key);
if (it != rrsets_.end()) {
return (&(*it->second));
......@@ -67,8 +69,9 @@ RRsetCollection::find(const Name& name, const RRType& rrtype) const {
}
RRsetPtr
RRsetCollection::find(const Name& name, const RRClass&, const RRType& rrtype) {
const CollectionKey key(name, rrtype);
RRsetCollection::find(const Name& name, const RRClass& rrclass,
const RRType& rrtype) {
const CollectionKey key(rrclass, rrtype, name);
CollectionMap::iterator it = rrsets_.find(key);
if (it != rrsets_.end()) {
return (it->second);
......@@ -77,10 +80,10 @@ RRsetCollection::find(const Name& name, const RRClass&, const RRType& rrtype) {
}
ConstRRsetPtr
RRsetCollection::find(const Name& name, const RRClass&,
RRsetCollection::find(const Name& name, const RRClass& rrclass,
const RRType& rrtype) const
{
const CollectionKey key(name, rrtype);
const CollectionKey key(rrclass, rrtype, name);
CollectionMap::const_iterator it = rrsets_.find(key);
if (it != rrsets_.end()) {
return (it->second);
......@@ -89,10 +92,10 @@ RRsetCollection::find(const Name& name, const RRClass&,
}
void
RRsetCollection::removeRRset(const Name& name, const RRClass&,
RRsetCollection::removeRRset(const Name& name, const RRClass& rrclass,
const RRType& rrtype)
{
const CollectionKey key(name, rrtype);
const CollectionKey key(rrclass, rrtype, name);
rrsets_.erase(key);
}
......
......@@ -18,7 +18,9 @@
#include <dns/rrset_collection_base.h>
#include <dns/rrclass.h>
#include <utility>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <map>
namespace isc {
......@@ -63,9 +65,11 @@ public:
///
/// \param name The name of the RRset to search for.
/// \param rrtype The type of the RRset to search for.
/// \param rrclass The class of the RRset to search for.
/// \returns A pointer to the RRset if found, \c NULL otherwise.
virtual const isc::dns::AbstractRRset* find(const isc::dns::Name& name,
const isc::dns::RRType& rrtype)
virtual const isc::dns::AbstractRRset* find
(const isc::dns::Name& name, const isc::dns::RRType& rrtype,
const isc::dns::RRClass& rrclass)
const;
isc::dns::RRsetPtr find(const isc::dns::Name& name,
......@@ -82,7 +86,8 @@ private:
const isc::dns::rdata::RdataPtr& data);
void loaderCallback(const std::string&, size_t, const std::string&);
typedef std::pair<isc::dns::Name, isc::dns::RRType> CollectionKey;
typedef boost::tuple<isc::dns::RRClass, isc::dns::RRType, isc::dns::Name>
CollectionKey;
typedef std::map<CollectionKey, isc::dns::RRsetPtr> CollectionMap;
CollectionMap rrsets_;
......
......@@ -46,9 +46,11 @@ public:
///
/// \param name The name of the RRset to search for.
/// \param rrtype The type of the RRset to search for.
/// \param rrclass The class of the RRset to search for.
/// \returns A pointer to the RRset if found, \c NULL otherwise.
virtual const isc::dns::AbstractRRset* find(const isc::dns::Name& name,
const isc::dns::RRType& rrtype)
virtual const isc::dns::AbstractRRset* find
(const isc::dns::Name& name, const isc::dns::RRType& rrtype,
const isc::dns::RRClass& rrclass)
const = 0;
protected:
......
......@@ -40,7 +40,7 @@ public:
TEST_F(RRsetCollectionTest, findBase) {
// Test the find() that returns isc::dns::AbstractRRset*
const AbstractRRset* rrset = collection.find(Name("www.example.org"),
RRType::A());
RRType::A(), rrclass);
EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
EXPECT_EQ(RRType::A(), rrset->getType());
EXPECT_EQ(RRTTL(3600), rrset->getTTL());
......@@ -48,15 +48,15 @@ TEST_F(RRsetCollectionTest, findBase) {
EXPECT_EQ(Name("www.example.org"), rrset->getName());
// foo.example.org doesn't exist
rrset = collection.find(Name("foo.example.org"), RRType::A());
rrset = collection.find(Name("foo.example.org"), RRType::A(), rrclass);
EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
// www.example.org exists, but not with MX
rrset = collection.find(Name("www.example.org"), RRType::MX());
rrset = collection.find(Name("www.example.org"), RRType::MX(), rrclass);
EXPECT_EQ(static_cast<AbstractRRset*>(NULL), rrset);
// www.example.org exists, with AAAA
rrset = collection.find(Name("www.example.org"), RRType::AAAA());
rrset = collection.find(Name("www.example.org"), RRType::AAAA(), rrclass);
EXPECT_NE(static_cast<AbstractRRset*>(NULL), rrset);
}
......
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