FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
lacp_api.c
Go to the documentation of this file.
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 vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
35 
36 /* Macro to finish up custom dump fns */
37 #define FINISH \
38  vec_add1 (s, 0); \
39  vl_print (handle, (char *)s); \
40  vec_free (s); \
41  return handle;
42 
43 #define REPLY_MSG_ID_BASE lm->msg_id_base
45 
46 static void
48  lacp_interface_details_t * lacp_if,
49  u32 context)
50 {
51  lacp_main_t *lm = &lacp_main;
53 
54  mp = vl_msg_api_alloc (sizeof (*mp));
55  clib_memset (mp, 0, sizeof (*mp));
56  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_LACP_DETAILS + lm->msg_id_base);
57  mp->sw_if_index = htonl (lacp_if->sw_if_index);
58 
59  /* These fields in network order already */
61  mp->actor_key = lacp_if->actor_key;
63  mp->actor_port_number = lacp_if->actor_port_number;
64  mp->actor_state = lacp_if->actor_state;
65  clib_memcpy (mp->actor_system, lacp_if->actor_system, 6);
67  mp->partner_key = lacp_if->partner_key;
70  mp->partner_state = lacp_if->partner_state;
71 
72  clib_memcpy (mp->partner_system, lacp_if->partner_system, 6);
74  MIN (ARRAY_LEN (mp->interface_name) - 1,
75  strlen ((const char *) lacp_if->interface_name)));
78  strlen ((const char *) lacp_if->bond_interface_name)));
79  mp->rx_state = htonl (lacp_if->rx_state);
80  mp->tx_state = htonl (lacp_if->tx_state);
81  mp->mux_state = htonl (lacp_if->mux_state);
82  mp->ptx_state = htonl (lacp_if->ptx_state);
83 
84  mp->context = context;
85  vl_api_send_msg (reg, (u8 *) mp);
86 }
87 
88 /**
89  * @brief Message handler for lacp_dump API.
90  * @param mp vl_api_lacp_dump_t * mp the api message
91  */
92 void
94 {
95  int rv;
97  lacp_interface_details_t *lacpifs = NULL;
98  lacp_interface_details_t *lacp_if = NULL;
99 
101  if (!reg)
102  return;
103 
104  rv = lacp_dump_ifs (&lacpifs);
105  if (rv)
106  return;
107 
108  vec_foreach (lacp_if, lacpifs)
109  {
110  lacp_send_sw_interface_details (reg, lacp_if, mp->context);
111  }
112 
113  vec_free (lacpifs);
114 }
115 
116 /* Set up the API message handling tables */
117 #include <lacp/lacp.api.c>
118 clib_error_t *
120 {
121  lacp_main_t *lm = &lacp_main;
123 
124  /* Ask for a correctly-sized block of API message decode slots */
126 
127  /* Mark these APIs as mp safe */
128  am->is_mp_safe[lm->msg_id_base + VL_API_SW_INTERFACE_LACP_DUMP] = 1;
129 
130  return 0;
131 }
132 
133 /*
134  * fd.io coding-style-patch-verification: ON
135  *
136  * Local Variables:
137  * eval: (c-set-style "gnu")
138  * End:
139  */
vlib.h
vl_api_sw_interface_lacp_details_t::actor_key
u16 actor_key
Definition: lacp.api:66
lacp_plugin_api_hookup
clib_error_t * lacp_plugin_api_hookup(vlib_main_t *vm)
Definition: lacp_api.c:119
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
vl_api_sw_interface_lacp_details_t::actor_state
u8 actor_state
Definition: lacp.api:69
vl_api_sw_interface_lacp_details_t::interface_name
string interface_name[64]
Definition: lacp.api:58
lacp_interface_details_t::actor_port_priority
u16 actor_port_priority
Definition: node.h:106
vl_api_sw_interface_lacp_details_t::partner_port_number
u16 partner_port_number
Definition: lacp.api:74
lacp_interface_details_t::partner_system
u8 partner_system[6]
Definition: node.h:110
lacp_interface_details_t::interface_name
u8 interface_name[64]
Definition: node.h:97
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
lacp_dump_ifs
int lacp_dump_ifs(lacp_interface_details_t **out_lacpifs)
Definition: cli.c:21
vl_api_sw_interface_lacp_details_t::actor_port_priority
u16 actor_port_priority
Definition: lacp.api:67
lacp_interface_details_t::partner_state
u8 partner_state
Definition: node.h:114
lacp_interface_details_t::partner_port_number
u16 partner_port_number
Definition: node.h:113
vl_api_sw_interface_lacp_dump_t
Dump lacp interfaces request.
Definition: lacp.api:27
am
app_main_t * am
Definition: application.c:489
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
lacp_main
lacp_main_t lacp_main
Definition: lacp.c:26
lacp_interface_details_t::partner_port_priority
u16 partner_port_priority
Definition: node.h:112
lacp_interface_details_t::actor_state
u8 actor_state
Definition: node.h:108
lacp_interface_details_t::partner_system_priority
u16 partner_system_priority
Definition: node.h:109
vl_api_sw_interface_lacp_details_t::partner_system
vl_api_mac_address_t partner_system
Definition: lacp.api:71
ethernet.h
lacp_interface_details_t::sw_if_index
u32 sw_if_index
Definition: node.h:96
lacp_interface_details_t::actor_key
u16 actor_key
Definition: node.h:105
vl_api_sw_interface_lacp_details_t::context
u32 context
Definition: lacp.api:56
lacp_interface_details_t::rx_state
u32 rx_state
Definition: node.h:98
vl_api_sw_interface_lacp_details_t::mux_state
u32 mux_state
Definition: lacp.api:61
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
MIN
#define MIN(x, y)
Definition: node.h:31
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vl_api_sw_interface_lacp_details_t::bond_interface_name
string bond_interface_name[64]
Definition: lacp.api:63
vl_api_sw_interface_lacp_details_t::partner_port_priority
u16 partner_port_priority
Definition: lacp.api:73
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
lacp_interface_details_t::tx_state
u32 tx_state
Definition: node.h:99
vl_api_sw_interface_lacp_details_t::rx_state
u32 rx_state
Definition: lacp.api:59
vl_api_sw_interface_lacp_details_t::ptx_state
u32 ptx_state
Definition: lacp.api:62
lacp_interface_details_t::actor_port_number
u16 actor_port_number
Definition: node.h:107
vl_api_sw_interface_lacp_details_t::actor_port_number
u16 actor_port_number
Definition: lacp.api:68
lacp_send_sw_interface_details
static void lacp_send_sw_interface_details(vl_api_registration_t *reg, lacp_interface_details_t *lacp_if, u32 context)
Definition: lacp_api.c:47
vl_api_sw_interface_lacp_details_t::partner_system_priority
u16 partner_system_priority
Definition: lacp.api:70
lacp_interface_details_t::partner_key
u16 partner_key
Definition: node.h:111
vl_api_sw_interface_lacp_dump_t::context
u32 context
Definition: lacp.api:30
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
lacp_interface_details_t::bond_interface_name
u8 bond_interface_name[64]
Definition: node.h:102
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
lacp_main_t
Definition: node.h:117
lacp_main_t::msg_id_base
u16 msg_id_base
API message ID base.
Definition: node.h:120
format_fns.h
u32
unsigned int u32
Definition: types.h:88
vl_api_sw_interface_lacp_details_t::partner_key
u16 partner_key
Definition: lacp.api:72
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
lacp_interface_details_t
LACP interface details struct.
Definition: node.h:94
vl_api_sw_interface_lacp_details_t::tx_state
u32 tx_state
Definition: lacp.api:60
vl_api_sw_interface_lacp_details_t::partner_state
u8 partner_state
Definition: lacp.api:75
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
unix.h
lacp_interface_details_t::actor_system
u8 actor_system[6]
Definition: node.h:104
lacp_interface_details_t::actor_system_priority
u16 actor_system_priority
Definition: node.h:103
context
u32 context
Definition: ip.api:852
rv
int __clib_unused rv
Definition: application.c:491
vl_api_sw_interface_lacp_details_t
Reply for lacp dump request.
Definition: lacp.api:54
vl_api_sw_interface_lacp_details_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: lacp.api:57
lacp_interface_details_t::ptx_state
u32 ptx_state
Definition: node.h:101
vl_api_sw_interface_lacp_details_t::actor_system
vl_api_mac_address_t actor_system
Definition: lacp.api:65
vl_api_sw_interface_lacp_dump_t_handler
void vl_api_sw_interface_lacp_dump_t_handler(vl_api_sw_interface_lacp_dump_t *mp)
Message handler for lacp_dump API.
Definition: lacp_api.c:93
vl_api_sw_interface_lacp_details_t::actor_system_priority
u16 actor_system_priority
Definition: lacp.api:64
node.h
lacp_interface_details_t::mux_state
u32 mux_state
Definition: node.h:100
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
vl_api_sw_interface_lacp_dump_t::client_index
u32 client_index
Definition: lacp.api:29