session: cleanup attach flags
[vpp.git] / src / uri / uri_tcp_test.c
index d1694cf..8bdcac3 100755 (executable)
 #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;
@@ -194,12 +190,12 @@ application_send_attach (uri_tcp_test_main_t * utm)
   bmp->client_index = utm->my_client_index;
   bmp->context = ntohl (0xfeedface);
   bmp->options[APP_OPTIONS_FLAGS] =
-    APP_OPTIONS_FLAGS_USE_FIFO | APP_OPTIONS_FLAGS_ADD_SEGMENT;
+    APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT;
   bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16;
-  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_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);
 }
 
@@ -250,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;
 
@@ -331,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 */
@@ -398,7 +396,6 @@ 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;
@@ -407,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
@@ -532,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;
@@ -547,6 +543,12 @@ vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
       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 =
     uword_to_pointer (mp->vpp_event_queue_address,
@@ -596,14 +598,13 @@ send_test_chunk (uri_tcp_test_main_t * utm, svm_fifo_t * tx_fifo, int mypid,
   u32 bytes_to_snd;
   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;
@@ -621,7 +622,6 @@ 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_APP_TX;
-             evt.event_id = serial_number++;
 
              unix_shared_memory_queue_add (utm->vpp_event_queue,
                                            (u8 *) & evt,
@@ -652,6 +652,8 @@ client_send_data (uri_tcp_test_main_t * utm)
   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);
@@ -922,6 +924,7 @@ 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;
@@ -987,7 +990,6 @@ server_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
              /* Fabricate TX event, send to vpp */
              evt.fifo = tx_fifo;
              evt.event_type = FIFO_EVENT_APP_TX;
-             evt.event_id = e->event_id;
 
              q = utm->vpp_event_queue;
              unix_shared_memory_queue_add (q, (u8 *) & evt,
@@ -1001,7 +1003,7 @@ server_handle_fifo_event_rx (uri_tcp_test_main_t * utm,
 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)
     {
@@ -1126,7 +1128,7 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
 _(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)                         \