1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
6 #include <vlibapi/api.h>
7 #include <vlibmemory/api.h>
8 #include <vppinfra/error.h>
9 #include <vpp/api/types.h>
11 #include <vnet/ip/ip_types_api.h>
13 #define __plugin_msg_base session_test_main.msg_id_base
14 #include <vlibapi/vat_helper_macros.h>
16 #include <vlibmemory/vlib.api_enum.h>
17 #include <vlibmemory/vlib.api_types.h>
19 /* Declare message IDs */
20 #include <vnet/format_fns.h>
21 #include <vnet/session/session.api_enum.h>
22 #include <vnet/session/session.api_types.h>
24 #define vl_endianfun /* define message structures */
25 #include <vnet/session/session.api.h>
30 /* API message ID base */
34 } session_test_main_t;
36 static session_test_main_t session_test_main;
39 api_session_rule_add_del (vat_main_t *vam)
41 vl_api_session_rule_add_del_t *mp;
42 unformat_input_t *i = vam->input;
43 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
44 u32 appns_index = 0, scope = 0;
45 ip4_address_t lcl_ip4, rmt_ip4;
46 ip6_address_t lcl_ip6, rmt_ip6;
47 u8 is_ip4 = 1, conn_set = 0;
48 u8 is_add = 1, *tag = 0;
50 fib_prefix_t lcl, rmt;
52 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
54 if (unformat (i, "del"))
56 else if (unformat (i, "add"))
58 else if (unformat (i, "proto tcp"))
60 else if (unformat (i, "proto udp"))
62 else if (unformat (i, "appns %d", &appns_index))
64 else if (unformat (i, "scope %d", &scope))
66 else if (unformat (i, "tag %_%v%_", &tag))
68 else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip4_address,
69 &lcl_ip4, &lcl_plen, &lcl_port, unformat_ip4_address,
70 &rmt_ip4, &rmt_plen, &rmt_port))
75 else if (unformat (i, "%U/%d %d %U/%d %d", unformat_ip6_address,
76 &lcl_ip6, &lcl_plen, &lcl_port, unformat_ip6_address,
77 &rmt_ip6, &rmt_plen, &rmt_port))
82 else if (unformat (i, "action %d", &action))
87 if (proto == ~0 || !conn_set || action == ~0)
89 errmsg ("transport proto, connection and action must be set");
95 errmsg ("scope should be 0-3");
99 M (SESSION_RULE_ADD_DEL, mp);
101 clib_memset (&lcl, 0, sizeof (lcl));
102 clib_memset (&rmt, 0, sizeof (rmt));
105 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
106 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
107 lcl.fp_len = lcl_plen;
108 rmt.fp_len = rmt_plen;
112 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
113 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
114 lcl.fp_len = lcl_plen;
115 rmt.fp_len = rmt_plen;
118 ip_prefix_encode (&lcl, &mp->lcl);
119 ip_prefix_encode (&rmt, &mp->rmt);
120 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
121 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
122 mp->transport_proto =
123 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
124 mp->action_index = clib_host_to_net_u32 (action);
125 mp->appns_index = clib_host_to_net_u32 (appns_index);
130 clib_memcpy (mp->tag, tag, vec_len (tag));
140 vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t *mp)
145 vl_api_app_add_cert_key_pair_reply_t_handler (
146 vl_api_app_add_cert_key_pair_reply_t *mp)
151 api_app_attach (vat_main_t *vat)
157 api_application_detach (vat_main_t *vat)
163 api_app_del_cert_key_pair (vat_main_t *vat)
169 api_app_add_cert_key_pair (vat_main_t *vat)
175 api_session_rules_dump (vat_main_t *vam)
177 vl_api_session_rules_dump_t *mp;
178 vl_api_control_ping_t *mp_ping;
181 if (!vam->json_output)
183 print (vam->ofp, "%=20s", "Session Rules");
186 M (SESSION_RULES_DUMP, mp);
190 /* Use a control ping for synchronization */
191 PING (&session_test_main, mp_ping);
194 /* Wait for a reply... */
200 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t *mp)
202 vat_main_t *vam = &vat_main;
203 fib_prefix_t lcl, rmt;
205 ip_prefix_decode (&mp->lcl, &lcl);
206 ip_prefix_decode (&mp->rmt, &rmt);
208 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
211 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
212 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
213 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
214 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
215 &rmt.fp_addr.ip4, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
216 clib_net_to_host_u32 (mp->action_index), mp->tag);
221 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
222 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
223 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
224 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
225 &rmt.fp_addr.ip6, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
226 clib_net_to_host_u32 (mp->action_index), mp->tag);
231 vl_api_app_namespace_add_del_reply_t_handler (
232 vl_api_app_namespace_add_del_reply_t *mp)
234 vat_main_t *vam = &vat_main;
235 i32 retval = ntohl (mp->retval);
238 vam->async_errors += (retval < 0);
242 vam->retval = retval;
244 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
245 vam->result_ready = 1;
250 vl_api_app_namespace_add_del_v2_reply_t_handler (
251 vl_api_app_namespace_add_del_v2_reply_t *vat)
256 vl_api_app_worker_add_del_reply_t_handler (
257 vl_api_app_worker_add_del_reply_t *vat)
262 api_app_namespace_add_del_v2 (vat_main_t *vat)
268 api_session_enable_disable (vat_main_t *vat)
274 api_app_worker_add_del (vat_main_t *vat)
280 api_application_tls_key_add (vat_main_t *vat)
286 api_app_namespace_add_del (vat_main_t *vam)
288 vl_api_app_namespace_add_del_t *mp;
289 unformat_input_t *i = vam->input;
290 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
291 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
297 if (unformat (i, "id %_%v%_", &ns_id))
299 else if (unformat (i, "secret %lu", &secret))
301 else if (unformat (i, "sw_if_index %d", &sw_if_index))
303 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
305 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
310 if (!ns_id || !secret_set || !sw_if_index_set)
312 errmsg ("namespace id, secret and sw_if_index must be set");
315 if (vec_len (ns_id) > 64)
317 errmsg ("namespace id too long");
320 M (APP_NAMESPACE_ADD_DEL, mp);
322 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
323 mp->secret = clib_host_to_net_u64 (secret);
324 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
325 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
326 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
334 api_application_tls_cert_add (vat_main_t *vat)
340 vl_api_app_namespace_add_del_v3_reply_t_handler (
341 vl_api_app_namespace_add_del_v3_reply_t *mp)
346 api_app_namespace_add_del_v3 (vat_main_t *vat)
352 api_session_sapi_enable_disable (vat_main_t *vat)
357 #include <vnet/session/session.api_test.c>
361 * eval: (c-set-style "gnu")