session udp: fix transport flags and migration
[vpp.git] / src / vnet / session / session_node.c
index b1c2428..0290fe6 100644 (file)
@@ -50,6 +50,8 @@ session_mq_listen_handler (void *data)
   clib_memset (a, 0, sizeof (*a));
   a->sep.is_ip4 = mp->is_ip4;
   clib_memcpy_fast (&a->sep.ip, &mp->ip, sizeof (mp->ip));
+  if (mp->is_ip4)
+    ip46_address_mask_ip4 (&a->sep.ip);
   a->sep.port = mp->port;
   a->sep.fib_index = mp->vrf;
   a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
@@ -113,11 +115,17 @@ session_mq_connect_handler (void *data)
   a->sep.transport_proto = mp->proto;
   a->sep.peer.fib_index = mp->vrf;
   clib_memcpy_fast (&a->sep.peer.ip, &mp->lcl_ip, sizeof (mp->lcl_ip));
+  if (mp->is_ip4)
+    {
+      ip46_address_mask_ip4 (&a->sep.ip);
+      ip46_address_mask_ip4 (&a->sep.peer.ip);
+    }
+  a->sep.peer.port = mp->lcl_port;
   a->sep.peer.sw_if_index = ENDPOINT_INVALID_INDEX;
   a->sep_ext.parent_handle = mp->parent_handle;
   a->sep_ext.ckpair_index = mp->ckpair_index;
   a->sep_ext.crypto_engine = mp->crypto_engine;
-  a->sep_ext.flags = mp->flags;
+  a->sep_ext.transport_flags = mp->flags;
   if (mp->hostname_len)
     {
       vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
@@ -872,7 +880,7 @@ session_tx_fifo_read_and_snd_i (session_worker_t * wrk,
          (ctx->s->session_state >= SESSION_STATE_TRANSPORT_CLOSED))
        return SESSION_TX_OK;
       max_burst -= n_custom_tx;
-      if (!max_burst)
+      if (!max_burst || (ctx->s->flags & SESSION_F_CUSTOM_TX))
        {
          session_evt_add_old (wrk, elt);
          return SESSION_TX_OK;
@@ -883,18 +891,18 @@ session_tx_fifo_read_and_snd_i (session_worker_t * wrk,
 
   if (!ctx->sp.snd_space)
     {
-      /* This flow queue is "empty" so it should be re-evaluated before
-       * the ones that have data to send. */
-      if (PREDICT_TRUE (!ctx->sp.flags))
-       session_evt_add_head_old (wrk, elt);
+      /* If the deschedule flag was set, remove session from scheduler.
+       * Transport is responsible for rescheduling this session. */
+      if (ctx->sp.flags & TRANSPORT_SND_F_DESCHED)
+       transport_connection_deschedule (ctx->tc);
       /* Request to postpone the session, e.g., zero-wnd and transport
        * is not currently probing */
       else if (ctx->sp.flags & TRANSPORT_SND_F_POSTPONE)
        session_evt_add_old (wrk, elt);
-      /* If the deschedule flag was set, remove session from scheduler.
-       * Transport is responsible for rescheduling this session. */
+      /* This flow queue is "empty" so it should be re-evaluated before
+       * the ones that have data to send. */
       else
-       transport_connection_deschedule (ctx->tc);
+       session_evt_add_head_old (wrk, elt);
 
       return SESSION_TX_NO_DATA;
     }
@@ -1563,33 +1571,40 @@ session_queue_exit (vlib_main_t * vm)
 
 VLIB_MAIN_LOOP_EXIT_FUNCTION (session_queue_exit);
 
+static uword
+session_queue_run_on_main (vlib_main_t * vm)
+{
+  vlib_node_runtime_t *node;
+
+  node = vlib_node_get_runtime (vm, session_queue_node.index);
+  return session_queue_node_fn (vm, node, 0);
+}
+
 static uword
 session_queue_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
                       vlib_frame_t * f)
 {
-  f64 now, timeout = 1.0;
   uword *event_data = 0;
+  f64 timeout = 1.0;
   uword event_type;
 
   while (1)
     {
       vlib_process_wait_for_event_or_clock (vm, timeout);
-      now = vlib_time_now (vm);
       event_type = vlib_process_get_events (vm, (uword **) & event_data);
 
       switch (event_type)
        {
-       case SESSION_Q_PROCESS_FLUSH_FRAMES:
-         /* Flush the frames by updating all transports times */
-         transport_update_time (now, 0);
+       case SESSION_Q_PROCESS_RUN_ON_MAIN:
+         /* Run session queue node on main thread */
+         session_queue_run_on_main (vm);
          break;
        case SESSION_Q_PROCESS_STOP:
          timeout = 100000.0;
          break;
        case ~0:
-         /* Timed out. Update time for all transports to trigger all
-          * outstanding retransmits. */
-         transport_update_time (now, 0);
+         /* Timed out. Run on main to ensure all events are handled */
+         session_queue_run_on_main (vm);
          break;
        }
       vec_reset_length (event_data);