[svn] commit: r2921 - /branches/trac191-rebased/src/bin/auth/auth_srv.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Sep 14 15:57:15 UTC 2010


Author: naokikambe
Date: Tue Sep 14 15:57:14 2010
New Revision: 2921

Log:
add ad-hoc implement for query counters in the auth module for the stats module
But it may bring worse performance to the auth module. It must be more considered.
trac #191 .

Modified:
    branches/trac191-rebased/src/bin/auth/auth_srv.cc

Modified: branches/trac191-rebased/src/bin/auth/auth_srv.cc
==============================================================================
--- branches/trac191-rebased/src/bin/auth/auth_srv.cc (original)
+++ branches/trac191-rebased/src/bin/auth/auth_srv.cc Tue Sep 14 15:57:14 2010
@@ -76,6 +76,9 @@
                             MessageRenderer& response_renderer);
     bool processNotify(const IOMessage& io_message, Message& message, 
                             MessageRenderer& response_renderer);
+
+    bool addStatsQueryCount(const IOMessage& io_message);
+
     std::string db_file_;
     ModuleCCSession* config_session_;
     MetaDataSrc data_sources_;
@@ -87,6 +90,7 @@
     bool verbose_mode_;
 
     AbstractSession* xfrin_session_;
+    AbstractSession* stats_session_;
 
     bool xfrout_connected_;
     AbstractXfroutClient& xfrout_client_;
@@ -101,7 +105,7 @@
 AuthSrvImpl::AuthSrvImpl(const bool use_cache,
                          AbstractXfroutClient& xfrout_client) :
     config_session_(NULL), verbose_mode_(false),
-    xfrin_session_(NULL),
+    xfrin_session_(NULL), stats_session_(NULL),
     xfrout_connected_(false),
     xfrout_client_(xfrout_client)
 {
@@ -198,6 +202,11 @@
 }
 
 void
+AuthSrv::setStatsSession(AbstractSession* stats_session) {
+    impl_->stats_session_ = stats_session;
+}
+
+void
 AuthSrv::setConfigSession(ModuleCCSession* config_session) {
     impl_->config_session_ = config_session;
 }
@@ -253,6 +262,9 @@
     if (impl_->verbose_mode_) {
         cerr << "[b10-auth] received a message:\n" << message.toText() << endl;
     }
+
+    // send query count to stats module
+    impl_->addStatsQueryCount(io_message);
 
     // Perform further protocol-level validation.
 
@@ -525,3 +537,67 @@
         return (isc::config::createAnswer(1, error.what()));
     }
 }
+
+bool
+AuthSrvImpl::addStatsQueryCount(const IOMessage& io_message)
+{
+    // This method sends increment counter to the stats module.
+    // TODO: 
+    // This implementation is very very ad-hoc style. It may bring
+    // worse performance in this style. It must be more considered and
+    // must be replaced with asynchronous one which is low const.
+    if (stats_session_ == NULL) {
+        if (verbose_mode_) {
+            cerr << "[b10-auth] "
+                "session interface for stats is not available" << endl;
+        }
+        return (false);
+    }
+    // get protocol
+    int protocol = io_message.getSocket().getProtocol();
+    // construct command string
+    static const string command_template_start =
+        "{ \"command\": [ \"increase\", { \"stats_data\": { \"auth.queries.";
+    static const string command_template_end = "\": 1 } } ] }";
+    string command_str;
+    if (protocol == IPPROTO_TCP) {
+        // in case of TCP
+        command_str = command_template_start
+            + "tcp" + command_template_end;
+    } else if (protocol == IPPROTO_UDP){
+        // in case of UDP
+        command_str = command_template_start
+            + "udp" + command_template_end;
+    } else {
+        // unknown protocol
+        cerr << "[     b10-auth] got unknown protocol: " << protocol
+             << endl;
+        return (false);
+    }
+    // send to stats module
+    try {
+        ConstElementPtr stats_command =
+          Element::fromJSON(command_str);
+        const unsigned int seq =
+            xfrin_session_->group_sendmsg(stats_command, "Stats",
+                                          "*", "*");
+        ConstElementPtr env, answer, parsed_answer;
+        xfrin_session_->group_recvmsg(env, answer, false, seq);
+        int rcode;
+        parsed_answer = parseAnswer(rcode, answer);
+        if (rcode != 0) {
+            if (verbose_mode_) {
+                cerr << "[b10-auth] failed to send statistics: "
+                     << parsed_answer->str() << endl; 
+            }
+            return (false);
+        }
+    } catch (const Exception& ex) {
+        if (verbose_mode_) {
+            cerr << "[b10-auth] failed to send statistics: "
+                 << ex.what() << endl;
+        }
+        return (false);
+    }
+    return (true);
+}




More information about the bind10-changes mailing list