Line data Source code
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 <vnet/format_fns.h>
32 : #include <lacp/lacp.api_enum.h>
33 : #include <lacp/lacp.api_types.h>
34 : #include <vlibmemory/vlib.api_types.h>
35 :
36 : typedef struct
37 : {
38 : /* API message ID base */
39 : u16 msg_id_base;
40 : u32 ping_id;
41 : vat_main_t *vat_main;
42 : } lacp_test_main_t;
43 :
44 : lacp_test_main_t lacp_test_main;
45 :
46 : /* lacp-dump API */
47 0 : static void vl_api_sw_interface_lacp_details_t_handler
48 : (vl_api_sw_interface_lacp_details_t * mp)
49 : {
50 0 : vat_main_t *vam = &vat_main;
51 :
52 0 : fformat (vam->ofp,
53 : "%-25s %-12d %-16s %3x %3x %3x %3x %3x %3x %3x %3x "
54 : "%4x %3x %3x %3x %3x %3x %3x %3x\n",
55 0 : mp->interface_name, ntohl (mp->sw_if_index),
56 0 : mp->bond_interface_name,
57 0 : lacp_bit_test (mp->actor_state, 7),
58 0 : lacp_bit_test (mp->actor_state, 6),
59 0 : lacp_bit_test (mp->actor_state, 5),
60 0 : lacp_bit_test (mp->actor_state, 4),
61 0 : lacp_bit_test (mp->actor_state, 3),
62 0 : lacp_bit_test (mp->actor_state, 2),
63 0 : lacp_bit_test (mp->actor_state, 1),
64 0 : lacp_bit_test (mp->actor_state, 0),
65 0 : lacp_bit_test (mp->partner_state, 7),
66 0 : lacp_bit_test (mp->partner_state, 6),
67 0 : lacp_bit_test (mp->partner_state, 5),
68 0 : lacp_bit_test (mp->partner_state, 4),
69 0 : lacp_bit_test (mp->partner_state, 3),
70 0 : lacp_bit_test (mp->partner_state, 2),
71 0 : lacp_bit_test (mp->partner_state, 1),
72 0 : lacp_bit_test (mp->partner_state, 0));
73 0 : fformat (vam->ofp,
74 : " LAG ID: [(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
75 : "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]\n",
76 0 : ntohs (mp->actor_system_priority), mp->actor_system[0],
77 0 : mp->actor_system[1], mp->actor_system[2], mp->actor_system[3],
78 0 : mp->actor_system[4], mp->actor_system[5], ntohs (mp->actor_key),
79 0 : ntohs (mp->actor_port_priority), ntohs (mp->actor_port_number),
80 0 : ntohs (mp->partner_system_priority), mp->partner_system[0],
81 0 : mp->partner_system[1], mp->partner_system[2],
82 0 : mp->partner_system[3], mp->partner_system[4],
83 0 : mp->partner_system[5], ntohs (mp->partner_key),
84 0 : ntohs (mp->partner_port_priority),
85 0 : ntohs (mp->partner_port_number));
86 0 : fformat (vam->ofp,
87 : " RX-state: %U, TX-state: %U, MUX-state: %U, PTX-state: %U\n",
88 : format_rx_sm_state, ntohl (mp->rx_state), format_tx_sm_state,
89 : ntohl (mp->tx_state), format_mux_sm_state, ntohl (mp->mux_state),
90 : format_ptx_sm_state, ntohl (mp->ptx_state));
91 0 : }
92 :
93 : static int
94 0 : api_sw_interface_lacp_dump (vat_main_t * vam)
95 : {
96 0 : lacp_test_main_t *lm = &lacp_test_main;
97 : vl_api_sw_interface_lacp_dump_t *mp;
98 : vl_api_control_ping_t *mp_ping;
99 : int ret;
100 :
101 0 : if (vam->json_output)
102 : {
103 0 : clib_warning ("JSON output not supported for sw_interface_lacp_dump");
104 0 : return -99;
105 : }
106 :
107 0 : fformat (vam->ofp, "%-55s %-32s %-32s\n", " ", "actor state",
108 : "partner state");
109 0 : fformat (vam->ofp, "%-25s %-12s %-16s %-31s %-31s\n", "interface name",
110 : "sw_if_index", "bond interface", "exp/def/dis/col/syn/agg/tim/act",
111 : "exp/def/dis/col/syn/agg/tim/act");
112 :
113 : /* Get list of lacp interfaces */
114 0 : M (SW_INTERFACE_LACP_DUMP, mp);
115 0 : S (mp);
116 :
117 : /* Use a control ping for synchronization */
118 0 : if (!lm->ping_id)
119 0 : lm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
120 0 : mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
121 0 : mp_ping->_vl_msg_id = htons (lm->ping_id);
122 0 : mp_ping->client_index = vam->my_client_index;
123 :
124 0 : fformat (vam->ofp, "Sending ping id=%d\n", lm->ping_id);
125 :
126 0 : vam->result_ready = 0;
127 0 : S (mp_ping);
128 :
129 0 : W (ret);
130 0 : return ret;
131 : }
132 :
133 : #include <lacp/lacp.api_test.c>
134 :
135 : /*
136 : * fd.io coding-style-patch-verification: ON
137 : *
138 : * Local Variables:
139 : * eval: (c-set-style "gnu")
140 : * End:
141 : */
|