FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define _GNU_SOURCE
17 #include <vnet/bonding/node.h>
18 #include <lacp/node.h>
19 
20 int
22 {
23  vnet_main_t *vnm = vnet_get_main ();
24  bond_main_t *bm = &bond_main;
25  slave_if_t *sif;
26  bond_if_t *bif;
28  lacp_interface_details_t *r_lacpifs = NULL;
30 
31  /* *INDENT-OFF* */
32  pool_foreach (sif, bm->neighbors,
33  if ((sif->port_enabled == 0) || (sif->lacp_enabled == 0))
34  continue;
35  vec_add2(r_lacpifs, lacpif, 1);
36  memset (lacpif, 0, sizeof (*lacpif));
37  lacpif->sw_if_index = sif->sw_if_index;
38  hi = vnet_get_hw_interface (vnm, sif->hw_if_index);
39  clib_memcpy(lacpif->interface_name, hi->name,
40  MIN (ARRAY_LEN (lacpif->interface_name) - 1,
41  strlen ((const char *) hi->name)));
43  hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
45  MIN (ARRAY_LEN (lacpif->bond_interface_name) - 1,
46  strlen ((const char *) hi->name)));
47  clib_memcpy (lacpif->actor_system, sif->actor.system, 6);
48  lacpif->actor_system_priority = sif->actor.system_priority;
49  lacpif->actor_key = sif->actor.key;
50  lacpif->actor_port_priority = sif->actor.port_priority;
51  lacpif->actor_port_number = sif->actor.port_number;
52  lacpif->actor_state = sif->actor.state;
53  clib_memcpy (lacpif->partner_system, sif->partner.system, 6);
54  lacpif->partner_system_priority = sif->partner.system_priority;
55  lacpif->partner_key = sif->partner.key;
56  lacpif->partner_port_priority = sif->partner.port_priority;
57  lacpif->partner_port_number = sif->partner.port_number;
58  lacpif->partner_state = sif->partner.state;
59  lacpif->rx_state = sif->rx_state;
60  lacpif->tx_state = sif->tx_state;
61  lacpif->ptx_state = sif->ptx_state;
62  lacpif->mux_state = sif->mux_state;
63  );
64  /* *INDENT-ON* */
65 
66  *out_lacpifs = r_lacpifs;
67 
68  return 0;
69 }
70 
71 static void
72 show_lacp (vlib_main_t * vm, u32 * sw_if_indices)
73 {
74  int i;
75  slave_if_t *sif;
76  bond_if_t *bif;
77 
78  if (!sw_if_indices)
79  return;
80 
81  vlib_cli_output (vm, "%-55s %-32s %-32s", " ", "actor state",
82  "partner state");
83  vlib_cli_output (vm, "%-25s %-12s %-16s %-31s %-31s", "interface name",
84  "sw_if_index", "bond interface",
85  "exp/def/dis/col/syn/agg/tim/act",
86  "exp/def/dis/col/syn/agg/tim/act");
87 
88  for (i = 0; i < vec_len (sw_if_indices); i++)
89  {
90  sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]);
91  if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0))
92  continue;
94  vlib_cli_output (vm,
95  "%-25U %-12d %-16U %3x %3x %3x %3x %3x %3x %3x %3x "
96  "%4x %3x %3x %3x %3x %3x %3x %3x",
98  sif->sw_if_index, sif->sw_if_index,
100  bif->sw_if_index, lacp_bit_test (sif->actor.state, 7),
101  lacp_bit_test (sif->actor.state, 6),
102  lacp_bit_test (sif->actor.state, 5),
103  lacp_bit_test (sif->actor.state, 4),
104  lacp_bit_test (sif->actor.state, 3),
105  lacp_bit_test (sif->actor.state, 2),
106  lacp_bit_test (sif->actor.state, 1),
107  lacp_bit_test (sif->actor.state, 0),
108  lacp_bit_test (sif->partner.state, 7),
109  lacp_bit_test (sif->partner.state, 6),
110  lacp_bit_test (sif->partner.state, 5),
111  lacp_bit_test (sif->partner.state, 4),
112  lacp_bit_test (sif->partner.state, 3),
113  lacp_bit_test (sif->partner.state, 2),
114  lacp_bit_test (sif->partner.state, 1),
115  lacp_bit_test (sif->partner.state, 0));
116  vlib_cli_output (vm,
117  " LAG ID: "
118  "[(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
119  "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]",
120  ntohs (sif->actor.system_priority),
121  sif->actor.system[0], sif->actor.system[1],
122  sif->actor.system[2], sif->actor.system[3],
123  sif->actor.system[4], sif->actor.system[5],
124  ntohs (sif->actor.key),
125  ntohs (sif->actor.port_priority),
126  ntohs (sif->actor.port_number),
127  ntohs (sif->partner.system_priority),
128  sif->partner.system[0], sif->partner.system[1],
129  sif->partner.system[2], sif->partner.system[3],
130  sif->partner.system[4], sif->partner.system[5],
131  ntohs (sif->partner.key),
132  ntohs (sif->partner.port_priority),
133  ntohs (sif->partner.port_number));
134  vlib_cli_output (vm,
135  " RX-state: %U, TX-state: %U, "
136  "MUX-state: %U, PTX-state: %U",
140  }
141 }
142 
143 static void
144 show_lacp_details (vlib_main_t * vm, u32 * sw_if_indices)
145 {
146  slave_if_t *sif;
147  lacp_state_struct *state_entry;
148  int i;
149  f64 now;
150 
151  if (!sw_if_indices)
152  return;
153 
154  now = vlib_time_now (vm);
155  for (i = 0; i < vec_len (sw_if_indices); i++)
156  {
157  sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]);
158  if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0))
159  continue;
161  vnet_get_main (), sif->sw_if_index);
162  vlib_cli_output (vm, " debug: %d", sif->debug);
163  vlib_cli_output (vm, " loopback port: %d", sif->loopback_port);
164  vlib_cli_output (vm, " port moved: %d", sif->port_moved);
165  vlib_cli_output (vm, " ready_n: %d", sif->ready_n);
166  vlib_cli_output (vm, " ready: %d", sif->ready);
167  vlib_cli_output (vm, " Actor");
168  vlib_cli_output (vm, " system: %U",
169  format_ethernet_address, sif->actor.system);
170  vlib_cli_output (vm, " system priority: %u",
171  ntohs (sif->actor.system_priority));
172  vlib_cli_output (vm, " key: %u", ntohs (sif->actor.key));
173  vlib_cli_output (vm, " port priority: %u",
174  ntohs (sif->actor.port_priority));
175  vlib_cli_output (vm, " port number: %u",
176  ntohs (sif->actor.port_number));
177  vlib_cli_output (vm, " state: 0x%x", sif->actor.state);
178 
179  state_entry = (lacp_state_struct *) & lacp_state_array;
180  while (state_entry->str)
181  {
182  if (sif->actor.state & (1 << state_entry->bit))
183  vlib_cli_output (vm, " %s (%d)", state_entry->str,
184  state_entry->bit);
185  state_entry++;
186  }
187 
188  vlib_cli_output (vm, " Partner");
189  vlib_cli_output (vm, " system: %U",
190  format_ethernet_address, sif->partner.system);
191  vlib_cli_output (vm, " system priority: %u",
192  ntohs (sif->partner.system_priority));
193  vlib_cli_output (vm, " key: %u", ntohs (sif->partner.key));
194  vlib_cli_output (vm, " port priority: %u",
195  ntohs (sif->partner.port_priority));
196  vlib_cli_output (vm, " port number: %u",
197  ntohs (sif->partner.port_number));
198  vlib_cli_output (vm, " state: 0x%x", sif->partner.state);
199 
200  state_entry = (lacp_state_struct *) & lacp_state_array;
201  while (state_entry->str)
202  {
203  if (sif->partner.state & (1 << state_entry->bit))
204  vlib_cli_output (vm, " %s (%d)", state_entry->str,
205  state_entry->bit);
206  state_entry++;
207  }
208 
210  vlib_cli_output (vm, " wait while timer: not running");
211  else
212  vlib_cli_output (vm, " wait while timer: %=10.2f seconds",
213  sif->wait_while_timer - now);
215  vlib_cli_output (vm, " current while timer: not running");
216  else
217  vlib_cli_output (vm, " current while timer: %=10.2f seconds",
218  sif->current_while_timer - now);
220  vlib_cli_output (vm, " periodic timer: not running");
221  else
222  vlib_cli_output (vm, " periodic timer: %=10.2f seconds",
223  sif->periodic_timer - now);
224  vlib_cli_output (vm, " RX-state: %U", format_rx_sm_state,
225  sif->rx_state);
226  vlib_cli_output (vm, " TX-state: %U", format_tx_sm_state,
227  sif->tx_state);
228  vlib_cli_output (vm, " MUX-state: %U", format_mux_sm_state,
229  sif->mux_state);
230  vlib_cli_output (vm, " PTX-state: %U", format_ptx_sm_state,
231  sif->ptx_state);
232  vlib_cli_output (vm, "\n");
233  }
234 }
235 
236 static clib_error_t *
238  vlib_cli_command_t * cmd)
239 {
240  bond_main_t *bm = &bond_main;
241  vnet_main_t *vnm = &vnet_main;
242  slave_if_t *sif;
243  clib_error_t *error = 0;
244  u8 details = 0;
245  u32 sw_if_index, *sw_if_indices = 0;
246 
248  {
249  if (unformat
250  (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
251  {
252  sif = bond_get_slave_by_sw_if_index (sw_if_index);
253  if (!sif)
254  {
255  error = clib_error_return (0, "interface is not enslaved");
256  goto done;
257  }
258  vec_add1 (sw_if_indices, sif->sw_if_index);
259  }
260  else if (unformat (input, "details"))
261  details = 1;
262  else
263  {
264  error = clib_error_return (0, "unknown input `%U'",
265  format_unformat_error, input);
266  goto done;
267  }
268  }
269 
270  if (vec_len (sw_if_indices) == 0)
271  {
272  pool_foreach (sif, bm->neighbors,
273  vec_add1 (sw_if_indices, sif->sw_if_index);
274  );
275  }
276 
277  if (details)
278  show_lacp_details (vm, sw_if_indices);
279  else
280  show_lacp (vm, sw_if_indices);
281 
282 done:
283  vec_free (sw_if_indices);
284  return error;
285 }
286 
287 /* *INDENT-OFF* */
288 VLIB_CLI_COMMAND (show_lacp_command, static) = {
289  .path = "show lacp",
290  .short_help = "show lacp [<interface>] [details]",
291  .function = show_lacp_fn,
292 };
293 /* *INDENT-ON* */
294 
295 static clib_error_t *
297  vlib_cli_command_t * cmd)
298 {
299  unformat_input_t _line_input, *line_input = &_line_input;
300  clib_error_t *error = NULL;
301  lacp_main_t *lm = &lacp_main;
302  u8 onoff = 0;
303  u8 input_found = 0;
304  u32 sw_if_index = ~0;
305  slave_if_t *sif;
306  vnet_main_t *vnm = vnet_get_main ();
307 
308  /* Get a line of input. */
309  if (!unformat_user (input, unformat_line_input, line_input))
310  return clib_error_return (0, "missing argument");
311 
312  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
313  {
314  if (unformat (line_input, "%U",
315  unformat_vnet_sw_interface, vnm, &sw_if_index))
316  ;
317  if (input_found)
318  {
319  error = clib_error_return (0, "unknown input `%U'",
320  format_unformat_error, line_input);
321  goto done;
322  }
323  else if (unformat (line_input, "on"))
324  {
325  input_found = 1;
326  onoff = 1;
327  }
328  else if (unformat (line_input, "off"))
329  {
330  input_found = 1;
331  onoff = 0;
332  }
333  else
334  {
335  error = clib_error_return (0, "unknown input `%U'",
336  format_unformat_error, line_input);
337  goto done;
338  }
339  }
340 
341  if (!input_found)
342  return clib_error_return (0, "must specify on or off");
343 
344  if (sw_if_index != ~0)
345  {
346  sif = bond_get_slave_by_sw_if_index (sw_if_index);
347  if (!sif)
348  return (clib_error_return (0, "Please enslave the interface first"));
349  sif->debug = onoff;
350  }
351  else
352  lm->debug = onoff;
353 
354 done:
355  unformat_free (line_input);
356 
357  return error;
358 }
359 
360 /* *INDENT-OFF* */
361 VLIB_CLI_COMMAND (debug_lacp_command, static) = {
362  .path = "debug lacp",
363  .short_help = "debug lacp <interface> <on | off>",
364  .function = debug_lacp_command_fn,
365 };
366 /* *INDENT-ON* */
367 
368 clib_error_t *
370 {
371  lacp_main_t *lm = &lacp_main;
372 
373  lm->vlib_main = vm;
374  lm->vnet_main = vnet_get_main ();
375 
376  return 0;
377 }
378 
380 
381 /*
382  * fd.io coding-style-patch-verification: ON
383  *
384  * Local Variables:
385  * eval: (c-set-style "gnu")
386  * End:
387  */
static void show_lacp_details(vlib_main_t *vm, u32 *sw_if_indices)
Definition: cli.c:144
u8 interface_name[64]
Definition: node.h:93
vmrglw vmrglh hi
vlib_main_t * vlib_main
Definition: node.h:119
u32 hw_if_index
Definition: node.h:151
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:227
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
int tx_state
Definition: node.h:265
int lacp_dump_ifs(lacp_interface_details_t **out_lacpifs)
Definition: cli.c:21
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:520
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:559
int i
bond_main_t bond_main
Definition: node.c:24
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
lacp_state_struct lacp_state_array[]
Definition: node.c:21
unformat_function_t unformat_vnet_sw_interface
f64 current_while_timer
Definition: node.h:246
format_function_t format_vnet_sw_if_index_name
static clib_error_t * show_lacp_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:237
f64 periodic_timer
Definition: node.h:255
static u8 * format_rx_sm_state(u8 *s, va_list *args)
Definition: node.h:177
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
static u8 lacp_timer_is_running(f64 timer)
Definition: node.h:163
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
vnet_main_t * vnet_main
Definition: node.h:120
u32 sw_if_index
Definition: node.h:152
lacp_port_info_t actor
Definition: node.h:215
#define clib_error_return(e, args...)
Definition: error.h:99
#define MIN(x, y)
Definition: node.h:31
unformat_function_t unformat_line_input
Definition: format.h:281
u8 ready
Definition: node.h:237
LACP interface details struct.
Definition: node.h:90
struct _unformat_input_t unformat_input_t
u8 port_moved
Definition: node.h:243
u8 debug
Definition: node.h:135
vnet_main_t vnet_main
Definition: misc.c:43
int ptx_state
Definition: node.h:267
u8 bond_interface_name[64]
Definition: node.h:98
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
u32 sw_if_index
Definition: node.h:181
vlib_main_t * vm
Definition: buffer.c:294
lacp_port_info_t partner
Definition: node.h:214
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
static u8 * format_mux_sm_state(u8 *s, va_list *args)
Definition: node.h:219
#define clib_memcpy(a, b, c)
Definition: string.h:75
int rx_state
Definition: node.h:264
#define ARRAY_LEN(x)
Definition: clib.h:59
lacp_main_t lacp_main
Definition: lacp.c:25
static clib_error_t * debug_lacp_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:296
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
u8 loopback_port
Definition: node.h:276
unsigned int u32
Definition: types.h:88
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:432
u32 bif_dev_instance
Definition: node.h:274
static u8 * format_ptx_sm_state(u8 *s, va_list *args)
Definition: node.h:240
u8 debug
Definition: node.h:190
u8 ready_n
Definition: node.h:234
clib_error_t * lacp_cli_init(vlib_main_t *vm)
Definition: cli.c:369
u8 lacp_enabled
Definition: node.h:231
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
static void show_lacp(vlib_main_t *vm, u32 *sw_if_indices)
Definition: cli.c:72
unsigned char u8
Definition: types.h:56
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
static int lacp_bit_test(u8 val, u8 bit)
Definition: node.h:261
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
slave_if_t * neighbors
Definition: node.h:293
static u8 * format_tx_sm_state(u8 *s, va_list *args)
Definition: node.h:198
u8 port_enabled
Definition: node.h:225
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:440
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
f64 wait_while_timer
Definition: node.h:261
u32 hw_if_index
Definition: node.h:208
int mux_state
Definition: node.h:266
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169