FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
oddbuf.c
Go to the documentation of this file.
1 /*
2  * oddbuf.c - awkward chained buffer geometry test tool
3  *
4  * Copyright (c) 2019 by Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <oddbuf/oddbuf.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25 #include <stdbool.h>
26 
27 /* define message IDs */
28 #include <oddbuf/oddbuf.api_enum.h>
29 #include <oddbuf/oddbuf.api_types.h>
30 
31 #define REPLY_MSG_ID_BASE omp->msg_id_base
33 
35 
36 /* Action function shared between message handler and debug CLI */
37 
38 int
40  int enable_disable)
41 {
43  int rv = 0;
44 
45  /* Utterly wrong? */
47  sw_if_index))
48  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
49 
50  /* Not a physical port? */
53  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
54 
55  vnet_feature_enable_disable ("device-input", "oddbuf",
56  sw_if_index, enable_disable, 0, 0);
57 
58  return rv;
59 }
60 
61 static clib_error_t *
63  unformat_input_t * input,
64  vlib_cli_command_t * cmd)
65 {
66  oddbuf_main_t *omp = &oddbuf_main;
67  u32 sw_if_index = ~0;
68  int enable_disable = 1;
69 
70  int rv;
71 
73  {
74  if (unformat (input, "disable"))
75  enable_disable = 0;
76  else if (unformat (input, "%U", unformat_vnet_sw_interface,
77  omp->vnet_main, &sw_if_index))
78  ;
79  else
80  break;
81  }
82 
83  if (sw_if_index == ~0)
84  return clib_error_return (0, "Please specify an interface...");
85 
86  rv = oddbuf_enable_disable (omp, sw_if_index, enable_disable);
87 
88  switch (rv)
89  {
90  case 0:
91  break;
92 
93  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
94  return clib_error_return
95  (0, "Invalid interface, only works on physical ports");
96  break;
97 
98  case VNET_API_ERROR_UNIMPLEMENTED:
99  return clib_error_return (0,
100  "Device driver doesn't support redirection");
101  break;
102 
103  default:
104  return clib_error_return (0, "oddbuf_enable_disable returned %d", rv);
105  }
106  return 0;
107 }
108 
109 /* *INDENT-OFF* */
111 {
112  .path = "oddbuf enable-disable",
113  .short_help =
114  "oddbuf enable-disable <interface-name> [disable]",
116 };
117 /* *INDENT-ON* */
118 
119 /* API message handler */
122 {
123  vl_api_oddbuf_enable_disable_reply_t *rmp;
124  oddbuf_main_t *omp = &oddbuf_main;
126  int rv;
127 
129 
130  sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
131  rv = oddbuf_enable_disable (omp, sw_if_index, (int) (mp->enable_disable));
132 
134  REPLY_MACRO (VL_API_ODDBUF_ENABLE_DISABLE_REPLY);
135 }
136 
137 #include <oddbuf/oddbuf.api.c>
138 static clib_error_t *
140 {
141  oddbuf_main_t *om = &oddbuf_main;
142  clib_error_t *error = 0;
143 
144  om->vlib_main = vm;
145  om->vnet_main = vnet_get_main ();
146 
147  /* Ask for a correctly-sized block of API message decode slots */
149 
150  /* Basic setup */
151  om->n_to_copy = 1;
152  om->second_chunk_offset = 1;
153  om->first_chunk_offset = 0;
154 
155  return error;
156 }
157 
159 
160 /* *INDENT-OFF* */
161 VNET_FEATURE_INIT (oddbuf, static) =
162 {
163  .arc_name = "device-input",
164  .node_name = "oddbuf",
165  .runs_before = VNET_FEATURES ("ethernet-input"),
166 };
167 /* *INDENT-ON */
168 
169 /* *INDENT-OFF* */
171 {
172  .version = VPP_BUILD_VER,
173  .description = "Awkward chained buffer geometry generator",
174  .default_disabled = 1,
175 };
176 /* *INDENT-ON* */
177 
178 
179 static clib_error_t *
181  unformat_input_t * input, vlib_cli_command_t * cmd)
182 {
183  oddbuf_main_t *omp = &oddbuf_main;
184  unformat_input_t _line_input, *line_input = &_line_input;
185 
186  /* Get a line of input. */
187  if (!unformat_user (input, unformat_line_input, line_input))
188  return 0;
189 
190  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
191  {
192  if (unformat (line_input, "n_to_copy %d", &omp->n_to_copy))
193  ;
194  else if (unformat (line_input, "offset %d", &omp->second_chunk_offset))
195  ;
196  else if (unformat (line_input, "first_offset %d",
197  &omp->first_chunk_offset))
198  ;
199  else
200  break;
201  }
202 
203  unformat_free (line_input);
204 
205  return 0;
206 }
207 
208 /* *INDENT-OFF* */
210 {
211  .path = "oddbuf configure",
212  .short_help =
213  "oddbuf configure n_to_copy <nn> offset <nn> first_offset <nn>",
214  .function = oddbuf_config_command_fn,
215 };
216 /* *INDENT-ON* */
217 
218 
219 
220 /*
221  * fd.io coding-style-patch-verification: ON
222  *
223  * Local Variables:
224  * eval: (c-set-style "gnu")
225  * End:
226  */
oddbuf_main_t
Definition: oddbuf.h:28
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
oddbuf_main_t::vnet_main
vnet_main_t * vnet_main
Definition: oddbuf.h:43
vnet_sw_interface_t
Definition: interface.h:869
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
oddbuf_main_t::vlib_main
vlib_main_t * vlib_main
Definition: oddbuf.h:42
oddbuf_main_t::second_chunk_offset
int second_chunk_offset
Definition: oddbuf.h:38
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vl_api_oddbuf_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: oddbuf.api:50
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
unformat_input_t
struct _unformat_input_t unformat_input_t
oddbuf.h
error
Definition: cJSON.c:88
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vl_api_oddbuf_enable_disable_t_handler
static void vl_api_oddbuf_enable_disable_t_handler(vl_api_oddbuf_enable_disable_t *mp)
Definition: oddbuf.c:121
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
oddbuf_enable_disable_command
static vlib_cli_command_t oddbuf_enable_disable_command
(constructor) VLIB_CLI_COMMAND (oddbuf_enable_disable_command)
Definition: oddbuf.c:110
oddbuf_config_command_fn
static clib_error_t * oddbuf_config_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: oddbuf.c:180
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
oddbuf_enable_disable_command_fn
static clib_error_t * oddbuf_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: oddbuf.c:62
vnet_interface_main_t::sw_interfaces
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:1015
oddbuf_main_t::msg_id_base
u16 msg_id_base
Definition: oddbuf.h:31
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
oddbuf_config_command
static vlib_cli_command_t oddbuf_config_command
(constructor) VLIB_CLI_COMMAND (oddbuf_config_command)
Definition: oddbuf.c:209
oddbuf_main_t::first_chunk_offset
int first_chunk_offset
Definition: oddbuf.h:39
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
vl_api_oddbuf_enable_disable_t::enable_disable
bool enable_disable
Definition: oddbuf.api:47
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
api_helper_macros.h
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
vlib_main_t
Definition: main.h:102
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
oddbuf_main
oddbuf_main_t oddbuf_main
Definition: oddbuf.c:34
rv
int __clib_unused rv
Definition: application.c:491
vl_api_oddbuf_enable_disable_t
API to enable / disable oddbuf on an interface.
Definition: oddbuf.api:39
vnet.h
VNET_SW_INTERFACE_TYPE_HARDWARE
@ VNET_SW_INTERFACE_TYPE_HARDWARE
Definition: interface.h:764
oddbuf_enable_disable
int oddbuf_enable_disable(oddbuf_main_t *omp, u32 sw_if_index, int enable_disable)
Definition: oddbuf.c:39
vlib_cli_command_t
Definition: cli.h:92
oddbuf_main_t::n_to_copy
int n_to_copy
Definition: oddbuf.h:37
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
oddbuf_init
static clib_error_t * oddbuf_init(vlib_main_t *vm)
Definition: oddbuf.c:139
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
VNET_FEATURE_INIT
VNET_FEATURE_INIT(oddbuf, static)
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137