[rds-devel] [PATCH RDS/netperf] Add RDS_STREAM test to netperf-2.4.2

Vladimir Sokolovsky vlad at dev.mellanox.co.il
Thu Jan 25 03:42:21 PST 2007


Hi,
The following patch adds the RDS_STREAM test for netperf-2.4.2.
Actually UDP_STREAM test executed with the only difference that the data socket 
created by socket(PF_RDS, SOCK_SEQPACKET, 0).

To compile:
sh ./autogen.sh
./configure
make

Test example:
On receiver side:
	./netserver
On sender side:
	netperf -H <remote IP address> -L <local IP address> -t RDS_STREAM
	Or
	netperf -H <remote IP address> -L <local IP address> -t UDP_STREAM -r

RDS values (PF_RDS and SOL_RDS) will be checked at run-time.


Patch for netperf-2.4.2. Added RDS_STREAM test.

Signed-off-by: Vladimir Sokolovsky <vlad at mellanox.co.il>


Index: netperf-2.4.2/src/netlib.c
===================================================================
--- netperf-2.4.2.orig/src/netlib.c
+++ netperf-2.4.2/src/netlib.c
@@ -436,6 +436,9 @@ inet_ttos(int type) 
   case SOCK_DGRAM:
     return("SOCK_DGRAM");
     break;
+  case SOCK_SEQPACKET:
+    return("SOCK_SEQPACKET");
+    break;
   case SOCK_STREAM:
     return("SOCK_STREAM");
     break;
@@ -481,6 +484,8 @@ inet_ftos(int family) 
     break;
 #endif
   default:
+    if (family == AF_RDS)
+       	return("AF_RDS");
     return("AF_UNSPEC");
   }
 }
@@ -515,6 +520,17 @@ inet_nton(int af, const void *src, char 
     break;
 #endif
   default:
+	if (af == AF_RDS) {
+    	    /* magic constants again... :) */
+    	    if (cnt >= 4) {
+    	      memcpy(dst,src,4);
+    	      return 4;
+    	    }
+    	    else {
+    	      Set_errno(ENOSPC);
+    	      return(-1);
+    	    }
+	}
     Set_errno(EAFNOSUPPORT);
     return(-1);
   }
Index: netperf-2.4.2/src/netlib.h
===================================================================
--- netperf-2.4.2.orig/src/netlib.h
+++ netperf-2.4.2/src/netlib.h
@@ -198,6 +198,10 @@
 #define         SCTP_RR_MANY_RESPONSE      531
 #define         SCTP_RR_MANY_RESULT        532
 
+#define         DO_RDS_STREAM           610
+#define         RDS_STREAM_RESPONSE     611
+#define         RDS_STREAM_RESULTS      612
+
 #if HAVE_INTTYPES_H
 # include <inttypes.h>
 #else
Index: netperf-2.4.2/src/netperf.c
===================================================================
--- netperf-2.4.2.orig/src/netperf.c
+++ netperf-2.4.2/src/netperf.c
@@ -163,6 +163,10 @@ main(int argc, char *argv[])
   else if (strcasecmp(test_name,"UDP_STREAM") == 0) {
     send_udp_stream(host_name);
   }
+  else if (strcasecmp(test_name,"RDS_STREAM") == 0) {
+    rds_enable=1;
+    send_udp_stream(host_name);
+  }
   else if (strcasecmp(test_name,"UDP_RR") == 0) {
     send_udp_rr(host_name);
   }
Index: netperf-2.4.2/src/netserver.c
===================================================================
--- netperf-2.4.2.orig/src/netserver.c
+++ netperf-2.4.2/src/netserver.c
@@ -151,9 +151,9 @@ extern	char	*optarg;
 extern	int	optind, opterr;
 
 #ifndef WIN32
-#define SERVER_ARGS "dL:n:p:v:46"
+#define SERVER_ARGS "dL:n:p:rv:46"
 #else
-#define SERVER_ARGS "dL:n:p:v:46I:i:"
+#define SERVER_ARGS "dL:n:p:rv:46I:i:"
 #endif
 
  /* This routine implements the "main event loop" of the netperf	*/
@@ -256,6 +256,11 @@ process_requests()
       recv_udp_rr();
       break;
       
+    case DO_RDS_STREAM:
+      rds_enable=1;
+      recv_udp_stream();
+      break;
+      
 #ifdef WANT_DLPI
 
     case DO_DLPI_CO_RR:
@@ -748,6 +753,11 @@ main(int argc, char *argv[])
       strncpy(listen_port,optarg,sizeof(listen_port));
       not_inetd = 1;
       break;
+    case 'r':
+      rds_enable = 1;
+      not_inetd = 1;
+      local_address_family = AF_INET;
+      break;
     case '4':
       local_address_family = AF_INET;
       break;
Index: netperf-2.4.2/src/netsh.c
===================================================================
--- netperf-2.4.2.orig/src/netsh.c
+++ netperf-2.4.2/src/netsh.c
@@ -85,6 +85,8 @@ double atof(const char *);
 #include "nettest_dns.h"
 #endif /* DO_DNS */
 
+int     rds_enable;                     /* enable RDS testing */
+
 /************************************************************************/
 /*									*/
 /*	Global constants  and macros					*/
@@ -94,7 +96,7 @@ double atof(const char *);
  /* Some of the args take optional parameters. Since we are using */
  /* getopt to parse the command line, we will tell getopt that they do */
  /* not take parms, and then look for them ourselves */
-#define GLOBAL_CMD_LINE_ARGS "A:a:b:B:CcdDf:F:H:hi:I:k:K:l:L:n:O:o:P:p:t:T:v:W:w:46"
+#define GLOBAL_CMD_LINE_ARGS "A:a:b:B:CcdDf:F:H:hi:I:k:K:l:L:n:O:o:P:p:rt:T:v:W:w:46"
 
 /************************************************************************/
 /*									*/
@@ -228,6 +230,7 @@ Options:\n\
     -d                Increase debugging output\n\
     -L name,family    Use name to pick listen address and family for family\n\
     -p portnum        Listen for connect requests on portnum.\n\
+    -r                Enable RDS usage for UDP tests\n\
     -4                Do IPv4\n\
     -6                Do IPv6\n\
     -v verbosity      Specify the verbosity level\n\
@@ -256,6 +259,7 @@ Global options:\n\
     -i max,min        Specify the max and min number of iterations (15,1)\n\
     -I lvl[,intvl]    Specify confidence level (95 or 99) (99) \n\
                       and confidence interval in percentage (10)\n\
+    -r                Enable RDS usage for UDP tests\n\
     -l testlen        Specify test duration (>0 secs) (<0 bytes|trans)\n\
     -L name|ip,fam *  Specify the local ip|name and address family\n\
     -o send,recv      Set the local send,recv buffer offsets\n\
@@ -360,6 +364,10 @@ parse_address_family(char family_string[
       strstr(temp,"4")) {
     return(AF_INET);
   }
+  if (strstr(temp,"af_rds") ||
+      strstr(temp,"32")) {
+    return(AF_RDS);
+  }
   if (strstr(temp,"unspec") ||
       strstr(temp,"0")) {
     return(AF_UNSPEC);
@@ -732,6 +740,11 @@ scan_cmd_line(int argc, char *argv[])
 		"Unable to malloc space for result brand\n");
       }
       break;
+    case 'r':
+      rds_enable = 1;
+      address_family = AF_INET;
+      local_address_family = AF_INET;
+      break;
     case '4':
       address_family = AF_INET;
       local_address_family = AF_INET;
@@ -780,9 +793,13 @@ scan_cmd_line(int argc, char *argv[])
       break;
 #endif
     default:
-      printf("Netperf does not understand %d as an address family\n",
+      if (address_family == AF_RDS)
+          strcpy(host_name,"localhost");
+      else {
+        printf("Netperf does not understand %d as an address family\n",
 	     address_family);
-      exit(-1);
+        exit(-1);
+      }
     }
   }
   
@@ -805,9 +822,13 @@ scan_cmd_line(int argc, char *argv[])
 	break;
 #endif
       default:
-	printf("Netperf does not understand %d as an address family\n",
-	       address_family);
-	exit(-1);
+        if (address_family == AF_RDS)
+	        strcpy(local_host_name,"0.0.0.0");
+        else {
+	        printf("Netperf does not understand %d as an address family\n",
+	                address_family);
+                exit(-1);
+        }
       }
       break;
 #if defined(AF_INET6)
@@ -849,6 +870,12 @@ scan_cmd_line(int argc, char *argv[])
 	scan_sockets_args(argc, argv);
       }
 
+    else if (strcasecmp(test_name,"RDS_STREAM") == 0)
+      {
+        rds_enable = 1;
+	scan_sockets_args(argc, argv);
+      }
+
 #ifdef WANT_DLPI
     else if ((strcasecmp(test_name,"DLCO_RR") == 0) ||
 	     (strcasecmp(test_name,"DLCL_RR") == 0) ||
Index: netperf-2.4.2/src/netsh.h
===================================================================
--- netperf-2.4.2.orig/src/netsh.h
+++ netperf-2.4.2/src/netsh.h
@@ -141,5 +141,21 @@ extern int
   dlpi_sap;
 
 #endif /* WANT_DLPI */
+#endif
 
+# include "pfhack.h"
+extern int rds_enable;
+#ifndef AF_RDS
+# define AF_RDS OFFICIAL_PF_RDS
+#endif
+#ifndef PF_RDS
+# define PF_RDS AF_RDS
+#endif
+#ifndef SOL_RDS
+# define SOL_RDS OFFICIAL_SOL_RDS
 #endif
+#ifndef NF_RDS
+# define NF_RDS AF_RDS
+#endif
+
+
Index: netperf-2.4.2/src/nettest_bsd.c
===================================================================
--- netperf-2.4.2.orig/src/nettest_bsd.c
+++ netperf-2.4.2/src/nettest_bsd.c
@@ -438,6 +438,8 @@ nf_to_af(int nf) {
 #endif
     break;
   default:
+    if (nf == NF_RDS)
+    	return AF_RDS;
     return AF_UNSPEC;
     break;
   }
@@ -459,6 +461,8 @@ af_to_nf(int af) {
     break;
 #endif
   default:
+    if (af == AF_RDS)
+    	return NF_RDS;
     return NF_UNSPEC;
     break;
   }
@@ -711,6 +715,10 @@ get_port_number(struct addrinfo *res) 
   }
 #endif
   default:
+    if (res->ai_family == AF_RDS) {
+	struct sockaddr_in *foo = (struct sockaddr_in *)res->ai_addr;
+	return(ntohs(foo->sin_port));
+    }
     fprintf(where,
 	    "Unexpected Address Family of %u\n",res->ai_family);
     fflush(where);
@@ -737,10 +745,15 @@ set_port_number(struct addrinfo *res, un
   }
 #endif
   default:
-    fprintf(where,
-	    "Unexpected Address Family of %u\n",res->ai_family);
-    fflush(where);
-    exit(-1);
+    if (res->ai_family == AF_RDS) {
+    	struct sockaddr_in *foo = (struct sockaddr_in *)res->ai_addr;
+    	foo->sin_port = htons(port);
+    } else {
+    	fprintf(where,
+    	        "Unexpected Address Family of %u\n",res->ai_family);
+    	fflush(where);
+    	exit(-1);
+    }
   }
 }
 
@@ -765,12 +778,16 @@ create_data_socket(struct addrinfo *res)
   int one;
   int    on  = 1;
   
-
   /*set up the data socket                        */
-  temp_socket = socket(res->ai_family,
-		       res->ai_socktype,
-		       res->ai_protocol);
-  
+  if (rds_enable)
+          temp_socket = socket(PF_RDS,
+        		       SOCK_SEQPACKET,
+        		       0);
+  else
+          temp_socket = socket(res->ai_family,
+        		       res->ai_socktype,
+        		       res->ai_protocol);
+ 
   if (temp_socket == INVALID_SOCKET){
     fprintf(where,
 	    "netperf: create_data_socket: socket: errno %d fam %s type %s prot %s errmsg %s\n",
@@ -5518,7 +5535,10 @@ bytes   bytes    secs            #      
 		     0);
 
   if ( print_headers ) {
-    print_top_test_header("UDP UNIDIRECTIONAL SEND TEST",local_res,remote_res);
+        if (rds_enable)
+                print_top_test_header("RDS UNIDIRECTIONAL SEND TEST",local_res,remote_res);
+        else
+                print_top_test_header("UDP UNIDIRECTIONAL SEND TEST",local_res,remote_res);
   }
 
   send_ring            = NULL;
@@ -9411,9 +9431,9 @@ recv_tcp_tran_rr()
   /* multi-connection situation, but for now, we'll ignore the issue */
   /* and concentrate on single connection testing. */
   
-  if (bind(s_listen,
-	   (struct sockaddr *)&myaddr_in,
-	   sizeof(myaddr_in)) == SOCKET_ERROR) {
+  if (bind(send_socket,
+        (struct sockaddr *)myaddr,
+	        sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
     netperf_response.content.serv_errno = errno;
     close(s_listen);
     send_response();
Index: netperf-2.4.2/src/Makefile.am
===================================================================
--- netperf-2.4.2.orig/src/Makefile.am
+++ netperf-2.4.2/src/Makefile.am
@@ -8,7 +8,7 @@ USE_CPU_SOURCE=netcpu_ at NETCPU_SOURCE@.c
 
 EXTRA_DIST = netcpu_none.c netcpu_looper.c netcpu_pstat.c netcpu_pstatnew.c netcpu_perfstat.c netcpu_procstat.c netcpu_kstat.c netcpu_kstat10.c netcpu_sysctl.c netcpu_ntperf.c nettest_ipv6.c nettest_ipv6.h missing/* dirs NetPerfDir/* NetServerDir/*
 
-COMMON_SRC = hist.h netlib.c netlib.h netcpu.h netsh.c netsh.h nettest_bsd.c nettest_bsd.h nettest_dlpi.c nettest_dlpi.h nettest_dns.c nettest_dns.h nettest_unix.c nettest_unix.h nettest_xti.c nettest_xti.h nettest_sctp.c nettest_sctp.h
+COMMON_SRC = hist.h netlib.c netlib.h netcpu.h netsh.c netsh.h nettest_bsd.c nettest_bsd.h nettest_dlpi.c nettest_dlpi.h nettest_dns.c nettest_dns.h nettest_unix.c nettest_unix.h nettest_xti.c nettest_xti.h nettest_sctp.c nettest_sctp.h pfhack.c pfhack.h
 
 netperf_SOURCES = netperf.c $(COMMON_SRC) $(USE_CPU_SOURCE)
 netserver_SOURCES = netserver.c $(COMMON_SRC) $(USE_CPU_SOURCE)
Index: netperf-2.4.2/src/pfhack.c
===================================================================
--- /dev/null
+++ netperf-2.4.2/src/pfhack.c
@@ -0,0 +1,79 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * pfhack.c - discover the RDS constants 
+ *
+ * PF_RDS and SOL_RDS should be assigned constants.  However, we don't have
+ * official values yet.  There is a hack to overload an existing PF_ value
+ * (21).  This dynamic code detects what the running kernel is using.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include "pfhack.h"
+
+#define PF_RDS_PATH	"/proc/sys/net/rds/pf_rds"
+#define SOL_RDS_PATH	"/proc/sys/net/rds/sol_rds"
+
+/* We don't allow any system that can't read pf_rds */
+static void explode(const char *reason)
+{
+	fprintf(stderr,
+	       	"Unable to determine RDS constant: %s\n",
+	       	reason);
+
+	exit(1);
+}
+
+static int discover_constant(const char *path, int official)
+{
+	int fd;
+	int tmp;
+	ssize_t ret, total = 0;
+	char buf[PATH_MAX];
+	char *ptr;
+	long val;
+
+	tmp = official;
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		explode("Can't open address constant");
+
+	while ((unsigned)total < sizeof(buf)) {
+		ret = read(fd, buf + total, sizeof(buf) - total);
+		if (ret > 0)
+			total += ret;
+		else
+			break;
+	}
+
+	close(fd);
+
+	if (ret < 0)
+		explode("Error reading address constant");
+
+	val = strtoul(buf, &ptr, 0);
+	if ((val > INT_MAX) || !ptr || (*ptr && (*ptr != '\n')))
+		explode("Invalid address constant");
+
+	return (int)val;
+}
+
+int discover_pf_rds()
+{
+	return discover_constant(PF_RDS_PATH, OFFICIAL_PF_RDS);
+}
+
+int discover_sol_rds()
+{
+	return discover_constant(SOL_RDS_PATH, OFFICIAL_SOL_RDS);
+}
Index: netperf-2.4.2/src/pfhack.h
===================================================================
--- /dev/null
+++ netperf-2.4.2/src/pfhack.h
@@ -0,0 +1,23 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * pfhack.h - discover the RDS constants 
+ *
+ * PF_RDS and SOL_RDS should be assigned constants.  However, we don't have
+ * official values yet.  There is a hack to overload an existing PF_ value
+ * (21).  This dynamic code detects what the running kernel is using.
+ */
+
+#ifndef __PF_HACK_H
+#define __PF_HACK_H
+
+#define OFFICIAL_PF_RDS		32
+#define OFFICIAL_SOL_RDS	272
+
+extern int discover_pf_rds();
+extern int discover_sol_rds();
+
+#define AF_RDS discover_pf_rds()
+#define SOL_RDS discover_sol_rds()
+
+#endif  /* __PF_HACK_H */
Index: netperf-2.4.2/autogen.sh
===================================================================
--- /dev/null
+++ netperf-2.4.2/autogen.sh
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+# We change dir since the later utilities assume to work in the project dir
+cd ${0%*/*}
+
+# create config dir if not exist
+test -d config || mkdir config
+
+set -x
+(aclocal -I config -I src/missing/m4 2>&1 ) && \
+(libtoolize --force --copy) && \
+(autoheader) && \
+(automake --foreign --add-missing --copy) && \
+autoconf




More information about the rds-devel mailing list