30 #include <vpp/app/version.h> 46 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 52 #define vl_api_version(n,v) static u32 api_version=(v); 56 #define REPLY_MSG_ID_BASE nsm->msg_id_base 63 #define foreach_nsim_plugin_api_msg \ 64 _(NSIM_ENABLE_DISABLE, nsim_enable_disable) \ 65 _(NSIM_CONFIGURE, nsim_configure) 71 u32 sw_if_index1,
int enable_disable)
78 return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
83 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
87 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
92 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
96 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
113 sw_if_index0, enable_disable, 0, 0);
115 sw_if_index1, enable_disable, 0, 0);
124 u64 total_buffer_size_in_bytes, per_worker_buffer_size;
125 u64 wheel_slots_per_worker;
128 u32 pagesize = getpagesize ();
131 if (bandwidth == 0.0)
132 return VNET_API_ERROR_INVALID_VALUE;
135 return VNET_API_ERROR_INVALID_VALUE_2;
138 return VNET_API_ERROR_INVALID_VALUE_3;
155 total_buffer_size_in_bytes = (
u32) ((delay * bandwidth) / 8.0) + 0.5;
162 per_worker_buffer_size = total_buffer_size_in_bytes / num_workers;
164 per_worker_buffer_size = total_buffer_size_in_bytes;
166 wheel_slots_per_worker = per_worker_buffer_size / packet_size;
167 wheel_slots_per_worker++;
177 for (i = num_workers ? 1 : 0; i < num_workers + 1; i++)
193 wp->
entries = (
void *) (wp + 1);
202 for (i = num_workers ? 1 : 0; i < num_workers + 1; i++)
207 VLIB_NODE_STATE_POLLING);
225 u32 sw_if_index0 = ~0;
226 u32 sw_if_index1 = ~0;
227 int enable_disable = 1;
238 if (sw_if_index0 == ~0)
247 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
257 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
260 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
262 (0,
"Invalid interface, only works on physical ports");
265 case VNET_API_ERROR_UNIMPLEMENTED:
267 "Device driver doesn't support redirection");
295 .path =
"nsim enable-disable",
297 "nsim enable-disable <interface-name-1> <interface-name-2> [disable]",
306 vl_api_nsim_enable_disable_reply_t *rmp;
321 vl_api_nsim_configure_reply_t *rmp;
323 f64 delay, bandwidth, packet_size, drop_fraction;
324 u32 packets_per_drop;
332 if (packets_per_drop > 0)
333 drop_fraction = 1.0 / (
f64) (packets_per_drop);
337 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
349 vl_msg_api_set_handlers((VL_API_##N + nsm->msg_id_base), \ 351 vl_api_##n##_t_handler, \ 353 vl_api_##n##_t_endian, \ 354 vl_api_##n##_t_print, \ 355 sizeof(vl_api_##n##_t), 1); 362 #define vl_msg_name_crc_list 364 #undef vl_msg_name_crc_list 369 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nsm->msg_id_base); 370 foreach_vl_msg_name_crc_nsim;
384 name =
format (0,
"nsim_%08x%c", api_version, 0);
405 .arc_name =
"device-input",
414 .version = VPP_BUILD_VER,
415 .description =
"network delay simulator plugin",
422 f64 *result = va_arg (*args,
f64 *);
425 if (
unformat (input,
"%f us", &tmp))
426 *result = tmp * 1e-6;
427 else if (
unformat (input,
"%f ms", &tmp))
428 *result = tmp * 1e-3;
429 else if (
unformat (input,
"%f sec", &tmp))
440 f64 *result = va_arg (*args,
f64 *);
443 if (
unformat (input,
"%f gbit", &tmp))
445 else if (
unformat (input,
"%f gbyte", &tmp))
457 f64 delay, bandwidth;
458 f64 packet_size = 1500.0;
459 f64 drop_fraction = 0.0;
460 u32 packets_per_drop;
471 else if (
unformat (input,
"packet-size %f", &packet_size))
473 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
475 if (packets_per_drop > 0)
476 drop_fraction = 1.0 / ((
f64) packets_per_drop);
478 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
480 if (drop_fraction < 0.0 || drop_fraction > 1.0)
482 (0,
"drop fraction must be between zero and 1");
488 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
492 case VNET_API_ERROR_INVALID_VALUE:
495 case VNET_API_ERROR_INVALID_VALUE_2:
498 case VNET_API_ERROR_INVALID_VALUE_3:
508 vlib_cli_output (vm,
"Configured link delay %.2f ms, %.2f ms round-trip",
516 vlib_cli_output (vm,
"Sim uses %llu bytes per thread, %llu bytes total",
544 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>",
574 "...inserting link delay of %.2f ms, %.2f ms round-trip",
589 (vm,
" Sim uses %llu bytes per thread, %llu bytes total",
618 .short_help =
"Display network delay simulator configuration",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static clib_error_t * nsim_init(vlib_main_t *vm)
#define WHEEL_ENTRY_DATA_SIZE
vnet_main_t * vnet_get_main(void)
vnet_interface_main_t interface_main
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface
vlib_main_t ** vlib_mains
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
#define vlib_worker_thread_barrier_sync(X)
#define VLIB_INIT_FUNCTION(x)
#define clib_error_return(e, args...)
static uword unformat_delay(unformat_input_t *input, va_list *args)
static int nsim_configure(nsim_main_t *nsm, f64 bandwidth, f64 delay, f64 packet_size, f64 drop_fraction)
VNET_FEATURE_INIT(nsim, static)
API main structure, used by both vpp and binary API clients.
int nsim_enable_disable(nsim_main_t *nsm, u32 sw_if_index0, u32 sw_if_index1, int enable_disable)
static void vl_api_nsim_configure_t_handler(vl_api_nsim_configure_t *mp)
vlib_node_registration_t nsim_input_node
(constructor) VLIB_REGISTER_NODE (nsim_input_node)
#define vec_free(V)
Free vector's memory (no header).
nsim_wheel_entry_t * entries
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#define foreach_nsim_plugin_api_msg
#define VLIB_CLI_COMMAND(x,...)
nsim_wheel_t ** wheel_by_thread
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
enable / disable the network delay simulation cross-connect
#define VNET_FEATURES(...)
static void vl_api_nsim_enable_disable_t_handler(vl_api_nsim_enable_disable_t *mp)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_sw_interface_t * sw_interfaces
u32 ** buffer_indices_by_thread
static uword unformat_bandwidth(unformat_input_t *input, va_list *args)
static clib_error_t * nsim_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
vnet_sw_interface_type_t type
static u32 vlib_num_workers()
static clib_error_t * show_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void * clib_mem_vm_alloc(uword size)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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)
static clib_error_t * set_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u16 vl_msg_api_get_msg_ids(const char *name, int n)
static void setup_message_id_table(nsim_main_t *nsm, api_main_t *am)
static clib_error_t * nsim_plugin_api_hookup(vlib_main_t *vm)