Line data Source code
1 : /* 2 : * Copyright (c) 2023 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 <vat/vat.h> 16 : #include <vlibapi/api.h> 17 : #include <vlibmemory/api.h> 18 : #include <vppinfra/error.h> 19 : #include <vnet/api_errno.h> 20 : #include <stdbool.h> 21 : 22 : #define __plugin_msg_base tracenode_test_main.msg_id_base 23 : #include <vlibapi/vat_helper_macros.h> 24 : 25 : /* Declare message IDs */ 26 : #include <tracenode/tracenode.api_enum.h> 27 : #include <tracenode/tracenode.api_types.h> 28 : 29 : typedef struct 30 : { 31 : /* API message ID base */ 32 : u16 msg_id_base; 33 : vat_main_t *vat_main; 34 : } tracenode_test_main_t; 35 : 36 : tracenode_test_main_t tracenode_test_main; 37 : 38 : int 39 0 : api_tracenode_enable_disable (vat_main_t *vam) 40 : { 41 0 : unformat_input_t *i = vam->input; 42 : vl_api_tracenode_enable_disable_t *mp; 43 : u32 sw_if_index; 44 : bool is_pcap, enable; 45 : 46 0 : sw_if_index = ~0; 47 0 : is_pcap = false; 48 0 : enable = true; 49 : 50 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) 51 : { 52 0 : if (unformat (i, "disable")) 53 0 : enable = 0; 54 0 : else if (unformat (i, "pcap")) 55 0 : is_pcap = 1; 56 0 : else if (unformat (i, "%U", unformat_vnet_sw_interface, vnet_get_main (), 57 : &sw_if_index)) 58 : { 59 0 : if (sw_if_index == 0) 60 : { 61 0 : clib_warning ("Local interface not supported..."); 62 0 : return -99; 63 : } 64 : } 65 : 66 : else 67 : { 68 0 : clib_warning ("Unknown input: %U\n", format_unformat_error, i); 69 0 : return -99; 70 : } 71 : } 72 : 73 0 : M (TRACENODE_ENABLE_DISABLE, mp); 74 0 : mp->sw_if_index = htonl (sw_if_index); 75 0 : mp->is_pcap = is_pcap; 76 0 : mp->enable = enable; 77 : 78 0 : int ret = 0; 79 0 : S (mp); 80 0 : W (ret); 81 : 82 0 : return ret; 83 : } 84 : 85 : #include <tracenode/tracenode.api_test.c> 86 : 87 : /* 88 : * fd.io coding-style-patch-verification: ON 89 : * 90 : * Local Variables: 91 : * eval: (c-set-style "gnu") 92 : * End: 93 : */