session: cleanup attach flags
[vpp.git] / src / uri / uri_tcp_test.c
old mode 100644 (file)
new mode 100755 (executable)
index c057e06..8bdcac3
 #include <vpp/api/vpe_all_api_h.h>
 #undef vl_printfun
 
-/* Satisfy external references when not linking with -lvlib */
-vlib_main_t vlib_global_main;
-vlib_main_t **vlib_mains;
-
 typedef struct
 {
   svm_fifo_t *server_rx_fifo;
   svm_fifo_t *server_tx_fifo;
 
-  u32 vpp_session_handle;
+  u64 vpp_session_handle;
+  u64 bytes_received;
+  f64 start;
 } session_t;
 
 typedef enum
 {
   STATE_START,
+  STATE_ATTACHED,
   STATE_READY,
   STATE_DISCONNECTING,
   STATE_FAILED
@@ -127,6 +126,34 @@ uri_tcp_test_main_t uri_tcp_test_main;
 #define NITER 4000000
 #endif
 
+static u8 *
+format_api_error (u8 * s, va_list * args)
+{
+  uri_tcp_test_main_t *utm = &uri_tcp_test_main;
+  i32 error = va_arg (*args, u32);
+  uword *p;
+
+  p = hash_get (utm->error_string_by_error_number, -error);
+
+  if (p)
+    s = format (s, "%s", p[0]);
+  else
+    s = format (s, "%d", error);
+  return s;
+}
+
+static void
+init_error_string_table (uri_tcp_test_main_t * utm)
+{
+  utm->error_string_by_error_number = hash_create (0, sizeof (uword));
+
+#define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
+  foreach_vnet_api_error;
+#undef _
+
+  hash_set (utm->error_string_by_error_number, 99, "Misc");
+}
+
 int
 wait_for_state_change (uri_tcp_test_main_t * utm, connection_state_t state)
 {
@@ -144,31 +171,46 @@ wait_for_state_change (uri_tcp_test_main_t * utm, connection_state_t state)
        return 0;
       if (utm->state == STATE_FAILED)
        return -1;
+      if (utm->time_to_stop == 1)
+       return 0;
     }
   clib_warning ("timeout waiting for STATE_READY");
   return -1;
 }
 
 void
-application_attach (uri_tcp_test_main_t * utm)
+application_send_attach (uri_tcp_test_main_t * utm)
 {
   vl_api_application_attach_t *bmp;
-  u32 fifo_size = 3 << 20;
+  u32 fifo_size = 4 << 20;
   bmp = vl_msg_api_alloc (sizeof (*bmp));
   memset (bmp, 0, sizeof (*bmp));
 
   bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
   bmp->client_index = utm->my_client_index;
   bmp->context = ntohl (0xfeedface);
-  bmp->options[SESSION_OPTIONS_FLAGS] =
-    SESSION_OPTIONS_FLAGS_USE_FIFO | SESSION_OPTIONS_FLAGS_ADD_SEGMENT;
-  bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
-  bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
-  bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
-  bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = 256 << 20;
+  bmp->options[APP_OPTIONS_FLAGS] =
+    APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT;
+  bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16;
+  bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
+  bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
+  bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
+  bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20;
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
 }
 
+int
+application_attach (uri_tcp_test_main_t * utm)
+{
+  application_send_attach (utm);
+  if (wait_for_state_change (utm, STATE_ATTACHED))
+    {
+      clib_warning ("timeout waiting for STATE_ATTACHED");
+      return -1;
+    }
+  return 0;
+}
+
 void
 application_detach (uri_tcp_test_main_t * utm)
 {
@@ -192,8 +234,8 @@ vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
 
   if (mp->retval)
     {
-      uword *errp = hash_get (utm->error_string_by_error_number, mp->retval);
-      clib_warning ("attach failed: %s", *errp);
+      clib_warning ("attach failed: %U", format_api_error,
+                   clib_net_to_host_u32 (mp->retval));
       utm->state = STATE_FAILED;
       return;
     }
@@ -204,6 +246,7 @@ vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
       return;
     }
 
+  memset (a, 0, sizeof (*a));
   a->segment_name = (char *) mp->segment_name;
   a->segment_size = mp->segment_size;
 
@@ -219,8 +262,9 @@ vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
     }
 
   utm->our_event_queue =
-    (unix_shared_memory_queue_t *) mp->app_event_queue_address;
-
+    uword_to_pointer (mp->app_event_queue_address,
+                     unix_shared_memory_queue_t *);
+  utm->state = STATE_ATTACHED;
 }
 
 static void
@@ -231,18 +275,6 @@ vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
     clib_warning ("detach returned with err: %d", mp->retval);
 }
 
-static void
-init_error_string_table (uri_tcp_test_main_t * utm)
-{
-  utm->error_string_by_error_number = hash_create (0, sizeof (uword));
-
-#define _(n,v,s) hash_set (utm->error_string_by_error_number, -v, s);
-  foreach_vnet_api_error;
-#undef _
-
-  hash_set (utm->error_string_by_error_number, 99, "Misc");
-}
-
 static void
 stop_signal (int signum)
 {
@@ -296,6 +328,7 @@ vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
   svm_fifo_segment_create_args_t _a, *a = &_a;
   int rv;
 
+  memset (a, 0, sizeof (*a));
   a->segment_name = (char *) mp->segment_name;
   a->segment_size = mp->segment_size;
   /* Attach to the segment vpp created */
@@ -310,11 +343,23 @@ vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
                mp->segment_size);
 }
 
+static void
+session_print_stats (uri_tcp_test_main_t * utm, session_t * session)
+{
+  f64 deltat;
+  u64 bytes;
+
+  deltat = clib_time_now (&utm->clib_time) - session->start;
+  bytes = utm->i_am_master ? session->bytes_received : utm->bytes_to_send;
+  fformat (stdout, "Finished in %.6f\n", deltat);
+  fformat (stdout, "%.4f Gbit/second\n", (bytes * 8.0) / deltat / 1e9);
+}
+
 static void
 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
 {
   uri_tcp_test_main_t *utm = &uri_tcp_test_main;
-  session_t *session;
+  session_t *session = 0;
   vl_api_disconnect_session_reply_t *rmp;
   uword *p;
   int rv = 0;
@@ -333,7 +378,7 @@ vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
       rv = -11;
     }
 
-  utm->time_to_stop = 1;
+//  utm->time_to_stop = 1;
 
   rmp = vl_msg_api_alloc (sizeof (*rmp));
   memset (rmp, 0, sizeof (*rmp));
@@ -342,13 +387,15 @@ vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
   rmp->retval = rv;
   rmp->handle = mp->handle;
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
+
+  if (session)
+    session_print_stats (utm, session);
 }
 
 static void
 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
 {
   uri_tcp_test_main_t *utm = &uri_tcp_test_main;
-  session_t *session;
   vl_api_reset_session_reply_t *rmp;
   uword *p;
   int rv = 0;
@@ -357,9 +404,8 @@ vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
 
   if (p)
     {
-      session = pool_elt_at_index (utm->sessions, p[0]);
-      hash_unset (utm->session_index_by_vpp_handles, mp->handle);
-      pool_put (utm->sessions, session);
+      clib_warning ("got reset");
+      /* Cleanup later */
       utm->time_to_stop = 1;
     }
   else
@@ -392,20 +438,25 @@ client_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
   /* Read the bytes */
   do
     {
-      n_read = svm_fifo_dequeue_nowait (rx_fifo, 0,
+      n_read = svm_fifo_dequeue_nowait (rx_fifo,
                                        clib_min (vec_len (utm->rx_buf),
                                                  bytes), utm->rx_buf);
       if (n_read > 0)
        {
          bytes -= n_read;
-         for (i = 0; i < n_read; i++)
+         if (utm->test_return_packets)
            {
-             if (utm->rx_buf[i] != ((utm->client_bytes_received + i) & 0xff))
+             for (i = 0; i < n_read; i++)
                {
-                 clib_warning ("error at byte %lld, 0x%x not 0x%x",
-                               utm->client_bytes_received + i,
-                               utm->rx_buf[i],
-                               ((utm->client_bytes_received + i) & 0xff));
+                 if (utm->rx_buf[i]
+                     != ((utm->client_bytes_received + i) & 0xff))
+                   {
+                     clib_warning ("error at byte %lld, 0x%x not 0x%x",
+                                   utm->client_bytes_received + i,
+                                   utm->rx_buf[i],
+                                   ((utm->client_bytes_received +
+                                     i) & 0xff));
+                   }
                }
            }
          utm->client_bytes_received += n_read;
@@ -432,11 +483,11 @@ client_handle_event_queue (uri_tcp_test_main_t * utm)
                                0 /* nowait */ );
   switch (e->event_type)
     {
-    case FIFO_EVENT_SERVER_RX:
+    case FIFO_EVENT_APP_RX:
       client_handle_fifo_event_rx (utm, e);
       break;
 
-    case FIFO_EVENT_SERVER_EXIT:
+    case FIFO_EVENT_DISCONNECT:
       return;
 
     default:
@@ -458,11 +509,11 @@ client_rx_thread_fn (void *arg)
                                    0 /* nowait */ );
       switch (e->event_type)
        {
-       case FIFO_EVENT_SERVER_RX:
+       case FIFO_EVENT_APP_RX:
          client_handle_fifo_event_rx (utm, e);
          break;
 
-       case FIFO_EVENT_SERVER_EXIT:
+       case FIFO_EVENT_DISCONNECT:
          return 0;
        default:
          clib_warning ("unknown event type %d", e->event_type);
@@ -477,7 +528,7 @@ client_rx_thread_fn (void *arg)
 
 
 static void
-vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
+vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
 {
   uri_tcp_test_main_t *utm = &uri_tcp_test_main;
   session_t *session;
@@ -487,14 +538,21 @@ vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
 
   if (mp->retval)
     {
-      uword *errp = hash_get (utm->error_string_by_error_number, -mp->retval);
-      clib_warning ("connection failed with code: %s", *errp);
+      clib_warning ("connection failed with code: %U", format_api_error,
+                   clib_net_to_host_u32 (mp->retval));
       utm->state = STATE_FAILED;
       return;
     }
+  else
+    {
+      clib_warning ("connected with local ip %U port %d", format_ip46_address,
+                   mp->lcl_ip, mp->is_ip4,
+                   clib_net_to_host_u16 (mp->lcl_port));
+    }
 
-  utm->vpp_event_queue = (unix_shared_memory_queue_t *)
-    mp->vpp_event_queue_address;
+  utm->vpp_event_queue =
+    uword_to_pointer (mp->vpp_event_queue_address,
+                     unix_shared_memory_queue_t *);
 
   /*
    * Setup session
@@ -503,14 +561,15 @@ vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
   pool_get (utm->sessions, session);
   session_index = session - utm->sessions;
 
-  rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
+  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
   rx_fifo->client_session_index = session_index;
-  tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
+  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
   tx_fifo->client_session_index = session_index;
 
   session->server_rx_fifo = rx_fifo;
   session->server_tx_fifo = tx_fifo;
   session->vpp_session_handle = mp->handle;
+  session->start = clib_time_now (&utm->clib_time);
 
   /* Save handle */
   utm->connected_session_index = session_index;
@@ -537,20 +596,19 @@ send_test_chunk (uri_tcp_test_main_t * utm, svm_fifo_t * tx_fifo, int mypid,
   u64 bytes_sent = 0;
   int test_buf_offset = 0;
   u32 bytes_to_snd;
-  u32 queue_max_chunk = 64 << 10, actual_write;
+  u32 queue_max_chunk = 128 << 10, actual_write;
   session_fifo_event_t evt;
-  static int serial_number = 0;
   int rv;
 
   bytes_to_snd = (bytes == 0) ? vec_len (test_data) : bytes;
   if (bytes_to_snd > vec_len (test_data))
     bytes_to_snd = vec_len (test_data);
 
-  while (bytes_to_snd > 0)
+  while (bytes_to_snd > 0 && !utm->time_to_stop)
     {
-      actual_write =
-       bytes_to_snd > queue_max_chunk ? queue_max_chunk : bytes_to_snd;
-      rv = svm_fifo_enqueue_nowait (tx_fifo, mypid, actual_write,
+      actual_write = (bytes_to_snd > queue_max_chunk) ?
+       queue_max_chunk : bytes_to_snd;
+      rv = svm_fifo_enqueue_nowait (tx_fifo, actual_write,
                                    test_data + test_buf_offset);
 
       if (rv > 0)
@@ -563,8 +621,7 @@ send_test_chunk (uri_tcp_test_main_t * utm, svm_fifo_t * tx_fifo, int mypid,
            {
              /* Fabricate TX event, send to vpp */
              evt.fifo = tx_fifo;
-             evt.event_type = FIFO_EVENT_SERVER_TX;
-             evt.event_id = serial_number++;
+             evt.event_type = FIFO_EVENT_APP_TX;
 
              unix_shared_memory_queue_add (utm->vpp_event_queue,
                                            (u8 *) & evt,
@@ -587,21 +644,25 @@ client_send_data (uri_tcp_test_main_t * utm)
   session = pool_elt_at_index (utm->sessions, utm->connected_session_index);
   tx_fifo = session->server_tx_fifo;
 
+  ASSERT (vec_len (test_data) > 0);
+
   vec_validate (utm->rx_buf, vec_len (test_data) - 1);
   n_iterations = utm->bytes_to_send / vec_len (test_data);
 
   for (i = 0; i < n_iterations; i++)
     {
       send_test_chunk (utm, tx_fifo, mypid, 0);
+      if (utm->time_to_stop)
+       break;
     }
 
   leftover = utm->bytes_to_send % vec_len (test_data);
   if (leftover)
     send_test_chunk (utm, tx_fifo, mypid, leftover);
 
-  if (utm->test_return_packets)
+  if (!utm->drop_packets)
     {
-      f64 timeout = clib_time_now (&utm->clib_time) + 2;
+      f64 timeout = clib_time_now (&utm->clib_time) + 10;
 
       /* Wait for the outstanding packets */
       while (utm->client_bytes_received <
@@ -618,7 +679,7 @@ client_send_data (uri_tcp_test_main_t * utm)
 }
 
 void
-client_connect (uri_tcp_test_main_t * utm)
+client_send_connect (uri_tcp_test_main_t * utm)
 {
   vl_api_connect_uri_t *cmp;
   cmp = vl_msg_api_alloc (sizeof (*cmp));
@@ -631,8 +692,20 @@ client_connect (uri_tcp_test_main_t * utm)
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & cmp);
 }
 
+int
+client_connect (uri_tcp_test_main_t * utm)
+{
+  client_send_connect (utm);
+  if (wait_for_state_change (utm, STATE_READY))
+    {
+      clib_warning ("Connect failed");
+      return -1;
+    }
+  return 0;
+}
+
 void
-client_disconnect (uri_tcp_test_main_t * utm)
+client_send_disconnect (uri_tcp_test_main_t * utm)
 {
   session_t *connected_session;
   vl_api_disconnect_session_t *dmp;
@@ -646,21 +719,35 @@ client_disconnect (uri_tcp_test_main_t * utm)
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & dmp);
 }
 
+int
+client_disconnect (uri_tcp_test_main_t * utm)
+{
+  client_send_disconnect (utm);
+  clib_warning ("Sent disconnect");
+  if (wait_for_state_change (utm, STATE_START))
+    {
+      clib_warning ("Disconnect failed");
+      return -1;
+    }
+  return 0;
+}
+
 static void
 client_test (uri_tcp_test_main_t * utm)
 {
   int i;
 
-  application_attach (utm);
-  client_connect (utm);
+  if (application_attach (utm))
+    return;
 
-  if (wait_for_state_change (utm, STATE_READY))
+  if (client_connect (utm))
     {
+      application_detach (utm);
       return;
     }
 
   /* Init test data */
-  vec_validate (utm->connect_test_data, 64 * 1024 - 1);
+  vec_validate (utm->connect_test_data, 128 * 1024 - 1);
   for (i = 0; i < vec_len (utm->connect_test_data); i++)
     utm->connect_test_data[i] = i & 0xff;
 
@@ -670,11 +757,6 @@ client_test (uri_tcp_test_main_t * utm)
   /* Disconnect */
   client_disconnect (utm);
 
-  if (wait_for_state_change (utm, STATE_START))
-    {
-      clib_warning ("Disconnect failed");
-      return;
-    }
   application_detach (utm);
 }
 
@@ -685,9 +767,8 @@ vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
 
   if (mp->retval)
     {
-      uword *errp = hash_get (utm->error_string_by_error_number,
-                             -clib_net_to_host_u32 (mp->retval));
-      clib_warning ("bind failed: %s", (char *) *errp);
+      clib_warning ("bind failed: %U", format_api_error,
+                   clib_net_to_host_u32 (mp->retval));
       utm->state = STATE_FAILED;
       return;
     }
@@ -806,16 +887,17 @@ vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
   ip_str = format (0, "%U", format_ip46_address, &mp->ip, mp->is_ip4);
   clib_warning ("Accepted session from: %s:%d", ip_str,
                clib_net_to_host_u16 (mp->port));
-  utm->vpp_event_queue = (unix_shared_memory_queue_t *)
-    mp->vpp_event_queue_address;
+  utm->vpp_event_queue =
+    uword_to_pointer (mp->vpp_event_queue_address,
+                     unix_shared_memory_queue_t *);
 
   /* Allocate local session and set it up */
   pool_get (utm->sessions, session);
   session_index = session - utm->sessions;
 
-  rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
+  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
   rx_fifo->client_session_index = session_index;
-  tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
+  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
   tx_fifo->client_session_index = session_index;
 
   session->server_rx_fifo = rx_fifo;
@@ -842,7 +924,11 @@ vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
   memset (rmp, 0, sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
   rmp->handle = mp->handle;
+  rmp->context = mp->context;
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & rmp);
+
+  session->bytes_received = 0;
+  session->start = clib_time_now (&utm->clib_time);
 }
 
 void
@@ -853,59 +939,71 @@ server_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
   int n_read;
   session_fifo_event_t evt;
   unix_shared_memory_queue_t *q;
-  int rv, bytes;
+  session_t *session;
+  int rv;
+  u32 max_dequeue, offset, max_transfer, rx_buf_len;
 
+  rx_buf_len = vec_len (utm->rx_buf);
   rx_fifo = e->fifo;
-  tx_fifo = utm->sessions[rx_fifo->client_session_index].server_tx_fifo;
+  session = &utm->sessions[rx_fifo->client_session_index];
+  tx_fifo = session->server_tx_fifo;
 
-  bytes = svm_fifo_max_dequeue (rx_fifo);
+  max_dequeue = svm_fifo_max_dequeue (rx_fifo);
   /* Allow enqueuing of a new event */
   svm_fifo_unset_event (rx_fifo);
 
-  if (bytes == 0)
-    return;
+  if (PREDICT_FALSE (max_dequeue == 0))
+    {
+      return;
+    }
 
-  /* Read the bytes */
+  /* Read the max_dequeue */
   do
     {
-      n_read = svm_fifo_dequeue_nowait (rx_fifo, 0, vec_len (utm->rx_buf),
-                                       utm->rx_buf);
+      max_transfer = clib_min (rx_buf_len, max_dequeue);
+      n_read = svm_fifo_dequeue_nowait (rx_fifo, max_transfer, utm->rx_buf);
       if (n_read > 0)
-       bytes -= n_read;
-
-      if (utm->drop_packets)
-       continue;
+       {
+         max_dequeue -= n_read;
+         session->bytes_received += n_read;
+       }
 
       /* Reflect if a non-drop session */
-      if (n_read > 0)
+      if (!utm->drop_packets && n_read > 0)
        {
+         offset = 0;
          do
            {
-             rv = svm_fifo_enqueue_nowait (tx_fifo, 0, n_read, utm->rx_buf);
+             rv = svm_fifo_enqueue_nowait (tx_fifo, n_read,
+                                           &utm->rx_buf[offset]);
+             if (rv > 0)
+               {
+                 n_read -= rv;
+                 offset += rv;
+               }
            }
-         while (rv <= 0 && !utm->time_to_stop);
+         while ((rv <= 0 || n_read > 0) && !utm->time_to_stop);
 
          /* If event wasn't set, add one */
          if (svm_fifo_set_event (tx_fifo))
            {
              /* Fabricate TX event, send to vpp */
              evt.fifo = tx_fifo;
-             evt.event_type = FIFO_EVENT_SERVER_TX;
-             evt.event_id = e->event_id;
+             evt.event_type = FIFO_EVENT_APP_TX;
 
              q = utm->vpp_event_queue;
              unix_shared_memory_queue_add (q, (u8 *) & evt,
-                                           0 /* do wait for mutex */ );
+                                           1 /* do wait for mutex */ );
            }
        }
     }
-  while ((n_read < 0 || bytes > 0) && !utm->time_to_stop);
+  while ((n_read < 0 || max_dequeue > 0) && !utm->time_to_stop);
 }
 
 void
 server_handle_event_queue (uri_tcp_test_main_t * utm)
 {
-  session_fifo_event_t _e, *e = &_e;;
+  session_fifo_event_t _e, *e = &_e;
 
   while (1)
     {
@@ -913,11 +1011,11 @@ server_handle_event_queue (uri_tcp_test_main_t * utm)
                                    0 /* nowait */ );
       switch (e->event_type)
        {
-       case FIFO_EVENT_SERVER_RX:
+       case FIFO_EVENT_APP_RX:
          server_handle_fifo_event_rx (utm, e);
          break;
 
-       case FIFO_EVENT_SERVER_EXIT:
+       case FIFO_EVENT_DISCONNECT:
          return;
 
        default:
@@ -935,7 +1033,7 @@ server_handle_event_queue (uri_tcp_test_main_t * utm)
 }
 
 void
-server_listen (uri_tcp_test_main_t * utm)
+server_send_listen (uri_tcp_test_main_t * utm)
 {
   vl_api_bind_uri_t *bmp;
   bmp = vl_msg_api_alloc (sizeof (*bmp));
@@ -948,8 +1046,20 @@ server_listen (uri_tcp_test_main_t * utm)
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & bmp);
 }
 
+int
+server_listen (uri_tcp_test_main_t * utm)
+{
+  server_send_listen (utm);
+  if (wait_for_state_change (utm, STATE_READY))
+    {
+      clib_warning ("timeout waiting for STATE_READY");
+      return -1;
+    }
+  return 0;
+}
+
 void
-server_unbind (uri_tcp_test_main_t * utm)
+server_send_unbind (uri_tcp_test_main_t * utm)
 {
   vl_api_unbind_uri_t *ump;
 
@@ -962,31 +1072,33 @@ server_unbind (uri_tcp_test_main_t * utm)
   vl_msg_api_send_shmem (utm->vl_input_queue, (u8 *) & ump);
 }
 
+int
+server_unbind (uri_tcp_test_main_t * utm)
+{
+  server_send_unbind (utm);
+  if (wait_for_state_change (utm, STATE_START))
+    {
+      clib_warning ("timeout waiting for STATE_START");
+      return -1;
+    }
+  return 0;
+}
+
 void
 server_test (uri_tcp_test_main_t * utm)
 {
-  application_attach (utm);
+  if (application_attach (utm))
+    return;
 
   /* Bind to uri */
-  server_listen (utm);
-
-  if (wait_for_state_change (utm, STATE_READY))
-    {
-      clib_warning ("timeout waiting for STATE_READY");
-      return;
-    }
+  if (server_listen (utm))
+    return;
 
   /* Enter handle event loop */
   server_handle_event_queue (utm);
 
   /* Cleanup */
-  server_unbind (utm);
-
-  if (wait_for_state_change (utm, STATE_START))
-    {
-      clib_warning ("timeout waiting for STATE_START");
-      return;
-    }
+  server_send_unbind (utm);
 
   application_detach (utm);
 
@@ -998,16 +1110,25 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
                                           mp)
 {
   uri_tcp_test_main_t *utm = &uri_tcp_test_main;
+  session_t *session;
+
+  if (mp->retval)
+    {
+      clib_warning ("vpp complained about disconnect: %d",
+                   ntohl (mp->retval));
+    }
 
-  clib_warning ("retval %d", ntohl (mp->retval));
   utm->state = STATE_START;
+  session = pool_elt_at_index (utm->sessions, utm->connected_session_index);
+  if (session)
+    session_print_stats (utm, session);
 }
 
 #define foreach_uri_msg                                 \
 _(BIND_URI_REPLY, bind_uri_reply)                       \
 _(UNBIND_URI_REPLY, unbind_uri_reply)                   \
 _(ACCEPT_SESSION, accept_session)                       \
-_(CONNECT_URI_REPLY, connect_uri_reply)                 \
+_(CONNECT_SESSION_REPLY, connect_session_reply)         \
 _(DISCONNECT_SESSION, disconnect_session)               \
 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply)   \
 _(RESET_SESSION, reset_session)                         \
@@ -1053,7 +1174,7 @@ main (int argc, char **argv)
   /* make the main heap thread-safe */
   h->flags |= MHEAP_FLAG_THREAD_SAFE;
 
-  vec_validate (utm->rx_buf, 65536);
+  vec_validate (utm->rx_buf, 128 << 10);
 
   utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
 
@@ -1116,6 +1237,7 @@ main (int argc, char **argv)
   utm->drop_packets = drop_packets;
   utm->test_return_packets = test_return_packets;
   utm->bytes_to_send = bytes_to_send;
+  utm->time_to_stop = 0;
 
   setup_signal_handlers ();
   uri_api_hookup (utm);