23 #include <vpp/app/version.h> 56 format (s,
"ICMP%s echo id %d seq %d", t->
is_ip6 ?
"6" :
"4", t->
id,
60 s =
format (s,
" (unknown)");
78 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break; 117 return cli_process_id;
123 uword cli_process_id)
134 goto have_found_and_set;
165 u16 * out_icmp_id,
u16 * out_icmp_seq,
int is_ip6)
171 if (ip6->
protocol != IP_PROTOCOL_ICMP6)
175 l4_offset =
sizeof (*ip6);
184 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
186 *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
187 *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
206 sizeof (
vnet_buffer (b0)->unused[0]) >
sizeof (nowts),
207 "ping reply timestamp fits within remaining space of vnet_buffer unused data");
239 u32 n_left_from, *from, *to_next;
247 while (n_left_from > 0)
252 while (n_left_from > 0 && n_left_to_next > 0)
281 icmp_id, icmp_seq, b0,
284 if (~0 == cli_process_id)
293 to_next, n_left_to_next,
343 .name =
"ip6-icmp-echo-reply",
344 .vector_size =
sizeof (
u32),
356 .name =
"ip4-icmp-echo-reply",
357 .vector_size =
sizeof (
u32),
380 return (offset % 256);
386 int l4_header_offset,
387 icmp46_echo_request_t * icmp46_echo,
u16 seq_host,
394 l4_header_offset +
sizeof (icmp46_header_t) +
395 offsetof (icmp46_echo_request_t,
data);
398 int first_buf_data_len = data_len < max_data_len ? data_len : max_data_len;
400 int payload_offset = 0;
401 for (i = 0; i < first_buf_data_len; i++)
406 int remaining_data_len = data_len - first_buf_data_len;
407 while (remaining_data_len)
409 int this_buf_data_len =
417 return (data_len - remaining_data_len);
419 b0->
flags |= VLIB_BUFFER_NEXT_PRESENT;
423 for (i = 0; i < this_buf_data_len; i++)
429 remaining_data_len -= this_buf_data_len;
431 hb->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
435 icmp46_echo->time_sent = now;
436 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
437 icmp46_echo->id = clib_host_to_net_u16 (id_host);
445 u32 fib_index = is_ip6 ?
457 return fib_entry_index;
477 u32 fib_table_index = is_ip6 ?
480 return fib_table_index;
493 clib_host_to_net_u32 (0x6 << 28);
548 void *format_addr_func;
572 icmp46->type = is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
574 icmp46->checksum = 0;
576 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
591 u32 ip_header_length, payload_length_host_byte_order;
592 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
594 void *data_this_buffer;
597 payload_length_host_byte_order =
598 clib_net_to_host_u16 (ip0->
length) - ip_header_length;
603 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
604 data_this_buffer = (
void *) ip0 + ip_header_length;
605 n_ip_bytes_this_buffer =
607 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
609 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
610 n_ip_bytes_this_buffer - ip_header_length : 0;
615 n_bytes_left -= n_this_buffer;
616 if (n_bytes_left == 0)
636 data_len +
sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
638 u16 total_length = payload_length + l4_offset;
640 icmp46->checksum = 0;
647 int bogus_length = 0;
654 ip4->
length = clib_host_to_net_u16 (total_length);
672 u32 lookup_node_index =
684 for (n_to_send =
at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
693 while (n_to_send > 1)
730 ASSERT (n_to_send <= f->n_vectors);
742 #define ERROR_OUT(e) do { err = e; goto done; } while (0) 747 ip46_address_t * pa46,
750 u8 verbose,
int is_ip6)
752 int err = SEND_PING_OK;
770 if (~0 == sw_if_index)
781 if (~0 == sw_if_index)
797 data_len, b0, is_ip6);
803 err = SEND_PING_NO_BUFFERS;
806 if (err != SEND_PING_OK)
818 u32 burst,
u8 verbose)
820 ip46_address_t target;
822 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
823 id_host, data_len, burst, verbose, 1 );
830 u32 burst,
u8 verbose)
832 ip46_address_t target;
834 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
835 id_host, data_len, burst, verbose, 0 );
844 void *format_addr_func;
867 icmp46_echo_request_t *icmp_echo = (icmp46_echo_request_t *) (icmp + 1);
872 ((
f64) (*dataplane_ts - icmp_echo->time_sent)) / clocks_per_second;
875 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
879 clib_host_to_net_u16 (icmp_echo->seq), ttl, rtt * 1000.0);
892 f64 ping_interval,
u32 ping_repeat,
u32 data_len,
893 u32 ping_burst,
u32 verbose)
901 static u32 rand_seed = 0;
910 vlib_cli_output (vm,
"ICMP ID collision at %d, incrementing", icmp_id);
916 for (i = 1; i <= ping_repeat; i++)
924 pa6, sw_if_index, i, icmp_id,
925 data_len, ping_burst, verbose);
926 if (SEND_PING_OK == res)
927 n_requests += ping_burst;
934 sw_if_index, i, icmp_id, data_len,
935 ping_burst, verbose);
936 if (SEND_PING_OK == res)
937 n_requests += ping_burst;
944 while ((i <= ping_repeat)
949 uword event_type, *event_data = 0;
962 for (ii = 0; ii <
vec_len (event_data); ii++)
964 u32 bi0 = event_data[ii];
986 n_requests) ? 0 : 100.0 * ((
float) n_requests -
987 (float) n_replies) / (float) n_requests;
989 "Statistics: %u sent, %u received, %f%% packet loss\n",
990 n_requests, n_replies, loss);
1004 u32 ping_repeat = 5;
1006 u8 ping_ip4, ping_ip6;
1014 ping_ip4 = ping_ip6 = 0;
1035 "expecting IPv4 address but got `%U'",
1049 "expecting IPv6 address but got `%U'",
1057 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
1063 if (!ping_ip4 && (
unformat (input,
"ipv4")))
1070 else if (!ping_ip6 && (
unformat (input,
"ipv6")))
1088 "unknown interface `%U'",
1095 if (!
unformat (input,
"%u", &data_len))
1099 "expecting size but got `%U'",
1107 "%d is bigger than maximum allowed payload size %d",
1112 else if (
unformat (input,
"table-id"))
1114 if (!
unformat (input,
"%u", &table_id))
1118 "expecting table-id but got `%U'",
1123 else if (
unformat (input,
"interval"))
1125 if (!
unformat (input,
"%f", &ping_interval))
1129 "expecting interval (floating point number) got `%U'",
1134 else if (
unformat (input,
"repeat"))
1136 if (!
unformat (input,
"%u", &ping_repeat))
1140 "expecting repeat count but got `%U'",
1145 else if (
unformat (input,
"burst"))
1147 if (!
unformat (input,
"%u", &ping_burst))
1151 "expecting burst count but got `%U'",
1156 else if (
unformat (input,
"verbose"))
1174 #define MAX_PING_BURST (10*VLIB_FRAME_SIZE) 1176 #define MAX_PING_BURST (VLIB_FRAME_SIZE) 1184 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
1185 ping_repeat, data_len, ping_burst, verbose);
1236 .short_help =
"ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}" 1237 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]" 1238 " [size <pktsize:60>] [interval <sec:1>] [repeat <cnt:5>] [table-id <id:0>]" 1239 " [burst <count:1>] [verbose]",
1264 .version = VPP_BUILD_VER,
1265 .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.
static int ip46_set_src_address(u32 sw_if_index, vlib_buffer_t *b0, int is_ip6)
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 f64 vlib_time_now(vlib_main_t *vm)
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)
ip_lookup_main_t lookup_main
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)
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
vl_api_interface_index_t sw_if_index
#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...
static u16 at_most_a_frame(u32 count)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define clib_error_return(e, args...)
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)
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 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.
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 int ip6_src_address_for_packet(ip_lookup_main_t *lm, u32 sw_if_index, const ip6_address_t *dst, ip6_address_t *src)
#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)
#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)
#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)
ip_lookup_main_t lookup_main
#define PING_MAXIMUM_DATA_SIZE
#define ip46_address_set_ip4(ip46, ip)
#define PING_CLI_UNKNOWN_NODE
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
template key/value backing page structure
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.
#define STATIC_ASSERT(truth,...)
#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.
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)
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.
#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 u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static fib_node_index_t ip46_fib_table_lookup_host(u32 fib_index, ip46_address_t *pa46, int is_ip6)
static int ip4_src_address_for_packet(ip_lookup_main_t *lm, u32 sw_if_index, ip4_address_t *src)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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)
static u16 ip_csum_fold(ip_csum_t c)