LCOV - code coverage report
Current view: top level - plugins/linux-cp/test - lcp_unittest.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 24 28 85.7 %
Date: 2023-10-26 01:39:38 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2021 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             : #include <vlib/vlib.h>
      16             : 
      17             : #include <plugins/linux-cp/lcp_interface.h>
      18             : 
      19             : static u32 host_vif;
      20             : const static char *host_template = "tap%d";
      21             : 
      22             : static clib_error_t *
      23          10 : lcp_add_pair_command_fn (vlib_main_t *vm, unformat_input_t *input,
      24             :                          vlib_cli_command_t *cmd)
      25             : {
      26             :   u32 phy_sw_if_index, host_sw_if_index;
      27             :   u8 is_add, *host_name;
      28          10 :   vnet_main_t *vnm = vnet_get_main ();
      29             : 
      30          10 :   ++host_vif;
      31          10 :   host_name = format (NULL, host_template, host_vif);
      32          10 :   phy_sw_if_index = host_sw_if_index = ~0;
      33          10 :   is_add = 1;
      34          10 :   lcp_main.test_mode = 1;
      35             : 
      36          40 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
      37             :     {
      38          30 :       if (unformat (input, "add"))
      39           5 :         is_add = 1;
      40          25 :       else if (unformat (input, "del"))
      41           5 :         is_add = 0;
      42          20 :       else if (unformat (input, "phy %U", unformat_vnet_sw_interface, vnm,
      43             :                          &phy_sw_if_index))
      44             :         ;
      45          10 :       else if (unformat (input, "host %U", unformat_vnet_sw_interface, vnm,
      46             :                          &host_sw_if_index))
      47             :         ;
      48             :       else
      49           0 :         return clib_error_return (0, "unknown input:%U", format_unformat_error,
      50             :                                   input);
      51             :     }
      52             : 
      53          10 :   if (phy_sw_if_index == ~0)
      54           0 :     return clib_error_return (0, "ERROR; no phy:%U", format_unformat_error,
      55             :                               input);
      56             : 
      57          10 :   lip_host_type_t host_type =
      58          10 :     (vnet_sw_interface_is_p2p (vnm, phy_sw_if_index) ? LCP_ITF_HOST_TUN :
      59             :                                                        LCP_ITF_HOST_TAP);
      60             : 
      61             :   int rv;
      62             : 
      63          10 :   if (is_add)
      64             :     {
      65           5 :       if (host_sw_if_index == ~0)
      66           0 :         return clib_error_return (0, "ERROR no-host:%U", format_unformat_error,
      67             :                                   input);
      68             : 
      69           5 :       rv = lcp_itf_pair_add (host_sw_if_index, phy_sw_if_index, host_name,
      70             :                              host_vif, host_type, NULL);
      71             :     }
      72             :   else
      73           5 :     rv = lcp_itf_pair_del (phy_sw_if_index);
      74             : 
      75          10 :   if (rv)
      76           0 :     return clib_error_return (0, "ERROR rv:%d", rv);
      77             : 
      78          10 :   return (NULL);
      79             : }
      80             : 
      81         604 : VLIB_CLI_COMMAND (test_time_range_command, static) = {
      82             :   .path = "test lcp",
      83             :   .short_help = "lcp [add|del] phy <SW_IF_INDEX> host <SW_IF_INDEX>",
      84             :   .function = lcp_add_pair_command_fn,
      85             : };
      86             : 
      87             : #include <vnet/plugin/plugin.h>
      88             : #include <vpp/app/version.h>
      89             : VLIB_PLUGIN_REGISTER () = {
      90             :   .version = VPP_BUILD_VER,
      91             :   .description = "Linux Control Plane - Unit Test",
      92             :   .default_disabled = 1,
      93             : };
      94             : 
      95             : /*
      96             :  * fd.io coding-style-patch-verification: ON
      97             :  *
      98             :  * Local Variables:
      99             :  * eval: (c-set-style "gnu")
     100             :  * End:
     101             :  */

Generated by: LCOV version 1.14