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_CROSS_CONNECT_ENABLE_DISABLE, nsim_cross_connect_enable_disable) \ 65 _(NSIM_OUTPUT_FEATURE_ENABLE_DISABLE, nsim_output_feature_enable_disable) \ 66 _(NSIM_CONFIGURE, nsim_configure) 72 u32 sw_if_index1,
int enable_disable)
79 return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
84 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
88 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
93 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
97 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
114 sw_if_index0, enable_disable, 0, 0);
116 sw_if_index1, enable_disable, 0, 0);
130 return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
135 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
140 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
152 sw_if_index, enable_disable, 0, 0);
160 u64 total_buffer_size_in_bytes, per_worker_buffer_size;
161 u64 wheel_slots_per_worker;
164 u32 pagesize = getpagesize ();
167 if (bandwidth == 0.0)
168 return VNET_API_ERROR_INVALID_VALUE;
171 return VNET_API_ERROR_INVALID_VALUE_2;
173 if (packet_size < 64.0 || packet_size > 9000.0)
174 return VNET_API_ERROR_INVALID_VALUE_3;
191 total_buffer_size_in_bytes = ((delay * bandwidth) / 8.0) + 0.5;
198 per_worker_buffer_size = total_buffer_size_in_bytes / num_workers;
200 per_worker_buffer_size = total_buffer_size_in_bytes;
202 wheel_slots_per_worker = per_worker_buffer_size / packet_size;
203 wheel_slots_per_worker++;
213 for (; i < num_workers + 1; i++)
229 wp->
entries = (
void *) (wp + 1);
237 for (; i < num_workers + 1; i++)
242 VLIB_NODE_STATE_POLLING);
261 u32 sw_if_index0 = ~0;
262 u32 sw_if_index1 = ~0;
263 int enable_disable = 1;
273 if (
unformat (line_input,
"disable"))
278 if (sw_if_index0 == ~0)
289 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
293 sw_if_index1, enable_disable);
300 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
303 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
305 (0,
"Invalid interface, only works on physical ports");
308 case VNET_API_ERROR_UNIMPLEMENTED:
310 "Device driver doesn't support redirection");
326 if (
unformat (input,
"poll-main-thread"))
360 .path =
"nsim cross-connect enable-disable",
362 "nsim cross-connect enable-disable <interface-name-1> " 363 "<interface-name-2> [disable]",
372 vl_api_nsim_cross_connect_enable_disable_reply_t *rmp;
375 u32 sw_if_index0, sw_if_index1;
382 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
383 goto bad_sw_if_index;
387 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
388 goto bad_sw_if_index;
395 REPLY_MACRO (VL_API_NSIM_CROSS_CONNECT_ENABLE_DISABLE_REPLY);
402 vl_api_nsim_output_feature_enable_disable_reply_t *rmp;
411 REPLY_MACRO (VL_API_NSIM_OUTPUT_FEATURE_ENABLE_DISABLE_REPLY);
418 vl_api_nsim_configure_reply_t *rmp;
420 f64 delay, bandwidth, packet_size, drop_fraction;
421 u32 packets_per_drop;
429 if (packets_per_drop > 0)
430 drop_fraction = 1.0 / (
f64) (packets_per_drop);
434 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
451 int enable_disable = 1;
460 if (
unformat (line_input,
"disable"))
477 if (sw_if_index == ~0)
487 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
490 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
492 (0,
"Invalid interface, only works on physical ports");
495 case VNET_API_ERROR_UNIMPLEMENTED:
497 "Device driver doesn't support redirection");
502 (0,
"nsim_output_feature_enable_disable returned %d", rv);
523 .path =
"nsim output-feature enable-disable",
525 "nsim output-feature enable-disable <interface-name> [disable]",
536 vl_msg_api_set_handlers((VL_API_##N + nsm->msg_id_base), \ 538 vl_api_##n##_t_handler, \ 540 vl_api_##n##_t_endian, \ 541 vl_api_##n##_t_print, \ 542 sizeof(vl_api_##n##_t), 1); 549 #define vl_msg_name_crc_list 551 #undef vl_msg_name_crc_list 556 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nsm->msg_id_base); 557 foreach_vl_msg_name_crc_nsim;
571 name =
format (0,
"nsim_%08x%c", api_version, 0);
592 .arc_name =
"device-input",
601 .arc_name =
"interface-output",
602 .node_name =
"nsim-output-feature",
610 .version = VPP_BUILD_VER,
611 .description =
"Network Delay Simulator",
618 f64 *result = va_arg (*args,
f64 *);
621 if (
unformat (input,
"%f us", &tmp))
622 *result = tmp * 1e-6;
623 else if (
unformat (input,
"%f ms", &tmp))
624 *result = tmp * 1e-3;
625 else if (
unformat (input,
"%f sec", &tmp))
636 f64 *result = va_arg (*args,
f64 *);
639 if (
unformat (input,
"%f gbit", &tmp))
641 else if (
unformat (input,
"%f gbyte", &tmp))
653 f64 delay, bandwidth;
654 f64 packet_size = 1500.0;
655 f64 drop_fraction = 0.0;
656 u32 packets_per_drop;
667 else if (
unformat (input,
"packet-size %f", &packet_size))
669 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
671 if (packets_per_drop > 0)
672 drop_fraction = 1.0 / ((
f64) packets_per_drop);
674 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
676 if (drop_fraction < 0.0 || drop_fraction > 1.0)
678 (0,
"drop fraction must be between zero and 1");
680 else if (
unformat (input,
"poll-main-thread"))
686 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
690 case VNET_API_ERROR_INVALID_VALUE:
693 case VNET_API_ERROR_INVALID_VALUE_2:
696 case VNET_API_ERROR_INVALID_VALUE_3:
706 vlib_cli_output (vm,
"Configured link delay %.2f ms, %.2f ms round-trip",
714 vlib_cli_output (vm,
"Sim uses %llu bytes per thread, %llu bytes total",
742 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n" 743 " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
773 "...inserting link delay of %.2f ms, %.2f ms round-trip",
788 (vm,
" Sim uses %llu bytes per thread, %llu bytes total",
817 .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) ...
u32 * output_next_index_by_sw_if_index
static clib_error_t * nsim_init(vlib_main_t *vm)
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)
enable / disable the network delay simulation cross-connect
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface
int nsim_cross_connect_enable_disable(nsim_main_t *nsm, u32 sw_if_index0, u32 sw_if_index1, int enable_disable)
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)
enable / disable the network delay simulation output feature
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
static void vl_api_nsim_output_feature_enable_disable_t_handler(vl_api_nsim_output_feature_enable_disable_t *mp)
#define clib_error_return(e, args...)
static uword unformat_delay(unformat_input_t *input, va_list *args)
#define VLIB_CONFIG_FUNCTION(x, n,...)
static void vl_api_nsim_cross_connect_enable_disable_t_handler(vl_api_nsim_cross_connect_enable_disable_t *mp)
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.
#define BAD_SW_IF_INDEX_LABEL
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
static void vl_api_nsim_configure_t_handler(vl_api_nsim_configure_t *mp)
static clib_error_t * nsim_output_feature_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nsim_config(vlib_main_t *vm, unformat_input_t *input)
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,...)
static clib_error_t * nsim_cross_connect_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int nsim_output_feature_enable_disable(nsim_main_t *nsm, u32 sw_if_index, int enable_disable)
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.
#define VNET_FEATURES(...)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_sw_interface_t * sw_interfaces
static uword unformat_bandwidth(unformat_input_t *input, va_list *args)
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)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
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)
#define VALIDATE_SW_IF_INDEX(mp)
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)