51 format (s,
"ICMP%s echo id %d seq %d", t->
is_ip6 ?
"6" :
"4", t->
id,
55 s =
format (s,
" (unknown)");
73 #define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);break; 112 return cli_process_id;
118 uword cli_process_id)
129 goto have_found_and_set;
160 u16 * out_icmp_id,
u16 * out_icmp_seq,
int is_ip6)
166 if (ip6->
protocol != IP_PROTOCOL_ICMP6)
170 l4_offset =
sizeof (*ip6);
179 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
181 *out_icmp_id = clib_net_to_host_u16 (icmp46_echo->id);
182 *out_icmp_seq = clib_net_to_host_u16 (icmp46_echo->seq);
201 sizeof (
vnet_buffer (b0)->unused[0]) >
sizeof (nowts),
202 "ping reply timestamp fits within remaining space of vnet_buffer unused data");
234 u32 n_left_from, *from, *to_next;
242 while (n_left_from > 0)
247 while (n_left_from > 0 && n_left_to_next > 0)
276 icmp_id, icmp_seq, b0,
279 if (~0 == cli_process_id)
288 to_next, n_left_to_next,
338 .name =
"ip6-icmp-echo-reply",
339 .vector_size =
sizeof (
u32),
351 .name =
"ip4-icmp-echo-reply",
352 .vector_size =
sizeof (
u32),
375 return (offset % 256);
381 int l4_header_offset,
382 icmp46_echo_request_t * icmp46_echo,
u16 seq_host,
389 l4_header_offset +
sizeof (icmp46_header_t) +
390 offsetof (icmp46_echo_request_t,
data);
393 int first_buf_data_len = data_len < max_data_len ? data_len : max_data_len;
395 int payload_offset = 0;
396 for (i = 0; i < first_buf_data_len; i++)
401 int remaining_data_len = data_len - first_buf_data_len;
402 while (remaining_data_len)
404 int this_buf_data_len =
412 return (data_len - remaining_data_len);
414 b0->
flags |= VLIB_BUFFER_NEXT_PRESENT;
418 for (i = 0; i < this_buf_data_len; i++)
424 remaining_data_len -= this_buf_data_len;
426 hb->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
430 icmp46_echo->time_sent = now;
431 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
432 icmp46_echo->id = clib_host_to_net_u16 (id_host);
440 u32 fib_index = is_ip6 ?
452 return fib_entry_index;
472 u32 fib_table_index = is_ip6 ?
475 return fib_table_index;
488 clib_host_to_net_u32 (0x6 << 28);
543 void *format_addr_func;
567 icmp46->type = is_ip6 ? ICMP6_echo_request : ICMP4_echo_request;
569 icmp46->checksum = 0;
571 icmp46_echo_request_t *icmp46_echo = (icmp46_echo_request_t *) (icmp46 + 1);
586 u32 ip_header_length, payload_length_host_byte_order;
587 u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
589 void *data_this_buffer;
592 payload_length_host_byte_order =
593 clib_net_to_host_u16 (ip0->
length) - ip_header_length;
598 n_bytes_left = n_this_buffer = payload_length_host_byte_order;
599 data_this_buffer = (
void *) ip0 + ip_header_length;
600 n_ip_bytes_this_buffer =
602 if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
604 n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
605 n_ip_bytes_this_buffer - ip_header_length : 0;
610 n_bytes_left -= n_this_buffer;
611 if (n_bytes_left == 0)
631 data_len +
sizeof (icmp46_header_t) + offsetof (icmp46_echo_request_t,
633 u16 total_length = payload_length + l4_offset;
635 icmp46->checksum = 0;
642 int bogus_length = 0;
649 ip4->
length = clib_host_to_net_u16 (total_length);
667 u32 lookup_node_index =
679 for (n_to_send =
at_most_a_frame (burst), burst -= n_to_send; n_to_send > 0;
688 while (n_to_send > 1)
735 #define ERROR_OUT(e) do { err = e; goto done; } while (0) 740 ip46_address_t * pa46,
743 u8 verbose,
int is_ip6)
745 int err = SEND_PING_OK;
763 if (~0 == sw_if_index)
774 if (~0 == sw_if_index)
790 data_len, b0, is_ip6);
796 err = SEND_PING_NO_BUFFERS;
799 if (err != SEND_PING_OK)
811 u32 burst,
u8 verbose)
813 ip46_address_t target;
815 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
816 id_host, data_len, burst, verbose, 1 );
823 u32 burst,
u8 verbose)
825 ip46_address_t target;
827 return send_ip46_ping (vm, table_id, &target, sw_if_index, seq_host,
828 id_host, data_len, burst, verbose, 0 );
837 void *format_addr_func;
860 icmp46_echo_request_t *icmp_echo = (icmp46_echo_request_t *) (icmp + 1);
865 ((
f64) (*dataplane_ts - icmp_echo->time_sent)) / clocks_per_second;
868 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
872 clib_host_to_net_u16 (icmp_echo->seq), ttl, rtt * 1000.0);
885 f64 ping_interval,
u32 ping_repeat,
u32 data_len,
886 u32 ping_burst,
u32 verbose)
894 static u32 rand_seed = 0;
903 vlib_cli_output (vm,
"ICMP ID collision at %d, incrementing", icmp_id);
909 for (i = 1; i <= ping_repeat; i++)
917 pa6, sw_if_index, i, icmp_id,
918 data_len, ping_burst, verbose);
919 if (SEND_PING_OK == res)
920 n_requests += ping_burst;
927 sw_if_index, i, icmp_id, data_len,
928 ping_burst, verbose);
929 if (SEND_PING_OK == res)
930 n_requests += ping_burst;
937 while ((i <= ping_repeat)
942 uword event_type, *event_data = 0;
955 for (ii = 0; ii <
vec_len (event_data); ii++)
957 u32 bi0 = event_data[ii];
979 n_requests) ? 0 : 100.0 * ((
float) n_requests -
980 (float) n_replies) / (float) n_requests;
982 "Statistics: %u sent, %u received, %f%% packet loss\n",
983 n_requests, n_replies, loss);
999 u8 ping_ip4, ping_ip6;
1007 ping_ip4 = ping_ip6 = 0;
1028 "expecting IPv4 address but got `%U'",
1042 "expecting IPv6 address but got `%U'",
1050 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
1056 if (!ping_ip4 && (
unformat (input,
"ipv4")))
1063 else if (!ping_ip6 && (
unformat (input,
"ipv6")))
1081 "unknown interface `%U'",
1088 if (!
unformat (input,
"%u", &data_len))
1092 "expecting size but got `%U'",
1100 "%d is bigger than maximum allowed payload size %d",
1105 else if (
unformat (input,
"table-id"))
1107 if (!
unformat (input,
"%u", &table_id))
1111 "expecting table-id but got `%U'",
1116 else if (
unformat (input,
"interval"))
1118 if (!
unformat (input,
"%f", &ping_interval))
1122 "expecting interval (floating point number) got `%U'",
1127 else if (
unformat (input,
"repeat"))
1129 if (!
unformat (input,
"%u", &ping_repeat))
1133 "expecting repeat count but got `%U'",
1138 else if (
unformat (input,
"burst"))
1140 if (!
unformat (input,
"%u", &ping_burst))
1144 "expecting burst count but got `%U'",
1149 else if (
unformat (input,
"verbose"))
1167 #define MAX_PING_BURST (10*VLIB_FRAME_SIZE) 1169 #define MAX_PING_BURST (VLIB_FRAME_SIZE) 1177 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
1178 ping_repeat, data_len, ping_burst, verbose);
1229 .short_help =
"ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}" 1230 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]" 1231 " [size <pktsize:60>] [interval <sec:1>] [repeat <cnt:5>] [table-id <id:0>]" 1232 " [burst <count:1>] [verbose]",
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 ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
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 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)