host stack: update stale copyright
[vpp.git] / src / vnet / session-apps / proxy.c
index 58412e0..0d4cdd4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015-2017 Cisco and/or its affiliates.
+* Copyright (c) 2017-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
@@ -34,6 +34,7 @@ proxy_cb_fn (void *data, u32 data_len)
   proxy_connect_args_t *pa = (proxy_connect_args_t *) data;
   vnet_connect_args_t a;
 
+  memset (&a, 0, sizeof (a));
   a.api_context = pa->api_context;
   a.app_index = pa->app_index;
   a.uri = pa->uri;
@@ -58,13 +59,13 @@ proxy_call_main_thread (vnet_connect_args_t * a)
 }
 
 static void
-delete_proxy_session (stream_session_t * s, int is_active_open)
+delete_proxy_session (session_t * s, int is_active_open)
 {
   proxy_main_t *pm = &proxy_main;
   proxy_session_t *ps = 0;
   vnet_disconnect_args_t _a, *a = &_a;
-  stream_session_t *active_open_session = 0;
-  stream_session_t *server_session = 0;
+  session_t *active_open_session = 0;
+  session_t *server_session = 0;
   uword *p;
   u64 handle;
 
@@ -105,9 +106,9 @@ delete_proxy_session (stream_session_t * s, int is_active_open)
       else if (!pool_is_free_index (pm->sessions, p[0]))
        {
          ps = pool_elt_at_index (pm->sessions, p[0]);
-         if (ps->vpp_server_handle != ~0)
+         if (ps->vpp_active_open_handle != ~0)
            active_open_session = session_get_from_handle
-             (ps->vpp_server_handle);
+             (ps->vpp_active_open_handle);
          else
            active_open_session = 0;
        }
@@ -116,7 +117,7 @@ delete_proxy_session (stream_session_t * s, int is_active_open)
   if (ps)
     {
       if (CLIB_DEBUG > 0)
-       memset (ps, 0xFE, sizeof (*ps));
+       clib_memset (ps, 0xFE, sizeof (*ps));
       pool_put (pm->sessions, ps);
     }
 
@@ -142,7 +143,7 @@ delete_proxy_session (stream_session_t * s, int is_active_open)
 }
 
 static int
-proxy_accept_callback (stream_session_t * s)
+proxy_accept_callback (session_t * s)
 {
   proxy_main_t *pm = &proxy_main;
 
@@ -154,35 +155,35 @@ proxy_accept_callback (stream_session_t * s)
 }
 
 static void
-proxy_disconnect_callback (stream_session_t * s)
+proxy_disconnect_callback (session_t * s)
 {
   delete_proxy_session (s, 0 /* is_active_open */ );
 }
 
 static void
-proxy_reset_callback (stream_session_t * s)
+proxy_reset_callback (session_t * s)
 {
-  clib_warning ("Reset session %U", format_stream_session, s, 2);
+  clib_warning ("Reset session %U", format_session, s, 2);
   delete_proxy_session (s, 0 /* is_active_open */ );
 }
 
 static int
 proxy_connected_callback (u32 app_index, u32 api_context,
-                         stream_session_t * s, u8 is_fail)
+                         session_t * s, u8 is_fail)
 {
   clib_warning ("called...");
   return -1;
 }
 
 static int
-proxy_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
+proxy_add_segment_callback (u32 client_index, u64 segment_handle)
 {
   clib_warning ("called...");
   return -1;
 }
 
 static int
-proxy_rx_callback (stream_session_t * s)
+proxy_rx_callback (session_t * s)
 {
   u32 max_dequeue;
   int actual_transfer __attribute__ ((unused));
@@ -194,7 +195,6 @@ proxy_rx_callback (stream_session_t * s)
   int proxy_index;
   uword *p;
   svm_fifo_t *active_open_tx_fifo;
-  session_fifo_event_t evt;
 
   ASSERT (s->thread_index == thread_index);
 
@@ -204,7 +204,7 @@ proxy_rx_callback (stream_session_t * s)
   if (PREDICT_TRUE (p != 0))
     {
       clib_spinlock_unlock_if_init (&pm->sessions_lock);
-      active_open_tx_fifo = s->server_rx_fifo;
+      active_open_tx_fifo = s->rx_fifo;
 
       /*
        * Send event for active open tx fifo
@@ -212,22 +212,22 @@ proxy_rx_callback (stream_session_t * s)
       if (svm_fifo_set_event (active_open_tx_fifo))
        {
          u32 ao_thread_index = active_open_tx_fifo->master_thread_index;
-         evt.fifo = active_open_tx_fifo;
-         evt.event_type = FIFO_EVENT_APP_TX;
-         if (svm_queue_add (pm->active_open_event_queue[ao_thread_index],
-                            (u8 *) & evt, 0 /* do wait for mutex */ ))
+         u32 ao_session_index = active_open_tx_fifo->master_session_index;
+         if (session_send_io_evt_to_thread_custom (&ao_session_index,
+                                                   ao_thread_index,
+                                                   SESSION_IO_EVT_TX))
            clib_warning ("failed to enqueue tx evt");
        }
     }
   else
     {
-      rx_fifo = s->server_rx_fifo;
-      tx_fifo = s->server_tx_fifo;
+      rx_fifo = s->rx_fifo;
+      tx_fifo = s->tx_fifo;
 
       ASSERT (rx_fifo->master_thread_index == thread_index);
       ASSERT (tx_fifo->master_thread_index == thread_index);
 
-      max_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
+      max_dequeue = svm_fifo_max_dequeue (s->rx_fifo);
 
       if (PREDICT_FALSE (max_dequeue == 0))
        return 0;
@@ -237,11 +237,11 @@ proxy_rx_callback (stream_session_t * s)
 
       /* $$$ your message in this space: parse url, etc. */
 
-      memset (a, 0, sizeof (*a));
+      clib_memset (a, 0, sizeof (*a));
 
       clib_spinlock_lock_if_init (&pm->sessions_lock);
       pool_get (pm->sessions, ps);
-      memset (ps, 0, sizeof (*ps));
+      clib_memset (ps, 0, sizeof (*ps));
       ps->server_rx_fifo = rx_fifo;
       ps->server_tx_fifo = tx_fifo;
       ps->vpp_server_handle = session_handle (s);
@@ -273,12 +273,11 @@ static session_cb_vft_t proxy_session_cb_vft = {
 
 static int
 active_open_connected_callback (u32 app_index, u32 opaque,
-                               stream_session_t * s, u8 is_fail)
+                               session_t * s, u8 is_fail)
 {
   proxy_main_t *pm = &proxy_main;
   proxy_session_t *ps;
   u8 thread_index = vlib_get_thread_index ();
-  session_fifo_event_t evt;
 
   if (is_fail)
     {
@@ -294,23 +293,23 @@ active_open_connected_callback (u32 app_index, u32 opaque,
   ps = pool_elt_at_index (pm->sessions, opaque);
   ps->vpp_active_open_handle = session_handle (s);
 
-  s->server_tx_fifo = ps->server_rx_fifo;
-  s->server_rx_fifo = ps->server_tx_fifo;
+  s->tx_fifo = ps->server_rx_fifo;
+  s->rx_fifo = ps->server_tx_fifo;
 
   /*
    * Reset the active-open tx-fifo master indices so the active-open session
    * will receive data, etc.
    */
-  s->server_tx_fifo->master_session_index = s->session_index;
-  s->server_tx_fifo->master_thread_index = s->thread_index;
+  s->tx_fifo->master_session_index = s->session_index;
+  s->tx_fifo->master_thread_index = s->thread_index;
 
   /*
    * Account for the active-open session's use of the fifos
    * so they won't disappear until the last session which uses
    * them disappears
    */
-  s->server_tx_fifo->refcnt++;
-  s->server_rx_fifo->refcnt++;
+  s->tx_fifo->refcnt++;
+  s->rx_fifo->refcnt++;
 
   hash_set (pm->proxy_session_by_active_open_handle,
            ps->vpp_active_open_handle, opaque);
@@ -320,57 +319,48 @@ active_open_connected_callback (u32 app_index, u32 opaque,
   /*
    * Send event for active open tx fifo
    */
-  if (svm_fifo_set_event (s->server_tx_fifo))
-    {
-      evt.fifo = s->server_tx_fifo;
-      evt.event_type = FIFO_EVENT_APP_TX;
-      if (svm_queue_add
-         (pm->active_open_event_queue[thread_index], (u8 *) & evt,
-          0 /* do wait for mutex */ ))
-       clib_warning ("failed to enqueue tx evt");
-    }
+  ASSERT (s->thread_index == thread_index);
+  if (svm_fifo_set_event (s->tx_fifo))
+    session_send_io_evt_to_thread (s->tx_fifo, SESSION_IO_EVT_TX);
 
   return 0;
 }
 
 static void
-active_open_reset_callback (stream_session_t * s)
+active_open_reset_callback (session_t * s)
 {
   delete_proxy_session (s, 1 /* is_active_open */ );
 }
 
 static int
-active_open_create_callback (stream_session_t * s)
+active_open_create_callback (session_t * s)
 {
   return 0;
 }
 
 static void
-active_open_disconnect_callback (stream_session_t * s)
+active_open_disconnect_callback (session_t * s)
 {
   delete_proxy_session (s, 1 /* is_active_open */ );
 }
 
 static int
-active_open_rx_callback (stream_session_t * s)
+active_open_rx_callback (session_t * s)
 {
-  proxy_main_t *pm = &proxy_main;
-  session_fifo_event_t evt;
   svm_fifo_t *proxy_tx_fifo;
 
-  proxy_tx_fifo = s->server_rx_fifo;
+  proxy_tx_fifo = s->rx_fifo;
 
   /*
    * Send event for server tx fifo
    */
   if (svm_fifo_set_event (proxy_tx_fifo))
     {
-      u32 p_thread_index = proxy_tx_fifo->master_thread_index;
-      evt.fifo = proxy_tx_fifo;
-      evt.event_type = FIFO_EVENT_APP_TX;
-      if (svm_queue_add (pm->server_event_queue[p_thread_index], (u8 *) & evt,
-                        0 /* do wait for mutex */ ))
-       clib_warning ("failed to enqueue server rx evt");
+      u8 thread_index = proxy_tx_fifo->master_thread_index;
+      u32 session_index = proxy_tx_fifo->master_session_index;
+      return session_send_io_evt_to_thread_custom (&session_index,
+                                                  thread_index,
+                                                  SESSION_IO_EVT_TX);
     }
 
   return 0;
@@ -410,8 +400,8 @@ proxy_server_attach ()
   vnet_app_attach_args_t _a, *a = &_a;
   u32 segment_size = 512 << 20;
 
-  memset (a, 0, sizeof (*a));
-  memset (options, 0, sizeof (options));
+  clib_memset (a, 0, sizeof (*a));
+  clib_memset (options, 0, sizeof (options));
 
   if (pm->private_segment_size)
     segment_size = pm->private_segment_size;
@@ -423,7 +413,7 @@ proxy_server_attach ()
   a->options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
   a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count;
   a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
-    pm->prealloc_fifos ? pm->prealloc_fifos : 1;
+    pm->prealloc_fifos ? pm->prealloc_fifos : 0;
 
   a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
 
@@ -444,8 +434,8 @@ active_open_attach (void)
   vnet_app_attach_args_t _a, *a = &_a;
   u64 options[16];
 
-  memset (a, 0, sizeof (*a));
-  memset (options, 0, sizeof (options));
+  clib_memset (a, 0, sizeof (*a));
+  clib_memset (options, 0, sizeof (options));
 
   a->api_client_index = pm->active_open_client_index;
   a->session_cb_vft = &active_open_clients;
@@ -456,7 +446,7 @@ active_open_attach (void)
   options[APP_OPTIONS_TX_FIFO_SIZE] = pm->fifo_size;
   options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = pm->private_segment_count;
   options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
-    pm->prealloc_fifos ? pm->prealloc_fifos : 1;
+    pm->prealloc_fifos ? pm->prealloc_fifos : 0;
 
   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN
     | APP_OPTIONS_FLAGS_IS_PROXY;
@@ -475,8 +465,8 @@ static int
 proxy_server_listen ()
 {
   proxy_main_t *pm = &proxy_main;
-  vnet_bind_args_t _a, *a = &_a;
-  memset (a, 0, sizeof (*a));
+  vnet_listen_args_t _a, *a = &_a;
+  clib_memset (a, 0, sizeof (*a));
   a->app_index = pm->server_app_index;
   a->uri = (char *) pm->server_uri;
   return vnet_bind_uri (a);
@@ -519,12 +509,11 @@ proxy_server_create (vlib_main_t * vm)
 
   for (i = 0; i < num_threads; i++)
     {
-      pm->active_open_event_queue[i] =
-       session_manager_get_vpp_event_queue (i);
+      pm->active_open_event_queue[i] = session_main_get_vpp_event_queue (i);
 
       ASSERT (pm->active_open_event_queue[i]);
 
-      pm->server_event_queue[i] = session_manager_get_vpp_event_queue (i);
+      pm->server_event_queue[i] = session_main_get_vpp_event_queue (i);
     }
 
   return 0;