FD.io VPP  v21.01.1
Vector Packet Processing
qos_store_node.c
Go to the documentation of this file.
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 
23 
24 /**
25  * per-packet trace data
26  */
27 typedef struct qos_store_trace_t_
28 {
29  /* per-pkt trace data */
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
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  {
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 
112 {
113  return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
114 }
115 
119 {
120  return (qos_store_inline (vm, node, frame, QOS_SOURCE_IP));
121 }
122 
123 
124 /* *INDENT-OFF* */
126  .name = "ip4-qos-store",
127  .vector_size = sizeof (u32),
128  .format_trace = format_qos_store_trace,
130 
131  .n_errors = 0,
132  .n_next_nodes = 1,
133 
134  .next_nodes = {
135  [0] = "ip4-drop",
136  },
137 };
138 
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 
149  .name = "ip6-qos-store",
150  .vector_size = sizeof (u32),
151  .format_trace = format_qos_store_trace,
153 
154  .n_errors = 0,
155  .n_next_nodes = 1,
156 
157  .next_nodes = {
158  [0] = "ip6-drop",
159  },
160 };
161 
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  */
VNET_FEATURE_INIT(ip4_qos_store_node, static)
static u8 * format_qos_store_trace(u8 *s, va_list *args)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
#define CLIB_UNUSED(x)
Definition: clib.h:87
#define vnet_buffer2(b)
Definition: buffer.h:481
per-packet trace data
vlib_main_t * vm
Definition: in2out_ed.c:1580
#define VLIB_NODE_FN(node)
Definition: node.h:203
unsigned char u8
Definition: types.h:56
description fragment has unexpected format
Definition: map.api:433
u8 * qos_store_configs[QOS_N_SOURCES]
Per-interface, per-protocol vector of feature on/off configurations.
Definition: qos_store.c:32
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:309
#define PREDICT_FALSE(x)
Definition: clib.h:121
vlib_node_registration_t ip6_qos_store_node
(constructor) VLIB_REGISTER_NODE (ip6_qos_store_node)
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:391
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:170
u16 n_vectors
Definition: node.h:397
enum qos_source_t_ qos_source_t
QoS types.
vlib_node_registration_t ip4_qos_store_node
(constructor) VLIB_REGISTER_NODE (ip4_qos_store_node)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:483
struct qos_store_trace_t_ qos_store_trace_t
per-packet trace data
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1580
IPv6 to IPv4 translation.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: in2out_ed.c:1581
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:297
u16 flags
Copy of main node flags.
Definition: node.h:501
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:634
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:302
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
u8 qos_bits_t
Type, er, safety for us water based entities.
Definition: qos_types.h:68
#define QOS_N_SOURCES
The maximum number of sources.
Definition: qos_types.h:45
static uword qos_store_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, qos_source_t qos_src)