Browse Source

[3065] Moved classes pertaining to sending and receiving
NameChangeRequests from src/bin/d2 into their own library,
libdhcp_ddns, in src/lib/dhcp_ddns.

Thomas Markwalder 11 years ago
parent
commit
a3e5965736

+ 2 - 0
configure.ac

@@ -1316,6 +1316,8 @@ AC_CONFIG_FILES([Makefile
                  src/lib/dns/benchmarks/Makefile
                  src/lib/dhcp/Makefile
                  src/lib/dhcp/tests/Makefile
+                 src/lib/dhcp_ddns/Makefile
+                 src/lib/dhcp_ddns/tests/Makefile
                  src/lib/dhcpsrv/Makefile
                  src/lib/dhcpsrv/tests/Makefile
                  src/lib/exceptions/Makefile

+ 1 - 3
src/bin/d2/Makefile.am

@@ -57,9 +57,6 @@ b10_dhcp_ddns_SOURCES += d2_cfg_mgr.cc d2_cfg_mgr.h
 b10_dhcp_ddns_SOURCES += d2_update_message.cc d2_update_message.h
 b10_dhcp_ddns_SOURCES += d2_zone.cc d2_zone.h
 b10_dhcp_ddns_SOURCES += dns_client.cc dns_client.h
-b10_dhcp_ddns_SOURCES += ncr_io.cc ncr_io.h
-b10_dhcp_ddns_SOURCES += ncr_msg.cc ncr_msg.h
-b10_dhcp_ddns_SOURCES += ncr_udp.cc ncr_udp.h
 
 nodist_b10_dhcp_ddns_SOURCES = d2_messages.h d2_messages.cc
 EXTRA_DIST += d2_messages.mes
@@ -70,6 +67,7 @@ b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/cc/libb10-cc.la
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/asiodns/libb10-asiodns.la
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/config/libb10-cfgclient.la
+b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libb10-dhcp_ddns.la
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/dhcpsrv/libb10-dhcpsrv.la 
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/dns/libb10-dns++.la
 b10_dhcp_ddns_LDADD += $(top_builddir)/src/lib/util/libb10-util.la

+ 1 - 5
src/bin/d2/tests/Makefile.am

@@ -62,9 +62,6 @@ d2_unittests_SOURCES += ../d2_cfg_mgr.cc ../d2_cfg_mgr.h
 d2_unittests_SOURCES += ../d2_update_message.cc ../d2_update_message.h
 d2_unittests_SOURCES += ../d2_zone.cc ../d2_zone.h
 d2_unittests_SOURCES += ../dns_client.cc ../dns_client.h
-d2_unittests_SOURCES += ../ncr_io.cc ../ncr_io.h
-d2_unittests_SOURCES += ../ncr_msg.cc ../ncr_msg.h
-d2_unittests_SOURCES += ../ncr_udp.cc ../ncr_udp.h
 d2_unittests_SOURCES += d_test_stubs.cc d_test_stubs.h
 d2_unittests_SOURCES += d2_unittests.cc
 d2_unittests_SOURCES += d2_process_unittests.cc
@@ -75,8 +72,6 @@ d2_unittests_SOURCES += d2_cfg_mgr_unittests.cc
 d2_unittests_SOURCES += d2_update_message_unittests.cc
 d2_unittests_SOURCES += d2_zone_unittests.cc
 d2_unittests_SOURCES += dns_client_unittests.cc
-d2_unittests_SOURCES += ncr_unittests.cc
-d2_unittests_SOURCES += ncr_udp_unittests.cc
 nodist_d2_unittests_SOURCES = ../d2_messages.h ../d2_messages.cc
 
 d2_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
@@ -88,6 +83,7 @@ d2_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libb10-asiodns.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/cc/libb10-cc.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/config/libb10-cfgclient.la
+d2_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libb10-dhcp_ddns.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libb10-dhcpsrv.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dns/libb10-dns++.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la

+ 1 - 1
src/lib/Makefile.am

@@ -1,3 +1,3 @@
 SUBDIRS = exceptions util log hooks cryptolink dns cc config acl xfr bench \
           asiolink asiodns nsas cache resolve testutils datasrc \
-          server_common python dhcp dhcpsrv statistics
+          server_common python dhcp dhcp_ddns dhcpsrv statistics

+ 51 - 0
src/lib/dhcp_ddns/Makefile.am

@@ -0,0 +1,51 @@
+SUBDIRS = . tests
+
+AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CXXFLAGS  = $(B10_CXXFLAGS)
+
+# Some versions of GCC warn about some versions of Boost regarding
+# missing initializer for members in its posix_time.
+# https://svn.boost.org/trac/boost/ticket/3477
+# But older GCC compilers don't have the flag.
+AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
+
+
+# Define rule to build logging source files from message file
+dhcp_ddns_messages.h dhcp_ddns_messages.cc: dhcp_ddns_messages.mes
+	$(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/dhcp_ddns/dhcp_ddns_messages.mes
+
+# Tell automake that the message files are built as part of the build process
+# (so that they are built before the main library is built).
+BUILT_SOURCES = dhcp_ddns_messages.h dhcp_ddns_messages.cc
+
+# Ensure that the message file is included in the distribution
+EXTRA_DIST = dhcp_ddns_messages.mes
+
+# Get rid of generated message files on a clean
+CLEANFILES = *.gcno *.gcda dhcp_ddns_messages.h dhcp_ddns_messages.cc
+
+lib_LTLIBRARIES = libb10-dhcp_ddns.la
+libb10_dhcp_ddns_la_SOURCES  =
+libb10_dhcp_ddns_la_SOURCES += dhcp_ddns_log.cc dhcp_ddns_log.h
+libb10_dhcp_ddns_la_SOURCES += ncr_io.cc ncr_io.h
+libb10_dhcp_ddns_la_SOURCES += ncr_msg.cc ncr_msg.h
+libb10_dhcp_ddns_la_SOURCES += ncr_udp.cc ncr_udp.h
+
+nodist_libb10_dhcp_ddns_la_SOURCES = dhcp_ddns_messages.cc dhcp_ddns_messages.h
+
+libb10_dhcp_ddns_la_CXXFLAGS = $(AM_CXXFLAGS)
+libb10_dhcp_ddns_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
+libb10_dhcp_ddns_la_LDFLAGS  = $(AM_LDFLAGS)
+libb10_dhcp_ddns_la_LIBADD  =
+libb10_dhcp_ddns_la_LIBADD += $(top_builddir)/src/lib/log/libb10-log.la
+libb10_dhcp_ddns_la_LIBADD += $(top_builddir)/src/lib/util/libb10-util.la
+libb10_dhcp_ddns_la_LIBADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
+libb10_dhcp_ddns_la_LIBADD += $(top_builddir)/src/lib/config/libb10-cfgclient.la
+
+if USE_CLANGPP
+# Disable unused parameter warning caused by some of the
+# Boost headers when compiling with clang.
+libb10_dhcp_ddns_la_CXXFLAGS += -Wno-unused-parameter
+endif
+

+ 27 - 0
src/lib/dhcp_ddns/dhcp_ddns_log.cc

@@ -0,0 +1,27 @@
+// Copyright (C) 2013  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 top-level component of b10-dhcp_ddns.
+
+#include <dhcp_ddns/dhcp_ddns_log.h>
+
+namespace isc {
+namespace dhcp_ddns {
+
+/// @brief Defines the logger used within lib dhcp_ddns.
+isc::log::Logger dhcp_ddns_logger("libdhcp-ddns");
+
+} // namespace dhcp_ddns
+} // namespace isc
+

+ 31 - 0
src/lib/dhcp_ddns/dhcp_ddns_log.h

@@ -0,0 +1,31 @@
+// Copyright (C) 2013  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 DHCP_DDNS_LOG_H
+#define DHCP_DDNS_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <dhcp_ddns/dhcp_ddns_messages.h>
+
+namespace isc {
+namespace dhcp_ddns {
+
+/// Define the logger for the "dhcp_ddns" logging.
+extern isc::log::Logger dhcp_ddns_logger;
+
+} // namespace dhcp_ddns
+} // namespace isc
+
+#endif // DHCP_DDNS_LOG_H

+ 63 - 0
src/lib/dhcp_ddns/dhcp_ddns_messages.mes

@@ -0,0 +1,63 @@
+# Copyright (C) 2013  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::dhcp_ddns
+
+% DHCP_DDNS_INVALID_NCR application received an invalid DNS update request: %1
+This is an error message that indicates that an invalid request to update
+a DNS entry was received by the application.  Either the format or the content
+of the request is incorrect. The request will be ignored.
+
+% DHCP_DDNS_NCR_LISTEN_CLOSE_ERROR application encountered an error while closing the listener used to receive NameChangeRequests : %1
+This is an error message that indicates the application was unable to close the
+listener connection used to receive NameChangeRequests.  Closure may occur
+during the course of error recovery or during normal shutdown procedure.  In
+either case the error is unlikely to impair the application's ability to
+process requests but it should be reported for analysis.
+
+% DHCP_DDNS_NCR_RECV_NEXT_ERROR application could not initiate the next read following a request receive.
+This is a error message indicating that NameChangeRequest listener could not
+start another read after receiving a request.  While possible, this is highly
+unlikely and is probably a programmatic error.  The application should recover
+on its own.
+
+% DHCP_DDNS_NCR_SEND_CLOSE_ERROR DHCP-DDNS client encountered an error while closing the sender connection used to send NameChangeRequests : %1
+This is an error message that indicates the DHCP-DDNS client was unable to
+close the connection used to send NameChangeRequests.  Closure may occur during
+the course of error recovery or during normal shutdown procedure.  In either
+case the error is unlikely to impair the client's ability to send requests but
+it should be reported for analysis.
+
+% DHCP_DDNS_NCR_SEND_NEXT_ERROR DHCP-DDNS client could not initiate the next request send following send completion.
+This is a error message indicating that NameChangeRequest sender could not
+start another send after completing the send of the previous request.  While
+possible, this is highly unlikely and is probably a programmatic error.  The
+application should recover on its own.
+
+% DHCP_DDNS_NCR_UDP_RECV_ERROR UDP socket receive error while listening for DNS Update requests: %1
+This is an error message indicating that an IO error occurred while listening
+over a UDP socket for DNS update requests. This could indicate a network
+connectivity or system resource issue.
+
+% DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR unexpected exception thrown from the application receive completion handler: %1
+This is an error message that indicates that an exception was thrown but not
+caught in the application's request receive completion handler.  This is a
+programmatic error that needs to be reported.  Dependent upon the nature of
+the error the application may or may not continue operating normally.
+
+% DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR unexpected exception thrown from the DHCP-DDNS client send completion handler: %1
+This is an error message that indicates that an exception was thrown but not
+caught in the application's send completion handler.  This is a programmatic
+error that needs to be reported.  Dependent upon the nature of the error the
+client may or may not continue operating normally.

+ 17 - 15
src/bin/d2/ncr_io.cc

@@ -12,11 +12,11 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <d2/d2_log.h>
-#include <d2/ncr_io.h>
+#include <dhcp_ddns/dhcp_ddns_log.h>
+#include <dhcp_ddns/ncr_io.h>
 
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 //************************** NameChangeListener ***************************
 
@@ -60,7 +60,8 @@ NameChangeListener::stopListening() {
     } catch (const isc::Exception &ex) {
         // Swallow exceptions. If we have some sort of error we'll log
         // it but we won't propagate the throw.
-        LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_LISTEN_CLOSE_ERROR).arg(ex.what());
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_LISTEN_CLOSE_ERROR)
+                  .arg(ex.what());
     }
 
     // Set it false, no matter what.  This allows us to at least try to
@@ -78,7 +79,7 @@ NameChangeListener::invokeRecvHandler(const Result result,
     try {
         recv_handler_(result, ncr);
     } catch (const std::exception& ex) {
-        LOG_ERROR(dctl_logger, DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR)
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR)
                   .arg(ex.what());
     }
 
@@ -95,7 +96,7 @@ NameChangeListener::invokeRecvHandler(const Result result,
             // at the IOService::run (or run variant) invocation.  So we will
             // close the window by invoking the application handler with
             // a failed result, and let the application layer sort it out.
-            LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_RECV_NEXT_ERROR)
+            LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_RECV_NEXT_ERROR)
                       .arg(ex.what());
 
             // Call the registered application layer handler.
@@ -106,7 +107,7 @@ NameChangeListener::invokeRecvHandler(const Result result,
             try {
                 recv_handler_(ERROR, empty);
             } catch (const std::exception& ex) {
-                LOG_ERROR(dctl_logger,
+                LOG_ERROR(dhcp_ddns_logger,
                           DHCP_DDNS_UNCAUGHT_NCR_RECV_HANDLER_ERROR)
                           .arg(ex.what());
             }
@@ -158,7 +159,8 @@ NameChangeSender::stopSending() {
     } catch (const isc::Exception &ex) {
         // Swallow exceptions. If we have some sort of error we'll log
         // it but we won't propagate the throw.
-        LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_SEND_CLOSE_ERROR).arg(ex.what());
+        LOG_ERROR(dhcp_ddns_logger, 
+                  DHCP_DDNS_NCR_SEND_CLOSE_ERROR).arg(ex.what());
     }
 
     // Set it false, no matter what.  This allows us to at least try to
@@ -199,7 +201,7 @@ NameChangeSender::sendNext() {
 
     // If queue isn't empty, then get one from the front. Note we leave
     // it on the front of the queue until we successfully send it.
-    if (send_queue_.size()) {
+    if (!send_queue_.empty()) {
         ncr_to_send_ = send_queue_.front();
 
        // @todo start defense timer
@@ -227,7 +229,7 @@ NameChangeSender::invokeSendHandler(const NameChangeSender::Result result) {
     try {
         send_handler_(result, ncr_to_send_);
     } catch (const std::exception& ex) {
-        LOG_ERROR(dctl_logger, DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR)
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR)
                   .arg(ex.what());
     }
 
@@ -244,7 +246,7 @@ NameChangeSender::invokeSendHandler(const NameChangeSender::Result result) {
         // at the IOService::run (or run variant) invocation.  So we will
         // close the window by invoking the application handler with
         // a failed result, and let the application layer sort it out.
-        LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_SEND_NEXT_ERROR)
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_SEND_NEXT_ERROR)
                   .arg(ex.what());
 
         // Invoke the completion handler passing in failed result.
@@ -254,15 +256,15 @@ NameChangeSender::invokeSendHandler(const NameChangeSender::Result result) {
         try {
             send_handler_(ERROR, ncr_to_send_);
         } catch (const std::exception& ex) {
-            LOG_ERROR(dctl_logger, DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR)
-                      .arg(ex.what());
+            LOG_ERROR(dhcp_ddns_logger, 
+                      DHCP_DDNS_UNCAUGHT_NCR_SEND_HANDLER_ERROR).arg(ex.what());
         }
     }
 }
 
 void
 NameChangeSender::skipNext() {
-    if (send_queue_.size()) {
+    if (!send_queue_.empty()) {
         // Discards the request at the front of the queue.
         send_queue_.pop_front();
     }
@@ -277,5 +279,5 @@ NameChangeSender::clearSendQueue() {
     send_queue_.clear();
 }
 
-} // namespace isc::d2
+} // namespace isc::dhcp_ddns
 } // namespace isc

+ 9 - 3
src/bin/d2/ncr_io.h

@@ -58,13 +58,13 @@
 
 #include <asiolink/io_address.h>
 #include <asiolink/io_service.h>
-#include <d2/ncr_msg.h>
+#include <dhcp_ddns/ncr_msg.h>
 #include <exceptions/exceptions.h>
 
 #include <deque>
 
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 /// @brief Exception thrown if an NcrListenerError encounters a general error.
 class NcrListenerError : public isc::Exception {
@@ -171,6 +171,9 @@ public:
         /// @throw This method MUST NOT throw.
         virtual void operator ()(const Result result,
                                  NameChangeRequestPtr& ncr) = 0;
+
+        virtual ~RequestReceiveHandler() {
+        }
     };
 
     /// @brief Constructor
@@ -435,6 +438,9 @@ public:
         /// @throw This method MUST NOT throw.
         virtual void operator ()(const Result result,
                                  NameChangeRequestPtr& ncr) = 0;
+
+        virtual ~RequestSendHandler() {
+        }
     };
 
     /// @brief Constructor
@@ -626,7 +632,7 @@ private:
 /// @brief Defines a smart pointer to an instance of a sender.
 typedef boost::shared_ptr<NameChangeSender> NameChangeSenderPtr;
 
-} // namespace isc::d2
+} // namespace isc::dhcp_ddns
 } // namespace isc
 
 #endif

+ 2 - 2
src/bin/d2/ncr_msg.cc

@@ -12,7 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <d2/ncr_msg.h>
+#include <dhcp_ddns/ncr_msg.h>
 #include <asiolink/io_address.h>
 #include <asiolink/io_error.h>
 
@@ -20,7 +20,7 @@
 #include <limits>
 
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 /********************************* D2Dhcid ************************************/
 

+ 3 - 3
src/bin/d2/ncr_msg.h

@@ -30,7 +30,7 @@
 #include <string>
 
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 /// @brief Exception thrown when NameChangeRequest marshalling error occurs.
 class NcrMessageError : public isc::Exception {
@@ -105,7 +105,7 @@ public:
     }
 
     /// @brief Compares two D2Dhcids for inequality
-    bool operator!=(const D2Dhcid other) const {
+    bool operator!=(const D2Dhcid& other) const {
         return (this->bytes_ != other.bytes_);
 }
 
@@ -494,7 +494,7 @@ private:
 };
 
 
-}; // end of isc::d2 namespace
+}; // end of isc::dhcp_ddns namespace
 }; // end of isc namespace
 
 #endif

+ 7 - 7
src/bin/d2/ncr_udp.cc

@@ -12,15 +12,15 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <d2/d2_log.h>
-#include <d2/ncr_udp.h>
+#include <dhcp_ddns/dhcp_ddns_log.h>
+#include <dhcp_ddns/ncr_udp.h>
 
 #include <asio/ip/udp.hpp>
 #include <asio/error_code.hpp>
 #include <boost/bind.hpp>
 
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 //*************************** UDPCallback ***********************
 UDPCallback::UDPCallback (RawBufferPtr& buffer, const size_t buf_size,
@@ -161,7 +161,7 @@ NameChangeUDPListener::receiveCompletionHandler(const bool successful,
             ncr = NameChangeRequest::fromFormat(format_, input_buffer);
         } catch (const NcrMessageError& ex) {
             // log it and go back to listening
-            LOG_ERROR(dctl_logger, DHCP_DDNS_INVALID_NCR).arg(ex.what());
+            LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_INVALID_NCR).arg(ex.what());
 
             // Queue up the next recieve.
             doReceive();
@@ -169,7 +169,7 @@ NameChangeUDPListener::receiveCompletionHandler(const bool successful,
         }
     } else {
         asio::error_code error_code = callback->getErrorCode();
-        LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_UDP_RECV_ERROR)
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_UDP_RECV_ERROR)
                   .arg(error_code.message());
         result = ERROR;
     }
@@ -286,7 +286,7 @@ NameChangeUDPSender::sendCompletionHandler(const bool successful,
     else {
         // On a failure, log the error and set the result to ERROR.
         asio::error_code error_code = send_callback->getErrorCode();
-        LOG_ERROR(dctl_logger, DHCP_DDNS_NCR_UDP_RECV_ERROR)
+        LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_UDP_RECV_ERROR)
                   .arg(error_code.message());
 
         result = ERROR;
@@ -295,5 +295,5 @@ NameChangeUDPSender::sendCompletionHandler(const bool successful,
     // Call the application's registered request send handler.
     invokeSendHandler(result);
 }
-}; // end of isc::d2 namespace
+}; // end of isc::dhcp_ddns namespace
 }; // end of isc namespace

+ 3 - 3
src/bin/d2/ncr_udp.h

@@ -111,7 +111,7 @@
 #include <asiolink/io_service.h>
 #include <asiolink/udp_endpoint.h>
 #include <asiolink/udp_socket.h>
-#include <d2/ncr_io.h>
+#include <dhcp_ddns/ncr_io.h>
 #include <util/buffer.h>
 
 #include <boost/shared_array.hpp>
@@ -121,7 +121,7 @@
 /// UDPCallback operator implementation is mostly a pass through.
 ///
 namespace isc {
-namespace d2 {
+namespace dhcp_ddns {
 
 /// @brief Thrown when a UDP level exception occurs.
 class NcrUDPError : public isc::Exception {
@@ -556,7 +556,7 @@ private:
     bool reuse_address_;
 };
 
-} // namespace isc::d2
+} // namespace isc::dhcp_ddns
 } // namespace isc
 
 #endif

+ 58 - 0
src/lib/dhcp_ddns/tests/Makefile.am

@@ -0,0 +1,58 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dhcp_ddns/tests\"
+AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
+
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+# Some versions of GCC warn about some versions of Boost regarding
+# missing initializer for members in its posix_time.
+# https://svn.boost.org/trac/boost/ticket/3477
+# But older GCC compilers don't have the flag.
+AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+	$(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+TESTS =
+if HAVE_GTEST
+TESTS += libdhcp_ddns_unittests
+
+libdhcp_ddns_unittests_SOURCES  = run_unittests.cc
+libdhcp_ddns_unittests_SOURCES += ../dhcp_ddns_log.cc ../dhcp_ddns_log.h
+libdhcp_ddns_unittests_SOURCES += ../ncr_io.cc ../ncr_io.h
+libdhcp_ddns_unittests_SOURCES += ../ncr_msg.cc ../ncr_msg.h
+libdhcp_ddns_unittests_SOURCES += ../ncr_udp.cc ../ncr_udp.h
+libdhcp_ddns_unittests_SOURCES += ncr_unittests.cc
+libdhcp_ddns_unittests_SOURCES += ncr_udp_unittests.cc
+nodist_libdhcp_ddns_unittests_SOURCES = ../dhcp_ddns_messages.h ../dhcp_ddns_messages.cc
+
+libdhcp_ddns_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
+
+libdhcp_ddns_unittests_LDFLAGS  = $(AM_LDFLAGS)  $(GTEST_LDFLAGS)
+
+libdhcp_ddns_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+if USE_CLANGPP
+# This is to workaround unused variables tcout and tcerr in
+# log4cplus's streams.h and unused parameters from some of the
+# Boost headers.
+libdhcp_ddns_unittests_CXXFLAGS += -Wno-unused-parameter
+endif
+
+libdhcp_ddns_unittests_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
+libdhcp_ddns_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
+libdhcp_ddns_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
+libdhcp_ddns_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
+libdhcp_ddns_unittests_LDADD += $(top_builddir)/src/lib/config/libb10-cfgclient.la
+libdhcp_ddns_unittests_LDADD += $(GTEST_LDADD)
+endif
+
+noinst_PROGRAMS = $(TESTS)

+ 3 - 3
src/bin/d2/tests/ncr_udp_unittests.cc

@@ -13,8 +13,8 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <asiolink/interval_timer.h>
-#include <d2/ncr_io.h>
-#include <d2/ncr_udp.h>
+#include <dhcp_ddns/ncr_io.h>
+#include <dhcp_ddns/ncr_udp.h>
 #include <util/time_utilities.h>
 
 #include <asio/ip/udp.hpp>
@@ -25,7 +25,7 @@
 
 using namespace std;
 using namespace isc;
-using namespace isc::d2;
+using namespace isc::dhcp_ddns;
 
 namespace {
 

+ 2 - 2
src/bin/d2/tests/ncr_unittests.cc

@@ -12,7 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <d2/ncr_msg.h>
+#include <dhcp_ddns/ncr_msg.h>
 #include <util/time_utilities.h>
 
 #include <gtest/gtest.h>
@@ -20,7 +20,7 @@
 
 using namespace std;
 using namespace isc;
-using namespace isc::d2;
+using namespace isc::dhcp_ddns;
 
 namespace {
 

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

@@ -0,0 +1,27 @@
+// 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 <log/logger_support.h>
+
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}