[svn] commit: r3880 - in /branches/trac226: ./ doc/guide/ src/bin/auth/ src/bin/auth/tests/ src/bin/bind10/ src/lib/datasrc/ src/lib/datasrc/tests/ src/lib/dns/ src/lib/dns/tests/ src/lib/dns/tests/testdata/ src/lib/nsas/ src/lib/nsas/tests/
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Dec 17 18:00:22 UTC 2010
Author: jreed
Date: Fri Dec 17 18:00:22 2010
New Revision: 3880
Log:
catch up to trunk
Added:
branches/trac226/src/lib/datasrc/memory_datasrc.cc
- copied unchanged from r3879, trunk/src/lib/datasrc/memory_datasrc.cc
branches/trac226/src/lib/datasrc/memory_datasrc.h
- copied unchanged from r3879, trunk/src/lib/datasrc/memory_datasrc.h
branches/trac226/src/lib/datasrc/tests/memory_datasrc_unittest.cc
- copied unchanged from r3879, trunk/src/lib/datasrc/tests/memory_datasrc_unittest.cc
branches/trac226/src/lib/dns/masterload.cc
- copied unchanged from r3879, trunk/src/lib/dns/masterload.cc
branches/trac226/src/lib/dns/masterload.h
- copied unchanged from r3879, trunk/src/lib/dns/masterload.h
branches/trac226/src/lib/dns/tests/masterload_unittest.cc
- copied unchanged from r3879, trunk/src/lib/dns/tests/masterload_unittest.cc
branches/trac226/src/lib/dns/tests/testdata/masterload.txt
- copied unchanged from r3879, trunk/src/lib/dns/tests/testdata/masterload.txt
Modified:
branches/trac226/ (props changed)
branches/trac226/ChangeLog
branches/trac226/configure.ac
branches/trac226/doc/guide/bind10-guide.html
branches/trac226/doc/guide/bind10-guide.xml
branches/trac226/src/bin/auth/query.cc
branches/trac226/src/bin/auth/tests/query_unittest.cc
branches/trac226/src/bin/bind10/bind10.py.in (props changed)
branches/trac226/src/lib/datasrc/Makefile.am
branches/trac226/src/lib/datasrc/tests/Makefile.am
branches/trac226/src/lib/datasrc/tests/datasrc_unittest.cc
branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc
branches/trac226/src/lib/datasrc/zonetable.cc
branches/trac226/src/lib/datasrc/zonetable.h
branches/trac226/src/lib/dns/Makefile.am
branches/trac226/src/lib/dns/tests/Makefile.am
branches/trac226/src/lib/dns/tests/testdata/Makefile.am
branches/trac226/src/lib/nsas/Makefile.am
branches/trac226/src/lib/nsas/nameserver_address_store.cc
branches/trac226/src/lib/nsas/nameserver_entry.cc
branches/trac226/src/lib/nsas/random_number_generator.h
branches/trac226/src/lib/nsas/tests/Makefile.am
branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc
branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc
branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc
branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc
branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc
branches/trac226/src/lib/nsas/zone_entry.cc
Modified: branches/trac226/ChangeLog
==============================================================================
--- branches/trac226/ChangeLog (original)
+++ branches/trac226/ChangeLog Fri Dec 17 18:00:22 2010
@@ -1,3 +1,23 @@
+ 130. [func] jerry
+ src/lib/datasrc: Introduced a new class MemoryDataSrc to provide
+ the general interface for memory data source. For the initial
+ implementation, we don't make it a derived class of AbstractDataSrc
+ because the interface is so different(we'll eventually consider this
+ as part of the generalization work).
+ (Trac #422, svn r3866)
+
+ 129. [func] jinmei
+ src/lib/dns: Added new functions masterLoad() for loading master
+ zone files. The initial implementation can only parse a limited
+ form of master files, but BIND 9's named-compilezone can convert
+ any valid zone file into the acceptable form.
+ (Trac #423, svn r3857)
+
+ 128. [build] vorner
+ Test for query name = '.', type = DS to authoritative nameserver
+ for root zone was added.
+ (Trac #85, svn r3836)
+
127. [bug] stephen
During normal operation process termination and resurrection messages
are now output regardless of the state of the verbose flag.
Modified: branches/trac226/configure.ac
==============================================================================
--- branches/trac226/configure.ac (original)
+++ branches/trac226/configure.ac Fri Dec 17 18:00:22 2010
@@ -195,17 +195,49 @@
# specify the default warning flags in CXXFLAGS and let specific modules
# "override" the default.
+# This may be used to try compiler flags.
+AC_DEFUN([BIND10_CXX_TRY_FLAG], [
+ AC_MSG_CHECKING([whether $CXX supports $1])
+
+ bind10_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $1"
+
+ AC_COMPILE_IFELSE([ ], [bind10_cxx_flag=yes], [bind10_cxx_flag=no])
+ CXXFLAGS="$bind10_save_CXXFLAGS"
+
+ if test "x$bind10_cxx_flag" = "xyes"; then
+ ifelse([$2], , :, [$2])
+ else
+ ifelse([$3], , :, [$3])
+ fi
+
+ AC_MSG_RESULT([$bind10_cxx_flag])
+])
+
werror_ok=0
# SunStudio compiler requires special compiler options for boost
# (http://blogs.sun.com/sga/entry/boost_mini_howto)
if test "$SUNCXX" = "yes"; then
CXXFLAGS="$CXXFLAGS -library=stlport4 -features=tmplife -features=tmplrefstatic"
-fi
+MULTITHREADING_FLAG="-mt"
+fi
+
+BIND10_CXX_TRY_FLAG(-Wno-missing-field-initializers,
+ [WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG="-Wno-missing-field-initializers"])
+AC_SUBST(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
# gcc specific settings:
if test "X$GXX" = "Xyes"; then
B10_CXXFLAGS="-Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
+case "$host" in
+*-solaris*)
+ MULTITHREADING_FLAG=-pthreads
+ ;;
+*)
+ MULTITHREADING_FLAG=-pthread
+ ;;
+esac
# Certain versions of gcc (g++) have a bug that incorrectly warns about
# the use of anonymous name spaces even if they're closed in a single
@@ -318,10 +350,45 @@
BOOST_INCLUDES="-I${boost_include_path}"
CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
fi
-AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp],,
+AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync/interprocess_upgradable_mutex.hpp],,
AC_MSG_ERROR([Missing required header files.]))
CPPFLAGS="$CPPFLAGS_SAVES"
AC_SUBST(BOOST_INCLUDES)
+
+# Using boost::mutex can result in requiring libboost_thread with older
+# versions of Boost. We'd like to avoid relying on a compiled Boost library
+# whenever possible, so we need to check for it step by step.
+#
+# NOTE: another fix of this problem is to simply require newer versions of
+# boost. If we choose that solution we should simplify the following tricky
+# checks accordingly and all Makefile.am's that refer to NEED_LIBBOOST_THREAD.
+AC_MSG_CHECKING(for boost::mutex)
+CPPFLAGS_SAVES="$CPPFLAGS"
+LIBS_SAVES="$LIBS"
+CPPFLAGS="$BOOST_INCLUDES $CPPFLAGS $MULTITHREADING_FLAG"
+need_libboost_thread=0
+AC_TRY_LINK([
+#include <boost/thread.hpp>
+],[
+boost::mutex m;
+],
+ [ AC_MSG_RESULT(yes (without libboost_thread)) ],
+ [ LIBS=" $LIBS -lboost_thread"
+ AC_TRY_LINK([
+#include <boost/thread.hpp>
+],[
+boost::mutex m;
+],
+ [ AC_MSG_RESULT(yes (with libboost_thread))
+ need_libboost_thread=1 ],
+ [ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([boost::mutex cannot be linked in this build environment.
+Perhaps you are using an older version of Boost that requires libboost_thread for the mutex support, which does not appear to be available.
+You may want to check the availability of the library or to upgrade Boost.])
+ ])])
+CPPFLAGS="$CPPFLAGS_SAVES"
+LIBS="$LIBS_SAVES"
+AM_CONDITIONAL(NEED_LIBBOOST_THREAD, test $need_libboost_thread = 1)
#
# Check availability of gtest, which will be used for unit tests.
@@ -387,6 +454,8 @@
PTHREAD_LDFLAGS=
AC_CHECK_LIB(pthread, pthread_create,[ PTHREAD_LDFLAGS=-lpthread ], [])
AC_SUBST(PTHREAD_LDFLAGS)
+
+AC_SUBST(MULTITHREADING_FLAG)
#
# ASIO: we extensively use it as the C++ event management module.
Modified: branches/trac226/doc/guide/bind10-guide.html
==============================================================================
--- branches/trac226/doc/guide/bind10-guide.html (original)
+++ branches/trac226/doc/guide/bind10-guide.html Fri Dec 17 18:00:22 2010
@@ -128,7 +128,7 @@
libraries, to build BIND 10 from source code.
</p></div><p>
Building from source code requires the Boost
- build-time headers. At least Boost version 1.34 is required.
+ build-time headers. At least Boost version 1.35 is required.
</p><p>
Modified: branches/trac226/doc/guide/bind10-guide.xml
==============================================================================
--- branches/trac226/doc/guide/bind10-guide.xml (original)
+++ branches/trac226/doc/guide/bind10-guide.xml Fri Dec 17 18:00:22 2010
@@ -274,7 +274,7 @@
<para>
Building from source code requires the Boost
- build-time headers. At least Boost version 1.34 is required.
+ build-time headers. At least Boost version 1.35 is required.
<!-- TODO: we don't check for this version -->
<!-- NOTE: jreed has tested with 1.34, 1.38, and 1.41. -->
</para>
Modified: branches/trac226/src/bin/auth/query.cc
==============================================================================
--- branches/trac226/src/bin/auth/query.cc (original)
+++ branches/trac226/src/bin/auth/query.cc Fri Dec 17 18:00:22 2010
@@ -26,10 +26,10 @@
namespace auth {
void
Query::process() const {
- const ZoneTable::FindResult result = zone_table_.find(qname_);
+ const ZoneTable::FindResult result = zone_table_.findZone(qname_);
- if (result.code != ZoneTable::SUCCESS &&
- result.code != ZoneTable::PARTIALMATCH) {
+ if (result.code != isc::datasrc::result::SUCCESS &&
+ result.code != isc::datasrc::result::PARTIALMATCH) {
response_.setRcode(Rcode::SERVFAIL());
return;
}
Modified: branches/trac226/src/bin/auth/tests/query_unittest.cc
==============================================================================
--- branches/trac226/src/bin/auth/tests/query_unittest.cc (original)
+++ branches/trac226/src/bin/auth/tests/query_unittest.cc Fri Dec 17 18:00:22 2010
@@ -55,7 +55,7 @@
TEST_F(QueryTest, matchZone) {
// add a matching zone. since the zone is empty right now, the response
// should have NXDOMAIN.
- zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.com"))));
+ zone_table.addZone(ZonePtr(new MemoryZone(qclass, Name("example.com"))));
query.process();
EXPECT_EQ(Rcode::NXDOMAIN(), response.getRcode());
}
@@ -63,7 +63,7 @@
TEST_F(QueryTest, noMatchZone) {
// there's a zone in the table but it doesn't match the qname. should
// result in SERVFAIL.
- zone_table.add(ZonePtr(new MemoryZone(qclass, Name("example.org"))));
+ zone_table.addZone(ZonePtr(new MemoryZone(qclass, Name("example.org"))));
query.process();
EXPECT_EQ(Rcode::SERVFAIL(), response.getRcode());
}
Modified: branches/trac226/src/lib/datasrc/Makefile.am
==============================================================================
--- branches/trac226/src/lib/datasrc/Makefile.am (original)
+++ branches/trac226/src/lib/datasrc/Makefile.am Fri Dec 17 18:00:22 2010
@@ -16,3 +16,4 @@
libdatasrc_la_SOURCES += query.h query.cc
libdatasrc_la_SOURCES += cache.h cache.cc
libdatasrc_la_SOURCES += zonetable.h zonetable.cc
+libdatasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
Modified: branches/trac226/src/lib/datasrc/tests/Makefile.am
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/Makefile.am (original)
+++ branches/trac226/src/lib/datasrc/tests/Makefile.am Fri Dec 17 18:00:22 2010
@@ -25,11 +25,12 @@
run_unittests_SOURCES += cache_unittest.cc
run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
run_unittests_SOURCES += zonetable_unittest.cc
+run_unittests_SOURCES += memory_datasrc_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
-run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
+run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
Modified: branches/trac226/src/lib/datasrc/tests/datasrc_unittest.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/datasrc_unittest.cc (original)
+++ branches/trac226/src/lib/datasrc/tests/datasrc_unittest.cc Fri Dec 17 18:00:22 2010
@@ -877,10 +877,30 @@
EXPECT_TRUE(it->isLast());
}
-TEST_F(DataSrcTest, RootDSQuery) {
+// Test sending a DS query to root (nonsense, but it should survive)
+TEST_F(DataSrcTest, RootDSQuery1) {
EXPECT_NO_THROW(createAndProcessQuery(Name("."), RRClass::IN(),
RRType::DS()));
headerCheck(msg, Rcode::REFUSED(), true, false, true, 0, 0, 0);
+}
+
+// The same, but when we have the root zone
+// (which triggers rfc4035 section 3.1.4.1)
+TEST_F(DataSrcTest, RootDSQuery2) {
+ // The message
+ msg.makeResponse();
+ msg.setOpcode(Opcode::QUERY());
+ msg.addQuestion(Question(Name("."), RRClass::IN(), RRType::DS()));
+ msg.setHeaderFlag(Message::HEADERFLAG_RD);
+ // Prepare the source
+ DataSrcPtr sql3_source = DataSrcPtr(new Sqlite3DataSrc);
+ ConstElementPtr sqlite_root = Element::fromJSON(
+ "{ \"database_file\": \"" TEST_DATA_DIR "/test-root.sqlite3\"}");
+ EXPECT_NO_THROW(sql3_source->init(sqlite_root));
+ // Make the query
+ EXPECT_NO_THROW(performQuery(*sql3_source, cache, msg));
+
+ headerCheck(msg, Rcode::NOERROR(), true, true, true, 0, 1, 0);
}
TEST_F(DataSrcTest, DSQueryFromCache) {
Modified: branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc (original)
+++ branches/trac226/src/lib/datasrc/tests/zonetable_unittest.cc Fri Dec 17 18:00:22 2010
@@ -53,61 +53,61 @@
ZonePtr zone1, zone2, zone3;
};
-TEST_F(ZoneTableTest, add) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(zone1));
+TEST_F(ZoneTableTest, addZone) {
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::EXIST, zone_table.addZone(zone1));
// names are compared in a case insensitive manner.
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(
+ EXPECT_EQ(result::EXIST, zone_table.addZone(
ZonePtr(new MemoryZone(RRClass::IN(), Name("EXAMPLE.COM")))));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone3));
// Zone table is indexed only by name. Duplicate origin name with
// different zone class isn't allowed.
- EXPECT_EQ(ZoneTable::EXIST, zone_table.add(
+ EXPECT_EQ(result::EXIST, zone_table.addZone(
ZonePtr(new MemoryZone(RRClass::CH(),
Name("example.com")))));
/// Bogus zone (NULL)
- EXPECT_THROW(zone_table.add(ZonePtr()), isc::InvalidParameter);
+ EXPECT_THROW(zone_table.addZone(ZonePtr()), isc::InvalidParameter);
}
-TEST_F(ZoneTableTest, remove) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+TEST_F(ZoneTableTest, removeZone) {
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone3));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.remove(Name("example.net")));
- EXPECT_EQ(ZoneTable::NOTFOUND, zone_table.remove(Name("example.net")));
+ EXPECT_EQ(result::SUCCESS, zone_table.removeZone(Name("example.net")));
+ EXPECT_EQ(result::NOTFOUND, zone_table.removeZone(Name("example.net")));
}
-TEST_F(ZoneTableTest, find) {
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone1));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone2));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone3));
+TEST_F(ZoneTableTest, findZone) {
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone1));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone2));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone3));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.find(Name("example.com")).code);
+ EXPECT_EQ(result::SUCCESS, zone_table.findZone(Name("example.com")).code);
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("example.com")).zone->getOrigin());
+ zone_table.findZone(Name("example.com")).zone->getOrigin());
- EXPECT_EQ(ZoneTable::NOTFOUND,
- zone_table.find(Name("example.org")).code);
- EXPECT_EQ(static_cast<const Zone*>(NULL),
- zone_table.find(Name("example.org")).zone);
+ EXPECT_EQ(result::NOTFOUND,
+ zone_table.findZone(Name("example.org")).code);
+ EXPECT_EQ(ConstZonePtr(),
+ zone_table.findZone(Name("example.org")).zone);
// there's no exact match. the result should be the longest match,
// and the code should be PARTIALMATCH.
- EXPECT_EQ(ZoneTable::PARTIALMATCH,
- zone_table.find(Name("www.example.com")).code);
+ EXPECT_EQ(result::PARTIALMATCH,
+ zone_table.findZone(Name("www.example.com")).code);
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("www.example.com")).zone->getOrigin());
+ zone_table.findZone(Name("www.example.com")).zone->getOrigin());
// make sure the partial match is indeed the longest match by adding
// a zone with a shorter origin and query again.
ZonePtr zone_com(new MemoryZone(RRClass::IN(), Name("com")));
- EXPECT_EQ(ZoneTable::SUCCESS, zone_table.add(zone_com));
+ EXPECT_EQ(result::SUCCESS, zone_table.addZone(zone_com));
EXPECT_EQ(Name("example.com"),
- zone_table.find(Name("www.example.com")).zone->getOrigin());
+ zone_table.findZone(Name("www.example.com")).zone->getOrigin());
}
}
Modified: branches/trac226/src/lib/datasrc/zonetable.cc
==============================================================================
--- branches/trac226/src/lib/datasrc/zonetable.cc (original)
+++ branches/trac226/src/lib/datasrc/zonetable.cc Fri Dec 17 18:00:22 2010
@@ -77,29 +77,30 @@
delete impl_;
}
-ZoneTable::Result
-ZoneTable::add(ZonePtr zone) {
+result::Result
+ZoneTable::addZone(ZonePtr zone) {
if (!zone) {
isc_throw(InvalidParameter,
- "Null pointer is passed to ZoneTable::add()");
+ "Null pointer is passed to ZoneTable::addZone()");
}
if (impl_->zones.insert(
ZoneTableImpl::NameAndZone(zone->getOrigin(), zone)).second
== true) {
- return (SUCCESS);
+ return (result::SUCCESS);
} else {
- return (EXIST);
+ return (result::EXIST);
}
}
-ZoneTable::Result
-ZoneTable::remove(const Name& origin) {
- return (impl_->zones.erase(origin) == 1 ? SUCCESS : NOTFOUND);
+result::Result
+ZoneTable::removeZone(const Name& origin) {
+ return (impl_->zones.erase(origin) == 1 ? result::SUCCESS :
+ result::NOTFOUND);
}
ZoneTable::FindResult
-ZoneTable::find(const Name& name) const {
+ZoneTable::findZone(const Name& name) const {
// Inefficient internal loop to find a longest match.
// This will be replaced with a single call to more intelligent backend.
for (int i = 0; i < name.getLabelCount(); ++i) {
@@ -107,11 +108,11 @@
ZoneTableImpl::ZoneMap::const_iterator found =
impl_->zones.find(matchname);
if (found != impl_->zones.end()) {
- return (FindResult(i == 0 ? SUCCESS : PARTIALMATCH,
- (*found).second.get()));
+ return (FindResult(i == 0 ? result::SUCCESS :
+ result::PARTIALMATCH, (*found).second));
}
}
- return (FindResult(NOTFOUND, NULL));
+ return (FindResult(result::NOTFOUND, ConstZonePtr()));
}
} // end of namespace datasrc
} // end of namespace isc
Modified: branches/trac226/src/lib/datasrc/zonetable.h
==============================================================================
--- branches/trac226/src/lib/datasrc/zonetable.h (original)
+++ branches/trac226/src/lib/datasrc/zonetable.h Fri Dec 17 18:00:22 2010
@@ -26,6 +26,21 @@
};
namespace datasrc {
+namespace result {
+/// Result codes of various public methods of in memory data source
+///
+/// The detailed semantics may differ in different methods.
+/// See the description of specific methods for more details.
+///
+/// Note: this is intended to be used from other data sources eventually,
+/// but for now it's specific to in memory data source and its backend.
+enum Result {
+ SUCCESS, ///< The operation is successful.
+ EXIST, ///< The search key is already stored.
+ NOTFOUND, ///< The specified object is not found.
+ PARTIALMATCH ///< \c Only a partial match is found.
+};
+}
/// \brief The base class for a single authoritative zone
///
@@ -223,81 +238,22 @@
/// \brief A set of authoritative zones.
///
-/// The \c ZoneTable class represents a set of zones of the same RR class
-/// and provides a basic interface to help DNS lookup processing.
-/// For a given domain name, its \c find() method searches the set for a zone
-/// that gives a longest match against that name.
-///
-/// The set of zones are assumed to be of the same RR class, but the
-/// \c ZoneTable class does not enforce the assumption through its interface.
-/// For example, the \c add() method does not check if the new zone
-/// is of the same RR class as that of the others already in the table.
-/// It is caller's responsibility to ensure this assumption.
-///
-/// <b>Notes to developer:</b>
-///
-/// The add() method takes a (Boost) shared pointer because it would be
-/// inconvenient to require the caller to maintain the ownership of zones,
-/// while it wouldn't be safe to delete unnecessary zones inside the zone
-/// table.
-///
-/// On the other hand, the find() method returns a bare pointer, rather than
-/// the shared pointer, in order to minimize the dependency on Boost
-/// definitions in our public interfaces. This means the caller can only
-/// refer to the returned object (via the pointer) for a short period.
-/// It should be okay for simple lookup purposes, but if we see the need
-/// for keeping a \c Zone object for a longer period of context, we may
-/// have to revisit this decision.
-///
-/// Currently, \c FindResult::zone is immutable for safety.
-/// In future versions we may want to make it changeable. For example,
-/// we may want to allow configuration update on an existing zone.
-///
-/// In BIND 9's "zt" module, the equivalent of \c find() has an "option"
-/// parameter. The only defined option is the one to specify the "no exact"
-/// mode, and the only purpose of that mode is to prefer a second longest match
-/// even if there is an exact match in order to deal with type DS query.
-/// This trick may help enhance performance, but it also seems to make the
-/// implementation complicated for a very limited, minor case. So, for now,
-/// we don't introduce the special mode, and, since it was the only reason to
-/// have search options in BIND 9, our initial implementation doesn't provide
-/// a switch for options.
+/// \c ZoneTable class is primarily intended to be used as a backend for the
+/// \c MemoryDataSrc class, but is exposed as a separate class in case some
+/// application wants to use it directly (e.g. for a customized data source
+/// implementation).
+///
+/// For more descriptions about its struct and interfaces, please refer to the
+/// corresponding struct and interfaces of \c MemoryDataSrc.
class ZoneTable {
public:
- /// Result codes of various public methods of \c ZoneTable.
- ///
- /// The detailed semantics may differ in different methods.
- /// See the description of specific methods for more details.
- enum Result {
- SUCCESS, ///< The operation is successful.
- EXIST, ///< A zone is already stored in \c ZoneTable.
- NOTFOUND, ///< The specified zone is not found in \c ZoneTable.
- PARTIALMATCH ///< \c Only a partial match is found in \c find().
- };
-
- /// \brief A helper structure to represent the search result of
- /// <code>ZoneTable::find()</code>.
- ///
- /// This is a straightforward pair of the result code and a pointer
- /// to the found zone to represent the result of \c find().
- /// We use this in order to avoid overloading the return value for both
- /// the result code ("success" or "not found") and the found object,
- /// i.e., avoid using \c NULL to mean "not found", etc.
- ///
- /// This is a simple value class with no internal state, so for
- /// convenience we allow the applications to refer to the members
- /// directly.
- ///
- /// See the description of \c find() for the semantics of the member
- /// variables.
struct FindResult {
- FindResult(Result param_code, const Zone* param_zone) :
+ FindResult(result::Result param_code, const ConstZonePtr param_zone) :
code(param_code), zone(param_zone)
{}
- const Result code;
- const Zone* const zone;
+ const result::Result code;
+ const ConstZonePtr zone;
};
-
///
/// \name Constructors and Destructor.
///
@@ -322,53 +278,25 @@
//@}
/// Add a \c Zone to the \c ZoneTable.
- ///
- /// \c zone must not be associated with a NULL pointer; otherwise
- /// an exception of class \c InvalidParameter will be thrown.
- /// If internal resource allocation fails, a corresponding standard
- /// exception will be thrown.
- /// This method never throws an exception otherwise.
- ///
- /// \param zone A \c Zone object to be added.
- /// \return \c SUCCESS If the zone is successfully added to the zone table.
- /// \return \c EXIST The zone table already stores a zone that has the
- /// same origin.
- Result add(ZonePtr zone);
+ /// See the description of <code>MemoryDataSrc::addZone()</code> for more
+ /// details.
+ result::Result addZone(ZonePtr zone);
/// Remove a \c Zone of the given origin name from the \c ZoneTable.
///
/// This method never throws an exception.
///
/// \param origin The origin name of the zone to be removed.
- /// \return \c SUCCESS If the zone is successfully removed from the
- /// zone table.
- /// \return \c NOTFOUND The zone table does not store the zone that matches
- /// \c origin.
- Result remove(const isc::dns::Name& origin);
+ /// \return \c result::SUCCESS If the zone is successfully
+ /// removed from the zone table.
+ /// \return \c result::NOTFOUND The zone table does not
+ /// store the zone that matches \c origin.
+ result::Result removeZone(const isc::dns::Name& origin);
/// Find a \c Zone that best matches the given name in the \c ZoneTable.
- ///
- /// It searches the internal storage for a \c Zone that gives the
- /// longest match against \c name, and returns the result in the
- /// form of a \c FindResult object as follows:
- /// - \c code: The result code of the operation.
- /// - \c SUCCESS: A zone that gives an exact match is found
- /// - \c PARTIALMATCH: A zone whose origin is a super domain of
- /// \c name is found (but there is no exact match)
- /// - \c NOTFOUND: For all other cases.
- /// - \c zone: A pointer to the found \c Zone object if one is found;
- /// otherwise \c NULL.
- ///
- /// The pointer returned in the \c FindResult object is only valid until
- /// the corresponding zone is removed from the zone table.
- /// The caller must ensure that the zone is held in the zone table while
- /// it needs to refer to it.
- ///
- /// This method never throws an exception.
- ///
- /// \param name A domain name for which the search is performed.
- /// \return A \c FindResult object enclosing the search result (see above).
- FindResult find(const isc::dns::Name& name) const;
+ /// See the description of <code>MemoryDataSrc::findZone()</code> for more
+ /// details.
+ FindResult findZone(const isc::dns::Name& name) const;
private:
struct ZoneTableImpl;
Modified: branches/trac226/src/lib/dns/Makefile.am
==============================================================================
--- branches/trac226/src/lib/dns/Makefile.am (original)
+++ branches/trac226/src/lib/dns/Makefile.am Fri Dec 17 18:00:22 2010
@@ -69,6 +69,7 @@
libdns___la_SOURCES += edns.h edns.cc
libdns___la_SOURCES += exceptions.h exceptions.cc
libdns___la_SOURCES += util/hex.h
+libdns___la_SOURCES += masterload.h masterload.cc
libdns___la_SOURCES += message.h message.cc
libdns___la_SOURCES += messagerenderer.h messagerenderer.cc
libdns___la_SOURCES += name.h name.cc
Modified: branches/trac226/src/lib/dns/tests/Makefile.am
==============================================================================
--- branches/trac226/src/lib/dns/tests/Makefile.am (original)
+++ branches/trac226/src/lib/dns/tests/Makefile.am Fri Dec 17 18:00:22 2010
@@ -42,6 +42,7 @@
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
run_unittests_SOURCES += rrparamregistry_unittest.cc
+run_unittests_SOURCES += masterload_unittest.cc
run_unittests_SOURCES += message_unittest.cc
run_unittests_SOURCES += base32hex_unittest.cc
run_unittests_SOURCES += base64_unittest.cc
Modified: branches/trac226/src/lib/dns/tests/testdata/Makefile.am
==============================================================================
--- branches/trac226/src/lib/dns/tests/testdata/Makefile.am (original)
+++ branches/trac226/src/lib/dns/tests/testdata/Makefile.am Fri Dec 17 18:00:22 2010
@@ -26,6 +26,7 @@
EXTRA_DIST = gen-wiredata.py.in
EXTRA_DIST += edns_toWire1.spec edns_toWire2.spec
EXTRA_DIST += edns_toWire3.spec edns_toWire4.spec
+EXTRA_DIST += masterload.txt
EXTRA_DIST += message_fromWire1 message_fromWire2
EXTRA_DIST += message_fromWire3 message_fromWire4
EXTRA_DIST += message_fromWire5 message_fromWire6
Modified: branches/trac226/src/lib/nsas/Makefile.am
==============================================================================
--- branches/trac226/src/lib/nsas/Makefile.am (original)
+++ branches/trac226/src/lib/nsas/Makefile.am Fri Dec 17 18:00:22 2010
@@ -1,10 +1,23 @@
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 += $(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 = libnsas.la
libnsas_la_SOURCES = address_entry.h address_entry.cc
Modified: branches/trac226/src/lib/nsas/nameserver_address_store.cc
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_address_store.cc (original)
+++ branches/trac226/src/lib/nsas/nameserver_address_store.cc Fri Dec 17 18:00:22 2010
@@ -17,6 +17,7 @@
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
+#include <boost/bind.hpp>
#include <config.h>
#include <dns/rdataclass.h>
@@ -32,7 +33,6 @@
using namespace isc::dns;
using namespace std;
-using namespace boost;
namespace isc {
namespace nsas {
@@ -43,7 +43,7 @@
// hash table, on the assumption that three elements is the longest linear
// search we want to do when looking up names in the hash table.
NameserverAddressStore::NameserverAddressStore(
- shared_ptr<ResolverInterface> resolver, uint32_t zonehashsize,
+ boost::shared_ptr<ResolverInterface> resolver, uint32_t zonehashsize,
uint32_t nshashsize) :
zone_hash_(new HashTable<ZoneEntry>(new NsasEntryCompare<ZoneEntry>,
zonehashsize)),
@@ -64,13 +64,13 @@
* no need to copy anything. In that case, the bind should not be
* called at all to create the object, just call the function.
*/
-shared_ptr<ZoneEntry>
-newZone(const shared_ptr<ResolverInterface>* resolver, const string* zone,
+boost::shared_ptr<ZoneEntry>
+newZone(const boost::shared_ptr<ResolverInterface>* resolver, const string* zone,
const RRClass* class_code,
- const shared_ptr<HashTable<NameserverEntry> >* ns_hash,
- const shared_ptr<LruList<NameserverEntry> >* ns_lru)
+ const boost::shared_ptr<HashTable<NameserverEntry> >* ns_hash,
+ const boost::shared_ptr<LruList<NameserverEntry> >* ns_lru)
{
- shared_ptr<ZoneEntry> result(new ZoneEntry(*resolver, *zone, *class_code,
+ boost::shared_ptr<ZoneEntry> result(new ZoneEntry(*resolver, *zone, *class_code,
*ns_hash, *ns_lru));
return (result);
}
@@ -79,9 +79,9 @@
void
NameserverAddressStore::lookup(const string& zone, const RRClass& class_code,
- shared_ptr<AddressRequestCallback> callback, AddressFamily family)
+ boost::shared_ptr<AddressRequestCallback> callback, AddressFamily family)
{
- pair<bool, shared_ptr<ZoneEntry> > zone_obj(zone_hash_->getOrAdd(HashKey(
+ pair<bool, boost::shared_ptr<ZoneEntry> > zone_obj(zone_hash_->getOrAdd(HashKey(
zone, class_code), boost::bind(newZone, &resolver_, &zone, &class_code,
&nameserver_hash_, &nameserver_lru_)));
if (zone_obj.first) {
Modified: branches/trac226/src/lib/nsas/nameserver_entry.cc
==============================================================================
--- branches/trac226/src/lib/nsas/nameserver_entry.cc (original)
+++ branches/trac226/src/lib/nsas/nameserver_entry.cc Fri Dec 17 18:00:22 2010
@@ -41,7 +41,6 @@
using namespace isc::nsas;
using namespace isc::dns;
using namespace std;
-using namespace boost;
namespace isc {
namespace nsas {
@@ -49,7 +48,7 @@
namespace {
// Just shorter type alias
-typedef recursive_mutex::scoped_lock Lock;
+typedef boost::recursive_mutex::scoped_lock Lock;
}
@@ -100,7 +99,7 @@
return (getState());
}
- shared_ptr<NameserverEntry> self(shared_from_this());
+ boost::shared_ptr<NameserverEntry> self(shared_from_this());
// If any address is OK, just pass everything we have
if (family == ANY_OK) {
BOOST_FOREACH(const AddressEntry& entry, addresses_[V6_ONLY]) {
@@ -202,7 +201,7 @@
*/
class NameserverEntry::ResolverCallback : public ResolverInterface::Callback {
public:
- ResolverCallback(shared_ptr<NameserverEntry> entry,
+ ResolverCallback(boost::shared_ptr<NameserverEntry> entry,
AddressFamily family, const RRType& type) :
entry_(entry),
family_(family),
@@ -214,7 +213,7 @@
* This extracts the addresses out from the response and puts them
* inside the entry. It tries to reuse the address entries from before (if there were any), to keep their RTTs.
*/
- virtual void success(const shared_ptr<AbstractRRset>& response) {
+ virtual void success(const boost::shared_ptr<AbstractRRset>& response) {
time_t now = time(NULL);
Lock lock(entry_->mutex_);
@@ -295,7 +294,7 @@
failureInternal(lock);
}
private:
- shared_ptr<NameserverEntry> entry_;
+ boost::shared_ptr<NameserverEntry> entry_;
AddressFamily family_;
RRType type_;
@@ -309,7 +308,7 @@
!entry_->expect_address_[ANY_OK];
// Sort out the callbacks we want
vector<CallbackPair> keep;
- vector<shared_ptr<NameserverEntry::Callback> > dispatch;
+ vector<boost::shared_ptr<NameserverEntry::Callback> > dispatch;
BOOST_FOREACH(const CallbackPair &callback, entry_->callbacks_)
{
if (callback.first == family_ || (dispatch_any &&
@@ -331,7 +330,7 @@
* FIXME: This is not completely exception safe. If there's an
* exception in a callback, we lose the rest of them.
*/
- BOOST_FOREACH(const shared_ptr<NameserverEntry::Callback>&
+ BOOST_FOREACH(const boost::shared_ptr<NameserverEntry::Callback>&
callback, dispatch)
{
(*callback)(entry_);
@@ -364,19 +363,19 @@
};
void
-NameserverEntry::askIP(shared_ptr<ResolverInterface> resolver,
+NameserverEntry::askIP(boost::shared_ptr<ResolverInterface> resolver,
const RRType& type, AddressFamily family)
{
QuestionPtr question(new Question(Name(getName()), RRClass(getClass()),
type));
- shared_ptr<ResolverCallback> callback(new ResolverCallback(
+ boost::shared_ptr<ResolverCallback> callback(new ResolverCallback(
shared_from_this(), family, type));
resolver->resolve(question, callback);
}
void
-NameserverEntry::askIP(shared_ptr<ResolverInterface> resolver,
- shared_ptr<Callback> callback, AddressFamily family)
+NameserverEntry::askIP(boost::shared_ptr<ResolverInterface> resolver,
+ boost::shared_ptr<Callback> callback, AddressFamily family)
{
Lock lock(mutex_);
Modified: branches/trac226/src/lib/nsas/random_number_generator.h
==============================================================================
--- branches/trac226/src/lib/nsas/random_number_generator.h (original)
+++ branches/trac226/src/lib/nsas/random_number_generator.h Fri Dec 17 18:00:22 2010
@@ -139,17 +139,20 @@
double epsilon = 0.0001;
// The sum must be equal to 1
- return fabs(sum - 1.0) < epsilon;
+ return std::fabs(sum - 1.0) < epsilon;
}
-
- // Shortcut typedefs
- typedef boost::variate_generator<boost::mt19937&, boost::uniform_real<> > UniformRealGenerator;
std::vector<double> cumulative_; ///< The partial sum of the probabilities
boost::mt19937 rng_; ///< Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator
boost::uniform_real<> dist_; ///< Uniformly distributed real numbers
+
+ // Shortcut typedef
+ // This typedef is placed directly before its use, as the sunstudio
+ // compiler could not handle it being anywhere else (don't know why)
+ typedef boost::variate_generator<boost::mt19937&, boost::uniform_real<> > UniformRealGenerator;
UniformRealGenerator uniform_real_gen_; ///< Uniformly distributed random real numbers generator
- size_t min_; ///< The minimum integer that will be generated
+
+ size_t min_; ///< The minimum integer that will be generated
};
} // namespace dns
Modified: branches/trac226/src/lib/nsas/tests/Makefile.am
==============================================================================
--- branches/trac226/src/lib/nsas/tests/Makefile.am (original)
+++ branches/trac226/src/lib/nsas/tests/Makefile.am Fri Dec 17 18:00:22 2010
@@ -1,15 +1,26 @@
SUBDIRS = .
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/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_CXXFLAGS = $(B10_CXXFLAGS)
-AM_LDFLAGS =
+AM_LDFLAGS = $(PTHREAD_LDFLAGS)
if USE_STATIC_LINK
AM_LDFLAGS += -static
endif
-AM_LDFLAGS += -lboost_thread
+
+# 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
+# see ../Makefile.am
+AM_CXXFLAGS += -Wno-unused-parameter
+endif
CLEANFILES = *.gcno *.gcda
@@ -36,6 +47,11 @@
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
+# NOTE: we may have to clean up this hack later (see the note in configure.ac)
+if NEED_LIBBOOST_THREAD
+run_unittests_LDADD += -lboost_thread
+endif
+
run_unittests_LDADD += $(top_builddir)/src/lib/nsas/libnsas.la
run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
Modified: branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_address_store_unittest.cc Fri Dec 17 18:00:22 2010
@@ -41,7 +41,6 @@
using namespace isc::dns;
using namespace std;
-using namespace boost;
namespace isc {
namespace nsas {
@@ -57,7 +56,7 @@
///
/// \param hashsize Size of the zone hash table
/// \param lrusize Size of the zone hash table
- DerivedNsas(shared_ptr<TestResolver> resolver, uint32_t hashsize,
+ DerivedNsas(boost::shared_ptr<TestResolver> resolver, uint32_t hashsize,
uint32_t lrusize) :
NameserverAddressStore(resolver, hashsize, lrusize),
resolver_(resolver)
@@ -87,8 +86,8 @@
* if it is asked for by the resolver.
*/
void lookupAndAnswer(const string& name, const RRClass& class_code,
- shared_ptr<AbstractRRset> authority,
- shared_ptr<AddressRequestCallback> callback)
+ boost::shared_ptr<AbstractRRset> authority,
+ boost::shared_ptr<AddressRequestCallback> callback)
{
size_t size(resolver_->requests.size());
NameserverAddressStore::lookup(name, class_code, callback, ANY_OK);
@@ -102,7 +101,7 @@
}
}
private:
- shared_ptr<TestResolver> resolver_;
+ boost::shared_ptr<TestResolver> resolver_;
};
@@ -133,8 +132,8 @@
std::string name = "zone" + boost::lexical_cast<std::string>(i);
zones_.push_back(boost::shared_ptr<ZoneEntry>(new ZoneEntry(
resolver_, name, RRClass(40 + i),
- shared_ptr<HashTable<NameserverEntry> >(),
- shared_ptr<LruList<NameserverEntry> >())));
+ boost::shared_ptr<HashTable<NameserverEntry> >(),
+ boost::shared_ptr<LruList<NameserverEntry> >())));
}
// A nameserver serving data
@@ -151,7 +150,7 @@
RRsetPtr authority_, empty_authority_;
- shared_ptr<TestResolver> resolver_;
+ boost::shared_ptr<TestResolver> resolver_;
class NSASCallback : public AddressRequestCallback {
public:
Modified: branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_address_unittest.cc Fri Dec 17 18:00:22 2010
@@ -31,7 +31,6 @@
using namespace dns;
using namespace rdata;
-using namespace boost;
#define TEST_ADDRESS_INDEX 1
@@ -48,8 +47,8 @@
rrv4_->addRdata(ConstRdataPtr(new RdataTest<A>("9.10.11.12")));
ns_.reset(new NameserverEntry(name_.toText(), RRClass::IN()));
- shared_ptr<TestResolver> resolver(new TestResolver);
- ns_->askIP(resolver, shared_ptr<Callback>(new Callback), ANY_OK);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
+ ns_->askIP(resolver, boost::shared_ptr<Callback>(new Callback), ANY_OK);
resolver->asksIPs(name_, 0, 1);
resolver->requests[0].second->success(rrv4_);
}
@@ -74,12 +73,12 @@
private:
Name name_; ///< Name of the sample
- shared_ptr<BasicRRset> rrv4_; ///< Standard RRSet - IN, A, lowercase name
+ boost::shared_ptr<BasicRRset> rrv4_; ///< Standard RRSet - IN, A, lowercase name
boost::shared_ptr<NameserverEntry> ns_; ///< Shared_ptr that points to a NameserverEntry object
class Callback : public NameserverEntry::Callback {
public:
- virtual void operator()(shared_ptr<NameserverEntry>) { }
+ virtual void operator()(boost::shared_ptr<NameserverEntry>) { }
};
};
Modified: branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/nameserver_entry_unittest.cc Fri Dec 17 18:00:22 2010
@@ -43,7 +43,6 @@
using namespace std;
using namespace isc::dns;
using namespace rdata;
-using namespace boost;
namespace {
@@ -53,7 +52,7 @@
/// \short Just a really stupid callback counting times called
struct Callback : public NameserverEntry::Callback {
size_t count;
- virtual void operator()(shared_ptr<NameserverEntry>) {
+ virtual void operator()(boost::shared_ptr<NameserverEntry>) {
count ++;
}
Callback() : count(0) { }
@@ -69,8 +68,8 @@
* \param set The answer. If the pointer is empty, it is taken
* as a failure.
*/
- void fillSet(shared_ptr<TestResolver> resolver, size_t index,
- shared_ptr<BasicRRset> set)
+ void fillSet(boost::shared_ptr<TestResolver> resolver, size_t index,
+ boost::shared_ptr<BasicRRset> set)
{
if (set) {
resolver->requests[index].second->success(set);
@@ -80,12 +79,12 @@
}
protected:
/// Fills the nameserver entry with data trough ask IP
- void fillNSEntry(shared_ptr<NameserverEntry> entry,
- shared_ptr<BasicRRset> rrv4, shared_ptr<BasicRRset> rrv6)
+ void fillNSEntry(boost::shared_ptr<NameserverEntry> entry,
+ boost::shared_ptr<BasicRRset> rrv4, boost::shared_ptr<BasicRRset> rrv6)
{
// Prepare data to run askIP
- shared_ptr<TestResolver> resolver(new TestResolver);
- shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<Callback> callback(new Callback);
// Let it ask for data
entry->askIP(resolver, callback, ANY_OK);
// Check it really asked and sort the queries
@@ -114,7 +113,7 @@
TEST_F(NameserverEntryTest, InitialRTT) {
// Get the RTT for the different addresses
- shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
+ boost::shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(alpha, rrv4_, rrv6_);
NameserverEntry::AddressVector vec;
@@ -133,7 +132,7 @@
TEST_F(NameserverEntryTest, SetRTT) {
// Get the RTT for the different addresses
- shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
+ boost::shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(alpha, rrv4_, rrv6_);
NameserverEntry::AddressVector vec;
@@ -168,7 +167,7 @@
TEST_F(NameserverEntryTest, Unreachable) {
// Get the RTT for the different addresses
- shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
+ boost::shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(alpha, rrv4_, rrv6_);
NameserverEntry::AddressVector vec;
@@ -211,21 +210,21 @@
time_t expiration = 0;
// Test where there is a single TTL
- shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- fillNSEntry(alpha, rrv4_, shared_ptr<BasicRRset>());
+ boost::shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ fillNSEntry(alpha, rrv4_, boost::shared_ptr<BasicRRset>());
expiration = alpha->getExpiration();
EXPECT_EQ(expiration, curtime + rrv4_->getTTL().getValue());
- shared_ptr<NameserverEntry> beta(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- fillNSEntry(beta, shared_ptr<BasicRRset>(), rrv6_);
+ boost::shared_ptr<NameserverEntry> beta(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ fillNSEntry(beta, boost::shared_ptr<BasicRRset>(), rrv6_);
expiration = beta->getExpiration();
EXPECT_EQ(expiration, curtime + rrv6_->getTTL().getValue());
// Test where there are two different TTLs
EXPECT_NE(rrv4_->getTTL().getValue(), rrv6_->getTTL().getValue());
- shared_ptr<NameserverEntry> gamma(new NameserverEntry(EXAMPLE_CO_UK,
+ boost::shared_ptr<NameserverEntry> gamma(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(gamma, rrv4_, rrv6_);
uint32_t minttl = min(rrv4_->getTTL().getValue(), rrv6_->getTTL().getValue());
@@ -236,9 +235,9 @@
// that the expiration time should be greater than the TTL (as the current
// time is greater than zero).
- shared_ptr<NameserverEntry> delta(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- fillNSEntry(delta, rrv4_, shared_ptr<BasicRRset>());
+ boost::shared_ptr<NameserverEntry> delta(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ fillNSEntry(delta, rrv4_, boost::shared_ptr<BasicRRset>());
EXPECT_GT(delta->getExpiration(), rrv4_->getTTL().getValue());
}
@@ -262,10 +261,10 @@
// Tests if it asks the IP addresses and calls callbacks when it comes
// including the right addresses are returned and that they expire
TEST_F(NameserverEntryTest, IPCallbacks) {
- shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- shared_ptr<Callback> callback(new Callback);
- shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ boost::shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
entry->askIP(resolver, callback, ANY_OK);
// Ensure it becomes IN_PROGRESS
@@ -311,10 +310,10 @@
// Test the callback is called even when the address is unreachable
TEST_F(NameserverEntryTest, IPCallbacksUnreachable) {
- shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- shared_ptr<Callback> callback(new Callback);
- shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ boost::shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
// Ask for its IP
entry->askIP(resolver, callback, ANY_OK);
@@ -339,18 +338,18 @@
* from resolve.
*/
TEST_F(NameserverEntryTest, DirectAnswer) {
- shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- shared_ptr<Callback> callback(new Callback);
- shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ boost::shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
resolver->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
RRType::A()), rrv4_);
resolver->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
RRType::AAAA()), rrv6_);
resolver->addPresetAnswer(Question(Name(EXAMPLE_NET), RRClass::IN(),
- RRType::A()), shared_ptr<AbstractRRset>());
+ RRType::A()), boost::shared_ptr<AbstractRRset>());
resolver->addPresetAnswer(Question(Name(EXAMPLE_NET), RRClass::IN(),
- RRType::AAAA()), shared_ptr<AbstractRRset>());
+ RRType::AAAA()), boost::shared_ptr<AbstractRRset>());
// A successfull test first
entry->askIP(resolver, callback, ANY_OK);
@@ -376,10 +375,10 @@
* data is received the next time.
*/
TEST_F(NameserverEntryTest, ChangedExpired) {
- shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- shared_ptr<Callback> callback(new Callback);
- shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ boost::shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
// Ask the first time
entry->askIP(resolver, callback, V4_ONLY);
@@ -426,10 +425,10 @@
* When the data expire and is asked again, the original RTT is kept.
*/
TEST_F(NameserverEntryTest, KeepRTT) {
- shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
- RRClass::IN()));
- shared_ptr<Callback> callback(new Callback);
- shared_ptr<TestResolver> resolver(new TestResolver);
+ boost::shared_ptr<NameserverEntry> entry(new NameserverEntry(EXAMPLE_CO_UK,
+ RRClass::IN()));
+ boost::shared_ptr<Callback> callback(new Callback);
+ boost::shared_ptr<TestResolver> resolver(new TestResolver);
// Ask the first time
entry->askIP(resolver, callback, V4_ONLY);
@@ -482,7 +481,7 @@
// Test the RTT is updated smoothly
TEST_F(NameserverEntryTest, UpdateRTT) {
- shared_ptr<NameserverEntry> ns(new NameserverEntry(EXAMPLE_CO_UK,
+ boost::shared_ptr<NameserverEntry> ns(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(ns, rrv4_, rrv6_);
NameserverEntry::AddressVector vec;
Modified: branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/random_number_generator_unittest.cc Fri Dec 17 18:00:22 2010
@@ -52,64 +52,64 @@
const static int max_ = 10;
};
+// Some validation tests will incur performance penalty, so the tests are
+// made only in "debug" version with assert(). But if NDEBUG is defined
+// the tests will be failed since assert() is non-op in non-debug version.
+// The "#ifndef NDEBUG" is added to make the tests be performed only in
+// non-debug environment.
+// Note: the death test is not supported by all platforms. We need to
+// compile tests using it selectively.
+#if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST)
+// Test of the constructor
+TEST_F(UniformRandomIntegerGeneratorTest, Constructor) {
+ // The range must be min<=max
+ ASSERT_DEATH(UniformRandomIntegerGenerator(3, 2), "");
+}
+#endif
+
+// Test of the generated integers are in the range [min, max]
+TEST_F(UniformRandomIntegerGeneratorTest, IntegerRange) {
+ vector<int> numbers;
+
+ // Generate a lot of random integers
+ for (int i = 0; i < max()*10; ++i) {
+ numbers.push_back(gen());
+ }
+
+ // Remove the duplicated values
+ sort(numbers.begin(), numbers.end());
+ vector<int>::iterator it = unique(numbers.begin(), numbers.end());
+
+ // make sure the numbers are in range [min, max]
+ ASSERT_EQ(it - numbers.begin(), max() - min() + 1);
+}
+
+/// \brief Test Fixture Class for weighted random number generator
+class WeightedRandomIntegerGeneratorTest : public ::testing::Test {
+public:
+ WeightedRandomIntegerGeneratorTest()
+ { }
+
+ virtual ~WeightedRandomIntegerGeneratorTest()
+ { }
+};
+
+// Test of the weighted random number generator constructor
+TEST_F(WeightedRandomIntegerGeneratorTest, Constructor) {
+ vector<double> probabilities;
+
+ // If no probabilities is provided, the smallest integer will always be generated
+ WeightedRandomIntegerGenerator gen(probabilities, 123);
+ for (int i = 0; i < 100; ++i) {
+ ASSERT_EQ(gen(), 123);
+ }
+
/// Some validation tests will incur performance penalty, so the tests are
/// made only in "debug" version with assert(). But if NDEBUG is defined
/// the tests will be failed since assert() is non-op in non-debug version.
/// The "#ifndef NDEBUG" is added to make the tests be performed only in
/// non-debug environment.
-#ifndef NDEBUG
-// Test of the constructor
-TEST_F(UniformRandomIntegerGeneratorTest, Constructor) {
- // The range must be min<=max
- ASSERT_DEATH(UniformRandomIntegerGenerator(3, 2), "");
-}
-#endif
-
-// Test of the generated integers are in the range [min, max]
-TEST_F(UniformRandomIntegerGeneratorTest, IntegerRange) {
- vector<int> numbers;
-
- // Generate a lot of random integers
- for(int i = 0; i < max()*10; ++i){
- numbers.push_back(gen());
- }
-
- // Remove the duplicated values
- sort(numbers.begin(), numbers.end());
- vector<int>::iterator it = unique(numbers.begin(), numbers.end());
-
- // make sure the numbers are in range [min, max]
- ASSERT_EQ(it - numbers.begin(), max() - min() + 1);
-}
-
-
-/// \brief Test Fixture Class for weighted random number generator
-class WeightedRandomIntegerGeneratorTest : public ::testing::Test {
-public:
- WeightedRandomIntegerGeneratorTest()
- { }
-
- virtual ~WeightedRandomIntegerGeneratorTest()
- { }
-};
-
-// Test of the weighted random number generator constructor
-TEST_F(WeightedRandomIntegerGeneratorTest, Constructor)
-{
- vector<double> probabilities;
-
- // If no probabilities is provided, the smallest integer will always be generated
- WeightedRandomIntegerGenerator gen(probabilities, 123);
- for(int i = 0; i < 100; ++i){
- ASSERT_EQ(gen(), 123);
- }
-
-/// Some validation tests will incur performance penalty, so the tests are
-/// made only in "debug" version with assert(). But if NDEBUG is defined
-/// the tests will be failed since assert() is non-op in non-debug version.
-/// The "#ifndef NDEBUG" is added to make the tests be performed only in
-/// non-debug environment.
-#ifndef NDEBUG
+#if !defined(NDEBUG) && defined(GTEST_HAS_DEATH_TEST)
//The probability must be >= 0
probabilities.push_back(-0.1);
probabilities.push_back(1.1);
@@ -137,8 +137,7 @@
}
// Test the randomization of the generator
-TEST_F(WeightedRandomIntegerGeneratorTest, WeightedRandomization)
-{
+TEST_F(WeightedRandomIntegerGeneratorTest, WeightedRandomization) {
const int repeats = 100000;
// We repeat the simulation for N=repeats times
// for each probability p, its average is mu = N*p
@@ -156,10 +155,13 @@
WeightedRandomIntegerGenerator gen(probabilities);
int c1 = 0;
int c2 = 0;
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i){
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ }
}
double mu = repeats * p;
double sigma = sqrt(repeats * p * (1 - p));
@@ -176,10 +178,13 @@
probabilities.push_back(p1);
probabilities.push_back(p2);
WeightedRandomIntegerGenerator gen(probabilities);
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i) {
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ }
}
double mu1 = repeats * p1;
double mu2 = repeats * p2;
@@ -198,10 +203,13 @@
probabilities.push_back(p1);
probabilities.push_back(p2);
WeightedRandomIntegerGenerator gen(probabilities);
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i) {
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ }
}
double mu1 = repeats * p1;
double mu2 = repeats * p2;
@@ -223,11 +231,15 @@
probabilities.push_back(p2);
probabilities.push_back(p3);
WeightedRandomIntegerGenerator gen(probabilities);
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i){
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
- else if(n == 2) ++c3;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ } else if (n == 2) {
+ ++c3;
+ }
}
double mu1 = repeats * p1;
double mu2 = repeats * p2;
@@ -242,8 +254,7 @@
}
// Test the reset function of generator
-TEST_F(WeightedRandomIntegerGeneratorTest, ResetProbabilities)
-{
+TEST_F(WeightedRandomIntegerGeneratorTest, ResetProbabilities) {
const int repeats = 100000;
vector<double> probabilities;
int c1 = 0;
@@ -253,10 +264,13 @@
probabilities.push_back(p1);
probabilities.push_back(p2);
WeightedRandomIntegerGenerator gen(probabilities);
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i) {
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ }
}
double mu1 = repeats * p1;
double mu2 = repeats * p2;
@@ -273,10 +287,13 @@
probabilities.push_back(p1);
probabilities.push_back(p2);
gen.reset(probabilities);
- for(int i = 0; i < repeats; ++i){
+ for (int i = 0; i < repeats; ++i) {
int n = gen();
- if(n == 0) ++c1;
- else if(n == 1) ++c2;
+ if (n == 0) {
+ ++c1;
+ } else if (n == 1) {
+ ++c2;
+ }
}
mu1 = repeats * p1;
mu2 = repeats * p2;
Modified: branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc
==============================================================================
--- branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc (original)
+++ branches/trac226/src/lib/nsas/tests/zone_entry_unittest.cc Fri Dec 17 18:00:22 2010
@@ -35,7 +35,6 @@
using namespace isc::nsas;
using namespace asiolink;
using namespace std;
-using namespace boost;
using namespace isc::dns;
namespace {
@@ -43,10 +42,10 @@
/// \brief Inherited version with access into its internals for tests
class InheritedZoneEntry : public ZoneEntry {
public:
- InheritedZoneEntry(shared_ptr<ResolverInterface> resolver,
+ InheritedZoneEntry(boost::shared_ptr<ResolverInterface> resolver,
const std::string& name, const RRClass& class_code,
- shared_ptr<HashTable<NameserverEntry> > nameserver_table,
- shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
+ boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table,
+ boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru) :
ZoneEntry(resolver, name, class_code, nameserver_table,
nameserver_lru)
{ }
@@ -67,10 +66,10 @@
callback_(new Callback)
{ }
/// \brief Tables of nameservers to pass into zone entry constructor
- shared_ptr<HashTable<NameserverEntry> > nameserver_table_;
- shared_ptr<LruList<NameserverEntry> > nameserver_lru_;
+ boost::shared_ptr<HashTable<NameserverEntry> > nameserver_table_;
+ boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru_;
/// \brief The resolver
- shared_ptr<TestResolver> resolver_;
+ boost::shared_ptr<TestResolver> resolver_;
/**
* \short A callback we use into the zone.
@@ -86,15 +85,15 @@
successes_.push_back(address);
}
};
- shared_ptr<Callback> callback_;
+ boost::shared_ptr<Callback> callback_;
// Empty callback to pass to nameserver entry, to do injection of them
struct NseCallback : public NameserverEntry::Callback {
- virtual void operator()(shared_ptr<NameserverEntry>) { }
+ virtual void operator()(boost::shared_ptr<NameserverEntry>) { }
};
- shared_ptr<NseCallback> nseCallback() {
- return (shared_ptr<NseCallback>(new NseCallback));
+ boost::shared_ptr<NseCallback> nseCallback() {
+ return (boost::shared_ptr<NseCallback>(new NseCallback));
}
/**
@@ -102,8 +101,8 @@
*
* Convenience funcion, just creating a new zone, to shorten the code.
*/
- shared_ptr<InheritedZoneEntry> getZone() {
- return (shared_ptr<InheritedZoneEntry>(new InheritedZoneEntry(
+ boost::shared_ptr<InheritedZoneEntry> getZone() {
+ return (boost::shared_ptr<InheritedZoneEntry>(new InheritedZoneEntry(
resolver_, EXAMPLE_CO_UK, RRClass::IN(), nameserver_table_,
nameserver_lru_)));
}
@@ -115,8 +114,8 @@
* hash table already contains the NameserverEntry. This function
* creates one and puts it into the hash table.
*/
- shared_ptr<NameserverEntry> injectEntry() {
- shared_ptr<NameserverEntry> nse(new NameserverEntry(ns_name_.toText(),
+ boost::shared_ptr<NameserverEntry> injectEntry() {
+ boost::shared_ptr<NameserverEntry> nse(new NameserverEntry(ns_name_.toText(),
RRClass::IN()));
nameserver_table_->add(nse, HashKey(ns_name_.toText(), RRClass::IN()));
EXPECT_EQ(Fetchable::NOT_ASKED, nse->getState());
@@ -148,7 +147,7 @@
size_t failure_count = 0)
{
// Create the zone and check it acts correctly
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
resolver_->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
RRType::NS()), rr_single_);
zone->addCallback(callback_, ANY_OK);
@@ -192,7 +191,7 @@
* should be generated anywhere and the failure should be provided).
*/
TEST_F(ZoneEntryTest, CallbackNoNS) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
// feed it with a callback
zone->addCallback(callback_, ANY_OK);
@@ -220,7 +219,7 @@
TEST_F(ZoneEntryTest, ChangedNS) {
// Make it zero TTL, so it expires right away
rr_single_->setTTL(RRTTL(0));
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
// Feed it with callback
zone->addCallback(callback_, ANY_OK);
@@ -283,7 +282,7 @@
* provided.
*/
TEST_F(ZoneEntryTest, CallbacksAnswered) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
// Feed it with a callback
zone->addCallback(callback_, ANY_OK);
@@ -343,7 +342,7 @@
* fail.
*/
TEST_F(ZoneEntryTest, CallbacksAOnly) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
zone->addCallback(callback_, ANY_OK);
EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
@@ -396,14 +395,14 @@
* (successful) answers to us.
*/
TEST_F(ZoneEntryTest, CallbackTwoNS) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
zone->addCallback(callback_, V4_ONLY);
EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
EXPECT_NO_THROW(resolver_->provideNS(0, rrns_));
EXPECT_EQ(Fetchable::READY, zone->getState());
// It asks a question (we do not know which nameserver)
- shared_ptr<Name> name;
+ boost::shared_ptr<Name> name;
ASSERT_NO_THROW(name.reset(new Name((*resolver_)[1]->getName())));
ASSERT_TRUE(resolver_->asksIPs(*name, 1, 2));
resolver_->requests[1].second->failure();
@@ -455,12 +454,12 @@
* resolve). Tries checking both positive and negative answers.
*/
TEST_F(ZoneEntryTest, DirectAnswer) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
// One unsuccessfull attempt, nameservers fail
resolver_->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
- RRType::NS()), shared_ptr<AbstractRRset>());
+ RRType::NS()), boost::shared_ptr<AbstractRRset>());
zone->addCallback(callback_, ANY_OK);
EXPECT_EQ(0, callback_->successes_.size());
EXPECT_EQ(1, callback_->unreachable_count_);
@@ -494,9 +493,9 @@
callback_->successes_.clear();
// Now, pretend we do not have IP addresses
resolver_->addPresetAnswer(Question(ns_name, RRClass::IN(), RRType::A()),
- shared_ptr<AbstractRRset>());
+ boost::shared_ptr<AbstractRRset>());
resolver_->addPresetAnswer(Question(ns_name, RRClass::IN(),
- RRType::AAAA()), shared_ptr<AbstractRRset>());
+ RRType::AAAA()), boost::shared_ptr<AbstractRRset>());
// Get another zone and ask it again. It should fail.
// Clean the table first, though, so it does not find the old nameserver
nameserver_table_->remove(HashKey(ns_name.toText(), RRClass::IN()));
@@ -518,7 +517,7 @@
* its addresses and must ask it again.
*/
TEST_F(ZoneEntryTest, AddressTimeout) {
- shared_ptr<InheritedZoneEntry> zone(getZone());
+ boost::shared_ptr<InheritedZoneEntry> zone(getZone());
EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
zone->addCallback(callback_, ANY_OK);
EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
@@ -567,7 +566,7 @@
/// \short Test how the zone reacts to a nameserver entry in ready state
TEST_F(ZoneEntryTest, NameserverEntryReady) {
// Inject the entry
- shared_ptr<NameserverEntry> nse(injectEntry());
+ boost::shared_ptr<NameserverEntry> nse(injectEntry());
// Fill it with data
nse->askIP(resolver_, nseCallback(), ANY_OK);
EXPECT_EQ(Fetchable::IN_PROGRESS, nse->getState());
@@ -593,7 +592,7 @@
/// \short What if the zone finds a nameserver in progress?
TEST_F(ZoneEntryTest, NameserverEntryInProgress) {
// Prepare the nameserver entry
- shared_ptr<NameserverEntry> nse(injectEntry());
+ boost::shared_ptr<NameserverEntry> nse(injectEntry());
nse->askIP(resolver_, nseCallback(), ANY_OK);
EXPECT_EQ(Fetchable::IN_PROGRESS, nse->getState());
EXPECT_TRUE(resolver_->asksIPs(ns_name_, 0, 1));
@@ -603,7 +602,7 @@
/// \short Check Zone's reaction to found expired nameserver
TEST_F(ZoneEntryTest, NameserverEntryExpired) {
- shared_ptr<NameserverEntry> nse(injectEntry());
+ boost::shared_ptr<NameserverEntry> nse(injectEntry());
nse->askIP(resolver_, nseCallback(), ANY_OK);
EXPECT_EQ(Fetchable::IN_PROGRESS, nse->getState());
EXPECT_TRUE(resolver_->asksIPs(ns_name_, 0, 1));
@@ -622,7 +621,7 @@
/// \short Check how it reacts to an unreachable zone already in the table
TEST_F(ZoneEntryTest, NameserverEntryUnreachable) {
- shared_ptr<NameserverEntry> nse(injectEntry());
+ boost::shared_ptr<NameserverEntry> nse(injectEntry());
nse->askIP(resolver_, nseCallback(), ANY_OK);
ASSERT_EQ(2, resolver_->requests.size());
resolver_->requests[0].second->failure();
@@ -651,7 +650,7 @@
const size_t repeats = 100000;
// Create the zone, give it 2 nameservers and total of 3 addresses
// (one of them is ipv6)
- shared_ptr<ZoneEntry> zone(getZone());
+ boost::shared_ptr<ZoneEntry> zone(getZone());
zone->addCallback(callback_, ANY_OK);
EXPECT_NO_THROW(resolver_->provideNS(0, rrns_));
ASSERT_GT(resolver_->requests.size(), 1);
@@ -666,7 +665,7 @@
resolver_->answer(3, name2, RRType::A(), rdata::in::A("192.0.2.3"));
resolver_->requests[4].second->failure();
- shared_ptr<NameserverEntry> ns1(nameserver_table_->get(HashKey(
+ boost::shared_ptr<NameserverEntry> ns1(nameserver_table_->get(HashKey(
name1.toText(), RRClass::IN()))),
ns2(nameserver_table_->get(HashKey(name2.toText(), RRClass::IN())));
Modified: branches/trac226/src/lib/nsas/zone_entry.cc
==============================================================================
--- branches/trac226/src/lib/nsas/zone_entry.cc (original)
+++ branches/trac226/src/lib/nsas/zone_entry.cc Fri Dec 17 18:00:22 2010
@@ -20,12 +20,11 @@
#include <algorithm>
#include <boost/foreach.hpp>
-#include <boost/random.hpp>
+#include <boost/bind.hpp>
#include <dns/rrttl.h>
#include <dns/rdataclass.h>
using namespace std;
-using namespace boost;
namespace isc {
@@ -48,16 +47,16 @@
namespace {
// Shorter aliases for frequently used types
-typedef recursive_mutex::scoped_lock Lock; // Local lock, nameservers not locked
-typedef shared_ptr<AddressRequestCallback> CallbackPtr;
+typedef boost::recursive_mutex::scoped_lock Lock; // Local lock, nameservers not locked
+typedef boost::shared_ptr<AddressRequestCallback> CallbackPtr;
/*
* Create a nameserver.
* Called inside a mutex so it is filled in atomically.
*/
-shared_ptr<NameserverEntry>
+boost::shared_ptr<NameserverEntry>
newNs(const std::string* name, const RRClass* class_code) {
- return (shared_ptr<NameserverEntry>(new NameserverEntry(*name,
+ return (boost::shared_ptr<NameserverEntry>(new NameserverEntry(*name,
*class_code)));
}
@@ -77,7 +76,7 @@
class ZoneEntry::ResolverCallback : public ResolverInterface::Callback {
public:
/// \short Constructor. Pass "this" zone entry
- ResolverCallback(shared_ptr<ZoneEntry> entry) :
+ ResolverCallback(boost::shared_ptr<ZoneEntry> entry) :
entry_(entry)
{ }
/**
@@ -91,7 +90,7 @@
* examining them and seeing if some addresses are already there
* and to ask for the rest of them.
*/
- virtual void success(const shared_ptr<AbstractRRset>& answer) {
+ virtual void success(const boost::shared_ptr<AbstractRRset>& answer) {
Lock lock(entry_->mutex_);
RdataIteratorPtr iterator(answer->getRdataIterator());
// If there are no data
@@ -137,7 +136,7 @@
string ns_name_str(ns_name.toText());
pair<bool, NameserverPtr> from_hash(
entry_->nameserver_table_->getOrAdd(HashKey(
- ns_name_str, entry_->class_code_), bind(
+ ns_name_str, entry_->class_code_), boost::bind(
newNs, &ns_name_str, &entry_->class_code_)));
// Make it at the front of the list
if (from_hash.first) {
@@ -203,7 +202,7 @@
entry_->process(ADDR_REQ_MAX, NameserverPtr());
}
/// \short The entry we are callback of
- shared_ptr<ZoneEntry> entry_;
+ boost::shared_ptr<ZoneEntry> entry_;
};
void
@@ -237,7 +236,7 @@
// Our callback might be directly called from resolve, unlock now
QuestionPtr question(new Question(Name(name_), class_code_,
RRType::NS()));
- shared_ptr<ResolverCallback> resolver_callback(
+ boost::shared_ptr<ResolverCallback> resolver_callback(
new ResolverCallback(shared_from_this()));
resolver_->resolve(question, resolver_callback);
return;
@@ -337,7 +336,7 @@
* \param family For which address family this change is, so we
* do not process all the nameserves and callbacks there.
*/
- NameserverCallback(shared_ptr<ZoneEntry> entry, AddressFamily family) :
+ NameserverCallback(boost::shared_ptr<ZoneEntry> entry, AddressFamily family) :
entry_(entry),
family_(family)
{ }
@@ -352,7 +351,7 @@
entry_->process(family_, ns);
}
private:
- shared_ptr<ZoneEntry> entry_;
+ boost::shared_ptr<ZoneEntry> entry_;
AddressFamily family_;
};
@@ -373,7 +372,7 @@
void
ZoneEntry::process(AddressFamily family,
- const shared_ptr<NameserverEntry>& nameserver)
+ const boost::shared_ptr<NameserverEntry>& nameserver)
{
Lock lock(mutex_);
switch (getState()) {
@@ -516,7 +515,7 @@
insertCallback(ns, V4_ONLY);
insertCallback(ns, V6_ONLY);
} else {
- shared_ptr<NameserverCallback> callback(new NameserverCallback(
+ boost::shared_ptr<NameserverCallback> callback(new NameserverCallback(
shared_from_this(), family));
ns->askIP(resolver_, callback, family);
}
More information about the bind10-changes
mailing list