30 #include <vpp/app/version.h> 33 #include <nsim/nsim.api_enum.h> 34 #include <nsim/nsim.api_types.h> 36 #define REPLY_MSG_ID_BASE nsm->msg_id_base 45 u32 sw_if_index1,
int enable_disable)
52 return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
57 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
61 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
66 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
70 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
87 sw_if_index0, enable_disable, 0, 0);
89 sw_if_index1, enable_disable, 0, 0);
103 return VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE;
108 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
113 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
125 sw_if_index, enable_disable, 0, 0);
133 u64 total_buffer_size_in_bytes, per_worker_buffer_size;
134 u64 wheel_slots_per_worker;
137 u32 pagesize = getpagesize ();
140 if (bandwidth == 0.0)
141 return VNET_API_ERROR_INVALID_VALUE;
144 return VNET_API_ERROR_INVALID_VALUE_2;
146 if (packet_size < 64.0 || packet_size > 9000.0)
147 return VNET_API_ERROR_INVALID_VALUE_3;
164 total_buffer_size_in_bytes = ((delay * bandwidth) / 8.0) + 0.5;
171 per_worker_buffer_size = total_buffer_size_in_bytes / num_workers;
173 per_worker_buffer_size = total_buffer_size_in_bytes;
175 wheel_slots_per_worker = per_worker_buffer_size / packet_size;
176 wheel_slots_per_worker++;
186 for (; i < num_workers + 1; i++)
202 wp->
entries = (
void *) (wp + 1);
210 for (; i < num_workers + 1; i++)
215 VLIB_NODE_STATE_POLLING);
234 u32 sw_if_index0 = ~0;
235 u32 sw_if_index1 = ~0;
236 int enable_disable = 1;
246 if (
unformat (line_input,
"disable"))
251 if (sw_if_index0 == ~0)
262 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
266 sw_if_index1, enable_disable);
273 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
276 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
278 (0,
"Invalid interface, only works on physical ports");
281 case VNET_API_ERROR_UNIMPLEMENTED:
283 "Device driver doesn't support redirection");
299 if (
unformat (input,
"poll-main-thread"))
333 .path =
"nsim cross-connect enable-disable",
335 "nsim cross-connect enable-disable <interface-name-1> " 336 "<interface-name-2> [disable]",
345 vl_api_nsim_cross_connect_enable_disable_reply_t *rmp;
348 u32 sw_if_index0, sw_if_index1;
355 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
356 goto bad_sw_if_index;
360 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
361 goto bad_sw_if_index;
368 REPLY_MACRO (VL_API_NSIM_CROSS_CONNECT_ENABLE_DISABLE_REPLY);
375 vl_api_nsim_output_feature_enable_disable_reply_t *rmp;
384 REPLY_MACRO (VL_API_NSIM_OUTPUT_FEATURE_ENABLE_DISABLE_REPLY);
391 vl_api_nsim_configure_reply_t *rmp;
393 f64 delay, bandwidth, packet_size, drop_fraction;
394 u32 packets_per_drop;
402 if (packets_per_drop > 0)
403 drop_fraction = 1.0 / (
f64) (packets_per_drop);
407 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
424 int enable_disable = 1;
433 if (
unformat (line_input,
"disable"))
450 if (sw_if_index == ~0)
460 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
463 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
465 (0,
"Invalid interface, only works on physical ports");
468 case VNET_API_ERROR_UNIMPLEMENTED:
470 "Device driver doesn't support redirection");
475 (0,
"nsim_output_feature_enable_disable returned %d", rv);
496 .path =
"nsim output-feature enable-disable",
498 "nsim output-feature enable-disable <interface-name> [disable]",
503 #include <nsim/nsim.api.c> 523 .arc_name =
"device-input",
532 .arc_name =
"interface-output",
533 .node_name =
"nsim-output-feature",
541 .version = VPP_BUILD_VER,
542 .description =
"Network Delay Simulator",
549 f64 *result = va_arg (*args,
f64 *);
552 if (
unformat (input,
"%f us", &tmp))
553 *result = tmp * 1e-6;
554 else if (
unformat (input,
"%f ms", &tmp))
555 *result = tmp * 1e-3;
556 else if (
unformat (input,
"%f sec", &tmp))
567 f64 *result = va_arg (*args,
f64 *);
570 if (
unformat (input,
"%f gbit", &tmp))
572 else if (
unformat (input,
"%f gbyte", &tmp))
584 f64 delay, bandwidth;
585 f64 packet_size = 1500.0;
586 f64 drop_fraction = 0.0;
587 u32 packets_per_drop;
598 else if (
unformat (input,
"packet-size %f", &packet_size))
600 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
602 if (packets_per_drop > 0)
603 drop_fraction = 1.0 / ((
f64) packets_per_drop);
605 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
607 if (drop_fraction < 0.0 || drop_fraction > 1.0)
609 (0,
"drop fraction must be between zero and 1");
611 else if (
unformat (input,
"poll-main-thread"))
617 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction);
621 case VNET_API_ERROR_INVALID_VALUE:
624 case VNET_API_ERROR_INVALID_VALUE_2:
627 case VNET_API_ERROR_INVALID_VALUE_3:
637 vlib_cli_output (vm,
"Configured link delay %.2f ms, %.2f ms round-trip",
645 vlib_cli_output (vm,
"Sim uses %llu bytes per thread, %llu bytes total",
673 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n" 674 " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
704 "...inserting link delay of %.2f ms, %.2f ms round-trip",
719 (vm,
" Sim uses %llu bytes per thread, %llu bytes total",
748 .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)
vl_api_interface_index_t sw_if_index1
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)
#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)
sll srl srl sll sra u16x4 i
nsim_wheel_entry_t * entries
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#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)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
nsim_wheel_t ** wheel_by_thread
vl_api_interface_index_t sw_if_index
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(...)
vl_api_interface_index_t sw_if_index0
#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 void setup_message_id_table(snat_main_t *sm, api_main_t *am)
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)
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)