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);
132 u32 pagesize = getpagesize ();
147 wp->
entries = (
void *) (wp + 1);
154 f64 drop_fraction,
f64 reorder_fraction)
156 u64 total_buffer_size_in_bytes, per_worker_buffer_size, wheel_slots_per_wrk;
160 if (bandwidth == 0.0)
161 return VNET_API_ERROR_INVALID_VALUE;
164 return VNET_API_ERROR_INVALID_VALUE_2;
166 if (packet_size < 64.0 || packet_size > 9000.0)
167 return VNET_API_ERROR_INVALID_VALUE_3;
169 if (reorder_fraction > 0.0 && delay == 0.0)
170 return VNET_API_ERROR_INVALID_VALUE_4;
187 total_buffer_size_in_bytes = ((delay * bandwidth) / 8.0) + 0.5;
194 per_worker_buffer_size = total_buffer_size_in_bytes / num_workers;
196 per_worker_buffer_size = total_buffer_size_in_bytes;
198 wheel_slots_per_wrk = per_worker_buffer_size / packet_size;
199 wheel_slots_per_wrk++;
209 for (; i < num_workers + 1; i++)
216 for (; i < num_workers + 1; i++)
221 VLIB_NODE_STATE_POLLING);
240 u32 sw_if_index0 = ~0;
241 u32 sw_if_index1 = ~0;
242 int enable_disable = 1;
252 if (
unformat (line_input,
"disable"))
257 if (sw_if_index0 == ~0)
268 if (sw_if_index0 == ~0 || sw_if_index1 == ~0)
272 sw_if_index1, enable_disable);
279 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
282 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
284 (0,
"Invalid interface, only works on physical ports");
287 case VNET_API_ERROR_UNIMPLEMENTED:
289 "Device driver doesn't support redirection");
305 if (
unformat (input,
"poll-main-thread"))
339 .path =
"nsim cross-connect enable-disable",
341 "nsim cross-connect enable-disable <interface-name-1> " 342 "<interface-name-2> [disable]",
351 vl_api_nsim_cross_connect_enable_disable_reply_t *rmp;
354 u32 sw_if_index0, sw_if_index1;
361 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
362 goto bad_sw_if_index;
366 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
367 goto bad_sw_if_index;
374 REPLY_MACRO (VL_API_NSIM_CROSS_CONNECT_ENABLE_DISABLE_REPLY);
381 vl_api_nsim_output_feature_enable_disable_reply_t *rmp;
390 REPLY_MACRO (VL_API_NSIM_OUTPUT_FEATURE_ENABLE_DISABLE_REPLY);
397 vl_api_nsim_configure_reply_t *rmp;
399 f64 delay, bandwidth, packet_size, drop_fraction = 0.0, reorder_rate = 0.0;
400 u32 packets_per_drop;
408 if (packets_per_drop > 0)
409 drop_fraction = 1.0 / (
f64) (packets_per_drop);
411 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
420 vl_api_nsim_configure_reply_t *rmp;
422 f64 delay, bandwidth, packet_size, drop_fraction = 0.0, reorder_rate = 0.0;
423 u32 packets_per_drop, packets_per_reorder;
431 if (packets_per_drop > 0)
432 drop_fraction = 1.0 / (
f64) (packets_per_drop);
435 if (packets_per_reorder > 0)
436 reorder_rate = 1.0 / (
f64) packets_per_reorder;
438 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
456 int enable_disable = 1;
465 if (
unformat (line_input,
"disable"))
482 if (sw_if_index == ~0)
492 case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
495 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
497 (0,
"Invalid interface, only works on physical ports");
500 case VNET_API_ERROR_UNIMPLEMENTED:
502 "Device driver doesn't support redirection");
507 (0,
"nsim_output_feature_enable_disable returned %d", rv);
528 .path =
"nsim output-feature enable-disable",
530 "nsim output-feature enable-disable <interface-name> [disable]",
535 #include <nsim/nsim.api.c> 555 .arc_name =
"device-input",
564 .arc_name =
"interface-output",
565 .node_name =
"nsim-output-feature",
573 .version = VPP_BUILD_VER,
574 .description =
"Network Delay Simulator",
581 f64 *result = va_arg (*args,
f64 *);
584 if (
unformat (input,
"%f us", &tmp))
585 *result = tmp * 1e-6;
586 else if (
unformat (input,
"%f ms", &tmp))
587 *result = tmp * 1e-3;
588 else if (
unformat (input,
"%f sec", &tmp))
599 f64 *result = va_arg (*args,
f64 *);
602 if (
unformat (input,
"%f gbit", &tmp))
604 else if (
unformat (input,
"%f gbyte", &tmp))
614 int verbose = va_arg (*args,
int);
617 s =
format (s,
"configuration\n");
618 s =
format (s,
" delay (ms): %.2f\n", nsm->
delay * 1e3);
622 s =
format (s,
" drop fraction: 0\n");
626 s =
format (s,
" reorder fraction: 0\n");
633 s =
format (s,
" memory: %U bytes per thread %U bytes total\n",
642 s =
format (s,
"cross-connect\n %U and %U\n",
650 s =
format (s,
"output feature arcs to:\n");
660 s =
format (s,
" nsim not enabled\n");
670 f64 drop_fraction = 0.0, reorder_fraction = 0.0;
671 f64 delay, bandwidth, packet_size = 1500.0;
672 u32 packets_per_drop, packets_per_reorder;
683 else if (
unformat (input,
"packet-size %f", &packet_size))
685 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
687 if (packets_per_drop > 0)
688 drop_fraction = 1.0 / ((
f64) packets_per_drop);
690 else if (
unformat (input,
"packets-per-reorder %d",
691 &packets_per_reorder))
693 if (packets_per_reorder > 0)
694 reorder_fraction = 1.0 / ((
f64) packets_per_reorder);
696 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
698 if (drop_fraction < 0.0 || drop_fraction > 1.0)
700 (0,
"drop fraction must be between zero and 1");
702 else if (
unformat (input,
"reorder-fraction %f", &reorder_fraction))
704 if (reorder_fraction < 0.0 || reorder_fraction > 1.0)
706 (0,
"reorder fraction must be between zero and 1");
708 else if (
unformat (input,
"poll-main-thread"))
714 rv =
nsim_configure (nsm, bandwidth, delay, packet_size, drop_fraction,
719 case VNET_API_ERROR_INVALID_VALUE:
722 case VNET_API_ERROR_INVALID_VALUE_2:
725 case VNET_API_ERROR_INVALID_VALUE_3:
728 case VNET_API_ERROR_INVALID_VALUE_4:
730 "delay %.2f", reorder_fraction, delay);
764 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n" 765 " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
809 .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
#define VLIB_INIT_FUNCTION(x)
description fragment has unexpected format
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 u8 * format_nsim_config(u8 *s, 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)
VNET_FEATURE_INIT(nsim, static)
static void setup_message_id_table(api_main_t *am)
#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 nsim_wheel_t * nsim_wheel_alloc(nsim_main_t *nsm, u32 wheel_slots)
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)
u8 output_feature_arc_index
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
static void clib_mem_vm_free(void *addr, uword size)
#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)
static int nsim_configure(nsim_main_t *nsm, f64 bandwidth, f64 delay, f64 packet_size, f64 drop_fraction, f64 reorder_fraction)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
static void vl_api_nsim_configure2_t_handler(vl_api_nsim_configure2_t *mp)
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)
vl_api_interface_index_t sw_if_index
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)