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++;
212 for (i = num_workers ? 1 : 0; i < num_workers + 1; i++)
228 wp->
entries = (
void *) (wp + 1);
235 for (i = num_workers ? 1 : 0; i < num_workers + 1; i++)
240 VLIB_NODE_STATE_POLLING);
259 u32 sw_if_index0 = ~0;
260 u32 sw_if_index1 = ~0;
261 int enable_disable = 1;
271 if (
unformat (line_input,
"disable"))
276 if (sw_if_index0 == ~0)
287 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
291 sw_if_index1, enable_disable);
298 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
301 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
303 (0,
"Invalid interface, only works on physical ports");
306 case VNET_API_ERROR_UNIMPLEMENTED:
308 "Device driver doesn't support redirection");
336 .path =
"nsim cross-connect enable-disable",
338 "nsim cross-connect enable-disable <interface-name-1> " 339 "<interface-name-2> [disable]",
348 vl_api_nsim_cross_connect_enable_disable_reply_t *rmp;
351 u32 sw_if_index0, sw_if_index1;
358 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
359 goto bad_sw_if_index;
363 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
364 goto bad_sw_if_index;
371 REPLY_MACRO (VL_API_NSIM_CROSS_CONNECT_ENABLE_DISABLE_REPLY);
378 vl_api_nsim_output_feature_enable_disable_reply_t *rmp;
387 REPLY_MACRO (VL_API_NSIM_OUTPUT_FEATURE_ENABLE_DISABLE_REPLY);
394 vl_api_nsim_configure_reply_t *rmp;
396 f64 delay, bandwidth, packet_size, drop_fraction;
397 u32 packets_per_drop;
405 if (packets_per_drop > 0)
406 drop_fraction = 1.0 / (
f64) (packets_per_drop);
410 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
427 int enable_disable = 1;
436 if (
unformat (line_input,
"disable"))
453 if (sw_if_index == ~0)
463 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
466 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
468 (0,
"Invalid interface, only works on physical ports");
471 case VNET_API_ERROR_UNIMPLEMENTED:
473 "Device driver doesn't support redirection");
478 (0,
"nsim_output_feature_enable_disable returned %d", rv);
499 .path =
"nsim output-feature enable-disable",
501 "nsim output-feature enable-disable <interface-name> [disable]",
512 vl_msg_api_set_handlers((VL_API_##N + nsm->msg_id_base), \ 514 vl_api_##n##_t_handler, \ 516 vl_api_##n##_t_endian, \ 517 vl_api_##n##_t_print, \ 518 sizeof(vl_api_##n##_t), 1); 525 #define vl_msg_name_crc_list 527 #undef vl_msg_name_crc_list 532 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nsm->msg_id_base); 533 foreach_vl_msg_name_crc_nsim;
547 name =
format (0,
"nsim_%08x%c", api_version, 0);
568 .arc_name =
"device-input",
577 .arc_name =
"interface-output",
578 .node_name =
"nsim-output-feature",
586 .version = VPP_BUILD_VER,
587 .description =
"Network Delay Simulator",
594 f64 *result = va_arg (*args,
f64 *);
597 if (
unformat (input,
"%f us", &tmp))
598 *result = tmp * 1e-6;
599 else if (
unformat (input,
"%f ms", &tmp))
600 *result = tmp * 1e-3;
601 else if (
unformat (input,
"%f sec", &tmp))
612 f64 *result = va_arg (*args,
f64 *);
615 if (
unformat (input,
"%f gbit", &tmp))
617 else if (
unformat (input,
"%f gbyte", &tmp))
629 f64 delay, bandwidth;
630 f64 packet_size = 1500.0;
631 f64 drop_fraction = 0.0;
632 u32 packets_per_drop;
643 else if (
unformat (input,
"packet-size %f", &packet_size))
645 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
647 if (packets_per_drop > 0)
648 drop_fraction = 1.0 / ((
f64) packets_per_drop);
650 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
652 if (drop_fraction < 0.0 || drop_fraction > 1.0)
654 (0,
"drop fraction must be between zero and 1");
660 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
664 case VNET_API_ERROR_INVALID_VALUE:
667 case VNET_API_ERROR_INVALID_VALUE_2:
670 case VNET_API_ERROR_INVALID_VALUE_3:
680 vlib_cli_output (vm,
"Configured link delay %.2f ms, %.2f ms round-trip",
688 vlib_cli_output (vm,
"Sim uses %llu bytes per thread, %llu bytes total",
716 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n" 717 " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
747 "...inserting link delay of %.2f ms, %.2f ms round-trip",
762 (vm,
" Sim uses %llu bytes per thread, %llu bytes total",
791 .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)
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)
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)