Ping; report failures to the terminal 90/15290/3
authorNeale Ranns <nranns@cisco.com>
Mon, 15 Oct 2018 12:47:58 +0000 (05:47 -0700)
committerDamjan Marion <dmarion@me.com>
Tue, 16 Oct 2018 11:35:46 +0000 (11:35 +0000)
Change-Id: Icd48de31302f62c59961c573699a1dd0474b8acb
Signed-off-by: Neale Ranns <nranns@cisco.com>
src/vnet/ip/ping.c
src/vnet/ip/ping.h

index 096b2eb..029e06c 100755 (executable)
@@ -46,6 +46,21 @@ format_icmp_echo_trace (u8 * s, va_list * va)
   return s;
 }
 
+static u8 *
+format_ip46_ping_result (u8 * s, va_list * args)
+{
+  send_ip46_ping_result_t res = va_arg (*args, send_ip46_ping_result_t);
+
+  switch (res)
+    {
+#define _(v, n) case SEND_PING_##v: s = format(s, "%s", n);
+      foreach_ip46_ping_result
+#undef _
+    }
+
+  return (s);
+}
+
 /*
  * If we can find the ping run by an ICMP ID, then we send the signal
  * to the CLI process referenced by that ping run, alongside with
@@ -582,25 +597,30 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4,
   hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index);
   for (i = 1; i <= ping_repeat; i++)
     {
+      send_ip46_ping_result_t res = SEND_PING_OK;
       f64 sleep_interval;
       f64 time_ping_sent = vlib_time_now (vm);
       /* Reset pr: running ping in other process could have changed pm->ping_runs */
       pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
       pr->curr_seq = i;
-      if (pa6 &&
-         (SEND_PING_OK ==
-          send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index,
-                         i, icmp_id, data_len, ping_burst, verbose)))
+      if (pa6)
        {
-         n_requests += ping_burst;
+         res = send_ip6_ping (vm, ping_main.ip6_main, table_id,
+                              pa6, sw_if_index, i, icmp_id,
+                              data_len, ping_burst, verbose);
        }
-      if (pa4 &&
-         (SEND_PING_OK ==
-          send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index,
-                         i, icmp_id, data_len, ping_burst, verbose)))
+      if (pa4)
+       {
+         res = send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4,
+                              sw_if_index, i, icmp_id, data_len,
+                              ping_burst, verbose);
+       }
+      if (SEND_PING_OK == res)
        {
          n_requests += ping_burst;
        }
+      else
+       vlib_cli_output (vm, "Failed: %U", format_ip46_ping_result, res);
       while ((i <= ping_repeat)
             &&
             ((sleep_interval =
index 3f7488f..442ba73 100644 (file)
@@ -26,13 +26,18 @@ typedef enum
   PING_RESPONSE_IP4,
 } ping_response_type_t;
 
+#define foreach_ip46_ping_result                                      \
+  _ (OK, "OK")                                                        \
+  _ (ALLOC_FAIL, "packet allocation failed")                          \
+  _ (NO_INTERFACE, "no egress interface")                             \
+  _ (NO_TABLE, "no IPv6 Table for lookup")                            \
+  _ (NO_SRC_ADDRESS, "no source address for egress interface")        \
+
 typedef enum
 {
-  SEND_PING_OK = 0,
-  SEND_PING_ALLOC_FAIL,
-  SEND_PING_NO_INTERFACE,
-  SEND_PING_NO_TABLE,
-  SEND_PING_NO_SRC_ADDRESS,
+#define _(v, s) SEND_PING_##v,
+    foreach_ip46_ping_result
+#undef _
 } send_ip46_ping_result_t;
 
 /*