Commit 5efcee70 authored by Likun Zhang's avatar Likun Zhang
Browse files

Commit unfinished code of recursor cache, in case it is deleted by mistake.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac449@4017 e5f2f494-b856-4b98-b285-d166d9295462
parent 5a7d0824
......@@ -616,6 +616,8 @@ AC_CONFIG_FILES([Makefile
src/lib/testutils/testdata/Makefile
src/lib/nsas/Makefile
src/lib/nsas/tests/Makefile
src/lib/cache/Makefile
src/lib/cache/tests/Makefile
])
AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
src/bin/cfgmgr/tests/b10-cfgmgr_test.py
......
SUBDIRS = exceptions dns cc config datasrc python xfr bench log asiolink \
testutils nsas
testutils nsas cache
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES) $(MULTITHREADING_FLAG)
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/nsas -I$(top_builddir)/src/lib/nsas
AM_CPPFLAGS += -I$(top_srcdir)/src/lib/cache -I$(top_builddir)/src/lib/cache
AM_CPPFLAGS += $(SQLITE_CFLAGS)
AM_CXXFLAGS = $(B10_CXXFLAGS)
# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
if USE_CLANGPP
# clang++ complains about unused function parameters in some boost header
# files.
AM_CXXFLAGS += -Wno-unused-parameter
endif
lib_LTLIBRARIES = libcache.la
libcache_la_SOURCES = recursor_cache.h recursor_cache.cc
libcache_la_SOURCES += message_cache.h message_cache.cc
libcache_la_SOURCES += message_entry.h message_entry.cc
libcache_la_SOURCES += rrset_cache.h rrset_cache.cc
libcache_la_SOURCES += rrset_entry.h rrset_entry.cc
CLEANFILES = *.gcno *.gcda
// Copyright (C) 2010 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.
// $Id$
#include "message_cache.h"
#include <nsas/nsas_entry_compare.h>
#include <nsas/hash_table.h>
#include <nsas/hash_deleter.h>
using namespace isc::nsas;
namespace isc {
namespace cache {
MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
uint32_t cache_size):
rrset_cache_(rrset_cache),
message_table_(new NsasEntryCompare<MessageEntry>, cache_size),
message_lru_((3 * cache_size),
new HashDeleter<MessageEntry>(message_table_))
{
}
bool
MessageCache::lookUp(const isc::dns::Name&,
const isc::dns::RRType&,
const isc::dns::RRClass&,
isc::dns::Message& )
{
return true;
}
bool
MessageCache::update(const isc::dns::Message&) {
return true;
}
void
MessageCache::dump(const std::string&) {
}
void
MessageCache::load(const std::string&) {
}
bool
MessageCache::resize(uint32_t) {
return true;
}
} // namespace cache
} // namespace isc
// Copyright (C) 2010 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.
// $Id$
#ifndef __MESSAGE_CACHE_H
#define __MESSAGE_CACHE_H
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
#include <dns/message.h>
#include "message_entry.h"
#include <nsas/hash_table.h>
#include <nsas/lru_list.h>
namespace isc {
namespace cache {
class RRsetCache;
/// \brief Message Cache
/// The object of MessageCache represents the cache for class-specific
/// messages.
///
class MessageCache {
public:
/// \param cache_size The size of message cache.
MessageCache(boost::shared_ptr<RRsetCache> rrset_cache_,
uint32_t cache_size);
/// \brief Look up message in cache.
/// \param message generated response message if the message entry
/// can be found.
/// \return return true if the message can be found in cache, or else,
/// return false.
//TODO Maybe some user just want to get the message_entry.
bool lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
isc::dns::Message& message);
/// \brief Update the message in the cache with the new one.
/// If the message doesn't exist in the cache, it will be added
/// directly.
bool update(const isc::dns::Message& msg);
/// \brief Dump the message cache to specified file.
/// \todo It should can be dumped to one configured database.
void dump(const std::string& file_name);
/// \brief Load the cache from one file.
/// \todo It should can be loaded from one configured database.
void load(const std::string& file_name);
/// \brief Resize the size of message cache in runtime.
bool resize(uint32_t size);
private:
uint16_t class_; // The class of the message cache.
boost::shared_ptr<RRsetCache> rrset_cache_;
isc::nsas::HashTable<MessageEntry> message_table_;
isc::nsas::LruList<MessageEntry> message_lru_;
};
} // namespace cache
} // namespace isc
#endif // __MESSAGE_CACHE_H
// Copyright (C) 2010 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.
// $Id$
#include <dns/message.h>
#include <nsas/nsas_entry.h>
#include <nsas/fetchable.h>
#include "message_entry.h"
namespace isc {
namespace cache {
MessageEntry::MessageEntry()
{
}
} // namespace cache
} // namespace isc
// Copyright (C) 2010 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.
// $Id$
#ifndef __MESSAGE_ENTRY_H
#define __MESSAGE_ENTRY_H
#include <vector>
#include <dns/message.h>
#include <nsas/nsas_entry.h>
#include <nsas/fetchable.h>
using namespace isc::nsas;
namespace isc {
namespace cache {
class RRsetEntry;
class MessageEntry : public NsasEntry<MessageEntry>,
public Fetchable
{
public:
MessageEntry();
/// \brief generate one dns message according
/// the rrsets information of the message.
/// \param response generated dns message.
/// \param time_now set the ttl of each rrset in the message
/// as "expire_time - time_now" (expire_time is the
/// expiration time of the rrset).
/// \param query_header the query message header.
void generateMessage(isc::dns::Message& response,
time_t* time_now,
uint16_t query_header);
private:
time_t expire_time_; // Expiration time of the message.
std::string query_name_; // query name of the message.
uint16_t query_class_; // query class of the message.
uint16_t query_type_; // query type of message.
uint16_t query_count_; // query count in query section.
uint16_t answer_count_; // rrset count in answer section.
uint16_t authority_count_; // rrset count in authority section.
uint16_t addition_count_; // rrset count in addition section.
std::vector<boost::shared_ptr<RRsetEntry*> > rrsets_;
};
} // namespace cache
} // namespace isc
#endif // __MESSAGE_ENTRY_H
// Copyright (C) 2010 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.
// $Id$
#include "recursor_cache.h"
namespace isc {
namespace cache {
RecursorCache::RecursorCache() {
}
bool
RecursorCache::lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
isc::dns::Message& response)
{
//TODO, temp code begin
qname.toText();
qtype.toText();
qclass.toText();
response.toText();
//TODO, temp code end
return true;
}
bool
RecursorCache::lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
isc::dns::RRset& rrset)
{
//TODO, temp code begin
qname.toText();
qtype.toText();
qclass.toText();
rrset.toText();
//TODO, temp code end
return true;
}
void
RecursorCache::update(const isc::dns::Message& msg) {
msg.toText();
return;
}
void
RecursorCache::update(const isc::dns::RRset& rrset) {
rrset.toText();
return;
}
void
RecursorCache::dump(const std::string& file_name) {
std::cout << file_name;
}
void
RecursorCache::load(const std::string& file_name) {
std::cout << file_name;
}
} // namespace cache
} // namespace isc
// Copyright (C) 2010 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.
// $Id$
#ifndef __RECURSOR_CACHE_H
#define __RECURSOR_CACHE_H
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
#include <dns/message.h>
#include "message_cache.h"
namespace isc {
namespace cache {
class RRsetCache;
///
/// \brief Recursor Cache
/// The object of RecursorCache represents the cache of the recursor. It holds
/// a list of message cache and rrset cache.
///
class RecursorCache {
public:
RecursorCache();
/// \name Lookup Interfaces
//@{
/// \brief Look up message in cache.
///
/// \param response generated response message if the message can be found
/// in cache.
///
/// \return return true if the message can be found, or else, return false.
bool lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
isc::dns::Message& response);
/// \brief Look up rrset in cache.
/// \param rrset generated rrset if it can be found in the cache.
/// \return return true if the rrset can be found, or else, return false.
///
/// \overload
///
bool lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
isc::dns::RRset& rrset);
//@}
/// \brief Update the message in the cache with the new one.
void update(const isc::dns::Message& msg);
/// \brief Update the rrset in the cache with the new one.
/// rrset_cache1_ and rrset_cache2_ should be updated together
/// if the rrset exists in both of them.
///
/// \overload
///
void update(const isc::dns::RRset& rrset);
/// \name Cache Serialization
//@{
/// \brief Dump the cache content to one file.
/// \todo It should can be dumped to one configured database.
void dump(const std::string& file_name);
/// \brief Load the cache from one file.
/// \todo It should can be loaded from one configured database.
void load(const std::string& file_name);
//@}
protected:
/// \brief the list of message cache for configured classes(message cache
/// is class-specific)
std::map<uint16_t, MessageCache*> messages_cache_;
/// \name rrset caches
//@{
/// \brief the list of rrset cache for configured classes.
/// rrsets_cache1_ is used to cache the configured rrsets in localzone, rrsets
/// in it will never expire.
std::map<uint16_t, RRsetCache*> rrsets_cache1_;
/// \brief cache the rrsets parsed from the received message.
std::map<uint16_t, RRsetCache*> rrsets_cache2_;
//@}
};
} // namespace cache
} // namespace isc
#endif // __RECURSOR_CACHE_H
// Copyright (C) 2010 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.
// $Id$
#include <string>
#include "rrset_cache.h"
#include <nsas/nsas_entry_compare.h>
#include <nsas/hash_table.h>
#include <nsas/hash_deleter.h>
using namespace isc::nsas;
namespace isc {
namespace cache {
RRsetCache::RRsetCache(uint32_t cache_size):
rrset_table_(new NsasEntryCompare<RRsetEntry>, cache_size),
rrset_lru_((3 * cache_size),
new HashDeleter<RRsetEntry>(rrset_table_))
{
}
bool
RRsetCache::lookUp(const isc::dns::Name&,
const isc::dns::RRType&,
const isc::dns::RRClass&,
RRsetEntry& )
{
return true;
}
bool
RRsetCache::update(const isc::dns::RRset&) {
return true;
}
void
RRsetCache::dump(const std::string&) {
}
void
RRsetCache::load(const std::string&) {
}
bool
RRsetCache::resize(uint32_t) {
return true;
}
} // namespace cache
} // namespace isc
// Copyright (C) 2010 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.
// $Id$
#ifndef __RRSET_CACHE_H
#define __RRSET_CACHE_H
#include <rrset_entry.h>
#include <nsas/hash_table.h>
#include <nsas/lru_list.h>
using namespace isc::nsas;
namespace isc {
namespace cache {
class RRsetEntry;
/// \brief RRset Cache
/// The object of RRsetCache represented the cache for class-specific
/// RRsets.
class RRsetCache{
public:
RRsetCache(uint32_t cache_size);
/// \brief Look up rrset in cache.
/// \param msg_entry
/// \return return true if the message can be found in cache, or else,
/// return false.
bool lookUp(const isc::dns::Name& qname,
const isc::dns::RRType& qtype,
const isc::dns::RRClass& qclass,
RRsetEntry& rrset_entry);
/// \brief Update the rrset in the cache with the new one.
/// If the rrset doesn't exist in the cache, it will be added
/// directly. It may be ingored if the new rrset is not more
/// authoritative than the old rrset in cache.
bool update(const isc::dns::RRset& rrset);
/// \brief Dump the rrset cache to specified file.
/// \todo It should can be dumped to one configured database.
void dump(const std::string& file_name);
/// \brief Load the cache from one file.
/// \todo It should can be loaded from one configured database.
void load(const std::string& file_name);
/// \brief Resize the size of rrset cache in runtime.
bool resize(uint32_t size);
private:
uint16_t class_; // The class of the rrset cache.
isc::nsas::HashTable<RRsetEntry> rrset_table_;
isc::nsas::LruList<RRsetEntry> rrset_lru_;
};
} // namespace cache