[svn] commit: r3950 - in /branches/trac446/src: bin/auth/ bin/auth/tests/ lib/datasrc/ lib/datasrc/tests/

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Dec 22 09:50:44 UTC 2010


Author: jinmei
Date: Wed Dec 22 09:50:41 2010
New Revision: 3950

Log:
initial implementation (test + code + doc) of trac #446: config knob for in memory data source

Added:
    branches/trac446/src/bin/auth/config.cc
    branches/trac446/src/bin/auth/config.h
    branches/trac446/src/bin/auth/tests/config_unittest.cc
Modified:
    branches/trac446/src/bin/auth/Makefile.am
    branches/trac446/src/bin/auth/auth.spec.pre.in
    branches/trac446/src/bin/auth/auth_srv.cc
    branches/trac446/src/bin/auth/auth_srv.h
    branches/trac446/src/bin/auth/main.cc
    branches/trac446/src/bin/auth/tests/Makefile.am
    branches/trac446/src/lib/datasrc/memory_datasrc.cc
    branches/trac446/src/lib/datasrc/memory_datasrc.h
    branches/trac446/src/lib/datasrc/tests/memory_datasrc_unittest.cc

Modified: branches/trac446/src/bin/auth/Makefile.am
==============================================================================
--- branches/trac446/src/bin/auth/Makefile.am (original)
+++ branches/trac446/src/bin/auth/Makefile.am Wed Dec 22 09:50:41 2010
@@ -39,6 +39,7 @@
 b10_auth_SOURCES = auth_srv.cc auth_srv.h
 b10_auth_SOURCES += query.cc query.h
 b10_auth_SOURCES += change_user.cc change_user.h
+b10_auth_SOURCES += config.cc config.h
 b10_auth_SOURCES += common.h
 b10_auth_SOURCES += main.cc
 b10_auth_LDADD =  $(top_builddir)/src/lib/datasrc/libdatasrc.la

Modified: branches/trac446/src/bin/auth/auth.spec.pre.in
==============================================================================
--- branches/trac446/src/bin/auth/auth.spec.pre.in (original)
+++ branches/trac446/src/bin/auth/auth.spec.pre.in Wed Dec 22 09:50:41 2010
@@ -7,6 +7,51 @@
         "item_type": "string",
         "item_optional": true,
         "item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
+      },
+      { "item_name": "datasources",
+        "item_type": "list",
+        "item_optional": true,
+        "item_default": [],
+	"list_item_spec": {
+          "item_name": "list_element",
+          "item_type": "map",
+          "item_optional": false,
+          "item_default": {},
+	  "map_item_spec": [
+	    { "item_name": "type",
+	      "item_type": "string",
+	      "item_optional": false,
+	      "item_default": ""
+	    },
+	    { "item_name": "class",
+	      "item_type": "string",
+	      "item_optional": false,
+	      "item_default": "IN"
+	    },
+	    { "item_name": "zones",
+	      "item_type": "list",
+	      "item_optional": false,
+	      "item_default": [],
+	      "list_item_spec": {
+	        "item_name": "list_element",
+	        "item_type": "map",
+	        "item_optional": true,
+	        "map_item_spec": [
+		  { "item_name": "origin",
+		    "item_type": "string",
+		    "item_optional": false,
+		    "item_default": ""
+		  },
+		  { "item_name": "file",
+		    "item_type": "string",
+		    "item_optional": false,
+		    "item_default": ""
+		  }
+		]
+	      }
+	    }
+	  ]
+        }
       }
     ],
     "commands": [

Modified: branches/trac446/src/bin/auth/auth_srv.cc
==============================================================================
--- branches/trac446/src/bin/auth/auth_srv.cc (original)
+++ branches/trac446/src/bin/auth/auth_srv.cc Wed Dec 22 09:50:41 2010
@@ -45,6 +45,7 @@
 
 #include <datasrc/query.h>
 #include <datasrc/data_source.h>
+#include <datasrc/memory_datasrc.h>
 #include <datasrc/static_datasrc.h>
 #include <datasrc/sqlite3_datasrc.h>
 
@@ -89,6 +90,9 @@
     ModuleCCSession* config_session_;
     bool verbose_mode_;
     AbstractSession* xfrin_session_;
+
+    /// In-memory data source.  Currently class IN only for simplicity.
+    AuthSrv::MemoryDataSrcPtr memory_datasrc_;
 
     /// Hot spot cache
     isc::datasrc::HotCache cache_;
@@ -288,6 +292,34 @@
 ModuleCCSession*
 AuthSrv::getConfigSession() const {
     return (impl_->config_session_);
+}
+
+AuthSrv::ConstMemoryDataSrcPtr
+AuthSrv::getMemoryDataSrc(const RRClass& rrclass) const {
+    // XXX: for simplicity, we only support the IN class right now.
+    if (rrclass != RRClass::IN()) {
+        isc_throw(InvalidParameter,
+                  "Memory data source is not supported for RR class "
+                  << rrclass);
+    }
+    return (impl_->memory_datasrc_);
+}
+
+void
+AuthSrv::setMemoryDataSrc(const isc::dns::RRClass& rrclass,
+                          MemoryDataSrcPtr memory_datasrc)
+{
+    // XXX: see above
+    if (rrclass != RRClass::IN()) {
+        isc_throw(InvalidParameter,
+                  "Memory data source is not supported for RR class "
+                  << rrclass);
+    }
+    impl_->memory_datasrc_ = memory_datasrc;
+    if (impl_->verbose_mode_) {
+        cerr << "[b10-auth] memory data source is configured for class "
+             << rrclass << endl;
+    }
 }
 
 void

Modified: branches/trac446/src/bin/auth/auth_srv.h
==============================================================================
--- branches/trac446/src/bin/auth/auth_srv.h (original)
+++ branches/trac446/src/bin/auth/auth_srv.h Wed Dec 22 09:50:41 2010
@@ -19,12 +19,19 @@
 
 #include <string>
 
+// For MemoryDataSrcPtr below.  This should be a temporary definition until
+// we reorganize the data source framework.
+#include <boost/shared_ptr.hpp>
+
 #include <cc/data.h>
 #include <config/ccsession.h>
 
 #include <asiolink/asiolink.h>
 
 namespace isc {
+namespace datasrc {
+class MemoryDataSrc;
+}
 namespace xfr {
 class AbstractXfroutClient;
 }
@@ -224,6 +231,53 @@
     ///
     void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
 
+    /// A shared pointer type for \c MemoryDataSrc.
+    ///
+    /// This is defined inside the \c AuthSrv class as it's supposed to be
+    /// a short term interface until we integrate the in-memory and other
+    /// data source frameworks.
+    typedef boost::shared_ptr<isc::datasrc::MemoryDataSrc> MemoryDataSrcPtr;
+
+    /// An immutable shared pointer type for \c MemoryDataSrc.
+    typedef boost::shared_ptr<const isc::datasrc::MemoryDataSrc>
+    ConstMemoryDataSrcPtr;
+
+    /// Returns the in-memory data source configured for the \c AuthSrv,
+    /// if any.
+    ///
+    /// The in-memory data source is configured per RR class.  However,
+    /// the data source may not be available for all RR classes.
+    /// If it is not available for the specified RR class, an exception of
+    /// class \c InvalidParameter will be thrown.
+    /// This method never throws an exception otherwise.
+    ///
+    /// Even for supported RR classes, the in-memory data source is not
+    /// configured by default.  In that case a NULL (shared) pointer will
+    /// be returned.
+    ///
+    /// \param rrclass The RR class of the requested in-memory data source.
+    /// \return A pointer to the in-memory data source, if configured;
+    /// otherwise NULL.
+    ConstMemoryDataSrcPtr
+    getMemoryDataSrc(const isc::dns::RRClass& rrclass) const;
+
+    /// Sets or replaces the in-memory data source of the specified RR class.
+    ///
+    /// As noted in \c getMemoryDataSrc(), some RR classes may not be
+    /// supported, in which case an exception of class \c InvalidParameter
+    /// will be thrown.
+    /// This method never throws an exception otherwise.
+    ///
+    /// If there is already an in memory data source configured, it will be
+    /// replaced with the newly specified one.
+    /// \c memory_datasrc can be NULL, in which case it will (re)disable the
+    /// in-memory data source.
+    ///
+    /// \param rrclass The RR class of the in-memory data source to be set.
+    /// \param memory_datasrc A (shared) pointer to \c MemoryDataSrc to be set.
+    void setMemoryDataSrc(const isc::dns::RRClass& rrclass,
+                          MemoryDataSrcPtr memory_datasrc);
+
 private:
     AuthSrvImpl* impl_;
     asiolink::IOService* io_service_;

Modified: branches/trac446/src/bin/auth/main.cc
==============================================================================
--- branches/trac446/src/bin/auth/main.cc (original)
+++ branches/trac446/src/bin/auth/main.cc Wed Dec 22 09:50:41 2010
@@ -41,6 +41,7 @@
 
 #include <auth/spec_config.h>
 #include <auth/common.h>
+#include <auth/config.h>
 #include <auth/change_user.h>
 #include <auth/auth_srv.h>
 #include <asiolink/asiolink.h>
@@ -235,7 +236,13 @@
         // from auth_server, and create io_service, auth_server, and
         // sessions in that order.
         auth_server->setXfrinSession(xfrin_session);
+
+        // Configure the server.  configureAuthServer() is expected to install
+        // all initial configurations, but as a short term workaround we
+        // handle the traditional "database_file" setup by directly calling
+        // updateConfig().
         auth_server->setConfigSession(config_session);
+        configureAuthServer(*auth_server, config_session->getFullConfig());
         auth_server->updateConfig(ElementPtr());
 
         cout << "[b10-auth] Server started." << endl;

Modified: branches/trac446/src/bin/auth/tests/Makefile.am
==============================================================================
--- branches/trac446/src/bin/auth/tests/Makefile.am (original)
+++ branches/trac446/src/bin/auth/tests/Makefile.am Wed Dec 22 09:50:41 2010
@@ -21,7 +21,9 @@
 run_unittests_SOURCES += ../auth_srv.h ../auth_srv.cc
 run_unittests_SOURCES += ../query.h ../query.cc
 run_unittests_SOURCES += ../change_user.h ../change_user.cc
+run_unittests_SOURCES += ../config.h ../config.cc
 run_unittests_SOURCES += auth_srv_unittest.cc
+run_unittests_SOURCES += config_unittest.cc
 run_unittests_SOURCES += query_unittest.cc
 run_unittests_SOURCES += change_user_unittest.cc
 run_unittests_SOURCES += run_unittests.cc

Modified: branches/trac446/src/lib/datasrc/memory_datasrc.cc
==============================================================================
--- branches/trac446/src/lib/datasrc/memory_datasrc.cc (original)
+++ branches/trac446/src/lib/datasrc/memory_datasrc.cc Wed Dec 22 09:50:41 2010
@@ -27,7 +27,10 @@
 /// For now, \c MemoryDataSrc only contains a \c ZoneTable object, which
 /// consists of (pointers to) \c MemoryZone objects, we may add more
 /// member variables later for new features.
-struct MemoryDataSrc::MemoryDataSrcImpl {
+class MemoryDataSrc::MemoryDataSrcImpl {
+public:
+    MemoryDataSrcImpl() : zone_count(0) {}
+    unsigned int zone_count;
     ZoneTable zone_table;
 };
 
@@ -38,13 +41,23 @@
     delete impl_;
 }
 
+unsigned int
+MemoryDataSrc::getZoneCount() const {
+    return (impl_->zone_count);
+}
+
 result::Result
 MemoryDataSrc::addZone(ZonePtr zone) {
     if (!zone) {
         isc_throw(InvalidParameter,
                   "Null pointer is passed to MemoryDataSrc::addZone()");
     }
-    return (impl_->zone_table.addZone(zone));
+
+    const result::Result result = impl_->zone_table.addZone(zone);
+    if (result == result::SUCCESS) {
+        ++impl_->zone_count;
+    }
+    return (result);
 }
 
 MemoryDataSrc::FindResult

Modified: branches/trac446/src/lib/datasrc/memory_datasrc.h
==============================================================================
--- branches/trac446/src/lib/datasrc/memory_datasrc.h (original)
+++ branches/trac446/src/lib/datasrc/memory_datasrc.h Wed Dec 22 09:50:41 2010
@@ -104,6 +104,13 @@
     ~MemoryDataSrc();
     //@}
 
+    /// Return the number of zones stored in the data source.
+    ///
+    /// This method never throws an exception.
+    ///
+    /// \return The number of zones stored in the data source.
+    unsigned int getZoneCount() const;
+
     /// Add a \c Zone to the \c MemoryDataSrc.
     ///
     /// \c Zone must not be associated with a NULL pointer; otherwise
@@ -140,7 +147,7 @@
     FindResult findZone(const isc::dns::Name& name) const;
 
 private:
-    struct MemoryDataSrcImpl;
+    class MemoryDataSrcImpl;
     MemoryDataSrcImpl* impl_;
 };
 }

Modified: branches/trac446/src/lib/datasrc/tests/memory_datasrc_unittest.cc
==============================================================================
--- branches/trac446/src/lib/datasrc/tests/memory_datasrc_unittest.cc (original)
+++ branches/trac446/src/lib/datasrc/tests/memory_datasrc_unittest.cc Wed Dec 22 09:50:41 2010
@@ -29,8 +29,9 @@
 
 class MemoryDataSrcTest : public ::testing::Test {
 protected:
-    MemoryDataSrcTest()
+    MemoryDataSrcTest() : rrclass(RRClass::IN())
     {}
+    RRClass rrclass;
     MemoryDataSrc memory_datasrc;
 };
 
@@ -112,4 +113,22 @@
     EXPECT_EQ(Name("i.g.h"),
               memory_datasrc.findZone(Name("z.i.g.h")).zone->getOrigin());
 }
+
+
+TEST_F(MemoryDataSrcTest, getZoneCount) {
+    EXPECT_EQ(0, memory_datasrc.getZoneCount());
+    memory_datasrc.addZone(
+                  ZonePtr(new MemoryZone(rrclass, Name("example.com"))));
+    EXPECT_EQ(1, memory_datasrc.getZoneCount());
+
+    // duplicate add.  counter shouldn't change
+    memory_datasrc.addZone(
+                  ZonePtr(new MemoryZone(rrclass, Name("example.com"))));
+    EXPECT_EQ(1, memory_datasrc.getZoneCount());
+
+    // add one more
+    memory_datasrc.addZone(
+                  ZonePtr(new MemoryZone(rrclass, Name("example.org"))));
+    EXPECT_EQ(2, memory_datasrc.getZoneCount());
 }
+}




More information about the bind10-changes mailing list