session: extend connect api for internal apps
[vpp.git] / src / vnet / session / session_test.c
index a9a902d..5c2993e 100644 (file)
@@ -45,26 +45,34 @@ dummy_session_reset_callback (stream_session_t * s)
   clib_warning ("called...");
 }
 
+volatile u32 connected_session_index = ~0;
+volatile u32 connected_session_thread = ~0;
 int
 dummy_session_connected_callback (u32 app_index, u32 api_context,
                                  stream_session_t * s, u8 is_fail)
 {
-  clib_warning ("called...");
-  return -1;
+  if (s)
+    {
+      connected_session_index = s->session_index;
+      connected_session_thread = s->thread_index;
+    }
+  return 0;
 }
 
+static u32 dummy_segment_count;
+
 int
-dummy_add_segment_callback (u32 client_index, const u8 * seg_name,
-                           u32 seg_size)
+dummy_add_segment_callback (u32 client_index, const ssvm_private_t * fs)
 {
-  clib_warning ("called...");
-  return -1;
+  dummy_segment_count = 1;
+  return 0;
 }
 
 int
-dummy_redirect_connect_callback (u32 client_index, void *mp)
+dummy_del_segment_callback (u32 client_index, const ssvm_private_t * fs)
 {
-  return VNET_API_ERROR_SESSION_REDIRECT;
+  dummy_segment_count = 0;
+  return 0;
 }
 
 void
@@ -73,11 +81,18 @@ dummy_session_disconnect_callback (stream_session_t * s)
   clib_warning ("called...");
 }
 
+static u32 dummy_accept;
+volatile u32 accepted_session_index;
+volatile u32 accepted_session_thread;
+
 int
 dummy_session_accept_callback (stream_session_t * s)
 {
-  clib_warning ("called...");
-  return -1;
+  dummy_accept = 1;
+  accepted_session_index = s->session_index;
+  accepted_session_thread = s->thread_index;
+  s->session_state = SESSION_STATE_READY;
+  return 0;
 }
 
 int
@@ -93,11 +108,53 @@ static session_cb_vft_t dummy_session_cbs = {
   .session_connected_callback = dummy_session_connected_callback,
   .session_accept_callback = dummy_session_accept_callback,
   .session_disconnect_callback = dummy_session_disconnect_callback,
-  .builtin_server_rx_callback = dummy_server_rx_callback,
-  .redirect_connect_callback = dummy_redirect_connect_callback,
+  .builtin_app_rx_callback = dummy_server_rx_callback,
+  .add_segment_callback = dummy_add_segment_callback,
+  .del_segment_callback = dummy_del_segment_callback,
 };
 /* *INDENT-ON* */
 
+static int
+session_create_lookpback (u32 table_id, u32 * sw_if_index,
+                         ip4_address_t * intf_addr)
+{
+  u8 intf_mac[6];
+
+  clib_memset (intf_mac, 0, sizeof (intf_mac));
+
+  if (vnet_create_loopback_interface (sw_if_index, intf_mac, 0, 0))
+    {
+      clib_warning ("couldn't create loopback. stopping the test!");
+      return -1;
+    }
+
+  if (table_id != 0)
+    {
+      ip_table_create (FIB_PROTOCOL_IP4, table_id, 0, 0);
+      ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id, 0);
+    }
+
+  vnet_sw_interface_set_flags (vnet_get_main (), *sw_if_index,
+                              VNET_SW_INTERFACE_FLAG_ADMIN_UP);
+
+  if (ip4_add_del_interface_address (vlib_get_main (), *sw_if_index,
+                                    intf_addr, 24, 0))
+    {
+      clib_warning ("couldn't assign loopback ip %U", format_ip4_address,
+                   intf_addr);
+      return -1;
+    }
+
+  return 0;
+}
+
+static void
+session_delete_loopback (u32 sw_if_index)
+{
+  /* fails spectacularly  */
+  /* vnet_delete_loopback_interface (sw_if_index); */
+}
+
 static int
 session_test_basic (vlib_main_t * vm, unformat_input_t * input)
 {
@@ -106,9 +163,8 @@ session_test_basic (vlib_main_t * vm, unformat_input_t * input)
   clib_error_t *error = 0;
   u32 server_index;
 
-  memset (options, 0, sizeof (options));
+  clib_memset (options, 0, sizeof (options));
   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
-  options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
   vnet_app_attach_args_t attach_args = {
@@ -116,11 +172,13 @@ session_test_basic (vlib_main_t * vm, unformat_input_t * input)
     .options = options,
     .namespace_id = 0,
     .session_cb_vft = &dummy_session_cbs,
+    .name = format (0, "session_test"),
   };
 
   error = vnet_application_attach (&attach_args);
   SESSION_TEST ((error == 0), "app attached");
   server_index = attach_args.app_index;
+  vec_free (attach_args.name);
 
   server_sep.is_ip4 = 1;
   vnet_bind_args_t bind_args = {
@@ -162,38 +220,221 @@ session_test_basic (vlib_main_t * vm, unformat_input_t * input)
   return 0;
 }
 
+static void
+session_add_del_route_via_lookup_in_table (u32 in_table_id, u32 via_table_id,
+                                          ip4_address_t * ip, u8 mask,
+                                          u8 is_add)
+{
+  fib_route_path_t *rpaths = 0, *rpath;
+  u32 in_fib_index, via_fib_index;
+
+  fib_prefix_t prefix = {
+    .fp_addr.ip4.as_u32 = ip->as_u32,
+    .fp_len = mask,
+    .fp_proto = FIB_PROTOCOL_IP4,
+  };
+
+  via_fib_index = fib_table_find (FIB_PROTOCOL_IP4, via_table_id);
+  if (via_fib_index == ~0)
+    {
+      clib_warning ("couldn't resolve via table id to index");
+      return;
+    }
+  in_fib_index = fib_table_find (FIB_PROTOCOL_IP4, in_table_id);
+  if (in_fib_index == ~0)
+    {
+      clib_warning ("couldn't resolve in table id to index");
+      return;
+    }
+
+  vec_add2 (rpaths, rpath, 1);
+  clib_memset (rpath, 0, sizeof (*rpath));
+  rpath->frp_weight = 1;
+  rpath->frp_fib_index = via_fib_index;
+  rpath->frp_proto = DPO_PROTO_IP4;
+  rpath->frp_sw_if_index = ~0;
+  rpath->frp_flags |= FIB_ROUTE_PATH_DEAG;
+
+  if (is_add)
+    fib_table_entry_path_add2 (in_fib_index, &prefix, FIB_SOURCE_CLI,
+                              FIB_ENTRY_FLAG_NONE, rpath);
+  else
+    fib_table_entry_path_remove2 (in_fib_index, &prefix, FIB_SOURCE_CLI,
+                                 rpath);
+  vec_free (rpaths);
+}
+
+static int
+session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input)
+{
+  session_endpoint_cfg_t client_sep = SESSION_ENDPOINT_CFG_NULL;
+  u64 options[APP_OPTIONS_N_OPTIONS], dummy_secret = 1234;
+  u16 dummy_server_port = 1234, dummy_client_port = 5678;
+  session_endpoint_t server_sep = SESSION_ENDPOINT_NULL;
+  u32 server_index, client_index, sw_if_index[2];
+  ip4_address_t intf_addr[3];
+  transport_connection_t *tc;
+  stream_session_t *s;
+  clib_error_t *error;
+  u8 *appns_id;
+
+  /*
+   * Create the loopbacks
+   */
+  intf_addr[0].as_u32 = clib_host_to_net_u32 (0x01010101),
+    session_create_lookpback (0, &sw_if_index[0], &intf_addr[0]);
+
+  intf_addr[1].as_u32 = clib_host_to_net_u32 (0x02020202),
+    session_create_lookpback (1, &sw_if_index[1], &intf_addr[1]);
+
+  session_add_del_route_via_lookup_in_table (0, 1, &intf_addr[1], 32,
+                                            1 /* is_add */ );
+  session_add_del_route_via_lookup_in_table (1, 0, &intf_addr[0], 32,
+                                            1 /* is_add */ );
+
+  /*
+   * Insert namespace
+   */
+  appns_id = format (0, "appns1");
+  vnet_app_namespace_add_del_args_t ns_args = {
+    .ns_id = appns_id,
+    .secret = dummy_secret,
+    .sw_if_index = sw_if_index[1],
+    .ip4_fib_id = 0,
+    .is_add = 1
+  };
+  error = vnet_app_namespace_add_del (&ns_args);
+  SESSION_TEST ((error == 0), "app ns insertion should succeed: %d",
+               clib_error_get_code (error));
+
+  /*
+   * Attach client/server
+   */
+  clib_memset (options, 0, sizeof (options));
+  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
+  options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
+
+  vnet_app_attach_args_t attach_args = {
+    .api_client_index = ~0,
+    .options = options,
+    .namespace_id = 0,
+    .session_cb_vft = &dummy_session_cbs,
+    .name = format (0, "session_test_client"),
+  };
+
+  error = vnet_application_attach (&attach_args);
+  SESSION_TEST ((error == 0), "client app attached");
+  client_index = attach_args.app_index;
+  vec_free (attach_args.name);
+
+  attach_args.name = format (0, "session_test_server");
+  attach_args.namespace_id = appns_id;
+  attach_args.options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret;
+  error = vnet_application_attach (&attach_args);
+  SESSION_TEST ((error == 0), "server app attached: %U", format_clib_error,
+               error);
+  vec_free (attach_args.name);
+  server_index = attach_args.app_index;
+
+  server_sep.is_ip4 = 1;
+  server_sep.port = dummy_server_port;
+  vnet_bind_args_t bind_args = {
+    .sep = server_sep,
+    .app_index = server_index,
+  };
+  error = vnet_bind (&bind_args);
+  SESSION_TEST ((error == 0), "server bind should work");
+
+  /*
+   * Connect and force lcl ip
+   */
+  client_sep.is_ip4 = 1;
+  client_sep.ip.ip4.as_u32 = clib_host_to_net_u32 (0x02020202);
+  client_sep.port = dummy_server_port;
+  client_sep.peer.is_ip4 = 1;
+  client_sep.peer.ip.ip4.as_u32 = clib_host_to_net_u32 (0x01010101);
+  client_sep.peer.port = dummy_client_port;
+  client_sep.transport_proto = TRANSPORT_PROTO_TCP;
+
+  vnet_connect_args_t connect_args = {
+    .sep_ext = client_sep,
+    .app_index = client_index,
+  };
+
+  error = vnet_connect (&connect_args);
+  SESSION_TEST ((error == 0), "connect should work");
+
+  /* wait for stuff to happen */
+  vlib_process_suspend (vm, 10e-3);
+
+  SESSION_TEST ((connected_session_index != ~0), "session should exist");
+  s = session_get (connected_session_index, connected_session_thread);
+  tc = session_get_transport (s);
+  SESSION_TEST ((tc != 0), "transport should exist");
+  SESSION_TEST ((memcmp (&tc->lcl_ip, &client_sep.peer.ip,
+                        sizeof (tc->lcl_ip)) == 0), "ips should be equal");
+  SESSION_TEST ((tc->lcl_port == dummy_client_port), "ports should be equal");
+
+  /* These sessions, because of the way they're established are pinned to
+   * main thread, even when we have workers and we avoid polling main thread,
+   * i.e., we can't cleanup pending disconnects, so force cleanup for both
+   */
+  stream_session_cleanup (s);
+  s = session_get (accepted_session_index, accepted_session_thread);
+  stream_session_cleanup (s);
+
+  vnet_app_detach_args_t detach_args = {
+    .app_index = server_index,
+  };
+  vnet_application_detach (&detach_args);
+  detach_args.app_index = client_index;
+  vnet_application_detach (&detach_args);
+
+  /* Allow the disconnects to finish before removing the routes. */
+  vlib_process_suspend (vm, 10e-3);
+
+  session_add_del_route_via_lookup_in_table (0, 1, &intf_addr[1], 32,
+                                            0 /* is_add */ );
+  session_add_del_route_via_lookup_in_table (1, 0, &intf_addr[0], 32,
+                                            0 /* is_add */ );
+
+  session_delete_loopback (sw_if_index[0]);
+  session_delete_loopback (sw_if_index[1]);
+  return 0;
+}
+
 static int
 session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
 {
   u64 options[APP_OPTIONS_N_OPTIONS], dummy_secret = 1234;
   u32 server_index, server_st_index, server_local_st_index;
-  u32 dummy_port = 1234, local_listener, client_index;
+  u32 dummy_port = 1234, client_index, server_wrk_index;
   u32 dummy_api_context = 4321, dummy_client_api_index = 1234;
   u32 dummy_server_api_index = ~0, sw_if_index = 0;
   session_endpoint_t server_sep = SESSION_ENDPOINT_NULL;
   session_endpoint_t client_sep = SESSION_ENDPOINT_NULL;
   session_endpoint_t intf_sep = SESSION_ENDPOINT_NULL;
   clib_error_t *error = 0;
-  u8 *ns_id = format (0, "appns1"), intf_mac[6];
+  u8 *ns_id = format (0, "appns1");
   app_namespace_t *app_ns;
   application_t *server;
   stream_session_t *s;
+  u64 handle;
   int code;
 
   server_sep.is_ip4 = 1;
   server_sep.port = dummy_port;
   client_sep.is_ip4 = 1;
   client_sep.port = dummy_port;
-  memset (options, 0, sizeof (options));
-  memset (intf_mac, 0, sizeof (intf_mac));
+  clib_memset (options, 0, sizeof (options));
 
   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
-  options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
   vnet_app_attach_args_t attach_args = {
     .api_client_index = ~0,
     .options = options,
     .namespace_id = 0,
     .session_cb_vft = &dummy_session_cbs,
+    .name = format (0, "session_test"),
   };
 
   vnet_bind_args_t bind_args = {
@@ -202,10 +443,10 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   };
 
   vnet_connect_args_t connect_args = {
-    .sep = client_sep,
     .app_index = 0,
     .api_context = 0,
   };
+  clib_memcpy (&connect_args.sep, &client_sep, sizeof (client_sep));
 
   vnet_unbind_args_t unbind_args = {
     .handle = bind_args.handle,
@@ -217,7 +458,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   };
 
   ip4_address_t intf_addr = {
-    .as_u32 = clib_host_to_net_u32 (0x06000105),
+    .as_u32 = clib_host_to_net_u32 (0x07000105),
   };
 
   intf_sep.ip.ip4 = intf_addr;
@@ -273,6 +514,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   SESSION_TEST ((error == 0), "server attachment should work");
   server_index = attach_args.app_index;
   server = application_get (server_index);
+  server_wrk_index = application_get_default_worker (server)->wrk_index;
   SESSION_TEST ((server->ns_index == 0),
                "server should be in the default ns");
 
@@ -283,8 +525,8 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   server_st_index = application_session_table (server, FIB_PROTOCOL_IP4);
   s = session_lookup_listener (server_st_index, &server_sep);
   SESSION_TEST ((s != 0), "listener should exist in global table");
-  SESSION_TEST ((s->app_index == server_index), "app_index should be that of "
-               "the server");
+  SESSION_TEST ((s->app_wrk_index == server_wrk_index), "app_index should be"
+               " that of the server");
   server_local_st_index = application_local_session_table (server);
   SESSION_TEST ((server_local_st_index == APP_INVALID_INDEX),
                "server shouldn't have access to local table");
@@ -312,6 +554,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   SESSION_TEST ((error == 0), "server attachment should work");
   server_index = attach_args.app_index;
   server = application_get (server_index);
+  server_wrk_index = application_get_default_worker (server)->wrk_index;
   SESSION_TEST ((server->ns_index == app_namespace_index (app_ns)),
                "server should be in the right ns");
 
@@ -321,12 +564,11 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   server_st_index = application_session_table (server, FIB_PROTOCOL_IP4);
   s = session_lookup_listener (server_st_index, &server_sep);
   SESSION_TEST ((s != 0), "listener should exist in global table");
-  SESSION_TEST ((s->app_index == server_index), "app_index should be that of "
-               "the server");
+  SESSION_TEST ((s->app_wrk_index == server_wrk_index), "app_index should be"
+               " that of the server");
   server_local_st_index = application_local_session_table (server);
-  local_listener =
-    session_lookup_local_endpoint (server_local_st_index, &server_sep);
-  SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (server_local_st_index, &server_sep);
+  SESSION_TEST ((handle != SESSION_INVALID_HANDLE),
                "listener should exist in local table");
 
   /*
@@ -344,12 +586,15 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   code = clib_error_get_code (error);
   SESSION_TEST ((code == VNET_API_ERROR_INVALID_VALUE),
                "error code should be invalid value (zero ip)");
+  SESSION_TEST ((dummy_segment_count == 0),
+               "shouldn't have received request to map new segment");
   connect_args.sep.ip.ip4.as_u8[0] = 127;
   error = vnet_connect (&connect_args);
-  SESSION_TEST ((error != 0), "client connect should return error code");
+  SESSION_TEST ((error == 0), "client connect should not return error code");
   code = clib_error_get_code (error);
-  SESSION_TEST ((code == VNET_API_ERROR_SESSION_REDIRECT),
-               "error code should be redirect");
+  SESSION_TEST ((dummy_segment_count == 1),
+               "should've received request to map new segment");
+  SESSION_TEST ((dummy_accept == 1), "should've received accept request");
   detach_args.app_index = client_index;
   vnet_application_detach (&detach_args);
 
@@ -376,9 +621,9 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
 
   s = session_lookup_listener (server_st_index, &server_sep);
   SESSION_TEST ((s == 0), "listener should not exist in global table");
-  local_listener =
-    session_lookup_local_endpoint (server_local_st_index, &server_sep);
-  SESSION_TEST ((s == 0), "listener should not exist in local table");
+  handle = session_lookup_local_endpoint (server_local_st_index, &server_sep);
+  SESSION_TEST ((handle == SESSION_INVALID_HANDLE),
+               "listener should not exist in local table");
 
   detach_args.app_index = server_index;
   vnet_application_detach (&detach_args);
@@ -401,18 +646,16 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   s = session_lookup_listener (server_st_index, &server_sep);
   SESSION_TEST ((s == 0), "listener should not exist in global table");
   server_local_st_index = application_local_session_table (server);
-  local_listener =
-    session_lookup_local_endpoint (server_local_st_index, &server_sep);
-  SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (server_local_st_index, &server_sep);
+  SESSION_TEST ((handle != SESSION_INVALID_HANDLE),
                "listener should exist in local table");
 
   unbind_args.handle = bind_args.handle;
   error = vnet_unbind (&unbind_args);
   SESSION_TEST ((error == 0), "unbind should work");
 
-  local_listener =
-    session_lookup_local_endpoint (server_local_st_index, &server_sep);
-  SESSION_TEST ((local_listener == SESSION_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (server_local_st_index, &server_sep);
+  SESSION_TEST ((handle == SESSION_INVALID_HANDLE),
                "listener should not exist in local table");
 
   /*
@@ -440,15 +683,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   /*
    * Create loopback interface
    */
-  if (vnet_create_loopback_interface (&sw_if_index, intf_mac, 0, 0))
-    {
-      clib_warning ("couldn't create loopback. stopping the test!");
-      return 0;
-    }
-  vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index,
-                              VNET_SW_INTERFACE_FLAG_ADMIN_UP);
-  ip4_add_del_interface_address (vlib_get_main (), sw_if_index, &intf_addr,
-                                24, 0);
+  session_create_lookpback (0, &sw_if_index, &intf_addr);
 
   /*
    * Update namespace
@@ -469,6 +704,8 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   error = vnet_application_attach (&attach_args);
   SESSION_TEST ((error == 0), "server attachment should work");
   server_index = attach_args.app_index;
+  server = application_get (server_index);
+  server_wrk_index = application_get_default_worker (server)->wrk_index;
 
   bind_args.app_index = server_index;
   error = vnet_bind (&bind_args);
@@ -478,12 +715,11 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
 
   s = session_lookup_listener (server_st_index, &intf_sep);
   SESSION_TEST ((s != 0), "intf listener should exist in global table");
-  SESSION_TEST ((s->app_index == server_index), "app_index should be that of "
-               "the server");
+  SESSION_TEST ((s->app_wrk_index == server_wrk_index), "app_index should be "
+               "that of the server");
   server_local_st_index = application_local_session_table (server);
-  local_listener =
-    session_lookup_local_endpoint (server_local_st_index, &server_sep);
-  SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (server_local_st_index, &server_sep);
+  SESSION_TEST ((handle != SESSION_INVALID_HANDLE),
                "zero listener should exist in local table");
   detach_args.app_index = server_index;
   vnet_application_detach (&detach_args);
@@ -491,9 +727,9 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   /*
    * Cleanup
    */
+  vec_free (attach_args.name);
   vec_free (ns_id);
-  /* fails in multi core scenarions .. */
-  /* vnet_delete_loopback_interface (sw_if_index); */
+  session_delete_loopback (sw_if_index);
   return 0;
 }
 
@@ -519,7 +755,7 @@ session_test_rule_table (vlib_main_t * vm, unformat_input_t * input)
        }
     }
 
-  memset (srt, 0, sizeof (*srt));
+  clib_memset (srt, 0, sizeof (*srt));
   session_rules_table_init (srt);
 
   ip4_address_t lcl_ip = {
@@ -772,7 +1008,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   session_endpoint_t server_sep = SESSION_ENDPOINT_NULL;
   u64 options[APP_OPTIONS_N_OPTIONS];
   u16 lcl_port = 1234, rmt_port = 4321;
-  u32 server_index, server_index2, app_index;
+  u32 server_index, server_index2;
   u32 dummy_server_api_index = ~0;
   transport_connection_t *tc;
   u32 dummy_port = 1111;
@@ -783,6 +1019,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   u32 local_ns_index = default_ns->local_table_index;
   int verbose = 0, rv;
   app_namespace_t *app_ns;
+  u64 handle;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -798,13 +1035,14 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
 
   server_sep.is_ip4 = 1;
   server_sep.port = dummy_port;
-  memset (options, 0, sizeof (options));
+  clib_memset (options, 0, sizeof (options));
 
   vnet_app_attach_args_t attach_args = {
     .api_client_index = ~0,
     .options = options,
     .namespace_id = 0,
     .session_cb_vft = &dummy_session_cbs,
+    .name = format (0, "session_test"),
   };
 
   vnet_bind_args_t bind_args = {
@@ -816,7 +1054,6 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
    * Attach server with global and local default scope
    */
   options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
-  options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
   attach_args.namespace_id = 0;
@@ -890,8 +1127,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
     .port = rmt_port,
     .transport_proto = TRANSPORT_PROTO_TCP,
   };
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index != server_index), "local session endpoint lookup "
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle != server_index), "local session endpoint lookup "
                "should not work (global scope)");
 
   tc = session_lookup_connection_wt4 (0, &lcl_pref.fp_addr.ip4,
@@ -915,8 +1152,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
                                      &is_filtered);
   SESSION_TEST ((tc->c_index == listener->connection_index),
                "optimized lookup for lcl port + 1 should work");
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == server_index), "local session endpoint lookup "
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == server_index), "local session endpoint lookup "
                "should work (lcl ip was zeroed)");
 
   /*
@@ -948,8 +1185,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
                "should fail (deny rule)");
   SESSION_TEST ((is_filtered == 1), "lookup should be filtered (deny)");
 
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_DROP_INDEX), "lookup for 1.2.3.4/32 1234 "
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_DROP_HANDLE), "lookup for 1.2.3.4/32 1234 "
                "5.6.7.8/16 4321 in local table should return deny");
 
   tc = session_lookup_connection_wt4 (0, &lcl_pref.fp_addr.ip4,
@@ -983,9 +1220,9 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
                "should fail (allow without app)");
   SESSION_TEST ((is_filtered == 0), "lookup should NOT be filtered");
 
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_INVALID_INDEX), "lookup for 1.2.3.4/32 1234"
-               " 5.6.7.8/32 4321 in local table should return invalid");
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_INVALID_HANDLE), "lookup for 1.2.3.4/32 "
+               "1234 5.6.7.8/32 4321 in local table should return invalid");
 
   if (verbose)
     {
@@ -995,15 +1232,15 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
     }
 
   sep.ip.ip4.as_u32 += 1 << 24;
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_DROP_INDEX), "lookup for 1.2.3.4/32 1234"
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_DROP_HANDLE), "lookup for 1.2.3.4/32 1234"
                " 5.6.7.9/32 4321 in local table should return deny");
 
   vnet_connect_args_t connect_args = {
-    .sep = sep,
     .app_index = attach_args.app_index,
     .api_context = 0,
   };
+  clib_memcpy (&connect_args.sep, &sep, sizeof (sep));
 
   /* Try connecting */
   error = vnet_connect (&connect_args);
@@ -1014,8 +1251,6 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
 
   sep.ip.ip4.as_u32 -= 1 << 24;
 
-
-
   /*
    * Delete masking rule: 1.2.3.4/32 1234 5.6.7.8/32 4321 allow
    */
@@ -1049,8 +1284,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
                                             TRANSPORT_PROTO_TCP);
     }
 
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_DROP_INDEX),
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_DROP_HANDLE),
                "local session endpoint lookup should return deny");
 
   /*
@@ -1065,8 +1300,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   error = vnet_session_rule_add_del (&args);
   SESSION_TEST ((error == 0), "Del 1.2.3.4/32 1234 5.6.7.8/32 4321 deny");
 
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_INVALID_HANDLE),
                "local session endpoint lookup should return invalid");
 
   /*
@@ -1082,8 +1317,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   args.table_args.rmt_port = 4321;
   error = vnet_session_rule_add_del (&args);
   SESSION_TEST ((error == 0), "Del 0/0 * 5.6.7.8/16 4321");
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index != server_index), "local session endpoint lookup "
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle != server_index), "local session endpoint lookup "
                "should not work (removed)");
 
   args.table_args.is_add = 0;
@@ -1270,18 +1505,20 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   /*
    * Lookup default namespace
    */
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_INVALID_INDEX),
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_INVALID_HANDLE),
                "lookup for 1.2.3.4/32 1234 5.6.7.8/32 4321 in local table "
                "should return allow (invalid)");
 
   sep.port += 1;
-  app_index = session_lookup_local_endpoint (local_ns_index, &sep);
-  SESSION_TEST ((app_index == APP_DROP_INDEX), "lookup for 1.2.3.4/32 1234 "
+  handle = session_lookup_local_endpoint (local_ns_index, &sep);
+  SESSION_TEST ((handle == SESSION_DROP_HANDLE), "lookup for 1.2.3.4/32 1234 "
                "5.6.7.8/16 432*2* in local table should return deny");
 
+
   connect_args.app_index = server_index;
-  connect_args.sep = sep;
+  clib_memcpy (&connect_args.sep, &sep, sizeof (sep));
+
   error = vnet_connect (&connect_args);
   SESSION_TEST ((error != 0), "connect should fail");
   rv = clib_error_get_code (error);
@@ -1291,8 +1528,8 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   /*
    * Lookup test namespace
    */
-  app_index = session_lookup_local_endpoint (app_ns->local_table_index, &sep);
-  SESSION_TEST ((app_index == APP_DROP_INDEX), "lookup for 1.2.3.4/32 1234 "
+  handle = session_lookup_local_endpoint (app_ns->local_table_index, &sep);
+  SESSION_TEST ((handle == SESSION_DROP_HANDLE), "lookup for 1.2.3.4/32 1234 "
                "5.6.7.8/16 4321 in local table should return deny");
 
   connect_args.app_index = server_index;
@@ -1324,6 +1561,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input)
   vnet_application_detach (&detach_args);
 
   vec_free (ns_id);
+  vec_free (attach_args.name);
   return 0;
 }
 
@@ -1337,7 +1575,7 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input)
   u32 server_index, app_index;
   u32 dummy_server_api_index = ~0, sw_if_index = 0;
   clib_error_t *error = 0;
-  u8 intf_mac[6], sst, is_filtered = 0;
+  u8 is_filtered = 0;
   stream_session_t *s;
   transport_connection_t *tc;
   u16 lcl_port = 1234, rmt_port = 4321;
@@ -1377,21 +1615,13 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input)
   /*
    * Create loopback interface
    */
-  memset (intf_mac, 0, sizeof (intf_mac));
-  if (vnet_create_loopback_interface (&sw_if_index, intf_mac, 0, 0))
-    {
-      clib_warning ("couldn't create loopback. stopping the test!");
-      return 0;
-    }
-  vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index,
-                              VNET_SW_INTERFACE_FLAG_ADMIN_UP);
-  ip4_add_del_interface_address (vlib_get_main (), sw_if_index, &lcl_ip,
-                                24, 0);
+  session_create_lookpback (0, &sw_if_index, &lcl_ip);
 
   app_ns = app_namespace_get_default ();
   app_ns->sw_if_index = sw_if_index;
 
-  memset (options, 0, sizeof (options));
+  clib_memset (options, 0, sizeof (options));
+  options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
   options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_PROXY;
   options[APP_OPTIONS_PROXY_TRANSPORT] = 1 << TRANSPORT_PROTO_TCP;
@@ -1402,6 +1632,7 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input)
     .options = options,
     .namespace_id = 0,
     .session_cb_vft = &dummy_session_cbs,
+    .name = format (0, "session_test"),
   };
 
   attach_args.api_client_index = dummy_server_api_index;
@@ -1423,10 +1654,9 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input)
                                      TRANSPORT_PROTO_TCP, 0, &is_filtered);
   SESSION_TEST ((tc != 0), "lookup 1.2.3.4 1234 5.6.7.8 4321 should be "
                "successful");
-  sst = session_type_from_proto_and_ip (TRANSPORT_PROTO_TCP, 1);
-  s = listen_session_get (sst, tc->s_index);
-  SESSION_TEST ((s->app_index == server_index), "lookup should return the"
-               " server");
+  s = listen_session_get (tc->s_index);
+  SESSION_TEST ((s->app_index == server_index), "lookup should return"
+               " the server");
 
   tc = session_lookup_connection_wt4 (0, &rmt_ip, &rmt_ip, lcl_port, rmt_port,
                                      TRANSPORT_PROTO_TCP, 0, &is_filtered);
@@ -1457,6 +1687,7 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input)
                "local session endpoint lookup should not work after detach");
   if (verbose)
     unformat_free (&tmp_input);
+  vec_free (attach_args.name);
   return 0;
 }
 
@@ -1480,6 +1711,8 @@ session_test (vlib_main_t * vm,
        res = session_test_rules (vm, input);
       else if (unformat (input, "proxy"))
        res = session_test_proxy (vm, input);
+      else if (unformat (input, "endpt-cfg"))
+       res = session_test_endpoint_cfg (vm, input);
       else if (unformat (input, "all"))
        {
          if ((res = session_test_basic (vm, input)))
@@ -1492,6 +1725,8 @@ session_test (vlib_main_t * vm,
            goto done;
          if ((res = session_test_proxy (vm, input)))
            goto done;
+         if ((res = session_test_endpoint_cfg (vm, input)))
+           goto done;
        }
       else
        break;