|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
25 #include <vpp/app/version.h>
58 format (s,
"ICMP%s echo id %d seq %d", t->
is_ip6 ?
"6" :
"4", t->
id,
62 s =
format (s,
" (unknown)");
80 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break;
119 return cli_process_id;
125 uword cli_process_id)
136 goto have_found_and_set;
173 if (
ip6->protocol != IP_PROTOCOL_ICMP6)
177 l4_offset =
sizeof (*ip6);
186 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
188 *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
189 *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
208 sizeof (
vnet_buffer (b0)->unused[0]) >
sizeof (nowts),
209 "ping reply timestamp fits within remaining space of vnet_buffer unused data");
283 icmp_id, icmp_seq, b0,
286 if (~0 == cli_process_id)
295 to_next, n_left_to_next,
306 return frame->n_vectors;
345 .name =
"ip6-icmp-echo-reply",
346 .vector_size =
sizeof (
u32),
358 .name =
"ip4-icmp-echo-reply",
359 .vector_size =
sizeof (
u32),
377 u16 *fragment_ids, *fid;
392 sizeof (fragment_ids[0]));
402 icmp46_header_t *icmp0, *icmp1;
407 bi0 = to_next[0] =
from[0];
408 bi1 = to_next[1] =
from[1];
428 sum0 = icmp0->checksum;
429 sum1 = icmp1->checksum;
431 ASSERT (icmp0->type == ICMP4_echo_request);
432 ASSERT (icmp1->type == ICMP4_echo_request);
433 sum0 =
ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
434 icmp46_header_t,
type);
435 sum1 =
ip_csum_update (sum1, ICMP4_echo_request, ICMP4_echo_reply,
436 icmp46_header_t,
type);
437 icmp0->type = ICMP4_echo_reply;
438 icmp1->type = ICMP4_echo_reply;
463 ip0->
ttl = host_config_ttl;
464 ip1->
ttl = host_config_ttl;
481 p0->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
482 p1->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
489 icmp46_header_t *icmp0;
493 bi0 = to_next[0] =
from[0];
508 sum0 = icmp0->checksum;
510 ASSERT (icmp0->type == ICMP4_echo_request);
511 sum0 =
ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
512 icmp46_header_t,
type);
513 icmp0->type = ICMP4_echo_reply;
526 ip0->
ttl = host_config_ttl;
537 p0->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
544 ICMP4_ERROR_ECHO_REPLIES_SENT,
frame->n_vectors);
546 return frame->n_vectors;
565 .name =
"ip4-icmp-echo-request",
567 .vector_size =
sizeof (
u32),
573 [0] =
"ip4-load-balance",
596 int l4_header_offset,
597 icmp46_echo_request_t * icmp46_echo,
u16 seq_host,
604 l4_header_offset +
sizeof (icmp46_header_t) +
605 offsetof (icmp46_echo_request_t,
data);
610 int payload_offset = 0;
611 for (
i = 0;
i < first_buf_data_len;
i++)
616 int remaining_data_len =
data_len - first_buf_data_len;
617 while (remaining_data_len)
619 int this_buf_data_len =
627 return (
data_len - remaining_data_len);
629 b0->
flags |= VLIB_BUFFER_NEXT_PRESENT;
633 for (
i = 0;
i < this_buf_data_len;
i++)
639 remaining_data_len -= this_buf_data_len;
641 hb->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
645 icmp46_echo->time_sent =
now;
646 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
647 icmp46_echo->id = clib_host_to_net_u16 (id_host);
667 return fib_entry_index;
690 return fib_table_index;
702 ip6->ip_version_traffic_class_and_flow_label =
703 clib_host_to_net_u32 (0x6 << 28);
704 ip6->payload_length = 0;
705 ip6->protocol = IP_PROTOCOL_ICMP6;
706 ip6->hop_limit = 255;
707 ip6->dst_address = pa46->ip6;
708 ip6->src_address = pa46->ip6;
716 ip4->ip_version_and_header_length = 0x45;
719 ip4->fragment_id = 0;
720 ip4->flags_and_fragment_offset = 0;
722 ip4->protocol = IP_PROTOCOL_ICMP;
723 ip4->src_address = pa46->ip4;
724 ip4->dst_address = pa46->ip4;
753 void *format_addr_func;
759 paddr = &
ip6->src_address;
765 paddr = &
ip4->src_address;
777 icmp46->type =
is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
779 icmp46->checksum = 0;
781 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
796 u32 ip_header_length, payload_length_host_byte_order;
797 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
799 void *data_this_buffer;
802 payload_length_host_byte_order =
803 clib_net_to_host_u16 (ip0->
length) - ip_header_length;
808 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
809 data_this_buffer = (
void *) ip0 + ip_header_length;
810 n_ip_bytes_this_buffer =
812 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
814 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
815 n_ip_bytes_this_buffer - ip_header_length : 0;
820 n_bytes_left -= n_this_buffer;
821 if (n_bytes_left == 0)
841 data_len +
sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
843 u16 total_length = payload_length + l4_offset;
845 icmp46->checksum = 0;
850 ip6->payload_length = clib_host_to_net_u16 (payload_length);
852 int bogus_length = 0;
859 ip4->length = clib_host_to_net_u16 (total_length);
877 u32 lookup_node_index =
889 for (n_to_send =
at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
898 while (n_to_send > 1)
947 #define ERROR_OUT(e) do { err = e; goto done; } while (0)
952 ip46_address_t * pa46,
957 int err = SEND_PING_OK;
1007 err = SEND_PING_NO_BUFFERS;
1010 if (err != SEND_PING_OK)
1022 u32 burst,
u8 verbose)
1024 ip46_address_t target;
1027 id_host,
data_len, burst, verbose, 1 );
1034 u32 burst,
u8 verbose)
1036 ip46_address_t target;
1039 id_host,
data_len, burst, verbose, 0 );
1048 void *format_addr_func;
1054 paddr = (
void *) &
ip6->src_address;
1058 payload_length = clib_net_to_host_u16 (
ip6->payload_length);
1063 paddr = (
void *) &
ip4->src_address;
1071 icmp46_echo_request_t *icmp_echo = (icmp46_echo_request_t *) (
icmp + 1);
1076 ((
f64) (*dataplane_ts - icmp_echo->time_sent)) / clocks_per_second;
1079 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
1083 clib_host_to_net_u16 (icmp_echo->seq),
ttl, rtt * 1000.0);
1097 u32 ping_burst,
u32 verbose)
1105 static u32 rand_seed = 0;
1120 for (
i = 1;
i <= ping_repeat;
i++)
1130 if (SEND_PING_OK == res)
1131 n_requests += ping_burst;
1139 ping_burst, verbose);
1140 if (SEND_PING_OK == res)
1141 n_requests += ping_burst;
1148 while ((
i <= ping_repeat)
1153 uword event_type, *event_data = 0;
1166 for (ii = 0; ii <
vec_len (event_data); ii++)
1168 u32 bi0 = event_data[ii];
1190 n_requests) ? 0 : 100.0 * ((
float) n_requests -
1191 (float) n_replies) / (float) n_requests;
1193 "Statistics: %u sent, %u received, %f%% packet loss\n",
1194 n_requests, n_replies, loss);
1208 u32 ping_repeat = 5;
1210 u8 ping_ip4, ping_ip6;
1218 ping_ip4 = ping_ip6 = 0;
1239 "expecting IPv4 address but got `%U'",
1253 "expecting IPv6 address but got `%U'",
1261 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
1267 if (!ping_ip4 && (
unformat (input,
"ipv4")))
1274 else if (!ping_ip6 && (
unformat (input,
"ipv6")))
1292 "unknown interface `%U'",
1303 "expecting size but got `%U'",
1311 "%d is bigger than maximum allowed payload size %d",
1316 else if (
unformat (input,
"table-id"))
1322 "expecting table-id but got `%U'",
1327 else if (
unformat (input,
"interval"))
1329 if (!
unformat (input,
"%f", &ping_interval))
1333 "expecting interval (floating point number) got `%U'",
1338 else if (
unformat (input,
"repeat"))
1340 if (!
unformat (input,
"%u", &ping_repeat))
1344 "expecting repeat count but got `%U'",
1349 else if (
unformat (input,
"burst"))
1351 if (!
unformat (input,
"%u", &ping_burst))
1355 "expecting burst count but got `%U'",
1360 else if (
unformat (input,
"verbose"))
1378 #define MAX_PING_BURST (10*VLIB_FRAME_SIZE)
1380 #define MAX_PING_BURST (VLIB_FRAME_SIZE)
1388 ping_ip6 ? &a6 : NULL,
sw_if_index, ping_interval,
1389 ping_repeat,
data_len, ping_burst, verbose);
1440 .short_help =
"ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}"
1441 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]"
1442 " [size <pktsize:60>] [interval <sec:1>] [repeat <cnt:5>] [table-id <id:0>]"
1443 " [burst <count:1>] [verbose]",
1472 .version = VPP_BUILD_VER,
1473 .description =
"Ping (ping)",
static void vlib_process_signal_event_mt(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Signal event to process from any thread.
@ ICMP46_ECHO_REPLY_NEXT_DROP
u8 ttl
TTL to use for host generated packets.
ping_run_t * active_ping_runs
static void clib_spinlock_init(clib_spinlock_t *p)
static_always_inline void clear_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
u32 next_buffer
Next buffer for this linked-list of buffers.
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
clib_random_buffer_t random_buffer
static u32 ip46_get_resolving_interface(u32 fib_index, ip46_address_t *pa46, int is_ip6)
static uword ip4_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline uword ip46_icmp_echo_reply_inner_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int do_trace, int is_ip6)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
static int ip46_fill_l3_header(ip46_address_t *pa46, vlib_buffer_t *b0, int is_ip6)
static_always_inline void set_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id, uword cli_process_id)
static void run_ping_ip46_address(vlib_main_t *vm, u32 table_id, ip4_address_t *pa4, ip6_address_t *pa6, u32 sw_if_index, f64 ping_interval, u32 ping_repeat, u32 data_len, u32 ping_burst, u32 verbose)
static u16 init_icmp46_echo_request(vlib_main_t *vm, vlib_buffer_t *b0, int l4_header_offset, icmp46_echo_request_t *icmp46_echo, u16 seq_host, u16 id_host, u64 now, u16 data_len)
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
nat44_ei_hairpin_src_next_t next_index
ip4_main_t ip4_main
Global ip4 main structure.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static uword ip6_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void ip46_address_set_ip4(ip46_address_t *ip46, const ip4_address_t *ip)
static u8 * format_ip46_ping_result(u8 *s, va_list *args)
@ ICMP46_ECHO_REPLY_NEXT_PUNT
static send_ip46_ping_result_t send_ip6_ping(vlib_main_t *vm, u32 table_id, ip6_address_t *pa6, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
static uword ip4_header_checksum_is_valid(ip4_header_t *i)
void vlib_trace_frame_buffers_only(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, uword n_buffers, uword next_buffer_stride, uword n_buffer_data_bytes_in_trace)
vlib_main_t vlib_node_runtime_t * node
#define clib_error_return(e, args...)
static u16 ip46_fill_icmp_request_at(vlib_main_t *vm, int l4_offset, u16 seq_host, u16 id_host, u16 data_len, vlib_buffer_t *b0, int is_ip6)
u8 * format_icmp_echo_trace(u8 *s, va_list *va)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static send_ip46_ping_result_t send_ip4_ping(vlib_main_t *vm, u32 table_id, ip4_address_t *pa4, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static uword vlib_current_process(vlib_main_t *vm)
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static u32 ip6_fib_index_from_table_id(u32 table_id)
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
static_always_inline u8 get_icmp_echo_payload_byte(int offset)
static u16 at_most_a_frame(u32 count)
void ip4_icmp_register_type(vlib_main_t *vm, icmp4_type_t type, u32 node_index)
static uword ip4_icmp_echo_request(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static u32 random_u32(u32 *seed)
32-bit random number generator
void icmp6_register_type(vlib_main_t *vm, icmp6_type_t type, u32 node_index)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static bool ip46_set_src_address(u32 sw_if_index, vlib_buffer_t *b0, int is_ip6)
static vlib_node_registration_t ip6_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define PING_MAXIMUM_DATA_SIZE
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
vnet_main_t * vnet_get_main(void)
#define VLIB_NODE_FLAG_TRACE
struct ip4_main_t::@372 host_config
Template information for VPP generated packets.
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define PING_CLI_UNKNOWN_NODE
static int ip46_enqueue_packet(vlib_main_t *vm, vlib_buffer_t *b0, u32 burst, int is_ip6)
#define static_always_inline
static void ip46_fix_len_and_csum(vlib_main_t *vm, int l4_offset, u16 data_len, vlib_buffer_t *b0, int is_ip6)
static vlib_node_registration_t ip4_icmp_echo_request_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_echo_request_node)
@ UNIX_CLI_PROCESS_EVENT_QUIT
A CLI session wants to close.
u32 fib_node_index_t
A typedef of a node index.
static clib_error_t * ping_ip_address(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
sll srl srl sll sra u16x4 i
static void print_ip46_icmp_reply(vlib_main_t *vm, u32 bi0, int is_ip6)
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
clib_spinlock_t ping_run_check_lock
#define VLIB_CLI_COMMAND(x,...)
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
bool fib_sas6_get(u32 sw_if_index, const ip6_address_t *dst, ip6_address_t *src)
Get an IPv6 Source address to use in a packet being sent out an interface.
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
#define STATIC_ASSERT(truth,...)
@ foreach_ip46_ping_result
struct _vlib_node_registration vlib_node_registration_t
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u16 current_length
Nbytes between current data and the end of this buffer.
@ ICMP46_ECHO_REPLY_N_NEXT
static void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
static send_ip46_ping_result_t send_ip46_ping(vlib_main_t *vm, u32 table_id, ip46_address_t *pa46, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u32 burst, u8 verbose, int is_ip6)
#define vec_free(V)
Free vector's memory (no header).
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
static_always_inline void ip46_post_icmp_reply_event(vlib_main_t *vm, uword cli_process_id, u32 bi0, int is_ip6)
template key/value backing page structure
@ UNIX_CLI_PROCESS_EVENT_READ_READY
A file descriptor has data to be read.
#define PING_DEFAULT_DATA_LEN
bool fib_sas4_get(u32 sw_if_index, const ip4_address_t *dst, ip4_address_t *src)
Get an IPv4 Source address to use in a packet being sent out an interface.
u32 local_interface_sw_if_index
unformat_function_t unformat_vnet_sw_interface
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
description fragment has unexpected format
vlib_put_next_frame(vm, node, next_index, 0)
static u32 ip46_fib_index_from_table_id(u32 table_id, int is_ip6)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
static void ip46_print_buffer_src_address(vlib_main_t *vm, vlib_buffer_t *b0, int is_ip6)
#define VLIB_INIT_FUNCTION(x)
static fib_node_index_t ip46_fib_table_lookup_host(u32 fib_index, ip46_address_t *pa46, int is_ip6)
static_always_inline int ip46_get_icmp_id_and_seq(vlib_main_t *vm, vlib_buffer_t *b0, u16 *out_icmp_id, u16 *out_icmp_seq, int is_ip6)
static_always_inline uword get_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
#define vec_foreach(var, vec)
Vector iterator.
static vlib_cli_command_t ping_command
(constructor) VLIB_CLI_COMMAND (ping_command)
static u32 ip4_fib_index_from_table_id(u32 table_id)
static vlib_node_registration_t ip4_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node)
#define ip_csum_update(sum, old, new, type, field)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
vlib_node_registration_t ip4_icmp_input_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_input_node)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u16 ip4_header_checksum(ip4_header_t *i)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
#define PING_DEFAULT_INTERVAL
u16 ip4_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
static u8 * format_icmp_input_trace(u8 *s, va_list *va)
static clib_error_t * ping_cli_init(vlib_main_t *vm)
static int ip4_header_bytes(const ip4_header_t *i)
static f64 vlib_time_now(vlib_main_t *vm)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
static u64 clib_cpu_time_now(void)
static vlib_thread_main_t * vlib_get_thread_main()
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
vl_api_interface_index_t sw_if_index
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static_always_inline void ip46_echo_reply_maybe_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, uword cli_process_id, u16 id, u16 seq, vlib_buffer_t *b0, int is_ip6)
static u16 ip_csum_fold(ip_csum_t c)
static_always_inline uword ip46_icmp_echo_reply_outer_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip6)
vl_api_fib_path_type_t type
static u32 ip46_fib_table_get_index_for_sw_if_index(u32 sw_if_index, int is_ip6)
#define vec_del1(v, i)
Delete the element at index I.
static void * ip4_next_header(ip4_header_t *i)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
VLIB buffer representation.
#define VLIB_REGISTER_NODE(x,...)
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)