66 net_icmp_id = h0->icmp_echo.id;
72 net_icmp_id = h0->icmp_echo.id;
80 clib_net_to_host_u16 (net_icmp_id));
102 u32 n_left_from, *from;
107 while (n_left_from > 0)
133 .name =
"ip6-icmp-echo-reply",
134 .vector_size =
sizeof (
u32),
150 u32 n_left_from, *from;
155 while (n_left_from > 0)
181 .name =
"ip4-icmp-echo-reply",
182 .vector_size =
sizeof (
u32),
221 icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
222 icmp46_echo->id = clib_host_to_net_u16 (id_host);
224 for (i = 0; i <
sizeof (icmp46_echo->data); i++)
226 icmp46_echo->data[
i] = i % 256;
229 if (data_len >
sizeof (icmp46_echo_request_t))
231 data_len =
sizeof (icmp46_echo_request_t);
244 char *lookup_next_nodes[],
u32 adj_index0,
245 u32 sw_if_index,
u8 verbose)
248 u32 sw_if_index0 = adj0->rewrite_header.sw_if_index;
252 adj_index0, sw_if_index0);
258 if (~0 != sw_if_index)
260 sw_if_index0 = sw_if_index;
271 u32 sw_if_index,
u16 seq_host,
u16 id_host,
u16 data_len,
274 icmp6_echo_request_header_t *h0;
278 int bogus_length = 0;
304 sw_if_index, verbose);
305 if ((~0 == sw_if_index0) && (~0 == sw_if_index))
315 h0->ip6.ip_version_traffic_class_and_flow_label =
316 clib_host_to_net_u32 (0x6 << 28);
317 h0->ip6.payload_length = 0;
318 h0->ip6.protocol = IP_PROTOCOL_ICMP6;
319 h0->ip6.hop_limit = 255;
320 h0->ip6.dst_address = *pa6;
321 h0->ip6.src_address = *pa6;
325 h0->ip6.src_address = a[0];
328 h0->icmp.type = ICMP6_echo_request;
330 h0->icmp.checksum = 0;
337 h0->ip6.payload_length =
338 clib_host_to_net_u16 (data_len +
sizeof (icmp46_header_t));
340 p0->
current_length = clib_net_to_host_u16 (h0->ip6.payload_length) +
344 h0->icmp.checksum = 0;
363 u16 seq_host,
u16 id_host,
u16 data_len,
u8 verbose)
365 icmp4_echo_request_header_t *h0;
396 sw_if_index, verbose);
397 if ((~0 == sw_if_index0) && (~0 == sw_if_index))
407 h0->ip4.checksum = 0;
408 h0->ip4.ip_version_and_header_length = 0x45;
411 h0->ip4.fragment_id = 0;
412 h0->ip4.flags_and_fragment_offset = 0;
414 h0->ip4.protocol = IP_PROTOCOL_ICMP;
415 h0->ip4.dst_address = *pa4;
416 h0->ip4.src_address = *pa4;
425 h0->ip4.src_address = *if_ip;
434 h0->icmp.type = ICMP4_echo_request;
436 h0->icmp.checksum = 0;
444 clib_host_to_net_u16 (data_len +
sizeof (icmp46_header_t) +
475 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
476 clib_host_to_net_u16 (h0->ip6.payload_length),
478 &h0->ip6.src_address,
479 clib_host_to_net_u16 (h0->icmp_echo.seq),
480 h0->ip6.hop_limit, rtt * 1000.0);
491 clib_host_to_net_u16 (h0->ip4.length) -
492 (4 * (0xF & h0->ip4.ip_version_and_header_length));
495 "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
498 &h0->ip4.src_address,
499 clib_host_to_net_u16 (h0->icmp_echo.seq),
500 h0->ip4.ttl, rtt * 1000.0);
514 f64 ping_interval,
u32 ping_repeat,
u32 data_len,
523 u32 ping_run_index = 0;
526 static u32 rand_seed = 0;
535 vlib_cli_output (vm,
"ICMP ID collision at %d, incrementing", icmp_id);
543 for (i = 1; i <= ping_repeat; i++)
552 sw_if_index, i, icmp_id, data_len,
559 sw_if_index, i, icmp_id, data_len,
564 while ((i <= ping_repeat)
569 uword event_type, *event_data = 0;
579 for (i = 0; i <
vec_len (event_data); i++)
581 u32 bi0 = event_data[0];
594 for (i = 0; i <
vec_len (event_data); i++)
596 u32 bi0 = event_data[0];
618 n_requests) ? 0 : 100.0 * ((
float) n_requests -
619 (float) n_replies) / (float) n_requests;
621 "Statistics: %u sent, %u received, %f%% packet loss\n",
622 n_requests, n_replies, loss);
642 u8 ping_ip4, ping_ip6;
647 ping_ip4 = ping_ip6 = 0;
668 "expecting IPv4 address but got `%U'",
682 "expecting IPv6 address but got `%U'",
690 "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
696 if (!ping_ip4 && (
unformat (input,
"ipv4")))
703 else if (!ping_ip6 && (
unformat (input,
"ipv6")))
721 "unknown interface `%U'",
728 if (!
unformat (input,
"%u", &data_len))
732 "expecting size but got `%U'",
737 else if (
unformat (input,
"interval"))
739 if (!
unformat (input,
"%f", &ping_interval))
743 "expecting interval (floating point number) got `%U'",
748 else if (
unformat (input,
"repeat"))
750 if (!
unformat (input,
"%u", &ping_repeat))
754 "expecting repeat count but got `%U'",
759 else if (
unformat (input,
"verbose"))
772 sw_if_index, ping_interval, ping_repeat, data_len,
824 .short_help =
"ping {<ip-addr> | ipv4 <ip4-addr> | ipv6 <ip6-addr>} [ipv4 <ip4-addr> | ipv6 <ip6-addr>] [source <interface>] [size <pktsize>] [interval <sec>] [repeat <cnt>] [verbose]",
#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
#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).
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)
vnet_main_t * vnet_get_main(void)
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.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define IP4_LOOKUP_NEXT_NODES
adj_index_t fib_entry_get_adj(fib_node_index_t fib_entry_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 ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static send_ip46_ping_result_t send_ip4_ping(vlib_main_t *vm, ip4_main_t *im, ip4_address_t *pa4, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
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)
#define pool_put(P, E)
Free an object E in pool P.
static send_ip46_ping_result_t send_ip6_ping(vlib_main_t *vm, ip6_main_t *im, ip6_address_t *pa6, u32 sw_if_index, u16 seq_host, u16 id_host, u16 data_len, u8 verbose)
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,...)
static void signal_ip46_icmp_reply_event(vlib_main_t *vm, u8 event_type, vlib_buffer_t *b0)
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)
static u32 adj_index_to_sw_if_index(vlib_main_t *vm, ip_lookup_main_t *lm, char *lookup_next_nodes[], u32 adj_index0, u32 sw_if_index, u8 verbose)
#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)
static void run_ping_ip46_address(vlib_main_t *vm, ip4_address_t *pa4, ip6_address_t *pa6, u32 sw_if_index, f64 ping_interval, u32 ping_repeat, u32 data_len, u32 verbose)
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.
u32 if_address_index
Interface address index for this local/arp adjacency.
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.
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)
u8 * format_icmp4_input_trace(u8 *s, va_list *va)
ip_lookup_next_t lookup_next_index
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)
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)
static ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
format_function_t format_icmp6_input_trace