LCOV - code coverage report
Current view: top level - vnet/session - session_test.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 0 156 0.0 %
Date: 2023-07-05 22:20:52 Functions: 0 21 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: Apache-2.0
       2             :  * Copyright(c) 2021 Cisco Systems, Inc.
       3             :  */
       4             : 
       5             : #include <vat/vat.h>
       6             : #include <vlibapi/api.h>
       7             : #include <vlibmemory/api.h>
       8             : #include <vppinfra/error.h>
       9             : #include <vpp/api/types.h>
      10             : 
      11             : #include <vnet/ip/ip_types_api.h>
      12             : 
      13             : #define __plugin_msg_base session_test_main.msg_id_base
      14             : #include <vlibapi/vat_helper_macros.h>
      15             : 
      16             : #include <vlibmemory/vlib.api_enum.h>
      17             : #include <vlibmemory/vlib.api_types.h>
      18             : 
      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>
      23             : 
      24             : #define vl_endianfun /* define message structures */
      25             : #include <vnet/session/session.api.h>
      26             : #undef vl_endianfun
      27             : 
      28             : typedef struct
      29             : {
      30             :   /* API message ID base */
      31             :   u16 msg_id_base;
      32             :   u32 ping_id;
      33             :   vat_main_t *vat_main;
      34             : } session_test_main_t;
      35             : 
      36             : static session_test_main_t session_test_main;
      37             : 
      38             : static int
      39           0 : api_session_rule_add_del (vat_main_t *vam)
      40             : {
      41             :   vl_api_session_rule_add_del_t *mp;
      42           0 :   unformat_input_t *i = vam->input;
      43           0 :   u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
      44           0 :   u32 appns_index = 0, scope = 0;
      45             :   ip4_address_t lcl_ip4, rmt_ip4;
      46             :   ip6_address_t lcl_ip6, rmt_ip6;
      47           0 :   u8 is_ip4 = 1, conn_set = 0;
      48           0 :   u8 is_add = 1, *tag = 0;
      49             :   int ret;
      50             :   fib_prefix_t lcl, rmt;
      51             : 
      52           0 :   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
      53             :     {
      54           0 :       if (unformat (i, "del"))
      55           0 :         is_add = 0;
      56           0 :       else if (unformat (i, "add"))
      57             :         ;
      58           0 :       else if (unformat (i, "proto tcp"))
      59           0 :         proto = 0;
      60           0 :       else if (unformat (i, "proto udp"))
      61           0 :         proto = 1;
      62           0 :       else if (unformat (i, "appns %d", &appns_index))
      63             :         ;
      64           0 :       else if (unformat (i, "scope %d", &scope))
      65             :         ;
      66           0 :       else if (unformat (i, "tag %_%v%_", &tag))
      67             :         ;
      68           0 :       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))
      71             :         {
      72           0 :           is_ip4 = 1;
      73           0 :           conn_set = 1;
      74             :         }
      75           0 :       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))
      78             :         {
      79           0 :           is_ip4 = 0;
      80           0 :           conn_set = 1;
      81             :         }
      82           0 :       else if (unformat (i, "action %d", &action))
      83             :         ;
      84             :       else
      85           0 :         break;
      86             :     }
      87           0 :   if (proto == ~0 || !conn_set || action == ~0)
      88             :     {
      89           0 :       errmsg ("transport proto, connection and action must be set");
      90           0 :       return -99;
      91             :     }
      92             : 
      93           0 :   if (scope > 3)
      94             :     {
      95           0 :       errmsg ("scope should be 0-3");
      96           0 :       return -99;
      97             :     }
      98             : 
      99           0 :   M (SESSION_RULE_ADD_DEL, mp);
     100             : 
     101           0 :   clib_memset (&lcl, 0, sizeof (lcl));
     102           0 :   clib_memset (&rmt, 0, sizeof (rmt));
     103           0 :   if (is_ip4)
     104             :     {
     105           0 :       ip_set (&lcl.fp_addr, &lcl_ip4, 1);
     106           0 :       ip_set (&rmt.fp_addr, &rmt_ip4, 1);
     107           0 :       lcl.fp_len = lcl_plen;
     108           0 :       rmt.fp_len = rmt_plen;
     109             :     }
     110             :   else
     111             :     {
     112           0 :       ip_set (&lcl.fp_addr, &lcl_ip6, 0);
     113           0 :       ip_set (&rmt.fp_addr, &rmt_ip6, 0);
     114           0 :       lcl.fp_len = lcl_plen;
     115           0 :       rmt.fp_len = rmt_plen;
     116             :     }
     117             : 
     118           0 :   ip_prefix_encode (&lcl, &mp->lcl);
     119           0 :   ip_prefix_encode (&rmt, &mp->rmt);
     120           0 :   mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
     121           0 :   mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
     122           0 :   mp->transport_proto =
     123           0 :     proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
     124           0 :   mp->action_index = clib_host_to_net_u32 (action);
     125           0 :   mp->appns_index = clib_host_to_net_u32 (appns_index);
     126           0 :   mp->scope = scope;
     127           0 :   mp->is_add = is_add;
     128           0 :   if (tag)
     129             :     {
     130           0 :       clib_memcpy (mp->tag, tag, vec_len (tag));
     131           0 :       vec_free (tag);
     132             :     }
     133             : 
     134           0 :   S (mp);
     135           0 :   W (ret);
     136           0 :   return ret;
     137             : }
     138             : 
     139             : static void
     140           0 : vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t *mp)
     141             : {
     142           0 : }
     143             : 
     144             : static void
     145           0 : vl_api_app_add_cert_key_pair_reply_t_handler (
     146             :   vl_api_app_add_cert_key_pair_reply_t *mp)
     147             : {
     148           0 : }
     149             : 
     150             : static int
     151           0 : api_app_attach (vat_main_t *vat)
     152             : {
     153           0 :   return -1;
     154             : }
     155             : 
     156             : static int
     157           0 : api_application_detach (vat_main_t *vat)
     158             : {
     159           0 :   return -1;
     160             : }
     161             : 
     162             : static int
     163           0 : api_app_del_cert_key_pair (vat_main_t *vat)
     164             : {
     165           0 :   return -1;
     166             : }
     167             : 
     168             : static int
     169           0 : api_app_add_cert_key_pair (vat_main_t *vat)
     170             : {
     171           0 :   return -1;
     172             : }
     173             : 
     174             : static int
     175           0 : api_session_rules_dump (vat_main_t *vam)
     176             : {
     177             :   vl_api_session_rules_dump_t *mp;
     178             :   vl_api_control_ping_t *mp_ping;
     179             :   int ret;
     180             : 
     181           0 :   if (!vam->json_output)
     182             :     {
     183           0 :       print (vam->ofp, "%=20s", "Session Rules");
     184             :     }
     185             : 
     186           0 :   M (SESSION_RULES_DUMP, mp);
     187             :   /* send it... */
     188           0 :   S (mp);
     189             : 
     190             :   /* Use a control ping for synchronization */
     191           0 :   PING (&session_test_main, mp_ping);
     192           0 :   S (mp_ping);
     193             : 
     194             :   /* Wait for a reply... */
     195           0 :   W (ret);
     196           0 :   return ret;
     197             : }
     198             : 
     199             : static void
     200           0 : vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t *mp)
     201             : {
     202           0 :   vat_main_t *vam = &vat_main;
     203             :   fib_prefix_t lcl, rmt;
     204             : 
     205           0 :   ip_prefix_decode (&mp->lcl, &lcl);
     206           0 :   ip_prefix_decode (&mp->rmt, &rmt);
     207             : 
     208           0 :   if (lcl.fp_proto == FIB_PROTOCOL_IP4)
     209             :     {
     210           0 :       print (vam->ofp,
     211             :              "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
     212           0 :              clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
     213           0 :              mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
     214           0 :              clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
     215           0 :              &rmt.fp_addr.ip4, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
     216           0 :              clib_net_to_host_u32 (mp->action_index), mp->tag);
     217             :     }
     218             :   else
     219             :     {
     220           0 :       print (vam->ofp,
     221             :              "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
     222           0 :              clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
     223           0 :              mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
     224           0 :              clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
     225           0 :              &rmt.fp_addr.ip6, rmt.fp_len, clib_net_to_host_u16 (mp->rmt_port),
     226           0 :              clib_net_to_host_u32 (mp->action_index), mp->tag);
     227             :     }
     228           0 : }
     229             : 
     230             : static void
     231           0 : vl_api_app_namespace_add_del_reply_t_handler (
     232             :   vl_api_app_namespace_add_del_reply_t *mp)
     233             : {
     234           0 :   vat_main_t *vam = &vat_main;
     235           0 :   i32 retval = ntohl (mp->retval);
     236           0 :   if (vam->async_mode)
     237             :     {
     238           0 :       vam->async_errors += (retval < 0);
     239             :     }
     240             :   else
     241             :     {
     242           0 :       vam->retval = retval;
     243           0 :       if (retval == 0)
     244           0 :         errmsg ("app ns index %d\n", ntohl (mp->appns_index));
     245           0 :       vam->result_ready = 1;
     246             :     }
     247           0 : }
     248             : 
     249             : static void
     250           0 : vl_api_app_namespace_add_del_v2_reply_t_handler (
     251             :   vl_api_app_namespace_add_del_v2_reply_t *vat)
     252             : {
     253           0 : }
     254             : 
     255             : static void
     256           0 : vl_api_app_worker_add_del_reply_t_handler (
     257             :   vl_api_app_worker_add_del_reply_t *vat)
     258             : {
     259           0 : }
     260             : 
     261             : static int
     262           0 : api_app_namespace_add_del_v2 (vat_main_t *vat)
     263             : {
     264           0 :   return -1;
     265             : }
     266             : 
     267             : static int
     268           0 : api_session_enable_disable (vat_main_t *vat)
     269             : {
     270           0 :   return -1;
     271             : }
     272             : 
     273             : static int
     274           0 : api_app_worker_add_del (vat_main_t *vat)
     275             : {
     276           0 :   return -1;
     277             : }
     278             : 
     279             : static int
     280           0 : api_app_namespace_add_del (vat_main_t *vam)
     281             : {
     282             :   vl_api_app_namespace_add_del_t *mp;
     283           0 :   unformat_input_t *i = vam->input;
     284           0 :   u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
     285             :   u32 sw_if_index, ip4_fib_id, ip6_fib_id;
     286             :   u64 secret;
     287             :   int ret;
     288             : 
     289           0 :   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     290             :     {
     291           0 :       if (unformat (i, "id %_%v%_", &ns_id))
     292             :         ;
     293           0 :       else if (unformat (i, "secret %lu", &secret))
     294           0 :         secret_set = 1;
     295           0 :       else if (unformat (i, "sw_if_index %d", &sw_if_index))
     296           0 :         sw_if_index_set = 1;
     297           0 :       else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
     298             :         ;
     299           0 :       else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
     300             :         ;
     301             :       else
     302           0 :         break;
     303             :     }
     304           0 :   if (!ns_id || !secret_set || !sw_if_index_set)
     305             :     {
     306           0 :       errmsg ("namespace id, secret and sw_if_index must be set");
     307           0 :       return -99;
     308             :     }
     309           0 :   if (vec_len (ns_id) > 64)
     310             :     {
     311           0 :       errmsg ("namespace id too long");
     312           0 :       return -99;
     313             :     }
     314           0 :   M (APP_NAMESPACE_ADD_DEL, mp);
     315             : 
     316           0 :   vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
     317           0 :   mp->secret = clib_host_to_net_u64 (secret);
     318           0 :   mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
     319           0 :   mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
     320           0 :   mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
     321           0 :   vec_free (ns_id);
     322           0 :   S (mp);
     323           0 :   W (ret);
     324           0 :   return ret;
     325             : }
     326             : 
     327             : static void
     328           0 : vl_api_app_namespace_add_del_v4_reply_t_handler (
     329             :   vl_api_app_namespace_add_del_v4_reply_t *mp)
     330             : {
     331           0 : }
     332             : 
     333             : static int
     334           0 : api_app_namespace_add_del_v4 (vat_main_t *vat)
     335             : {
     336           0 :   return -1;
     337             : }
     338             : 
     339             : static void
     340           0 : vl_api_app_namespace_add_del_v3_reply_t_handler (
     341             :   vl_api_app_namespace_add_del_v3_reply_t *mp)
     342             : {
     343           0 : }
     344             : 
     345             : static int
     346           0 : api_app_namespace_add_del_v3 (vat_main_t *vat)
     347             : {
     348           0 :   return -1;
     349             : }
     350             : 
     351             : static int
     352           0 : api_session_sapi_enable_disable (vat_main_t *vat)
     353             : {
     354           0 :   return -1;
     355             : }
     356             : 
     357             : #include <vnet/session/session.api_test.c>
     358             : 
     359             : /*
     360             :  * Local Variables:
     361             :  * eval: (c-set-style "gnu")
     362             :  * End:
     363             :  */

Generated by: LCOV version 1.14