2 * oddbuf.c - awkward chained buffer geometry test tool
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <oddbuf/oddbuf.h>
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
27 /* define message IDs */
28 #include <oddbuf/oddbuf.api_enum.h>
29 #include <oddbuf/oddbuf.api_types.h>
31 #define REPLY_MSG_ID_BASE omp->msg_id_base
32 #include <vlibapi/api_helper_macros.h>
34 oddbuf_main_t oddbuf_main;
36 /* Action function shared between message handler and debug CLI */
39 oddbuf_enable_disable (oddbuf_main_t * omp, u32 sw_if_index,
42 vnet_sw_interface_t *sw;
46 if (pool_is_free_index (omp->vnet_main->interface_main.sw_interfaces,
48 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
50 /* Not a physical port? */
51 sw = vnet_get_sw_interface (omp->vnet_main, sw_if_index);
52 if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
53 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
55 vnet_feature_enable_disable ("device-input", "oddbuf",
56 sw_if_index, enable_disable, 0, 0);
62 oddbuf_enable_disable_command_fn (vlib_main_t * vm,
63 unformat_input_t * input,
64 vlib_cli_command_t * cmd)
66 oddbuf_main_t *omp = &oddbuf_main;
68 int enable_disable = 1;
72 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
74 if (unformat (input, "disable"))
76 else if (unformat (input, "%U", unformat_vnet_sw_interface,
77 omp->vnet_main, &sw_if_index))
83 if (sw_if_index == ~0)
84 return clib_error_return (0, "Please specify an interface...");
86 rv = oddbuf_enable_disable (omp, sw_if_index, enable_disable);
93 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
94 return clib_error_return
95 (0, "Invalid interface, only works on physical ports");
98 case VNET_API_ERROR_UNIMPLEMENTED:
99 return clib_error_return (0,
100 "Device driver doesn't support redirection");
104 return clib_error_return (0, "oddbuf_enable_disable returned %d", rv);
110 VLIB_CLI_COMMAND (oddbuf_enable_disable_command, static) =
112 .path = "oddbuf enable-disable",
114 "oddbuf enable-disable <interface-name> [disable]",
115 .function = oddbuf_enable_disable_command_fn,
119 /* API message handler */
120 static void vl_api_oddbuf_enable_disable_t_handler
121 (vl_api_oddbuf_enable_disable_t * mp)
123 vl_api_oddbuf_enable_disable_reply_t *rmp;
124 oddbuf_main_t *omp = &oddbuf_main;
128 VALIDATE_SW_IF_INDEX (mp);
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));
133 BAD_SW_IF_INDEX_LABEL;
134 REPLY_MACRO (VL_API_ODDBUF_ENABLE_DISABLE_REPLY);
137 #include <oddbuf/oddbuf.api.c>
138 static clib_error_t *
139 oddbuf_init (vlib_main_t * vm)
141 oddbuf_main_t *om = &oddbuf_main;
142 clib_error_t *error = 0;
145 om->vnet_main = vnet_get_main ();
147 /* Ask for a correctly-sized block of API message decode slots */
148 om->msg_id_base = setup_message_id_table ();
152 om->second_chunk_offset = 1;
153 om->first_chunk_offset = 0;
158 VLIB_INIT_FUNCTION (oddbuf_init);
161 VNET_FEATURE_INIT (oddbuf, static) =
163 .arc_name = "device-input",
164 .node_name = "oddbuf",
165 .runs_before = VNET_FEATURES ("ethernet-input"),
170 VLIB_PLUGIN_REGISTER () =
172 .version = VPP_BUILD_VER,
173 .description = "Awkward chained buffer geometry generator",
174 .default_disabled = 1,
179 static clib_error_t *
180 oddbuf_config_command_fn (vlib_main_t * vm,
181 unformat_input_t * input, vlib_cli_command_t * cmd)
183 oddbuf_main_t *omp = &oddbuf_main;
184 unformat_input_t _line_input, *line_input = &_line_input;
186 /* Get a line of input. */
187 if (!unformat_user (input, unformat_line_input, line_input))
190 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
192 if (unformat (line_input, "n_to_copy %d", &omp->n_to_copy))
194 else if (unformat (line_input, "offset %d", &omp->second_chunk_offset))
196 else if (unformat (line_input, "first_offset %d",
197 &omp->first_chunk_offset))
203 unformat_free (line_input);
209 VLIB_CLI_COMMAND (oddbuf_config_command, static) =
211 .path = "oddbuf configure",
213 "oddbuf configure n_to_copy <nn> offset <nn> first_offset <nn>",
214 .function = oddbuf_config_command_fn,
221 * fd.io coding-style-patch-verification: ON
224 * eval: (c-set-style "gnu")