Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #include <vnet/bier/bier_disp_table.h> |
| 17 | #include <vnet/bier/bier_hdr_inlines.h> |
| 18 | |
| 19 | /** |
| 20 | * @brief A struct to hold tracing information for the MPLS label imposition |
| 21 | * node. |
| 22 | */ |
| 23 | typedef struct bier_disp_lookup_trace_t_ |
| 24 | { |
| 25 | /** |
| 26 | * BIER source BP used in the lookup - host order |
| 27 | */ |
| 28 | bier_bp_t bp; |
| 29 | /** |
| 30 | * BIER disp table |
| 31 | */ |
| 32 | index_t bdti; |
| 33 | } bier_disp_lookup_trace_t; |
| 34 | |
| 35 | /** |
| 36 | * Next nodes from BIER disposition lookup |
| 37 | */ |
| 38 | typedef enum bier_disp_lookup_next_t_ |
| 39 | { |
| 40 | BIER_DISP_LOOKUP_NEXT_DROP, |
| 41 | BIER_DISP_LOOKUP_NEXT_DISPATCH, |
| 42 | } bier_disp_lookup_next_t; |
| 43 | #define BIER_DISP_LOOKUP_N_NEXT (BIER_DISP_LOOKUP_NEXT_DISPATCH+1) |
| 44 | |
| 45 | always_inline uword |
| 46 | bier_disp_lookup_inline (vlib_main_t * vm, |
| 47 | vlib_node_runtime_t * node, |
| 48 | vlib_frame_t * from_frame) |
| 49 | { |
| 50 | u32 n_left_from, next_index, * from, * to_next; |
| 51 | |
| 52 | from = vlib_frame_vector_args (from_frame); |
| 53 | n_left_from = from_frame->n_vectors; |
| 54 | |
| 55 | next_index = node->cached_next_index; |
| 56 | |
| 57 | while (n_left_from > 0) |
| 58 | { |
| 59 | u32 n_left_to_next; |
| 60 | |
| 61 | vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next); |
| 62 | |
| 63 | while (n_left_from > 0 && n_left_to_next > 0) |
| 64 | { |
| 65 | const bier_hdr_t *hdr0; |
| 66 | vlib_buffer_t * b0; |
| 67 | u32 bdei0, bdti0; |
| 68 | u32 next0, bi0; |
| 69 | |
| 70 | bi0 = from[0]; |
| 71 | to_next[0] = bi0; |
| 72 | from += 1; |
| 73 | to_next += 1; |
| 74 | n_left_from -= 1; |
| 75 | n_left_to_next -= 1; |
| 76 | |
| 77 | b0 = vlib_get_buffer (vm, bi0); |
| 78 | |
| 79 | bdti0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 80 | hdr0 = vlib_buffer_get_current(b0); |
| 81 | |
| 82 | /* |
| 83 | * lookup - source is in network order. |
| 84 | */ |
| 85 | bdei0 = bier_disp_table_lookup(bdti0, bier_hdr_get_src_id(hdr0)); |
| 86 | |
| 87 | if (PREDICT_FALSE(INDEX_INVALID == bdei0)) |
| 88 | { |
| 89 | next0 = BIER_DISP_LOOKUP_NEXT_DROP; |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | next0 = BIER_DISP_LOOKUP_NEXT_DISPATCH; |
| 94 | } |
| 95 | |
| 96 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = bdei0; |
| 97 | |
| 98 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 99 | { |
| 100 | bier_disp_lookup_trace_t *tr = |
| 101 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 102 | tr->bp = clib_net_to_host_u16(bier_hdr_get_src_id(hdr0)); |
| 103 | tr->bdti = bdti0; |
| 104 | } |
| 105 | |
| 106 | vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, |
| 107 | n_left_to_next, bi0, next0); |
| 108 | } |
| 109 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 110 | } |
| 111 | return from_frame->n_vectors; |
| 112 | } |
| 113 | |
| 114 | static u8 * |
| 115 | format_bier_disp_lookup_trace (u8 * s, va_list * args) |
| 116 | { |
| 117 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 118 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 119 | bier_disp_lookup_trace_t * t; |
| 120 | |
| 121 | t = va_arg (*args, bier_disp_lookup_trace_t *); |
| 122 | s = format (s, "tbl:%d src:%d", t->bdti, t->bp); |
| 123 | |
| 124 | return (s); |
| 125 | } |
| 126 | |
| 127 | static uword |
| 128 | bier_disp_lookup (vlib_main_t * vm, |
| 129 | vlib_node_runtime_t * node, |
| 130 | vlib_frame_t * frame) |
| 131 | { |
| 132 | return (bier_disp_lookup_inline(vm, node, frame)); |
| 133 | } |
| 134 | |
| 135 | VLIB_REGISTER_NODE (bier_disp_lookup_node) = { |
| 136 | .function = bier_disp_lookup, |
| 137 | .name = "bier-disp-lookup", |
| 138 | .vector_size = sizeof (u32), |
| 139 | |
| 140 | .format_trace = format_bier_disp_lookup_trace, |
| 141 | .n_next_nodes = BIER_DISP_LOOKUP_N_NEXT, |
| 142 | .next_nodes = { |
| 143 | [BIER_DISP_LOOKUP_NEXT_DROP] = "bier-drop", |
| 144 | [BIER_DISP_LOOKUP_NEXT_DISPATCH] = "bier-disp-dispatch", |
| 145 | } |
| 146 | }; |
| 147 | VLIB_NODE_FUNCTION_MULTIARCH (bier_disp_lookup_node, bier_disp_lookup) |