Neale Ranns | 83832e7 | 2019-07-31 02:48:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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/qos/qos_store.h> |
| 17 | #include <vnet/ip/ip.h> |
| 18 | #include <vnet/ip/ip6_to_ip4.h> |
| 19 | #include <vnet/feature/feature.h> |
| 20 | #include <vnet/qos/qos_types.h> |
| 21 | |
| 22 | extern u8 *qos_store_configs[QOS_N_SOURCES]; |
| 23 | |
| 24 | /** |
| 25 | * per-packet trace data |
| 26 | */ |
| 27 | typedef struct qos_store_trace_t_ |
| 28 | { |
| 29 | /* per-pkt trace data */ |
| 30 | qos_bits_t bits; |
| 31 | } qos_store_trace_t; |
| 32 | |
| 33 | /* packet trace format function */ |
| 34 | static u8 * |
| 35 | format_qos_store_trace (u8 * s, va_list * args) |
| 36 | { |
| 37 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 38 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 39 | qos_store_trace_t *t = va_arg (*args, qos_store_trace_t *); |
| 40 | |
| 41 | s = format (s, "qos:%d", t->bits); |
| 42 | |
| 43 | return s; |
| 44 | } |
| 45 | |
| 46 | static inline uword |
| 47 | qos_store_inline (vlib_main_t * vm, |
| 48 | vlib_node_runtime_t * node, |
| 49 | vlib_frame_t * frame, qos_source_t qos_src) |
| 50 | { |
| 51 | u32 n_left_from, *from, *to_next, next_index; |
| 52 | |
| 53 | next_index = 0; |
| 54 | n_left_from = frame->n_vectors; |
| 55 | from = vlib_frame_vector_args (frame); |
| 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 | vlib_buffer_t *b0; |
| 66 | u32 next0, bi0; |
| 67 | qos_bits_t qos0; |
| 68 | |
| 69 | next0 = 0; |
| 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 | qos0 = |
| 80 | *(qos_bits_t *) vnet_feature_next_with_data (&next0, b0, |
| 81 | sizeof (qos_bits_t)); |
| 82 | |
| 83 | vnet_buffer2 (b0)->qos.bits = qos0; |
| 84 | vnet_buffer2 (b0)->qos.source = qos_src; |
| 85 | b0->flags |= VNET_BUFFER_F_QOS_DATA_VALID; |
| 86 | |
| 87 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 88 | (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 89 | { |
| 90 | qos_store_trace_t *t = |
| 91 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 92 | t->bits = qos0; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /* verify speculative enqueue, maybe switch current next frame */ |
| 97 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 98 | to_next, n_left_to_next, |
| 99 | bi0, next0); |
| 100 | } |
| 101 | |
| 102 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 103 | } |
| 104 | |
| 105 | return frame->n_vectors; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | VLIB_NODE_FN (ip4_qos_store_node) (vlib_main_t * vm, |
| 110 | vlib_node_runtime_t * node, |
| 111 | vlib_frame_t * frame) |
| 112 | { |
| 113 | return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP)); |
| 114 | } |
| 115 | |
| 116 | VLIB_NODE_FN (ip6_qos_store_node) (vlib_main_t * vm, |
| 117 | vlib_node_runtime_t * node, |
| 118 | vlib_frame_t * frame) |
| 119 | { |
| 120 | return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP)); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /* *INDENT-OFF* */ |
| 125 | VLIB_REGISTER_NODE (ip4_qos_store_node) = { |
| 126 | .name = "ip4-qos-store", |
| 127 | .vector_size = sizeof (u32), |
| 128 | .format_trace = format_qos_store_trace, |
| 129 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 130 | |
| 131 | .n_errors = 0, |
| 132 | .n_next_nodes = 1, |
| 133 | |
| 134 | .next_nodes = { |
| 135 | [0] = "ip4-drop", |
| 136 | }, |
| 137 | }; |
| 138 | |
| 139 | VNET_FEATURE_INIT (ip4_qos_store_node, static) = { |
| 140 | .arc_name = "ip4-unicast", |
| 141 | .node_name = "ip4-qos-store", |
| 142 | }; |
| 143 | VNET_FEATURE_INIT (ip4m_qos_store_node, static) = { |
| 144 | .arc_name = "ip4-multicast", |
| 145 | .node_name = "ip4-qos-store", |
| 146 | }; |
| 147 | |
| 148 | VLIB_REGISTER_NODE (ip6_qos_store_node) = { |
| 149 | .name = "ip6-qos-store", |
| 150 | .vector_size = sizeof (u32), |
| 151 | .format_trace = format_qos_store_trace, |
| 152 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 153 | |
| 154 | .n_errors = 0, |
| 155 | .n_next_nodes = 1, |
| 156 | |
| 157 | .next_nodes = { |
| 158 | [0] = "ip6-drop", |
| 159 | }, |
| 160 | }; |
| 161 | |
| 162 | VNET_FEATURE_INIT (ip6_qos_store_node, static) = { |
| 163 | .arc_name = "ip6-unicast", |
| 164 | .node_name = "ip6-qos-store", |
| 165 | }; |
| 166 | VNET_FEATURE_INIT (ip6m_qos_store_node, static) = { |
| 167 | .arc_name = "ip6-multicast", |
| 168 | .node_name = "ip6-qos-store", |
| 169 | }; |
| 170 | |
| 171 | /* *INDENT-ON* */ |
| 172 | |
| 173 | /* |
| 174 | * fd.io coding-style-patch-verification: ON |
| 175 | * |
| 176 | * Local Variables: |
| 177 | * eval: (c-set-style "gnu") |
| 178 | * End: |
| 179 | */ |