24 #include <vpp/app/version.h> 57 format (s,
"ICMP%s echo id %d seq %d", t->
is_ip6 ?
"6" :
"4", t->
id,
61 s =
format (s,
" (unknown)");
79 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break; 118 return cli_process_id;
124 uword cli_process_id)
135 goto have_found_and_set;
172 if (ip6->
protocol != IP_PROTOCOL_ICMP6)
176 l4_offset =
sizeof (*ip6);
185 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
187 *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
188 *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
207 sizeof (
vnet_buffer (b0)->unused[0]) >
sizeof (nowts),
208 "ping reply timestamp fits within remaining space of vnet_buffer unused data");
240 u32 n_left_from, *from, *to_next;
248 while (n_left_from > 0)
253 while (n_left_from > 0 && n_left_to_next > 0)
282 icmp_id, icmp_seq, b0,
285 if (~0 == cli_process_id)
294 to_next, n_left_to_next,
344 .name =
"ip6-icmp-echo-reply",
345 .vector_size =
sizeof (
u32),
357 .name =
"ip4-icmp-echo-reply",
358 .vector_size =
sizeof (
u32),
374 u32 n_left_from, n_left_to_next, next;
376 u16 *fragment_ids, *fid;
380 n_left_from = n_packets;
391 sizeof (fragment_ids[0]));
393 while (n_left_from > 0)
397 while (n_left_from > 2 && n_left_to_next > 2)
401 icmp46_header_t *icmp0, *icmp1;
406 bi0 = to_next[0] = from[0];
407 bi1 = to_next[1] = from[1];
427 sum0 = icmp0->checksum;
428 sum1 = icmp1->checksum;
430 ASSERT (icmp0->type == ICMP4_echo_request);
431 ASSERT (icmp1->type == ICMP4_echo_request);
432 sum0 =
ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
433 icmp46_header_t,
type);
434 sum1 =
ip_csum_update (sum1, ICMP4_echo_request, ICMP4_echo_reply,
435 icmp46_header_t,
type);
436 icmp0->type = ICMP4_echo_reply;
437 icmp1->type = ICMP4_echo_reply;
462 ip0->
ttl = host_config_ttl;
463 ip1->
ttl = host_config_ttl;
480 p0->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
481 p1->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
484 while (n_left_from > 0 && n_left_to_next > 0)
488 icmp46_header_t *icmp0;
492 bi0 = to_next[0] = from[0];
507 sum0 = icmp0->checksum;
509 ASSERT (icmp0->type == ICMP4_echo_request);
510 sum0 =
ip_csum_update (sum0, ICMP4_echo_request, ICMP4_echo_reply,
511 icmp46_header_t,
type);
512 icmp0->type = ICMP4_echo_reply;
525 ip0->
ttl = host_config_ttl;
536 p0->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
543 ICMP4_ERROR_ECHO_REPLIES_SENT, frame->
n_vectors);
564 .name =
"ip4-icmp-echo-request",
566 .vector_size =
sizeof (
u32),
572 [0] =
"ip4-load-balance",
589 return (offset % 256);
595 int l4_header_offset,
596 icmp46_echo_request_t * icmp46_echo,
u16 seq_host,
603 l4_header_offset +
sizeof (icmp46_header_t) +
604 offsetof (icmp46_echo_request_t,
data);
607 int first_buf_data_len = data_len < max_data_len ?
data_len : max_data_len;
609 int payload_offset = 0;
610 for (i = 0; i < first_buf_data_len; i++)
615 int remaining_data_len = data_len - first_buf_data_len;
616 while (remaining_data_len)
618 int this_buf_data_len =
626 return (data_len - remaining_data_len);
628 b0->
flags |= VLIB_BUFFER_NEXT_PRESENT;
632 for (i = 0; i < this_buf_data_len; i++)
638 remaining_data_len -= this_buf_data_len;
640 hb->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
644 icmp46_echo->time_sent = now;
645 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
646 icmp46_echo->id = clib_host_to_net_u16 (id_host);
654 u32 fib_index = is_ip6 ?
666 return fib_entry_index;
686 u32 fib_table_index = is_ip6 ?
689 return fib_table_index;
702 clib_host_to_net_u32 (0x6 << 28);
752 void *format_addr_func;
776 icmp46->type = is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
778 icmp46->checksum = 0;
780 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
795 u32 ip_header_length, payload_length_host_byte_order;
796 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
798 void *data_this_buffer;
801 payload_length_host_byte_order =
802 clib_net_to_host_u16 (ip0->
length) - ip_header_length;
807 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
808 data_this_buffer = (
void *) ip0 + ip_header_length;
809 n_ip_bytes_this_buffer =
811 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
813 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
814 n_ip_bytes_this_buffer - ip_header_length : 0;
819 n_bytes_left -= n_this_buffer;
820 if (n_bytes_left == 0)
840 data_len +
sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
842 u16 total_length = payload_length + l4_offset;
844 icmp46->checksum = 0;
851 int bogus_length = 0;
858 ip4->
length = clib_host_to_net_u16 (total_length);
876 u32 lookup_node_index =
888 for (n_to_send =
at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
897 while (n_to_send > 1)
934 ASSERT (n_to_send <= f->n_vectors);
946 #define ERROR_OUT(e) do { err = e; goto done; } while (0) 951 ip46_address_t * pa46,
956 int err = SEND_PING_OK;
974 if (~0 == sw_if_index)
985 if (~0 == sw_if_index)
1001 data_len, b0, is_ip6);
1007 err = SEND_PING_NO_BUFFERS;
1010 if (err != SEND_PING_OK)
1022 u32 burst,
u8 verbose)
1024 ip46_address_t target;
1026 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
1027 id_host, data_len, burst, verbose, 1 );
1034 u32 burst,
u8 verbose)
1036 ip46_address_t target;
1038 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
1039 id_host, data_len, burst, verbose, 0 );
1048 void *format_addr_func;
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;
1114 vlib_cli_output (vm,
"ICMP ID collision at %d, incrementing", icmp_id);
1120 for (i = 1; i <= ping_repeat; i++)
1128 pa6, sw_if_index, i, icmp_id,
1129 data_len, ping_burst, verbose);
1130 if (SEND_PING_OK == res)
1131 n_requests += ping_burst;
1138 sw_if_index, i, icmp_id, data_len,
1139 ping_burst, verbose);
1140 if (SEND_PING_OK == res)
1141 n_requests += ping_burst;
1148 while ((i <= ping_repeat)
1151 time_ping_sent + ping_interval -
vlib_time_now (vm)) > 0.0))
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'",
1299 if (!
unformat (input,
"%u", &data_len))
1303 "expecting size but got `%U'",
1311 "%d is bigger than maximum allowed payload size %d",
1316 else if (
unformat (input,
"table-id"))
1318 if (!
unformat (input,
"%u", &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)",
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static_always_inline void clear_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
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 uword random_default_seed(void)
Default random seed (unix/linux user-mode)
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...
static int ip46_fill_l3_header(ip46_address_t *pa46, vlib_buffer_t *b0, int is_ip6)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
vnet_main_t * vnet_get_main(void)
static uword vlib_current_process(vlib_main_t *vm)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
static f64 vlib_time_now(vlib_main_t *vm)
static void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
static u32 ip46_fib_index_from_table_id(u32 table_id, int is_ip6)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
u16 current_length
Nbytes between current data and the end of this buffer.
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)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u64 clib_cpu_time_now(void)
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)
clib_spinlock_t ping_run_check_lock
static int ip46_enqueue_packet(vlib_main_t *vm, vlib_buffer_t *b0, u32 burst, int is_ip6)
unformat_function_t unformat_vnet_sw_interface
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)
static bool ip46_set_src_address(u32 sw_if_index, vlib_buffer_t *b0, int is_ip6)
u8 * format_icmp_echo_trace(u8 *s, va_list *va)
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
static void print_ip46_icmp_reply(vlib_main_t *vm, u32 bi0, int is_ip6)
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
static uword ip4_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static_always_inline u8 get_icmp_echo_payload_byte(int offset)
#define static_always_inline
static uword ip4_header_checksum_is_valid(ip4_header_t *i)
#define VLIB_INIT_FUNCTION(x)
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...
u32 local_interface_sw_if_index
description fragment has unexpected format
static u16 at_most_a_frame(u32 count)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_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.
#define clib_error_return(e, args...)
static void * ip4_next_header(ip4_header_t *i)
static u32 ip46_get_resolving_interface(u32 fib_index, ip46_address_t *pa46, int is_ip6)
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static u8 * format_ip46_ping_result(u8 *s, va_list *args)
static void clib_spinlock_init(clib_spinlock_t *p)
vl_api_fib_path_type_t type
void ip4_icmp_register_type(vlib_main_t *vm, icmp4_type_t type, u32 node_index)
static clib_error_t * ping_cli_init(vlib_main_t *vm)
static uword ip4_icmp_echo_request(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static u32 ip6_fib_index_from_table_id(u32 table_id)
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define vec_del1(v, i)
Delete the element at index I.
struct ip4_main_t::@380 host_config
Template information for VPP generated packets.
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)
#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.
#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 uword get_cli_process_id_by_icmp_id_mt(vlib_main_t *vm, u16 icmp_id)
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
static vlib_node_registration_t ip4_icmp_echo_request_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_echo_request_node)
#define VLIB_REGISTER_NODE(x,...)
#define PING_DEFAULT_INTERVAL
static vlib_node_registration_t ip6_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
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.
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
static vlib_node_registration_t ip4_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_echo_reply_node)
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)
u32 fib_node_index_t
A typedef of a node index.
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)
static u32 ip4_fib_index_from_table_id(u32 table_id)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
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)
vlib_main_t vlib_node_runtime_t * node
#define VLIB_CLI_COMMAND(x,...)
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
ping_run_t * active_ping_runs
static_always_inline void ip46_post_icmp_reply_event(vlib_main_t *vm, uword cli_process_id, u32 bi0, int is_ip6)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
#define PING_MAXIMUM_DATA_SIZE
#define PING_CLI_UNKNOWN_NODE
template key/value backing page structure
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)
void icmp6_register_type(vlib_main_t *vm, icmp6_type_t type, u32 node_index)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 next_buffer
Next buffer for this linked-list of buffers.
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.
#define STATIC_ASSERT(truth,...)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static u32 ip46_fib_table_get_index_for_sw_if_index(u32 sw_if_index, int is_ip6)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define ip_csum_update(sum, old, new, type, field)
u16 ip4_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
static void ip46_print_buffer_src_address(vlib_main_t *vm, 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)
vlib_node_registration_t ip4_icmp_input_node
(constructor) VLIB_REGISTER_NODE (ip4_icmp_input_node)
static uword ip6_icmp_echo_reply_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static u32 random_u32(u32 *seed)
32-bit random number generator
ip4_main_t ip4_main
Global ip4 main structure.
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
u16 flags
Copy of main node flags.
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define PING_DEFAULT_DATA_LEN
static int ip4_header_bytes(const ip4_header_t *i)
#define VLIB_NODE_FLAG_TRACE
static clib_error_t * ping_ip_address(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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 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_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)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
static fib_node_index_t ip46_fib_table_lookup_host(u32 fib_index, ip46_address_t *pa46, int is_ip6)
u8 ttl
TTL to use for host generated packets.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
clib_random_buffer_t random_buffer
static u16 ip_csum_fold(ip_csum_t c)
static u8 * format_icmp_input_trace(u8 *s, va_list *va)
static void ip46_address_set_ip4(ip46_address_t *ip46, const ip4_address_t *ip)
vl_api_interface_index_t sw_if_index