[netperf-dev] netperf2 commit notice r170 - trunk/src

raj at netperf.org raj at netperf.org
Thu Jan 17 16:16:28 PST 2008


Author: raj
Date: 2008-01-17 16:16:27 -0800 (Thu, 17 Jan 2008)
New Revision: 170

Modified:
   trunk/src/nettest_bsd.c
   trunk/src/nettest_bsd.h
   trunk/src/nettest_omni.c
Log:
looks like omni stream maerts rr cc and crr work for udp and tcp eghads of course still wrinkles

Modified: trunk/src/nettest_bsd.c
===================================================================
--- trunk/src/nettest_bsd.c	2008-01-17 07:04:37 UTC (rev 169)
+++ trunk/src/nettest_bsd.c	2008-01-18 00:16:27 UTC (rev 170)
@@ -912,6 +912,93 @@
   }
 }
 
+/* stuff the address family, port number and address into a
+   sockaddr. for now, we will go ahead and zero-out the sockaddr
+   first */
+void
+set_sockaddr_family_addr_port(struct sockaddr_storage *sockaddr, int family, void *addr, int port) {
+  
+  memset(sockaddr,0,sizeof(struct sockaddr_storage));
+
+  switch (family) {
+  case AF_INET: {
+    struct sockaddr_in *foo = (struct sockaddr_in *)sockaddr;
+    foo->sin_port = htons(port);
+    foo->sin_family = family;
+    memcpy(&(foo->sin_addr),addr,sizeof(foo->sin_addr));
+    *(int *)addr = htonl(*(int *)addr);
+    break;
+  }
+#if defined(AF_INET6)
+  case AF_INET6: {
+    struct sockaddr_in6 *foo = (struct sockaddr_in6 *)sockaddr;
+    int *bar;
+    int i;
+    foo->sin6_port = htons(port);
+    foo->sin6_family = family;
+    memcpy(&(foo->sin6_addr),addr,sizeof(foo->sin6_addr));
+    /* how to put this into "host" order? */
+    for (i = sizeof(foo->sin6_addr)/sizeof(int), bar=addr; i > 0; i--) {
+      bar[i] = htonl(bar[i]);
+    }
+    break;
+  }
+#endif
+  default:
+    fprintf(where,
+	    "Unexpected Address Family of %u\n",family);
+    fflush(where);
+    exit(-1);
+  }
+}
+
+/* pull the port and address out of the sockaddr in host format */
+int
+get_sockaddr_family_addr_port(struct sockaddr_storage *sockaddr, int family, void *addr, int *port)
+{
+  struct sockaddr_in *sin = (struct sockaddr_in *)sockaddr;
+
+  int ret = 0;
+  if (sin->sin_family != family) {
+    fprintf(where,
+	    "get_sockaddr_family_addr_port family mismatch %d vs %d\n",
+	    sin->sin_family,
+	    family);
+    fflush(where);
+    return -1;
+  }
+
+  switch(family) {
+  case  AF_INET: {
+    *port = ntohs(sin->sin_port);
+    memcpy(addr,&(sin->sin_addr),sizeof(sin->sin_addr));
+    if (*(int *)addr == INADDR_ANY) ret = 1;
+    *(int *)addr = ntohl(*(int *)addr);
+    break;
+  }
+#ifdef AF_INET6
+  case AF_INET6: {
+    int *foo;
+    int i;
+    ret = 0;
+    struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sockaddr;
+    *port = ntohs(sin6->sin6_port);
+    memcpy(addr,&(sin6->sin6_addr), sizeof(sin6->sin6_addr));
+    /* how to put this into "host" order? */
+    for (i = sizeof(sin6->sin6_addr)/sizeof(int), foo=addr; i > 0; i--) {
+      if (foo[i] != 0) ret = 1;
+      foo[i] = ntohl(foo[i]);
+    }
+  }
+#endif
+  default:
+    fprintf(where,
+	    "Unexpected Address Family of %u\n",family);
+    fflush(where);
+    exit(-1);
+  }
+  return ret;
+}
 
 
  /* This routine will create a data (listen) socket with the

Modified: trunk/src/nettest_bsd.h
===================================================================
--- trunk/src/nettest_bsd.h	2008-01-17 07:04:37 UTC (rev 169)
+++ trunk/src/nettest_bsd.h	2008-01-18 00:16:27 UTC (rev 170)
@@ -532,6 +532,14 @@
 				  char *portstr, 
 				  int family, 
 				  int port);
+extern void set_sockaddr_family_addr_port(struct sockaddr_storage *sockaddr,
+					  int family,
+					  void *addr,
+					  int port);
+extern int  get_sockaddr_family_addr_port(struct sockaddr_storage *sockaddr,
+					  int family,
+					  void *addr,
+					  int *port);
 extern void send_tcp_stream(char remote_host[]);
 extern void send_tcp_maerts(char remote_host[]);
 extern void send_tcp_rr(char remote_host[]);

Modified: trunk/src/nettest_omni.c
===================================================================
--- trunk/src/nettest_omni.c	2008-01-17 07:04:37 UTC (rev 169)
+++ trunk/src/nettest_omni.c	2008-01-18 00:16:27 UTC (rev 170)
@@ -118,8 +118,14 @@
 #define NETPERF_RECV 0x4
 
 #define NETPERF_IS_RR(x) (((x & NETPERF_XMIT) && (x & NETPERF_RECV)) || \
-			  (!((x & NETPERF_XMIT) || (x & NETPERF_RECV)))
+			  (!((x & NETPERF_XMIT) || (x & NETPERF_RECV))))
 
+#define NETPERF_RECV_ONLY(x) ((x & NETPERF_RECV) && !(x & NETPERF_XMIT))
+
+#define NETPERF_XMIT_ONLY(x) ((x & NETPERF_XMIT) && !(x & NETPERF_RECV))
+
+#define NETPERF_CC(x) (!(x & NETPERF_XMIT) && !(x & NETPERF_RECV))
+
 /* a boatload of globals while I settle things out */
 int socket_type;
 int protocol;
@@ -554,13 +560,15 @@
   
   int len;
   int ret;
-  int connected;
+  int connected = 0;
 
   struct ring_elt *send_ring;
   struct ring_elt *recv_ring;
 
   struct sockaddr_storage remote_addr;
+  struct sockaddr_storage my_addr;
   int                     remote_addr_len = sizeof(remote_addr);
+  int                     my_addr_len = sizeof(my_addr);
 
   SOCKET	data_socket;
   int           need_socket;
@@ -774,13 +782,12 @@
 
     /* some tests may require knowledge of our local addressing. such
        tests will for the time being require that the user specify a
-       local IP/name and port number, so we can extract them from the
-       local_res addrinfo. we "know" that the ipaddr "array" has
-       enough space for a full ipv6 address */
-    extract_inet_address_and_port(local_res,
-				  omni_request->ipaddr,
-				  sizeof(omni_request->ipaddr),
-				  &(omni_request->netperf_port));
+       local IP/name so we can extract them from the data_socket. */
+    getsockname(data_socket, (struct sockaddr *)&my_addr, &my_addr_len);
+    ret = get_sockaddr_family_addr_port(&my_addr,
+					nf_to_af(omni_request->ipfamily),
+					omni_request->ipaddr,
+					&(omni_request->netperf_port));
     
     if (debug > 1) {
       fprintf(where,"netperf: send_omni: requesting OMNI test\n");
@@ -1099,7 +1106,7 @@
        style test will have no xmit or recv :) so, we check for either
        both XMIT and RECV set, or neither XMIT nor RECV set */
     if (((direction & NETPERF_XMIT) && (direction & NETPERF_RECV)) ||
-	!((direction & NETPERF_XMIT) || (direction & NETPERF_RECV))) {
+	  !((direction & NETPERF_XMIT) || (direction & NETPERF_RECV))) { 
       trans_completed++;
       if (units_remaining) {
 	units_remaining--;
@@ -1603,8 +1610,17 @@
   
     }
     else {
-      /* I wonder if duping would be better here? */
-      if (omni_request->protocol == IPPROTO_UDP) data_socket = s_listen;
+      /* I wonder if duping would be better here? we also need to set
+	 peeraddr_in so we can send to netperf if this isn't a
+	 request/response test or if we are going to connect() the
+	 socket */
+      if (omni_request->protocol == IPPROTO_UDP) {
+	data_socket = s_listen;
+	set_sockaddr_family_addr_port(&peeraddr_in,
+				      nf_to_af(omni_request->ipfamily),
+				      omni_request->ipaddr,
+				      omni_request->netperf_port);
+      }
     }
 
     if (need_to_connect) {
@@ -1762,8 +1778,7 @@
     /* was this a "transaction" test? don't for get that a TCP_CC
        style test will have no xmit or recv :) so, we check for either
        both XMIT and RECV set, or neither XMIT nor RECV set */
-    if (((direction & NETPERF_XMIT) && (direction & NETPERF_RECV)) ||
-	!((direction & NETPERF_XMIT) || (direction & NETPERF_RECV))) {
+    if (NETPERF_IS_RR(omni_request->direction)) {
       trans_completed++;
       if (units_remaining) {
 	units_remaining--;



More information about the netperf-dev mailing list