session: segment manager refactor
[vpp.git] / src / vnet / session / application_interface.c
index f2a13be..efdd3dd 100644 (file)
@@ -275,9 +275,8 @@ vnet_connect_i (u32 app_index, u32 api_context, session_endpoint_t * sep,
 /**
  * unformat a vnet URI
  *
- * fifo://name
- * tcp://ip46-addr:port
- * udp://ip46-addr:port
+ * transport-proto://ip46-addr:port
+ * eg. tcp://ip46-addr:port
  *
  * u8 ip46_address[16];
  * u16  port_in_host_byte_order;
@@ -293,51 +292,21 @@ uword
 unformat_vnet_uri (unformat_input_t * input, va_list * args)
 {
   session_endpoint_t *sep = va_arg (*args, session_endpoint_t *);
-
-  if (unformat (input, "tcp://%U/%d", unformat_ip4_address, &sep->ip.ip4,
-               &sep->port))
-    {
-      sep->transport_proto = TRANSPORT_PROTO_TCP;
-      sep->port = clib_host_to_net_u16 (sep->port);
-      sep->is_ip4 = 1;
-      return 1;
-    }
-  if (unformat (input, "udp://%U/%d", unformat_ip4_address, &sep->ip.ip4,
-               &sep->port))
-    {
-      sep->transport_proto = TRANSPORT_PROTO_UDP;
-      sep->port = clib_host_to_net_u16 (sep->port);
-      sep->is_ip4 = 1;
-      return 1;
-    }
-  if (unformat (input, "udp://%U/%d", unformat_ip6_address, &sep->ip.ip6,
+  u32 transport_proto = 0;
+  if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+               &transport_proto, unformat_ip4_address, &sep->ip.ip4,
                &sep->port))
     {
-      sep->transport_proto = TRANSPORT_PROTO_UDP;
-      sep->port = clib_host_to_net_u16 (sep->port);
-      sep->is_ip4 = 0;
-      return 1;
-    }
-  if (unformat (input, "tcp://%U/%d", unformat_ip6_address, &sep->ip.ip6,
-               &sep->port))
-    {
-      sep->transport_proto = TRANSPORT_PROTO_TCP;
-      sep->port = clib_host_to_net_u16 (sep->port);
-      sep->is_ip4 = 0;
-      return 1;
-    }
-  if (unformat (input, "sctp://%U/%d", unformat_ip4_address, &sep->ip.ip4,
-               &sep->port))
-    {
-      sep->transport_proto = TRANSPORT_PROTO_SCTP;
+      sep->transport_proto = transport_proto;
       sep->port = clib_host_to_net_u16 (sep->port);
       sep->is_ip4 = 1;
       return 1;
     }
-  if (unformat (input, "sctp://%U/%d", unformat_ip6_address, &sep->ip.ip6,
+  if (unformat (input, "%U://%U/%d", unformat_transport_proto,
+               &transport_proto, unformat_ip6_address, &sep->ip.ip6,
                &sep->port))
     {
-      sep->transport_proto = TRANSPORT_PROTO_SCTP;
+      sep->transport_proto = transport_proto;
       sep->port = clib_host_to_net_u16 (sep->port);
       sep->is_ip4 = 0;
       return 1;
@@ -437,7 +406,7 @@ vnet_application_attach (vnet_app_attach_args_t * a)
 
   a->app_event_queue_address = pointer_to_uword (app->event_queue);
   sm = segment_manager_get (app->first_segment_manager);
-  fs = segment_manager_get_segment (sm->segment_indices[0]);
+  fs = segment_manager_get_segment_w_lock (sm, 0);
 
   if (application_is_proxy (app))
     application_setup_proxy (app);
@@ -446,6 +415,8 @@ vnet_application_attach (vnet_app_attach_args_t * a)
   a->segment = &fs->ssvm;
   a->app_index = app->index;
 
+  segment_manager_segment_reader_unlock (sm);
+
   return 0;
 }
 
@@ -531,8 +502,7 @@ vnet_disconnect_session (vnet_disconnect_args_t * a)
   /* We're peeking into another's thread pool. Make sure */
   ASSERT (s->session_index == index);
 
-  session_send_session_evt_to_thread (a->handle, FIFO_EVENT_DISCONNECT,
-                                     thread_index);
+  stream_session_disconnect (s);
   return 0;
 }