38 s =
format (s,
"ICMP echo id %d seq %d%s",
39 clib_net_to_host_u16 (t->
id),
40 clib_net_to_host_u16 (t->
seq), t->
bound ?
"" :
" (unknown)");
67 net_icmp_id = h0->icmp_echo.id;
73 net_icmp_id = h0->icmp_echo.id;
81 clib_net_to_host_u16 (net_icmp_id));
104 u32 n_left_from, *from;
109 while (n_left_from > 0)
125 tr->
id = h0->icmp_echo.id;
126 tr->
seq = h0->icmp_echo.seq;
144 .name =
"ip6-icmp-echo-reply",
145 .vector_size =
sizeof (
u32),
162 u32 n_left_from, *from;
167 while (n_left_from > 0)
183 tr->
id = h0->icmp_echo.id;
184 tr->
seq = h0->icmp_echo.seq;
202 .name =
"ip4-icmp-echo-reply",
203 .vector_size =
sizeof (
u32),
243 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
244 icmp46_echo->id = clib_host_to_net_u16 (id_host);
246 for (i = 0; i <
sizeof (icmp46_echo->data); i++)
248 icmp46_echo->data[
i] = i % 256;
251 if (data_len >
sizeof (icmp46_echo_request_t))
253 data_len =
sizeof (icmp46_echo_request_t);
261 u32 sw_if_index,
u16 seq_host,
u16 id_host,
u16 data_len,
264 icmp6_echo_request_header_t *h0;
266 int bogus_length = 0;
280 if (~0 == sw_if_index)
310 if (~0 == sw_if_index)
321 h0->ip6.ip_version_traffic_class_and_flow_label =
322 clib_host_to_net_u32 (0x6 << 28);
323 h0->ip6.payload_length = 0;
324 h0->ip6.protocol = IP_PROTOCOL_ICMP6;
325 h0->ip6.hop_limit = 255;
326 h0->ip6.dst_address = *pa6;
327 h0->ip6.src_address = *pa6;
331 h0->ip6.src_address = a[0];
334 h0->icmp.type = ICMP6_echo_request;
336 h0->icmp.checksum = 0;
343 h0->ip6.payload_length =
344 clib_host_to_net_u16 (data_len +
sizeof (icmp46_header_t));
346 p0->
current_length = clib_net_to_host_u16 (h0->ip6.payload_length) +
350 h0->icmp.checksum = 0;
370 u16 seq_host,
u16 id_host,
u16 data_len,
u8 verbose)
372 icmp4_echo_request_header_t *h0;
389 if (~0 == sw_if_index)
420 if (~0 == sw_if_index)
431 h0->ip4.checksum = 0;
432 h0->ip4.ip_version_and_header_length = 0x45;
435 h0->ip4.fragment_id = 0;
436 h0->ip4.flags_and_fragment_offset = 0;
438 h0->ip4.protocol = IP_PROTOCOL_ICMP;
439 h0->ip4.dst_address = *pa4;
440 h0->ip4.src_address = *pa4;
449 h0->ip4.src_address = *if_ip;
458 h0->icmp.type = ICMP4_echo_request;
460 h0->icmp.checksum = 0;
468 clib_host_to_net_u16 (data_len +
sizeof (icmp46_header_t) +
499 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
500 clib_host_to_net_u16 (h0->ip6.payload_length),
502 &h0->ip6.src_address,
503 clib_host_to_net_u16 (h0->icmp_echo.seq),
504 h0->ip6.hop_limit, rtt * 1000.0);
514 clib_host_to_net_u16 (h0->ip4.length) -
515 (4 * (0xF & h0->ip4.ip_version_and_header_length));
518 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
521 &h0->ip4.src_address,
522 clib_host_to_net_u16 (h0->icmp_echo.seq),
523 h0->ip4.ttl, rtt * 1000.0);
537 f64 ping_interval,
u32 ping_repeat,
u32 data_len,
546 u32 ping_run_index = 0;
549 static u32 rand_seed = 0;
558 vlib_cli_output (vm,
"ICMP ID collision at %d, incrementing", icmp_id);
566 for (i = 1; i <= ping_repeat; i++)
576 i, icmp_id, data_len, verbose)))
583 i, icmp_id, data_len, verbose)))
587 while ((i <= ping_repeat)
592 uword event_type, *event_data = 0;
602 for (i = 0; i <
vec_len (event_data); i++)
604 u32 bi0 = event_data[0];
617 for (i = 0; i <
vec_len (event_data); i++)
619 u32 bi0 = event_data[0];
641 n_requests) ? 0 : 100.0 * ((
float) n_requests -
642 (float) n_replies) / (float) n_requests;
644 "Statistics: %u sent, %u received, %f%% packet loss\n",
645 n_requests, n_replies, loss);
665 u8 ping_ip4, ping_ip6;
670 u32 sw_if_index, table_id;
673 ping_ip4 = ping_ip6 = 0;
694 "expecting IPv4 address but got `%U'",
708 "expecting IPv6 address but got `%U'",
716 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
722 if (!ping_ip4 && (
unformat (input,
"ipv4")))
729 else if (!ping_ip6 && (
unformat (input,
"ipv6")))
747 "unknown interface `%U'",
754 if (!
unformat (input,
"%u", &data_len))
758 "expecting size but got `%U'",
763 else if (
unformat (input,
"table-id"))
765 if (!
unformat (input,
"du", &table_id))
769 "expecting table-id but got `%U'",
774 else if (
unformat (input,
"interval"))
776 if (!
unformat (input,
"%f", &ping_interval))
780 "expecting interval (floating point number) got `%U'",
785 else if (
unformat (input,
"repeat"))
787 if (!
unformat (input,
"%u", &ping_repeat))
791 "expecting repeat count but got `%U'",
796 else if (
unformat (input,
"verbose"))
809 ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
810 ping_repeat, data_len, verbose);
861 .short_help =
"ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>}" 862 " [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>]" 863 " [size <pktsize>] [interval <sec>] [repeat <cnt>] [table-id <id>]" #define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
char * ip6_lookup_next_nodes[]
char * ip4_lookup_next_nodes[]
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
static send_ip46_ping_result_t send_ip6_ping(vlib_main_t *vm, ip6_main_t *im, u32 table_id, ip6_address_t *pa6, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
#define IP6_LOOKUP_NEXT_NODES
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...
#define hash_unset(h, key)
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
ip_interface_address_t * if_address_pool
Pool of addresses that are assigned to interfaces.
static uword vlib_current_process(vlib_main_t *vm)
static f64 vlib_time_now(vlib_main_t *vm)
static u16 init_icmp46_echo_request(icmp46_echo_request_t *icmp46_echo, u16 seq_host, u16 id_host, u16 data_len)
#define STRUCT_OFFSET_OF(t, f)
ip_lookup_main_t lookup_main
unformat_function_t unformat_vnet_sw_interface
static void print_ip6_icmp_reply(vlib_main_t *vm, u32 bi0)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u8 * format_icmp_echo_trace(u8 *s, va_list *va)
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)
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 verbose)
vnet_main_t * vnet_get_main(void)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
#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 void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static send_ip46_ping_result_t send_ip4_ping(vlib_main_t *vm, ip4_main_t *im, u32 table_id, ip4_address_t *pa4, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static int signal_ip46_icmp_reply_event(vlib_main_t *vm, u8 event_type, vlib_buffer_t *b0)
#define IP4_LOOKUP_NEXT_NODES
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
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)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static ip6_address_t * ip6_interface_first_address(ip6_main_t *im, u32 sw_if_index)
static u32 ip6_fib_index_from_table_id(u32 table_id)
#define pool_put(P, E)
Free an object E in pool P.
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
The IPv4 FIB.
#define PING_DEFAULT_INTERVAL
static vlib_node_registration_t ip6_icmp_echo_reply_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node)
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)
#define clib_memcpy(a, b, c)
u32 fib_node_index_t
A typedef of a node index.
static u32 ip4_fib_index_from_table_id(u32 table_id)
#define VLIB_CLI_COMMAND(x,...)
u32 * if_address_pool_index_by_sw_if_index
Head of doubly linked list of interface addresses for each software interface.
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)
ip_lookup_main_t lookup_main
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static void print_ip4_icmp_reply(vlib_main_t *vm, u32 bi0)
u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
#define VLIB_BUFFER_IS_TRACED
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
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)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
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
#define VLIB_REGISTER_NODE(x,...)
ip4_main_t ip4_main
Global ip4 main structure.
ping_run_t * ping_run_by_icmp_id
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
#define PING_DEFAULT_DATA_LEN
#define clib_error_return(e, args...)
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static clib_error_t * ping_ip_address(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
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)