|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
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;
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);
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;
456 int enable_disable = 1;
465 if (
unformat (line_input,
"disable"))
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",
563 .arc_name =
"interface-output",
564 .node_name =
"nsim-output-feature",
572 .version = VPP_BUILD_VER,
573 .description =
"Network Delay Simulator",
580 f64 *result = va_arg (*args,
f64 *);
584 *result =
tmp * 1e-6;
586 *result =
tmp * 1e-3;
598 f64 *result = va_arg (*args,
f64 *);
613 int verbose = va_arg (*args,
int);
616 s =
format (s,
"configuration\n");
617 s =
format (s,
" delay (ms): %.2f\n", nsm->
delay * 1e3);
621 s =
format (s,
" drop fraction: 0\n");
625 s =
format (s,
" reorder fraction: 0\n");
632 s =
format (s,
" memory: %U bytes per thread %U bytes total\n",
641 s =
format (s,
"cross-connect\n %U and %U\n",
649 s =
format (s,
"output feature arcs to:\n");
659 s =
format (s,
" nsim not enabled\n");
669 f64 drop_fraction = 0.0, reorder_fraction = 0.0;
670 f64 delay, bandwidth, packet_size = 1500.0;
671 u32 packets_per_drop, packets_per_reorder;
682 else if (
unformat (input,
"packet-size %f", &packet_size))
684 else if (
unformat (input,
"packets-per-drop %d", &packets_per_drop))
686 if (packets_per_drop > 0)
687 drop_fraction = 1.0 / ((
f64) packets_per_drop);
689 else if (
unformat (input,
"packets-per-reorder %d",
690 &packets_per_reorder))
692 if (packets_per_reorder > 0)
693 reorder_fraction = 1.0 / ((
f64) packets_per_reorder);
695 else if (
unformat (input,
"drop-fraction %f", &drop_fraction))
697 if (drop_fraction < 0.0 || drop_fraction > 1.0)
699 (0,
"drop fraction must be between zero and 1");
701 else if (
unformat (input,
"reorder-fraction %f", &reorder_fraction))
703 if (reorder_fraction < 0.0 || reorder_fraction > 1.0)
705 (0,
"reorder fraction must be between zero and 1");
707 else if (
unformat (input,
"poll-main-thread"))
718 case VNET_API_ERROR_INVALID_VALUE:
721 case VNET_API_ERROR_INVALID_VALUE_2:
724 case VNET_API_ERROR_INVALID_VALUE_3:
727 case VNET_API_ERROR_INVALID_VALUE_4:
729 "delay %.2f", reorder_fraction, delay);
763 .short_help =
"set nsim delay <time> bandwidth <bps> packet-size <nbytes>\n"
764 " [packets-per-drop <nn>][drop-fraction <f64: 0.0 - 1.0>]",
808 .short_help =
"Display network delay simulator configuration",
vl_api_interface_index_t sw_if_index
#define VALIDATE_SW_IF_INDEX(mp)
static u32 vlib_num_workers()
enable / disable the network delay simulation cross-connect
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
vnet_sw_interface_type_t type
static vlib_cli_command_t set_nsim_command
(constructor) VLIB_CLI_COMMAND (set_nsim_command)
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
static int nsim_configure(nsim_main_t *nsm, f64 bandwidth, f64 delay, f64 packet_size, f64 drop_fraction, f64 reorder_fraction)
static void vl_api_nsim_cross_connect_enable_disable_t_handler(vl_api_nsim_cross_connect_enable_disable_t *mp)
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
static vlib_cli_command_t show_nsim_command
(constructor) VLIB_CLI_COMMAND (show_nsim_command)
static uword unformat_bandwidth(unformat_input_t *input, va_list *args)
enable / disable the network delay simulation output feature
static void vl_api_nsim_configure2_t_handler(vl_api_nsim_configure2_t *mp)
#define clib_error_return(e, args...)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * set_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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)
#define VLIB_CONFIG_FUNCTION(x, n,...)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static void setup_message_id_table(api_main_t *am)
VNET_FEATURE_INIT(nsim, static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
vnet_main_t * vnet_get_main(void)
#define vlib_worker_thread_barrier_sync(X)
static clib_error_t * nsim_init(vlib_main_t *vm)
vl_api_interface_index_t sw_if_index0
static clib_error_t * nsim_cross_connect_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
sll srl srl sll sra u16x4 i
int nsim_cross_connect_enable_disable(nsim_main_t *nsm, u32 sw_if_index0, u32 sw_if_index1, int enable_disable)
int nsim_output_feature_enable_disable(nsim_main_t *nsm, u32 sw_if_index, int enable_disable)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
static void clib_mem_vm_free(void *addr, uword size)
#define VLIB_CLI_COMMAND(x,...)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vnet_sw_interface_t * sw_interfaces
nsim_wheel_t ** wheel_by_thread
static void vl_api_nsim_output_feature_enable_disable_t_handler(vl_api_nsim_output_feature_enable_disable_t *mp)
#define BAD_SW_IF_INDEX_LABEL
static clib_error_t * show_nsim_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
static uword unformat_delay(unformat_input_t *input, va_list *args)
static vlib_cli_command_t nsim_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nsim_enable_disable_command)
format_function_t format_vnet_sw_if_index_name
unformat_function_t unformat_vnet_sw_interface
description fragment has unexpected format
static void * clib_mem_vm_alloc(uword size)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
#define VLIB_INIT_FUNCTION(x)
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)
static vlib_main_t * vlib_get_main_by_index(u32 thread_index)
vl_api_interface_index_t sw_if_index1
nsim_wheel_entry_t * entries
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 u8 * format_nsim_config(u8 *s, va_list *args)
#define VNET_FEATURES(...)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
static void vl_api_nsim_configure_t_handler(vl_api_nsim_configure_t *mp)
static vlib_cli_command_t nsim_output_feature_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nsim_output_feature_enable_disable_command)
@ VNET_SW_INTERFACE_TYPE_HARDWARE
u32 * output_next_index_by_sw_if_index
vl_api_interface_index_t sw_if_index
u8 output_feature_arc_index
vnet_interface_main_t interface_main