Line data Source code
1 : /* 2 : *------------------------------------------------------------------ 3 : * lacp_api.c - lacp api 4 : * 5 : * Copyright (c) 2017 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 <vlib/vlib.h> 21 : #include <vnet/ethernet/ethernet.h> 22 : #include <vlib/unix/unix.h> 23 : #include <lacp/node.h> 24 : 25 : #include <vlibapi/api.h> 26 : #include <vlibmemory/api.h> 27 : 28 : 29 : /* define message IDs */ 30 : #include <vnet/format_fns.h> 31 : #include <lacp/lacp.api_enum.h> 32 : #include <lacp/lacp.api_types.h> 33 : 34 : #define FINISH \ 35 : vec_add1 (s, 0); \ 36 : vlib_cli_output (handle, (char *) s); \ 37 : vec_free (s); \ 38 : return handle; 39 : 40 : #define REPLY_MSG_ID_BASE lm->msg_id_base 41 : #include <vlibapi/api_helper_macros.h> 42 : 43 : static void 44 16 : lacp_send_sw_interface_details (vl_api_registration_t * reg, 45 : lacp_interface_details_t * lacp_if, 46 : u32 context) 47 : { 48 16 : lacp_main_t *lm = &lacp_main; 49 : vl_api_sw_interface_lacp_details_t *mp; 50 : 51 16 : mp = vl_msg_api_alloc (sizeof (*mp)); 52 16 : clib_memset (mp, 0, sizeof (*mp)); 53 16 : mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_LACP_DETAILS + lm->msg_id_base); 54 16 : mp->sw_if_index = htonl (lacp_if->sw_if_index); 55 : 56 : /* These fields in network order already */ 57 16 : mp->actor_system_priority = lacp_if->actor_system_priority; 58 16 : mp->actor_key = lacp_if->actor_key; 59 16 : mp->actor_port_priority = lacp_if->actor_port_priority; 60 16 : mp->actor_port_number = lacp_if->actor_port_number; 61 16 : mp->actor_state = lacp_if->actor_state; 62 16 : clib_memcpy (mp->actor_system, lacp_if->actor_system, 6); 63 16 : mp->partner_system_priority = lacp_if->partner_system_priority; 64 16 : mp->partner_key = lacp_if->partner_key; 65 16 : mp->partner_port_priority = lacp_if->partner_port_priority; 66 16 : mp->partner_port_number = lacp_if->partner_port_number; 67 16 : mp->partner_state = lacp_if->partner_state; 68 : 69 16 : clib_memcpy (mp->partner_system, lacp_if->partner_system, 6); 70 16 : clib_memcpy (mp->interface_name, lacp_if->interface_name, 71 : MIN (ARRAY_LEN (mp->interface_name) - 1, 72 : strlen ((const char *) lacp_if->interface_name))); 73 16 : clib_memcpy (mp->bond_interface_name, lacp_if->bond_interface_name, 74 : MIN (ARRAY_LEN (mp->bond_interface_name) - 1, 75 : strlen ((const char *) lacp_if->bond_interface_name))); 76 16 : mp->rx_state = htonl (lacp_if->rx_state); 77 16 : mp->tx_state = htonl (lacp_if->tx_state); 78 16 : mp->mux_state = htonl (lacp_if->mux_state); 79 16 : mp->ptx_state = htonl (lacp_if->ptx_state); 80 : 81 16 : mp->context = context; 82 16 : vl_api_send_msg (reg, (u8 *) mp); 83 16 : } 84 : 85 : /** 86 : * @brief Message handler for lacp_dump API. 87 : * @param mp vl_api_lacp_dump_t * mp the api message 88 : */ 89 : void 90 4 : vl_api_sw_interface_lacp_dump_t_handler (vl_api_sw_interface_lacp_dump_t * mp) 91 : { 92 : int rv; 93 : vl_api_registration_t *reg; 94 4 : lacp_interface_details_t *lacpifs = NULL; 95 4 : lacp_interface_details_t *lacp_if = NULL; 96 : 97 4 : reg = vl_api_client_index_to_registration (mp->client_index); 98 4 : if (!reg) 99 0 : return; 100 : 101 4 : rv = lacp_dump_ifs (&lacpifs); 102 4 : if (rv) 103 0 : return; 104 : 105 20 : vec_foreach (lacp_if, lacpifs) 106 : { 107 16 : lacp_send_sw_interface_details (reg, lacp_if, mp->context); 108 : } 109 : 110 4 : vec_free (lacpifs); 111 : } 112 : 113 : /* Set up the API message handling tables */ 114 : #include <lacp/lacp.api.c> 115 : clib_error_t * 116 575 : lacp_plugin_api_hookup (vlib_main_t * vm) 117 : { 118 575 : lacp_main_t *lm = &lacp_main; 119 575 : api_main_t *am = vlibapi_get_main (); 120 : 121 : /* Ask for a correctly-sized block of API message decode slots */ 122 575 : lm->msg_id_base = setup_message_id_table (); 123 : 124 : /* Mark these APIs as mp safe */ 125 575 : vl_api_set_msg_thread_safe ( 126 575 : am, lm->msg_id_base + VL_API_SW_INTERFACE_LACP_DUMP, 1); 127 : 128 575 : return 0; 129 : } 130 : 131 : /* 132 : * fd.io coding-style-patch-verification: ON 133 : * 134 : * Local Variables: 135 : * eval: (c-set-style "gnu") 136 : * End: 137 : */