API refactoring : vhost_user
[vpp.git] / vnet / vnet / ip / ping.c
index 0bf83e9..68dbe75 100644 (file)
@@ -36,9 +36,8 @@ format_icmp_echo_trace (u8 * s, va_list * va)
   icmp_echo_trace_t *t = va_arg (*va, icmp_echo_trace_t *);
 
   s = format (s, "ICMP echo id %d seq %d%s",
-              clib_net_to_host_u16(t->id),
-              clib_net_to_host_u16(t->seq),
-              t->bound ? "" : " (unknown)");
+             clib_net_to_host_u16 (t->id),
+             clib_net_to_host_u16 (t->seq), t->bound ? "" : " (unknown)");
 
   return s;
 }
@@ -54,7 +53,7 @@ format_icmp_echo_trace (u8 * s, va_list * va)
 
 static int
 signal_ip46_icmp_reply_event (vlib_main_t * vm,
-                              u8 event_type, vlib_buffer_t * b0)
+                             u8 event_type, vlib_buffer_t * b0)
 {
   ping_main_t *pm = &ping_main;
   u16 net_icmp_id = 0;
@@ -64,14 +63,14 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
     {
     case PING_RESPONSE_IP4:
       {
-        icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
-        net_icmp_id = h0->icmp_echo.id;
+       icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+       net_icmp_id = h0->icmp_echo.id;
       }
       break;
     case PING_RESPONSE_IP6:
       {
-        icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
-        net_icmp_id = h0->icmp_echo.id;
+       icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+       net_icmp_id = h0->icmp_echo.id;
       }
       break;
     default:
@@ -79,7 +78,7 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
     }
 
   uword *p = hash_get (pm->ping_run_by_icmp_id,
-                       clib_net_to_host_u16 (net_icmp_id));
+                      clib_net_to_host_u16 (net_icmp_id));
   if (!p)
     return 0;
 
@@ -100,12 +99,12 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm,
  */
 static uword
 ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
-                             vlib_node_runtime_t * node, vlib_frame_t * frame)
+                            vlib_node_runtime_t * node, vlib_frame_t * frame)
 {
   u32 n_left_from, *from;
 
-  from = vlib_frame_vector_args (frame);        /* array of buffer indices */
-  n_left_from = frame->n_vectors;       /* number of buffer indices */
+  from = vlib_frame_vector_args (frame);       /* array of buffer indices */
+  n_left_from = frame->n_vectors;      /* number of buffer indices */
 
   while (n_left_from > 0)
     {
@@ -117,16 +116,16 @@ ip6_icmp_echo_reply_node_fn (vlib_main_t * vm,
       b0 = vlib_get_buffer (vm, bi0);
 
       next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP6, b0) ?
-        ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
+       ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT;
 
-      if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) 
-         {
-           icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
-           icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
-           tr->id = h0->icmp_echo.id;
-           tr->seq = h0->icmp_echo.seq;
-           tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
-         }
+      if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+       {
+         icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+         icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
+         tr->id = h0->icmp_echo.id;
+         tr->seq = h0->icmp_echo.seq;
+         tr->bound = (next0 == ICMP6_ECHO_REPLY_NEXT_DROP);
+       }
 
       /* push this pkt to the next graph node */
       vlib_set_next_frame_buffer (vm, node, next0, bi0);
@@ -158,12 +157,12 @@ VLIB_REGISTER_NODE (ip6_icmp_echo_reply_node, static) =
  */
 static uword
 ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
-                             vlib_node_runtime_t * node, vlib_frame_t * frame)
+                            vlib_node_runtime_t * node, vlib_frame_t * frame)
 {
   u32 n_left_from, *from;
 
-  from = vlib_frame_vector_args (frame);        /* array of buffer indices */
-  n_left_from = frame->n_vectors;       /* number of buffer indices */
+  from = vlib_frame_vector_args (frame);       /* array of buffer indices */
+  n_left_from = frame->n_vectors;      /* number of buffer indices */
 
   while (n_left_from > 0)
     {
@@ -175,16 +174,16 @@ ip4_icmp_echo_reply_node_fn (vlib_main_t * vm,
       b0 = vlib_get_buffer (vm, bi0);
 
       next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP4, b0) ?
-        ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
+       ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT;
 
-      if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) 
-         {
-           icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
-           icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
-           tr->id = h0->icmp_echo.id;
-           tr->seq = h0->icmp_echo.seq;
-           tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
-         }
+      if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+       {
+         icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
+         icmp_echo_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
+         tr->id = h0->icmp_echo.id;
+         tr->seq = h0->icmp_echo.seq;
+         tr->bound = (next0 == ICMP4_ECHO_REPLY_NEXT_DROP);
+       }
 
       /* push this pkt to the next graph node */
       vlib_set_next_frame_buffer (vm, node, next0, bi0);
@@ -222,23 +221,23 @@ ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
   ip_interface_address_t *ia = 0;
   ip6_address_t *result = 0;
 
+  /* *INDENT-OFF* */
   foreach_ip_interface_address (lm, ia, sw_if_index,
                                 1 /* honor unnumbered */ ,
-                                (
-                                  {
-                                  ip6_address_t * a =
-                                  ip_interface_address_get_address (lm, ia);
-                                  result = a;
-                                  break;
-                                  }
-                                ));
+  ({
+    ip6_address_t * a =
+      ip_interface_address_get_address (lm, ia);
+    result = a;
+    break;
+  }));
+  /* *INDENT-ON* */
   return result;
 }
 
 /* Fill in the ICMP ECHO structure, return the safety-checked and possibly shrunk data_len */
 static u16
 init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
-                          u16 seq_host, u16 id_host, u16 data_len)
+                         u16 seq_host, u16 id_host, u16 data_len)
 {
   int i;
   icmp46_echo->seq = clib_host_to_net_u16 (seq_host);
@@ -256,95 +255,79 @@ init_icmp46_echo_request (icmp46_echo_request_t * icmp46_echo,
   return data_len;
 }
 
-/*
- * Given adj index, return sw_if_index, possibly overwritten
- * by a parameter. There is mostly debug outputs here,
- * but it turned out handy to have these.
- */
-
-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)
-{
-  ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0);
-  u32 sw_if_index0 = adj0->rewrite_header.sw_if_index;
-  if (verbose)
-    {
-      vlib_cli_output (vm, "Adjacency index: %u, sw_if_index: %u\n",
-                       adj_index0, sw_if_index0);
-      vlib_cli_output (vm, "Adj: %s\n",
-                       lookup_next_nodes[adj0->lookup_next_index]);
-      vlib_cli_output (vm, "Adj Interface: %d\n", adj0->if_address_index);
-    }
-
-  if (~0 != sw_if_index)
-    {
-      sw_if_index0 = sw_if_index;
-      if (verbose)
-        {
-          vlib_cli_output (vm, "Forced set interface: %d\n", sw_if_index0);
-        }
-    }
-  return sw_if_index0;
-}
-
 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)
+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)
 {
   icmp6_echo_request_header_t *h0;
   u32 bi0 = 0;
-  u32 sw_if_index0;
-  ip_lookup_main_t *lm = &im->lookup_main;
   int bogus_length = 0;
-  u32 adj_index0;
   vlib_buffer_t *p0;
   vlib_frame_t *f;
   u32 *to_next;
-  u32 fib_index0;
 
   if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
     return SEND_PING_ALLOC_FAIL;
 
   p0 = vlib_get_buffer (vm, bi0);
 
-  /* Determine sw_if_index0 of source intf, may be force-set via sw_if_index. */
-  vnet_buffer (p0)->sw_if_index[VLIB_RX] = 0;
-  vnet_buffer (p0)->sw_if_index[VLIB_TX] = ~0;  /* use interface VRF */
-  fib_index0 = 0;
-  adj_index0 = fib_entry_get_adj(ip6_fib_table_lookup(fib_index0, pa6, 128));
-
-  if (ADJ_INDEX_INVALID == adj_index0)
+  /*
+   * if the user did not provide a source interface, use the any interface
+   * that the destination resolves via.
+   */
+  if (~0 == sw_if_index)
     {
-      vlib_buffer_free (vm, &bi0, 1);
-      return SEND_PING_NO_INTERFACE;
+      fib_node_index_t fib_entry_index;
+      u32 fib_index;
+
+      fib_index = ip6_fib_index_from_table_id (table_id);
+
+      if (~0 == fib_index)
+       {
+         vlib_buffer_free (vm, &bi0, 1);
+         return SEND_PING_NO_TABLE;
+       }
+
+      fib_entry_index = ip6_fib_table_lookup (fib_index, pa6, 128);
+      sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
+      /*
+       * Set the TX interface to force ip-lookup to use its table ID
+       */
+      vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
+    }
+  else
+    {
+      /*
+       * force an IP lookup in the table bound to the user's chosen
+       * source interface.
+       */
+      vnet_buffer (p0)->sw_if_index[VLIB_TX] =
+       ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
     }
 
-  sw_if_index0 =
-    adj_index_to_sw_if_index (vm, lm, ip6_lookup_next_nodes, adj_index0,
-                              sw_if_index, verbose);
-  if ((~0 == sw_if_index0) && (~0 == sw_if_index))
+  if (~0 == sw_if_index)
     {
       vlib_buffer_free (vm, &bi0, 1);
       return SEND_PING_NO_INTERFACE;
     }
-  vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index0;
+
+  vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
 
   h0 = vlib_buffer_get_current (p0);
 
   /* Fill in ip6 header fields */
   h0->ip6.ip_version_traffic_class_and_flow_label =
     clib_host_to_net_u32 (0x6 << 28);
-  h0->ip6.payload_length = 0;   /* Set below */
+  h0->ip6.payload_length = 0;  /* Set below */
   h0->ip6.protocol = IP_PROTOCOL_ICMP6;
   h0->ip6.hop_limit = 255;
   h0->ip6.dst_address = *pa6;
   h0->ip6.src_address = *pa6;
 
   /* Fill in the correct source now */
-  ip6_address_t *a = ip6_interface_first_address (im, sw_if_index0);
+  ip6_address_t *a = ip6_interface_first_address (im, sw_if_index);
   h0->ip6.src_address = a[0];
 
   /* Fill in icmp fields */
@@ -380,20 +363,18 @@ send_ip6_ping (vlib_main_t * vm, ip6_main_t * im, ip6_address_t * pa6,
 
 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)
+              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)
 {
   icmp4_echo_request_header_t *h0;
   u32 bi0 = 0;
-  u32 sw_if_index0;
   ip_lookup_main_t *lm = &im->lookup_main;
-  u32 adj_index0;
   vlib_buffer_t *p0;
   vlib_frame_t *f;
   u32 *to_next;
-  u32 fib_index0;
   u32 if_add_index0;
 
   if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
@@ -401,28 +382,48 @@ send_ip4_ping (vlib_main_t * vm,
 
   p0 = vlib_get_buffer (vm, bi0);
 
-  /* Determine sw_if_index0 of the source intf, may be force-set via sw_if_index.  */
-  vnet_buffer (p0)->sw_if_index[VLIB_RX] = 0;
-  vnet_buffer (p0)->sw_if_index[VLIB_TX] = ~0;  /* use interface VRF */
-  fib_index0 = 0;
-  adj_index0 = fib_entry_get_adj(ip4_fib_table_lookup(
-                                    ip4_fib_get(fib_index0), pa4, 32));
-
-  if (ADJ_INDEX_INVALID == adj_index0)
+  /*
+   * if the user did not provide a source interface, use the any interface
+   * that the destination resolves via.
+   */
+  if (~0 == sw_if_index)
     {
-      vlib_buffer_free (vm, &bi0, 1);
-      return SEND_PING_NO_INTERFACE;
+      fib_node_index_t fib_entry_index;
+      u32 fib_index;
+
+      fib_index = ip4_fib_index_from_table_id (table_id);
+
+      if (~0 == fib_index)
+       {
+         vlib_buffer_free (vm, &bi0, 1);
+         return SEND_PING_NO_TABLE;
+       }
+
+      fib_entry_index =
+       ip4_fib_table_lookup (ip4_fib_get (fib_index), pa4, 32);
+      sw_if_index = fib_entry_get_resolving_interface (fib_entry_index);
+      /*
+       * Set the TX interface to force ip-lookup to use the user's table ID
+       */
+      vnet_buffer (p0)->sw_if_index[VLIB_TX] = fib_index;
+    }
+  else
+    {
+      /*
+       * force an IP lookup in the table bound to the user's chosen
+       * source interface.
+       */
+      vnet_buffer (p0)->sw_if_index[VLIB_TX] =
+       ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
     }
 
-  sw_if_index0 =
-    adj_index_to_sw_if_index (vm, lm, ip4_lookup_next_nodes, adj_index0,
-                              sw_if_index, verbose);
-  if ((~0 == sw_if_index0) && (~0 == sw_if_index))
+  if (~0 == sw_if_index)
     {
       vlib_buffer_free (vm, &bi0, 1);
       return SEND_PING_NO_INTERFACE;
     }
-  vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index0;
+
+  vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
 
   h0 = vlib_buffer_get_current (p0);
 
@@ -430,7 +431,7 @@ send_ip4_ping (vlib_main_t * vm,
   h0->ip4.checksum = 0;
   h0->ip4.ip_version_and_header_length = 0x45;
   h0->ip4.tos = 0;
-  h0->ip4.length = 0;           /* Set below */
+  h0->ip4.length = 0;          /* Set below */
   h0->ip4.fragment_id = 0;
   h0->ip4.flags_and_fragment_offset = 0;
   h0->ip4.ttl = 0xff;
@@ -439,18 +440,18 @@ send_ip4_ping (vlib_main_t * vm,
   h0->ip4.src_address = *pa4;
 
   /* Fill in the correct source now */
-  if_add_index0 = lm->if_address_pool_index_by_sw_if_index[sw_if_index0];
+  if_add_index0 = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
   if (PREDICT_TRUE (if_add_index0 != ~0))
     {
       ip_interface_address_t *if_add =
-        pool_elt_at_index (lm->if_address_pool, if_add_index0);
+       pool_elt_at_index (lm->if_address_pool, if_add_index0);
       ip4_address_t *if_ip = ip_interface_address_get_address (lm, if_add);
       h0->ip4.src_address = *if_ip;
       if (verbose)
-        {
-          vlib_cli_output (vm, "Source address: %U",
-                           format_ip4_address, &h0->ip4.src_address);
-        }
+       {
+         vlib_cli_output (vm, "Source address: %U",
+                          format_ip4_address, &h0->ip4.src_address);
+       }
     }
 
   /* Fill in icmp fields */
@@ -465,7 +466,7 @@ send_ip4_ping (vlib_main_t * vm,
   /* Fix up the lengths */
   h0->ip4.length =
     clib_host_to_net_u16 (data_len + sizeof (icmp46_header_t) +
-                          sizeof (ip4_header_t));
+                         sizeof (ip4_header_t));
 
   p0->current_length = clib_net_to_host_u16 (h0->ip4.length);
 
@@ -473,7 +474,8 @@ send_ip4_ping (vlib_main_t * vm,
   h0->ip4.checksum = ip4_header_checksum (&(h0->ip4));
   h0->icmp.checksum =
     ~ip_csum_fold (ip_incremental_checksum (0, &(h0->icmp),
-                    p0->current_length - sizeof (ip4_header_t)));
+                                           p0->current_length -
+                                           sizeof (ip4_header_t)));
 
   /* Enqueue the packet right now */
   f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
@@ -489,25 +491,23 @@ send_ip4_ping (vlib_main_t * vm,
 static void
 print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0)
 {
-  vlib_buffer_t *b0 = vlib_get_buffer (vm,
-                                       bi0);
+  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
   icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
   f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
 
   vlib_cli_output (vm,
-                   "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
-                   clib_host_to_net_u16 (h0->ip6.payload_length),
-                   format_ip6_address,
-                   &h0->ip6.src_address,
-                   clib_host_to_net_u16 (h0->icmp_echo.seq),
-                   h0->ip6.hop_limit, rtt * 1000.0);
+                  "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
+                  clib_host_to_net_u16 (h0->ip6.payload_length),
+                  format_ip6_address,
+                  &h0->ip6.src_address,
+                  clib_host_to_net_u16 (h0->icmp_echo.seq),
+                  h0->ip6.hop_limit, rtt * 1000.0);
 }
 
 static void
 print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
 {
-  vlib_buffer_t *b0 = vlib_get_buffer (vm,
-                                       bi0);
+  vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
   icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0);
   f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent;
   u32 rcvd_icmp_len =
@@ -515,12 +515,12 @@ print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
     (4 * (0xF & h0->ip4.ip_version_and_header_length));
 
   vlib_cli_output (vm,
-                   "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
-                   rcvd_icmp_len,
-                   format_ip4_address,
-                   &h0->ip4.src_address,
-                   clib_host_to_net_u16 (h0->icmp_echo.seq),
-                   h0->ip4.ttl, rtt * 1000.0);
+                  "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms",
+                  rcvd_icmp_len,
+                  format_ip4_address,
+                  &h0->ip4.src_address,
+                  clib_host_to_net_u16 (h0->icmp_echo.seq),
+                  h0->ip4.ttl, rtt * 1000.0);
 }
 
 
@@ -532,10 +532,10 @@ print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0)
  */
 
 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)
+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)
 {
   int i;
   ping_main_t *pm = &ping_main;
@@ -548,10 +548,10 @@ run_ping_ip46_address (vlib_main_t * vm, ip4_address_t * pa4,
 
   static u32 rand_seed = 0;
 
-  if (PREDICT_FALSE(!rand_seed))
-      rand_seed = random_default_seed();
+  if (PREDICT_FALSE (!rand_seed))
+    rand_seed = random_default_seed ();
 
-  icmp_id = random_u32(&rand_seed) & 0xffff;
+  icmp_id = random_u32 (&rand_seed) & 0xffff;
 
   while (hash_get (pm->ping_run_by_icmp_id, icmp_id))
     {
@@ -571,78 +571,78 @@ run_ping_ip46_address (vlib_main_t * vm, ip4_address_t * pa4,
       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, pa6,
-                                          sw_if_index, i, icmp_id, data_len,
-                                          verbose)))
-        {
-          n_requests++;
-        }
+         (SEND_PING_OK ==
+          send_ip6_ping (vm, ping_main.ip6_main, table_id, pa6, sw_if_index,
+                         i, icmp_id, data_len, verbose)))
+       {
+         n_requests++;
+       }
       if (pa4 &&
-          (SEND_PING_OK == send_ip4_ping (vm, ping_main.ip4_main, pa4,
-                                          sw_if_index, i, icmp_id, data_len,
-                                          verbose)))
-        {
-          n_requests++;
-        }
+         (SEND_PING_OK ==
+          send_ip4_ping (vm, ping_main.ip4_main, table_id, pa4, sw_if_index,
+                         i, icmp_id, data_len, verbose)))
+       {
+         n_requests++;
+       }
       while ((i <= ping_repeat)
-             &&
-             ((sleep_interval =
-               time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
-        {
-          uword event_type, *event_data = 0;
-          vlib_process_wait_for_event_or_clock (vm, sleep_interval);
-          event_type = vlib_process_get_events (vm, &event_data);
-          switch (event_type)
-            {
-            case ~0:           /* no events => timeout */
-              break;
-            case PING_RESPONSE_IP6:
-              {
-                int i;
-                for (i = 0; i < vec_len (event_data); i++)
-                  {
-                    u32 bi0 = event_data[0];
-                    print_ip6_icmp_reply (vm, bi0);
-                    n_replies++;
-                    if (0 != bi0)
-                      {
-                        vlib_buffer_free (vm, &bi0, 1);
-                      }
-                  }
-              }
-              break;
-            case PING_RESPONSE_IP4:
-              {
-                int i;
-                for (i = 0; i < vec_len (event_data); i++)
-                  {
-                    u32 bi0 = event_data[0];
-                    print_ip4_icmp_reply (vm, bi0);
-                    n_replies++;
-                    if (0 != bi0)
-                      {
-                        vlib_buffer_free (vm, &bi0, 1);
-                      }
-                  }
-              }
-              break;
-            default:
-              /* someone pressed a key, abort */
-              vlib_cli_output (vm, "Aborted due to a keypress.");
-              i = 1 + ping_repeat;
-              break;
-            }
-        }
+            &&
+            ((sleep_interval =
+              time_ping_sent + ping_interval - vlib_time_now (vm)) > 0.0))
+       {
+         uword event_type, *event_data = 0;
+         vlib_process_wait_for_event_or_clock (vm, sleep_interval);
+         event_type = vlib_process_get_events (vm, &event_data);
+         switch (event_type)
+           {
+           case ~0:            /* no events => timeout */
+             break;
+           case PING_RESPONSE_IP6:
+             {
+               int i;
+               for (i = 0; i < vec_len (event_data); i++)
+                 {
+                   u32 bi0 = event_data[0];
+                   print_ip6_icmp_reply (vm, bi0);
+                   n_replies++;
+                   if (0 != bi0)
+                     {
+                       vlib_buffer_free (vm, &bi0, 1);
+                     }
+                 }
+             }
+             break;
+           case PING_RESPONSE_IP4:
+             {
+               int i;
+               for (i = 0; i < vec_len (event_data); i++)
+                 {
+                   u32 bi0 = event_data[0];
+                   print_ip4_icmp_reply (vm, bi0);
+                   n_replies++;
+                   if (0 != bi0)
+                     {
+                       vlib_buffer_free (vm, &bi0, 1);
+                     }
+                 }
+             }
+             break;
+           default:
+             /* someone pressed a key, abort */
+             vlib_cli_output (vm, "Aborted due to a keypress.");
+             i = 1 + ping_repeat;
+             break;
+           }
+       }
     }
   vlib_cli_output (vm, "\n");
   {
     float loss =
       (0 ==
        n_requests) ? 0 : 100.0 * ((float) n_requests -
-                                  (float) n_replies) / (float) n_requests;
+                                 (float) n_replies) / (float) n_requests;
     vlib_cli_output (vm,
-                     "Statistics: %u sent, %u received, %f%% packet loss\n",
-                     n_requests, n_replies, loss);
+                    "Statistics: %u sent, %u received, %f%% packet loss\n",
+                    n_requests, n_replies, loss);
     /* Reset pr: running ping in other process could have changed pm->ping_runs */
     pr = vec_elt_at_index (pm->ping_runs, ping_run_index);
     hash_unset (pm->ping_run_by_icmp_id, icmp_id);
@@ -656,7 +656,7 @@ run_ping_ip46_address (vlib_main_t * vm, ip4_address_t * pa4,
 
 static clib_error_t *
 ping_ip_address (vlib_main_t * vm,
-                 unformat_input_t * input, vlib_cli_command_t * cmd)
+                unformat_input_t * input, vlib_cli_command_t * cmd)
 {
   ip4_address_t a4;
   ip6_address_t a6;
@@ -667,9 +667,12 @@ ping_ip_address (vlib_main_t * vm,
   u32 data_len = PING_DEFAULT_DATA_LEN;
   u32 verbose = 0;
   f64 ping_interval = PING_DEFAULT_INTERVAL;
+  u32 sw_if_index, table_id;
+
+  table_id = 0;
   ping_ip4 = ping_ip6 = 0;
-  u32 sw_if_index;
   sw_if_index = ~0;
+
   if (unformat (input, "%U", unformat_ip4_address, &a4))
     {
       ping_ip4 = 1;
@@ -681,37 +684,37 @@ ping_ip_address (vlib_main_t * vm,
   else if (unformat (input, "ipv4"))
     {
       if (unformat (input, "%U", unformat_ip4_address, &a4))
-        {
-          ping_ip4 = 1;
-        }
+       {
+         ping_ip4 = 1;
+       }
       else
-        {
-          error =
-            clib_error_return (0,
-                               "expecting IPv4 address but got `%U'",
-                               format_unformat_error, input);
-        }
+       {
+         error =
+           clib_error_return (0,
+                              "expecting IPv4 address but got `%U'",
+                              format_unformat_error, input);
+       }
     }
   else if (unformat (input, "ipv6"))
     {
       if (unformat (input, "%U", unformat_ip6_address, &a6))
-        {
-          ping_ip6 = 1;
-        }
+       {
+         ping_ip6 = 1;
+       }
       else
-        {
-          error =
-            clib_error_return (0,
-                               "expecting IPv6 address but got `%U'",
-                               format_unformat_error, input);
-        }
+       {
+         error =
+           clib_error_return (0,
+                              "expecting IPv6 address but got `%U'",
+                              format_unformat_error, input);
+       }
     }
   else
     {
       error =
-        clib_error_return (0,
-                           "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
-                           format_unformat_error, input);
+       clib_error_return (0,
+                          "expecting IP4/IP6 address `%U'. Usage: ping <addr> [source <intf>] [size <datasz>] [repeat <count>] [verbose]",
+                          format_unformat_error, input);
       goto done;
     }
 
@@ -719,81 +722,92 @@ ping_ip_address (vlib_main_t * vm,
   if (!ping_ip4 && (unformat (input, "ipv4")))
     {
       if (unformat (input, "%U", unformat_ip4_address, &a4))
-        {
-          ping_ip4 = 1;
-        }
+       {
+         ping_ip4 = 1;
+       }
     }
   else if (!ping_ip6 && (unformat (input, "ipv6")))
     {
       if (unformat (input, "%U", unformat_ip6_address, &a6))
-        {
-          ping_ip6 = 1;
-        }
+       {
+         ping_ip6 = 1;
+       }
     }
 
   /* parse the rest of the parameters  in a cycle */
   while (!unformat_eof (input, NULL))
     {
       if (unformat (input, "source"))
-        {
-          if (!unformat_user
-              (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
-            {
-              error =
-                clib_error_return (0,
-                                   "unknown interface `%U'",
-                                   format_unformat_error, input);
-              goto done;
-            }
-        }
+       {
+         if (!unformat_user
+             (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+           {
+             error =
+               clib_error_return (0,
+                                  "unknown interface `%U'",
+                                  format_unformat_error, input);
+             goto done;
+           }
+       }
       else if (unformat (input, "size"))
-        {
-          if (!unformat (input, "%u", &data_len))
-            {
-              error =
-                clib_error_return (0,
-                                   "expecting size but got `%U'",
-                                   format_unformat_error, input);
-              goto done;
-            }
-        }
+       {
+         if (!unformat (input, "%u", &data_len))
+           {
+             error =
+               clib_error_return (0,
+                                  "expecting size but got `%U'",
+                                  format_unformat_error, input);
+             goto done;
+           }
+       }
+      else if (unformat (input, "table-id"))
+       {
+         if (!unformat (input, "du", &table_id))
+           {
+             error =
+               clib_error_return (0,
+                                  "expecting table-id but got `%U'",
+                                  format_unformat_error, input);
+             goto done;
+           }
+       }
       else if (unformat (input, "interval"))
-        {
-          if (!unformat (input, "%f", &ping_interval))
-            {
-              error =
-                clib_error_return (0,
-                                   "expecting interval (floating point number) got `%U'",
-                                   format_unformat_error, input);
-              goto done;
-            }
-        }
+       {
+         if (!unformat (input, "%f", &ping_interval))
+           {
+             error =
+               clib_error_return (0,
+                                  "expecting interval (floating point number) got `%U'",
+                                  format_unformat_error, input);
+             goto done;
+           }
+       }
       else if (unformat (input, "repeat"))
-        {
-          if (!unformat (input, "%u", &ping_repeat))
-            {
-              error =
-                clib_error_return (0,
-                                   "expecting repeat count but got `%U'",
-                                   format_unformat_error, input);
-              goto done;
-            }
-        }
+       {
+         if (!unformat (input, "%u", &ping_repeat))
+           {
+             error =
+               clib_error_return (0,
+                                  "expecting repeat count but got `%U'",
+                                  format_unformat_error, input);
+             goto done;
+           }
+       }
       else if (unformat (input, "verbose"))
-        {
-          verbose = 1;
-        }
+       {
+         verbose = 1;
+       }
       else
-        {
-          error = clib_error_return (0, "unknown input `%U'",
-                                     format_unformat_error, input);
-          goto done;
-        }
+       {
+         error = clib_error_return (0, "unknown input `%U'",
+                                    format_unformat_error, input);
+         goto done;
+       }
     }
 
-  run_ping_ip46_address (vm, ping_ip4 ? &a4 : NULL, ping_ip6 ? &a6 : NULL,
-                         sw_if_index, ping_interval, ping_repeat, data_len,
-                         verbose);
+  run_ping_ip46_address (vm, table_id, ping_ip4 ? &a4 : NULL,
+                        ping_ip6 ? &a6 : NULL, sw_if_index, ping_interval,
+                        ping_repeat, data_len, verbose);
 done:
   return error;
 }
@@ -844,7 +858,10 @@ VLIB_CLI_COMMAND (ping_command, static) =
 {
   .path = "ping",
   .function = ping_ip_address,
-  .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]",
+  .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>] [table-id <id>]"
+  " [verbose]",
 };
 /* *INDENT-ON* */
 
@@ -856,8 +873,16 @@ ping_cli_init (vlib_main_t * vm)
   pm->ip4_main = &ip4_main;
   icmp6_register_type (vm, ICMP6_echo_reply, ip6_icmp_echo_reply_node.index);
   ip4_icmp_register_type (vm, ICMP4_echo_reply,
-                          ip4_icmp_echo_reply_node.index);
+                         ip4_icmp_echo_reply_node.index);
   return 0;
 }
 
 VLIB_INIT_FUNCTION (ping_cli_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */