FD.io VPP  v20.05.1-6-gf53edbc3b
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;
122  api_main_t *am = vlibapi_get_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[VL_API_SW_INTERFACE_LACP_DUMP] = 1;
129  am->is_mp_safe[VL_API_SW_INTERFACE_LACP_DETAILS] = 1;
130 
131  return 0;
132 }
133 
134 /*
135  * fd.io coding-style-patch-verification: ON
136  *
137  * Local Variables:
138  * eval: (c-set-style "gnu")
139  * End:
140  */
u8 interface_name[64]
Definition: node.h:95
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
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
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_mac_address_t actor_system
Definition: lacp.api:65
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
int lacp_dump_ifs(lacp_interface_details_t **out_lacpifs)
Definition: cli.c:21
#define clib_memcpy(d, s, n)
Definition: string.h:180
unsigned int u32
Definition: types.h:88
#define MIN(x, y)
Definition: node.h:31
LACP interface details struct.
Definition: node.h:92
Reply for lacp dump request.
Definition: lacp.api:54
vl_api_mac_address_t partner_system
Definition: lacp.api:71
vlib_main_t * vm
Definition: in2out_ed.c:1599
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:226
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
Dump lacp interfaces request.
Definition: lacp.api:27
u8 bond_interface_name[64]
Definition: node.h:100
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
#define ARRAY_LEN(x)
Definition: clib.h:66
lacp_main_t lacp_main
Definition: lacp.c:26
clib_error_t * lacp_plugin_api_hookup(vlib_main_t *vm)
Definition: lacp_api.c:119
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
vl_api_interface_index_t sw_if_index
Definition: lacp.api:57
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:379
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:249
#define vec_foreach(var, vec)
Vector iterator.
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3256
u16 msg_id_base
API message ID base.
Definition: node.h:118