[Xorp-cvs] SF.net SVN: xorp:[11598] trunk/xorp

bms_fbsd at users.sourceforge.net bms_fbsd at users.sourceforge.net
Thu Nov 26 20:42:34 PST 2009


Revision: 11598
          http://xorp.svn.sourceforge.net/xorp/?rev=11598&view=rev
Author:   bms_fbsd
Date:     2009-11-27 04:42:34 +0000 (Fri, 27 Nov 2009)

Log Message:
-----------
Disable XRL syntax verification in the Router Manager.
Validating each XRL as it is sent is only useful for XORP developers,
and should not be necessary in a production deployment.

The XRLdb runtime validation support is now controlled by the SCons
command line variable 'debug_xrldb'. If this variable is changed,
a full rebuild should be made.

The xrl/targets/*.xrls files are no longer installed unless this feature
is enabled. The scope of the preprocessor define DEBUG_XRLDB is constrained
to the librtrmgr SCons target only; xrldb.cc is now conditionally compiled.

In all other cases, the XRLdb is elided to a 0 pointer, as it needs to
be passed down the call graph from the surrounding Rtrmgr instance; method
signatures have been appropriately refactored.

'scons check' passes with this change. The Router Manager has been tested
with both configurations, however, any performance increase has not
been measured.

Modified Paths:
--------------
    trunk/xorp/SConstruct
    trunk/xorp/rtrmgr/SConscript
    trunk/xorp/rtrmgr/main_rtrmgr.cc
    trunk/xorp/rtrmgr/master_template_tree.cc
    trunk/xorp/rtrmgr/master_template_tree.hh
    trunk/xorp/rtrmgr/master_template_tree_node.cc
    trunk/xorp/rtrmgr/master_template_tree_node.hh
    trunk/xorp/rtrmgr/module_command.cc
    trunk/xorp/rtrmgr/module_command.hh
    trunk/xorp/rtrmgr/template_commands.cc
    trunk/xorp/rtrmgr/template_commands.hh
    trunk/xorp/rtrmgr/template_tree_node.hh
    trunk/xorp/xrl/targets/SConscript

Modified: trunk/xorp/SConstruct
===================================================================
--- trunk/xorp/SConstruct	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/SConstruct	2009-11-27 04:42:34 UTC (rev 11598)
@@ -69,6 +69,7 @@
     BoolVariable('debug_msg',  'Build with debug messages', False),
     BoolVariable('debug_fn',  'Build with function names in debug_msg output', False),
     BoolVariable('debug_cb',  'Build with callback debugging', False),
+    BoolVariable('debug_xrldb',  'Build with runtime XRL syntax validation in Router Manager', False),
     EnumVariable('debug', 'Build with debug symbols', 'full',
                  allowed_values=('no', 'yes', 'full', 'override'),
                  map={}, ignorecase=2),
@@ -178,6 +179,7 @@
 print 'Debug messages:   ', env['debug_msg']
 print 'Debug function names: ', env['debug_fn']
 print 'Debug callbacks:  ', env['debug_cb']
+print 'Debug XRL syntax: ', env['debug_xrldb']
 
 env['CONFIGURELOG'] = str(builddir) + os.sep + 'config.log'
 env['CONFIGUREDIR'] = str(builddir) + os.sep + '.sconf_temp'

Modified: trunk/xorp/rtrmgr/SConscript
===================================================================
--- trunk/xorp/rtrmgr/SConscript	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/SConscript	2009-11-27 04:42:34 UTC (rev 11598)
@@ -95,12 +95,18 @@
 	'unexpanded_xrl.cc',
 	'userdb.cc',
 	'xorp_client.cc',
-	'xrldb.cc',
 	'y.boot_tab.cc',
 	'y.opcmd_tab.cc',
 	'y.tplt_tab.cc',
 	]
 
+# Runtime XRL syntax validation for developers.
+if env['debug_xrldb']:
+    librtrmgr_srcs += [ 'xrldb.cc' ]
+    librtrmgr_env.AppendUnique(CPPDEFINES = [
+        ( 'DEBUG_XRLDB', 1 ),
+    ])
+
 # Pushdown for static paths in util.cc.
 xorp_paths = {
     "XORP_INSTALL_ROOT" : '\\"' + str(env['prefix']) + '\\"',
@@ -120,6 +126,13 @@
 
 rtrmgr_env = env.Clone()
 
+# The Router Manager's main() function is responsible for
+# creating the XRLdb, if XRL syntax debugging is enabled.
+if env['debug_xrldb']:
+    rtrmgr_env.AppendUnique(CPPDEFINES = [
+        ( 'DEBUG_XRLDB', 1 ),
+    ])
+
 rtrmgr_env.AppendUnique(LIBS = [
     'rtrmgr',
     'rtrmgrbase',

Modified: trunk/xorp/rtrmgr/main_rtrmgr.cc
===================================================================
--- trunk/xorp/rtrmgr/main_rtrmgr.cc	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/main_rtrmgr.cc	2009-11-27 04:42:34 UTC (rev 11598)
@@ -78,7 +78,6 @@
 //
 static volatile bool	running = false;
 static string	template_dir;
-static string	xrl_targets_dir;
 static string	boot_file;
 static bool     do_logfile = false;
 static bool     do_pidfile = false;
@@ -93,6 +92,7 @@
 static string	pidfilename;
 int32_t		quit_time = -1;
 static bool	daemon_mode = false;
+static string	xrl_targets_dir;	// for DEBUG_XRLDB
 
 static void cleanup_and_exit(int errcode);
 
@@ -122,7 +122,10 @@
     fprintf(stderr, "  -p <port> Set port to run Finder on\n");
     fprintf(stderr, "  -q <secs> Set forced quit period\n");
     fprintf(stderr, "  -t <dir>  Specify templates directory\n");
-    fprintf(stderr, "  -x <dir>  Specify Xrl targets directory\n");
+#ifdef DEBUG_XRLDB
+    fprintf(stderr,
+	    "  -x <dir>  Specify Xrl targets directory (debug_xrldb)\n");
+#endif
 }
 
 static void
@@ -133,8 +136,10 @@
 	    xorp_boot_file().c_str());
     fprintf(stderr, "  Templates directory        := %s\n",
 	    xorp_template_dir().c_str());
+#ifdef DEBUG_XRLDB
     fprintf(stderr, "  Xrl targets directory      := %s\n",
 	    xorp_xrl_targets_dir().c_str());
+#endif
     fprintf(stderr, "  Execute Xrls               := %s\n",
 	    bool_c_str(default_do_exec));
     fprintf(stderr, "  Restart failed processes   := %s\n",
@@ -228,8 +233,6 @@
 	       boot_file.c_str());
     XLOG_TRACE(_verbose, "Templates directory        := %s\n",
 	       template_dir.c_str());
-    XLOG_TRACE(_verbose, "Xrl targets directory      := %s\n",
-	       xrl_targets_dir.c_str());
     XLOG_TRACE(_verbose, "Execute Xrls               := %s\n",
 	       bool_c_str(do_exec));
     XLOG_TRACE(_verbose, "Restart failed processes   := %s\n",
@@ -237,20 +240,30 @@
     XLOG_TRACE(_verbose, "Print verbose information  := %s\n",
 	       bool_c_str(_verbose));
 
+#ifdef DEBUG_XRLDB
+# define DEBUG_XRLDB_INSTANCE	xrldb
+    XRLdb* xrldb = 0;
 
-    XRLdb* xrldb = NULL;
+    XLOG_TRACE(_verbose, "Xrl targets directory      := %s\n",
+	       xrl_targets_dir.c_str());
+    XLOG_TRACE(_verbose, "Validate XRL syntax        := %s\n",
+	       bool_c_str(true));
     try {
 	xrldb = new XRLdb(_xrl_targets_dir, _verbose);
     } catch (const InitError& e) {
 	XLOG_ERROR("Shutting down due to an init error: %s", e.why().c_str());
 	return (1);
     }
+#else // ! DEBUG_XRLDB
+# define DEBUG_XRLDB_INSTANCE	0
+#endif // DEBUG_XRLDB
 
     //
     // Read the router config template files
     //
     MasterTemplateTree* tt = new MasterTemplateTree(xorp_config_root_dir(),
-						    *xrldb, _verbose);
+						    DEBUG_XRLDB_INSTANCE,
+						    _verbose);
     if (!tt->load_template_tree(_template_dir, errmsg)) {
 	XLOG_ERROR("Shutting down due to an init error: %s", errmsg.c_str());
 	return (1);
@@ -388,13 +401,16 @@
     // Delete the template tree
     delete tt;
 
+#ifdef DEBUG_XRLDB
     // Delete the XRLdb
     delete xrldb;
+#endif
 
     // Shutdown the finder
     delete fs;
 
     return (errcode);
+#undef DEBUG_XRLDB_INSTANCE
 }
 
 bool 
@@ -517,11 +533,19 @@
     //
     xorp_path_init(argv[0]);
     template_dir	= xorp_template_dir();
+    boot_file		= xorp_boot_file();
     xrl_targets_dir	= xorp_xrl_targets_dir();
-    boot_file		= xorp_boot_file();
 
+#ifdef DEBUG_XRLDB
+#define RTRMGR_X_OPT ""
+#else
+#define RTRMGR_X_OPT "x:"
+#endif
+
+    static const char* optstring =
+	"da:l:L:n:t:b:" RTRMGR_X_OPT "i:P:p:q:Nrvh";
     int c;
-    while ((c = getopt(argc, argv, "da:l:L:n:t:b:x:i:P:p:q:Nrvh")) != EOF) {
+    while ((c = getopt(argc, argv, optstring)) != EOF) {
 	switch(c) {
 	case 'd':
 	    daemon_mode = true;
@@ -566,9 +590,11 @@
 	case 'b':
 	    boot_file = optarg;
 	    break;
+#ifdef DEBUG_XRLDB
 	case 'x':
 	    xrl_targets_dir = optarg;
 	    break;
+#endif
 	case 'q':
 	    quit_time = atoi(optarg);
 	    break;
@@ -653,6 +679,7 @@
     errcode = rtrmgr.run();
 
     cleanup_and_exit(errcode);
+#undef RTRMGR_X_OPT
 }
 
 void

Modified: trunk/xorp/rtrmgr/master_template_tree.cc
===================================================================
--- trunk/xorp/rtrmgr/master_template_tree.cc	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/master_template_tree.cc	2009-11-27 04:42:34 UTC (rev 11598)
@@ -36,7 +36,7 @@
 
 
 MasterTemplateTree::MasterTemplateTree(const string& xorp_root_dir,
-				       XRLdb& xrldb,
+				       XRLdb* xrldb,
 				       bool verbose) throw (InitError)
     : TemplateTree(xorp_root_dir, verbose),
       _xrldb(xrldb)

Modified: trunk/xorp/rtrmgr/master_template_tree.hh
===================================================================
--- trunk/xorp/rtrmgr/master_template_tree.hh	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/master_template_tree.hh	2009-11-27 04:42:34 UTC (rev 11598)
@@ -22,15 +22,19 @@
 #ifndef __RTRMGR_MASTER_TEMPLATE_TREE_HH__
 #define __RTRMGR_MASTER_TEMPLATE_TREE_HH__
 
+class XRLdb;
 
+#ifdef DEBUG_XRLDB
 #include "xrldb.hh"
+#endif
+
 #include "template_tree.hh"
 #include "master_template_tree_node.hh"
 
 class MasterTemplateTree : public TemplateTree {
 public:
     MasterTemplateTree(const string& xorp_root_dir,
-		       XRLdb& xrldb,
+		       XRLdb* xrldb,
 		       bool verbose)  throw (InitError);
 
     bool load_template_tree(const string& config_template_dir,
@@ -39,7 +43,7 @@
     void add_cmd(char* cmd) throw (ParseError);
     void add_cmd_action(const string& cmd, const list<string>& action)
 	throw (ParseError);
-    const XRLdb& xrldb() const { return _xrldb; }
+    const XRLdb* xrldb() const { return _xrldb; }
 
     const MasterTemplateTreeNode* find_node(const list<string>& path_segments) 
 	const 
@@ -55,7 +59,7 @@
     bool expand_master_template_tree(string& error_msg);
     bool check_master_template_tree(string& error_msg);
 
-    XRLdb		_xrldb;
+    XRLdb*		_xrldb;
 };
 
 #endif // __RTRMGR_MASTER_TEMPLATE_TREE_HH__

Modified: trunk/xorp/rtrmgr/master_template_tree_node.cc
===================================================================
--- trunk/xorp/rtrmgr/master_template_tree_node.cc	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/master_template_tree_node.cc	2009-11-27 04:42:34 UTC (rev 11598)
@@ -76,7 +76,7 @@
 void
 MasterTemplateTreeNode::add_action(const string& cmd,
 				   const list<string>& action_list,
-				   const XRLdb& xrldb) throw (ParseError)
+				   const XRLdb* xrldb) throw (ParseError)
 {
     BaseCommand* command;
     map<string, BaseCommand*>::iterator iter;

Modified: trunk/xorp/rtrmgr/master_template_tree_node.hh
===================================================================
--- trunk/xorp/rtrmgr/master_template_tree_node.hh	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/master_template_tree_node.hh	2009-11-27 04:42:34 UTC (rev 11598)
@@ -41,7 +41,7 @@
 
     void add_cmd(const string& cmd, TemplateTree& tt) throw (ParseError);
     void add_action(const string& cmd, const list<string>& action_list,
-		    const XRLdb& xrldb) throw (ParseError);
+		    const XRLdb* xrldb) throw (ParseError);
     bool expand_master_template_tree(string& error_msg);
     bool check_master_template_tree(string& error_msg) const;
 

Modified: trunk/xorp/rtrmgr/module_command.cc
===================================================================
--- trunk/xorp/rtrmgr/module_command.cc	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/module_command.cc	2009-11-27 04:42:34 UTC (rev 11598)
@@ -35,9 +35,11 @@
 #include "template_tree_node.hh"
 #include "master_conf_tree_node.hh"
 #include "util.hh"
+
+#ifdef DEBUG_XRLDB
 #include "xrldb.hh"
+#endif
 
-
 static string
 strip_quotes(const string& command, const string& value) throw (ParseError)
 {
@@ -91,7 +93,7 @@
 }
 
 void
-ModuleCommand::add_action(const list<string>& action, const XRLdb& xrldb)
+ModuleCommand::add_action(const list<string>& action, const XRLdb* xrldb)
     throw (ParseError)
 {
     size_t expected_action_size = 2;

Modified: trunk/xorp/rtrmgr/module_command.hh
===================================================================
--- trunk/xorp/rtrmgr/module_command.hh	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/module_command.hh	2009-11-27 04:42:34 UTC (rev 11598)
@@ -39,7 +39,7 @@
     ~ModuleCommand();
 
     void add_action(const list<string>& action,
-		    const XRLdb& xrldb) throw (ParseError);
+		    const XRLdb* xrldb) throw (ParseError);
     virtual bool expand_actions(string& error_msg);
     virtual bool check_referred_variables(string& error_msg) const;
 

Modified: trunk/xorp/rtrmgr/template_commands.cc
===================================================================
--- trunk/xorp/rtrmgr/template_commands.cc	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/template_commands.cc	2009-11-27 04:42:34 UTC (rev 11598)
@@ -35,7 +35,10 @@
 #include "template_tree.hh"
 #include "template_tree_node.hh"
 #include "util.hh"
+
+#ifdef DEBUG_XRLDB
 #include "xrldb.hh"
+#endif
 
 #include "libxipc/xrl_atom_encoding.hh"
 
@@ -161,11 +164,18 @@
 /***********************************************************************/
 
 XrlAction::XrlAction(TemplateTreeNode& template_tree_node,
-		     const list<string>& action, const XRLdb& xrldb)
+		     const list<string>& action, const XRLdb* xrldb)
     throw (ParseError)
     : Action(template_tree_node, action),
-      _xrldb(xrldb)
+      _xrldb(0)
 {
+#ifdef DEBUG_XRLDB
+    XLOG_ASSERT(0 != dynamic_cast<const XRLdb*>(xrldb));
+    _xrldb = xrldb;
+#else
+    UNUSED(xrldb);
+#endif
+
     list<string> xrl_parts = _split_cmd;
 
     debug_msg("XrlAction constructor\n");
@@ -271,19 +281,24 @@
 	return false;
     }
 
+#ifdef DEBUG_XRLDB
     if (check_xrl_is_valid(_action, _xrldb, error_msg) != true)
 	return false;
+#endif
 
     return true;
 }
 
+#ifdef DEBUG_XRLDB
 bool
-XrlAction::check_xrl_is_valid(const list<string>& action, const XRLdb& xrldb,
+XrlAction::check_xrl_is_valid(const list<string>& action,
+			      const XRLdb* xrldb,
 			      string& error_msg)
 {
     const string module_name = template_tree_node().module_name();
 
     XLOG_ASSERT(action.front() == "xrl");
+    XLOG_ASSERT(0 != dynamic_cast<const XRLdb*>(xrldb));
 
     list<string>::const_iterator xrl_pos = ++action.begin();
     if (xrl_pos == action.end()) {
@@ -450,13 +465,13 @@
     }
     debug_msg("XrlAction after cleaning:\n%s\n", cleaned_xrl.c_str());
 
-    if (xrldb.check_xrl_syntax(cleaned_xrl) == false) {
+    if (xrldb->check_xrl_syntax(cleaned_xrl) == false) {
 	error_msg = c_format("Syntax error in module %s XRL %s: "
 			     "invalid XRL syntax",
 			     module_name.c_str(), cleaned_xrl.c_str());
 	return false;
     }
-    XRLMatchType match = xrldb.check_xrl_exists(cleaned_xrl);
+    XRLMatchType match = xrldb->check_xrl_exists(cleaned_xrl);
     switch (match) {
     case MATCH_FAIL:
     case MATCH_RSPEC: {
@@ -479,6 +494,7 @@
 
     return true;
 }
+#endif // DEBUG_XRLDB
 
 int
 XrlAction::execute(const MasterConfigTreeNode& ctn,
@@ -1263,7 +1279,7 @@
 }
 
 void
-Command::add_action(const list<string>& action, const XRLdb& xrldb)
+Command::add_action(const list<string>& action, const XRLdb* xrldb)
     throw (ParseError)
 {
     string action_type;

Modified: trunk/xorp/rtrmgr/template_commands.hh
===================================================================
--- trunk/xorp/rtrmgr/template_commands.hh	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/template_commands.hh	2009-11-27 04:42:34 UTC (rev 11598)
@@ -61,7 +61,7 @@
 class XrlAction : public Action {
 public:
     XrlAction(TemplateTreeNode& template_tree_node, const list<string>& action,
-	      const XRLdb& xrldb) throw (ParseError);
+	      const XRLdb* xrldb) throw (ParseError);
 
     virtual bool expand_action(string& error_msg);
     int execute(const MasterConfigTreeNode& ctn, TaskManager& task_manager,
@@ -79,18 +79,20 @@
     string affected_module() const;
 
 private:
+#ifdef DEBUG_XRLDB
     bool check_xrl_is_valid(const list<string>& action,
-			    const XRLdb& xrldb, string& error_msg);
+			    const XRLdb* xrldb, string& error_msg);
+#endif
     template<class TreeNode> bool expand_vars(const TreeNode& tn,
 					      const string& s, 
 					      string& result) const;
 
-    const XRLdb&	_xrldb;
     string		_module_name;
     list<string>	_split_request;
     string		_request;
     list<string>	_split_response;
     string		_response;
+    const XRLdb*	_xrldb;
 };
 
 class ProgramAction : public Action {
@@ -129,7 +131,7 @@
     Command(TemplateTreeNode& template_tree_node, const string& cmd_name);
     virtual ~Command();
 
-    void add_action(const list<string>& action, const XRLdb& xrldb)
+    void add_action(const list<string>& action, const XRLdb* xrldb)
 	throw (ParseError);
     int execute(MasterConfigTreeNode& ctn, TaskManager& task_manager) const;
     void xrl_action_complete(const XrlError& err,

Modified: trunk/xorp/rtrmgr/template_tree_node.hh
===================================================================
--- trunk/xorp/rtrmgr/template_tree_node.hh	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/rtrmgr/template_tree_node.hh	2009-11-27 04:42:34 UTC (rev 11598)
@@ -33,9 +33,11 @@
 #include "config_operators.hh"
 #include "rtrmgr_error.hh"
 #include "xorp_client.hh"
+
+#ifdef DEBUG_XRLDB
 #include "xrldb.hh"
+#endif
 
-
 enum TTNodeType {
     NODE_VOID		= 0,
     NODE_TEXT		= 1,

Modified: trunk/xorp/xrl/targets/SConscript
===================================================================
--- trunk/xorp/xrl/targets/SConscript	2009-11-27 02:56:41 UTC (rev 11597)
+++ trunk/xorp/xrl/targets/SConscript	2009-11-27 04:42:34 UTC (rev 11598)
@@ -99,7 +99,8 @@
     if base[:4] != "test":
         if is_shared:
             env.Alias('install', env.InstallLibrary('$libdir', lib))
-        env.Alias('install', env.InstallData(xrlspath, xrls))
+        if env['debug_xrldb']:
+            env.Alias('install', env.InstallData(xrlspath, xrls))
 
     return lib
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Xorp-cvs mailing list