Line data Source code
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 50 : format_qos_store_trace (u8 * s, va_list * args)
36 : {
37 50 : CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
38 50 : CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
39 50 : qos_store_trace_t *t = va_arg (*args, qos_store_trace_t *);
40 :
41 50 : s = format (s, "qos:%d", t->bits);
42 :
43 50 : return s;
44 : }
45 :
46 : static inline uword
47 1 : 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 1 : next_index = 0;
54 1 : n_left_from = frame->n_vectors;
55 1 : from = vlib_frame_vector_args (frame);
56 :
57 2 : while (n_left_from > 0)
58 : {
59 : u32 n_left_to_next;
60 :
61 1 : vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
62 :
63 68 : 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 67 : next0 = 0;
70 67 : bi0 = from[0];
71 67 : to_next[0] = bi0;
72 67 : from += 1;
73 67 : to_next += 1;
74 67 : n_left_from -= 1;
75 67 : n_left_to_next -= 1;
76 :
77 67 : b0 = vlib_get_buffer (vm, bi0);
78 :
79 67 : qos0 =
80 67 : *(qos_bits_t *) vnet_feature_next_with_data (&next0, b0,
81 : sizeof (qos_bits_t));
82 :
83 67 : vnet_buffer2 (b0)->qos.bits = qos0;
84 67 : vnet_buffer2 (b0)->qos.source = qos_src;
85 67 : b0->flags |= VNET_BUFFER_F_QOS_DATA_VALID;
86 :
87 67 : if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
88 : (b0->flags & VLIB_BUFFER_IS_TRACED)))
89 : {
90 : qos_store_trace_t *t =
91 67 : vlib_add_trace (vm, node, b0, sizeof (*t));
92 67 : t->bits = qos0;
93 : }
94 :
95 :
96 : /* verify speculative enqueue, maybe switch current next frame */
97 67 : vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
98 : to_next, n_left_to_next,
99 : bi0, next0);
100 : }
101 :
102 1 : vlib_put_next_frame (vm, node, next_index, n_left_to_next);
103 : }
104 :
105 1 : return frame->n_vectors;
106 : }
107 :
108 :
109 560 : VLIB_NODE_FN (ip4_qos_store_node) (vlib_main_t * vm,
110 : vlib_node_runtime_t * node,
111 : vlib_frame_t * frame)
112 : {
113 1 : return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
114 : }
115 :
116 559 : VLIB_NODE_FN (ip6_qos_store_node) (vlib_main_t * vm,
117 : vlib_node_runtime_t * node,
118 : vlib_frame_t * frame)
119 : {
120 0 : return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
121 : }
122 :
123 :
124 : /* *INDENT-OFF* */
125 178120 : 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 70583 : VNET_FEATURE_INIT (ip4_qos_store_node, static) = {
140 : .arc_name = "ip4-unicast",
141 : .node_name = "ip4-qos-store",
142 : };
143 70583 : VNET_FEATURE_INIT (ip4m_qos_store_node, static) = {
144 : .arc_name = "ip4-multicast",
145 : .node_name = "ip4-qos-store",
146 : };
147 :
148 178120 : 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 70583 : VNET_FEATURE_INIT (ip6_qos_store_node, static) = {
163 : .arc_name = "ip6-unicast",
164 : .node_name = "ip6-qos-store",
165 : };
166 70583 : 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 : */
|