Parcourir la source

[3391] Fix distcheck issues.

Marcin Siodelski il y a 11 ans
Parent
commit
b6e72599da
33 fichiers modifiés avec 9 ajouts et 6159 suppressions
  1. 0 6
      configure.ac
  2. 3 1
      src/lib/asiodns/dns_service.h
  3. 0 3
      src/lib/resolve/.gitignore
  4. 0 48
      src/lib/resolve/Makefile.am
  5. 0 1225
      src/lib/resolve/recursive_query.cc
  6. 0 229
      src/lib/resolve/recursive_query.h
  7. 0 78
      src/lib/resolve/resolve.cc
  8. 0 95
      src/lib/resolve/resolve.h
  9. 0 26
      src/lib/resolve/resolve_log.cc
  10. 0 53
      src/lib/resolve/resolve_log.h
  11. 0 229
      src/lib/resolve/resolve_messages.mes
  12. 0 36
      src/lib/resolve/resolver_callback.cc
  13. 0 50
      src/lib/resolve/resolver_callback.h
  14. 0 98
      src/lib/resolve/resolver_interface.h
  15. 0 279
      src/lib/resolve/response_classifier.cc
  16. 0 157
      src/lib/resolve/response_classifier.h
  17. 0 1
      src/lib/resolve/tests/.gitignore
  18. 0 45
      src/lib/resolve/tests/Makefile.am
  19. 0 1006
      src/lib/resolve/tests/recursive_query_unittest.cc
  20. 0 728
      src/lib/resolve/tests/recursive_query_unittest_2.cc
  21. 0 590
      src/lib/resolve/tests/recursive_query_unittest_3.cc
  22. 0 198
      src/lib/resolve/tests/resolve_unittest.cc
  23. 0 90
      src/lib/resolve/tests/resolver_callback_unittest.cc
  24. 0 554
      src/lib/resolve/tests/response_classifier_unittest.cc
  25. 0 27
      src/lib/resolve/tests/run_unittests.cc
  26. 6 3
      src/lib/testutils/mockups.h
  27. 0 15
      src/lib/xfr/Makefile.am
  28. 0 1
      src/lib/xfr/tests/.gitignore
  29. 0 28
      src/lib/xfr/tests/Makefile.am
  30. 0 37
      src/lib/xfr/tests/client_test.cc
  31. 0 24
      src/lib/xfr/tests/run_unittests.cc
  32. 0 108
      src/lib/xfr/xfrout_client.cc
  33. 0 91
      src/lib/xfr/xfrout_client.h

+ 0 - 6
configure.ac

@@ -1469,7 +1469,6 @@ AC_CONFIG_FILES([compatcheck/Makefile
                  src/lib/dhcpsrv/tests/Makefile
                  src/lib/dhcpsrv/tests/test_libraries.h
                  src/lib/dhcp/tests/Makefile
-                 src/lib/dns/benchmarks/Makefile
                  src/lib/dns/gen-rdatacode.py
                  src/lib/dns/Makefile
                  src/lib/dns/python/Makefile
@@ -1668,11 +1667,6 @@ fi
 
 cat >> config.report << END
 
-Components:
-  DHCP: $want_dhcp
-  DNS: $want_dns
-  Experimental resolver: $want_experimental_resolver
-
 Features:
   $enable_features
 

+ 3 - 1
src/lib/asiodns/dns_service.h

@@ -15,7 +15,9 @@
 #ifndef ASIOLINK_DNS_SERVICE_H
 #define ASIOLINK_DNS_SERVICE_H 1
 
-#include <resolve/resolver_interface.h>
+// The commented header occurs to be unused so we remove it to get
+// rid of dependency on resolver.
+// #include <resolve/resolver_interface.h>
 
 #include <asiolink/io_service.h>
 #include <asiolink/simple_callback.h>

+ 0 - 3
src/lib/resolve/.gitignore

@@ -1,3 +0,0 @@
-/resolve_messages.cc
-/resolve_messages.h
-/s-messages

+ 0 - 48
src/lib/resolve/Makefile.am

@@ -1,48 +0,0 @@
-SUBDIRS = . tests
-
-AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
-AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
-AM_CPPFLAGS += $(BOOST_INCLUDES)
-
-AM_CXXFLAGS = $(B10_CXXFLAGS)
-
-# Define rule to build logging source files from message file
-resolve_messages.h resolve_messages.cc: s-messages
-
-s-messages: resolve_messages.mes
-	$(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/resolve/resolve_messages.mes
-	touch $@
-
-# Tell Automake that the nsasdef.{cc,h} source files are created in the build
-# process, so it must create these before doing anything else.  Although they
-# are a dependency of the library (so will be created from the message file
-# anyway), there is no guarantee as to exactly _when_ in the build they will be
-# created.  As the .h file is included in other sources file (so must be
-# present when they are compiled), the safest option is to create it first.
-BUILT_SOURCES = resolve_messages.h resolve_messages.cc
-
-CLEANFILES = *.gcno *.gcda resolve_messages.cc resolve_messages.h s-messages
-
-lib_LTLIBRARIES = libb10-resolve.la
-libb10_resolve_la_SOURCES = resolve.h resolve.cc
-libb10_resolve_la_SOURCES += resolve_log.h resolve_log.cc
-libb10_resolve_la_SOURCES += resolver_interface.h
-libb10_resolve_la_SOURCES += resolver_callback.h resolver_callback.cc
-libb10_resolve_la_SOURCES += response_classifier.cc response_classifier.h
-libb10_resolve_la_SOURCES += recursive_query.cc recursive_query.h
-
-nodist_libb10_resolve_la_SOURCES = resolve_messages.h resolve_messages.cc
-
-libb10_resolve_la_LIBADD = $(top_builddir)/src/lib/dns/libb10-dns++.la
-libb10_resolve_la_LIBADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
-libb10_resolve_la_LIBADD += $(top_builddir)/src/lib/log/libb10-log.la
-libb10_resolve_la_LIBADD += $(top_builddir)/src/lib/asiodns/libb10-asiodns.la
-libb10_resolve_la_LIBADD += $(top_builddir)/src/lib/nsas/libb10-nsas.la
-
-# The message file should be in the distribution.
-EXTRA_DIST = resolve_messages.mes
-
-# Note: the ordering matters: -Wno-... must follow -Wextra (defined in
-# B10_CXXFLAGS)
-libb10_resolve_la_CXXFLAGS = $(AM_CXXFLAGS)
-libb10_resolve_la_CPPFLAGS = $(AM_CPPFLAGS)

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 1225
src/lib/resolve/recursive_query.cc


+ 0 - 229
src/lib/resolve/recursive_query.h

@@ -1,229 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef RECURSIVE_QUERY_H
-#define RECURSIVE_QUERY_H 1
-
-#include <util/buffer.h>
-#include <asiodns/dns_service.h>
-#include <asiodns/dns_server.h>
-#include <nsas/nameserver_address_store.h>
-#include <cache/resolver_cache.h>
-
-namespace isc {
-namespace asiodns {
-
-/// \brief RTT Recorder
-///
-/// Used for testing, this class will hold the set of round-trip times to
-/// nameservers for the current recursive query.
-///
-/// A pointer to an object of this class is passed to RecursiveQuery which in
-/// turn passes it to the created RunningQuery class.  When a running query
-/// completes, its RTT is passed to the RTT Recorder object.
-class RttRecorder {
-public:
-    /// \brief Record Time
-    ///
-    /// Adds a round-trip time to the internal vector of times.
-    ///
-    /// \param rtt RTT to record.
-    void addRtt(uint32_t rtt) {
-        rtt_.push_back(rtt);
-    }
-
-    /// \brief Return RTT Vector
-    std::vector<uint32_t> getRtt() const {
-        return rtt_;
-    }
-
-private:
-    std::vector<uint32_t>   rtt_;   ///< Stored round-trip times
-};
-
-typedef std::vector<std::pair<std::string, uint16_t> > AddressVector;
-
-/// \brief A Running query
-///
-/// This base class represents an active running query object;
-/// i.e. an outstanding query to an authoritative name server or
-/// upstream server (when running in forwarder mode).
-///
-/// It can not be instantiated directly, but is created by
-/// RecursiveQuery::resolve() and RecursiveQuery::forward().
-///
-/// Its only public method is its destructor, and that should in theory
-/// not be called either except in some unit tests. Instances should
-/// delete themselves when the query is finished.
-class AbstractRunningQuery {
-protected:
-    AbstractRunningQuery() {};
-public:
-    virtual ~AbstractRunningQuery() {};
-};
-
-/// \brief Recursive Query
-///
-/// The \c RecursiveQuery class provides a layer of abstraction around
-/// the ASIO code that carries out an upstream query.
-
-class RecursiveQuery {
-    ///
-    /// \name Constructors
-    ///
-    //@{
-public:
-    /// \brief Constructor
-    ///
-    /// This is currently the only way to construct \c RecursiveQuery
-    /// object. If the addresses of the forward nameservers is specified,
-    /// and every upstream query will be sent to one random address, and
-    /// the result sent back directly. If not, it will do full resolving.
-    ///
-    /// \param dns_service The DNS Service to perform the recursive
-    ///        query on.
-    /// \param nsas Nameserver address store, used to hold information about zone
-    ///        nameservers.
-    /// \param cache Resolver cache object, used to hold information about retrieved
-    ///        records.
-    /// \param upstream Addresses and ports of the upstream servers
-    ///        to forward queries to.
-    /// \param upstream_root Addresses and ports of the root servers
-    ///        to use when resolving.
-    /// \param query_timeout Timeout value for queries we sent, in ms
-    /// \param client_timeout Timeout value for when we send back an
-    ///        error, in ms
-    /// \param lookup_timeout Timeout value for when we give up, in ms
-    /// \param retries how many times we try again (0 means just send and
-    ///     and return if it returs).
-    RecursiveQuery(DNSServiceBase& dns_service,
-                   isc::nsas::NameserverAddressStore& nsas,
-                   isc::cache::ResolverCache& cache,
-                   const std::vector<std::pair<std::string, uint16_t> >&
-                   upstream,
-                   const std::vector<std::pair<std::string, uint16_t> >&
-                   upstream_root,
-                   int query_timeout = 2000,
-                   int client_timeout = 4000,
-                   int lookup_timeout = 30000,
-                   unsigned retries = 3);
-    //@}
-
-    /// \brief Set Round-Trip Time Recorder
-    ///
-    /// Sets the RTT recorder object.  This is not accessed directly, instead
-    /// it is passed to created RunningQuery objects.
-    ///
-    /// \param recorder Pointer to the RTT recorder object used to hold RTTs.
-    void setRttRecorder(boost::shared_ptr<RttRecorder>& recorder);
-
-    /// \brief Initiate resolving
-    ///
-    /// When sendQuery() is called, a (set of) message(s) is sent
-    /// asynchronously. If upstream servers are set, one is chosen
-    /// and the response (if any) from that server will be returned.
-    ///
-    /// If not upstream is set, a root server is chosen from the
-    /// root_servers, and the RunningQuery shall do a full resolve
-    /// (i.e. if the answer is a delegation, it will be followed, etc.)
-    /// until there is an answer or an error.
-    ///
-    /// When there is a response or an error and we give up, the given
-    /// CallbackPtr object shall be called (with either success() or
-    /// failure(). See ResolverInterface::Callback for more information.
-    ///
-    /// \param question The question being answered <qname/qclass/qtype>
-    /// \param callback Callback object. See
-    ///        \c ResolverInterface::Callback for more information
-    AbstractRunningQuery* resolve(const isc::dns::QuestionPtr& question,
-        const isc::resolve::ResolverInterface::CallbackPtr callback);
-
-
-    /// \brief Initiates resolving for the given question.
-    ///
-    /// This actually calls the previous sendQuery() with a default
-    /// callback object, which calls resume() on the given DNSServer
-    /// object.
-    ///
-    /// \param question The question being answered <qname/qclass/qtype>
-    /// \param answer_message An output Message into which the final response will
-    ///        be copied.
-    /// \param buffer An output buffer into which the intermediate responses will
-    ///        be copied.
-    /// \param server A pointer to the \c DNSServer object handling the client
-    /// \return A pointer to the active AbstractRunningQuery object
-    ///         created by this call (if any); this object should delete
-    ///         itself in normal circumstances, and can normally be ignored
-    ///         by the caller, but a pointer is returned for use-cases
-    ///         such as unit tests.
-    ///         Returns NULL if the data was found internally and no actual
-    ///         query was sent.
-    AbstractRunningQuery* resolve(const isc::dns::Question& question,
-                          isc::dns::MessagePtr answer_message,
-                          isc::util::OutputBufferPtr buffer,
-                          DNSServer* server);
-
-    /// \brief Initiates forwarding for the given query.
-    ///
-    ///  Others parameters are same with the parameters of
-    ///  function resolve().
-    ///
-    /// \param query_message the full query got from client.
-    /// \param answer_message the full answer received from other server.
-    /// \param buffer Output buffer into which the responses will be copied.
-    /// \param server Server object that handles receipt and processing of the
-    ///               received messages.
-    /// \param callback callback object
-    /// \return A pointer to the active ForwardQuery created by this call;
-    ///         this object should delete itself in normal circumstances,
-    ///         and can normally be ignored by the caller, but a pointer
-    ///         is returned for use-cases such as unit tests.
-    AbstractRunningQuery* forward(isc::dns::ConstMessagePtr query_message,
-                 isc::dns::MessagePtr answer_message,
-                 isc::util::OutputBufferPtr buffer,
-                 DNSServer* server,
-                 isc::resolve::ResolverInterface::CallbackPtr callback =
-                     isc::resolve::ResolverInterface::CallbackPtr());
-
-    /// \brief Set Test Server
-    ///
-    /// This method is *only* for unit testing the class.  If set, it enables
-    /// recursive behaviour but, regardless of responses received, sends every
-    /// query to the test server.
-    ///
-    /// The test server is enabled by setting a non-zero port number.
-    ///
-    /// \param address IP address of the test server.
-    /// \param port Port number of the test server
-    void setTestServer(const std::string& address, uint16_t port);
-
-private:
-    DNSServiceBase& dns_service_;
-    isc::nsas::NameserverAddressStore& nsas_;
-    isc::cache::ResolverCache& cache_;
-    boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
-        upstream_;
-    boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
-        upstream_root_;
-    std::pair<std::string, uint16_t> test_server_;
-    int query_timeout_;
-    int client_timeout_;
-    int lookup_timeout_;
-    unsigned retries_;
-    boost::shared_ptr<RttRecorder>  rtt_recorder_;  ///< Round-trip time recorder
-};
-
-}      // namespace asiodns
-}      // namespace isc
-#endif // RECURSIVE_QUERY_H

+ 0 - 78
src/lib/resolve/resolve.cc

@@ -1,78 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <resolve/resolve.h>
-
-#include <dns/message.h>
-#include <dns/opcode.h>
-
-using namespace isc::dns;
-
-namespace {
-    class SectionInserter {
-    public:
-        SectionInserter(MessagePtr message, const Message::Section sect) :
-            message_(message), section_(sect)
-        {}
-        void operator()(const RRsetPtr rrset) {
-            message_->addRRset(section_, rrset);
-        }
-        MessagePtr message_;
-        const Message::Section section_;
-    };
-}
-
-namespace isc {
-namespace resolve {
-
-void
-makeErrorMessage(MessagePtr answer_message,
-                 const Rcode& error_code)
-{
-    answer_message->clearSection(Message::SECTION_ANSWER);
-    answer_message->clearSection(Message::SECTION_AUTHORITY);
-    answer_message->clearSection(Message::SECTION_ADDITIONAL);
-
-    answer_message->setRcode(error_code);
-}
-
-void initResponseMessage(const isc::dns::Message& query_message,
-                         isc::dns::Message& response_message)
-{
-    response_message.setOpcode(query_message.getOpcode());
-    response_message.setQid(query_message.getQid());
-    assert(response_message.getRRCount(Message::SECTION_QUESTION) == 0);
-    response_message.appendSection(Message::SECTION_QUESTION,
-        query_message);
-}
-
-void initResponseMessage(const isc::dns::Question& question,
-                         isc::dns::Message& response_message)
-{
-    response_message.setOpcode(isc::dns::Opcode::QUERY());
-    response_message.addQuestion(question);
-}
-
-void copyResponseMessage(const Message& source, MessagePtr target) {
-    target->setRcode(source.getRcode());
-
-    target->appendSection(Message::SECTION_ANSWER, source);
-    target->appendSection(Message::SECTION_AUTHORITY, source);
-    target->appendSection(Message::SECTION_ADDITIONAL, source);
-}
-
-
-} // namespace resolve
-} // namespace isc
-

+ 0 - 95
src/lib/resolve/resolve.h

@@ -1,95 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef ISC_RESOLVE_H
-#define ISC_RESOLVE_H 1
-
-/// This file includes all other libresolve headers, and provides
-/// several helper functions used in resolving.
-
-#include <resolve/resolver_interface.h>
-#include <resolve/resolver_callback.h>
-#include <resolve/response_classifier.h>
-
-#include <dns/rcode.h>
-
-namespace isc {
-namespace resolve {
-
-/// \brief Create an error response
-///
-/// Clears the answer, authority, and additional section of the
-/// given MessagePtr and sets the given error code
-///
-/// Notes: Assuming you have already done initial preparations
-/// on the given answer message (copy the opcode, qid and question
-/// section), you can simply use this to create an error response.
-///
-/// \param answer_message The message to clear and place the error in
-/// \param error_code The error Rcode
-void makeErrorMessage(isc::dns::MessagePtr answer_message,
-                      const isc::dns::Rcode& error_code);
-
-
-/// \brief Initialize a response message
-///
-/// Based on the given query message, this fills in the very
-/// first details of the response (i.e. the Question section and
-/// the Opcode). This allows for direct usage of makeErrorMessage(),
-/// as well as ResolveCache.lookup().
-///
-/// Raises an isc::dns::InvalidMessageOperation if reponse_message is
-/// not in RENDER mode.
-///
-/// \param query_message The query message to take the Question, Qid,
-///                      and Opcode from.
-/// \param response_message The fresh response message to initialize
-///                         (must be in RENDER mode)
-void initResponseMessage(const isc::dns::Message& query_message,
-                         isc::dns::Message& response_message);
-
-
-/// \brief Initialize a response message
-///
-/// Based on the given question, this fills in the very
-/// first details of the response (i.e. the Question section and the
-/// Opcode Query). This allows for direct usage of makeErrorMessage(),
-/// as well as ResolveCache.lookup().
-///
-/// Raises an isc::dns::InvalidMessageOperation if reponse_message is
-/// not in RENDER mode.
-///
-/// \param question The question to place in the Question section
-/// \param response_message The fresh response message to initialize
-///                         (must be in RENDER mode)
-void initResponseMessage(const isc::dns::Question& question,
-                         isc::dns::Message& response_message);
-
-
-/// \brief Copies the parts relevant for a DNS response to the
-/// target message
-///
-/// This adds all the RRsets in the answer, authority and
-/// additional sections to the target, as well as the response
-/// code
-/// \param source The Message to copy the data from
-/// \param target The Message to copy the data to
-void copyResponseMessage(const isc::dns::Message& source,
-                         isc::dns::MessagePtr target);
-
-
-} // namespace resolve
-} // namespace isc
-
-#endif // ISC_RESOLVE_H_

+ 0 - 26
src/lib/resolve/resolve_log.cc

@@ -1,26 +0,0 @@
-// Copyright (C) 2011  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.
-
-/// Defines the logger used by the NSAS
-
-#include <resolve/resolve_log.h>
-
-namespace isc {
-namespace resolve {
-
-isc::log::Logger logger("reslib");  // Distinct from "resolver"
-
-} // namespace resolve
-} // namespace isc
-

+ 0 - 53
src/lib/resolve/resolve_log.h

@@ -1,53 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef RESOLVE_LOG_H
-#define RESOLVE_LOG_H
-
-#include <log/macros.h>
-#include "resolve_messages.h"
-
-namespace isc {
-namespace resolve {
-
-/// \brief Resolver Library Logging
-///
-/// Defines the levels used to output debug messages in the resolver library.
-/// Note that higher numbers equate to more verbose (and detailed) output.
-
-// The first level traces normal operations
-const int RESLIB_DBG_TRACE = DBGLVL_TRACE_BASIC;
-
-// The next level extends the normal operations and records the results of the
-// lookups.
-const int RESLIB_DBG_RESULTS = DBGLVL_TRACE_BASIC_DATA;
-
-// Report cache lookups and results
-const int RESLIB_DBG_CACHE = DBGLVL_TRACE_DETAIL_DATA;
-
-// Indicate when callbacks are called
-const int RESLIB_DBG_CB = DBGLVL_TRACE_DETAIL_DATA + 10;
-
-
-/// \brief Resolver Library Logger
-///
-/// Define the logger used to log messages.  We could define it in multiple
-/// modules, but defining in a single module and linking to it saves time and
-/// space.
-extern isc::log::Logger logger;
-
-} // namespace resolve
-} // namespace isc
-
-#endif // RESOLVE_LOG_H

+ 0 - 229
src/lib/resolve/resolve_messages.mes

@@ -1,229 +0,0 @@
-# Copyright (C) 2011  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.
-
-$NAMESPACE isc::resolve
-
-% RESLIB_ANSWER answer received in response to query for <%1>
-A debug message reporting that an answer has been received to an upstream
-query for the specified question.  Previous debug messages will have
-indicated the server to which the question was sent.
-
-% RESLIB_CNAME CNAME received in response to query for <%1>
-A debug message recording that CNAME response has been received to an
-upstream query for the specified question.  Previous debug messages will
-have indicated the server to which the question was sent.
-
-% RESLIB_DEEPEST did not find <%1> in cache, deepest delegation found is %2
-A debug message, a cache lookup did not find the specified <name,
-class, type> tuple in the cache; instead, the deepest delegation found
-is indicated.
-
-% RESLIB_EMPTY_RESPONSE empty response received to query for <%1>
-A debug message, the response to the specified query from an upstream
-nameserver did not contain anything in the answer or authority sections,
-although in all other respects it was a valid response.  A SERVFAIL will
-be returned to the system making the original query.
-
-% RESLIB_ERROR_RESPONSE unspecified error received in response to query for <%1>
-A debug message, the response to the specified query to an upstream
-nameserver indicated that the response was classified as an erroneous
-response, but that the nature of the error cannot be identified.
-A SERVFAIL will be returned to the system making the original query.
-
-% RESLIB_EXTRADATA_RESPONSE extra data in response to query for <%1>
-A debug message indicating that the response to the specified query
-from an upstream nameserver contained too much data.  This can happen if
-an ANY query was sent and the answer section in the response contained
-multiple RRs with different names.  A SERVFAIL will be returned to the
-system making the original query.
-
-% RESLIB_FOLLOW_CNAME following CNAME chain to <%1>
-A debug message, a CNAME response was received and another query is
-being issued for the <name, class, type> tuple.
-
-% RESLIB_INVALID_NAMECLASS_RESPONSE invalid name or class in response to query for <%1>
-A debug message, the response to the specified query from an upstream
-nameserver (as identified by the ID of the response) contained either
-an answer not matching the query name or an answer having a different
-class to that queried for.  A SERVFAIL will be returned to the system
-making the original query.
-
-% RESLIB_INVALID_QNAME_RESPONSE invalid name or class in response to query for <%1>
-A debug message, the response to the specified query from an upstream
-nameserver (as identified by the ID of the response) contained a name
-in the question section that did not match that of the query. A SERVFAIL
-will be returned to the system making the original query.
-
-% RESLIB_INVALID_TYPE_RESPONSE invalid name or class in response to query for <%1>
-A debug message, the response to the specified query from an upstream
-nameserver (as identified by the ID of the response) contained an
-invalid type field. A SERVFAIL will be returned to the system making
-the original query.
-
-% RESLIB_LONG_CHAIN CNAME received in response to query for <%1>: CNAME chain length exceeded
-A debug message recording that a CNAME response has been received to an upstream
-query for the specified question (Previous debug messages will have indicated
-the server to which the question was sent).  However, receipt of this CNAME
-has meant that the resolver has exceeded the CNAME chain limit (a CNAME chain
-is where on CNAME points to another) and so an error is being returned.
-
-% RESLIB_MULTIPLE_CLASS_RESPONSE response to query for <%1> contained multiple RRsets with different classes
-A debug message reporting that the response to an upstream query for
-the specified name contained multiple RRsets in the answer and not all
-were of the same class.  This is a violation of the standard and so a
-SERVFAIL will be returned.
-
-% RESLIB_NOTSINGLE_RESPONSE response to query for <%1> was not a response
-A debug message, the response to the specified query from an upstream
-nameserver was a CNAME that had multiple RRs in the RRset.  This is
-an invalid response according to the standards so a SERVFAIL will be
-returned to the system making the original query.
-
-% RESLIB_NOT_ONE_QNAME_RESPONSE not one question in response to query for <%1>
-A debug message, the response to the specified query from an upstream
-nameserver (as identified by the ID of the response) did not contain
-one name in the question section as required by the standard. A SERVFAIL
-will be returned to the system making the original query.
-
-% RESLIB_NOT_RESPONSE response to query for <%1> was not a response
-A debug message, the response to the specified query from an upstream
-nameserver (as identified by the ID of the response) did not have the QR
-bit set (thus indicating that the packet was a query, not a response).
-A SERVFAIL will be returned to the system making the original query.
-
-% RESLIB_NO_NS_RRSET no NS RRSet in referral response received to query for <%1>
-A debug message, this indicates that a response was received for the specified
-query and was categorized as a referral.  However, the received message did
-not contain any NS RRsets.  This may indicate a programming error in the
-response classification code.
-
-% RESLIB_NSAS_LOOKUP looking up nameserver for zone %1 in the NSAS
-A debug message, the RunningQuery object is querying the NSAS for the
-nameservers for the specified zone.
-
-% RESLIB_NXDOM_NXRR NXDOMAIN/NXRRSET received in response to query for <%1>
-A debug message recording that either a NXDOMAIN or an NXRRSET response has
-been received to an upstream query for the specified question.  Previous debug
-messages will have indicated the server to which the question was sent.
-
-% RESLIB_OPCODE_RESPONSE response to query for <%1> did not have query opcode
-A debug message, the response to the specified query from an upstream
-nameserver was a response that did not have the opcode set to that of
-a query.  According to the standards, this is an invalid response to
-the query that was made, so a SERVFAIL will be returned to the system
-making the original query.
-
-% RESLIB_PROTOCOL protocol error in answer for %1:  %3
-A debug message indicating that a protocol error was received.  As there
-are no retries left, an error will be reported.
-
-% RESLIB_PROTOCOL_RETRY protocol error in answer for %1: %2 (retries left: %3)
-A debug message indicating that a protocol error was received and that
-the resolver is repeating the query to the same nameserver.  After this
-repeated query, there will be the indicated number of retries left.
-
-% RESLIB_RCODE_RETURNED response to query for <%1> returns RCODE of %2
-A debug message, the response to the specified query indicated an error
-that is not covered by a specific code path.  A SERVFAIL will be returned.
-
-% RESLIB_RECQ_CACHE_FIND found <%1> in the cache (resolve() instance %2)
-This is a debug message and indicates that a RecursiveQuery object found
-the specified <name, class, type> tuple in the cache.  The instance number
-at the end of the message indicates which of the two resolve() methods has
-been called.
-
-% RESLIB_RECQ_CACHE_NO_FIND did not find <%1> in the cache, starting RunningQuery (resolve() instance %2)
-This is a debug message and indicates that the look in the cache made by the
-RecursiveQuery::resolve() method did not find an answer, so a new RunningQuery
-object has been created to resolve the question.  The instance number at
-the end of the message indicates which of the two resolve() methods has
-been called.
-
-% RESLIB_REFERRAL referral received in response to query for <%1>
-A debug message recording that a referral response has been received to an
-upstream query for the specified question.  Previous debug messages will
-have indicated the server to which the question was sent.
-
-% RESLIB_REFER_ZONE referred to zone %1
-A debug message indicating that the last referral message was to the specified
-zone.
-
-% RESLIB_RESOLVE asked to resolve <%1> (resolve() instance %2)
-A debug message, the RecursiveQuery::resolve method has been called to resolve
-the specified <name, class, type> tuple.  The first action will be to lookup
-the specified tuple in the cache.  The instance number at the end of the
-message indicates which of the two resolve() methods has been called.
-
-% RESLIB_RRSET_FOUND found single RRset in the cache when querying for <%1> (resolve() instance %2)
-A debug message, indicating that when RecursiveQuery::resolve queried the
-cache, a single RRset was found which was put in the answer.  The instance
-number at the end of the message indicates which of the two resolve()
-methods has been called.
-
-% RESLIB_RTT round-trip time of last query calculated as %1 ms
-A debug message giving the round-trip time of the last query and response.
-
-% RESLIB_RUNQ_CACHE_FIND found <%1> in the cache
-This is a debug message and indicates that a RunningQuery object found
-the specified <name, class, type> tuple in the cache.
-
-% RESLIB_RUNQ_CACHE_LOOKUP looking up <%1> in the cache
-This is a debug message and indicates that a RunningQuery object has made
-a call to its doLookup() method to look up the specified <name, class, type>
-tuple, the first action of which will be to examine the cache.
-
-% RESLIB_RUNQ_FAIL failure callback - nameservers are unreachable
-A debug message indicating that a RunningQuery's failure callback has been
-called because all nameservers for the zone in question are unreachable.
-
-% RESLIB_RUNQ_SUCCESS success callback - sending query to %1
-A debug message indicating that a RunningQuery's success callback has been
-called because a nameserver has been found, and that a query is being sent
-to the specified nameserver.
-
-% RESLIB_TCP_TRUNCATED TCP response to query for %1 was truncated
-This is a debug message logged when a response to the specified  query to an
-upstream nameserver returned a response with the TC (truncation) bit set.  This
-is treated as an error by the code.
-
-% RESLIB_TEST_SERVER setting test server to %1(%2)
-This is a warning message only generated in unit tests.  It indicates
-that all upstream queries from the resolver are being routed to the
-specified server, regardless of the address of the nameserver to which
-the query would normally be routed.  If seen during normal operation,
-please submit a bug report.
-
-% RESLIB_TEST_UPSTREAM sending upstream query for <%1> to test server at %2
-This is a debug message and should only be seen in unit tests.  A query for
-the specified <name, class, type> tuple is being sent to a test nameserver
-whose address is given in the message.
-
-% RESLIB_TIMEOUT query <%1> to %2 timed out
-A debug message indicating that the specified upstream query has timed out and
-there are no retries left.
-
-% RESLIB_TIMEOUT_RETRY query <%1> to %2 timed out, re-trying (retries left: %3)
-A debug message indicating that the specified query has timed out and that
-the resolver is repeating the query to the same nameserver.  After this
-repeated query, there will be the indicated number of retries left.
-
-% RESLIB_TRUNCATED response to query for <%1> was truncated, re-querying over TCP
-A debug message, this indicates that the response to the specified query was
-truncated and that the resolver will be re-querying over TCP.  There are
-various reasons why responses may be truncated, so this message is normal and
-gives no cause for concern.
-
-% RESLIB_UPSTREAM sending upstream query for <%1> to %2
-A debug message indicating that a query for the specified <name, class, type>
-tuple is being sent to a nameserver whose address is given in the message.

+ 0 - 36
src/lib/resolve/resolver_callback.cc

@@ -1,36 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <resolve/resolver_callback.h>
-
-namespace isc {
-namespace resolve {
-
-void
-ResolverCallbackServer::success(const isc::dns::MessagePtr response)
-{
-    // ignore our response here
-    (void)response;
-    
-    server_->resume(true);
-}
-
-void
-ResolverCallbackServer::failure()
-{
-    server_->resume(false);
-}
-
-} // namespace resolve
-} // namespace isc

+ 0 - 50
src/lib/resolve/resolver_callback.h

@@ -1,50 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef ISC_RESOLVER_CALLBACK_H
-#define ISC_RESOLVER_CALLBACK_H 1
-
-#include <asiodns/dns_server.h>
-#include <dns/message.h>
-
-#include <resolve/resolver_interface.h>
-
-namespace isc {
-namespace resolve {
-
-/// \short Standard Callback for sendQuery for DNSServer instances
-///
-/// This is a standard ResolverInterface::Callback implementation
-/// that is used by Resolver; when RunningQuery finishes and has either
-/// some data or an error, DNSServer::resume() will be called.
-///
-/// This class will ignore the response MessagePtr in the callback,
-/// as the server itself should also have a reference.
-class ResolverCallbackServer : public ResolverInterface::Callback {
-public:
-    ResolverCallbackServer(asiodns::DNSServer* server) :
-        server_(server->clone()) {}
-    ~ResolverCallbackServer() { delete server_; };
-    
-    void success(const isc::dns::MessagePtr response);
-    void failure();
-
-private:
-    asiodns::DNSServer* server_;
-};
-
-} //namespace resolve
-} //namespace isc
-
-#endif // ISC_RESOLVER_CALLBACK_H_

+ 0 - 98
src/lib/resolve/resolver_interface.h

@@ -1,98 +0,0 @@
-// 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.
-
-#ifndef RESOLVER_INTERFACE_H
-#define RESOLVER_INTERFACE_H
-
-#include <dns/message.h>
-
-///
-/// \file resolver_interface.h
-/// \short Interface to resolver.
-///
-/// This file contains an interface for the resolver. By subclassing
-/// this abstract interface, other parts of the system can ask the
-/// resolver to do some resolving too.
-///
-/// This is done by creating a subclass of ResolverInterface::Callback,
-/// which defines what to do with the result, and then calling resolve()
-/// on the ResolverInterface implementation.
-///
-/// One default Callback subclass is provided right now, in
-/// resolver_callback.[h|cc], which calls resumse() on a given DNSServer
-///
-
-namespace isc {
-namespace resolve {
-
-///
-/// \short Abstract interface to the resolver.
-///
-/// Abstract interface to the resolver. The NameserverAddressStore uses this
-/// to ask for addresses. It is here because resolver does not yet exist.
-///
-/// It is abstract to allow tests pass dummy resolvers.
-///
-class ResolverInterface {
-    public:
-        /// \short An abstract callback for when the resolver is done.
-        ///
-        /// You can pass an instance of a subclass of this (as a
-        /// CallbackPtr) to RecursiveQuery::sendQuery(), and when it
-        /// is done, it will either call success() if there is an
-        /// answer MessagePtr, or failure(), if the resolver was not
-        /// able to find anything.
-        ///
-        /// Note that a result Message does not necessarily contain
-        /// the actual answer (it could be a noerror/nodata response).
-        class Callback {
-            public:
-                /// \short Some data arrived.
-                virtual void success(const isc::dns::MessagePtr response) = 0;
-                
-                ///
-                ///\short No data available.
-                ///
-                ///\todo Provide error reason (result of the
-                ///      classification call, for instance? We'd also
-                ///      need some way to say 'everything times out')
-                ///
-                virtual void failure() = 0;
-
-                /// \short Virtual destructor, so descendants are cleaned up
-                virtual ~Callback() {};
-        };
-
-        typedef boost::shared_ptr<Callback> CallbackPtr;
-
-        ///
-        ///\short Ask a question.
-        ///
-        /// Asks the resolver a question. Once the answer is ready
-        /// the callback is called.
-        ///
-        /// \param question What to ask. The resolver will decide who.
-        /// \param callback What should happen when the answer is ready.
-        ///
-        virtual void resolve(const isc::dns::QuestionPtr& question,
-            const CallbackPtr& callback) = 0;
-
-        /// \short Virtual destructor, so descendants are properly cleaned up
-        virtual ~ ResolverInterface() {}
-};
-
-} // namespace nsas
-} // namespace isc
-
-#endif //RESOLVER_INTERFACE_H

+ 0 - 279
src/lib/resolve/response_classifier.cc

@@ -1,279 +0,0 @@
-// Copyright (C) 2011  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 <cstddef>
-#include <vector>
-
-#include <resolve/response_classifier.h>
-#include <dns/name.h>
-#include <dns/opcode.h>
-#include <dns/rcode.h>
-#include <dns/rrset.h>
-
-using namespace isc::dns;
-using namespace std;
-
-namespace isc {
-namespace resolve {
-
-// Classify the response in the "message" object.
-
-ResponseClassifier::Category ResponseClassifier::classify(
-    const Question& question, const Message& message, 
-    Name& cname_target, unsigned int& cname_count, bool tcignore
-    )
-{
-    // Check header bits
-    if (!message.getHeaderFlag(Message::HEADERFLAG_QR)) {
-        return (NOTRESPONSE);   // Query-response bit not set in the response
-    }
-
-    // We only recognise responses to queries here
-    if (message.getOpcode() != Opcode::QUERY()) {
-        return (OPCODE);
-    }
-
-    // Apparently have a response.  There must be a single question in it...
-    const vector<QuestionPtr> msgquestion(message.beginQuestion(),
-            message.endQuestion());
-    if (msgquestion.size() != 1) {
-        return (NOTONEQUEST); // Not one question in response question section
-    }
-
-    // ... and the question should be equal to the question given.
-    // XXX: This means that "question" may not be the question sent by the
-    // client.  In the case of a CNAME response, the qname of subsequent
-    // questions needs to be altered.
-    if (question != *(msgquestion[0])) {
-        return (MISMATQUEST);
-    }
-
-    // Check for Rcode-related errors.
-    const Rcode& rcode = message.getRcode();
-    if (rcode != Rcode::NOERROR()) {
-        if (rcode == Rcode::NXDOMAIN()) {
-
-            // No such domain.  According to RFC2308, the domain referred to by
-            // the QNAME does not exist, although there may be a CNAME in the
-            // answer section and there may be an SOA and/or NS RRs in the
-            // authority section (ignoring any DNSSEC RRs for now).
-            //
-            // Note the "may".  There may not be anything.  Also, note that if
-            // there is a CNAME in the answer section, the authoritative server
-            // has verified that the name given in the CNAME's RDATA field does
-            // not exist. And that if a CNAME is returned in the answer, then
-            // the QNAME of the RRs in the authority section will refer to the
-            // authority for the CNAME's RDATA and not to the original question.
-            //
-            // Without doing further classification, it is sufficient to say
-            // that if an NXDOMAIN is received, there was no translation of the
-            // QNAME available.
-            return (NXDOMAIN);  // Received NXDOMAIN from parent.
-
-        } else {
-
-            // Not NXDOMAIN but not NOERROR either.  Must be an RCODE-related
-            // error.
-            return (RCODE);
-        }
-    }
-
-    // All seems OK and we can start looking at the content.  However, one
-    // more header check remains - was the response truncated?  If so, we'll
-    // probably want to re-query over TCP.  However, in some circumstances we
-    // might want to go with what we have.  So give the caller the option of
-    // ignoring the TC bit.
-    if (message.getHeaderFlag(Message::HEADERFLAG_TC) && (!tcignore)) {
-        return (TRUNCATED);
-    }
-
-    // By the time we get here, we're assured that the packet format is correct.
-    // We now need to decide as to whether it is an answer, a CNAME, or a
-    // referral.  For this, we need to inspect the contents of the answer
-    // and authority sections.
-    const vector<RRsetPtr> answer(
-            message.beginSection(Message::SECTION_ANSWER),
-            message.endSection(Message::SECTION_ANSWER)
-            );
-    const vector<RRsetPtr> authority(
-            message.beginSection(Message::SECTION_AUTHORITY),
-            message.endSection(Message::SECTION_AUTHORITY)
-            );
-
-    // If there is nothing in the answer section, it is a referral - unless
-    // there is no NS in the authority section
-    if (answer.empty()) {
-        if (authority.empty()) {
-            return (EMPTY);
-        }
-        for (vector<RRsetPtr>::size_type i = 0; i < authority.size(); ++i) {
-            if (authority[i]->getType() == RRType::NS()) {
-                return (REFERRAL);
-            }
-        }
-        return (NXRRSET);
-    }
-
-    // Look at two cases - one RRset in the answer and multiple RRsets in
-    // the answer.
-    if (answer.size() == 1) {
-
-        // Does the name and class of the answer match that of the question?
-        if ((answer[0]->getName() == question.getName()) &&
-            (answer[0]->getClass() == question.getClass())) {
-
-            // It does.  How about the type of the response?  The response
-            // is an answer if the type matches that of the question, or if the
-            // question was for type ANY.  It is a CNAME reply if the answer
-            // type is CNAME.  And it is an error for anything else.
-            if ((answer[0]->getType() == question.getType()) ||
-                (question.getType() == RRType::ANY())) {
-                return (ANSWER);
-            } else if (answer[0]->getType() == RRType::CNAME()) {
-                RdataIteratorPtr it = answer[0]->getRdataIterator();
-                cname_target = Name(it->getCurrent().toText());
-                ++cname_count;
-                return (CNAME);
-            } else {
-                return (INVTYPE);
-            }
-        }
-        else {
-
-            // Either the name and/or class of the reply don't match that of
-            // the question.
-            return (INVNAMCLASS);
-        }
-    }
-
-    // There are multiple RRsets in the answer. They should all have the same
-    // QCLASS, else there is some error in the response.
-    for (vector<RRsetPtr>::size_type i = 1; i < answer.size(); ++i) {
-        if (answer[0]->getClass() != answer[i]->getClass()) {
-            return (MULTICLASS);
-        }
-    }
-
-    // If the request type was ANY and they all have the same QNAME, we have
-    // an answer.  But if they don't have the same QNAME, we must have an error;
-    // the only way we could get different QNAMES in an answer is if one were a
-    // CNAME - in which case there should no other record types at that QNAME.
-    if (question.getType() == RRType::ANY()) {
-        bool all_same = true;
-        for (vector<RRsetPtr>::size_type i = 1; (i < answer.size()) && all_same;
-             ++i) {
-            all_same = (answer[0]->getName() == answer[i]->getName());
-        }
-        if (all_same) {
-            return (ANSWER);
-        } else {
-            return (EXTRADATA);
-        }
-    }
-
-    // Multiple RRs in the answer, and not all the same QNAME.  This
-    // is either an answer, a CNAME (in either case, there could be multiple
-    // CNAMEs in the chain) or an error.
-    //
-    // So we need to follow the CNAME chain to resolve this.  For this to work:
-    //
-    // a) There must be one RR that matches the name, class and type of
-    //    the question, and this is a CNAME.
-    // b) The CNAME chain is followed until the end of the chain does not
-    //    exist (answer is a CNAME) or it is not of type CNAME (ANSWER).
-    //
-    // In the latter case, if there are additional RRs, it must be an error.
-
-    vector<RRsetPtr> ansrrset(answer);
-    vector<int> present(ansrrset.size(), 1);
-    return cnameChase(question.getName(), question.getType(),
-        cname_target, cname_count,
-        ansrrset, present, ansrrset.size());
-}
-
-// Search the CNAME chain.
-ResponseClassifier::Category ResponseClassifier::cnameChase(
-    const Name& qname, const RRType& qtype,
-    Name& cname_target, unsigned int& cname_count,
-    vector<RRsetPtr>& ansrrset, vector<int>& present, size_t size)
-{
-    // Search through the vector of RRset pointers until we find one with the
-    // right QNAME.
-    for (vector<RRsetPtr>::size_type i = 0; i < ansrrset.size(); ++i) {
-        if (present[i]) {
-
-            // This entry has not been logically removed, so look at it.
-            if (ansrrset[i]->getName() == qname) {
-
-                // QNAME match.  If this RRset is a CNAME, remove it from
-                // further consideration.  If nothing is left, the end of the
-                // chain is a CNAME so this is a CNAME.  Otherwise replace
-                // the name with the RDATA of the CNAME and call ourself
-                // recursively.
-                if (ansrrset[i]->getType() == RRType::CNAME()) {
-
-                    // Don't consider it in the next iteration (although we
-                    // can still access it for now).
-                    present[i] = 0;
-                    --size;
-                    if (size == 0) {
-                        RdataIteratorPtr it = ansrrset[i]->getRdataIterator();
-                        cname_target = Name(it->getCurrent().toText());
-                        return (CNAME);
-                    } else {
-                        if (ansrrset[i]->getRdataCount() != 1) {
-
-                            // Multiple RDATA for a CNAME?  This is invalid.
-
-                            return (NOTSINGLE);
-                        }
-                        RdataIteratorPtr it = ansrrset[i]->getRdataIterator();
-                        Name newname(it->getCurrent().toText());
-
-                        // Increase CNAME count, and continue
-                        return cnameChase(newname, qtype, cname_target,
-                            ++cname_count, ansrrset, present, size);
-                    }
-
-                } else {
-
-                    // We've got here because the element is not a CNAME.  If
-                    // this is the last element and the type is the one we are
-                    // after, we've found the answer, or it is an error.  If
-                    // there is more than one RRset left in the list we are
-                    // searching, we have extra data in the answer.
-                    if (ansrrset[i]->getType() == qtype) {
-                        if (size == 1) {
-                            return (ANSWERCNAME);
-                        } else {
-                            return (EXTRADATA);
-                        }
-                    }
-                    return (INVTYPE);
-                }
-            }
-        }
-    }
-
-    // We get here if we've dropped off the end of the list without finding the
-    // QNAME we are looking for.  This means that the CNAME chain has ended
-    // but there are additional RRsets in the data.
-
-    return (EXTRADATA);
-}
-
-} // namespace resolve
-} // namespace isc

+ 0 - 157
src/lib/resolve/response_classifier.h

@@ -1,157 +0,0 @@
-// Copyright (C) 2011  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 RESPONSE_CLASSIFIER_H
-#define RESPONSE_CLASSIFIER_H
-
-#include <cstddef>
-
-#include <dns/question.h>
-#include <dns/message.h>
-#include <dns/question.h>
-
-#define RESOLVER_MAX_CNAME_CHAIN    16
-
-namespace isc {
-namespace resolve {
-
-/// \brief Classify Server Response
-///
-/// This class is used in the recursive server.  It is passed an answer received
-/// from an upstream server and categorises it.
-///
-/// TODO: The code here does not take into account any EDNS0 fields.
-
-class ResponseClassifier {
-public:
-
-    /// \brief Category of Answer
-    ///
-    /// In the valid answers, not the distinction between REFERRAL and CNAME.
-    /// A REFERRAL answer means that the answer section of the message is
-    /// empty, but there is something in the authority section.  A CNAME means
-    /// that the answer section contains one or more CNAMES in a chain that
-    /// do not end with a non-CNAME RRset.
-    enum Category {
-
-        // Codes indicating that a message is valid.
-
-        ANSWER,             ///< Response contains the answer
-        ANSWERCNAME,        ///< Response was a CNAME chain ending in an answer
-        CNAME,              ///< Response was a CNAME
-        NXDOMAIN,           ///< Response was an NXDOMAIN
-        NXRRSET,            ///< Response was name exists, but type does not
-        REFERRAL,           ///< Response contains a referral
-
-        // Codes indicating that a message is invalid.  Note that the error()
-        // method relies on these appearing after the "message valid" codes.
-
-        EMPTY,              ///< No answer or authority sections
-        EXTRADATA,          ///< Answer section contains more RRsets than needed
-        INVNAMCLASS,        ///< Invalid name or class in answer
-        INVTYPE,            ///< Name/class of answer correct, type is wrong
-        MISMATQUEST,        ///< Response question section != question
-        MULTICLASS,         ///< Multiple classes in multi-RR answer
-        NOTONEQUEST,        ///< Not one question in response question section
-        NOTRESPONSE,        ///< Response has the Query/Response bit clear
-        NOTSINGLE,          ///< CNAME has multiple RDATA elements.
-        OPCODE,             ///< Opcode field does not indicate a query
-        RCODE,              ///< RCODE indicated an error
-        TRUNCATED           ///< Response was truncated
-    };
-
-    /// \brief Check Error
-    ///
-    /// An inline routine to quickly classify whether the return category is
-    /// an error or not.  This makes use of internal knowledge of the order of
-    /// codes in the Category enum.
-    ///
-    /// \param code Return category from classify()
-    ///
-    /// \return true if the category is an error, false if not.
-    static bool error(Category code) {
-        return (code > REFERRAL);
-    }
-
-    /// \brief Classify
-    ///
-    /// Classify the response in the "message" object.
-    ///
-    /// \param question Question that was sent to the server
-    /// \param message Pointer to the associated response from the server.
-    /// \param cname_target If the message contains an (unfinished) CNAME
-    /// chain, this Name will be replaced by the target of the last CNAME
-    /// in the chain
-    /// \param cname_count This unsigned int will be incremented with
-    /// the number of CNAMEs followed
-    /// \param tcignore If set, the TC bit in a response packet is
-    /// ignored.  Otherwise the error code TRUNCATED will be returned.  The
-    /// only time this is likely to be used is in development where we are not
-    /// going to fail over to TCP and will want to use what is returned, even
-    /// if some of the response was lost.
-    static Category classify(const isc::dns::Question& question,
-            const isc::dns::Message& message, 
-            isc::dns::Name& cname_target, unsigned int& cname_count,
-            bool tcignore = false);
-
-private:
-    /// \brief Follow CNAMEs
-    ///
-    /// Given a QNAME and an answer section that contains CNAMEs, assume that
-    /// they form a CNAME chain and search through them.  Possible outcomes
-    /// are:
-    ///
-    /// a) All CNAMES and they form a chain.  The result is a referral.
-    /// b) All but one are CNAMES and they form a chain.  The other is pointed
-    ///    to by the last element of the chain and is the correct QTYPE.  The
-    ///    result is an answer.
-    /// c) Having followed the CNAME chain as far as we can, there is one
-    ///    remaining RRset that is of the wrong type, or there are multiple
-    ///    RRsets remaining.  return the EXTRADATA code.
-    ///
-    /// \param qname Question name we are searching for
-    /// \param qtype Question type we are search for.  (This is assumed not
-    /// to be "ANY".)
-    /// \param ansrrset Vector of RRsetPtr pointing to the RRsets we are
-    /// considering.
-    /// \param present Array of "int" the same size of ansrrset, with each
-    /// element set to "1" to allow the corresponding element of ansrrset to
-    /// be checked, and "0" to skip it.  This might be premature optimisation,
-    /// but the algorithm would otherwise involve duplicating the RRset
-    /// vector then removing elements from random positions one by one.  As
-    /// each removal involves the destruction of an "xxxPtr" element (which
-    /// presently is implemented by boost::shared_ptr), the overhad of memory
-    /// management seemed high.  This solution imposes some additional loop
-    /// cycles, but that should be minimal compared with the overhead of the
-    /// memory management.
-    /// \param cname_target If the message contains an (unfinished) CNAME
-    /// chain, this Name will be replaced by the target of the last CNAME
-    /// in the chain
-    /// \param cname_count This unsigned int will be incremented with
-    /// the number of CNAMEs followed
-    /// \param size Number of elements to check.  See description of \c present
-    /// for details.
-    static Category cnameChase(const isc::dns::Name& qname,
-        const isc::dns::RRType& qtype,
-        isc::dns::Name& cname_target, unsigned int& cname_count,
-        std::vector<isc::dns::RRsetPtr>& ansrrset, std::vector<int>& present,
-        size_t size);
-};
-
-} // namespace resolve
-} // namespace isc
-
-#endif // RESPONSE_CLASSIFIER_H

+ 0 - 1
src/lib/resolve/tests/.gitignore

@@ -1 +0,0 @@
-/run_unittests

+ 0 - 45
src/lib/resolve/tests/Makefile.am

@@ -1,45 +0,0 @@
-AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
-AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
-
-if USE_STATIC_LINK
-AM_LDFLAGS = -static
-endif
-
-CLEANFILES = *.gcno *.gcda
-
-TESTS_ENVIRONMENT = \
-        $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
-
-TESTS =
-if HAVE_GTEST
-TESTS += run_unittests
-
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
-run_unittests_LDFLAGS  = $(AM_LDFLAGS)  $(GTEST_LDFLAGS)
-
-run_unittests_SOURCES  = run_unittests.cc
-run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.h
-run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc
-run_unittests_SOURCES += resolve_unittest.cc
-run_unittests_SOURCES += resolver_callback_unittest.cc
-run_unittests_SOURCES += response_classifier_unittest.cc
-run_unittests_SOURCES += recursive_query_unittest.cc
-run_unittests_SOURCES += recursive_query_unittest_2.cc
-run_unittests_SOURCES += recursive_query_unittest_3.cc
-
-run_unittests_LDADD = $(GTEST_LDADD)
-run_unittests_LDADD +=  $(top_builddir)/src/lib/nsas/libb10-nsas.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/cache/libb10-cache.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/asiodns/libb10-asiodns.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/resolve/libb10-resolve.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/dns/libb10-dns++.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/util/libb10-util.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/log/libb10-log.la
-run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
-run_unittests_LDADD +=  $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
-
-endif
-
-noinst_PROGRAMS = $(TESTS)

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 1006
src/lib/resolve/tests/recursive_query_unittest.cc


+ 0 - 728
src/lib/resolve/tests/recursive_query_unittest_2.cc

@@ -1,728 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <algorithm>
-#include <cstdlib>
-#include <iomanip>
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include <gtest/gtest.h>
-#include <boost/bind.hpp>
-
-#include <asio.hpp>
-
-#include <util/buffer.h>
-#include <util/io_utilities.h>
-
-#include <dns/question.h>
-#include <dns/message.h>
-#include <dns/messagerenderer.h>
-#include <dns/opcode.h>
-#include <dns/name.h>
-#include <dns/rcode.h>
-#include <dns/rrtype.h>
-#include <dns/rrset.h>
-#include <dns/rrttl.h>
-#include <dns/rdata.h>
-
-#include <util/io_utilities.h>
-#include <asiodns/dns_service.h>
-#include <asiodns/io_fetch.h>
-#include <asiolink/io_address.h>
-#include <asiolink/io_endpoint.h>
-#include <asiolink/io_service.h>
-#include <resolve/recursive_query.h>
-#include <resolve/resolver_interface.h>
-
-using namespace asio;
-using namespace asio::ip;
-using namespace isc::asiolink;
-using namespace isc::dns;
-using namespace isc::dns::rdata;
-using namespace isc::util;
-using namespace isc::resolve;
-using namespace std;
-
-/// RecursiveQuery Test - 2
-///
-/// The second part of the RecursiveQuery unit tests, this attempts to get the
-/// RecursiveQuery object to follow a set of referrals for "www.example.org" to
-/// and to invoke TCP fallback on one of the queries.  In particular, we expect
-/// that the test will do the following in an attempt to resolve
-/// www.example.org:
-///
-/// - Send question over UDP to "root" - get referral to "org".
-/// - Send question over UDP to "org" - get referral to "example.org" with TC bit set.
-/// - Send question over TCP to "org" - get referral to "example.org".
-/// - Send question over UDP to "example.org" - get response for www.example.org.
-///
-/// (The order of queries is set in this way in order to also test that after a
-/// failover to TCP, queries revert to UDP).
-///
-/// By using the "test_server_" element of RecursiveQuery, all queries are
-/// directed to one or other of the "servers" in the RecursiveQueryTest2 class,
-/// regardless of the glue returned in referrals.
-
-namespace {
-const char* const TEST_ADDRESS = "127.0.0.1"; ///< Servers are on this address
-const uint16_t TEST_PORT = 5301;              ///< ... and this port
-const size_t BUFFER_SIZE = 1024;              ///< For all buffers
-const char* const WWW_EXAMPLE_ORG = "192.0.2.254";
-                                              ///< Address of www.example.org
-} //end anonymous namespace
-
-namespace isc {
-namespace asiodns {
-
-// As the test is fairly long and complex, debugging "print" statements have
-// been left in although they are disabled.  Set the following to "true" to
-// enable them.
-const bool DEBUG_PRINT = false;
-
-class MockResolver : public isc::resolve::ResolverInterface {
-public:
-    virtual void resolve(const QuestionPtr& question,
-                 const ResolverInterface::CallbackPtr& callback) {
-    }
-
-    virtual ~MockResolver() {}
-};
-
-
-
-/// \brief Test fixture for the RecursiveQuery Test
-class RecursiveQueryTest2 : public virtual ::testing::Test
-{
-public:
-
-    /// \brief Status of query
-    ///
-    /// Set before the query and then by each "server" when responding.
-    enum QueryStatus {
-        NONE = 0,                   ///< Default
-        UDP_ROOT = 1,               ///< Query root server over UDP
-        UDP_ORG = 2,                ///< Query ORG server over UDP
-        TCP_ORG = 3,                ///< Query ORG server over TCP
-        UDP_EXAMPLE_ORG_BAD = 4,    ///< Query EXAMPLE.ORG server over UDP
-                                    ///< (return malformed packet)
-        UDP_EXAMPLE_ORG = 5,        ///< Query EXAMPLE.ORG server over UDP
-        COMPLETE = 6                ///< Query is complete
-    };
-
-    // Common stuff
-    bool            debug_;                     ///< Set true for debug print
-    IOService       service_;                   ///< Service to run everything
-    DNSService      dns_service_;               ///< Resolver is part of "server"
-    QuestionPtr     question_;                  ///< What to ask
-    QueryStatus     last_;                      ///< What was the last state
-    QueryStatus     expected_;                  ///< Expected next state
-    OutputBufferPtr question_buffer_;           ///< Question we expect to receive
-    boost::shared_ptr<MockResolver> resolver_;  ///< Mock resolver
-    isc::nsas::NameserverAddressStore* nsas_;   ///< Nameserver address store
-    isc::cache::ResolverCache cache_;           ///< Resolver cache
-
-    // Data for TCP Server
-    size_t          tcp_cumulative_;            ///< Cumulative TCP data received
-    tcp::endpoint   tcp_endpoint_;              ///< Endpoint for TCP receives
-    size_t          tcp_length_;                ///< Expected length value
-    uint8_t         tcp_receive_buffer_[BUFFER_SIZE];   ///< Receive buffer for TCP I/O
-    OutputBufferPtr tcp_send_buffer_;           ///< Send buffer for TCP I/O
-    tcp::socket     tcp_socket_;                ///< Socket used by TCP server
-
-    /// Data for UDP
-    udp::endpoint   udp_remote_;                ///< Endpoint for UDP receives
-    size_t          udp_length_;                ///< Expected length value
-    uint8_t         udp_receive_buffer_[BUFFER_SIZE];   ///< Receive buffer for UDP I/O
-    OutputBufferPtr udp_send_buffer_;           ///< Send buffer for UDP I/O
-    udp::socket     udp_socket_;                ///< Socket used by UDP server
-
-    /// Some of the tests cause an 'active' running query to be created, but
-    /// don't complete the framework that makes that query delete itself.
-    /// This member can be used to store it so that it is deleted automatically
-    /// when the test is finished.
-    AbstractRunningQuery* running_query_;
-
-    /// \brief Constructor
-    RecursiveQueryTest2() :
-        debug_(DEBUG_PRINT),
-        service_(),
-        dns_service_(service_, NULL, NULL),
-        question_(new Question(Name("www.example.org"), RRClass::IN(), RRType::A())),
-        last_(NONE),
-        expected_(NONE),
-        question_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        resolver_(new MockResolver()),
-        nsas_(new isc::nsas::NameserverAddressStore(resolver_)),
-        tcp_cumulative_(0),
-        tcp_endpoint_(asio::ip::address::from_string(TEST_ADDRESS), TEST_PORT),
-        tcp_length_(0),
-        tcp_receive_buffer_(),
-        tcp_send_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        tcp_socket_(service_.get_io_service()),
-        udp_remote_(),
-        udp_length_(0),
-        udp_receive_buffer_(),
-        udp_send_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        udp_socket_(service_.get_io_service(), udp::v4()),
-        running_query_(NULL)
-    {}
-
-    ~RecursiveQueryTest2() {
-        // It would delete itself, but after the io_service_, which could
-        // segfailt in case there were unhandled requests
-        resolver_.reset();
-        // In a similar note, we wait until the resolver has been cleaned up
-        // until deleting and active test running_query_
-        delete running_query_;
-        delete nsas_;
-    }
-
-    /// \brief Set Common Message Bits
-    ///
-    /// Sets up the common bits of a response message returned by the handlers.
-    ///
-    /// \param msg Message buffer in RENDER mode.
-    /// \param qid QID to set the message to
-    void setCommonMessage(isc::dns::Message& msg, uint16_t qid = 0) {
-        msg.setQid(qid);
-        msg.setHeaderFlag(Message::HEADERFLAG_QR);
-        msg.setOpcode(Opcode::QUERY());
-        msg.setHeaderFlag(Message::HEADERFLAG_AA);
-        msg.setRcode(Rcode::NOERROR());
-        msg.addQuestion(*question_);
-    }
-
-    /// \brief Set Referral to "org"
-    ///
-    /// Sets up the passed-in message (expected to be in "RENDER" mode to
-    /// indicate a referral to fictitious .org nameservers.
-    ///
-    /// \param msg Message to update with referral information.
-    void setReferralOrg(isc::dns::Message& msg) {
-        if (debug_) {
-            cout << "setReferralOrg(): creating referral to .org nameservers" << endl;
-        }
-
-        // Do a referral to org.  We'll define all NS records as "in-zone"
-        // nameservers (and supply glue) to avoid the possibility of the
-        // resolver starting another recursive query to resolve the address of
-        // a nameserver.
-        RRsetPtr org_ns(new RRset(Name("org."), RRClass::IN(), RRType::NS(), RRTTL(300)));
-        org_ns->addRdata(createRdata(RRType::NS(), RRClass::IN(), "ns1.org."));
-        org_ns->addRdata(createRdata(RRType::NS(), RRClass::IN(), "ns2.org."));
-        msg.addRRset(Message::SECTION_AUTHORITY, org_ns);
-
-        RRsetPtr org_ns1(new RRset(Name("ns1.org."), RRClass::IN(), RRType::A(), RRTTL(300)));
-        org_ns1->addRdata(createRdata(RRType::A(), RRClass::IN(), "192.0.2.1"));
-        msg.addRRset(Message::SECTION_ADDITIONAL, org_ns1);
-
-        RRsetPtr org_ns2(new RRset(Name("ns2.org."), RRClass::IN(), RRType::A(), RRTTL(300)));
-        org_ns2->addRdata(createRdata(RRType::A(), RRClass::IN(), "192.0.2.2"));
-        msg.addRRset(Message::SECTION_ADDITIONAL, org_ns2);
-    }
-
-    /// \brief Set Referral to "example.org"
-    ///
-    /// Sets up the passed-in message (expected to be in "RENDER" mode to
-    /// indicate a referral to fictitious example.org nameservers.
-    ///
-    /// \param msg Message to update with referral information.
-    void setReferralExampleOrg(isc::dns::Message& msg) {
-        if (debug_) {
-            cout << "setReferralExampleOrg(): creating referral to example.org nameservers" << endl;
-        }
-
-        // Do a referral to example.org.  As before, we'll define all NS
-        // records as "in-zone" nameservers (and supply glue) to avoid the
-        // possibility of the resolver starting another recursive query to look
-        // up the address of the nameserver.
-        RRsetPtr example_org_ns(new RRset(Name("example.org."), RRClass::IN(), RRType::NS(), RRTTL(300)));
-        example_org_ns->addRdata(createRdata(RRType::NS(), RRClass::IN(), "ns1.example.org."));
-        example_org_ns->addRdata(createRdata(RRType::NS(), RRClass::IN(), "ns2.example.org."));
-        msg.addRRset(Message::SECTION_AUTHORITY, example_org_ns);
-
-        RRsetPtr example_org_ns1(new RRset(Name("ns1.example.org."), RRClass::IN(), RRType::A(), RRTTL(300)));
-        example_org_ns1->addRdata(createRdata(RRType::A(), RRClass::IN(), "192.0.2.11"));
-        msg.addRRset(Message::SECTION_ADDITIONAL, example_org_ns1);
-
-        RRsetPtr example_org_ns2(new RRset(Name("ns2.example.org."), RRClass::IN(), RRType::A(), RRTTL(300)));
-        example_org_ns2->addRdata(createRdata(RRType::A(), RRClass::IN(), "192.0.2.21"));
-        msg.addRRset(Message::SECTION_ADDITIONAL, example_org_ns2);
-    }
-
-    /// \brief Set Answer to "www.example.org"
-    ///
-    /// Sets up the passed-in message (expected to be in "RENDER" mode) to
-    /// indicate an authoritative answer to www.example.org.
-    ///
-    /// \param msg Message to update with referral information.
-    void setAnswerWwwExampleOrg(isc::dns::Message& msg) {
-        if (debug_) {
-            cout << "setAnswerWwwExampleOrg(): creating answer for www.example.org" << endl;
-        }
-
-        // Give a response for www.example.org.
-        RRsetPtr www_example_org_a(new RRset(Name("www.example.org."), RRClass::IN(), RRType::A(), RRTTL(300)));
-        www_example_org_a->addRdata(createRdata(RRType::A(), RRClass::IN(), WWW_EXAMPLE_ORG));
-        msg.addRRset(Message::SECTION_ANSWER, www_example_org_a);
-
-        // ... and add the Authority and Additional sections. (These are the
-        // same as in the referral to example.org from the .org nameserver.)
-        setReferralExampleOrg(msg);
-    }
-
-    /// \brief UDP Receive Handler
-    ///
-    /// This is invoked when a message is received over UDP from the
-    /// RecursiveQuery object under test.  It formats an answer and sends it
-    /// asynchronously, with the UdpSendHandler method being specified as the
-    /// completion handler.
-    ///
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param length Amount of data received.
-    void udpReceiveHandler(asio::error_code ec = asio::error_code(),
-                           size_t length = 0)
-    {
-        if (debug_) {
-            cout << "udpReceiveHandler(): error = " << ec.value() <<
-                    ", length = " << length << ", last state = " << last_ <<
-                    ", expected state = " << expected_ << endl;
-        }
-
-        // Expected state should be one greater than the last state.
-        EXPECT_EQ(static_cast<int>(expected_), static_cast<int>(last_) + 1);
-        last_ = expected_;
-
-        // The QID in the incoming data is random so set it to 0 for the
-        // data comparison check. (It is set to 0 in the buffer containing
-        // the expected data.)
-        // And check that question we received is what was expected.
-        uint16_t qid = checkReceivedPacket(udp_receive_buffer_, length);
-
-        // The message returned depends on what state we are in.  Set up
-        // common stuff first: bits not mentioned are set to 0.
-        Message msg(Message::RENDER);
-        setCommonMessage(msg, qid);
-
-        // In the case of UDP_EXAMPLE_ORG_BAD, we shall mangle the
-        // response
-        bool mangle_response = false;
-
-        // Set up state-dependent bits:
-        switch (expected_) {
-        case UDP_ROOT:
-            // Return a referral to org.  We then expect to query the "org"
-            // nameservers over UDP next.
-            setReferralOrg(msg);
-            expected_ = UDP_ORG;
-            break;
-
-         case UDP_ORG:
-            // Return a referral to example.org.  We explicitly set the TC bit to
-            // force a repeat query to the .org nameservers over TCP.
-            setReferralExampleOrg(msg);
-            if (debug_) {
-                cout << "udpReceiveHandler(): setting TC bit" << endl;
-            }
-            msg.setHeaderFlag(Message::HEADERFLAG_TC);
-            expected_ = TCP_ORG;
-            break;
-
-         case UDP_EXAMPLE_ORG_BAD:
-            // Return the answer to the question.
-            setAnswerWwwExampleOrg(msg);
-            // Mangle the response to enfore another query
-            mangle_response = true;
-            expected_ = UDP_EXAMPLE_ORG;
-            break;
-
-         case UDP_EXAMPLE_ORG:
-            // Return the answer to the question.
-            setAnswerWwwExampleOrg(msg);
-            expected_ = COMPLETE;
-            break;
-
-         default:
-            FAIL() << "UdpReceiveHandler called with unknown state";
-        }
-
-        // Convert to wire format
-        udp_send_buffer_->clear();
-        MessageRenderer renderer;
-        renderer.setBuffer(udp_send_buffer_.get());
-        msg.toWire(renderer);
-
-        if (mangle_response) {
-            // mangle the packet a bit
-            // set additional to one more
-            udp_send_buffer_->writeUint8At(3, 11);
-        }
-
-        // Return a message back to the IOFetch object (after setting the
-        // expected length of data for the check in the send handler).
-        udp_length_ = udp_send_buffer_->getLength();
-        udp_socket_.async_send_to(asio::buffer(udp_send_buffer_->getData(),
-                                               udp_send_buffer_->getLength()),
-                                  udp_remote_,
-                                  boost::bind(&RecursiveQueryTest2::udpSendHandler,
-                                              this, _1, _2));
-    }
-
-    /// \brief UDP Send Handler
-    ///
-    /// Called when a send operation of the UDP server (i.e. a response
-    /// being sent to the RecursiveQuery) has completed, this re-issues
-    /// a read call.
-    ///
-    /// \param ec Completion error code of the send.
-    /// \param length Actual number of bytes sent.
-    void udpSendHandler(asio::error_code ec = asio::error_code(),
-                        size_t length = 0)
-    {
-        if (debug_) {
-            cout << "udpSendHandler(): error = " << ec.value() <<
-                    ", length = " << length << endl;
-        }
-
-        // Check send was OK
-        EXPECT_EQ(0, ec.value());
-        EXPECT_EQ(udp_length_, length);
-
-        // Reissue the receive call to await the next message.
-        udp_socket_.async_receive_from(
-            asio::buffer(udp_receive_buffer_, sizeof(udp_receive_buffer_)),
-            udp_remote_,
-            boost::bind(&RecursiveQueryTest2::udpReceiveHandler, this, _1, _2));
-    }
-
-    /// \brief Completion Handler for Accepting TCP Data
-    ///
-    /// Called when the remote system connects to the "TCP server".  It issues
-    /// an asynchronous read on the socket to read data.
-    ///
-    /// \param socket Socket on which data will be received
-    /// \param ec Boost error code, value should be zero.
-    void tcpAcceptHandler(asio::error_code ec = asio::error_code(),
-                          size_t length = 0)
-    {
-        if (debug_) {
-            cout << "tcpAcceptHandler(): error = " << ec.value() <<
-                    ", length = " << length << endl;
-        }
-
-        // Expect that the accept completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // Initiate a read on the socket, indicating that nothing has yet been
-        // received.
-        tcp_cumulative_ = 0;
-        tcp_socket_.async_receive(
-            asio::buffer(tcp_receive_buffer_, sizeof(tcp_receive_buffer_)),
-            boost::bind(&RecursiveQueryTest2::tcpReceiveHandler, this, _1, _2));
-    }
-
-    /// \brief Completion Handler for Receiving TCP Data
-    ///
-    /// Reads data from the RecursiveQuery object and loops, reissuing reads,
-    /// until all the message has been read.  It then returns an appropriate
-    /// response.
-    ///
-    /// \param socket Socket to use to send the answer
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param length Amount of data received.
-    void tcpReceiveHandler(asio::error_code ec = asio::error_code(),
-                           size_t length = 0)
-    {
-        if (debug_) {
-            cout << "tcpReceiveHandler(): error = " << ec.value() <<
-                    ", length = " << length <<
-                    ", cumulative = " << tcp_cumulative_ << endl;
-        }
-
-        // Expect that the receive completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // Have we received all the data?  We know this by checking if the two-
-        // byte length count in the message is equal to the data received.
-        tcp_cumulative_ += length;
-        bool complete = false;
-        if (tcp_cumulative_ > 2) {
-            uint16_t dns_length = readUint16(tcp_receive_buffer_,
-                                             sizeof(tcp_receive_buffer_));
-            complete = ((dns_length + 2) == tcp_cumulative_);
-        }
-
-        if (!complete) {
-            if (debug_) {
-                cout << "tcpReceiveHandler(): read not complete, " <<
-                        "issuing another read" << endl;
-            }
-
-            // Not complete yet, issue another read.
-            tcp_socket_.async_receive(
-                asio::buffer(tcp_receive_buffer_ + tcp_cumulative_,
-                             sizeof(tcp_receive_buffer_) - tcp_cumulative_),
-                boost::bind(&RecursiveQueryTest2::tcpReceiveHandler, this, _1, _2));
-            return;
-        }
-
-        // Have received a TCP message.  Expected state should be one greater
-        // than the last state.
-        EXPECT_EQ(static_cast<int>(expected_), static_cast<int>(last_) + 1);
-        last_ = expected_;
-
-        // Check that question we received is what was expected.  Note that we
-        // have to ignore the two-byte header in order to parse the message.
-        qid_t qid = checkReceivedPacket(tcp_receive_buffer_ + 2, length - 2);
-
-        // Return a message back.  This is a referral to example.org, which
-        // should result in another query over UDP.  Note the setting of the
-        // QID in the returned message with what was in the received message.
-        Message msg(Message::RENDER);
-        setCommonMessage(msg, qid);
-        setReferralExampleOrg(msg);
-
-        // Convert to wire format
-        // Use a temporary renderer for the dns wire data (we copy it
-        // to the 'real' buffer below)
-        MessageRenderer renderer;
-        msg.toWire(renderer);
-
-        // Expected next state (when checked) is the UDP query to example.org.
-        // Also, take this opportunity to clear the accumulated read count in
-        // readiness for the next read. (If any - at present, there is only
-        // one read in the test, although extensions to this test suite could
-        // change that.)
-        expected_ = UDP_EXAMPLE_ORG_BAD;
-        tcp_cumulative_ = 0;
-
-        // Unless we go through a callback loop we cannot simply use
-        // async_send() multiple times, so we cannot send the size first
-        // followed by the actual data. We copy them to a new buffer
-        // first
-        tcp_send_buffer_->clear();
-        tcp_send_buffer_->writeUint16(renderer.getLength());
-        tcp_send_buffer_->writeData(renderer.getData(), renderer.getLength());
-        tcp_socket_.async_send(asio::buffer(tcp_send_buffer_->getData(),
-                                            tcp_send_buffer_->getLength()),
-                               boost::bind(
-                                   &RecursiveQueryTest2::tcpSendHandler, this,
-                                   tcp_send_buffer_->getLength(), _1, _2));
-    }
-
-    /// \brief Completion Handler for Sending TCP data
-    ///
-    /// Called when the asynchronous send of data back to the RecursiveQuery
-    /// by the TCP "server" in this class has completed.  (This send has to
-    /// be asynchronous because control needs to return to the caller in order
-    /// for the IOService "run()" method to be called to run the handlers.)
-    ///
-    /// \param expected_length Number of bytes that were expected to have been sent.
-    /// \param ec Boost error code, value should be zero.
-    /// \param length Number of bytes sent.
-    void tcpSendHandler(size_t expected_length = 0,
-                        asio::error_code ec = asio::error_code(),
-                        size_t length = 0)
-    {
-        if (debug_) {
-            cout << "tcpSendHandler(): error = " << ec.value() <<
-                    ", length = " << length <<
-                    ", (expected length = " << expected_length << ")" << endl;
-        }
-        EXPECT_EQ(0, ec.value());       // Expect no error
-        EXPECT_EQ(expected_length, length);    // And that amount sent is as expected
-    }
-
-    /// \brief Check Received Packet
-    ///
-    /// Checks the packet received from the RecursiveQuery object to ensure
-    /// that the question is what is expected.
-    ///
-    /// \param data Start of data.  This is the start of the received buffer in
-    ///        the case of UDP data, and an offset into the buffer past the
-    ///        count field for TCP data.
-    /// \param length Length of data.
-    /// \return The QID of the message
-    qid_t checkReceivedPacket(uint8_t* data, size_t length) {
-
-        // Decode the received buffer.
-        InputBuffer buffer(data, length);
-        Message message(Message::PARSE);
-        message.fromWire(buffer);
-
-        // Check the packet.
-        EXPECT_FALSE(message.getHeaderFlag(Message::HEADERFLAG_QR));
-
-        Question question = **(message.beginQuestion());
-        EXPECT_TRUE(question == *question_);
-
-        return message.getQid();
-    }
-};
-
-/// \brief Resolver Callback Object
-///
-/// Holds the success and failure callback methods for the resolver
-class ResolverCallback : public isc::resolve::ResolverInterface::Callback {
-public:
-    /// \brief Constructor
-    ResolverCallback(IOService& service) :
-        service_(service), run_(false), status_(false), debug_(DEBUG_PRINT)
-    {}
-
-    /// \brief Destructor
-    virtual ~ResolverCallback()
-    {}
-
-    /// \brief Resolver Callback Success
-    ///
-    /// Called if the resolver detects that the call has succeeded.
-    ///
-    /// \param response Answer to the question.
-    virtual void success(const isc::dns::MessagePtr response) {
-        if (debug_) {
-            cout << "ResolverCallback::success(): answer received" << endl;
-            cout << response->toText() << endl;
-        }
-
-        // There should be one RR each  in the question and answer sections, and
-        // two RRs in each of the the authority and additional sections.
-        EXPECT_EQ(1, response->getRRCount(Message::SECTION_QUESTION));
-        EXPECT_EQ(1, response->getRRCount(Message::SECTION_ANSWER));
-        EXPECT_EQ(2, response->getRRCount(Message::SECTION_AUTHORITY));
-        EXPECT_EQ(2, response->getRRCount(Message::SECTION_ADDITIONAL));
-
-        // Check the answer - that the RRset is there...
-        EXPECT_TRUE(response->hasRRset(Message::SECTION_ANSWER,
-                                       RRsetPtr(new RRset(Name("www.example.org."),
-                                                RRClass::IN(),
-                                                RRType::A(),
-                                                RRTTL(300)))));
-        const RRsetIterator rrset_i = response->beginSection(Message::SECTION_ANSWER);
-
-        // ... get iterator into the Rdata of this RRset and point to first
-        // element...
-        const RdataIteratorPtr rdata_i = (*rrset_i)->getRdataIterator();
-        rdata_i->first();
-
-        // ... and check it is what we expect.
-        EXPECT_EQ(string(WWW_EXAMPLE_ORG), rdata_i->getCurrent().toText());
-
-        // Flag completion
-        run_ = true;
-        status_ = true;
-
-        service_.stop();    // Cause run() to exit.
-    }
-
-    /// \brief Resolver Failure Completion
-    ///
-    /// Called if the resolver detects that the resolution has failed.
-    virtual void failure() {
-        if (debug_) {
-            cout << "ResolverCallback::success(): resolution failure" << endl;
-        }
-        FAIL() << "Resolver reported completion failure";
-
-        // Flag completion
-        run_ = true;
-        status_ = false;
-
-        service_.stop();    // Cause run() to exit.
-    }
-
-    /// \brief Return status of "run" flag
-    bool getRun() const {
-        return (run_);
-    }
-
-    /// \brief Return "status" flag
-    bool getStatus() const {
-        return (status_);
-    }
-
-private:
-    IOService&      service_;       ///< Service handling the run queue
-    bool            run_;           ///< Set true when completion handler run
-    bool            status_;        ///< Set true for success, false on error
-    bool            debug_;         ///< Debug flag
-};
-
-// Sets up the UDP and TCP "servers", then tries a resolution.
-
-TEST_F(RecursiveQueryTest2, Resolve) {
-    // Set up the UDP server and issue the first read.  The endpoint from which
-    // the query is sent is put in udp_endpoint_ when the read completes, which
-    // is referenced in the callback as the place to which the response is sent.
-    udp_socket_.set_option(socket_base::reuse_address(true));
-    udp_socket_.bind(udp::endpoint(address::from_string(TEST_ADDRESS), TEST_PORT));
-    udp_socket_.async_receive_from(asio::buffer(udp_receive_buffer_,
-                                                sizeof(udp_receive_buffer_)),
-                                   udp_remote_,
-                                   boost::bind(&RecursiveQueryTest2::udpReceiveHandler,
-                                               this, _1, _2));
-
-    // Set up the TCP server and issue the accept.  Acceptance will cause the
-    // read to be issued.
-    tcp::acceptor acceptor(service_.get_io_service(),
-                           tcp::endpoint(tcp::v4(), TEST_PORT));
-    acceptor.async_accept(tcp_socket_,
-                          boost::bind(&RecursiveQueryTest2::tcpAcceptHandler,
-                                      this, _1, 0));
-
-    // Set up the RecursiveQuery object. We will also test that it correctly records
-    // RTT times by setting up a RTT recorder object as well.
-    std::vector<std::pair<std::string, uint16_t> > upstream;         // Empty
-    std::vector<std::pair<std::string, uint16_t> > upstream_root;    // Empty
-    RecursiveQuery query(dns_service_, *nsas_, cache_,
-                         upstream, upstream_root);
-    query.setTestServer(TEST_ADDRESS, TEST_PORT);
-
-    boost::shared_ptr<RttRecorder> recorder(new RttRecorder());
-    query.setRttRecorder(recorder);
-
-    // Set up callback to receive notification that the query has completed.
-    isc::resolve::ResolverInterface::CallbackPtr
-        resolver_callback(new ResolverCallback(service_));
-
-    // Kick off the resolution process.  We expect the first question to go to
-    // "root".
-    expected_ = UDP_ROOT;
-    running_query_ = query.resolve(question_, resolver_callback);
-    service_.run();
-
-    // Check what ran. (We have to cast the callback to ResolverCallback as we
-    // lost the information on the derived class when we used a
-    // ResolverInterface::CallbackPtr to store a pointer to it.)
-    ResolverCallback* rc = static_cast<ResolverCallback*>(resolver_callback.get());
-    EXPECT_TRUE(rc->getRun());
-    EXPECT_TRUE(rc->getStatus());
-
-    // Finally, check that all the RTTs were "reasonable" (defined here as
-    // being below 2 seconds).  This is an explicit check to test that the
-    // variables in the RTT calculation are at least being initialized; if they
-    // weren't, we would expect some absurdly high answers.
-    vector<uint32_t> rtt = recorder->getRtt();
-    EXPECT_GT(rtt.size(), 0);
-    for (vector<uint32_t>::size_type i = 0; i < rtt.size(); ++i) {
-        EXPECT_LT(rtt[i], 2000);
-    }
-}
-
-} // namespace asiodns
-} // namespace isc

+ 0 - 590
src/lib/resolve/tests/recursive_query_unittest_3.cc

@@ -1,590 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <algorithm>
-#include <cstdlib>
-#include <iomanip>
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include <gtest/gtest.h>
-#include <boost/bind.hpp>
-
-#include <asio.hpp>
-
-#include <util/buffer.h>
-#include <util/io_utilities.h>
-
-#include <dns/question.h>
-#include <dns/message.h>
-#include <dns/messagerenderer.h>
-#include <dns/opcode.h>
-#include <dns/name.h>
-#include <dns/rcode.h>
-#include <dns/rrtype.h>
-#include <dns/rrset.h>
-#include <dns/rrttl.h>
-#include <dns/rdata.h>
-
-#include <util/io_utilities.h>
-#include <asiodns/dns_service.h>
-#include <asiodns/io_fetch.h>
-#include <asiolink/io_address.h>
-#include <asiolink/io_endpoint.h>
-#include <asiolink/io_service.h>
-#include <resolve/recursive_query.h>
-#include <resolve/resolver_interface.h>
-
-using namespace asio;
-using namespace asio::ip;
-using namespace isc::asiolink;
-using namespace isc::dns;
-using namespace isc::dns::rdata;
-using namespace isc::util;
-using namespace isc::resolve;
-using namespace std;
-
-/// RecursiveQuery Test - 3
-///
-/// The second part of the RecursiveQuery unit tests, this attempts to get the
-/// RecursiveQuery object to follow a set of EDNS-induced errors, causing the
-/// resolver to follow the fallback logic.
-///
-/// - Send EDNS question over UDP - get FORMERR
-/// - Send EDNS question over TCP - get FORMERR
-/// - Send non-EDNS question over UDP - get RESPONSE
-///
-/// By using the "test_server_" element of RecursiveQuery, all queries are
-/// directed to one or other of the "servers" in the RecursiveQueryTest3 class.
-
-namespace {
-const char* const TEST_ADDRESS3 = "127.0.0.1"; ///< Servers are on this address
-const uint16_t TEST_PORT3 = 5303;              ///< ... and this port
-const size_t BUFFER_SIZE = 1024;               ///< For all buffers
-
-const char* const DUMMY_ADDR3 = "1.2.3.4";     ///< address to return as A
-} // end anonymous namespace
-
-namespace isc {
-namespace asiodns {
-
-class MockResolver3 : public isc::resolve::ResolverInterface {
-public:
-    virtual void resolve(const QuestionPtr& question,
-                 const ResolverInterface::CallbackPtr& callback) {
-    }
-
-    virtual ~MockResolver3() {}
-};
-
-
-
-/// \brief Test fixture for the RecursiveQuery Test
-class RecursiveQueryTest3 : public virtual ::testing::Test
-{
-public:
-
-    /// \brief Status of query
-    ///
-    /// Set before the query and then by each "server" when responding.
-    enum QueryStatus {
-        NONE = 0,                   ///< Default
-        EDNS_UDP = 1,               ///< EDNS query over UDP
-        NON_EDNS_UDP = 2,           ///< Non-EDNS query over UDP
-        COMPLETE = 6                ///< Query is complete
-    };
-
-    // Common stuff
-    IOService       service_;                   ///< Service to run everything
-    DNSService      dns_service_;               ///< Resolver is part of "server"
-    QuestionPtr     question_;                  ///< What to ask
-    QueryStatus     last_;                      ///< What was the last state
-    QueryStatus     expected_;                  ///< Expected next state
-    OutputBufferPtr question_buffer_;           ///< Question we expect to receive
-    boost::shared_ptr<MockResolver3> resolver_;  ///< Mock resolver
-    isc::nsas::NameserverAddressStore* nsas_;   ///< Nameserver address store
-    isc::cache::ResolverCache cache_;           ///< Resolver cache
-
-    // Data for TCP Server
-    size_t          tcp_cumulative_;            ///< Cumulative TCP data received
-    tcp::endpoint   tcp_endpoint_;              ///< Endpoint for TCP receives
-    size_t          tcp_length_;                ///< Expected length value
-    uint8_t         tcp_receive_buffer_[BUFFER_SIZE];   ///< Receive buffer for TCP I/O
-    OutputBufferPtr tcp_send_buffer_;           ///< Send buffer for TCP I/O
-    tcp::socket     tcp_socket_;                ///< Socket used by TCP server
-
-    /// Data for UDP
-    udp::endpoint   udp_remote_;                ///< Endpoint for UDP receives
-    size_t          udp_length_;                ///< Expected length value
-    uint8_t         udp_receive_buffer_[BUFFER_SIZE];   ///< Receive buffer for UDP I/O
-    OutputBufferPtr udp_send_buffer_;           ///< Send buffer for UDP I/O
-    udp::socket     udp_socket_;                ///< Socket used by UDP server
-
-    /// Some of the tests cause an 'active' running query to be created, but
-    /// don't complete the framework that makes that query delete itself.
-    /// This member can be used to store it so that it is deleted automatically
-    /// when the test is finished.
-    AbstractRunningQuery* running_query_;
-
-    /// \brief Constructor
-    RecursiveQueryTest3() :
-        service_(),
-        dns_service_(service_, NULL, NULL),
-        question_(new Question(Name("ednsfallback"),
-                  RRClass::IN(), RRType::A())),
-        last_(NONE),
-        expected_(NONE),
-        question_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        resolver_(new MockResolver3()),
-        nsas_(new isc::nsas::NameserverAddressStore(resolver_)),
-        tcp_cumulative_(0),
-        tcp_endpoint_(asio::ip::address::from_string(TEST_ADDRESS3),
-                      TEST_PORT3),
-        tcp_length_(0),
-        tcp_receive_buffer_(),
-        tcp_send_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        tcp_socket_(service_.get_io_service()),
-        udp_remote_(),
-        udp_length_(0),
-        udp_receive_buffer_(),
-        udp_send_buffer_(new OutputBuffer(BUFFER_SIZE)),
-        udp_socket_(service_.get_io_service(), udp::v4()),
-        running_query_(NULL)
-    {
-    }
-
-    ~RecursiveQueryTest3() {
-        delete nsas_;
-        // It would delete itself, but after the io_service_, which could
-        // segfailt in case there were unhandled requests
-        resolver_.reset();
-        // In a similar note, we wait until the resolver has been cleaned up
-        // until deleting and active test running_query_
-        delete running_query_;
-    }
-
-    /// \brief Set Common Message Bits
-    ///
-    /// Sets up the common bits of a response message returned by the handlers.
-    ///
-    /// \param message Message buffer in RENDER mode.
-    /// \param qid QID to set the message to
-    void setCommonMessage(isc::dns::Message& message, uint16_t qid) {
-        message.setQid(qid);
-        message.setHeaderFlag(Message::HEADERFLAG_QR);
-        message.setOpcode(Opcode::QUERY());
-        message.setHeaderFlag(Message::HEADERFLAG_AA);
-        message.addQuestion(*question_);
-    }
-
-    /// \brief Set FORMERR answer
-    ///
-    /// \param message Message to update with FORMERR status
-    void setFORMERR(isc::dns::Message& message) {
-        message.setRcode(Rcode::FORMERR());
-    }
-
-    /// \brief Set Answer
-    ///
-    /// \param message Message to update with FORMERR status
-    void setAnswer(isc::dns::Message& message) {
-        // Give a response
-        RRsetPtr answer(new RRset(Name("ednsfallback."), RRClass::IN(),
-                        RRType::A(), RRTTL(300)));
-        answer->addRdata(createRdata(RRType::A(), RRClass::IN(), DUMMY_ADDR3));
-        message.addRRset(Message::SECTION_ANSWER, answer);
-        message.setRcode(Rcode::NOERROR());
-    }
-
-    /// \brief UDP Receive Handler
-    ///
-    /// This is invoked when a message is received over UDP from the
-    /// RecursiveQuery object under test.  It formats an answer and sends it
-    /// asynchronously, with the UdpSendHandler method being specified as the
-    /// completion handler.
-    ///
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param length Amount of data received.
-    void udpReceiveHandler(asio::error_code ec = asio::error_code(),
-                           size_t length = 0) {
-        // Expected state should be one greater than the last state.
-        EXPECT_EQ(static_cast<int>(expected_), static_cast<int>(last_) + 1);
-        last_ = expected_;
-
-        Message query(Message::PARSE);
-
-        // The QID in the incoming data is random so set it to 0 for the
-        // data comparison check. (It is set to 0 in the buffer containing
-        // the expected data.)
-        // And check that question we received is what was expected.
-        checkReceivedPacket(udp_receive_buffer_, length, query);
-
-        // The message returned depends on what state we are in.  Set up
-        // common stuff first: bits not mentioned are set to 0.
-        Message message(Message::RENDER);
-        setCommonMessage(message, query.getQid());
-
-        // Set up state-dependent bits:
-        switch (expected_) {
-        case EDNS_UDP:
-            EXPECT_TRUE(query.getEDNS());
-            // Return FORMERROR
-            setFORMERR(message);
-            expected_ = NON_EDNS_UDP;
-            break;
-
-        case NON_EDNS_UDP:
-            EXPECT_FALSE(query.getEDNS());
-            // Return the answer to the question.
-            setAnswer(message);
-            expected_ = COMPLETE;
-            break;
-
-         default:
-            FAIL() << "UdpReceiveHandler called with unknown state";
-        }
-
-        // Convert to wire format
-        udp_send_buffer_->clear();
-        MessageRenderer renderer;
-        renderer.setBuffer(udp_send_buffer_.get());
-        message.toWire(renderer);
-        renderer.setBuffer(NULL);
-
-        // Return a message back to the IOFetch object (after setting the
-        // expected length of data for the check in the send handler).
-        udp_length_ = udp_send_buffer_->getLength();
-        udp_socket_.async_send_to(asio::buffer(udp_send_buffer_->getData(),
-                                               udp_send_buffer_->getLength()),
-                                  udp_remote_,
-                              boost::bind(&RecursiveQueryTest3::udpSendHandler,
-                                              this, _1, _2));
-    }
-
-    /// \brief UDP Send Handler
-    ///
-    /// Called when a send operation of the UDP server (i.e. a response
-    /// being sent to the RecursiveQuery) has completed, this re-issues
-    /// a read call.
-    ///
-    /// \param ec Completion error code of the send.
-    /// \param length Actual number of bytes sent.
-    void udpSendHandler(asio::error_code ec = asio::error_code(),
-                        size_t length = 0) {
-        // Check send was OK
-        EXPECT_EQ(0, ec.value());
-        EXPECT_EQ(udp_length_, length);
-
-        // Reissue the receive call to await the next message.
-        udp_socket_.async_receive_from(
-            asio::buffer(udp_receive_buffer_, sizeof(udp_receive_buffer_)),
-            udp_remote_,
-            boost::bind(&RecursiveQueryTest3::udpReceiveHandler,
-                        this, _1, _2));
-    }
-
-    /// \brief Completion Handler for Accepting TCP Data
-    ///
-    /// Called when the remote system connects to the "TCP server".  It issues
-    /// an asynchronous read on the socket to read data.
-    ///
-    /// \param socket Socket on which data will be received
-    /// \param ec Boost error code, value should be zero.
-    void tcpAcceptHandler(asio::error_code ec = asio::error_code(),
-                          size_t length = 0) {
-        // Expect that the accept completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // Initiate a read on the socket, indicating that nothing has yet been
-        // received.
-        tcp_cumulative_ = 0;
-        tcp_socket_.async_receive(
-            asio::buffer(tcp_receive_buffer_, sizeof(tcp_receive_buffer_)),
-            boost::bind(&RecursiveQueryTest3::tcpReceiveHandler, this, _1, _2));
-    }
-
-    /// \brief Completion Handler for Receiving TCP Data
-    ///
-    /// Reads data from the RecursiveQuery object and loops, reissuing reads,
-    /// until all the message has been read.  It then returns an appropriate
-    /// response.
-    ///
-    /// \param socket Socket to use to send the answer
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param length Amount of data received.
-    void tcpReceiveHandler(asio::error_code ec = asio::error_code(),
-                           size_t length = 0) {
-        // Expect that the receive completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // Have we received all the data?  We know this by checking if the two-
-        // byte length count in the message is equal to the data received.
-        tcp_cumulative_ += length;
-        bool complete = false;
-        if (tcp_cumulative_ > 2) {
-            uint16_t dns_length = readUint16(tcp_receive_buffer_,
-                                             sizeof(tcp_receive_buffer_));
-            complete = ((dns_length + 2) == tcp_cumulative_);
-        }
-
-        if (!complete) {
-            // Not complete yet, issue another read.
-            tcp_socket_.async_receive(
-                asio::buffer(tcp_receive_buffer_ + tcp_cumulative_,
-                             sizeof(tcp_receive_buffer_) - tcp_cumulative_),
-                boost::bind(&RecursiveQueryTest3::tcpReceiveHandler,
-                            this, _1, _2));
-            return;
-        }
-
-        // Have received a TCP message.  Expected state should be one greater
-        // than the last state.
-        EXPECT_EQ(static_cast<int>(expected_), static_cast<int>(last_) + 1);
-        last_ = expected_;
-
-        Message query(Message::PARSE);
-
-        // Check that question we received is what was expected.  Note that we
-        // have to ignore the two-byte header in order to parse the message.
-        checkReceivedPacket(tcp_receive_buffer_ + 2, length - 2, query);
-
-        // Return a message back.  This is a referral to example.org, which
-        // should result in another query over UDP.  Note the setting of the
-        // QID in the returned message with what was in the received message.
-        Message message(Message::RENDER);
-        setCommonMessage(message, query.getQid());
-
-        // Set up state-dependent bits:
-        switch (expected_) {
-        default:
-            FAIL() << "TcpReceiveHandler called with unknown state";
-        }
-
-
-        // Convert to wire format
-        // Use a temporary buffer for the dns wire data (we copy it
-        // to the 'real' buffer below)
-        MessageRenderer renderer;
-        message.toWire(renderer);
-
-        // Also, take this opportunity to clear the accumulated read count in
-        // readiness for the next read. (If any - at present, there is only
-        // one read in the test, although extensions to this test suite could
-        // change that.)
-        tcp_cumulative_ = 0;
-
-        // Unless we go through a callback loop we cannot simply use
-        // async_send() multiple times, so we cannot send the size first
-        // followed by the actual data. We copy them to a new buffer
-        // first
-        tcp_send_buffer_->clear();
-        tcp_send_buffer_->writeUint16(renderer.getLength());
-        tcp_send_buffer_->writeData(renderer.getData(), renderer.getLength());
-        tcp_socket_.async_send(asio::buffer(tcp_send_buffer_->getData(),
-                                            tcp_send_buffer_->getLength()),
-                               boost::bind(
-                                   &RecursiveQueryTest3::tcpSendHandler,
-                                   this,
-                                   tcp_send_buffer_->getLength(), _1, _2));
-    }
-
-    /// \brief Completion Handler for Sending TCP data
-    ///
-    /// Called when the asynchronous send of data back to the RecursiveQuery
-    /// by the TCP "server" in this class has completed.  (This send has to
-    /// be asynchronous because control needs to return to the caller in order
-    /// for the IOService "run()" method to be called to run the handlers.)
-    ///
-    /// \param expected_length Number of bytes that were expected to have been
-    /// sent.
-    /// \param ec Boost error code, value should be zero.
-    /// \param length Number of bytes sent.
-    void tcpSendHandler(size_t expected_length = 0,
-                        asio::error_code ec = asio::error_code(),
-                        size_t length = 0)
-    {
-        EXPECT_EQ(0, ec.value());       // Expect no error
-        EXPECT_EQ(expected_length, length);    // And that amount sent is as
-                                               // expected
-    }
-
-    /// \brief Check Received Packet
-    ///
-    /// Checks the packet received from the RecursiveQuery object to ensure
-    /// that the question is what is expected.
-    ///
-    /// \param data Start of data.  This is the start of the received buffer in
-    ///        the case of UDP data, and an offset into the buffer past the
-    ///        count field for TCP data.
-    /// \param length Length of data.
-    /// \return The QID of the message
-    void checkReceivedPacket(uint8_t* data, size_t length, Message& message) {
-
-        // Decode the received buffer.
-        InputBuffer buffer(data, length);
-        message.fromWire(buffer);
-
-        // Check the packet.
-        EXPECT_FALSE(message.getHeaderFlag(Message::HEADERFLAG_QR));
-
-        Question question = **(message.beginQuestion());
-        EXPECT_TRUE(question == *question_);
-    }
-};
-
-/// \brief Resolver Callback Object
-///
-/// Holds the success and failure callback methods for the resolver
-class ResolverCallback3 : public isc::resolve::ResolverInterface::Callback {
-public:
-    /// \brief Constructor
-    ResolverCallback3(IOService& service) :
-        service_(service), run_(false), status_(false)
-    {}
-
-    /// \brief Destructor
-    virtual ~ResolverCallback3()
-    {}
-
-    /// \brief Resolver Callback Success
-    ///
-    /// Called if the resolver detects that the call has succeeded.
-    ///
-    /// \param response Answer to the question.
-    virtual void success(const isc::dns::MessagePtr response) {
-        // There should be one RR each  in the question and answer sections,
-        // and two RRs in each of the the authority and additional sections.
-        EXPECT_EQ(1, response->getRRCount(Message::SECTION_QUESTION));
-        EXPECT_EQ(1, response->getRRCount(Message::SECTION_ANSWER));
-
-        // Check the answer - that the RRset is there...
-        EXPECT_TRUE(response->hasRRset(Message::SECTION_ANSWER,
-                                       RRsetPtr(new RRset(Name("ednsfallback."),
-                                                RRClass::IN(),
-                                                RRType::A(),
-                                                RRTTL(300)))));
-        const RRsetIterator rrset_i = response->beginSection(Message::SECTION_ANSWER);
-
-        // ... get iterator into the Rdata of this RRset and point to first
-        // element...
-        const RdataIteratorPtr rdata_i = (*rrset_i)->getRdataIterator();
-        rdata_i->first();
-
-        // ... and check it is what we expect.
-        EXPECT_EQ(string(DUMMY_ADDR3), rdata_i->getCurrent().toText());
-
-        // Flag completion
-        run_ = true;
-        status_ = true;
-
-        service_.stop();    // Cause run() to exit.
-    }
-
-    /// \brief Resolver Failure Completion
-    ///
-    /// Called if the resolver detects that the resolution has failed.
-    virtual void failure() {
-        FAIL() << "Resolver reported completion failure";
-
-        // Flag completion
-        run_ = true;
-        status_ = false;
-
-        service_.stop();    // Cause run() to exit.
-    }
-
-    /// \brief Return status of "run" flag
-    bool getRun() const {
-        return (run_);
-    }
-
-    /// \brief Return "status" flag
-    bool getStatus() const {
-        return (status_);
-    }
-
-private:
-    IOService&      service_;       ///< Service handling the run queue
-    bool            run_;           ///< Set true when completion handler run
-    bool            status_;        ///< Set true for success, false on error
-};
-
-// Sets up the UDP and TCP "servers", then tries a resolution.
-
-TEST_F(RecursiveQueryTest3, Resolve) {
-    // Set up the UDP server and issue the first read.  The endpoint from which
-    // the query is sent is put in udp_endpoint_ when the read completes, which
-    // is referenced in the callback as the place to which the response is
-    // sent.
-    udp_socket_.set_option(socket_base::reuse_address(true));
-    udp_socket_.bind(udp::endpoint(address::from_string(TEST_ADDRESS3),
-                                   TEST_PORT3));
-    udp_socket_.async_receive_from(asio::buffer(udp_receive_buffer_,
-                                                sizeof(udp_receive_buffer_)),
-                                   udp_remote_,
-                           boost::bind(&RecursiveQueryTest3::udpReceiveHandler,
-                                               this, _1, _2));
-
-    // Set up the TCP server and issue the accept.  Acceptance will cause the
-    // read to be issued.
-    tcp::acceptor acceptor(service_.get_io_service(),
-                           tcp::endpoint(tcp::v4(), TEST_PORT3));
-    acceptor.async_accept(tcp_socket_,
-                          boost::bind(&RecursiveQueryTest3::tcpAcceptHandler,
-                                      this, _1, 0));
-
-    // Set up the RecursiveQuery object. We will also test that it correctly
-    // records RTT times by setting up a RTT recorder object as well.
-    std::vector<std::pair<std::string, uint16_t> > upstream;         // Empty
-    std::vector<std::pair<std::string, uint16_t> > upstream_root;    // Empty
-    RecursiveQuery query(dns_service_, *nsas_, cache_,
-                         upstream, upstream_root);
-    query.setTestServer(TEST_ADDRESS3, TEST_PORT3);
-
-    boost::shared_ptr<RttRecorder> recorder(new RttRecorder());
-    query.setRttRecorder(recorder);
-
-    // Set up callback to receive notification that the query has completed.
-    isc::resolve::ResolverInterface::CallbackPtr
-        resolver_callback(new ResolverCallback3(service_));
-
-    // Kick off the resolution process.
-    expected_ = EDNS_UDP;
-    running_query_ = query.resolve(question_, resolver_callback);
-    service_.run();
-
-    // Check what ran. (We have to cast the callback to ResolverCallback3 as we
-    // lost the information on the derived class when we used a
-    // ResolverInterface::CallbackPtr to store a pointer to it.)
-    ResolverCallback3* rc
-                    = static_cast<ResolverCallback3*>(resolver_callback.get());
-    EXPECT_TRUE(rc->getRun());
-    EXPECT_TRUE(rc->getStatus());
-
-    // Finally, check that all the RTTs were "reasonable" (defined here as
-    // being below 2 seconds).  This is an explicit check to test that the
-    // variables in the RTT calculation are at least being initialized; if they
-    // weren't, we would expect some absurdly high answers.
-    vector<uint32_t> rtt = recorder->getRtt();
-    EXPECT_GT(rtt.size(), 0);
-    for (int i = 0; i < rtt.size(); ++i) {
-        EXPECT_LT(rtt[i], 2000);
-    }
-}
-
-} // namespace asiodns
-} // namespace isc

+ 0 - 198
src/lib/resolve/tests/resolve_unittest.cc

@@ -1,198 +0,0 @@
-// 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.
-
-#include <iostream>
-#include <gtest/gtest.h>
-
-#include <dns/message.h>
-#include <dns/question.h>
-#include <dns/opcode.h>
-#include <dns/rcode.h>
-#include <dns/rrttl.h>
-#include <dns/rdata.h>
-#include <resolve/resolve.h>
-
-using namespace isc::dns;
-
-namespace {
-
-class ResolveHelperFunctionsTest : public ::testing::Test {
-public:
-    ResolveHelperFunctionsTest() :
-        message_a_(new Message(Message::RENDER)),
-        message_b_(new Message(Message::RENDER)),
-        question_(new Question(Name("www.example.com"), RRClass::IN(), RRType::A()))
-    {
-        createMessageA();
-        createMessageB();
-    };
-
-    void createMessageA() {
-        message_a_->setOpcode(Opcode::QUERY());
-        message_a_->setRcode(Rcode::NOERROR());
-        message_a_->addQuestion(question_);
-    }
-
-    void createMessageB() {
-        message_b_->setOpcode(Opcode::QUERY());
-        message_b_->setRcode(Rcode::NOERROR());
-        message_b_->addQuestion(question_);
-
-        // We could reuse the same rrset in the different sections,
-        // but to be sure, we create separate ones
-        RRsetPtr answer_rrset(new RRset(Name("www.example.com"),
-                                        RRClass::IN(), RRType::TXT(),
-                                        RRTTL(3600)));
-        answer_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                                  RRClass::IN(),
-                                                  "Answer"));
-        message_b_->addRRset(Message::SECTION_ANSWER, answer_rrset);
-    
-        RRsetPtr auth_rrset(new RRset(Name("www.example.com"),
-                                        RRClass::IN(), RRType::TXT(),
-                                        RRTTL(3600)));
-        auth_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                                  RRClass::IN(),
-                                                  "Authority"));
-        auth_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                                  RRClass::IN(),
-                                                  "Rdata"));
-        message_b_->addRRset(Message::SECTION_AUTHORITY, auth_rrset);
-    
-        RRsetPtr add_rrset(new RRset(Name("www.example.com"),
-                                     RRClass::IN(), RRType::TXT(),
-                                     RRTTL(3600)));
-        add_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                               RRClass::IN(),
-                                               "Additional"));
-        add_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                               RRClass::IN(),
-                                               "Rdata"));
-        add_rrset->addRdata(rdata::createRdata(RRType::TXT(),
-                                               RRClass::IN(),
-                                               "fields."));
-        message_b_->addRRset(Message::SECTION_ADDITIONAL, add_rrset);
-    };
-
-    MessagePtr message_a_;
-    MessagePtr message_b_;
-    QuestionPtr question_;
-};
-
-TEST_F(ResolveHelperFunctionsTest, makeErrorMessageEmptyMessage) {
-    ASSERT_EQ(Rcode::NOERROR(), message_a_->getRcode());
-    ASSERT_EQ(1, message_a_->getRRCount(Message::SECTION_QUESTION));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_ANSWER));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_AUTHORITY));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_ADDITIONAL));
-
-    isc::resolve::makeErrorMessage(message_a_, Rcode::SERVFAIL());
-    EXPECT_EQ(Rcode::SERVFAIL(), message_a_->getRcode());
-    EXPECT_EQ(1, message_a_->getRRCount(Message::SECTION_QUESTION));
-    EXPECT_EQ(0, message_a_->getRRCount(Message::SECTION_ANSWER));
-    EXPECT_EQ(0, message_a_->getRRCount(Message::SECTION_AUTHORITY));
-    EXPECT_EQ(0, message_a_->getRRCount(Message::SECTION_ADDITIONAL));
-}
-
-TEST_F(ResolveHelperFunctionsTest, makeErrorMessageNonEmptyMessage) {
-
-    ASSERT_EQ(Rcode::NOERROR(), message_b_->getRcode());
-    ASSERT_EQ(1, message_b_->getRRCount(Message::SECTION_QUESTION));
-    ASSERT_EQ(1, message_b_->getRRCount(Message::SECTION_ANSWER));
-    ASSERT_EQ(2, message_b_->getRRCount(Message::SECTION_AUTHORITY));
-    ASSERT_EQ(3, message_b_->getRRCount(Message::SECTION_ADDITIONAL));
-
-    isc::resolve::makeErrorMessage(message_b_, Rcode::FORMERR());
-    EXPECT_EQ(Rcode::FORMERR(), message_b_->getRcode());
-    EXPECT_EQ(1, message_b_->getRRCount(Message::SECTION_QUESTION));
-    EXPECT_EQ(0, message_b_->getRRCount(Message::SECTION_ANSWER));
-    EXPECT_EQ(0, message_b_->getRRCount(Message::SECTION_AUTHORITY));
-    EXPECT_EQ(0, message_b_->getRRCount(Message::SECTION_ADDITIONAL));
-}
-
-void
-compareSections(const Message& message_a, const Message& message_b,
-                Message::Section section)
-{
-    RRsetIterator rrs_a = message_a.beginSection(section);
-    RRsetIterator rrs_b = message_b.beginSection(section);
-    while (rrs_a != message_a.endSection(section) &&
-           rrs_b != message_b.endSection(section)
-          ) {
-        EXPECT_EQ(*rrs_a, *rrs_b);
-        ++rrs_a;
-        ++rrs_b;
-    }
-    // can't use EXPECT_EQ here, no eqHelper for endsection comparison
-    EXPECT_TRUE(rrs_a == message_a.endSection(section));
-    EXPECT_TRUE(rrs_b == message_b.endSection(section));
-}
-
-TEST_F(ResolveHelperFunctionsTest, initResponseMessage) {
-    Message response_parse(Message::PARSE);
-    EXPECT_THROW(isc::resolve::initResponseMessage(*message_a_,
-                                                   response_parse),
-                 isc::dns::InvalidMessageOperation);
-    EXPECT_THROW(isc::resolve::initResponseMessage(*question_,
-                                                   response_parse),
-                 isc::dns::InvalidMessageOperation);
-    
-    Message response1(Message::RENDER);
-    isc::resolve::initResponseMessage(*message_a_, response1);
-    ASSERT_EQ(message_a_->getOpcode(), response1.getOpcode());
-    ASSERT_EQ(message_a_->getQid(), response1.getQid());
-    isc::dns::QuestionIterator qi = response1.beginQuestion();
-    ASSERT_EQ(*question_, **qi);
-    ASSERT_TRUE(++qi == response1.endQuestion());
-
-    Message response2(Message::RENDER);
-    isc::resolve::initResponseMessage(*question_, response2);
-    ASSERT_EQ(Opcode::QUERY(), response2.getOpcode());
-    ASSERT_EQ(0, response2.getQid());
-    qi = response2.beginQuestion();
-    ASSERT_EQ(*question_, **qi);
-    ASSERT_TRUE(++qi == response2.endQuestion());
-}
-
-TEST_F(ResolveHelperFunctionsTest, copyAnswerMessage) {
-    message_b_->setRcode(Rcode::NXDOMAIN());
-    
-    ASSERT_NE(message_b_->getRcode(), message_a_->getRcode());
-    ASSERT_NE(message_b_->getRRCount(Message::SECTION_ANSWER),
-              message_a_->getRRCount(Message::SECTION_ANSWER));
-    ASSERT_NE(message_b_->getRRCount(Message::SECTION_AUTHORITY),
-              message_a_->getRRCount(Message::SECTION_AUTHORITY));
-    ASSERT_NE(message_b_->getRRCount(Message::SECTION_ADDITIONAL),
-              message_a_->getRRCount(Message::SECTION_ADDITIONAL));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_ANSWER));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_AUTHORITY));
-    ASSERT_EQ(0, message_a_->getRRCount(Message::SECTION_ADDITIONAL));
-
-    isc::resolve::copyResponseMessage(*message_b_, message_a_);
-
-    EXPECT_EQ(message_b_->getRcode(), message_a_->getRcode());
-    ASSERT_EQ(message_b_->getRRCount(Message::SECTION_ANSWER),
-              message_a_->getRRCount(Message::SECTION_ANSWER));
-    ASSERT_EQ(message_b_->getRRCount(Message::SECTION_AUTHORITY),
-              message_a_->getRRCount(Message::SECTION_AUTHORITY));
-    ASSERT_EQ(message_b_->getRRCount(Message::SECTION_ADDITIONAL),
-              message_a_->getRRCount(Message::SECTION_ADDITIONAL));
-
-    
-    compareSections(*message_a_, *message_b_, Message::SECTION_ANSWER);
-    compareSections(*message_a_, *message_b_, Message::SECTION_AUTHORITY);
-    compareSections(*message_a_, *message_b_, Message::SECTION_ADDITIONAL);
-}
-
-} // Anonymous namespace

+ 0 - 90
src/lib/resolve/tests/resolver_callback_unittest.cc

@@ -1,90 +0,0 @@
-// 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.
-
-#include <gtest/gtest.h>
-#include <asiodns/dns_server.h>
-#include <resolve/resolver_callback.h>
-
-using namespace isc::resolve;
-
-// Dummy subclass for DNSServer*
-// We want to check if resume is called
-// Since the server will get cloned(), we want the clones to share
-// our bools for whether resume got called and with what value
-class DummyServer : public isc::asiodns::DNSServer {
-public:
-    DummyServer(DummyServer* orig) {
-        resume_called_ = orig->getResumeCalled();
-        resume_value_ = orig->getResumeValue();
-    }
-    DummyServer(bool* resume_called, bool* resume_value) :
-        resume_called_(resume_called), resume_value_(resume_value)
-    {}
-
-    bool* getResumeCalled() { return resume_called_; }
-    bool* getResumeValue() { return resume_value_; }
-
-    DNSServer* clone() {
-        DummyServer* n = new DummyServer(this);
-        return n;
-    }
-
-    void resume(bool value) {
-        *resume_called_ = true;
-        *resume_value_ = value;
-    }
-
-private:
-    bool* resume_called_;
-    bool* resume_value_;
-};
-
-class ResolverCallbackServerTest : public ::testing::Test {
-public:
-    ResolverCallbackServerTest() : resume_called_(false),
-                                   resume_value_(false) {
-        server_ = new DummyServer(&resume_called_, &resume_value_);
-        callback_ = new ResolverCallbackServer(server_);
-    };
-
-    ~ResolverCallbackServerTest() {
-        delete callback_;
-        delete server_;
-    }
-
-    DummyServer* getServer() { return server_; }
-    ResolverCallbackServer* getCallback() { return callback_; }
-    bool getResumeCalled() { return resume_called_; }
-    bool getResumeValue() { return resume_value_; }
-
-private:
-    DummyServer* server_;
-    ResolverCallbackServer* callback_;
-    bool resume_called_;
-    bool resume_value_;
-};
-
-TEST_F(ResolverCallbackServerTest, testSuccess) {
-    EXPECT_FALSE(getResumeCalled());
-    getCallback()->success(isc::dns::MessagePtr());
-    EXPECT_TRUE(getResumeCalled());
-    EXPECT_TRUE(getResumeValue());
-}
-
-TEST_F(ResolverCallbackServerTest, testFailure) {
-    EXPECT_FALSE(getResumeCalled());
-    getCallback()->failure();
-    EXPECT_TRUE(getResumeCalled());
-    EXPECT_FALSE(getResumeValue());
-}

+ 0 - 554
src/lib/resolve/tests/response_classifier_unittest.cc

@@ -1,554 +0,0 @@
-// 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.
-
-#include <iostream>
-#include <gtest/gtest.h>
-
-#include <dns/tests/unittest_util.h>
-
-#include <resolve/response_classifier.h>
-
-#include <dns/name.h>
-#include <dns/opcode.h>
-#include <dns/question.h>
-#include <dns/rdata.h>
-#include <dns/rdataclass.h>
-#include <dns/rcode.h>
-#include <dns/rrclass.h>
-#include <dns/rrset.h>
-#include <dns/rrtype.h>
-#include <dns/rrttl.h>
-
-using namespace std;
-using namespace isc::dns;
-using namespace rdata;
-using namespace isc::dns::rdata::generic;
-using namespace isc::dns::rdata::in;
-using namespace isc::resolve;
-
-
-namespace {
-class ResponseClassifierTest : public ::testing::Test {
-public:
-    /// \brief Constructor
-    ///
-    /// The naming convention is:
-    ///
-    /// <category>_<class>_<type>_<name>
-    ///
-    /// <category> is "qu" (question), "rrs" (rrset),
-    /// <qclass> is self-explanatory
-    /// <qtype> is self-explanatory
-    /// <name> is the first part of the domain name (all expected to be in
-    /// example.com)
-    ///
-    /// Message variables
-    ///
-    /// msg_<qtype>  Where <qtype> is the type of query.  These are only used
-    /// in the early tests where simple messages are required.
-
-    ResponseClassifierTest() :
-        msg_a(Message::RENDER),
-        msg_any(Message::RENDER),
-        qu_ch_a_www(Name("www.example.com"), RRClass::CH(), RRType::A()),
-        qu_in_any_www(Name("www.example.com"), RRClass::IN(), RRType::ANY()),
-        qu_in_a_www2(Name("www2.example.com"), RRClass::IN(), RRType::A()),
-        qu_in_a_www(Name("www.example.com"), RRClass::IN(), RRType::A()),
-        qu_in_cname_www1(Name("www1.example.com"), RRClass::IN(), RRType::A()),
-        qu_in_ns_(Name("example.com"), RRClass::IN(), RRType::NS()),
-        qu_in_txt_www(Name("www.example.com"), RRClass::IN(), RRType::TXT()),
-        rrs_hs_txt_www(new RRset(Name("www.example.com"), RRClass::HS(),
-            RRType::TXT(), RRTTL(300))),
-        rrs_in_a_mail(new RRset(Name("mail.example.com"), RRClass::IN(),
-            RRType::A(), RRTTL(300))),
-        rrs_in_a_www(new RRset(Name("www.example.com"), RRClass::IN(),
-            RRType::A(), RRTTL(300))),
-        rrs_in_cname_www1(new RRset(Name("www1.example.com"), RRClass::IN(),
-            RRType::CNAME(), RRTTL(300))),
-        rrs_in_cname_www2(new RRset(Name("www2.example.com"), RRClass::IN(),
-            RRType::CNAME(), RRTTL(300))),
-        rrs_in_ns_(new RRset(Name("example.com"), RRClass::IN(),
-            RRType::NS(), RRTTL(300))),
-        rrs_in_soa_(new RRset(Name("example.com"), RRClass::IN(),
-            RRType::SOA(), RRTTL(300))),
-        rrs_in_txt_www(new RRset(Name("www.example.com"), RRClass::IN(),
-            RRType::TXT(), RRTTL(300))),
-        cname_target("."),
-        cname_count(0)
-    {
-        // Set up the message to indicate a successful response to the question
-        // "www.example.com A", but don't add in any response sections.
-        msg_a.setHeaderFlag(Message::HEADERFLAG_QR);
-        msg_a.setOpcode(Opcode::QUERY());
-        msg_a.setRcode(Rcode::NOERROR());
-        msg_a.addQuestion(qu_in_a_www);
-
-        // ditto for the query "www.example.com ANY"
-        msg_any.setHeaderFlag(Message::HEADERFLAG_QR);
-        msg_any.setOpcode(Opcode::QUERY());
-        msg_any.setRcode(Rcode::NOERROR());
-        msg_any.addQuestion(qu_in_any_www);
-
-        // The next set of assignments set up the following zone records
-        //
-        // example.com           NS     ns0.isc.org
-        //                       NS     ns0.example.org
-        //
-        // www.example.com       A      1.2.3.4
-        //                       TXT    "An example text string"
-        //
-        // mail.example.com      A      4.5.6.7
-        //
-        // www1.example.com      CNAME  www.example.com
-        //
-        // www2.example.com      CNAME  www1.example.com
-
-        // Set up an imaginary NS RRset for an authority section
-        rrs_in_ns_->addRdata(ConstRdataPtr(new NS(Name("ns0.isc.org"))));
-        rrs_in_ns_->addRdata(ConstRdataPtr(new NS(Name("ns0.example.org"))));
-        
-        // And an imaginary SOA
-        rrs_in_soa_->addRdata(ConstRdataPtr(new SOA(Name("ns0.example.org"), Name("root.example.org"), 1, 2, 3, 4, 5)));
-
-        // Set up the records for the www host
-        rrs_in_a_www->addRdata(ConstRdataPtr(new A("1.2.3.4")));
-        rrs_in_txt_www->addRdata(ConstRdataPtr(
-            new TXT("An example text string")));
-
-        // ... for the mail host
-        rrs_in_a_mail->addRdata(ConstRdataPtr(new A("5.6.7.8")));
-
-        // ... the CNAME records
-        rrs_in_cname_www1->addRdata(ConstRdataPtr(
-            new CNAME("www.example.com.")));
-        rrs_in_cname_www2->addRdata(ConstRdataPtr(
-            new CNAME("www1.example.com.")));
-    }
-
-    Message     msg_a;              // Pointer to message in RENDER state
-    Message     msg_any;            // Pointer to message in RENDER state
-    Question    qu_ch_a_www;        // www.example.com CH A
-    Question    qu_in_any_www;      // www.example.com IN ANY
-    Question    qu_in_a_www2;       // www.example.com IN ANY
-    Question    qu_in_a_www;        // www.example.com IN A
-    Question    qu_in_cname_www1;   // www1.example.com IN CNAME
-    Question    qu_in_ns_;          // example.com IN NS
-    Question    qu_in_txt_www;      // www.example.com IN TXT
-    RRsetPtr    rrs_hs_txt_www;     // www.example.com HS TXT
-    RRsetPtr    rrs_in_a_mail;      // mail.example.com IN A
-    RRsetPtr    rrs_in_a_www;       // www.example.com IN A
-    RRsetPtr    rrs_in_cname_www1;  // www1.example.com IN CNAME
-    RRsetPtr    rrs_in_cname_www2;  // www2.example.com IN CNAME
-    RRsetPtr    rrs_in_ns_;         // example.com IN NS
-    RRsetPtr    rrs_in_soa_;        // example.com IN SOA
-    RRsetPtr    rrs_in_txt_www;     // www.example.com IN TXT
-    Name        cname_target;       // Used in response classifier to
-                                    // store the target of a possible
-                                    // CNAME chain
-    unsigned int cname_count;       // Used to count cnames in a chain
-};
-
-// Test that the error() function categorises the codes correctly.
-
-TEST_F(ResponseClassifierTest, StatusCodes) {
-    EXPECT_FALSE(ResponseClassifier::error(ResponseClassifier::ANSWER));
-    EXPECT_FALSE(ResponseClassifier::error(ResponseClassifier::ANSWERCNAME));
-    EXPECT_FALSE(ResponseClassifier::error(ResponseClassifier::CNAME));
-    EXPECT_FALSE(ResponseClassifier::error(ResponseClassifier::NXDOMAIN));
-    EXPECT_FALSE(ResponseClassifier::error(ResponseClassifier::REFERRAL));
-
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::EMPTY));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::EXTRADATA));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::INVNAMCLASS));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::INVTYPE));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::MISMATQUEST));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::MULTICLASS));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::NOTONEQUEST));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::NOTRESPONSE));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::NOTSINGLE));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::OPCODE));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::RCODE));
-    EXPECT_TRUE(ResponseClassifier::error(ResponseClassifier::TRUNCATED));
-}
-
-// Test that the system will reject a message which is a query.
-
-TEST_F(ResponseClassifierTest, Query) {
-
-    // Set up message to indicate a query (QR flag = 0, one question).  By
-    // default the opcode will be 0 (query)
-    msg_a.setHeaderFlag(Message::HEADERFLAG_QR, false);
-
-    // Should be rejected as it is a query, not a response
-    EXPECT_EQ(ResponseClassifier::NOTRESPONSE,
-        ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                     cname_target, cname_count));
-}
-
-// Check that we get an OPCODE error on all but QUERY opcodes.
-
-TEST_F(ResponseClassifierTest, Opcode) {
-
-    uint8_t query = static_cast<uint8_t>(Opcode::QUERY().getCode());
-
-    for (uint8_t i = 0; i < (1 << 4); ++i) {
-        msg_a.setOpcode(Opcode(i));
-        if (i == query) {
-            EXPECT_NE(ResponseClassifier::OPCODE,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        } else {
-            EXPECT_EQ(ResponseClassifier::OPCODE,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        }
-    }
-}
-
-// Test that the system will reject a response with anything other than one
-// question.
-
-TEST_F(ResponseClassifierTest, MultipleQuestions) {
-
-    // Create a message object for this test that has no question section.
-    Message message(Message::RENDER);
-    message.setHeaderFlag(Message::HEADERFLAG_QR);
-    message.setOpcode(Opcode::QUERY());
-    message.setRcode(Rcode::NOERROR());
-
-    // Zero questions
-    EXPECT_EQ(ResponseClassifier::NOTONEQUEST,
-        ResponseClassifier::classify(qu_in_a_www, message,
-                                     cname_target, cname_count));
-
-    // One question
-    message.addQuestion(qu_in_a_www);
-    EXPECT_NE(ResponseClassifier::NOTONEQUEST,
-        ResponseClassifier::classify(qu_in_a_www, message,
-                                     cname_target, cname_count));
-
-    // Two questions
-    message.addQuestion(qu_in_ns_);
-    EXPECT_EQ(ResponseClassifier::NOTONEQUEST,
-        ResponseClassifier::classify(qu_in_a_www, message,
-                                     cname_target, cname_count));
-
-    // And finish the check with three questions
-    message.addQuestion(qu_in_txt_www);
-    EXPECT_EQ(ResponseClassifier::NOTONEQUEST,
-        ResponseClassifier::classify(qu_in_a_www, message,
-                                     cname_target, cname_count));
-}
-
-// Test that the question in the question section in the message response
-// is equal to the question supplied.
-
-TEST_F(ResponseClassifierTest, SameQuestion) {
-
-    EXPECT_EQ(ResponseClassifier::MISMATQUEST,
-        ResponseClassifier::classify(qu_in_ns_, msg_a,
-                                     cname_target, cname_count));
-    EXPECT_NE(ResponseClassifier::MISMATQUEST,
-        ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                     cname_target, cname_count));
-}
-
-// Should get an NXDOMAIN response only on an NXDOMAIN RCODE.
-
-TEST_F(ResponseClassifierTest, NXDOMAIN) {
-
-    uint16_t nxdomain = static_cast<uint16_t>(Rcode::NXDOMAIN().getCode());
-
-    for (uint8_t i = 0; i < (1 << 4); ++i) {
-        msg_a.setRcode(Rcode(i));
-        if (i == nxdomain) {
-            EXPECT_EQ(ResponseClassifier::NXDOMAIN,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        } else {
-            EXPECT_NE(ResponseClassifier::NXDOMAIN,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        }
-    }
-}
-
-// Check that we get an RCODE error on all but NXDOMAIN and NOERROR responses.
-
-TEST_F(ResponseClassifierTest, RCODE) {
-
-    uint16_t nxdomain = static_cast<uint16_t>(Rcode::NXDOMAIN().getCode());
-    uint16_t noerror = static_cast<uint16_t>(Rcode::NOERROR().getCode());
-
-    for (uint8_t i = 0; i < (1 << 4); ++i) {
-        msg_a.setRcode(Rcode(i));
-        if ((i == nxdomain) || (i == noerror)) {
-            EXPECT_NE(ResponseClassifier::RCODE,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        } else {
-            EXPECT_EQ(ResponseClassifier::RCODE,
-                ResponseClassifier::classify(qu_in_a_www, msg_a,
-                                             cname_target, cname_count));
-        }
-    }
-}
-
-// Test that the code will detect a truncated message.  Even if nothing else
-// is wrong, we'll want to retry the query if we receive a truncated code.
-// However, we give the option to the user of the code aws to whether they
-// want to take into account the truncated bit.
-
-TEST_F(ResponseClassifierTest, Truncated) {
-
-    // Don't expect the truncated code whatever option we ask for if the TC
-    // bit is not set.
-    msg_a.setHeaderFlag(Message::HEADERFLAG_TC, false);
-    EXPECT_NE(ResponseClassifier::TRUNCATED,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count, true));
-    EXPECT_NE(ResponseClassifier::TRUNCATED,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count, false));
-
-    // Expect the truncated code if the TC bit is set, only if we don't ignore
-    // it.
-    msg_a.setHeaderFlag(Message::HEADERFLAG_TC, true);
-    EXPECT_NE(ResponseClassifier::TRUNCATED,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count, true));
-    EXPECT_EQ(ResponseClassifier::TRUNCATED,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count, false));
-}
-
-// Check for an empty packet (i.e. no error, but with the answer and additional
-// sections empty).
-
-TEST_F(ResponseClassifierTest, Empty) {
-
-    EXPECT_EQ(ResponseClassifier::EMPTY,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count));
-}
-
-// Anything where we have an empty answer section but something in the
-// authority section is a referral (if the status is NOERROR).
-
-TEST_F(ResponseClassifierTest, EmptyAnswerReferral) {
-
-    msg_a.addRRset(Message::SECTION_AUTHORITY, rrs_in_ns_);
-    EXPECT_EQ(ResponseClassifier::REFERRAL,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count));
-
-}
-
-// Test if we get a NOERROR answer that contains neither an actual
-// answer nor a delegation
-TEST_F(ResponseClassifierTest, NoErrorNoData) {
-
-    msg_a.addRRset(Message::SECTION_AUTHORITY, rrs_in_soa_);
-    EXPECT_EQ(ResponseClassifier::NXRRSET,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count));
-
-}
-
-// Check the case where we have a simple answer in the answer section.  This
-// occurs when the QNAME/QTYPE/QCLASS matches one of the RRsets in the
-// answer section - expect when the QTYPE is ANY, in which case the match
-// must be on the QNAME/QCLASS alone.
-
-TEST_F(ResponseClassifierTest, SingleAnswer) {
-
-    // Check a question that matches the answer
-    msg_a.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    EXPECT_EQ(ResponseClassifier::ANSWER,
-        ResponseClassifier::classify(qu_in_a_www, msg_a, cname_target,
-                                     cname_count));
-
-    // Check an ANY question that matches the answer
-    msg_any.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    EXPECT_EQ(ResponseClassifier::ANSWER,
-        ResponseClassifier::classify(qu_in_any_www, msg_any, cname_target,
-                                     cname_count));
-
-    // Check a CNAME response that matches the QNAME.
-    Message message_a(Message::RENDER);
-    message_a.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_a.setOpcode(Opcode::QUERY());
-    message_a.setRcode(Rcode::NOERROR());
-    message_a.addQuestion(qu_in_cname_www1);
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_cname_www1);
-    EXPECT_EQ(ResponseClassifier::CNAME,
-        ResponseClassifier::classify(qu_in_cname_www1, message_a,
-                                     cname_target, cname_count));
-
-    // Check if the answer QNAME does not match the question
-    // Q: www.example.com  IN A
-    // A: mail.example.com IN A
-    Message message_b(Message::RENDER);
-    message_b.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_b.setOpcode(Opcode::QUERY());
-    message_b.setRcode(Rcode::NOERROR());
-    message_b.addQuestion(qu_in_a_www);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_a_mail);
-    EXPECT_EQ(ResponseClassifier::INVNAMCLASS,
-        ResponseClassifier::classify(qu_in_a_www, message_b,
-                                     cname_target, cname_count));
-
-    // Check if the answer class does not match the question
-    // Q: www.example.com CH A
-    // A: www.example.com IN A
-    Message message_c(Message::RENDER);
-    message_c.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_c.setOpcode(Opcode::QUERY());
-    message_c.setRcode(Rcode::NOERROR());
-    message_c.addQuestion(qu_ch_a_www);
-    message_c.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    EXPECT_EQ(ResponseClassifier::INVNAMCLASS,
-        ResponseClassifier::classify(qu_ch_a_www, message_c,
-                                     cname_target, cname_count));
-
-    // Check if the answer type does not match the question
-    // Q: www.example.com IN A
-    // A: www.example.com IN TXT
-    Message message_d(Message::RENDER);
-    message_d.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_d.setOpcode(Opcode::QUERY());
-    message_d.setRcode(Rcode::NOERROR());
-    message_d.addQuestion(qu_in_a_www);
-    message_d.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-    EXPECT_EQ(ResponseClassifier::INVTYPE,
-        ResponseClassifier::classify(qu_in_a_www, message_d,
-                                     cname_target, cname_count));
-}
-
-// Check what happens if we have multiple RRsets in the answer.
-
-TEST_F(ResponseClassifierTest, MultipleAnswerRRsets) {
-
-    // All the same QNAME but different types is only valid on an ANY query.
-    Message message_a(Message::RENDER);
-    message_a.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_a.setOpcode(Opcode::QUERY());
-    message_a.setRcode(Rcode::NOERROR());
-    message_a.addQuestion(qu_in_any_www);
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-    EXPECT_EQ(ResponseClassifier::ANSWER,
-        ResponseClassifier::classify(qu_in_any_www, message_a,
-                                     cname_target, cname_count));
-
-    // On another type of query, it results in an EXTRADATA error
-    Message message_b(Message::RENDER);
-    message_b.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_b.setOpcode(Opcode::QUERY());
-    message_b.setRcode(Rcode::NOERROR());
-    message_b.addQuestion(qu_in_a_www);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-    EXPECT_EQ(ResponseClassifier::EXTRADATA,
-        ResponseClassifier::classify(qu_in_a_www, message_b,
-                                     cname_target, cname_count));
-
-    // Same QNAME on an ANY query is not valid with mixed classes
-    Message message_c(Message::RENDER);
-    message_c.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_c.setOpcode(Opcode::QUERY());
-    message_c.setRcode(Rcode::NOERROR());
-    message_c.addQuestion(qu_in_any_www);
-    message_c.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    message_c.addRRset(Message::SECTION_ANSWER, rrs_hs_txt_www);
-    EXPECT_EQ(ResponseClassifier::MULTICLASS,
-        ResponseClassifier::classify(qu_in_any_www, message_c,
-                                     cname_target, cname_count));
-
-    // Mixed QNAME is not valid unless QNAME requested is a CNAME.
-    Message message_d(Message::RENDER);
-    message_d.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_d.setOpcode(Opcode::QUERY());
-    message_d.setRcode(Rcode::NOERROR());
-    message_d.addQuestion(qu_in_a_www);
-    message_d.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    message_d.addRRset(Message::SECTION_ANSWER, rrs_in_a_mail);
-    EXPECT_EQ(ResponseClassifier::EXTRADATA,
-        ResponseClassifier::classify(qu_in_a_www, message_d,
-                                     cname_target, cname_count));
-
-    // Mixed QNAME is not valid when the query is an ANY.
-    Message message_e(Message::RENDER);
-    message_e.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_e.setOpcode(Opcode::QUERY());
-    message_e.setRcode(Rcode::NOERROR());
-    message_e.addQuestion(qu_in_any_www);
-    message_e.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    message_e.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-    message_e.addRRset(Message::SECTION_ANSWER, rrs_in_a_mail);
-    EXPECT_EQ(ResponseClassifier::EXTRADATA,
-        ResponseClassifier::classify(qu_in_any_www, message_e,
-                                     cname_target, cname_count));
-}
-
-// CNAME chain is CNAME if it terminates in a CNAME, answer if it
-// does not, and error if there are RRs left over.
-TEST_F(ResponseClassifierTest, CNAMEChain) {
-
-    // Answer contains a single CNAME
-    Message message_a(Message::RENDER);
-    message_a.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_a.setOpcode(Opcode::QUERY());
-    message_a.setRcode(Rcode::NOERROR());
-    message_a.addQuestion(qu_in_a_www2);
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_cname_www2);
-    EXPECT_EQ(ResponseClassifier::CNAME,
-        ResponseClassifier::classify(qu_in_a_www2, message_a,
-                                     cname_target, cname_count));
-
-    // Add a CNAME for www1, and it should still return a CNAME
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_cname_www1);
-    EXPECT_EQ(ResponseClassifier::CNAME,
-        ResponseClassifier::classify(qu_in_a_www2, message_a,
-                                     cname_target, cname_count));
-
-    // Add the A record for www and it should be an answer
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_a_www);
-    EXPECT_EQ(ResponseClassifier::ANSWERCNAME,
-        ResponseClassifier::classify(qu_in_a_www2, message_a,
-                                     cname_target, cname_count));
-
-    // Adding an unrelated TXT record should result in EXTRADATA
-    message_a.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-    EXPECT_EQ(ResponseClassifier::EXTRADATA,
-        ResponseClassifier::classify(qu_in_a_www2, message_a,
-                                     cname_target, cname_count));
-
-    // Recreate the chain, but this time end with a TXT RR and not the A
-    // record.  This should return INVTYPE.
-    Message message_b(Message::RENDER);
-    message_b.setHeaderFlag(Message::HEADERFLAG_QR);
-    message_b.setOpcode(Opcode::QUERY());
-    message_b.setRcode(Rcode::NOERROR());
-    message_b.addQuestion(qu_in_a_www2);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_cname_www2);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_cname_www1);
-    message_b.addRRset(Message::SECTION_ANSWER, rrs_in_txt_www);
-
-    EXPECT_EQ(ResponseClassifier::INVTYPE,
-        ResponseClassifier::classify(qu_in_a_www2, message_b,
-                                     cname_target, cname_count));
-}
-
-} // Anonymous namespace

+ 0 - 27
src/lib/resolve/tests/run_unittests.cc

@@ -1,27 +0,0 @@
-// Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <gtest/gtest.h>
-#include <util/unittests/run_all.h>
-
-#include <dns/tests/unittest_util.h>
-#include <log/logger_support.h>
-
-int
-main(int argc, char* argv[]) {
-    ::testing::InitGoogleTest(&argc, argv);
-    isc::log::initLogger();
-
-    return (isc::util::unittests::run_all());
-}

+ 6 - 3
src/lib/testutils/mockups.h

@@ -22,7 +22,7 @@
 #include <cc/data.h>
 #include <cc/session.h>
 
-#include <xfr/xfrout_client.h>
+//#include <xfr/xfrout_client.h>
 
 #include <asiodns/asiodns.h>
 
@@ -173,8 +173,11 @@ private:
     bool done_;
 };
 
+// Commenting out this class as it is not used anyware. The removal of this class
+// allows for removal of the lib/xfr.
+
 // Mock Xfrout client
-class MockXfroutClient : public isc::xfr::AbstractXfroutClient {
+/*class MockXfroutClient : public isc::xfr::AbstractXfroutClient {
 public:
     MockXfroutClient() :
         is_connected_(false), connect_ok_(true), send_ok_(true),
@@ -215,7 +218,7 @@ private:
     bool connect_ok_;
     bool send_ok_;
     bool disconnect_ok_;
-};
+    }; */
 
 } // end of testutils
 } // end of isc

+ 0 - 15
src/lib/xfr/Makefile.am

@@ -1,15 +0,0 @@
-SUBDIRS = . tests
-
-AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
-AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
-AM_CPPFLAGS += $(BOOST_INCLUDES)
-
-AM_CXXFLAGS = $(B10_CXXFLAGS)
-AM_CXXFLAGS += -Wno-unused-parameter
-# see src/lib/cc/Makefile.am
-
-CLEANFILES = *.gcno *.gcda
-
-lib_LTLIBRARIES = libb10-xfr.la
-libb10_xfr_la_SOURCES = xfrout_client.h xfrout_client.cc
-libb10_xfr_la_LIBADD = $(top_builddir)/src/lib/util/io/libb10-util-io.la

+ 0 - 1
src/lib/xfr/tests/.gitignore

@@ -1 +0,0 @@
-/run_unittests

+ 0 - 28
src/lib/xfr/tests/Makefile.am

@@ -1,28 +0,0 @@
-AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
-AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CXXFLAGS = $(B10_CXXFLAGS)
-
-if USE_STATIC_LINK
-AM_LDFLAGS = -static
-endif
-
-CLEANFILES = *.gcno *.gcda
-
-TESTS_ENVIRONMENT = \
-        $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
-
-TESTS =
-if HAVE_GTEST
-TESTS += run_unittests
-run_unittests_SOURCES = run_unittests.cc client_test.cc
-
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
-run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
-
-run_unittests_LDADD = $(GTEST_LDADD)
-run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
-run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libb10-xfr.la
-run_unittests_LDADD += $(top_builddir)/src/lib/log/libb10-log.la
-endif
-
-noinst_PROGRAMS = $(TESTS)

+ 0 - 37
src/lib/xfr/tests/client_test.cc

@@ -1,37 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <gtest/gtest.h>
-
-#include <sys/un.h>
-#include <string>
-
-#include <xfr/xfrout_client.h>
-
-using namespace std;
-using namespace isc::xfr;
-
-namespace {
-
-TEST(ClientTest, connectFile) {
-    // File path is too long
-    struct sockaddr_un s;     // can't be const; some compiler complains
-    EXPECT_THROW(XfroutClient(string(sizeof(s.sun_path), 'x')).connect(),
-                 XfroutError);
-
-    // File doesn't exist (we assume the file "no_such_file" doesn't exist)
-    EXPECT_THROW(XfroutClient("no_such_file").connect(), XfroutError);
-}
-
-}

+ 0 - 24
src/lib/xfr/tests/run_unittests.cc

@@ -1,24 +0,0 @@
-// Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <gtest/gtest.h>
-#include <log/logger_support.h>
-#include <util/unittests/run_all.h>
-
-int
-main(int argc, char* argv[]) {
-    ::testing::InitGoogleTest(&argc, argv);
-    isc::log::initLogger();
-    return (isc::util::unittests::run_all());
-}

+ 0 - 108
src/lib/xfr/xfrout_client.cc

@@ -1,108 +0,0 @@
-// 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.
-
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-
-// for some IPC/network system calls in asio/detail/pipe_select_interrupter.hpp
-#include <unistd.h>
-#include <asio.hpp>
-
-#include <util/io/fd_share.h>
-#include <xfr/xfrout_client.h>
-
-using namespace std;
-using namespace isc::util::io;
-using asio::local::stream_protocol;
-
-namespace isc {
-namespace xfr {
-
-struct XfroutClientImpl {
-    XfroutClientImpl(const string& file);
-    const std::string file_path_;
-    asio::io_service io_service_;
-    // The socket used to communicate with the xfrout server.
-    stream_protocol::socket socket_;
-};
-
-XfroutClientImpl::XfroutClientImpl(const string& file) :
-    file_path_(file), socket_(io_service_)
-{}
-
-XfroutClient::XfroutClient(const string& file) :
-    impl_(new XfroutClientImpl(file))
-{}
-
-XfroutClient::~XfroutClient() {
-    delete impl_;
-}
-
-void
-XfroutClient::connect() {
-    try {
-        impl_->socket_.connect(stream_protocol::endpoint(impl_->file_path_));
-    } catch (const asio::system_error& err) {
-        isc_throw(XfroutError, "socket connect failed for " <<
-                  impl_->file_path_ << ": " << err.what());
-    }
-}
-
-void
-XfroutClient::disconnect() {
-    asio::error_code err;
-    impl_->socket_.close(err);
-    if (err) {
-        isc_throw(XfroutError, "close socket failed: " << err.message());
-    }
-}
-
-int
-XfroutClient::sendXfroutRequestInfo(const int tcp_sock,
-                                    const void* const msg_data,
-                                    const uint16_t msg_len)
-{
-    if (send_fd(impl_->socket_.native(), tcp_sock) < 0) {
-        isc_throw(XfroutError,
-                  "Failed to send the socket file descriptor "
-                  "to xfrout module");
-    }
-
-    // TODO: this shouldn't be blocking send, even though it's unlikely to
-    // block.
-    // Converting the 16-bit word to network byte order.
-
-    // Splitting msg_len below performs something called a 'narrowing
-    // conversion' (conversion of uint16_t to uint8_t). C++0x (and GCC
-    // 4.7) requires explicit casting when a narrowing conversion is
-    // performed. For reference, see 8.5.4/6 of n3225.
-    const uint8_t lenbuf[2] = { static_cast<uint8_t>(msg_len >> 8),
-                                static_cast<uint8_t>(msg_len & 0xff) };
-    if (send(impl_->socket_.native(), lenbuf, sizeof(lenbuf), 0) !=
-        sizeof(lenbuf)) {
-        isc_throw(XfroutError,
-                  "failed to send XFR request length to xfrout module");
-    }
-    if (send(impl_->socket_.native(), msg_data, msg_len, 0) != msg_len) {
-        isc_throw(XfroutError,
-                  "failed to send XFR request data to xfrout module");
-    }
-
-    return (0);
-}
-
-} // End for xfr
-} // End for isc
-

+ 0 - 91
src/lib/xfr/xfrout_client.h

@@ -1,91 +0,0 @@
-// 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.
-
-#ifndef XFROUT_CLIENT_H
-#define XFROUT_CLIENT_H
-
-#include <stdint.h>
-
-#include <string>
-
-#include <exceptions/exceptions.h>
-
-namespace isc {
-namespace xfr {
-
-struct XfroutClientImpl;
-
-class XfroutError: public Exception {
-public:
-    XfroutError(const char *file, size_t line, const char *what):
-        isc::Exception(file, line, what) {}
-};
-
-/// \brief The AbstractXfroutClient class is an abstract base class that
-/// defines the interfaces of XfroutClient.
-///
-/// The intended primary usage of abstraction is to allow tests for the
-/// user class of XfroutClient without requiring actual communication.
-class AbstractXfroutClient {
-    ///
-    /// \name Constructors, Assignment Operator and Destructor.
-    ///
-    /// Note: The copy constructor and the assignment operator are
-    /// intentionally defined as private to make it explicit that this is a
-    /// pure base class.
-    //@{
-private:
-    AbstractXfroutClient(const AbstractXfroutClient& source);
-    AbstractXfroutClient& operator=(const AbstractXfroutClient& source);
-protected:
-    /// \brief The default constructor.
-    ///
-    /// This is intentionally defined as \c protected as this base class should
-    /// never be instantiated (except as part of a derived class).
-    AbstractXfroutClient() {}
-public:
-    /// \brief The destructor.
-    virtual ~AbstractXfroutClient() {}
-    //@}
-    virtual void connect() = 0;
-    virtual void disconnect() = 0;
-    virtual int sendXfroutRequestInfo(int tcp_sock, const void* msg_data,
-                                      uint16_t msg_len) = 0;
-};
-
-class XfroutClient : public AbstractXfroutClient {
-public:
-    XfroutClient(const std::string& file);
-    ~XfroutClient();
-private:
-    // make this class non copyable
-    XfroutClient(const XfroutClient& source);
-    XfroutClient& operator=(const XfroutClient& source);
-public:
-    virtual void connect();
-    virtual void disconnect();
-    virtual int sendXfroutRequestInfo(int tcp_sock, const void* msg_data,
-                                      uint16_t msg_len);
-private:
-    XfroutClientImpl* impl_;
-};
-
-} // End for namespace xfr
-} // End for namespace isc
-
-#endif
-
-// Local Variables: 
-// mode: c++
-// End: