-/*
- * Copyright (c) 2017 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:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
*/
-#include <vnet/session/application_namespace.h>
-#include <vnet/session/application_interface.h>
-#include <vnet/session/application.h>
-#include <vnet/session/session.h>
-
-#define SESSION_TEST_I(_cond, _comment, _args...) \
-({ \
- int _evald = (_cond); \
- if (!(_evald)) { \
- fformat(stderr, "FAIL:%d: " _comment "\n", \
- __LINE__, ##_args); \
- } else { \
- fformat(stderr, "PASS:%d: " _comment "\n", \
- __LINE__, ##_args); \
- } \
- _evald; \
-})
-
-#define SESSION_TEST(_cond, _comment, _args...) \
-{ \
- if (!SESSION_TEST_I(_cond, _comment, ##_args)) { \
- return 1; \
- } \
+#include <vat/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <vpp/api/types.h>
+
+#include <vnet/ip/ip_types_api.h>
+
+#define __plugin_msg_base session_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+#include <vlibmemory/vlib.api_enum.h>
+#include <vlibmemory/vlib.api_types.h>
+
+/* Declare message IDs */
+#include <vnet/format_fns.h>
+#include <vnet/session/session.api_enum.h>
+#include <vnet/session/session.api_types.h>
+
+#define vl_endianfun /* define message structures */
+#include <vnet/session/session.api.h>
+#undef vl_endianfun
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ u32 ping_id;
+ vat_main_t *vat_main;
+} session_test_main_t;
+
+static session_test_main_t session_test_main;
+
+static int
+api_session_rule_add_del (vat_main_t *vam)
+{
+ vl_api_session_rule_add_del_t *mp;
+ unformat_input_t *i = vam->input;
+ u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
+ u32 appns_index = 0, scope = 0;
+ ip4_address_t lcl_ip4, rmt_ip4;
+ ip6_address_t lcl_ip6, rmt_ip6;
+ u8 is_ip4 = 1, conn_set = 0;
+ u8 is_add = 1, *tag = 0;
+ int ret;
+ fib_prefix_t lcl, rmt;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "del"))
+ is_add = 0;
+ else if (unformat (i, "add"))
+ ;
+ else if (unformat (i, "proto tcp"))
+ proto = 0;
+ else if (unformat (i, "proto udp"))
+ proto = 1;
+ else if (unformat (i, "appns %d", &appns_index))
+ ;
+ else if (unformat (i, "scope %d", &scope))
+ ;
+ else if (unformat (i, "tag %_%v%_", &tag))
+ ;
+ else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip4_address,
+ &lcl_ip4, &lcl_plen, &lcl_port, unformat_ip4_address,
+ &rmt_ip4, &rmt_plen, &rmt_port))
+ {
+ is_ip4 = 1;
+ conn_set = 1;
+ }
+ else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip6_address,
+ &lcl_ip6, &lcl_plen, &lcl_port, unformat_ip6_address,
+ &rmt_ip6, &rmt_plen, &rmt_port))
+ {
+ is_ip4 = 0;
+ conn_set = 1;
+ }
+ else if (unformat (i, "action %d", &action))
+ ;
+ else
+ break;
+ }
+ if (proto == ~0 || !conn_set || action == ~0)
+ {
+ errmsg ("transport proto, connection and action must be set");
+ return -99;
+ }
+
+ if (scope > 3)
+ {
+ errmsg ("scope should be 0-3");
+ return -99;
+ }
+
+ M (SESSION_RULE_ADD_DEL, mp);
+
+ clib_memset (&lcl, 0, sizeof (lcl));
+ clib_memset (&rmt, 0, sizeof (rmt));
+ if (is_ip4)
+ {
+ ip_set (&lcl.fp_addr, &lcl_ip4, 1);
+ ip_set (&rmt.fp_addr, &rmt_ip4, 1);
+ lcl.fp_len = lcl_plen;
+ rmt.fp_len = rmt_plen;
+ }
+ else
+ {
+ ip_set (&lcl.fp_addr, &lcl_ip6, 0);
+ ip_set (&rmt.fp_addr, &rmt_ip6, 0);
+ lcl.fp_len = lcl_plen;
+ rmt.fp_len = rmt_plen;
+ }
+
+ ip_prefix_encode (&lcl, &mp->lcl);
+ ip_prefix_encode (&rmt, &mp->rmt);
+ mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
+ mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
+ mp->transport_proto =
+ proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
+ mp->action_index = clib_host_to_net_u32 (action);
+ mp->appns_index = clib_host_to_net_u32 (appns_index);
+ mp->scope = scope;
+ mp->is_add = is_add;
+ if (tag)
+ {
+ clib_memcpy (mp->tag, tag, vec_len (tag));
+ vec_free (tag);
+ }
+
+ S (mp);
+ W (ret);
+ return ret;
}
-void
-dummy_session_reset_callback (stream_session_t * s)
+static void
+vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t *mp)
{
- clib_warning ("called...");
}
-int
-dummy_session_connected_callback (u32 app_index, u32 api_context,
- stream_session_t * s, u8 is_fail)
+static void
+vl_api_app_add_cert_key_pair_reply_t_handler (
+ vl_api_app_add_cert_key_pair_reply_t *mp)
{
- clib_warning ("called...");
- return -1;
}
-int
-dummy_add_segment_callback (u32 client_index, const u8 * seg_name,
- u32 seg_size)
+static int
+api_app_attach (vat_main_t *vat)
{
- clib_warning ("called...");
return -1;
}
-int
-dummy_redirect_connect_callback (u32 client_index, void *mp)
+static int
+api_application_detach (vat_main_t *vat)
{
- return VNET_API_ERROR_SESSION_REDIRECT;
+ return -1;
}
-void
-dummy_session_disconnect_callback (stream_session_t * s)
+static int
+api_app_del_cert_key_pair (vat_main_t *vat)
{
- clib_warning ("called...");
+ return -1;
}
-int
-dummy_session_accept_callback (stream_session_t * s)
+static int
+api_app_add_cert_key_pair (vat_main_t *vat)
{
- clib_warning ("called...");
return -1;
}
-int
-dummy_server_rx_callback (stream_session_t * s)
+static int
+api_session_rules_dump (vat_main_t *vam)
{
- clib_warning ("called...");
- return -1;
+ vl_api_session_rules_dump_t *mp;
+ vl_api_control_ping_t *mp_ping;
+ int ret;
+
+ if (!vam->json_output)
+ {
+ print (vam->ofp, "%=20s", "Session Rules");
+ }
+
+ M (SESSION_RULES_DUMP, mp);
+ /* send it... */
+ S (mp);
+
+ /* Use a control ping for synchronization */
+ PING (&session_test_main, mp_ping);
+ S (mp_ping);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
}
-/* *INDENT-OFF* */
-static session_cb_vft_t dummy_session_cbs = {
- .session_reset_callback = dummy_session_reset_callback,
- .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,
-};
-/* *INDENT-ON* */
+static void
+vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t *mp)
+{
+ vat_main_t *vam = &vat_main;
+ fib_prefix_t lcl, rmt;
-static int
-session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
+ ip_prefix_decode (&mp->lcl, &lcl);
+ ip_prefix_decode (&mp->rmt, &rmt);
+
+ if (lcl.fp_proto == FIB_PROTOCOL_IP4)
+ {
+ print (vam->ofp,
+ "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
+ clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
+ mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
+ clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
+ &rmt.fp_addr.ip4, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
+ clib_net_to_host_u32 (mp->action_index), mp->tag);
+ }
+ else
+ {
+ print (vam->ofp,
+ "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
+ clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
+ mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
+ clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
+ &rmt.fp_addr.ip6, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
+ clib_net_to_host_u32 (mp->action_index), mp->tag);
+ }
+}
+
+static void
+vl_api_app_namespace_add_del_reply_t_handler (
+ vl_api_app_namespace_add_del_reply_t *mp)
{
- u64 options[SESSION_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_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];
- app_namespace_t *app_ns;
- u8 segment_name[128];
- application_t *server;
- stream_session_t *s;
- 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));
-
- options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_BUILTIN_APP;
- 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,
- .segment_name = segment_name,
- };
-
- vnet_bind_args_t bind_args = {
- .sep = server_sep,
- .app_index = 0,
- };
-
- vnet_connect_args_t connect_args = {
- .sep = client_sep,
- .app_index = 0,
- .api_context = 0,
- };
-
- vnet_unbind_args_t unbind_args = {
- .handle = bind_args.handle,
- .app_index = 0,
- };
-
- vnet_app_detach_args_t detach_args = {
- .app_index = 0,
- };
-
- ip4_address_t intf_addr = {
- .as_u32 = clib_host_to_net_u32 (0x06000105),
- };
-
- intf_sep.ip.ip4 = intf_addr;
- intf_sep.is_ip4 = 1;
- intf_sep.port = dummy_port;
-
- /*
- * Insert namespace and lookup
- */
-
- vnet_app_namespace_add_del_args_t ns_args = {
- .ns_id = ns_id,
- .secret = dummy_secret,
- .sw_if_index = APP_NAMESPACE_INVALID_INDEX,
- .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));
-
- app_ns = app_namespace_get_from_id (ns_id);
- SESSION_TEST ((app_ns != 0), "should find ns %v status", ns_id);
- SESSION_TEST ((app_ns->ns_secret == dummy_secret), "secret should be %d",
- dummy_secret);
- SESSION_TEST ((app_ns->sw_if_index == APP_NAMESPACE_INVALID_INDEX),
- "sw_if_index should be invalid");
-
- /*
- * Try application attach with wrong secret
- */
-
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret - 1;
- attach_args.namespace_id = ns_id;
- attach_args.api_client_index = dummy_server_api_index;
-
- error = vnet_application_attach (&attach_args);
- SESSION_TEST ((error != 0), "app attachment should fail");
- code = clib_error_get_code (error);
- SESSION_TEST ((code == VNET_API_ERROR_APP_WRONG_NS_SECRET),
- "code should be wrong ns secret: %d", code);
-
- /*
- * Attach server with global default scope
- */
- options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- options[APP_OPTIONS_NAMESPACE_SECRET] = 0;
- attach_args.namespace_id = 0;
- attach_args.api_client_index = dummy_server_api_index;
- 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);
- SESSION_TEST ((server->ns_index == 0),
- "server should be in the default ns");
-
- bind_args.app_index = server_index;
- error = vnet_bind (&bind_args);
- SESSION_TEST ((error == 0), "server bind should work");
-
- 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");
- 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");
-
- unbind_args.app_index = server_index;
- unbind_args.handle = bind_args.handle;
- error = vnet_unbind (&unbind_args);
- SESSION_TEST ((error == 0), "unbind should work");
-
- s = session_lookup_listener (server_st_index, &server_sep);
- SESSION_TEST ((s == 0), "listener should not exist in global table");
-
- detach_args.app_index = server_index;
- vnet_application_detach (&detach_args);
-
- /*
- * Attach server with local and global scope
- */
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret;
- attach_args.namespace_id = ns_id;
- attach_args.api_client_index = dummy_server_api_index;
- 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);
- SESSION_TEST ((server->ns_index == app_namespace_index (app_ns)),
- "server should be in the right ns");
-
- bind_args.app_index = server_index;
- error = vnet_bind (&bind_args);
- SESSION_TEST ((error == 0), "bind should work");
- 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");
- server_local_st_index = application_local_session_table (server);
- local_listener =
- session_lookup_local_session_endpoint (server_local_st_index,
- &server_sep);
- SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
- "listener should exist in local table");
-
- /*
- * Try client connect with 1) local scope 2) global scope
- */
- options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- attach_args.api_client_index = dummy_client_api_index;
- error = vnet_application_attach (&attach_args);
- SESSION_TEST ((error == 0), "client attachment should work");
- client_index = attach_args.app_index;
- connect_args.api_context = dummy_api_context;
- connect_args.app_index = client_index;
- error = vnet_connect (&connect_args);
- SESSION_TEST ((error != 0), "client connect should return error code");
- code = clib_error_get_code (error);
- SESSION_TEST ((code == VNET_API_ERROR_INVALID_VALUE),
- "error code should be invalid value (zero ip)");
- connect_args.sep.ip.ip4.as_u8[0] = 127;
- error = vnet_connect (&connect_args);
- SESSION_TEST ((error != 0), "client connect should return error code");
- code = clib_error_get_code (error);
- SESSION_TEST ((code == VNET_API_ERROR_SESSION_REDIRECT),
- "error code should be redirect");
- detach_args.app_index = client_index;
- vnet_application_detach (&detach_args);
-
- options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- attach_args.api_client_index = dummy_client_api_index;
- error = vnet_application_attach (&attach_args);
- SESSION_TEST ((error == 0), "client attachment should work");
- error = vnet_connect (&connect_args);
- SESSION_TEST ((error != 0), "client connect should return error code");
- code = clib_error_get_code (error);
- SESSION_TEST ((code == VNET_API_ERROR_SESSION_CONNECT),
- "error code should be connect (nothing in local scope)");
- detach_args.app_index = client_index;
- vnet_application_detach (&detach_args);
-
- /*
- * Unbind and detach server and then re-attach with local scope only
- */
- unbind_args.handle = bind_args.handle;
- unbind_args.app_index = server_index;
- error = vnet_unbind (&unbind_args);
- SESSION_TEST ((error == 0), "unbind should work");
-
- 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_session_endpoint (server_local_st_index,
- &server_sep);
- SESSION_TEST ((s == 0), "listener should not exist in local table");
-
- detach_args.app_index = server_index;
- vnet_application_detach (&detach_args);
-
- options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- attach_args.api_client_index = dummy_server_api_index;
- error = vnet_application_attach (&attach_args);
- SESSION_TEST ((error == 0), "app attachment should work");
- server_index = attach_args.app_index;
- server = application_get (server_index);
- SESSION_TEST ((server->ns_index == app_namespace_index (app_ns)),
- "app should be in the right ns");
-
- bind_args.app_index = server_index;
- error = vnet_bind (&bind_args);
- SESSION_TEST ((error == 0), "bind should work");
-
- 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 not exist in global table");
- server_local_st_index = application_local_session_table (server);
- local_listener =
- session_lookup_local_session_endpoint (server_local_st_index,
- &server_sep);
- SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
- "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_session_endpoint (server_local_st_index,
- &server_sep);
- SESSION_TEST ((local_listener == SESSION_INVALID_INDEX),
- "listener should not exist in local table");
-
- /*
- * Client attach + connect in default ns with local scope
- */
- 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;
- attach_args.api_client_index = dummy_client_api_index;
- vnet_application_attach (&attach_args);
- error = vnet_connect (&connect_args);
- SESSION_TEST ((error != 0), "client connect should return error code");
- code = clib_error_get_code (error);
- SESSION_TEST ((code == VNET_API_ERROR_SESSION_CONNECT),
- "error code should be connect (not in same ns)");
- detach_args.app_index = client_index;
- vnet_application_detach (&detach_args);
-
- /*
- * Detach server
- */
- detach_args.app_index = server_index;
- vnet_application_detach (&detach_args);
-
- /*
- * Create loopback interface
- */
- if (vnet_create_loopback_interface (&sw_if_index, intf_mac, 0, 0))
+ vat_main_t *vam = &vat_main;
+ i32 retval = ntohl (mp->retval);
+ if (vam->async_mode)
{
- clib_warning ("couldn't create loopback. stopping the test!");
- return 0;
+ vam->async_errors += (retval < 0);
+ }
+ else
+ {
+ vam->retval = retval;
+ if (retval == 0)
+ errmsg ("app ns index %d\n", ntohl (mp->appns_index));
+ vam->result_ready = 1;
}
- 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);
-
- /*
- * Update namespace
- */
- ns_args.sw_if_index = sw_if_index;
- error = vnet_app_namespace_add_del (&ns_args);
- SESSION_TEST ((error == 0), "app ns insertion should succeed: %d",
- clib_error_get_code (error));
-
- /*
- * Attach server with local and global scope
- */
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
- options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
- options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret;
- attach_args.namespace_id = ns_id;
- attach_args.api_client_index = dummy_server_api_index;
- error = vnet_application_attach (&attach_args);
- SESSION_TEST ((error == 0), "server attachment should work");
- server_index = attach_args.app_index;
-
- bind_args.app_index = server_index;
- error = vnet_bind (&bind_args);
- server_st_index = application_session_table (server, FIB_PROTOCOL_IP4);
- s = session_lookup_listener (server_st_index, &server_sep);
- SESSION_TEST ((s == 0), "zero listener should not exist in global table");
-
- 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");
- server_local_st_index = application_local_session_table (server);
- local_listener =
- session_lookup_local_session_endpoint (server_local_st_index,
- &server_sep);
- SESSION_TEST ((local_listener != SESSION_INVALID_INDEX),
- "zero listener should exist in local table");
- detach_args.app_index = server_index;
- vnet_application_detach (&detach_args);
-
- /*
- * Cleanup
- */
- vec_free (ns_id);
- vnet_delete_loopback_interface (sw_if_index);
- return 0;
}
-static clib_error_t *
-session_test (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd_arg)
+static void
+vl_api_app_namespace_add_del_v2_reply_t_handler (
+ vl_api_app_namespace_add_del_v2_reply_t *vat)
{
- int res = 0;
+}
- vnet_session_enable_disable (vm, 1);
+static void
+vl_api_app_worker_add_del_reply_t_handler (
+ vl_api_app_worker_add_del_reply_t *vat)
+{
+}
+
+static int
+api_app_namespace_add_del_v2 (vat_main_t *vat)
+{
+ return -1;
+}
+
+static int
+api_session_enable_disable (vat_main_t *vat)
+{
+ return -1;
+}
+
+static int
+api_session_enable_disable_v2 (vat_main_t *vat)
+{
+ return -1;
+}
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+static int
+api_app_worker_add_del (vat_main_t *vat)
+{
+ return -1;
+}
+
+static int
+api_app_namespace_add_del (vat_main_t *vam)
+{
+ vl_api_app_namespace_add_del_t *mp;
+ unformat_input_t *i = vam->input;
+ u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
+ u32 sw_if_index, ip4_fib_id, ip6_fib_id;
+ u64 secret;
+ int ret;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "namespace"))
- {
- res = session_test_namespace (vm, input);
- }
+ if (unformat (i, "id %_%v%_", &ns_id))
+ ;
+ else if (unformat (i, "secret %lu", &secret))
+ secret_set = 1;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
+ ;
+ else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
+ ;
else
break;
}
+ if (!ns_id || !secret_set || !sw_if_index_set)
+ {
+ errmsg ("namespace id, secret and sw_if_index must be set");
+ return -99;
+ }
+ if (vec_len (ns_id) > 64)
+ {
+ errmsg ("namespace id too long");
+ return -99;
+ }
+ M (APP_NAMESPACE_ADD_DEL, mp);
- if (res)
- return clib_error_return (0, "Session unit test failed");
- return 0;
+ vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
+ mp->secret = clib_host_to_net_u64 (secret);
+ mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
+ mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
+ mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
+ vec_free (ns_id);
+ S (mp);
+ W (ret);
+ return ret;
}
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (tcp_test_command, static) =
+static void
+vl_api_app_namespace_add_del_v4_reply_t_handler (
+ vl_api_app_namespace_add_del_v4_reply_t *mp)
{
- .path = "test session",
- .short_help = "internal session unit tests",
- .function = session_test,
-};
-/* *INDENT-ON* */
+}
+
+static int
+api_app_namespace_add_del_v4 (vat_main_t *vat)
+{
+ return -1;
+}
+
+static void
+vl_api_app_namespace_add_del_v3_reply_t_handler (
+ vl_api_app_namespace_add_del_v3_reply_t *mp)
+{
+}
+
+static int
+api_app_namespace_add_del_v3 (vat_main_t *vat)
+{
+ return -1;
+}
+
+static int
+api_session_sapi_enable_disable (vat_main_t *vat)
+{
+ return -1;
+}
+
+static int
+api_session_sdl_add_del (vat_main_t *vam)
+{
+ return -1;
+}
+
+static void
+vl_api_session_sdl_details_t_handler (vl_api_session_rules_details_t *mp)
+{
+}
+
+static int
+api_session_sdl_dump (vat_main_t *vam)
+{
+ return -1;
+}
+
+#include <vnet/session/session.api_test.c>
/*
- * fd.io coding-style-patch-verification: ON
- *
* Local Variables:
* eval: (c-set-style "gnu")
* End: