blob: 6a5ad24453d587529d72a3d94090aa64422712c9 [file] [log] [blame]
Neale Ranns83832e72019-07-31 02:48:02 -07001/*
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
22extern u8 *qos_store_configs[QOS_N_SOURCES];
23
24/**
25 * per-packet trace data
26 */
27typedef 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 */
34static u8 *
35format_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
46static inline uword
47qos_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
109VLIB_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
116VLIB_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
Neale Ranns83832e72019-07-31 02:48:02 -0700124VLIB_REGISTER_NODE (ip4_qos_store_node) = {
125 .name = "ip4-qos-store",
126 .vector_size = sizeof (u32),
127 .format_trace = format_qos_store_trace,
128 .type = VLIB_NODE_TYPE_INTERNAL,
129
130 .n_errors = 0,
131 .n_next_nodes = 1,
132
133 .next_nodes = {
134 [0] = "ip4-drop",
135 },
136};
137
138VNET_FEATURE_INIT (ip4_qos_store_node, static) = {
139 .arc_name = "ip4-unicast",
140 .node_name = "ip4-qos-store",
141};
142VNET_FEATURE_INIT (ip4m_qos_store_node, static) = {
143 .arc_name = "ip4-multicast",
144 .node_name = "ip4-qos-store",
145};
146
147VLIB_REGISTER_NODE (ip6_qos_store_node) = {
148 .name = "ip6-qos-store",
149 .vector_size = sizeof (u32),
150 .format_trace = format_qos_store_trace,
151 .type = VLIB_NODE_TYPE_INTERNAL,
152
153 .n_errors = 0,
154 .n_next_nodes = 1,
155
156 .next_nodes = {
157 [0] = "ip6-drop",
158 },
159};
160
161VNET_FEATURE_INIT (ip6_qos_store_node, static) = {
162 .arc_name = "ip6-unicast",
163 .node_name = "ip6-qos-store",
164};
165VNET_FEATURE_INIT (ip6m_qos_store_node, static) = {
166 .arc_name = "ip6-multicast",
167 .node_name = "ip6-qos-store",
168};
169
Neale Ranns83832e72019-07-31 02:48:02 -0700170
171/*
172 * fd.io coding-style-patch-verification: ON
173 *
174 * Local Variables:
175 * eval: (c-set-style "gnu")
176 * End:
177 */