Ben Greear wrote:

UNIX domain sockets can be used in XRL as it stands, by passing 'env
XORP_PF=x', without any patches.

If these are faster, why not use them by default?

How about this? 'scons check' runs to completion.

P.S. The old bench_ipc* scripts expect to pass 't' for 'tcp' in env XORP_PF.
Allow the default transport protocol for XRL to be set
on the SCons command line, using the 'transport' variable.

The default setting is now 'local', which forces the use
of UNIX domain stream sockets. This is suitable for the
production use case of XORP running on a single machine.

Currently, the only alternative option is 'tcp'; users
intending to configure XORP for distributed operation should
pass 'transport=tcp' on the SCons command line.

This option is implemented using a preprocessor define on
the command line, XRL_PF. The define is passed as an
ordinal ASCII value to avoid issues with shell argument quoting.

The define needs to be seen by the whole tree, as any XORP code
which includes <libxipc/xrl_std_router.hh> is affected by the
setting of this option.

Communication with the Finder is exempt from this option,
and defaults to TCP over the loopback interface.

Requested by:   Ben Greear
Index: libxipc/xrl_std_router.hh
===================================================================
--- libxipc/xrl_std_router.hh   (revision 11632)
+++ libxipc/xrl_std_router.hh   (working copy)
@@ -27,7 +27,11 @@
 #include "xrl_router.hh"
 #include "xrl_pf.hh"
 
+#if !defined(XRL_PF) || (XRL_PF == 'x')
+#define UNIX_SOCKET_DEFAULT true
+#else
 #define UNIX_SOCKET_DEFAULT false
+#endif
 
 /**
  * @short Standard XRL transmission and reception point.
Index: libxipc/xrl_std_router.cc
===================================================================
--- libxipc/xrl_std_router.cc   (revision 11632)
+++ libxipc/xrl_std_router.cc   (working copy)
@@ -23,42 +23,55 @@
 
 #include "xrl_module.h"
 #include "xrl_std_router.hh"
-//#include "xrl_pf_inproc.hh"
+//#include "xrl_pf_inproc.hh"  // Inproc is deprecated.
 #include "xrl_pf_stcp.hh"
-//#include "xrl_pf_sudp.hh"
+//#include "xrl_pf_sudp.hh"    // UDP is deprecated.
 #include "xrl_pf_unix.hh"
 #include "libxorp/xlog.h"
 
+
 // ----------------------------------------------------------------------------
 // Helper methods
 
+#if !defined(XRL_PF)
+#error "A default transport for XRL must be defined using the preprocessor."
+#endif
+
+static const char default_pf[] = { XRL_PF, '\0' };
+
 XrlPFListener*
 XrlStdRouter::create_listener()
 {
     const char* pf = getenv("XORP_PF");
+    if (pf == NULL)
+       pf = default_pf;
 
-    if (pf != NULL) {
-       switch (pf[0]) {
-#if 0
+    switch (pf[0]) {
+#if 0  // Inproc is deprecated.
        case 'i':
            return new XrlPFInProcListener(_e, this);
-
+#endif
+       // For the benefit of bench_ipc.sh.
+       case 't':
+           return new XrlPFSTCPListener(_e, this);
+           break;
+#if 0  // UDP is deprecated.
        case 'u':
            return new XrlPFSUDPListener(_e, this);
 #endif
-
        case 'x':
+#if XRL_PF != 'x'
            XLOG_ASSERT(_unix == NULL);
+#endif
            return new XrlPFUNIXListener(_e, this);
-
        default:
            XLOG_ERROR("Unknown PF %s\n", pf);
            XLOG_ASSERT(false);
            break;
-       }
     }
 
-    return new XrlPFSTCPListener(_e, this);
+    XLOG_UNREACHABLE();
+    return 0;
 }
 
 static void
Index: SConstruct
===================================================================
--- SConstruct  (revision 11631)
+++ SConstruct  (working copy)
@@ -79,6 +79,9 @@
     EnumVariable('profile', 'Build with profiling', 'no',
                  allowed_values=('no', 'gprof', 'pprof', 'override'),
                  map={}, ignorecase=2),
+    EnumVariable('transport', 'Set default XRL transport', 'local',
+                 allowed_values=('tcp', 'local'),
+                 map={}, ignorecase=2),
     )
 
 def log_args(afname):
@@ -171,6 +174,9 @@
 # Default to disable; wrapper for compiler profiling support.
 print 'Profile code:     ', env['profile']
 
+# Default to local (UNIX domain sockets).
+print 'Default transport:', env['transport']
+
 # Most of our shared library tweaks are specific to GNU ld.
 # Check if the GNU linker is available, and print a warning if not.
 if env['shared']:
@@ -441,8 +447,16 @@
             env.AppendUnique( LIBS = [ 'profiler' ] )
             #env.AppendUnique( CPPDEFINES = [ 'WITH_PPROF' ] )
 
+# Apply top-level 'transport' option.
+# We pass it as an ordinal character constant to avoid shell
+# quoting issues, as it is specified by 1 character.
+# Note: We need to do this at top level to make sure the option
+# is propagated correctly, because anything which includes
+# <libxipc/xrl_std_router.hh> will be affected by this option.
+xrl_pf_dict = { 'tcp': 't', 'local': 'x' }
 env.AppendUnique(CPPDEFINES = [
     ( '_FORTIFY_SOURCE', 0 ),
+    ( 'XRL_PF', ord(xrl_pf_dict[env['transport']]) ),
     ])
 
 # NOTE: gcc specific flags.
_______________________________________________
Xorp-hackers mailing list
[email protected]
http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers

Reply via email to