lacp: remove api boilerplate
[vpp.git] / src / plugins / lacp / lacp_test.c
1 /*
2  * lacp VAT support
3  *
4  * Copyright (c) 2017 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <inttypes.h>
19
20 #include <vat/vat.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23
24 #include <vppinfra/error.h>
25 #include <lacp/node.h>
26
27 #define __plugin_msg_base lacp_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
29
30 /* declare message IDs */
31 #include <lacp/lacp.api_enum.h>
32 #include <lacp/lacp.api_types.h>
33 #include <vpp/api/vpe.api_types.h>
34
35 typedef struct
36 {
37   /* API message ID base */
38   u16 msg_id_base;
39   u32 ping_id;
40   vat_main_t *vat_main;
41 } lacp_test_main_t;
42
43 lacp_test_main_t lacp_test_main;
44
45 /* lacp-dump API */
46 static void vl_api_sw_interface_lacp_details_t_handler
47   (vl_api_sw_interface_lacp_details_t * mp)
48 {
49   vat_main_t *vam = &vat_main;
50
51   fformat (vam->ofp,
52            "%-25s %-12d %-16s %3x %3x %3x %3x %3x %3x %3x %3x "
53            "%4x %3x %3x %3x %3x %3x %3x %3x\n",
54            mp->interface_name, ntohl (mp->sw_if_index),
55            mp->bond_interface_name,
56            lacp_bit_test (mp->actor_state, 7),
57            lacp_bit_test (mp->actor_state, 6),
58            lacp_bit_test (mp->actor_state, 5),
59            lacp_bit_test (mp->actor_state, 4),
60            lacp_bit_test (mp->actor_state, 3),
61            lacp_bit_test (mp->actor_state, 2),
62            lacp_bit_test (mp->actor_state, 1),
63            lacp_bit_test (mp->actor_state, 0),
64            lacp_bit_test (mp->partner_state, 7),
65            lacp_bit_test (mp->partner_state, 6),
66            lacp_bit_test (mp->partner_state, 5),
67            lacp_bit_test (mp->partner_state, 4),
68            lacp_bit_test (mp->partner_state, 3),
69            lacp_bit_test (mp->partner_state, 2),
70            lacp_bit_test (mp->partner_state, 1),
71            lacp_bit_test (mp->partner_state, 0));
72   fformat (vam->ofp,
73            "  LAG ID: [(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
74            "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]\n",
75            ntohs (mp->actor_system_priority), mp->actor_system[0],
76            mp->actor_system[1], mp->actor_system[2], mp->actor_system[3],
77            mp->actor_system[4], mp->actor_system[5], ntohs (mp->actor_key),
78            ntohs (mp->actor_port_priority), ntohs (mp->actor_port_number),
79            ntohs (mp->partner_system_priority), mp->partner_system[0],
80            mp->partner_system[1], mp->partner_system[2],
81            mp->partner_system[3], mp->partner_system[4],
82            mp->partner_system[5], ntohs (mp->partner_key),
83            ntohs (mp->partner_port_priority),
84            ntohs (mp->partner_port_number));
85   fformat (vam->ofp,
86            "  RX-state: %U, TX-state: %U, MUX-state: %U, PTX-state: %U\n",
87            format_rx_sm_state, ntohl (mp->rx_state), format_tx_sm_state,
88            ntohl (mp->tx_state), format_mux_sm_state, ntohl (mp->mux_state),
89            format_ptx_sm_state, ntohl (mp->ptx_state));
90 }
91
92 static int
93 api_sw_interface_lacp_dump (vat_main_t * vam)
94 {
95   lacp_test_main_t *lm = &lacp_test_main;
96   vl_api_sw_interface_lacp_dump_t *mp;
97   vl_api_control_ping_t *mp_ping;
98   int ret;
99
100   if (vam->json_output)
101     {
102       clib_warning ("JSON output not supported for sw_interface_lacp_dump");
103       return -99;
104     }
105
106   fformat (vam->ofp, "%-55s %-32s %-32s\n", " ", "actor state",
107            "partner state");
108   fformat (vam->ofp, "%-25s %-12s %-16s %-31s  %-31s\n", "interface name",
109            "sw_if_index", "bond interface", "exp/def/dis/col/syn/agg/tim/act",
110            "exp/def/dis/col/syn/agg/tim/act");
111
112   /* Get list of lacp interfaces */
113   M (SW_INTERFACE_LACP_DUMP, mp);
114   S (mp);
115
116   /* Use a control ping for synchronization */
117   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
118   mp_ping->_vl_msg_id = htons (lm->ping_id);
119   mp_ping->client_index = vam->my_client_index;
120
121   fformat (vam->ofp, "Sending ping id=%d\n", lm->ping_id);
122
123   vam->result_ready = 0;
124   S (mp_ping);
125
126   W (ret);
127   return ret;
128 }
129
130 #include <lacp/lacp.api_test.c>
131
132 /*
133  * fd.io coding-style-patch-verification: ON
134  *
135  * Local Variables:
136  * eval: (c-set-style "gnu")
137  * End:
138  */