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 | |
| 47 | if (node_index > vec_len (vnm->nodes)) |
| 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 | { |
| 67 | vec_validate (vnet_buffer2 (b)->trajectory_trace, 7); |
| 68 | _vec_len (vnet_buffer2 (b)->trajectory_trace) = 0; |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | add_trajectory_trace (vlib_buffer_t * b, u32 node_index) |
| 73 | { |
| 74 | vec_add1 (vnet_buffer2 (b)->trajectory_trace, (u16) node_index); |
| 75 | } |
| 76 | |
| 77 | static clib_error_t * |
| 78 | trajectory_trace_init (vlib_main_t * vm) |
| 79 | { |
| 80 | vlib_buffer_trace_trajectory_cb = add_trajectory_trace; |
| 81 | vlib_buffer_trace_trajectory_init_cb = init_trajectory_trace; |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | VLIB_INIT_FUNCTION (trajectory_trace_init); |
| 86 | |
| 87 | #endif |
| 88 | |
| 89 | /* |
| 90 | * fd.io coding-style-patch-verification: ON |
| 91 | * |
| 92 | * Local Variables: |
| 93 | * eval: (c-set-style "gnu") |
| 94 | * End: |
| 95 | */ |