FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/error.h>
18 #include <vppinfra/format.h>
19 #include <vppinfra/xxhash.h>
20 
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
24 #include <vnet/mpls/packet.h>
25 
26 #include <dpdk/device/dpdk_priv.h>
27 
28 /**
29  * @file
30  * @brief CLI for DPDK Abstraction Layer and pcap Tx Trace.
31  *
32  * This file contains the source code for CLI for DPDK
33  * Abstraction Layer and pcap Tx Trace.
34  */
35 
36 
37 static clib_error_t *
38 get_hqos (u32 hw_if_index, u32 subport_id, dpdk_device_t ** xd,
39  dpdk_device_config_t ** devconf)
40 {
41  dpdk_main_t *dm = &dpdk_main;
43  struct rte_eth_dev_info dev_info;
44  uword *p = 0;
45  clib_error_t *error = NULL;
46 
47 
48  if (hw_if_index == (u32) ~ 0)
49  {
50  error = clib_error_return (0, "please specify valid interface name");
51  goto done;
52  }
53 
54  if (subport_id != 0)
55  {
56  error = clib_error_return (0, "Invalid subport");
57  goto done;
58  }
59 
60  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
61  *xd = vec_elt_at_index (dm->devices, hw->dev_instance);
62 
63  rte_eth_dev_info_get ((*xd)->device_index, &dev_info);
64  if (dev_info.pci_dev)
65  { /* bonded interface has no pci info */
66  vlib_pci_addr_t pci_addr;
67 
68  pci_addr.domain = dev_info.pci_dev->addr.domain;
69  pci_addr.bus = dev_info.pci_dev->addr.bus;
70  pci_addr.slot = dev_info.pci_dev->addr.devid;
71  pci_addr.function = dev_info.pci_dev->addr.function;
72 
73  p =
74  hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
75  }
76 
77  if (p)
78  (*devconf) = pool_elt_at_index (dm->conf->dev_confs, p[0]);
79  else
80  (*devconf) = &dm->conf->default_devconf;
81 
82 done:
83  return error;
84 }
85 
86 static clib_error_t *
88  unformat_input_t * input, vlib_cli_command_t * cmd)
89 {
90 #define PCAP_DEF_PKT_TO_CAPTURE (100)
91 
92  unformat_input_t _line_input, *line_input = &_line_input;
93  dpdk_main_t *dm = &dpdk_main;
94  u8 *filename;
95  u8 *chroot_filename = 0;
96  u32 max = 0;
97  int enabled = 0;
98  int errorFlag = 0;
99  clib_error_t *error = 0;
100 
101  /* Get a line of input. */
102  if (!unformat_user (input, unformat_line_input, line_input))
103  return 0;
104 
105  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
106  {
107  if (unformat (line_input, "on"))
108  {
109  if (dm->tx_pcap_enable == 0)
110  {
111  enabled = 1;
112  }
113  else
114  {
115  vlib_cli_output (vm, "pcap tx capture already on...");
116  errorFlag = 1;
117  break;
118  }
119  }
120  else if (unformat (line_input, "off"))
121  {
122  if (dm->tx_pcap_enable)
123  {
124  vlib_cli_output (vm, "captured %d pkts...",
125  dm->pcap_main.n_packets_captured + 1);
127  {
130  error = pcap_write (&dm->pcap_main);
131  if (error)
132  clib_error_report (error);
133  else
134  vlib_cli_output (vm, "saved to %s...", dm->pcap_filename);
135  }
136 
137  dm->tx_pcap_enable = 0;
138  }
139  else
140  {
141  vlib_cli_output (vm, "pcap tx capture already off...");
142  errorFlag = 1;
143  break;
144  }
145  }
146  else if (unformat (line_input, "max %d", &max))
147  {
148  if (dm->tx_pcap_enable)
149  {
150  vlib_cli_output (vm,
151  "can't change max value while pcap tx capture active...");
152  errorFlag = 1;
153  break;
154  }
155  }
156  else if (unformat (line_input, "intfc %U",
158  &dm->pcap_sw_if_index))
159  ;
160 
161  else if (unformat (line_input, "intfc any"))
162  {
163  dm->pcap_sw_if_index = 0;
164  }
165  else if (unformat (line_input, "file %s", &filename))
166  {
167  if (dm->tx_pcap_enable)
168  {
169  vlib_cli_output (vm,
170  "can't change file while pcap tx capture active...");
171  errorFlag = 1;
172  break;
173  }
174 
175  /* Brain-police user path input */
176  if (strstr ((char *) filename, "..")
177  || index ((char *) filename, '/'))
178  {
179  vlib_cli_output (vm, "illegal characters in filename '%s'",
180  filename);
181  vlib_cli_output (vm,
182  "Hint: Only filename, do not enter directory structure.");
183  vec_free (filename);
184  errorFlag = 1;
185  break;
186  }
187 
188  chroot_filename = format (0, "/tmp/%s%c", filename, 0);
189  vec_free (filename);
190  }
191  else if (unformat (line_input, "status"))
192  {
193  if (dm->pcap_sw_if_index == 0)
194  {
195  vlib_cli_output (vm, "max is %d for any interface to file %s",
196  dm->
197  pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
199  dm->
200  pcap_filename ? dm->pcap_filename : (u8 *)
201  "/tmp/vpe.pcap");
202  }
203  else
204  {
205  vlib_cli_output (vm, "max is %d for interface %U to file %s",
206  dm->
207  pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
210  dm->pcap_sw_if_index,
211  dm->
212  pcap_filename ? dm->pcap_filename : (u8 *)
213  "/tmp/vpe.pcap");
214  }
215 
216  if (dm->tx_pcap_enable == 0)
217  {
218  vlib_cli_output (vm, "pcap tx capture is off...");
219  }
220  else
221  {
222  vlib_cli_output (vm, "pcap tx capture is on: %d of %d pkts...",
225  }
226  break;
227  }
228 
229  else
230  {
231  error = clib_error_return (0, "unknown input `%U'",
232  format_unformat_error, line_input);
233  errorFlag = 1;
234  break;
235  }
236  }
237  unformat_free (line_input);
238 
239 
240  if (errorFlag == 0)
241  {
242  /* Since no error, save configured values. */
243  if (chroot_filename)
244  {
245  if (dm->pcap_filename)
246  vec_free (dm->pcap_filename);
247  vec_add1 (chroot_filename, 0);
248  dm->pcap_filename = chroot_filename;
249  }
250 
251  if (max)
252  dm->pcap_pkts_to_capture = max;
253 
254 
255  if (enabled)
256  {
257  if (dm->pcap_filename == 0)
258  dm->pcap_filename = format (0, "/tmp/vpe.pcap%c", 0);
259 
260  memset (&dm->pcap_main, 0, sizeof (dm->pcap_main));
261  dm->pcap_main.file_name = (char *) dm->pcap_filename;
263  if (dm->pcap_pkts_to_capture)
265 
266  dm->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
267  dm->tx_pcap_enable = 1;
268  vlib_cli_output (vm, "pcap tx capture on...");
269  }
270  }
271  else if (chroot_filename)
272  vec_free (chroot_filename);
273 
274 
275  return error;
276 }
277 
278 /*?
279  * This command is used to start or stop a packet capture, or show
280  * the status of packet capture.
281  *
282  * This command has the following optional parameters:
283  *
284  * - <b>on|off</b> - Used to start or stop a packet capture.
285  *
286  * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
287  * of packets have been received, buffer is flushed to file. Once another
288  * '<em>nn</em>' number of packets have been received, buffer is flushed
289  * to file, overwriting previous write. If not entered, value defaults
290  * to 100. Can only be updated if packet capture is off.
291  *
292  * - <b>intfc <interface>|any</b> - Used to specify a given interface,
293  * or use '<em>any</em>' to run packet capture on all interfaces.
294  * '<em>any</em>' is the default if not provided. Settings from a previous
295  * packet capture are preserved, so '<em>any</em>' can be used to reset
296  * the interface setting.
297  *
298  * - <b>file <name></b> - Used to specify the output filename. The file will
299  * be placed in the '<em>/tmp</em>' directory, so only the filename is
300  * supported. Directory should not be entered. If file already exists, file
301  * will be overwritten. If no filename is provided, '<em>/tmp/vpe.pcap</em>'
302  * will be used. Can only be updated if packet capture is off.
303  *
304  * - <b>status</b> - Displays the current status and configured attributes
305  * associated with a packet capture. If packet capture is in progress,
306  * '<em>status</em>' also will return the number of packets currently in
307  * the local buffer. All additional attributes entered on command line
308  * with '<em>status</em>' will be ingnored and not applied.
309  *
310  * @cliexpar
311  * Example of how to display the status of a tx packet capture when off:
312  * @cliexstart{pcap tx trace status}
313  * max is 100, for any interface to file /tmp/vpe.pcap
314  * pcap tx capture is off...
315  * @cliexend
316  * Example of how to start a tx packet capture:
317  * @cliexstart{pcap tx trace on max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
318  * pcap tx capture on...
319  * @cliexend
320  * Example of how to display the status of a tx packet capture in progress:
321  * @cliexstart{pcap tx trace status}
322  * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
323  * pcap tx capture is on: 20 of 35 pkts...
324  * @cliexend
325  * Example of how to stop a tx packet capture:
326  * @cliexstart{vppctl pcap tx trace off}
327  * captured 21 pkts...
328  * saved to /tmp/vppTest.pcap...
329  * @cliexend
330 ?*/
331 /* *INDENT-OFF* */
332 VLIB_CLI_COMMAND (pcap_trace_command, static) = {
333  .path = "pcap tx trace",
334  .short_help =
335  "pcap tx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
336  .function = pcap_trace_command_fn,
337 };
338 /* *INDENT-ON* */
339 
340 
341 static clib_error_t *
343  vlib_cli_command_t * cmd)
344 {
345  struct rte_mempool *rmp;
346  int i;
347 
348  for (i = 0; i < vec_len (dpdk_main.pktmbuf_pools); i++)
349  {
350  rmp = dpdk_main.pktmbuf_pools[i];
351  if (rmp)
352  {
353  unsigned count = rte_mempool_avail_count (rmp);
354  unsigned free_count = rte_mempool_in_use_count (rmp);
355 
356  vlib_cli_output (vm,
357  "name=\"%s\" available = %7d allocated = %7d total = %7d\n",
358  rmp->name, (u32) count, (u32) free_count,
359  (u32) (count + free_count));
360  }
361  else
362  {
363  vlib_cli_output (vm, "rte_mempool is NULL (!)\n");
364  }
365  }
366  return 0;
367 }
368 
369 /*?
370  * This command displays statistics of each DPDK mempool.
371  *
372  * @cliexpar
373  * Example of how to display DPDK buffer data:
374  * @cliexstart{show dpdk buffer}
375  * name="mbuf_pool_socket0" available = 15104 allocated = 1280 total = 16384
376  * @cliexend
377 ?*/
378 /* *INDENT-OFF* */
379 VLIB_CLI_COMMAND (cmd_show_dpdk_bufferr,static) = {
380  .path = "show dpdk buffer",
381  .short_help = "show dpdk buffer",
382  .function = show_dpdk_buffer,
383  .is_mp_safe = 1,
384 };
385 /* *INDENT-ON* */
386 
387 static clib_error_t *
389  vlib_cli_command_t * cmd)
390 {
391  static u32 *allocated_buffers;
392  u32 n_alloc = 0;
393  u32 n_free = 0;
394  u32 first, actual_alloc;
395 
397  {
398  if (unformat (input, "allocate %d", &n_alloc))
399  ;
400  else if (unformat (input, "free %d", &n_free))
401  ;
402  else
403  break;
404  }
405 
406  if (n_free)
407  {
408  if (vec_len (allocated_buffers) < n_free)
409  return clib_error_return (0, "Can't free %d, only %d allocated",
410  n_free, vec_len (allocated_buffers));
411 
412  first = vec_len (allocated_buffers) - n_free;
413  vlib_buffer_free (vm, allocated_buffers + first, n_free);
414  _vec_len (allocated_buffers) = first;
415  }
416  if (n_alloc)
417  {
418  first = vec_len (allocated_buffers);
419  vec_validate (allocated_buffers,
420  vec_len (allocated_buffers) + n_alloc - 1);
421 
422  actual_alloc = vlib_buffer_alloc (vm, allocated_buffers + first,
423  n_alloc);
424  _vec_len (allocated_buffers) = first + actual_alloc;
425 
426  if (actual_alloc < n_alloc)
427  vlib_cli_output (vm, "WARNING: only allocated %d buffers",
428  actual_alloc);
429  }
430 
431  vlib_cli_output (vm, "Currently %d buffers allocated",
432  vec_len (allocated_buffers));
433 
434  if (allocated_buffers && vec_len (allocated_buffers) == 0)
435  vec_free (allocated_buffers);
436 
437  return 0;
438 }
439 
440 /*?
441  * This command tests the allocation and freeing of DPDK buffers.
442  * If both '<em>allocate</em>' and '<em>free</em>' are entered on the
443  * same command, the '<em>free</em>' is executed first. If no
444  * parameters are provided, this command display how many DPDK buffers
445  * the test command has allocated.
446  *
447  * @cliexpar
448  * @parblock
449  *
450  * Example of how to display how many DPDK buffer test command has allcoated:
451  * @cliexstart{test dpdk buffer}
452  * Currently 0 buffers allocated
453  * @cliexend
454  *
455  * Example of how to allocate DPDK buffers using the test command:
456  * @cliexstart{test dpdk buffer allocate 10}
457  * Currently 10 buffers allocated
458  * @cliexend
459  *
460  * Example of how to free DPDK buffers allocated by the test command:
461  * @cliexstart{test dpdk buffer free 10}
462  * Currently 0 buffers allocated
463  * @cliexend
464  * @endparblock
465 ?*/
466 /* *INDENT-OFF* */
467 VLIB_CLI_COMMAND (cmd_test_dpdk_buffer,static) = {
468  .path = "test dpdk buffer",
469  .short_help = "test dpdk buffer [allocate <nn>] [free <nn>]",
470  .function = test_dpdk_buffer,
471  .is_mp_safe = 1,
472 };
473 /* *INDENT-ON* */
474 
475 static clib_error_t *
477  vlib_cli_command_t * cmd)
478 {
479  unformat_input_t _line_input, *line_input = &_line_input;
480  dpdk_main_t *dm = &dpdk_main;
482  dpdk_device_t *xd;
483  u32 hw_if_index = (u32) ~ 0;
484  u32 nb_rx_desc = (u32) ~ 0;
485  u32 nb_tx_desc = (u32) ~ 0;
486  clib_error_t *error = NULL;
487 
488  if (!unformat_user (input, unformat_line_input, line_input))
489  return 0;
490 
491  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
492  {
493  if (unformat
494  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
495  &hw_if_index))
496  ;
497  else if (unformat (line_input, "tx %d", &nb_tx_desc))
498  ;
499  else if (unformat (line_input, "rx %d", &nb_rx_desc))
500  ;
501  else
502  {
503  error = clib_error_return (0, "parse error: '%U'",
504  format_unformat_error, line_input);
505  goto done;
506  }
507  }
508 
509  if (hw_if_index == (u32) ~ 0)
510  {
511  error = clib_error_return (0, "please specify valid interface name");
512  goto done;
513  }
514 
515  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
516  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
517 
518  if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
519  {
520  error =
522  "number of descriptors can be set only for "
523  "physical devices");
524  goto done;
525  }
526 
527  if ((nb_rx_desc == (u32) ~ 0 || nb_rx_desc == xd->nb_rx_desc) &&
528  (nb_tx_desc == (u32) ~ 0 || nb_tx_desc == xd->nb_tx_desc))
529  {
530  error = clib_error_return (0, "nothing changed");
531  goto done;
532  }
533 
534  if (nb_rx_desc != (u32) ~ 0)
535  xd->nb_rx_desc = nb_rx_desc;
536 
537  if (nb_tx_desc != (u32) ~ 0)
538  xd->nb_tx_desc = nb_tx_desc;
539 
540  error = dpdk_port_setup (dm, xd);
541 
542 done:
543  unformat_free (line_input);
544 
545  return error;
546 }
547 
548 /*?
549  * This command sets the number of DPDK '<em>rx</em>' and
550  * '<em>tx</em>' descriptors for the given physical interface. Use
551  * the command '<em>show hardware-interface</em>' to display the
552  * current descriptor allocation.
553  *
554  * @cliexpar
555  * Example of how to set the DPDK interface descriptors:
556  * @cliexcmd{set dpdk interface descriptors GigabitEthernet0/8/0 rx 512 tx 512}
557 ?*/
558 /* *INDENT-OFF* */
559 VLIB_CLI_COMMAND (cmd_set_dpdk_if_desc,static) = {
560  .path = "set dpdk interface descriptors",
561  .short_help = "set dpdk interface descriptors <interface> [rx <nn>] [tx <nn>]",
562  .function = set_dpdk_if_desc,
563 };
564 /* *INDENT-ON* */
565 
566 static clib_error_t *
568  vlib_cli_command_t * cmd)
569 {
571  dpdk_main_t *dm = &dpdk_main;
573  int cpu;
574 
575  if (tm->n_vlib_mains == 1)
576  vlib_cli_output (vm, "All interfaces are handled by main thread");
577 
578  for (cpu = 0; cpu < vec_len (dm->devices_by_cpu); cpu++)
579  {
580  if (cpu >= dm->input_cpu_first_index &&
581  cpu < (dm->input_cpu_first_index + dm->input_cpu_count))
582  vlib_cli_output (vm, "Thread %u (%s at lcore %u):", cpu,
583  vlib_worker_threads[cpu].name,
584  vlib_worker_threads[cpu].lcore_id);
585 
586  /* *INDENT-OFF* */
587  vec_foreach(dq, dm->devices_by_cpu[cpu])
588  {
589  u32 hw_if_index = dm->devices[dq->device].vlib_hw_if_index;
591  vlib_cli_output(vm, " %v queue %u", hi->name, dq->queue_id);
592  }
593  /* *INDENT-ON* */
594  }
595  return 0;
596 }
597 
598 /*?
599  * This command is used to display the thread and core each
600  * DPDK interface and queue is assigned too.
601  *
602  * @cliexpar
603  * Example of how to display the DPDK interface placement:
604  * @cliexstart{show dpdk interface placement}
605  * Thread 1 (vpp_wk_0 at lcore 1):
606  * GigabitEthernet0/8/0 queue 0
607  * GigabitEthernet0/9/0 queue 0
608  * Thread 2 (vpp_wk_1 at lcore 2):
609  * GigabitEthernet0/8/0 queue 1
610  * GigabitEthernet0/9/0 queue 1
611  * @cliexend
612 ?*/
613 /* *INDENT-OFF* */
614 VLIB_CLI_COMMAND (cmd_show_dpdk_if_placement,static) = {
615  .path = "show dpdk interface placement",
616  .short_help = "show dpdk interface placement",
617  .function = show_dpdk_if_placement,
618 };
619 /* *INDENT-ON* */
620 
621 static int
622 dpdk_device_queue_sort (void *a1, void *a2)
623 {
624  dpdk_device_and_queue_t *dq1 = a1;
625  dpdk_device_and_queue_t *dq2 = a2;
626 
627  if (dq1->device > dq2->device)
628  return 1;
629  else if (dq1->device < dq2->device)
630  return -1;
631  else if (dq1->queue_id > dq2->queue_id)
632  return 1;
633  else if (dq1->queue_id < dq2->queue_id)
634  return -1;
635  else
636  return 0;
637 }
638 
639 static clib_error_t *
641  vlib_cli_command_t * cmd)
642 {
643  unformat_input_t _line_input, *line_input = &_line_input;
644  dpdk_main_t *dm = &dpdk_main;
647  dpdk_device_t *xd;
648  u32 hw_if_index = (u32) ~ 0;
649  u32 queue = (u32) 0;
650  u32 cpu = (u32) ~ 0;
651  int i;
652  clib_error_t *error = NULL;
653 
654  if (!unformat_user (input, unformat_line_input, line_input))
655  return 0;
656 
657  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
658  {
659  if (unformat
660  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
661  &hw_if_index))
662  ;
663  else if (unformat (line_input, "queue %d", &queue))
664  ;
665  else if (unformat (line_input, "thread %d", &cpu))
666  ;
667  else
668  {
669  error = clib_error_return (0, "parse error: '%U'",
670  format_unformat_error, line_input);
671  goto done;
672  }
673  }
674 
675  if (hw_if_index == (u32) ~ 0)
676  {
677  error = clib_error_return (0, "please specify valid interface name");
678  goto done;
679  }
680 
681  if (cpu < dm->input_cpu_first_index ||
682  cpu >= (dm->input_cpu_first_index + dm->input_cpu_count))
683  {
684  error = clib_error_return (0, "please specify valid thread id");
685  goto done;
686  }
687 
688  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
689  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
690 
691  for (i = 0; i < vec_len (dm->devices_by_cpu); i++)
692  {
693  /* *INDENT-OFF* */
694  vec_foreach(dq, dm->devices_by_cpu[i])
695  {
696  if (hw_if_index == dm->devices[dq->device].vlib_hw_if_index &&
697  queue == dq->queue_id)
698  {
699  if (cpu == i) /* nothing to do */
700  goto done;
701 
702  vec_del1(dm->devices_by_cpu[i], dq - dm->devices_by_cpu[i]);
703  vec_add2(dm->devices_by_cpu[cpu], dq, 1);
704  dq->queue_id = queue;
705  dq->device = xd->device_index;
706  xd->cpu_socket_id_by_queue[queue] =
707  rte_lcore_to_socket_id(vlib_worker_threads[cpu].lcore_id);
708 
711 
714 
715  if (vec_len(dm->devices_by_cpu[i]) == 0)
717  VLIB_NODE_STATE_DISABLED);
718 
719  if (vec_len(dm->devices_by_cpu[cpu]) == 1)
721  VLIB_NODE_STATE_POLLING);
722 
723  goto done;
724  }
725  }
726  /* *INDENT-ON* */
727  }
728 
729  error = clib_error_return (0, "not found");
730 
731 done:
732  unformat_free (line_input);
733 
734  return error;
735 }
736 
737 /*?
738  * This command is used to assign a given interface, and optionally a
739  * given queue, to a different thread. This will not create a thread,
740  * so the thread must already exist. Use '<em>/etc/vpp/startup.conf</em>'
741  * for the initial thread creation. If the '<em>queue</em>' is not provided,
742  * it defaults to 0.
743  *
744  * @cliexpar
745  * Example of how to display the DPDK interface placement:
746  * @cliexstart{show dpdk interface placement}
747  * Thread 1 (vpp_wk_0 at lcore 1):
748  * GigabitEthernet0/8/0 queue 0
749  * GigabitEthernet0/9/0 queue 0
750  * Thread 2 (vpp_wk_1 at lcore 2):
751  * GigabitEthernet0/8/0 queue 1
752  * GigabitEthernet0/9/0 queue 1
753  * @cliexend
754  * Example of how to assign a DPDK interface and queue to a thread:
755  * @cliexcmd{set dpdk interface placement GigabitEthernet0/8/0 queue 1 thread 1}
756 ?*/
757 /* *INDENT-OFF* */
758 VLIB_CLI_COMMAND (cmd_set_dpdk_if_placement,static) = {
759  .path = "set dpdk interface placement",
760  .short_help = "set dpdk interface placement <interface> [queue <n>] thread <n>",
761  .function = set_dpdk_if_placement,
762 };
763 /* *INDENT-ON* */
764 
765 static clib_error_t *
767  vlib_cli_command_t * cmd)
768 {
770  dpdk_main_t *dm = &dpdk_main;
772  int cpu;
773 
774  if (tm->n_vlib_mains == 1)
775  vlib_cli_output (vm, "All interfaces are handled by main thread");
776 
777  for (cpu = 0; cpu < vec_len (dm->devices_by_hqos_cpu); cpu++)
778  {
779  if (cpu >= dm->hqos_cpu_first_index &&
780  cpu < (dm->hqos_cpu_first_index + dm->hqos_cpu_count))
781  vlib_cli_output (vm, "Thread %u (%s at lcore %u):", cpu,
782  vlib_worker_threads[cpu].name,
783  vlib_worker_threads[cpu].lcore_id);
784 
785  vec_foreach (dq, dm->devices_by_hqos_cpu[cpu])
786  {
787  u32 hw_if_index = dm->devices[dq->device].vlib_hw_if_index;
789  vnet_get_hw_interface (dm->vnet_main, hw_if_index);
790  vlib_cli_output (vm, " %v queue %u", hi->name, dq->queue_id);
791  }
792  }
793  return 0;
794 }
795 
796 /*?
797  * This command is used to display the thread and core each
798  * DPDK output interface and HQoS queue is assigned too.
799  *
800  * @cliexpar
801  * Example of how to display the DPDK output interface and HQoS queue placement:
802  * @cliexstart{show dpdk interface hqos placement}
803  * Thread 1 (vpp_hqos-threads_0 at lcore 3):
804  * GigabitEthernet0/8/0 queue 0
805  * Thread 2 (vpp_hqos-threads_1 at lcore 4):
806  * GigabitEthernet0/9/0 queue 0
807  * @cliexend
808 ?*/
809 /* *INDENT-OFF* */
810 VLIB_CLI_COMMAND (cmd_show_dpdk_if_hqos_placement, static) = {
811  .path = "show dpdk interface hqos placement",
812  .short_help = "show dpdk interface hqos placement",
813  .function = show_dpdk_if_hqos_placement,
814 };
815 /* *INDENT-ON* */
816 
817 static clib_error_t *
819  vlib_cli_command_t * cmd)
820 {
821  unformat_input_t _line_input, *line_input = &_line_input;
822  dpdk_main_t *dm = &dpdk_main;
825  dpdk_device_t *xd;
826  u32 hw_if_index = (u32) ~ 0;
827  u32 cpu = (u32) ~ 0;
828  int i;
829  clib_error_t *error = NULL;
830 
831  if (!unformat_user (input, unformat_line_input, line_input))
832  return 0;
833 
834  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
835  {
836  if (unformat
837  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
838  &hw_if_index))
839  ;
840  else if (unformat (line_input, "thread %d", &cpu))
841  ;
842  else
843  {
844  error = clib_error_return (0, "parse error: '%U'",
845  format_unformat_error, line_input);
846  goto done;
847  }
848  }
849 
850  if (hw_if_index == (u32) ~ 0)
851  return clib_error_return (0, "please specify valid interface name");
852 
853  if (cpu < dm->hqos_cpu_first_index ||
854  cpu >= (dm->hqos_cpu_first_index + dm->hqos_cpu_count))
855  {
856  error = clib_error_return (0, "please specify valid thread id");
857  goto done;
858  }
859 
860  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
861  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
862 
863  for (i = 0; i < vec_len (dm->devices_by_hqos_cpu); i++)
864  {
865  vec_foreach (dq, dm->devices_by_hqos_cpu[i])
866  {
867  if (hw_if_index == dm->devices[dq->device].vlib_hw_if_index)
868  {
869  if (cpu == i) /* nothing to do */
870  goto done;
871 
873  dq - dm->devices_by_hqos_cpu[i]);
874  vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
875  dq->queue_id = 0;
876  dq->device = xd->device_index;
877 
880 
883 
884  goto done;
885  }
886  }
887  }
888 
889  error = clib_error_return (0, "not found");
890 
891 done:
892  unformat_free (line_input);
893 
894  return error;
895 }
896 
897 /*?
898  * This command is used to assign a given DPDK output interface and
899  * HQoS queue to a different thread. This will not create a thread,
900  * so the thread must already exist. Use '<em>/etc/vpp/startup.conf</em>'
901  * for the initial thread creation. See @ref qos_doc for more details.
902  *
903  * @cliexpar
904  * Example of how to display the DPDK output interface and HQoS queue placement:
905  * @cliexstart{show dpdk interface hqos placement}
906  * Thread 1 (vpp_hqos-threads_0 at lcore 3):
907  * GigabitEthernet0/8/0 queue 0
908  * Thread 2 (vpp_hqos-threads_1 at lcore 4):
909  * GigabitEthernet0/9/0 queue 0
910  * @cliexend
911  * Example of how to assign a DPDK output interface and HQoS queue to a thread:
912  * @cliexcmd{set dpdk interface hqos placement GigabitEthernet0/8/0 thread 2}
913 ?*/
914 /* *INDENT-OFF* */
915 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_placement, static) = {
916  .path = "set dpdk interface hqos placement",
917  .short_help = "set dpdk interface hqos placement <interface> thread <n>",
918  .function = set_dpdk_if_hqos_placement,
919 };
920 /* *INDENT-ON* */
921 
922 static clib_error_t *
924  vlib_cli_command_t * cmd)
925 {
926  unformat_input_t _line_input, *line_input = &_line_input;
927  dpdk_main_t *dm = &dpdk_main;
929  dpdk_device_t *xd;
930  u32 hw_if_index = (u32) ~ 0;
931  u32 subport_id = (u32) ~ 0;
932  u32 pipe_id = (u32) ~ 0;
933  u32 profile_id = (u32) ~ 0;
934  int rv;
935  clib_error_t *error = NULL;
936 
937  if (!unformat_user (input, unformat_line_input, line_input))
938  return 0;
939 
940  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
941  {
942  if (unformat
943  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
944  &hw_if_index))
945  ;
946  else if (unformat (line_input, "subport %d", &subport_id))
947  ;
948  else if (unformat (line_input, "pipe %d", &pipe_id))
949  ;
950  else if (unformat (line_input, "profile %d", &profile_id))
951  ;
952  else
953  {
954  error = clib_error_return (0, "parse error: '%U'",
955  format_unformat_error, line_input);
956  goto done;
957  }
958  }
959 
960  if (hw_if_index == (u32) ~ 0)
961  {
962  error = clib_error_return (0, "please specify valid interface name");
963  goto done;
964  }
965 
966  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
967  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
968 
969  rv =
970  rte_sched_pipe_config (xd->hqos_ht->hqos, subport_id, pipe_id,
971  profile_id);
972  if (rv)
973  {
974  error = clib_error_return (0, "pipe configuration failed");
975  goto done;
976  }
977 
978 done:
979  unformat_free (line_input);
980 
981  return error;
982 }
983 
984 /*?
985  * This command is used to change the profile associate with a HQoS pipe. The
986  * '<em><profile_id></em>' is zero based. Use the command
987  * '<em>show dpdk interface hqos</em>' to display the content of each profile.
988  * See @ref qos_doc for more details.
989  *
990  * @note
991  * Currently there is not an API to create a new HQoS pipe profile. One is
992  * created by default in the code (search for '<em>hqos_pipe_params_default</em>'').
993  * Additional profiles can be created in code and code recompiled. Then use this
994  * command to assign it.
995  *
996  * @cliexpar
997  * Example of how to assign a new profile to a HQoS pipe:
998  * @cliexcmd{set dpdk interface hqos pipe GigabitEthernet0/8/0 subport 0 pipe 2 profile 1}
999 ?*/
1000 /* *INDENT-OFF* */
1001 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_pipe, static) =
1002 {
1003  .path = "set dpdk interface hqos pipe",
1004  .short_help = "set dpdk interface hqos pipe <interface> subport <subport_id> pipe <pipe_id> "
1005  "profile <profile_id>",
1006  .function = set_dpdk_if_hqos_pipe,
1007 };
1008 /* *INDENT-ON* */
1009 
1010 static clib_error_t *
1012  vlib_cli_command_t * cmd)
1013 {
1014  unformat_input_t _line_input, *line_input = &_line_input;
1015  dpdk_main_t *dm = &dpdk_main;
1016  dpdk_device_t *xd = NULL;
1017  u32 hw_if_index = (u32) ~ 0;
1018  u32 subport_id = (u32) ~ 0;
1019  struct rte_sched_subport_params p;
1020  int rv;
1021  clib_error_t *error = NULL;
1022  u32 tb_rate = (u32) ~ 0;
1023  u32 tb_size = (u32) ~ 0;
1024  u32 tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE] =
1025  { (u32) ~ 0, (u32) ~ 0, (u32) ~ 0, (u32) ~ 0 };
1026  u32 tc_period = (u32) ~ 0;
1027  dpdk_device_config_t *devconf = NULL;
1028 
1029  if (!unformat_user (input, unformat_line_input, line_input))
1030  return 0;
1031 
1032  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1033  {
1034  if (unformat
1035  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1036  &hw_if_index))
1037  ;
1038  else if (unformat (line_input, "subport %d", &subport_id))
1039  ;
1040  else if (unformat (line_input, "rate %d", &tb_rate))
1041  ;
1042  else if (unformat (line_input, "bktsize %d", &tb_size))
1043  ;
1044  else if (unformat (line_input, "tc0 %d", &tc_rate[0]))
1045  ;
1046  else if (unformat (line_input, "tc1 %d", &tc_rate[1]))
1047  ;
1048  else if (unformat (line_input, "tc2 %d", &tc_rate[2]))
1049  ;
1050  else if (unformat (line_input, "tc3 %d", &tc_rate[3]))
1051  ;
1052  else if (unformat (line_input, "period %d", &tc_period))
1053  ;
1054  else
1055  {
1056  error = clib_error_return (0, "parse error: '%U'",
1057  format_unformat_error, line_input);
1058  goto done;
1059  }
1060  }
1061 
1062  error = get_hqos (hw_if_index, subport_id, &xd, &devconf);
1063 
1064  if (error == NULL)
1065  {
1066  /* Copy the current values over to local structure. */
1067  memcpy (&p, &devconf->hqos.subport[subport_id], sizeof (p));
1068 
1069  /* Update local structure with input values. */
1070  if (tb_rate != (u32) ~ 0)
1071  {
1072  p.tb_rate = tb_rate;
1073  p.tc_rate[0] = tb_rate;
1074  p.tc_rate[1] = tb_rate;
1075  p.tc_rate[2] = tb_rate;
1076  p.tc_rate[3] = tb_rate;
1077  }
1078  if (tb_size != (u32) ~ 0)
1079  {
1080  p.tb_size = tb_size;
1081  }
1082  if (tc_rate[0] != (u32) ~ 0)
1083  {
1084  p.tc_rate[0] = tc_rate[0];
1085  }
1086  if (tc_rate[1] != (u32) ~ 0)
1087  {
1088  p.tc_rate[1] = tc_rate[1];
1089  }
1090  if (tc_rate[2] != (u32) ~ 0)
1091  {
1092  p.tc_rate[2] = tc_rate[2];
1093  }
1094  if (tc_rate[3] != (u32) ~ 0)
1095  {
1096  p.tc_rate[3] = tc_rate[3];
1097  }
1098  if (tc_period != (u32) ~ 0)
1099  {
1100  p.tc_period = tc_period;
1101  }
1102 
1103  /* Apply changes. */
1104  rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport_id, &p);
1105  if (rv)
1106  {
1107  error = clib_error_return (0, "subport configuration failed");
1108  goto done;
1109  }
1110  else
1111  {
1112  /* Successfully applied, so save of the input values. */
1113  memcpy (&devconf->hqos.subport[subport_id], &p, sizeof (p));
1114  }
1115  }
1116 
1117 done:
1118  unformat_free (line_input);
1119 
1120  return error;
1121 }
1122 
1123 /*?
1124  * This command is used to set the subport level parameters such as token
1125  * bucket rate (bytes per seconds), token bucket size (bytes), traffic class
1126  * rates (bytes per seconds) and token update period (Milliseconds).
1127  *
1128  * By default, the '<em>rate</em>' is set to 1250000000 bytes/second (10GbE
1129  * rate) and each of the four traffic classes is set to 100% of the port rate.
1130  * If the '<em>rate</em>' is updated by this command, all four traffic classes
1131  * are assigned the same value. Each of the four traffic classes can be updated
1132  * individually.
1133  *
1134  * @cliexpar
1135  * Example of how modify the subport attributes for a 1GbE link:
1136  * @cliexcmd{set dpdk interface hqos subport GigabitEthernet0/8/0 subport 0 rate 125000000}
1137 ?*/
1138 /* *INDENT-OFF* */
1139 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_subport, static) = {
1140  .path = "set dpdk interface hqos subport",
1141  .short_help = "set dpdk interface hqos subport <interface> subport <subport_id> "
1142  "[rate <n>] [bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] "
1143  "[period <n>]",
1144  .function = set_dpdk_if_hqos_subport,
1145 };
1146 /* *INDENT-ON* */
1147 
1148 static clib_error_t *
1150  vlib_cli_command_t * cmd)
1151 {
1152  unformat_input_t _line_input, *line_input = &_line_input;
1154  dpdk_main_t *dm = &dpdk_main;
1155  vnet_hw_interface_t *hw;
1156  dpdk_device_t *xd;
1157  u32 hw_if_index = (u32) ~ 0;
1158  u32 tc = (u32) ~ 0;
1159  u32 queue = (u32) ~ 0;
1160  u32 entry = (u32) ~ 0;
1161  u32 val, i;
1162  clib_error_t *error = NULL;
1163 
1164  if (!unformat_user (input, unformat_line_input, line_input))
1165  return 0;
1166 
1167  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1168  {
1169  if (unformat
1170  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1171  &hw_if_index))
1172  ;
1173  else if (unformat (line_input, "entry %d", &entry))
1174  ;
1175  else if (unformat (line_input, "tc %d", &tc))
1176  ;
1177  else if (unformat (line_input, "queue %d", &queue))
1178  ;
1179  else
1180  {
1181  error = clib_error_return (0, "parse error: '%U'",
1182  format_unformat_error, line_input);
1183  goto done;
1184  }
1185  }
1186 
1187  if (hw_if_index == (u32) ~ 0)
1188  {
1189  error = clib_error_return (0, "please specify valid interface name");
1190  goto done;
1191  }
1192  if (entry >= 64)
1193  {
1194  error = clib_error_return (0, "invalid entry");
1195  goto done;
1196  }
1197  if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1198  {
1199  error = clib_error_return (0, "invalid traffic class");
1200  goto done;
1201  }
1202  if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1203  {
1204  error = clib_error_return (0, "invalid traffic class queue");
1205  goto done;
1206  }
1207 
1208  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1209  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1210 
1211  /* Detect the set of worker threads */
1212  uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1213  /* Should never happen, shut up Coverity warning */
1214  if (p == 0)
1215  {
1216  error = clib_error_return (0, "no worker registrations?");
1217  goto done;
1218  }
1219 
1221  int worker_thread_first = tr->first_index;
1222  int worker_thread_count = tr->count;
1223 
1224  val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1225  for (i = 0; i < worker_thread_count; i++)
1226  xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1227 
1228 done:
1229  unformat_free (line_input);
1230 
1231  return error;
1232 }
1233 
1234 /*?
1235  * This command is used to set the traffic class translation table. The
1236  * traffic class translation table is used to map 64 values (0-63) to one of
1237  * four traffic class and one of four HQoS input queue. Use the '<em>show
1238  * dpdk interface hqos</em>' command to display the traffic class translation
1239  * table. See @ref qos_doc for more details.
1240  *
1241  * This command has the following parameters:
1242  *
1243  * - <b><interface></b> - Used to specify the output interface.
1244  *
1245  * - <b>entry <map_val></b> - Mapped value (0-63) to assign traffic class and queue to.
1246  *
1247  * - <b>tc <tc_id></b> - Traffic class (0-3) to be used by the provided mapped value.
1248  *
1249  * - <b>queue <queue_id></b> - HQoS input queue (0-3) to be used by the provided mapped value.
1250  *
1251  * @cliexpar
1252  * Example of how modify the traffic class translation table:
1253  * @cliexcmd{set dpdk interface hqos tctbl GigabitEthernet0/8/0 entry 16 tc 2 queue 2}
1254 ?*/
1255 /* *INDENT-OFF* */
1256 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_tctbl, static) = {
1257  .path = "set dpdk interface hqos tctbl",
1258  .short_help = "set dpdk interface hqos tctbl <interface> entry <map_val> tc <tc_id> queue <queue_id>",
1259  .function = set_dpdk_if_hqos_tctbl,
1260 };
1261 /* *INDENT-ON* */
1262 
1263 static clib_error_t *
1265  vlib_cli_command_t * cmd)
1266 {
1267  unformat_input_t _line_input, *line_input = &_line_input;
1269  dpdk_main_t *dm = &dpdk_main;
1270  clib_error_t *error = NULL;
1271 
1272  /* Device specific data */
1273  struct rte_eth_dev_info dev_info;
1274  dpdk_device_config_t *devconf = 0;
1275  vnet_hw_interface_t *hw;
1276  dpdk_device_t *xd;
1277  u32 hw_if_index = (u32) ~ 0;
1278 
1279  /* Detect the set of worker threads */
1280  uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1281  /* Should never happen, shut up Coverity warning */
1282  if (p == 0)
1283  return clib_error_return (0, "no worker registrations?");
1284 
1286  int worker_thread_first = tr->first_index;
1287  int worker_thread_count = tr->count;
1288 
1289  /* Packet field configuration */
1290  u64 mask = (u64) ~ 0;
1291  u32 id = (u32) ~ 0;
1292  u32 offset = (u32) ~ 0;
1293 
1294  /* HQoS params */
1295  u32 n_subports_per_port, n_pipes_per_subport, tctbl_size;
1296 
1297  u32 i;
1298 
1299  /* Parse input arguments */
1300  if (!unformat_user (input, unformat_line_input, line_input))
1301  return 0;
1302 
1303  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1304  {
1305  if (unformat
1306  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1307  &hw_if_index))
1308  ;
1309  else if (unformat (line_input, "id subport"))
1310  id = 0;
1311  else if (unformat (line_input, "id pipe"))
1312  id = 1;
1313  else if (unformat (line_input, "id tc"))
1314  id = 2;
1315  else if (unformat (line_input, "id %d", &id))
1316  ;
1317  else if (unformat (line_input, "offset %d", &offset))
1318  ;
1319  else if (unformat (line_input, "mask %llx", &mask))
1320  ;
1321  else
1322  {
1323  error = clib_error_return (0, "parse error: '%U'",
1324  format_unformat_error, line_input);
1325  goto done;
1326  }
1327  }
1328 
1329  /* Get interface */
1330  if (hw_if_index == (u32) ~ 0)
1331  {
1332  error = clib_error_return (0, "please specify valid interface name");
1333  goto done;
1334  }
1335 
1336  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1337  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1338 
1339  rte_eth_dev_info_get (xd->device_index, &dev_info);
1340  if (dev_info.pci_dev)
1341  { /* bonded interface has no pci info */
1342  vlib_pci_addr_t pci_addr;
1343 
1344  pci_addr.domain = dev_info.pci_dev->addr.domain;
1345  pci_addr.bus = dev_info.pci_dev->addr.bus;
1346  pci_addr.slot = dev_info.pci_dev->addr.devid;
1347  pci_addr.function = dev_info.pci_dev->addr.function;
1348 
1349  p =
1350  hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1351  }
1352 
1353  if (p)
1354  devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1355  else
1356  devconf = &dm->conf->default_devconf;
1357 
1358  if (devconf->hqos_enabled == 0)
1359  {
1360  vlib_cli_output (vm, "HQoS disabled for this interface");
1361  goto done;
1362  }
1363 
1364  n_subports_per_port = devconf->hqos.port.n_subports_per_port;
1365  n_pipes_per_subport = devconf->hqos.port.n_pipes_per_subport;
1366  tctbl_size = RTE_DIM (devconf->hqos.tc_table);
1367 
1368  /* Validate packet field configuration: id, offset and mask */
1369  if (id >= 3)
1370  {
1371  error = clib_error_return (0, "invalid packet field id");
1372  goto done;
1373  }
1374 
1375  switch (id)
1376  {
1377  case 0:
1378  if (dpdk_hqos_validate_mask (mask, n_subports_per_port) != 0)
1379  {
1380  error = clib_error_return (0, "invalid subport ID mask "
1381  "(n_subports_per_port = %u)",
1382  n_subports_per_port);
1383  goto done;
1384  }
1385  break;
1386  case 1:
1387  if (dpdk_hqos_validate_mask (mask, n_pipes_per_subport) != 0)
1388  {
1389  error = clib_error_return (0, "invalid pipe ID mask "
1390  "(n_pipes_per_subport = %u)",
1391  n_pipes_per_subport);
1392  goto done;
1393  }
1394  break;
1395  case 2:
1396  default:
1397  if (dpdk_hqos_validate_mask (mask, tctbl_size) != 0)
1398  {
1399  error = clib_error_return (0, "invalid TC table index mask "
1400  "(TC table size = %u)", tctbl_size);
1401  goto done;
1402  }
1403  }
1404 
1405  /* Propagate packet field configuration to all workers */
1406  for (i = 0; i < worker_thread_count; i++)
1407  switch (id)
1408  {
1409  case 0:
1410  xd->hqos_wt[worker_thread_first + i].hqos_field0_slabpos = offset;
1411  xd->hqos_wt[worker_thread_first + i].hqos_field0_slabmask = mask;
1412  xd->hqos_wt[worker_thread_first + i].hqos_field0_slabshr =
1413  __builtin_ctzll (mask);
1414  break;
1415  case 1:
1416  xd->hqos_wt[worker_thread_first + i].hqos_field1_slabpos = offset;
1417  xd->hqos_wt[worker_thread_first + i].hqos_field1_slabmask = mask;
1418  xd->hqos_wt[worker_thread_first + i].hqos_field1_slabshr =
1419  __builtin_ctzll (mask);
1420  break;
1421  case 2:
1422  default:
1423  xd->hqos_wt[worker_thread_first + i].hqos_field2_slabpos = offset;
1424  xd->hqos_wt[worker_thread_first + i].hqos_field2_slabmask = mask;
1425  xd->hqos_wt[worker_thread_first + i].hqos_field2_slabshr =
1426  __builtin_ctzll (mask);
1427  }
1428 
1429 done:
1430  unformat_free (line_input);
1431 
1432  return error;
1433 }
1434 
1435 /*?
1436  * This command is used to set the packet fields required for classifiying the
1437  * incoming packet. As a result of classification process, packet field
1438  * information will be mapped to 5 tuples (subport, pipe, traffic class, pipe,
1439  * color) and stored in packet mbuf.
1440  *
1441  * This command has the following parameters:
1442  *
1443  * - <b><interface></b> - Used to specify the output interface.
1444  *
1445  * - <b>id subport|pipe|tc</b> - Classification occurs across three fields.
1446  * This parameter indicates which of the three masks are being configured. Legacy
1447  * code used 0-2 to represent these three fields, so 0-2 is still accepted.
1448  * - <b>subport|0</b> - Currently only one subport is supported, so only
1449  * an empty mask is supported for the subport classification.
1450  * - <b>pipe|1</b> - Currently, 4096 pipes per subport are supported, so a
1451  * 12-bit mask should be configure to map to the 0-4095 pipes.
1452  * - <b>tc|2</b> - The translation table (see '<em>set dpdk interface hqos
1453  * tctbl</em>' command) maps each value (0-63) into one of the 4 traffic classes
1454  * per pipe. A 6-bit mask should be configure to map this field to a traffic class.
1455  *
1456  * - <b>offset <n></b> - Offset in the packet to apply the 64-bit mask for classification.
1457  * The offset should be on an 8-byte boundary (0,8,16,24..).
1458  *
1459  * - <b>mask <hex-mask></b> - 64-bit mask to apply to packet at the given '<em>offset</em>'.
1460  * Bits must be contiguous and should not include '<em>0x</em>'.
1461  *
1462  * The default values for the '<em>pktfield</em>' assumes Ethernet/IPv4/UDP packets with
1463  * no VLAN. Adjust based on expected packet format and desired classification field.
1464  * - '<em>subport</em>' is always empty (offset 0 mask 0000000000000000)
1465  * - By default, '<em>pipe</em>' maps to the UDP payload bits 12 .. 23 (offset 40
1466  * mask 0000000fff000000)
1467  * - By default, '<em>tc</em>' maps to the DSCP field in IP header (offset 48 mask
1468  * 00000000000000fc)
1469  *
1470  * @cliexpar
1471  * Example of how modify the '<em>pipe</em>' classification filter to match VLAN:
1472  * @cliexcmd{set dpdk interface hqos pktfield GigabitEthernet0/8/0 id pipe offset 8 mask 0000000000000FFF}
1473 ?*/
1474 /* *INDENT-OFF* */
1475 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_pktfield, static) = {
1476  .path = "set dpdk interface hqos pktfield",
1477  .short_help = "set dpdk interface hqos pktfield <interface> id subport|pipe|tc offset <n> "
1478  "mask <hex-mask>",
1479  .function = set_dpdk_if_hqos_pktfield,
1480 };
1481 /* *INDENT-ON* */
1482 
1483 static clib_error_t *
1485  vlib_cli_command_t * cmd)
1486 {
1487  unformat_input_t _line_input, *line_input = &_line_input;
1489  dpdk_main_t *dm = &dpdk_main;
1490  vnet_hw_interface_t *hw;
1491  dpdk_device_t *xd;
1495  u32 *tctbl;
1496  u32 hw_if_index = (u32) ~ 0;
1497  u32 profile_id, subport_id, i;
1498  struct rte_eth_dev_info dev_info;
1499  dpdk_device_config_t *devconf = 0;
1501  uword *p = 0;
1502  clib_error_t *error = NULL;
1503 
1504  if (!unformat_user (input, unformat_line_input, line_input))
1505  return 0;
1506 
1507  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1508  {
1509  if (unformat
1510  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1511  &hw_if_index))
1512  ;
1513  else
1514  {
1515  error = clib_error_return (0, "parse error: '%U'",
1516  format_unformat_error, line_input);
1517  goto done;
1518  }
1519  }
1520 
1521  if (hw_if_index == (u32) ~ 0)
1522  {
1523  error = clib_error_return (0, "please specify interface name!!");
1524  goto done;
1525  }
1526 
1527  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1528  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1529 
1530  rte_eth_dev_info_get (xd->device_index, &dev_info);
1531  if (dev_info.pci_dev)
1532  { /* bonded interface has no pci info */
1533  vlib_pci_addr_t pci_addr;
1534 
1535  pci_addr.domain = dev_info.pci_dev->addr.domain;
1536  pci_addr.bus = dev_info.pci_dev->addr.bus;
1537  pci_addr.slot = dev_info.pci_dev->addr.devid;
1538  pci_addr.function = dev_info.pci_dev->addr.function;
1539 
1540  p =
1541  hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1542  }
1543 
1544  if (p)
1545  devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1546  else
1547  devconf = &dm->conf->default_devconf;
1548 
1549  if (devconf->hqos_enabled == 0)
1550  {
1551  vlib_cli_output (vm, "HQoS disabled for this interface");
1552  goto done;
1553  }
1554 
1555  /* Detect the set of worker threads */
1556  p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1557 
1558  /* Should never happen, shut up Coverity warning */
1559  if (p == 0)
1560  {
1561  error = clib_error_return (0, "no worker registrations?");
1562  goto done;
1563  }
1564 
1565  tr = (vlib_thread_registration_t *) p[0];
1566 
1567  cfg = &devconf->hqos;
1568  ht = xd->hqos_ht;
1569  wk = &xd->hqos_wt[tr->first_index];
1570  tctbl = wk->hqos_tc_table;
1571 
1572  vlib_cli_output (vm, " Thread:");
1573  vlib_cli_output (vm, " Input SWQ size = %u packets", cfg->swq_size);
1574  vlib_cli_output (vm, " Enqueue burst size = %u packets",
1575  ht->hqos_burst_enq);
1576  vlib_cli_output (vm, " Dequeue burst size = %u packets",
1577  ht->hqos_burst_deq);
1578 
1579  vlib_cli_output (vm,
1580  " Packet field 0: slab position = %4u, slab bitmask = 0x%016llx (subport)",
1582  vlib_cli_output (vm,
1583  " Packet field 1: slab position = %4u, slab bitmask = 0x%016llx (pipe)",
1585  vlib_cli_output (vm,
1586  " Packet field 2: slab position = %4u, slab bitmask = 0x%016llx (tc)",
1588  vlib_cli_output (vm,
1589  " Packet field 2 tc translation table: ([Mapped Value Range]: tc/queue tc/queue ...)");
1590  vlib_cli_output (vm,
1591  " [ 0 .. 15]: "
1592  "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1593  tctbl[0] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1594  tctbl[0] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1595  tctbl[1] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1596  tctbl[1] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1597  tctbl[2] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1598  tctbl[2] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1599  tctbl[3] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1600  tctbl[3] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1601  tctbl[4] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1602  tctbl[4] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1603  tctbl[5] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1604  tctbl[5] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1605  tctbl[6] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1606  tctbl[6] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1607  tctbl[7] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1608  tctbl[7] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1609  tctbl[8] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1610  tctbl[8] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1611  tctbl[9] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1612  tctbl[9] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1613  tctbl[10] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1614  tctbl[10] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1615  tctbl[11] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1616  tctbl[11] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1617  tctbl[12] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1618  tctbl[12] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1619  tctbl[13] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1620  tctbl[13] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1621  tctbl[14] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1622  tctbl[14] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1623  tctbl[15] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1624  tctbl[15] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1625  vlib_cli_output (vm,
1626  " [16 .. 31]: "
1627  "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1628  tctbl[16] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1629  tctbl[16] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1630  tctbl[17] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1631  tctbl[17] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1632  tctbl[18] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1633  tctbl[18] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1634  tctbl[19] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1635  tctbl[19] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1636  tctbl[20] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1637  tctbl[20] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1638  tctbl[21] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1639  tctbl[21] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1640  tctbl[22] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1641  tctbl[22] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1642  tctbl[23] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1643  tctbl[23] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1644  tctbl[24] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1645  tctbl[24] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1646  tctbl[25] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1647  tctbl[25] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1648  tctbl[26] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1649  tctbl[26] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1650  tctbl[27] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1651  tctbl[27] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1652  tctbl[28] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1653  tctbl[28] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1654  tctbl[29] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1655  tctbl[29] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1656  tctbl[30] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1657  tctbl[30] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1658  tctbl[31] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1659  tctbl[31] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1660  vlib_cli_output (vm,
1661  " [32 .. 47]: "
1662  "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1663  tctbl[32] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1664  tctbl[32] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1665  tctbl[33] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1666  tctbl[33] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1667  tctbl[34] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1668  tctbl[34] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1669  tctbl[35] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1670  tctbl[35] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1671  tctbl[36] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1672  tctbl[36] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1673  tctbl[37] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1674  tctbl[37] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1675  tctbl[38] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1676  tctbl[38] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1677  tctbl[39] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1678  tctbl[39] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1679  tctbl[40] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1680  tctbl[40] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1681  tctbl[41] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1682  tctbl[41] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1683  tctbl[42] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1684  tctbl[42] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1685  tctbl[43] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1686  tctbl[43] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1687  tctbl[44] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1688  tctbl[44] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1689  tctbl[45] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1690  tctbl[45] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1691  tctbl[46] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1692  tctbl[46] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1693  tctbl[47] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1694  tctbl[47] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1695  vlib_cli_output (vm,
1696  " [48 .. 63]: "
1697  "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1698  tctbl[48] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1699  tctbl[48] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1700  tctbl[49] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1701  tctbl[49] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1702  tctbl[50] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1703  tctbl[50] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1704  tctbl[51] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1705  tctbl[51] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1706  tctbl[52] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1707  tctbl[52] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1708  tctbl[53] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1709  tctbl[53] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1710  tctbl[54] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1711  tctbl[54] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1712  tctbl[55] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1713  tctbl[55] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1714  tctbl[56] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1715  tctbl[56] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1716  tctbl[57] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1717  tctbl[57] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1718  tctbl[58] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1719  tctbl[58] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1720  tctbl[59] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1721  tctbl[59] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1722  tctbl[60] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1723  tctbl[60] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1724  tctbl[61] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1725  tctbl[61] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1726  tctbl[62] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1727  tctbl[62] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1728  tctbl[63] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1729  tctbl[63] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1730  vlib_cli_output (vm, " Port:");
1731  vlib_cli_output (vm, " Rate = %u bytes/second", cfg->port.rate);
1732  vlib_cli_output (vm, " MTU = %u bytes", cfg->port.mtu);
1733  vlib_cli_output (vm, " Frame overhead = %u bytes",
1734  cfg->port.frame_overhead);
1735  vlib_cli_output (vm, " Number of subports = %u",
1736  cfg->port.n_subports_per_port);
1737  vlib_cli_output (vm, " Number of pipes per subport = %u",
1738  cfg->port.n_pipes_per_subport);
1739  vlib_cli_output (vm,
1740  " Packet queue size: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u packets",
1741  cfg->port.qsize[0], cfg->port.qsize[1], cfg->port.qsize[2],
1742  cfg->port.qsize[3]);
1743  vlib_cli_output (vm, " Number of pipe profiles = %u",
1744  cfg->port.n_pipe_profiles);
1745 
1746  for (subport_id = 0; subport_id < vec_len (cfg->subport); subport_id++)
1747  {
1748  vlib_cli_output (vm, " Subport %u:", subport_id);
1749  vlib_cli_output (vm, " Rate = %u bytes/second",
1750  cfg->subport[subport_id].tb_rate);
1751  vlib_cli_output (vm, " Token bucket size = %u bytes",
1752  cfg->subport[subport_id].tb_size);
1753  vlib_cli_output (vm,
1754  " Traffic class rate: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u bytes/second",
1755  cfg->subport[subport_id].tc_rate[0],
1756  cfg->subport[subport_id].tc_rate[1],
1757  cfg->subport[subport_id].tc_rate[2],
1758  cfg->subport[subport_id].tc_rate[3]);
1759  vlib_cli_output (vm, " TC period = %u milliseconds",
1760  cfg->subport[subport_id].tc_period);
1761  }
1762 
1763  for (profile_id = 0; profile_id < vec_len (cfg->pipe); profile_id++)
1764  {
1765  vlib_cli_output (vm, " Pipe profile %u:", profile_id);
1766  vlib_cli_output (vm, " Rate = %u bytes/second",
1767  cfg->pipe[profile_id].tb_rate);
1768  vlib_cli_output (vm, " Token bucket size = %u bytes",
1769  cfg->pipe[profile_id].tb_size);
1770  vlib_cli_output (vm,
1771  " Traffic class rate: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u bytes/second",
1772  cfg->pipe[profile_id].tc_rate[0],
1773  cfg->pipe[profile_id].tc_rate[1],
1774  cfg->pipe[profile_id].tc_rate[2],
1775  cfg->pipe[profile_id].tc_rate[3]);
1776  vlib_cli_output (vm, " TC period = %u milliseconds",
1777  cfg->pipe[profile_id].tc_period);
1778 #ifdef RTE_SCHED_SUBPORT_TC_OV
1779  vlib_cli_output (vm, " TC3 oversubscription_weight = %u",
1780  cfg->pipe[profile_id].tc_ov_weight);
1781 #endif
1782 
1783  for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1784  {
1785  vlib_cli_output (vm,
1786  " TC%u WRR weights: Q0 = %u, Q1 = %u, Q2 = %u, Q3 = %u",
1787  i, cfg->pipe[profile_id].wrr_weights[i * 4],
1788  cfg->pipe[profile_id].wrr_weights[i * 4 + 1],
1789  cfg->pipe[profile_id].wrr_weights[i * 4 + 2],
1790  cfg->pipe[profile_id].wrr_weights[i * 4 + 3]);
1791  }
1792  }
1793 
1794 #ifdef RTE_SCHED_RED
1795  vlib_cli_output (vm, " Weighted Random Early Detection (WRED):");
1796  for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1797  {
1798  vlib_cli_output (vm, " TC%u min: G = %u, Y = %u, R = %u", i,
1799  cfg->port.red_params[i][e_RTE_METER_GREEN].min_th,
1800  cfg->port.red_params[i][e_RTE_METER_YELLOW].min_th,
1801  cfg->port.red_params[i][e_RTE_METER_RED].min_th);
1802 
1803  vlib_cli_output (vm, " TC%u max: G = %u, Y = %u, R = %u", i,
1804  cfg->port.red_params[i][e_RTE_METER_GREEN].max_th,
1805  cfg->port.red_params[i][e_RTE_METER_YELLOW].max_th,
1806  cfg->port.red_params[i][e_RTE_METER_RED].max_th);
1807 
1808  vlib_cli_output (vm,
1809  " TC%u inverted probability: G = %u, Y = %u, R = %u",
1810  i, cfg->port.red_params[i][e_RTE_METER_GREEN].maxp_inv,
1811  cfg->port.red_params[i][e_RTE_METER_YELLOW].maxp_inv,
1812  cfg->port.red_params[i][e_RTE_METER_RED].maxp_inv);
1813 
1814  vlib_cli_output (vm, " TC%u weight: R = %u, Y = %u, R = %u", i,
1815  cfg->port.red_params[i][e_RTE_METER_GREEN].wq_log2,
1816  cfg->port.red_params[i][e_RTE_METER_YELLOW].wq_log2,
1817  cfg->port.red_params[i][e_RTE_METER_RED].wq_log2);
1818  }
1819 #endif
1820 
1821 done:
1822  unformat_free (line_input);
1823 
1824  return error;
1825 }
1826 
1827 /*?
1828  * This command is used to display details of an output interface's HQoS
1829  * settings.
1830  *
1831  * @cliexpar
1832  * Example of how to display HQoS settings for an interfaces:
1833  * @cliexstart{show dpdk interface hqos GigabitEthernet0/8/0}
1834  * Thread:
1835  * Input SWQ size = 4096 packets
1836  * Enqueue burst size = 256 packets
1837  * Dequeue burst size = 220 packets
1838  * Packet field 0: slab position = 0, slab bitmask = 0x0000000000000000 (subport)
1839  * Packet field 1: slab position = 40, slab bitmask = 0x0000000fff000000 (pipe)
1840  * Packet field 2: slab position = 8, slab bitmask = 0x00000000000000fc (tc)
1841  * Packet field 2 tc translation table: ([Mapped Value Range]: tc/queue tc/queue ...)
1842  * [ 0 .. 15]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1843  * [16 .. 31]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1844  * [32 .. 47]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1845  * [48 .. 63]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1846  * Port:
1847  * Rate = 1250000000 bytes/second
1848  * MTU = 1514 bytes
1849  * Frame overhead = 24 bytes
1850  * Number of subports = 1
1851  * Number of pipes per subport = 4096
1852  * Packet queue size: TC0 = 64, TC1 = 64, TC2 = 64, TC3 = 64 packets
1853  * Number of pipe profiles = 2
1854  * Subport 0:
1855  * Rate = 1250000000 bytes/second
1856  * Token bucket size = 1000000 bytes
1857  * Traffic class rate: TC0 = 1250000000, TC1 = 1250000000, TC2 = 1250000000, TC3 = 1250000000 bytes/second
1858  * TC period = 10 milliseconds
1859  * Pipe profile 0:
1860  * Rate = 305175 bytes/second
1861  * Token bucket size = 1000000 bytes
1862  * Traffic class rate: TC0 = 305175, TC1 = 305175, TC2 = 305175, TC3 = 305175 bytes/second
1863  * TC period = 40 milliseconds
1864  * TC0 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1865  * TC1 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1866  * TC2 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1867  * TC3 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1868  * @cliexend
1869 ?*/
1870 /* *INDENT-OFF* */
1871 VLIB_CLI_COMMAND (cmd_show_dpdk_if_hqos, static) = {
1872  .path = "show dpdk interface hqos",
1873  .short_help = "show dpdk interface hqos <interface>",
1874  .function = show_dpdk_if_hqos,
1875 };
1876 
1877 /* *INDENT-ON* */
1878 
1879 static clib_error_t *
1881  vlib_cli_command_t * cmd)
1882 {
1883  unformat_input_t _line_input, *line_input = &_line_input;
1884  clib_error_t *error = NULL;
1885 #ifdef RTE_SCHED_COLLECT_STATS
1886  dpdk_main_t *dm = &dpdk_main;
1887  u32 hw_if_index = (u32) ~ 0;
1888  u32 subport = (u32) ~ 0;
1889  u32 pipe = (u32) ~ 0;
1890  u32 tc = (u32) ~ 0;
1891  u32 tc_q = (u32) ~ 0;
1892  vnet_hw_interface_t *hw;
1893  dpdk_device_t *xd;
1894  uword *p = 0;
1895  struct rte_eth_dev_info dev_info;
1896  dpdk_device_config_t *devconf = 0;
1897  u32 qindex;
1898  struct rte_sched_queue_stats stats;
1899  u16 qlen;
1900 
1901  if (!unformat_user (input, unformat_line_input, line_input))
1902  return 0;
1903 
1904  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1905  {
1906  if (unformat
1907  (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1908  &hw_if_index))
1909  ;
1910 
1911  else if (unformat (line_input, "subport %d", &subport))
1912  ;
1913 
1914  else if (unformat (line_input, "pipe %d", &pipe))
1915  ;
1916 
1917  else if (unformat (line_input, "tc %d", &tc))
1918  ;
1919 
1920  else if (unformat (line_input, "tc_q %d", &tc_q))
1921  ;
1922 
1923  else
1924  {
1925  error = clib_error_return (0, "parse error: '%U'",
1926  format_unformat_error, line_input);
1927  goto done;
1928  }
1929  }
1930 
1931  if (hw_if_index == (u32) ~ 0)
1932  {
1933  error = clib_error_return (0, "please specify interface name!!");
1934  goto done;
1935  }
1936 
1937  hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1938  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1939 
1940  rte_eth_dev_info_get (xd->device_index, &dev_info);
1941  if (dev_info.pci_dev)
1942  { /* bonded interface has no pci info */
1943  vlib_pci_addr_t pci_addr;
1944 
1945  pci_addr.domain = dev_info.pci_dev->addr.domain;
1946  pci_addr.bus = dev_info.pci_dev->addr.bus;
1947  pci_addr.slot = dev_info.pci_dev->addr.devid;
1948  pci_addr.function = dev_info.pci_dev->addr.function;
1949 
1950  p =
1951  hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1952  }
1953 
1954  if (p)
1955  devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1956  else
1957  devconf = &dm->conf->default_devconf;
1958 
1959  if (devconf->hqos_enabled == 0)
1960  {
1961  vlib_cli_output (vm, "HQoS disabled for this interface");
1962  goto done;
1963  }
1964 
1965  /*
1966  * Figure out which queue to query. cf rte_sched_port_qindex. (Not sure why
1967  * that method isn't made public by DPDK - how _should_ we get the queue ID?)
1968  */
1969  qindex = subport * devconf->hqos.port.n_pipes_per_subport + pipe;
1970  qindex = qindex * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE + tc;
1971  qindex = qindex * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + tc_q;
1972 
1973  if (rte_sched_queue_read_stats (xd->hqos_ht->hqos, qindex, &stats, &qlen) !=
1974  0)
1975  {
1976  error = clib_error_return (0, "failed to read stats");
1977  goto done;
1978  }
1979 
1980  vlib_cli_output (vm, "%=24s%=16s", "Stats Parameter", "Value");
1981  vlib_cli_output (vm, "%=24s%=16d", "Packets", stats.n_pkts);
1982  vlib_cli_output (vm, "%=24s%=16d", "Packets dropped", stats.n_pkts_dropped);
1983 #ifdef RTE_SCHED_RED
1984  vlib_cli_output (vm, "%=24s%=16d", "Packets dropped (RED)",
1985  stats.n_pkts_red_dropped);
1986 #endif
1987  vlib_cli_output (vm, "%=24s%=16d", "Bytes", stats.n_bytes);
1988  vlib_cli_output (vm, "%=24s%=16d", "Bytes dropped", stats.n_bytes_dropped);
1989 
1990 #else
1991 
1992  /* Get a line of input */
1993  if (!unformat_user (input, unformat_line_input, line_input))
1994  return 0;
1995 
1996  vlib_cli_output (vm, "RTE_SCHED_COLLECT_STATS disabled in DPDK");
1997  goto done;
1998 
1999 #endif
2000 
2001 done:
2002  unformat_free (line_input);
2003 
2004  return error;
2005 }
2006 
2007 /*?
2008  * This command is used to display statistics associated with a HQoS traffic class
2009  * queue.
2010  *
2011  * @note
2012  * Statistic collection by the scheduler is disabled by default in DPDK. In order to
2013  * turn it on, add the following line to '<em>../vpp/dpdk/Makefile</em>':
2014  * - <b>$(call set,RTE_SCHED_COLLECT_STATS,y)</b>
2015  *
2016  * @cliexpar
2017  * Example of how to display statistics of HQoS a HQoS traffic class queue:
2018  * @cliexstart{show dpdk hqos queue GigabitEthernet0/9/0 subport 0 pipe 3181 tc 0 tc_q 0}
2019  * Stats Parameter Value
2020  * Packets 140
2021  * Packets dropped 0
2022  * Bytes 8400
2023  * Bytes dropped 0
2024  * @cliexend
2025 ?*/
2026 /* *INDENT-OFF* */
2027 VLIB_CLI_COMMAND (cmd_show_dpdk_hqos_queue_stats, static) = {
2028  .path = "show dpdk hqos queue",
2029  .short_help = "show dpdk hqos queue <interface> subport <subport_id> pipe <pipe_id> tc <tc_id> tc_q <queue_id>",
2030  .function = show_dpdk_hqos_queue_stats,
2031 };
2032 /* *INDENT-ON* */
2033 
2034 static clib_error_t *
2036  unformat_input_t * input,
2037  vlib_cli_command_t * cmd)
2038 {
2039 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
2040  _("DPDK Version", "%s", rte_version ());
2041  _("DPDK EAL init args", "%s", dpdk_config_main.eal_init_args_str);
2042 #undef _
2043  return 0;
2044 }
2045 
2046 /*?
2047  * This command is used to display the current DPDK version and
2048  * the list of arguments passed to DPDK when started.
2049  *
2050  * @cliexpar
2051  * Example of how to display how many DPDK buffer test command has allcoated:
2052  * @cliexstart{show dpdk version}
2053  * DPDK Version: DPDK 16.11.0
2054  * DPDK EAL init args: -c 1 -n 4 --huge-dir /run/vpp/hugepages --file-prefix vpp -w 0000:00:08.0 -w 0000:00:09.0 --master-lcore 0 --socket-mem 256
2055  * @cliexend
2056 ?*/
2057 /* *INDENT-OFF* */
2058 VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
2059  .path = "show dpdk version",
2060  .short_help = "show dpdk version",
2061  .function = show_dpdk_version_command_fn,
2062 };
2063 /* *INDENT-ON* */
2064 
2065 clib_error_t *
2067 {
2068  return 0;
2069 }
2070 
2072 
2073 /*
2074  * fd.io coding-style-patch-verification: ON
2075  *
2076  * Local Variables:
2077  * eval: (c-set-style "gnu")
2078  * End:
2079  */
unformat_function_t unformat_vnet_hw_interface
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
vmrglw vmrglh hi
char * file_name
File name of pcap output.
Definition: pcap.h:124
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
u8 * eal_init_args_str
Definition: dpdk.h:322
static clib_error_t * set_dpdk_if_hqos_placement(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:818
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:290
u32 n_packets_to_capture
Number of packets to capture.
Definition: pcap.h:127
static clib_error_t * set_dpdk_if_desc(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:476
dpdk_main_t dpdk_main
Definition: dpdk.h:422
int dpdk_hqos_validate_mask(u64 mask, u32 n)
Definition: hqos.c:171
static clib_error_t * show_dpdk_if_hqos(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1484
#define NULL
Definition: clib.h:55
u16 flags
Definition: dpdk.h:194
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static clib_error_t * get_hqos(u32 hw_if_index, u32 subport_id, dpdk_device_t **xd, dpdk_device_config_t **devconf)
Definition: cli.c:38
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
dpdk_device_and_queue_t ** devices_by_hqos_cpu
Definition: dpdk.h:357
static clib_error_t * set_dpdk_if_hqos_pipe(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:923
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:561
struct rte_sched_port_params port
Definition: dpdk.h:278
static clib_error_t * show_dpdk_hqos_queue_stats(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1880
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:982
struct rte_sched_port * hqos
Definition: dpdk.h:162
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static clib_error_t * pcap_trace_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:87
unformat_function_t unformat_vnet_sw_interface
dpdk_device_config_hqos_t hqos
Definition: dpdk.h:314
u8 * pcap_filename
Definition: dpdk.h:377
vlib_main_t ** vlib_mains
Definition: buffer.c:285
format_function_t format_vnet_sw_if_index_name
#define DPDK_DEVICE_FLAG_PMD
Definition: dpdk.h:197
clib_error_t * dpdk_port_setup(dpdk_main_t *dm, dpdk_device_t *xd)
Definition: init.c:322
static clib_error_t * show_dpdk_buffer(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:342
struct rte_sched_pipe_params * pipe
Definition: dpdk.h:280
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
dpdk_config_main_t dpdk_config_main
Definition: dpdk.h:349
vlib_node_registration_t dpdk_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_input_node)
Definition: node.c:655
dpdk_device_config_t default_devconf
Definition: dpdk.h:343
u32 pcap_pkts_to_capture
Definition: dpdk.h:379
int input_cpu_first_index
Definition: dpdk.h:396
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:111
unsigned long u64
Definition: types.h:89
u32 device_index
Definition: dpdk.h:176
static clib_error_t * test_dpdk_buffer(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:388
static clib_error_t * show_dpdk_if_placement(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:567
dpdk_device_hqos_per_worker_thread_t * hqos_wt
Definition: dpdk.h:220
unformat_function_t unformat_line_input
Definition: format.h:281
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
u32 pcap_sw_if_index
Definition: dpdk.h:378
char * name
Definition: main.h:98
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
#define hash_get(h, key)
Definition: hash.h:248
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
dpdk_device_and_queue_t ** devices_by_cpu
Definition: dpdk.h:356
u32 vlib_hw_if_index
Definition: dpdk.h:178
pcap_main_t pcap_main
Definition: dpdk.h:376
struct _unformat_input_t unformat_input_t
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:805
int input_cpu_count
Definition: dpdk.h:397
u16 nb_rx_desc
Definition: dpdk.h:214
static int dpdk_device_queue_sort(void *a1, void *a2)
Definition: cli.c:622
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
dpdk_device_t * devices
Definition: dpdk.h:355
vlib_main_t * vm
Definition: buffer.c:276
static clib_error_t * set_dpdk_if_hqos_tctbl(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1149
u16 * cpu_socket_id_by_queue
Definition: dpdk.h:215
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
dpdk_device_config_t * dev_confs
Definition: dpdk.h:344
clib_error_t * pcap_write(pcap_main_t *pm)
Write PCAP file.
Definition: pcap.c:89
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
int hqos_cpu_count
Definition: dpdk.h:401
struct rte_mempool ** pktmbuf_pools
Definition: dpdk.h:416
dpdk_device_hqos_per_hqos_thread_t * hqos_ht
Definition: dpdk.h:221
#define clib_error_report(e)
Definition: error.h:125
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
Definition: node_funcs.h:146
uword * thread_registrations_by_name
Definition: threads.h:276
clib_error_t * dpdk_cli_init(vlib_main_t *vm)
Definition: cli.c:2066
u64 uword
Definition: types.h:112
static clib_error_t * set_dpdk_if_hqos_subport(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1011
#define PCAP_DEF_PKT_TO_CAPTURE
template key/value backing page structure
Definition: bihash_doc.h:44
pcap_packet_type_t packet_type
Packet type.
Definition: pcap.h:130
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static clib_error_t * set_dpdk_if_hqos_pktfield(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:1264
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:960
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
#define hash_get_mem(h, key)
Definition: hash.h:268
struct clib_bihash_value offset
template key/value backing page structure
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
int hqos_cpu_first_index
Definition: dpdk.h:400
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
struct rte_sched_subport_params * subport
Definition: dpdk.h:279
#define vec_foreach(var, vec)
Vector iterator.
static clib_error_t * set_dpdk_if_placement(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:640
static clib_error_t * show_dpdk_version_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:2035
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:245
int tx_pcap_enable
Definition: dpdk.h:375
vnet_main_t * vnet_main
Definition: dpdk.h:412
u16 nb_tx_desc
Definition: dpdk.h:203
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:577
uword * device_config_index_by_pci_addr
Definition: dpdk.h:345
u32 n_packets_captured
Number of packets currently captured.
Definition: pcap.h:133
static clib_error_t * show_dpdk_if_hqos_placement(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:766
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:971
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
dpdk_config_main_t * conf
Definition: dpdk.h:413