Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | /** \file |
| 17 | * Buffer trace trajectory utilities |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | |
| 22 | /** |
| 23 | * Dump a trajectory trace, reasonably easy to call from gdb |
| 24 | */ |
| 25 | void |
| 26 | vnet_dump_trajectory_trace (vlib_main_t * vm, u32 bi) |
| 27 | { |
| 28 | #if VLIB_BUFFER_TRACE_TRAJECTORY > 0 |
| 29 | vlib_node_main_t *vnm = &vm->node_main; |
| 30 | vlib_buffer_t *b; |
| 31 | u16 *trace; |
| 32 | u8 i; |
| 33 | |
| 34 | b = vlib_get_buffer (vm, bi); |
| 35 | |
| 36 | trace = vnet_buffer2 (b)->trajectory_trace; |
| 37 | |
| 38 | fformat (stderr, "Context trace for bi %d b 0x%llx, visited %d\n", |
| 39 | bi, b, vec_len (trace)); |
| 40 | |
| 41 | for (i = 0; i < vec_len (trace); i++) |
| 42 | { |
| 43 | u32 node_index; |
| 44 | |
| 45 | node_index = trace[i]; |
| 46 | |
Eyal Bari | cd30774 | 2018-07-22 12:45:15 +0300 | [diff] [blame] | 47 | if (node_index >= vec_len (vnm->nodes)) |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 48 | { |
| 49 | fformat (stderr, "Skip bogus node index %d\n", node_index); |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | fformat (stderr, "%v (%d)\n", vnm->nodes[node_index]->name, node_index); |
| 54 | } |
| 55 | #else |
| 56 | fformat (stderr, "in vlib/buffers.h, " |
| 57 | "#define VLIB_BUFFER_TRACE_TRAJECTORY 1\n"); |
| 58 | |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | #if VLIB_BUFFER_TRACE_TRAJECTORY > 0 |
| 63 | |
| 64 | void |
| 65 | init_trajectory_trace (vlib_buffer_t * b) |
| 66 | { |
Florin Coras | f988e69 | 2017-11-27 04:34:14 -0500 | [diff] [blame] | 67 | if (!clib_mem_is_vec (vnet_buffer2 (b)->trajectory_trace)) |
| 68 | { |
| 69 | vnet_buffer2 (b)->trajectory_trace = 0; |
| 70 | vec_validate (vnet_buffer2 (b)->trajectory_trace, 7); |
| 71 | } |
Dave Barach | 7bee773 | 2017-10-18 18:48:11 -0400 | [diff] [blame] | 72 | _vec_len (vnet_buffer2 (b)->trajectory_trace) = 0; |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | add_trajectory_trace (vlib_buffer_t * b, u32 node_index) |
| 77 | { |
| 78 | vec_add1 (vnet_buffer2 (b)->trajectory_trace, (u16) node_index); |
| 79 | } |
| 80 | |
| 81 | static clib_error_t * |
| 82 | trajectory_trace_init (vlib_main_t * vm) |
| 83 | { |
| 84 | vlib_buffer_trace_trajectory_cb = add_trajectory_trace; |
| 85 | vlib_buffer_trace_trajectory_init_cb = init_trajectory_trace; |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | VLIB_INIT_FUNCTION (trajectory_trace_init); |
| 90 | |
| 91 | #endif |
| 92 | |
| 93 | /* |
| 94 | * fd.io coding-style-patch-verification: ON |
| 95 | * |
| 96 | * Local Variables: |
| 97 | * eval: (c-set-style "gnu") |
| 98 | * End: |
| 99 | */ |