Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 1 | /* |
| 2 | * handoff_trace.c - used to generate handoff trace records |
| 3 | * |
| 4 | * Copyright (c) 2019 Cisco Systems and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | #include <vlib/vlib.h> |
| 18 | #include <vnet/vnet.h> |
| 19 | #include <vnet/pg/pg.h> |
| 20 | #include <vppinfra/error.h> |
| 21 | |
| 22 | typedef struct |
| 23 | { |
| 24 | u32 prev_thread; |
| 25 | u32 prev_trace_index; |
| 26 | } handoff_trace_t; |
| 27 | |
| 28 | /* packet trace format function */ |
| 29 | static u8 * |
| 30 | format_handoff_trace (u8 * s, va_list * args) |
| 31 | { |
| 32 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 33 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 34 | handoff_trace_t *t = va_arg (*args, handoff_trace_t *); |
| 35 | |
| 36 | s = format (s, "HANDED-OFF: from thread %d trace index %d", |
| 37 | t->prev_thread, t->prev_trace_index); |
| 38 | return s; |
| 39 | } |
| 40 | |
| 41 | static vlib_node_registration_t handoff_trace_node; |
| 42 | |
| 43 | #define foreach_handoff_trace_error \ |
| 44 | _(BUGS, "Warning: packets sent to the handoff trace node!") |
| 45 | |
| 46 | typedef enum |
| 47 | { |
| 48 | #define _(sym,str) HANDOFF_TRACE_ERROR_##sym, |
| 49 | foreach_handoff_trace_error |
| 50 | #undef _ |
| 51 | HANDOFF_TRACE_N_ERROR, |
| 52 | } handoff_trace_error_t; |
| 53 | |
| 54 | static char *handoff_trace_error_strings[] = { |
| 55 | #define _(sym,string) string, |
| 56 | foreach_handoff_trace_error |
| 57 | #undef _ |
| 58 | }; |
| 59 | |
| 60 | static uword |
| 61 | handoff_trace_node_fn (vlib_main_t * vm, |
| 62 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 63 | { |
| 64 | vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors); |
| 65 | |
| 66 | vlib_node_increment_counter (vm, node->node_index, |
| 67 | HANDOFF_TRACE_ERROR_BUGS, frame->n_vectors); |
| 68 | |
| 69 | return frame->n_vectors; |
| 70 | } |
| 71 | |
| 72 | typedef enum |
| 73 | { |
| 74 | HANDOFF_TRACE_NEXT_DROP, |
| 75 | HANDOFF_TRACE_N_NEXT, |
Dave Barach | 11fb09e | 2020-08-06 12:10:09 -0400 | [diff] [blame] | 76 | } tplaceholder_next_t; |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 77 | |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 78 | VLIB_REGISTER_NODE (handoff_trace_node, static) = |
| 79 | { |
| 80 | .name = "handoff_trace", |
Damjan Marion | 7ca5aaa | 2019-09-24 18:10:49 +0200 | [diff] [blame] | 81 | .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED, |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 82 | .function = handoff_trace_node_fn, |
| 83 | .vector_size = sizeof (u32), |
| 84 | .format_trace = format_handoff_trace, |
| 85 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 86 | .n_next_nodes = HANDOFF_TRACE_N_NEXT, |
| 87 | |
| 88 | /* edit / add dispositions here */ |
| 89 | .next_nodes = { |
| 90 | [HANDOFF_TRACE_NEXT_DROP] = "error-drop", |
| 91 | }, |
| 92 | |
| 93 | .n_errors = ARRAY_LEN(handoff_trace_error_strings), |
| 94 | .error_strings = handoff_trace_error_strings, |
| 95 | }; |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 96 | |
Benoît Ganne | 9a3973e | 2020-10-02 19:36:57 +0200 | [diff] [blame] | 97 | int |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 98 | vlib_add_handoff_trace (vlib_main_t * vm, vlib_buffer_t * b) |
| 99 | { |
| 100 | u32 prev_thread = vlib_buffer_get_trace_thread (b); |
| 101 | u32 prev_trace_index = vlib_buffer_get_trace_index (b); |
| 102 | handoff_trace_t *t; |
| 103 | vlib_node_runtime_t *node |
| 104 | = vlib_node_get_runtime (vm, handoff_trace_node.index); |
| 105 | |
Benoît Ganne | 9a3973e | 2020-10-02 19:36:57 +0200 | [diff] [blame] | 106 | if (PREDICT_FALSE |
| 107 | (!vlib_trace_buffer |
| 108 | (vm, node, 0 /* fake next frame index */ , b, 1 /* follow chain */ ))) |
| 109 | return 0; |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 110 | |
| 111 | t = vlib_add_trace (vm, node, b, sizeof (*t)); |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 112 | t->prev_thread = prev_thread; |
| 113 | t->prev_trace_index = prev_trace_index; |
Benoît Ganne | 9a3973e | 2020-10-02 19:36:57 +0200 | [diff] [blame] | 114 | return 1; |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
Dave Barach | a638c18 | 2019-06-21 18:24:07 -0400 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * fd.io coding-style-patch-verification: ON |
| 121 | * |
| 122 | * Local Variables: |
| 123 | * eval: (c-set-style "gnu") |
| 124 | * End: |
| 125 | */ |