Line data Source code
1 : /* 2 : *------------------------------------------------------------------ 3 : * pg_api.c - vnet pg api 4 : * 5 : * Copyright (c) 2016 Cisco and/or its affiliates. 6 : * Licensed under the Apache License, Version 2.0 (the "License"); 7 : * you may not use this file except in compliance with the License. 8 : * You may obtain a copy of the License at: 9 : * 10 : * http://www.apache.org/licenses/LICENSE-2.0 11 : * 12 : * Unless required by applicable law or agreed to in writing, software 13 : * distributed under the License is distributed on an "AS IS" BASIS, 14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 : * See the License for the specific language governing permissions and 16 : * limitations under the License. 17 : *------------------------------------------------------------------ 18 : */ 19 : 20 : #include <vnet/vnet.h> 21 : #include <vlibmemory/api.h> 22 : #include <vnet/pg/pg.h> 23 : 24 : #include <vnet/format_fns.h> 25 : #include <vnet/pg/pg.api_enum.h> 26 : #include <vnet/pg/pg.api_types.h> 27 : 28 : #define REPLY_MSG_ID_BASE pg->msg_id_base 29 : #include <vlibapi/api_helper_macros.h> 30 : 31 : static void 32 0 : vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp) 33 : { 34 : vl_api_pg_create_interface_reply_t *rmp; 35 0 : int rv = 0; 36 : 37 0 : pg_main_t *pg = &pg_main; 38 : u32 pg_if_id = 39 0 : pg_interface_add_or_get (pg, ntohl (mp->interface_id), mp->gso_enabled, 40 : ntohl (mp->gso_size), 0, PG_MODE_ETHERNET); 41 0 : pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id); 42 : 43 : /* *INDENT-OFF* */ 44 0 : REPLY_MACRO2(VL_API_PG_CREATE_INTERFACE_REPLY, 45 : ({ 46 : rmp->sw_if_index = ntohl(pi->sw_if_index); 47 : })); 48 : /* *INDENT-ON* */ 49 : } 50 : 51 : static void 52 2485 : vl_api_pg_create_interface_v2_t_handler (vl_api_pg_create_interface_v2_t *mp) 53 : { 54 : vl_api_pg_create_interface_v2_reply_t *rmp; 55 2485 : int rv = 0; 56 : 57 2485 : pg_main_t *pg = &pg_main; 58 : u32 pg_if_id = 59 2485 : pg_interface_add_or_get (pg, ntohl (mp->interface_id), mp->gso_enabled, 60 2485 : ntohl (mp->gso_size), 0, (u8) mp->mode); 61 2485 : pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id); 62 : 63 2485 : REPLY_MACRO2 (VL_API_PG_CREATE_INTERFACE_V2_REPLY, 64 : ({ rmp->sw_if_index = ntohl (pi->sw_if_index); })); 65 : } 66 : 67 : static void 68 2 : vl_api_pg_interface_enable_disable_coalesce_t_handler 69 : (vl_api_pg_interface_enable_disable_coalesce_t * mp) 70 : { 71 : vl_api_pg_interface_enable_disable_coalesce_reply_t *rmp; 72 2 : int rv = 0; 73 : 74 2 : VALIDATE_SW_IF_INDEX (mp); 75 : 76 2 : u32 sw_if_index = ntohl (mp->sw_if_index); 77 : 78 2 : pg_main_t *pg = &pg_main; 79 2 : vnet_main_t *vnm = vnet_get_main (); 80 : vnet_hw_interface_t *hw = 81 2 : vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index); 82 : 83 2 : if (hw) 84 : { 85 2 : pg_interface_t *pi = 86 2 : pool_elt_at_index (pg->interfaces, hw->dev_instance); 87 2 : if (pi->gso_enabled) 88 2 : pg_interface_enable_disable_coalesce (pi, mp->coalesce_enabled, 89 : hw->tx_node_index); 90 : else 91 0 : rv = VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE; 92 : } 93 : else 94 : { 95 0 : rv = VNET_API_ERROR_NO_MATCHING_INTERFACE; 96 : } 97 : 98 2 : BAD_SW_IF_INDEX_LABEL; 99 2 : REPLY_MACRO (VL_API_PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY); 100 : } 101 : 102 : static void 103 0 : vl_api_pg_capture_t_handler (vl_api_pg_capture_t * mp) 104 : { 105 0 : pg_main_t *pg = &pg_main; 106 : vl_api_pg_capture_reply_t *rmp; 107 0 : int rv = 0; 108 : 109 0 : vnet_main_t *vnm = vnet_get_main (); 110 0 : vnet_interface_main_t *im = &vnm->interface_main; 111 0 : vnet_hw_interface_t *hi = 0; 112 : 113 0 : u8 *intf_name = format (0, "pg%d", ntohl (mp->interface_id), 0); 114 0 : vec_terminate_c_string (intf_name); 115 0 : u32 hw_if_index = ~0; 116 0 : uword *p = hash_get_mem (im->hw_interface_by_name, intf_name); 117 0 : if (p) 118 0 : hw_if_index = *p; 119 0 : vec_free (intf_name); 120 : 121 0 : if (hw_if_index != ~0) 122 : { 123 0 : pg_capture_args_t _a, *a = &_a; 124 0 : char *pcap_file_name = 125 0 : vl_api_from_api_to_new_c_string (&mp->pcap_file_name); 126 : 127 0 : hi = vnet_get_sup_hw_interface (vnm, hw_if_index); 128 0 : a->hw_if_index = hw_if_index; 129 0 : a->dev_instance = hi->dev_instance; 130 0 : a->is_enabled = mp->is_enabled; 131 0 : a->pcap_file_name = pcap_file_name; 132 0 : a->count = ntohl (mp->count); 133 : 134 0 : clib_error_t *e = pg_capture (a); 135 0 : if (e) 136 : { 137 0 : clib_error_report (e); 138 0 : rv = VNET_API_ERROR_CANNOT_CREATE_PCAP_FILE; 139 : } 140 : 141 0 : vec_free (pcap_file_name); 142 : } 143 0 : REPLY_MACRO (VL_API_PG_CAPTURE_REPLY); 144 : } 145 : 146 : static void 147 0 : vl_api_pg_enable_disable_t_handler (vl_api_pg_enable_disable_t * mp) 148 : { 149 : vl_api_pg_enable_disable_reply_t *rmp; 150 0 : int rv = 0; 151 : 152 0 : pg_main_t *pg = &pg_main; 153 0 : u32 stream_index = ~0; 154 : 155 0 : int is_enable = mp->is_enabled != 0; 156 : 157 0 : if (vl_api_string_len (&mp->stream_name) > 0) 158 : { 159 0 : u8 *stream_name = vl_api_from_api_to_new_vec (mp, &mp->stream_name); 160 0 : uword *p = hash_get_mem (pg->stream_index_by_name, stream_name); 161 0 : if (p) 162 0 : stream_index = *p; 163 0 : vec_free (stream_name); 164 : } 165 : 166 0 : pg_enable_disable (stream_index, is_enable); 167 : 168 0 : REPLY_MACRO (VL_API_PG_ENABLE_DISABLE_REPLY); 169 : } 170 : 171 : #include <vnet/pg/pg.api.c> 172 : static clib_error_t * 173 575 : pg_api_hookup (vlib_main_t * vm) 174 : { 175 575 : pg_main_t *pg = &pg_main; 176 : /* 177 : * Set up the (msg_name, crc, message-id) table 178 : */ 179 575 : pg->msg_id_base = setup_message_id_table (); 180 : 181 575 : return 0; 182 : } 183 : 184 14975 : VLIB_API_INIT_FUNCTION (pg_api_hookup); 185 : 186 : /* 187 : * fd.io coding-style-patch-verification: ON 188 : * 189 : * Local Variables: 190 : * eval: (c-set-style "gnu") 191 : * End: 192 : */