LCOV - code coverage report
Current view: top level - plugins/unittest - interface_test.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 14 16 87.5 %
Date: 2023-07-05 22:20:52 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 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             : #include <vnet/vnet.h>
      17             : 
      18             : static clib_error_t *
      19           6 : test_interface_command_fn (vlib_main_t * vm,
      20             :                            unformat_input_t * input, vlib_cli_command_t * cmd)
      21             : {
      22             :   vnet_hw_interface_flags_t flags;
      23             :   vnet_main_t *vnm;
      24             :   u32 sw_if_index;
      25             : 
      26           6 :   flags = VNET_HW_INTERFACE_FLAG_NONE;
      27           6 :   sw_if_index = ~0;
      28           6 :   vnm = vnet_get_main ();
      29             : 
      30          18 :   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
      31             :     {
      32          12 :       if (unformat
      33             :           (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
      34             :         ;
      35           6 :       else if (unformat (input, "up"))
      36           3 :         flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
      37           3 :       else if (unformat (input, "down"))
      38             :         ;
      39             :       else
      40           0 :         break;
      41             :     }
      42             : 
      43           6 :   if (~0 != sw_if_index)
      44             :     {
      45             :       vnet_sw_interface_t *sw;
      46             : 
      47           6 :       sw = vnet_get_sw_interface (vnm, sw_if_index);
      48             : 
      49           6 :       vnet_hw_interface_set_flags (vnm, sw->hw_if_index, flags);
      50             :     }
      51             :   else
      52             :     {
      53           0 :       return clib_error_return (0, "unknown interface `%U'",
      54             :                                 format_unformat_error, input);
      55             :     }
      56             : 
      57           6 :   return (NULL);
      58             : }
      59             : 
      60             : /* *INDENT-OFF* */
      61       16239 : VLIB_CLI_COMMAND (test_interface_command, static) =
      62             : {
      63             :   .path = "test interface link-state",
      64             :   .short_help = "test interface link-state <interface> [up] [down]",
      65             :   .function = test_interface_command_fn,
      66             : };
      67             : /* *INDENT-ON* */
      68             : 
      69             : /*
      70             :  * fd.io coding-style-patch-verification: ON
      71             :  *
      72             :  * Local Variables:
      73             :  * eval: (c-set-style "gnu")
      74             :  * End:
      75             :  */

Generated by: LCOV version 1.14