NAT: VPP-1552 code migration from old multiarch scheme
[vpp.git] / src / plugins / nat / nat44_handoff.c
index a49b8de..2a8404d 100644 (file)
@@ -31,7 +31,9 @@ typedef struct
 } nat44_handoff_trace_t;
 
 #define foreach_nat44_handoff_error                       \
-_(CONGESTION_DROP, "congestion drop")
+_(CONGESTION_DROP, "congestion drop")                     \
+_(SAME_WORKER, "same worker")                             \
+_(DO_HANDOFF, "do handoff")
 
 typedef enum
 {
@@ -48,10 +50,6 @@ static char *nat44_handoff_error_strings[] = {
 };
 
 
-vlib_node_registration_t snat_in2out_worker_handoff_node;
-vlib_node_registration_t snat_in2out_output_worker_handoff_node;
-vlib_node_registration_t snat_out2in_worker_handoff_node;
-
 static u8 *
 format_nat44_handoff_trace (u8 * s, va_list * args)
 {
@@ -79,6 +77,8 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
   u16 thread_indices[VLIB_FRAME_SIZE], *ti;
   u32 fq_index;
   snat_get_worker_function_t *get_worker;
+  u32 thread_index = vm->thread_index;
+  u32 do_handoff = 0, same_worker = 0;
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -114,6 +114,11 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       ip0 = vlib_buffer_get_current (b[0]);
       ti[0] = get_worker (ip0, rx_fib_index0);
 
+      if (ti[0] != thread_index)
+       do_handoff++;
+      else
+       same_worker++;
+
       if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
                         && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
        {
@@ -136,20 +141,22 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
     vlib_node_increment_counter (vm, node->node_index,
                                 NAT44_HANDOFF_ERROR_CONGESTION_DROP,
                                 frame->n_vectors - n_enq);
+  vlib_node_increment_counter (vm, node->node_index,
+                              NAT44_HANDOFF_ERROR_SAME_WORKER, same_worker);
+  vlib_node_increment_counter (vm, node->node_index,
+                              NAT44_HANDOFF_ERROR_DO_HANDOFF, do_handoff);
   return frame->n_vectors;
 }
 
-static uword
-snat_in2out_worker_handoff_fn (vlib_main_t * vm,
-                              vlib_node_runtime_t * node,
-                              vlib_frame_t * frame)
+VLIB_NODE_FN (snat_in2out_worker_handoff_node) (vlib_main_t * vm,
+                                               vlib_node_runtime_t * node,
+                                               vlib_frame_t * frame)
 {
   return nat44_worker_handoff_fn_inline (vm, node, frame, 0, 1);
 }
 
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node) = {
-  .function = snat_in2out_worker_handoff_fn,
   .name = "nat44-in2out-worker-handoff",
   .vector_size = sizeof (u32),
   .format_trace = format_nat44_handoff_trace,
@@ -163,20 +170,16 @@ VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node) = {
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (snat_in2out_worker_handoff_node,
-                             snat_in2out_worker_handoff_fn);
-
-static uword
-snat_in2out_output_worker_handoff_fn (vlib_main_t * vm,
-                                     vlib_node_runtime_t * node,
-                                     vlib_frame_t * frame)
+VLIB_NODE_FN (snat_in2out_output_worker_handoff_node) (vlib_main_t * vm,
+                                                      vlib_node_runtime_t *
+                                                      node,
+                                                      vlib_frame_t * frame)
 {
   return nat44_worker_handoff_fn_inline (vm, node, frame, 1, 1);
 }
 
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node) = {
-  .function = snat_in2out_output_worker_handoff_fn,
   .name = "nat44-in2out-output-worker-handoff",
   .vector_size = sizeof (u32),
   .format_trace = format_nat44_handoff_trace,
@@ -190,20 +193,15 @@ VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node) = {
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (snat_in2out_output_worker_handoff_node,
-                             snat_in2out_output_worker_handoff_fn);
-
-static uword
-snat_out2in_worker_handoff_fn (vlib_main_t * vm,
-                              vlib_node_runtime_t * node,
-                              vlib_frame_t * frame)
+VLIB_NODE_FN (snat_out2in_worker_handoff_node) (vlib_main_t * vm,
+                                               vlib_node_runtime_t * node,
+                                               vlib_frame_t * frame)
 {
   return nat44_worker_handoff_fn_inline (vm, node, frame, 0, 0);
 }
 
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node) = {
-  .function = snat_out2in_worker_handoff_fn,
   .name = "nat44-out2in-worker-handoff",
   .vector_size = sizeof (u32),
   .format_trace = format_nat44_handoff_trace,
@@ -217,9 +215,6 @@ VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node) = {
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (snat_out2in_worker_handoff_node,
-                             snat_out2in_worker_handoff_fn);
-
 /*
  * fd.io coding-style-patch-verification: ON
  *