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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
22 extern u8 *qos_store_configs[QOS_N_SOURCES];
25 * per-packet trace data
27 typedef struct qos_store_trace_t_
29 /* per-pkt trace data */
33 /* packet trace format function */
35 format_qos_store_trace (u8 * s, va_list * args)
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 *);
41 s = format (s, "qos:%d", t->bits);
47 qos_store_inline (vlib_main_t * vm,
48 vlib_node_runtime_t * node,
49 vlib_frame_t * frame, qos_source_t qos_src)
51 u32 n_left_from, *from, *to_next, next_index;
54 n_left_from = frame->n_vectors;
55 from = vlib_frame_vector_args (frame);
57 while (n_left_from > 0)
61 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
63 while (n_left_from > 0 && n_left_to_next > 0)
77 b0 = vlib_get_buffer (vm, bi0);
80 *(qos_bits_t *) vnet_feature_next_with_data (&next0, b0,
83 vnet_buffer2 (b0)->qos.bits = qos0;
84 vnet_buffer2 (b0)->qos.source = qos_src;
85 b0->flags |= VNET_BUFFER_F_QOS_DATA_VALID;
87 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
88 (b0->flags & VLIB_BUFFER_IS_TRACED)))
90 qos_store_trace_t *t =
91 vlib_add_trace (vm, node, b0, sizeof (*t));
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,
102 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
105 return frame->n_vectors;
109 VLIB_NODE_FN (ip4_qos_store_node) (vlib_main_t * vm,
110 vlib_node_runtime_t * node,
111 vlib_frame_t * frame)
113 return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
116 VLIB_NODE_FN (ip6_qos_store_node) (vlib_main_t * vm,
117 vlib_node_runtime_t * node,
118 vlib_frame_t * frame)
120 return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
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,
139 VNET_FEATURE_INIT (ip4_qos_store_node, static) = {
140 .arc_name = "ip4-unicast",
141 .node_name = "ip4-qos-store",
143 VNET_FEATURE_INIT (ip4m_qos_store_node, static) = {
144 .arc_name = "ip4-multicast",
145 .node_name = "ip4-qos-store",
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,
162 VNET_FEATURE_INIT (ip6_qos_store_node, static) = {
163 .arc_name = "ip6-unicast",
164 .node_name = "ip6-qos-store",
166 VNET_FEATURE_INIT (ip6m_qos_store_node, static) = {
167 .arc_name = "ip6-multicast",
168 .node_name = "ip6-qos-store",
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "gnu")