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 <vnet/ethernet/ethernet.h>
25 
26 #include <marvell/pp2/pp2.h>
27 
28 static clib_error_t *
30  vlib_cli_command_t * cmd)
31 {
32  unformat_input_t _line_input, *line_input = &_line_input;
33  mrvl_pp2_create_if_args_t args = { 0 };
34 
35  /* Get a line of input. */
36  if (!unformat_user (input, unformat_line_input, line_input))
37  return 0;
38 
39  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
40  {
41  if (unformat (line_input, "name %s", &args.name))
42  ;
43  else
44  return clib_error_return (0, "unknown input `%U'",
45  format_unformat_error, input);
46  }
47  unformat_free (line_input);
48 
49 
50  mrvl_pp2_create_if (&args);
51 
52  vec_free (args.name);
53 
54  return args.error;
55 }
56 
57 /* *INDENT-OFF* */
58 VLIB_CLI_COMMAND (mrvl_pp2_create_command, static) = {
59  .path = "create interface marvell pp2",
60  .short_help = "create interface marvell pp2 [name <ifname>]",
61  .function = mrvl_pp2_create_command_fn,
62 };
63 /* *INDENT-ON* */
64 
65 static clib_error_t *
67  vlib_cli_command_t * cmd)
68 {
69  unformat_input_t _line_input, *line_input = &_line_input;
70  u32 sw_if_index = ~0;
73  mrvl_pp2_if_t *dif;
74  vnet_main_t *vnm = vnet_get_main ();
75 
76  /* Get a line of input. */
77  if (!unformat_user (input, unformat_line_input, line_input))
78  return 0;
79 
80  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
81  {
82  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
83  ;
84  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
85  vnm, &sw_if_index))
86  ;
87  else
88  return clib_error_return (0, "unknown input `%U'",
89  format_unformat_error, input);
90  }
91  unformat_free (line_input);
92 
93  if (sw_if_index == ~0)
94  return clib_error_return (0,
95  "please specify interface name or sw_if_index");
96 
97  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
98  if (hw == NULL || mrvl_pp2_device_class.index != hw->dev_class_index)
99  return clib_error_return (0, "not a Marvell PP2 interface");
100 
101  dif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
102 
103  mrvl_pp2_delete_if (dif);
104 
105  return 0;
106 }
107 
108 /* *INDENT-OFF* */
109 VLIB_CLI_COMMAND (mrvl_pp2_delete_command, static) = {
110  .path = "delete interface marvell pp2",
111  .short_help = "delete interface marvell pp2 "
112  "{<interface> | sw_if_index <sw_idx>}",
113  .function = mrvl_pp2_delete_command_fn,
114 };
115 /* *INDENT-ON* */
116 
117 clib_error_t *
119 {
120  /* initialize binary API */
122 
123  return 0;
124 }
125 
127 
128 /*
129  * fd.io coding-style-patch-verification: ON
130  *
131  * Local Variables:
132  * eval: (c-set-style "gnu")
133  * End:
134  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
clib_error_t * mrvl_pp2_cli_init(vlib_main_t *vm)
Definition: cli.c:118
mrvl_pp2_main_t mrvl_pp2_main
Definition: pp2.c:36
vnet_device_class_t mrvl_pp2_device_class
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
static clib_error_t * mrvl_pp2_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:29
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * mrvl_pp2_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:66
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#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 * mrvl_pp2_plugin_api_hookup(vlib_main_t *vm)
Definition: pp2_api.c:155
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
vlib_main_t * vm
Definition: buffer.c:323
#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 mrvl_pp2_delete_if(mrvl_pp2_if_t *ppif)
Definition: pp2.c:115
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
void mrvl_pp2_create_if(mrvl_pp2_create_if_args_t *args)
Definition: pp2.c:180
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
clib_error_t * error
Definition: pp2.h:98
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
mrvl_pp2_if_t * interfaces
Definition: pp2.h:79
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