Use arbitrary FIB for IPFIX 96/1896/3
authorJuraj Sloboda <jsloboda@cisco.com>
Fri, 1 Jul 2016 13:12:58 +0000 (06:12 -0700)
committerDamjan Marion <dmarion.lists@gmail.com>
Thu, 7 Jul 2016 20:28:14 +0000 (20:28 +0000)
Change-Id: I85b3543a3f72a10e15c252e04ce2e4a390513ca9
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
vnet/vnet/flow/flow_report.c
vnet/vnet/flow/flow_report.h
vnet/vnet/flow/flow_report_sample.c

index ece6eb0..97ff277 100644 (file)
@@ -66,8 +66,7 @@ int send_template_packet (flow_report_main_t *frm,
   b0->current_length = vec_len (fr->rewrite);
   b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
   vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
-  /* $$$ for now, look up in fib-0. Later: arbitrary TX fib */
-  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
+  vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
 
   tp = vlib_buffer_get_current (b0);
   ip = (ip4_header_t *) &tp->ip4;
@@ -217,6 +216,8 @@ set_ipfix_command_fn (vlib_main_t * vm,
 {
   flow_report_main_t * frm = &flow_report_main;
   ip4_address_t collector, src;
+  u32 fib_id;
+  u32 fib_index = ~0;
   
   collector.as_u32 = 0;
   src.as_u32 = 0;
@@ -226,6 +227,15 @@ set_ipfix_command_fn (vlib_main_t * vm,
       ;
     else if (unformat (input, "src %U", unformat_ip4_address, &src))
       ;
+    else if (unformat (input, "fib-id %u", &fib_id))
+      {
+        ip4_main_t * im = &ip4_main;
+        uword * p = hash_get (im->fib_index_by_table_id, fib_id);
+        if (! p)
+          return clib_error_return (0, "fib ID %d doesn't exist\n",
+                                    fib_id);
+        fib_index = p[0];
+      }
     else
       break;
   }
@@ -238,10 +248,11 @@ set_ipfix_command_fn (vlib_main_t * vm,
 
   frm->ipfix_collector.as_u32 = collector.as_u32;
   frm->src_address.as_u32 = src.as_u32;
+  frm->fib_index = fib_index;
   
-  vlib_cli_output (vm, "Collector %U, src address %U",
+  vlib_cli_output (vm, "Collector %U, src address %U, fib index %d",
                    format_ip4_address, &frm->ipfix_collector,
-                   format_ip4_address, &frm->src_address);
+                   format_ip4_address, &frm->src_address, fib_index);
   
   /* Turn on the flow reporting process */
   vlib_process_signal_event (vm, flow_report_process_node.index,
@@ -251,7 +262,8 @@ set_ipfix_command_fn (vlib_main_t * vm,
 
 VLIB_CLI_COMMAND (set_ipfix_command, static) = {
     .path = "set ipfix",
-    .short_help = "set ipfix collector <ip4-address> src <ip4-address>",
+    .short_help = "set ipfix collector <ip4-address> "
+                  "src <ip4-address> [fib-id <fib-id>]",
     .function = set_ipfix_command_fn,
 };
 
index e4c7767..518e7b0 100644 (file)
@@ -74,9 +74,10 @@ typedef struct flow_report {
 typedef struct flow_report_main {
   flow_report_t * reports;
 
-  /* ipfix collector, our ip address */
+  /* ipfix collector, our ip address, fib index */
   ip4_address_t ipfix_collector;
   ip4_address_t src_address;
+  u32 fib_index;
 
   /* time scale transform. Joy. */
   u32 unix_time_0;
index 1bd58e5..122bd9d 100644 (file)
@@ -199,8 +199,7 @@ static vlib_frame_t * send_flows (flow_report_main_t * frm,
                   b0->current_length = copy_len;
                   b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
                   vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
-                  /* $$$ for now, look up in fib-0. Later: arbitrary TX fib */
-                  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
+                  vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
                   
                   tp = vlib_buffer_get_current (b0);
                   ip = (ip4_header_t *) &tp->ip4;