Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * feat_bitmap.c: bitmap for managing feature invocation |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco 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 | |
| 18 | #include <vlib/vlib.h> |
| 19 | #include <vnet/vnet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vnet/ethernet/packet.h> |
| 22 | #include <vlib/cli.h> |
| 23 | #include <vnet/l2/l2_input.h> |
| 24 | #include <vnet/l2/feat_bitmap.h> |
| 25 | |
| 26 | #include <vppinfra/error.h> |
| 27 | #include <vppinfra/hash.h> |
| 28 | #include <vppinfra/cache.h> |
| 29 | |
| 30 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 31 | /* |
| 32 | * Drop node for feature bitmaps |
| 33 | * For features that just do a drop, or are not yet implemented. |
| 34 | * Initial feature dispatch nodes don't need to set b0->error |
| 35 | * in case of a possible drop because that will be done here. |
| 36 | *The next node is always error-drop. |
| 37 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | |
| 39 | static vlib_node_registration_t feat_bitmap_drop_node; |
| 40 | |
| 41 | #define foreach_feat_bitmap_drop_error \ |
| 42 | _(NO_FWD, "L2 feature forwarding disabled") \ |
| 43 | _(NYI, "L2 feature not implemented") |
| 44 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 45 | typedef enum |
| 46 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | #define _(sym,str) FEAT_BITMAP_DROP_ERROR_##sym, |
| 48 | foreach_feat_bitmap_drop_error |
| 49 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 50 | FEAT_BITMAP_DROP_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | } feat_bitmap_drop_error_t; |
| 52 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 53 | static char *feat_bitmap_drop_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | #define _(sym,string) string, |
| 55 | foreach_feat_bitmap_drop_error |
| 56 | #undef _ |
| 57 | }; |
| 58 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 59 | typedef enum |
| 60 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | FEAT_BITMAP_DROP_NEXT_DROP, |
| 62 | FEAT_BITMAP_DROP_N_NEXT, |
| 63 | } feat_bitmap_drop_next_t; |
| 64 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 65 | typedef struct |
| 66 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | u32 feature_bitmap; |
| 68 | } feat_bitmap_drop_trace_t; |
| 69 | |
| 70 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 71 | static u8 * |
| 72 | format_feat_bitmap_drop_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | { |
| 74 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 75 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 76 | feat_bitmap_drop_trace_t *t = va_arg (*args, feat_bitmap_drop_trace_t *); |
| 77 | |
| 78 | s = |
| 79 | format (s, "feat_bitmap_drop: feature bitmap 0x%08x", t->feature_bitmap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | return s; |
| 81 | } |
| 82 | |
| 83 | static uword |
| 84 | feat_bitmap_drop_node_fn (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 85 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 87 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | feat_bitmap_drop_next_t next_index; |
| 89 | |
| 90 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 91 | n_left_from = frame->n_vectors; /* number of packets to process */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | next_index = node->cached_next_index; |
| 93 | |
| 94 | while (n_left_from > 0) |
| 95 | { |
| 96 | u32 n_left_to_next; |
| 97 | |
| 98 | /* get space to enqueue frame to graph node "next_index" */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 99 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 100 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | while (n_left_from > 0 && n_left_to_next > 0) |
| 102 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 103 | u32 bi0; |
| 104 | vlib_buffer_t *b0; |
| 105 | u32 next0; |
| 106 | |
| 107 | /* speculatively enqueue b0 to the current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | bi0 = from[0]; |
| 109 | to_next[0] = bi0; |
| 110 | from += 1; |
| 111 | to_next += 1; |
| 112 | n_left_from -= 1; |
| 113 | n_left_to_next -= 1; |
| 114 | |
| 115 | b0 = vlib_get_buffer (vm, bi0); |
| 116 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 117 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 118 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 119 | { |
| 120 | feat_bitmap_drop_trace_t *t = |
| 121 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 122 | t->feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap; |
| 123 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 125 | if (vnet_buffer (b0)->l2.feature_bitmap == 1) |
| 126 | { |
| 127 | /* |
| 128 | * If we are executing the last feature, this is the |
| 129 | * No forwarding catch-all |
| 130 | */ |
| 131 | b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NO_FWD]; |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | b0->error = node->errors[FEAT_BITMAP_DROP_ERROR_NYI]; |
| 136 | } |
| 137 | next0 = FEAT_BITMAP_DROP_NEXT_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 139 | /* verify speculative enqueue, maybe switch current next frame */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 141 | to_next, n_left_to_next, |
| 142 | bi0, next0); |
| 143 | } |
| 144 | |
| 145 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 146 | } |
| 147 | return frame->n_vectors; |
| 148 | } |
| 149 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 150 | clib_error_t * |
| 151 | feat_bitmap_drop_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | { |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | VLIB_INIT_FUNCTION (feat_bitmap_drop_init); |
| 157 | |
| 158 | VLIB_REGISTER_NODE (feat_bitmap_drop_node,static) = { |
| 159 | .function = feat_bitmap_drop_node_fn, |
| 160 | .name = "feature-bitmap-drop", |
| 161 | .vector_size = sizeof (u32), |
| 162 | .format_trace = format_feat_bitmap_drop_trace, |
| 163 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 164 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | .n_errors = ARRAY_LEN(feat_bitmap_drop_error_strings), |
| 166 | .error_strings = feat_bitmap_drop_error_strings, |
| 167 | |
| 168 | .n_next_nodes = FEAT_BITMAP_DROP_N_NEXT, |
| 169 | |
| 170 | /* edit / add dispositions here */ |
| 171 | .next_nodes = { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 172 | [FEAT_BITMAP_DROP_NEXT_DROP] = "error-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | }, |
| 174 | }; |
| 175 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 176 | /* |
| 177 | * fd.io coding-style-patch-verification: ON |
| 178 | * |
| 179 | * Local Variables: |
| 180 | * eval: (c-set-style "gnu") |
| 181 | * End: |
| 182 | */ |