[svn] commit: r4098 - in /branches/trac449/src/lib/cache: Makefile.am cache_entry_key.h message_cache.cc message_entry.cc message_entry.h rrset_cache.cc rrset_cache.h rrset_entry.cc rrset_entry.h tests/Makefile.am tests/rrset_entry_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Dec 30 10:45:37 UTC 2010
Author: zhanglikun
Date: Thu Dec 30 10:45:37 2010
New Revision: 4098
Log:
Commit the latest change for recursor cache.
Added:
branches/trac449/src/lib/cache/tests/rrset_entry_unittest.cc
Modified:
branches/trac449/src/lib/cache/Makefile.am
branches/trac449/src/lib/cache/cache_entry_key.h
branches/trac449/src/lib/cache/message_cache.cc
branches/trac449/src/lib/cache/message_entry.cc
branches/trac449/src/lib/cache/message_entry.h
branches/trac449/src/lib/cache/rrset_cache.cc
branches/trac449/src/lib/cache/rrset_cache.h
branches/trac449/src/lib/cache/rrset_entry.cc
branches/trac449/src/lib/cache/rrset_entry.h
branches/trac449/src/lib/cache/tests/Makefile.am
Modified: branches/trac449/src/lib/cache/Makefile.am
==============================================================================
--- branches/trac449/src/lib/cache/Makefile.am (original)
+++ branches/trac449/src/lib/cache/Makefile.am Thu Dec 30 10:45:37 2010
@@ -26,6 +26,6 @@
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
-libcache_la_SOURCES += cache_entry_key.h
+libcache_la_SOURCES += cache_entry_key.h cache_entry_key.cc
CLEANFILES = *.gcno *.gcda
Modified: branches/trac449/src/lib/cache/cache_entry_key.h
==============================================================================
--- branches/trac449/src/lib/cache/cache_entry_key.h (original)
+++ branches/trac449/src/lib/cache/cache_entry_key.h Thu Dec 30 10:45:37 2010
@@ -14,30 +14,35 @@
// $Id$
-#ifndef __CACHE_ENTRY_H
-#define __CACHE_ENTRY_H
+#ifndef __CACHE_ENTRY_KEY_H
+#define __CACHE_ENTRY_KEY_H
#include <string>
-
+#include <dns/name.h>
+#include <dns/rrtype.h>
namespace isc {
namespace cache {
-class Name;
-class RRtype;
+typedef std::pair<const char*, const uint32_t> CacheEntryKey;
-std::pair<const char*, const uint32_t>
-genCacheEntryKey(const isc::dns::Name& qname,
- const isc::dns::RRType& qtype)
-{
- std::string keystr = qname.toText();
- //TODO, use uint16_t rcode in case the text is too long?
- keystr += qtype.toText();
- return std::pair<const char*, const uint32_t>(keystr.c_str(), keystr.length());
-}
-
+/// \brief Key Generation Functions
+/// Generate the hash key for message/rrset entries.
+/// The key is name(name of rrset) + type(16bits).
+/// Note. the name is text string, not wire format.
+/// \return a pair(key_name, key_lenght) is returned
+CacheEntryKey
+genCacheEntryKey(const isc::dns::Name& name,
+ const isc::dns::RRType& type);
+
+///
+/// \overload
+///
+CacheEntryKey
+genCacheEntryKey(const std::string& namestr, const uint16_t type);
+
} // namespace cache
} // namespace isc
-#endif // __CACHE_ENTRY_H
+#endif // __CACHE_ENTRY_KEY_H
Modified: branches/trac449/src/lib/cache/message_cache.cc
==============================================================================
--- branches/trac449/src/lib/cache/message_cache.cc (original)
+++ branches/trac449/src/lib/cache/message_cache.cc Thu Dec 30 10:45:37 2010
@@ -43,7 +43,7 @@
const uint16_t query_header,
isc::dns::Message& response)
{
- std::pair<const char*, const uint32_t> keydata = genCacheEntryKey(qname, qtype);
+ CacheEntryKey keydata = genCacheEntryKey(qname, qtype);
//TODO, HashKey need to be refactored, since we don't need query class
// as the parameters.
Modified: branches/trac449/src/lib/cache/message_entry.cc
==============================================================================
--- branches/trac449/src/lib/cache/message_entry.cc (original)
+++ branches/trac449/src/lib/cache/message_entry.cc Thu Dec 30 10:45:37 2010
@@ -18,7 +18,10 @@
#include <nsas/nsas_entry.h>
#include <nsas/fetchable.h>
#include "message_entry.h"
+#include "rrset_entry.h"
+
+using namespace isc::dns;
namespace isc {
namespace cache {
@@ -39,9 +42,26 @@
}
void
-MessageEntry::initMessageEntry(const isc::dns::Message&) {
+MessageEntry::initMessageEntry(const isc::dns::Message& msg) {
+ query_count_ = msg.getRRCount(Message::SECTION_QUESTION);
+ answer_count_ = msg.getRRCount(Message::SECTION_ANSWER);
+ authority_count_ = msg.getRRCount(Message::SECTION_AUTHORITY);
+ additional_count_ = msg.getRRCount(Message::SECTION_ADDITIONAL);
+
+ // query_header \\TODO how to cache the header?
+ RRsetIterator iter;
+ for (iter = msg.beginSection(Message::SECTION_ANSWER);
+ iter != msg.endSection(Message::SECTION_ANSWER);
+ ++iter) {
+ //*rit is one pointer to RRset.
+ //boost::shared_ptr<RRsetEntry> entry_ptr = new RRsetEntry(*(*iter);
+ //rrsets_.append(entry_ptr);
+
+ // Add the rrset entry to rrset_cache or update the existed
+ // rrset entry if the new one is more authoritative.
+ }
+
}
-
} // namespace cache
} // namespace isc
Modified: branches/trac449/src/lib/cache/message_entry.h
==============================================================================
--- branches/trac449/src/lib/cache/message_entry.h (original)
+++ branches/trac449/src/lib/cache/message_entry.h Thu Dec 30 10:45:37 2010
@@ -75,12 +75,14 @@
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.
+ uint16_t additional_count_; // rrset count in addition section.
std::vector<boost::shared_ptr<RRsetEntry*> > rrsets_;
boost::shared_ptr<RRsetCache> rrset_cache_;
};
+typedef boost::shared_ptr<MessageEntry> MessageEntryPtr;
+
} // namespace cache
} // namespace isc
Modified: branches/trac449/src/lib/cache/rrset_cache.cc
==============================================================================
--- branches/trac449/src/lib/cache/rrset_cache.cc (original)
+++ branches/trac449/src/lib/cache/rrset_cache.cc Thu Dec 30 10:45:37 2010
@@ -21,6 +21,7 @@
#include <nsas/hash_deleter.h>
using namespace isc::nsas;
+using namespace isc::dns;
namespace isc {
namespace cache {
@@ -33,18 +34,45 @@
{
}
-bool
-RRsetCache::lookUp(const isc::dns::Name&,
- const isc::dns::RRType&,
- const isc::dns::RRClass&,
- RRsetEntry& )
+RRsetEntryPtr
+RRsetCache::lookup(const isc::dns::Name& qname,
+ const isc::dns::RRType& qtype)
{
- return true;
+ CacheEntryKey keydata = genCacheEntryKey(qname, qtype);
+ //TODO, HashKey need to be refactored, since we don't need query class
+ // as the parameters.
+ return rrset_table_.get(HashKey(
+ keydata.first, keydata.second, RRClass(class_)));
}
-bool
-RRsetCache::update(const isc::dns::RRset&) {
- return true;
+RRsetEntryPtr
+RRsetCache::update(const isc::dns::RRset& rrset, const RRsetTrustLevel& level) {
+ // lookup first
+ RRsetEntryPtr entry_ptr = lookup(rrset.getName(), rrset.getType());
+ if(!entry_ptr) {
+ // rrset entry doesn't exist, create one rrset entry for the rrset
+ // and add it directly.
+ entry_ptr.reset(new RRsetEntry(rrset, level));
+ rrset_table_.add(entry_ptr, entry_ptr->hashKey());
+ //TODO , lru list touch.
+ return entry_ptr;
+ } else {
+ // there is one rrset entry in the cache, need to check whether
+ // the new rrset is more authoritative.
+ if (entry_ptr->getTrustLevel() > level) {
+ // existed rrset entry is more authoritative, do nothing,
+ // just return it.
+ //TODO, lru list touch
+ return entry_ptr;
+ } else {
+ HashKey key = entry_ptr->hashKey();
+ rrset_table_.remove(key);
+ entry_ptr.reset(new RRsetEntry(rrset, level));
+ //TODO, lru list touch.
+ rrset_table_.add(entry_ptr, key);
+ return entry_ptr;
+ }
+ }
}
void
Modified: branches/trac449/src/lib/cache/rrset_cache.h
==============================================================================
--- branches/trac449/src/lib/cache/rrset_cache.h (original)
+++ branches/trac449/src/lib/cache/rrset_cache.h Thu Dec 30 10:45:37 2010
@@ -36,19 +36,23 @@
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);
+ /// \return return the shared_ptr of rrset entry if it can
+ /// found in the cache, or else, return NULL.
+ RRsetEntryPtr lookup(const isc::dns::Name& qname,
+ const isc::dns::RRType& qtype);
- /// \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 Update RRset Cache
+ /// Update the rrset entry in the cache with the new one.
+ /// If the rrset has expired or 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.
+ ///
+ /// \param rrset The new rrset used to update cache.
+ /// \param level trustworthiness of the rrset.
+ /// \return return the rrset entry in the cache, it may be the
+ /// new added rrset entry or existed one if it is not replaced.
+ RRsetEntryPtr update(const isc::dns::RRset& rrset,
+ const RRsetTrustLevel& level);
/// \brief Dump the rrset cache to specified file.
/// \todo It should can be dumped to one configured database.
Modified: branches/trac449/src/lib/cache/rrset_entry.cc
==============================================================================
--- branches/trac449/src/lib/cache/rrset_entry.cc (original)
+++ branches/trac449/src/lib/cache/rrset_entry.cc Thu Dec 30 10:45:37 2010
@@ -19,11 +19,14 @@
#include <nsas/fetchable.h>
#include "rrset_entry.h"
+using namespace isc::dns;
namespace isc {
namespace cache {
-RRsetEntry::RRsetEntry() {
+RRsetEntry::RRsetEntry(const isc::dns::RRset&,
+ const RRsetTrustLevel& level):trust_level_(level)
+{
}
void
@@ -35,6 +38,13 @@
return expire_time_;
}
+HashKey
+RRsetEntry::hashKey() const {
+ CacheEntryKey keydata = genCacheEntryKey(name_, type_);
+ // as the parameters.
+ return HashKey(keydata.first, keydata.second, RRClass(class_));
+}
+
} // namespace cache
} // namespace isc
Modified: branches/trac449/src/lib/cache/rrset_entry.h
==============================================================================
--- branches/trac449/src/lib/cache/rrset_entry.h (original)
+++ branches/trac449/src/lib/cache/rrset_entry.h Thu Dec 30 10:45:37 2010
@@ -20,18 +20,51 @@
#include <dns/message.h>
#include <nsas/nsas_entry.h>
#include <nsas/fetchable.h>
-
+#include "cache_entry_key.h"
using namespace isc::nsas;
namespace isc {
namespace cache {
+/// \brief RRset Trustworthiness
+/// For detail of rrset trustworthiness, please refer to
+/// RFC2181 section5.4.1.
+/// Bigger value is more trustworthy.
+enum RRsetTrustLevel {
+ // Default trust for rrset.
+ RRSET_TRUST_DEFAULT = 0,
+ // Additional information from non-authoritative answer.
+ RRSET_TRUST_ADDITIONAL_NONAA,
+ // Data from the authority section of a non-authoritative answer
+ RRSET_TRUST_AUTHORITY_NONAA,
+ // Additional information from an authoritative answer.
+ RRSET_TRUST_ADDITIONAL_AA,
+ // Non-authoritative data from the answer section of authoritative
+ // answers
+ RRSET_TRUST_NONAUTH_ANSWER_AA,
+ // Data from the answer section of a non-authoritative answer.
+ RRSET_TRUST_ANSWER_NONAA,
+ // Data from the authority section of an authoritative answer.
+ RRSET_TRUST_AUTHORITY_AA,
+ // Authoritative data included in the answer section of
+ // an authoritative reply.
+ RRSET_TRUST_ANSWER_AA,
+ // Data from a primary zone file, other than glue data.
+ RRSET_TRUST_PRIM_ZONE_NONGLUE, ///< RRSET_TRUST_DEFAULT
+};
+
+/// \brief RRset Entry
+/// The object of RRsetEntry represents one cached rrset.
+/// Each rrset entry may be refered using shared_ptr by several message
+/// entries.
class RRsetEntry : public NsasEntry<RRsetEntry>,
public Fetchable
{
public:
- RRsetEntry();
+ /// \param rrset The rrset used to initialize the rrset entry.
+ /// \param level trustworthiness of the rrset.
+ RRsetEntry(const isc::dns::RRset& rrset, const RRsetTrustLevel& level);
/// \brief Generate one rrset according the entry information.
void generateRRset(isc::dns::RRset& rrset) const;
@@ -39,16 +72,30 @@
/// \brief Get the expiration time of the rrset.
time_t getExpirationTime() const;
+ /// \return return hash key
+ virtual HashKey hashKey() const;
+
+ /// \brief get rrset trustworthiness
+ RRsetTrustLevel getTrustLevel() const {
+ return trust_level_;
+ }
+
private:
- time_t expire_time_; // Expiration time of rrset.
- uint32_t ttl_;
- uint16_t class_;
+ std::string name_; // rrset name.
+ uint16_t type_; // rrset type.
+ uint16_t class_; // rrset class.
+
+ uint32_t ttl_; // ttl of rrset
uint32_t rr_count;
uint32_t rrsig_count;
+
+ time_t expire_time_; // Expiration time of rrset.
+ RRsetTrustLevel trust_level_; // rrset trustworthiness.
// sec_status;
- // trust_level; trust or not.
};
+typedef boost::shared_ptr<RRsetEntry> RRsetEntryPtr;
+
} // namespace cache
} // namespace isc
Modified: branches/trac449/src/lib/cache/tests/Makefile.am
==============================================================================
--- branches/trac449/src/lib/cache/tests/Makefile.am (original)
+++ branches/trac449/src/lib/cache/tests/Makefile.am Thu Dec 30 10:45:37 2010
@@ -28,6 +28,7 @@
if HAVE_GTEST
TESTS += run_unittests
run_unittests_SOURCES = run_unittests.cc
+run_unittests_SOURCES += rrset_entry_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
More information about the bind10-changes
mailing list