LCOV - code coverage report
Current view: top level - plugins/ioam/export-vxlan-gpe - vxlan_gpe_ioam_export.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 13 62 21.0 %
Date: 2023-07-05 22:20:52 Functions: 5 8 62.5 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : /*
      16             :  *------------------------------------------------------------------
      17             :  * vxlan_gpe_ioam_export.c - ioam export API / debug CLI handling
      18             :  *------------------------------------------------------------------
      19             :  */
      20             : 
      21             : #include <vnet/vnet.h>
      22             : #include <vnet/plugin/plugin.h>
      23             : #include <ioam/export-common/ioam_export.h>
      24             : #include <vnet/vxlan-gpe/vxlan_gpe.h>
      25             : 
      26             : #include <vlibapi/api.h>
      27             : #include <vlibmemory/api.h>
      28             : #include <vnet/format_fns.h>
      29             : #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
      30             : 
      31             : /* define message IDs */
      32             : #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_enum.h>
      33             : #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_types.h>
      34             : 
      35             : #define REPLY_MSG_ID_BASE sm->msg_id_base
      36             : #include <vlibapi/api_helper_macros.h>
      37             : 
      38             : ioam_export_main_t vxlan_gpe_ioam_export_main;
      39             : extern vlib_node_registration_t vxlan_export_node;
      40             : 
      41             : extern void vxlan_gpe_set_next_override (uword next);
      42             : /* Action function shared between message handler and debug CLI */
      43             : int
      44           0 : vxlan_gpe_ioam_export_enable_disable (ioam_export_main_t * em,
      45             :                                       u8 is_disable,
      46             :                                       ip4_address_t * collector_address,
      47             :                                       ip4_address_t * src_address)
      48             : {
      49           0 :   vlib_main_t *vm = em->vlib_main;
      50           0 :   u32 node_index = vxlan_export_node.index;
      51           0 :   vlib_node_t *vxlan_gpe_decap_ioam_node = NULL;
      52             : 
      53           0 :   if (is_disable == 0)
      54             :     {
      55           0 :       if (em->my_hbh_slot == ~0)
      56             :         {
      57             :           /* Hook this export node to vxlan-gpe-decap-ioam-v4 */
      58             :           vxlan_gpe_decap_ioam_node =
      59           0 :             vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-decap-ioam-v4");
      60           0 :           if (!vxlan_gpe_decap_ioam_node)
      61             :             {
      62             :               /* node does not exist give up */
      63           0 :               return (-1);
      64             :             }
      65           0 :           em->my_hbh_slot =
      66           0 :             vlib_node_add_next (vm, vxlan_gpe_decap_ioam_node->index,
      67             :                                 node_index);
      68             :         }
      69           0 :       if (1 == ioam_export_header_create (em, collector_address, src_address))
      70             :         {
      71           0 :           ioam_export_thread_buffer_init (em, vm);
      72           0 :           vxlan_gpe_set_next_override (em->my_hbh_slot);
      73             :           /* Turn on the export buffer check process */
      74           0 :           vlib_process_signal_event (vm, em->export_process_node_index, 1, 0);
      75             : 
      76             :         }
      77             :       else
      78             :         {
      79           0 :           return (-2);
      80             :         }
      81             :     }
      82             :   else
      83             :     {
      84           0 :       vxlan_gpe_set_next_override (VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP);
      85           0 :       ioam_export_header_cleanup (em, collector_address, src_address);
      86           0 :       ioam_export_thread_buffer_free (em);
      87             :       /* Turn off the export buffer check process */
      88           0 :       vlib_process_signal_event (vm, em->export_process_node_index, 2, 0);
      89             : 
      90             :     }
      91             : 
      92           0 :   return 0;
      93             : }
      94             : 
      95             : /* API message handler */
      96           0 : static void vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler
      97             :   (vl_api_vxlan_gpe_ioam_export_enable_disable_t * mp)
      98             : {
      99             :   vl_api_vxlan_gpe_ioam_export_enable_disable_reply_t *rmp;
     100           0 :   ioam_export_main_t *sm = &vxlan_gpe_ioam_export_main;
     101             :   int rv;
     102             : 
     103           0 :   rv = vxlan_gpe_ioam_export_enable_disable (sm, (int) (mp->is_disable),
     104             :                                              (ip4_address_t *)
     105           0 :                                              mp->collector_address,
     106             :                                              (ip4_address_t *)
     107           0 :                                              mp->src_address);
     108             : 
     109           0 :   REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY);
     110             : }                               /* API message handler */
     111             : 
     112             : static clib_error_t *
     113           0 : set_vxlan_gpe_ioam_export_ipfix_command_fn (vlib_main_t * vm,
     114             :                                             unformat_input_t * input,
     115             :                                             vlib_cli_command_t * cmd)
     116             : {
     117           0 :   ioam_export_main_t *em = &vxlan_gpe_ioam_export_main;
     118             :   ip4_address_t collector, src;
     119           0 :   u8 is_disable = 0;
     120             : 
     121           0 :   collector.as_u32 = 0;
     122           0 :   src.as_u32 = 0;
     123             : 
     124           0 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     125             :     {
     126           0 :       if (unformat (input, "collector %U", unformat_ip4_address, &collector))
     127             :         ;
     128           0 :       else if (unformat (input, "src %U", unformat_ip4_address, &src))
     129             :         ;
     130           0 :       else if (unformat (input, "disable"))
     131           0 :         is_disable = 1;
     132             :       else
     133           0 :         break;
     134             :     }
     135             : 
     136           0 :   if (collector.as_u32 == 0)
     137           0 :     return clib_error_return (0, "collector address required");
     138             : 
     139           0 :   if (src.as_u32 == 0)
     140           0 :     return clib_error_return (0, "src address required");
     141             : 
     142           0 :   em->ipfix_collector.as_u32 = collector.as_u32;
     143           0 :   em->src_address.as_u32 = src.as_u32;
     144             : 
     145           0 :   vlib_cli_output (vm, "Collector %U, src address %U",
     146             :                    format_ip4_address, &em->ipfix_collector,
     147             :                    format_ip4_address, &em->src_address);
     148             : 
     149             :   /* Turn on the export timer process */
     150             :   // vlib_process_signal_event (vm, flow_report_process_node.index,
     151             :   //1, 0);
     152           0 :   if (0 !=
     153           0 :       vxlan_gpe_ioam_export_enable_disable (em, is_disable, &collector, &src))
     154             :     {
     155           0 :       return clib_error_return (0, "Unable to set ioam vxlan-gpe export");
     156             :     }
     157             : 
     158           0 :   return 0;
     159             : }
     160             : 
     161             : /* *INDENT-OFF* */
     162      176567 : VLIB_CLI_COMMAND (set_vxlan_gpe_ioam_ipfix_command, static) =
     163             : {
     164             : .path = "set vxlan-gpe-ioam export ipfix",
     165             : .short_help = "set vxlan-gpe-ioam export ipfix collector <ip4-address> src <ip4-address>",
     166             : .function = set_vxlan_gpe_ioam_export_ipfix_command_fn,
     167             : };
     168             : /* *INDENT-ON* */
     169             : 
     170             : #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api.c>
     171             : static clib_error_t *
     172         559 : vxlan_gpe_ioam_export_init (vlib_main_t * vm)
     173             : {
     174         559 :   ioam_export_main_t *em = &vxlan_gpe_ioam_export_main;
     175             : 
     176         559 :   em->set_id = IPFIX_VXLAN_IOAM_EXPORT_ID;
     177             : 
     178             :   /* Ask for a correctly-sized block of API message decode slots */
     179         559 :   em->msg_id_base = setup_message_id_table ();
     180         559 :   em->unix_time_0 = (u32) time (0);  /* Store starting time */
     181         559 :   em->vlib_time_0 = vlib_time_now (vm);
     182             : 
     183         559 :   em->my_hbh_slot = ~0;
     184         559 :   em->vlib_main = vm;
     185         559 :   em->vnet_main = vnet_get_main ();
     186         559 :   ioam_export_reset_next_node (em);
     187             : 
     188         559 :   return 0;
     189             : }
     190             : 
     191        4479 : VLIB_INIT_FUNCTION (vxlan_gpe_ioam_export_init);
     192             : 
     193             : 
     194             : /*
     195             :  * fd.io coding-style-patch-verification: ON
     196             :  *
     197             :  * Local Variables:
     198             :  * eval: (c-set-style "gnu")
     199             :  * End:
     200             :  */

Generated by: LCOV version 1.14