FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
26 
27 #include <rdma/rdma.h>
28 
29 static clib_error_t *
31  vlib_cli_command_t * cmd)
32 {
33  unformat_input_t _line_input, *line_input = &_line_input;
35 
36  /* Get a line of input. */
37  if (!unformat_user (input, unformat_line_input, line_input))
38  return 0;
39 
40  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
41 
42  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
43  {
44  if (unformat (line_input, "host-if %s", &args.ifname))
45  ;
46  else if (unformat (line_input, "name %s", &args.name))
47  ;
48  else if (unformat (line_input, "rx-queue-size %u", &args.rxq_size))
49  ;
50  else if (unformat (line_input, "tx-queue-size %u", &args.txq_size))
51  ;
52  else if (unformat (line_input, "num-rx-queues %u", &args.rxq_num))
53  ;
54  else
55  return clib_error_return (0, "unknown input `%U'",
56  format_unformat_error, input);
57  }
58  unformat_free (line_input);
59 
60  rdma_create_if (vm, &args);
61 
62  vec_free (args.ifname);
63  vec_free (args.name);
64 
65  return args.error;
66 }
67 
68 /* *INDENT-OFF* */
69 VLIB_CLI_COMMAND (rdma_create_command, static) = {
70  .path = "create interface rdma",
71  .short_help = "create interface rdma <host-if ifname> [name <name>]"
72  " [rx-queue-size <size>] [tx-queue-size <size>]"
73  " [num-rx-queues <size>]",
74  .function = rdma_create_command_fn,
75 };
76 /* *INDENT-ON* */
77 
78 static clib_error_t *
80  vlib_cli_command_t * cmd)
81 {
82  unformat_input_t _line_input, *line_input = &_line_input;
83  u32 sw_if_index = ~0;
85  rdma_main_t *rm = &rdma_main;
86  rdma_device_t *rd;
87  vnet_main_t *vnm = vnet_get_main ();
88 
89  /* Get a line of input. */
90  if (!unformat_user (input, unformat_line_input, line_input))
91  return 0;
92 
93  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
94  {
95  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
96  ;
97  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
98  vnm, &sw_if_index))
99  ;
100  else
101  return clib_error_return (0, "unknown input `%U'",
102  format_unformat_error, input);
103  }
104  unformat_free (line_input);
105 
106  if (sw_if_index == ~0)
107  return clib_error_return (0,
108  "please specify interface name or sw_if_index");
109 
110  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
111  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
112  return clib_error_return (0, "not a RDMA interface");
113 
114  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
115 
116  rdma_delete_if (vm, rd);
117 
118  return 0;
119 }
120 
121 /* *INDENT-OFF* */
122 VLIB_CLI_COMMAND (rdma_delete_command, static) = {
123  .path = "delete interface rdma",
124  .short_help = "delete interface rdma "
125  "{<interface> | sw_if_index <sw_idx>}",
126  .function = rdma_delete_command_fn,
127 };
128 /* *INDENT-ON* */
129 
130 clib_error_t *
132 {
133  return 0;
134 }
135 
137 
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * rdma_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:79
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static clib_error_t * rdma_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:30
rdma_device_t * devices
Definition: rdma.h:95
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_line_input
Definition: format.h:283
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
struct _unformat_input_t unformat_input_t
clib_error_t * rdma_cli_init(vlib_main_t *vm)
Definition: cli.c:131
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
rdma_main_t rdma_main
Definition: device.c:46
vlib_main_t * vm
Definition: buffer.c:323
clib_error_t * error
Definition: rdma.h:112
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
void rdma_create_if(vlib_main_t *vm, rdma_create_if_args_t *args)
Definition: device.c:580
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
vnet_device_class_t rdma_device_class
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
void rdma_delete_if(vlib_main_t *vm, rdma_device_t *rd)
Definition: device.c:717
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171