session: support local sessions and deprecate redirects

Memfd backed shared memory segments can only be negotiated over sockets.
For such scenarios, the existing redirect mechanism that establishes
cut-through sessions does not work anymore as the two peer application
do not share such a socket.

This patch adds support for local sessions, as opposed to sessions
backed by a transport connection, in a way that is almost transparent to
the two applications by reusing the existing binary api messages.
Moreover, all segment allocations are now entirely done through the
segment manager valloc, so segment overlaps due to independent
allocations previously required for redirects are completely avoided.
The one notable characteristic of local sessions (cut-through from app
perspective) notification messages is that they carry pointers to two
event queues, one for each app peer, instead of one. For
transport-backed sessions one of the queues can be inferred but for
local session they cannot.

Change-Id: Ia443fb63e2d9d8e43490275062a708f039038175
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/session-apps/echo_server.c b/src/vnet/session-apps/echo_server.c
index 024ffa6..0d03508 100644
--- a/src/vnet/session-apps/echo_server.c
+++ b/src/vnet/session-apps/echo_server.c
@@ -245,7 +245,6 @@
   .session_disconnect_callback = echo_server_session_disconnect_callback,
   .session_connected_callback = echo_server_session_connected_callback,
   .add_segment_callback = echo_server_add_segment_callback,
-  .redirect_connect_callback = echo_server_redirect_connect_callback,
   .builtin_server_rx_callback = echo_server_rx_callback,
   .session_reset_callback = echo_server_session_reset_callback
 };
@@ -387,7 +386,7 @@
   u8 server_uri_set = 0, *appns_id = 0;
   u64 tmp, appns_flags = 0, appns_secret = 0;
   char *default_uri = "tcp://0.0.0.0/1234";
-  int rv;
+  int rv, is_stop = 0;
 
   esm->no_echo = 0;
   esm->fifo_size = 64 << 10;
@@ -431,11 +430,29 @@
 	appns_flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
       else if (unformat (input, "secret %lu", &appns_secret))
 	;
+      else if (unformat (input, "stop"))
+	is_stop = 1;
       else
 	return clib_error_return (0, "failed: unknown input `%U'",
 				  format_unformat_error, input);
     }
 
+  if (is_stop)
+    {
+      if (esm->app_index == (u32) ~ 0)
+	{
+	  clib_warning ("server not running");
+	  return clib_error_return (0, "failed: server not running");
+	}
+      rv = echo_server_detach ();
+      if (rv)
+	{
+	  clib_warning ("failed: detach");
+	  return clib_error_return (0, "failed: server detach %d", rv);
+	}
+      return 0;
+    }
+
   vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */ );
 
   if (!server_uri_set)