FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
qos_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vlibmemory/api.h>
20 #include <vnet/api_errno.h>
21 
22 #include <vnet/qos/qos_record.h>
23 #include <vnet/qos/qos_store.h>
24 #include <vnet/qos/qos_mark.h>
26 
27 #include <vnet/format_fns.h>
28 #include <vnet/qos/qos.api_enum.h>
29 #include <vnet/qos/qos.api_types.h>
30 
31 #define REPLY_MSG_ID_BASE msg_id_base
33 
35 
36 static int
37 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
38 {
39  switch (v)
40  {
41  case QOS_API_SOURCE_EXT:
42  *q = QOS_SOURCE_EXT;
43  return 0;
45  *q = QOS_SOURCE_VLAN;
46  return 0;
48  *q = QOS_SOURCE_MPLS;
49  return 0;
50  case QOS_API_SOURCE_IP:
51  *q = QOS_SOURCE_IP;
52  return 0;
53  }
54 
55  return (VNET_API_ERROR_INVALID_VALUE);
56 }
57 
58 static vl_api_qos_source_t
60 {
61  return ((vl_api_qos_source_t) q);
62 }
63 
64 void
66  * mp)
67 {
68  vl_api_qos_record_enable_disable_reply_t *rmp;
69  qos_source_t qs;
70  int rv = 0;
71 
73 
74  rv = qos_source_decode (mp->record.input_source, &qs);
75 
76  if (0 == rv)
77  {
78  if (mp->enable)
79  rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
80  else
81  rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
82  }
83 
85  REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
86 }
87 
89 {
93 
94 static walk_rc_t
96 {
99 
100  ctx = c;
101  mp = vl_msg_api_alloc_zero (sizeof (*mp));
102 
103  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_RECORD_DETAILS);
104  mp->context = ctx->context;
105  mp->record.sw_if_index = htonl (sw_if_index);
106  mp->record.input_source = qos_source_encode (input_source);
107 
108  vl_api_send_msg (ctx->reg, (u8 *) mp);
109 
110  return (WALK_CONTINUE);
111 }
112 
113 static void
115 {
117 
119  if (!reg)
120  return;
121 
123  .reg = reg,
124  .context = mp->context,
125  };
127 }
128 
129 void
131  * mp)
132 {
133  vl_api_qos_store_enable_disable_reply_t *rmp;
134  qos_source_t qs;
135  int rv = 0;
136 
137  VALIDATE_SW_IF_INDEX (&(mp->store));
138 
139  rv = qos_source_decode (mp->store.input_source, &qs);
140 
141  if (0 == rv)
142  {
143  if (mp->enable)
144  rv = qos_store_enable (ntohl (mp->store.sw_if_index), qs,
145  mp->store.value);
146  else
147  rv = qos_store_disable (ntohl (mp->store.sw_if_index), qs);
148  }
149 
151  REPLY_MACRO (VL_API_QOS_STORE_ENABLE_DISABLE_REPLY);
152 }
153 
155 {
159 
160 static walk_rc_t
163 {
166 
167  ctx = c;
168  mp = vl_msg_api_alloc_zero (sizeof (*mp));
169 
170  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_STORE_DETAILS);
171  mp->context = ctx->context;
172  mp->store.sw_if_index = htonl (sw_if_index);
173  mp->store.input_source = qos_source_encode (input_source);
174  mp->store.value = value;
175 
176  vl_api_send_msg (ctx->reg, (u8 *) mp);
177 
178  return (WALK_CONTINUE);
179 }
180 
181 static void
183 {
185 
187  if (!reg)
188  return;
189 
191  .reg = reg,
192  .context = mp->context,
193  };
195 }
196 
197 void
199 {
200  vl_api_qos_egress_map_update_reply_t *rmp;
201  qos_source_t qs;
202  int rv = 0;
203 
205  {
206  qos_egress_map_update (ntohl (mp->map.id), qs,
207  &mp->map.rows[qs].outputs[0]);
208  }
209 
210  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
211 }
212 
213 void
215 {
216  vl_api_qos_egress_map_delete_reply_t *rmp;
217  int rv = 0;
218 
219  qos_egress_map_delete (ntohl (mp->id));
220 
221  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
222 }
223 
225 {
229 
230 static walk_rc_t
232  const qos_egress_map_t * m, void *c)
233 {
236  u8 ii;
237 
238  ctx = c;
239  mp = vl_msg_api_alloc_zero (sizeof (*mp));
240 
241  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_EGRESS_MAP_DETAILS);
242  mp->context = ctx->context;
243  mp->map.id = htonl (id);
244 
245  for (ii = 0; ii < 4; ii++)
246  clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
247 
248  vl_api_send_msg (ctx->reg, (u8 *) mp);
249 
250  return (WALK_CONTINUE);
251 }
252 
253 static void
255 {
257 
259  if (!reg)
260  return;
261 
263  .reg = reg,
264  .context = mp->context,
265  };
267 }
268 
269 void
271  mp)
272 {
273  vl_api_qos_mark_enable_disable_reply_t *rmp;
274  qos_source_t qs;
275  int rv = 0;
276 
277  rv = qos_source_decode (mp->mark.output_source, &qs);
278 
279  if (0 == rv)
280  {
281  if (mp->enable)
282  rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
283  qs, ntohl (mp->mark.map_id));
284  else
285  rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
286  }
287 
288  REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
289 }
290 
292 {
296 
297 static walk_rc_t
300 {
303 
304  ctx = c;
305  mp = vl_msg_api_alloc_zero (sizeof (*mp));
306 
307  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_QOS_MARK_DETAILS);
308  mp->context = ctx->context;
309  mp->mark.sw_if_index = htonl (sw_if_index);
310  mp->mark.output_source = qos_source_encode (output_source);
311  mp->mark.map_id = htonl (map_id);
312 
313  vl_api_send_msg (ctx->reg, (u8 *) mp);
314 
315  return (WALK_CONTINUE);
316 }
317 
318 static void
320 {
322 
324  if (!reg)
325  return;
326 
328  .reg = reg,
329  .context = mp->context,
330  };
332 }
333 
334 #include <vnet/qos/qos.api.c>
335 
336 static clib_error_t *
338 {
339  /*
340  * Set up the (msg_name, crc, message-id) table
341  */
343 
344  return 0;
345 }
346 
348 
349 /*
350  * fd.io coding-style-patch-verification: ON
351  *
352  * Local Variables:
353  * eval: (c-set-style "gnu")
354  * End:
355  */
vl_api_qos_mark_dump_t
Dump QoS marking configs.
Definition: qos.api:234
QOS_SOURCE_EXT
@ QOS_SOURCE_EXT
Some external source, e.g.
Definition: qos_types.h:35
vl_api_qos_mark_dump_t_handler
static void vl_api_qos_mark_dump_t_handler(vl_api_qos_mark_dump_t *mp)
Definition: qos_api.c:319
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
vl_api_qos_store_details_t
Details of QoS recording configs.
Definition: qos.api:84
api.h
qos_egress_map_t_
For a given output source a table maps each value of every input source.
Definition: qos_egress_map.h:37
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
qos_mark_walk
void qos_mark_walk(qos_mark_walk_cb_t fn, void *c)
Definition: qos_mark.c:121
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_qos_egress_map_delete_t_handler
void vl_api_qos_egress_map_delete_t_handler(vl_api_qos_egress_map_delete_t *mp)
Definition: qos_api.c:214
qos_api_hookup
static clib_error_t * qos_api_hookup(vlib_main_t *vm)
Definition: qos_api.c:337
vl_api_qos_store_dump_t::context
u32 context
Definition: qos.api:78
QOS_SOURCE_MPLS
@ QOS_SOURCE_MPLS
Definition: qos_types.h:37
QOS_API_SOURCE_VLAN
@ QOS_API_SOURCE_VLAN
Definition: qos.api:36
qos_record_enable
int qos_record_enable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:67
msg_id_base
static u16 msg_id_base
Definition: qos_api.c:34
qos_store_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:156
send_qos_egress_map_details
static walk_rc_t send_qos_egress_map_details(qos_egress_map_id_t id, const qos_egress_map_t *m, void *c)
Definition: qos_api.c:231
qos_source_encode
static vl_api_qos_source_t qos_source_encode(qos_source_t q)
Definition: qos_api.c:59
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
qos_mark_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:294
vl_api_qos_mark_enable_disable_t::enable
bool enable[default=true]
Definition: qos.api:227
vl_api_qos_mark_details_t::context
u32 context
Definition: qos.api:246
qos_egress_map_t_::qem_output
qos_bits_t qem_output[QOS_N_SOURCES][256]
The array of output mapped values; output = eq_qos[input-source][input-value].
Definition: qos_egress_map.h:48
vl_api_qos_mark_enable_disable_t_handler
void vl_api_qos_mark_enable_disable_t_handler(vl_api_qos_mark_enable_disable_t *mp)
Definition: qos_api.c:270
vl_api_qos_mark_details_t::mark
vl_api_qos_mark_t mark
Definition: qos.api:247
vl_msg_api_alloc_zero
void * vl_msg_api_alloc_zero(int nbytes)
Definition: memory_shared.c:214
output_source
vl_api_qos_source_t output_source
Definition: qos.api:215
vl_api_qos_egress_map_delete_t::id
u32 id
Definition: qos.api:179
vl_api_qos_record_enable_disable_t::enable
bool enable[default=true]
Definition: qos.api:113
vl_api_qos_egress_map_dump_t_handler
static void vl_api_qos_egress_map_dump_t_handler(vl_api_qos_egress_map_dump_t *mp)
Definition: qos_api.c:254
vl_api_qos_record_details_t::record
vl_api_qos_record_t record
Definition: qos.api:132
vl_api_qos_record_dump_t
Dump the QoS record configs.
Definition: qos.api:120
vl_api_qos_store_enable_disable_t::enable
bool enable[default=true]
Definition: qos.api:68
vl_api_qos_store_dump_t_handler
static void vl_api_qos_store_dump_t_handler(vl_api_qos_store_dump_t *mp)
Definition: qos_api.c:182
vl_api_qos_record_dump_t::context
u32 context
Definition: qos.api:123
vl_api_qos_egress_map_dump_t
Dump the QoS egress maps.
Definition: qos.api:185
vl_api_qos_store_enable_disable_t
Enable/Disable QoS storing The QoS bits from the packet at the specified input layer are copied into ...
Definition: qos.api:64
qos_store_walk
void qos_store_walk(qos_store_walk_cb_t fn, void *c)
Definition: qos_store.c:111
qos_bits_t
u8 qos_bits_t
Type, er, safety for us water based entities.
Definition: qos_types.h:68
QOS_SOURCE_VLAN
@ QOS_SOURCE_VLAN
Definition: qos_types.h:36
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(qos_api_hookup)
vl_api_qos_egress_map_dump_t::context
u32 context
Definition: qos.api:188
qos_egress_map.h
QOS_API_SOURCE_EXT
@ QOS_API_SOURCE_EXT
Definition: qos.api:35
send_qos_store_details
static walk_rc_t send_qos_store_details(u32 sw_if_index, qos_source_t input_source, qos_bits_t value, void *c)
Definition: qos_api.c:161
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
vl_api_qos_store_enable_disable_t::store
vl_api_qos_store_t store
Definition: qos.api:69
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
send_qos_mark_details
static walk_rc_t send_qos_mark_details(u32 sw_if_index, u32 map_id, qos_source_t output_source, void *c)
Definition: qos_api.c:298
vl_api_qos_egress_map_details_t::context
u32 context
Definition: qos.api:196
vl_api_qos_egress_map_details_t
QoS map details.
Definition: qos.api:194
qos_store_send_walk_ctx_t_
Definition: qos_api.c:154
qos_record_walk
void qos_record_walk(qos_record_walk_cb_t fn, void *c)
Definition: qos_record.c:100
qos_store_send_walk_ctx_t
struct qos_store_send_walk_ctx_t_ qos_store_send_walk_ctx_t
input_source
vl_api_qos_source_t input_source
Definition: qos.api:53
vl_api_qos_store_dump_t::client_index
u32 client_index
Definition: qos.api:77
vl_api_qos_record_enable_disable_t
Enable/Disable QoS recording The QoS bits from the packet at the specified input layer are copied int...
Definition: qos.api:109
vl_api_qos_record_details_t::context
u32 context
Definition: qos.api:131
vl_api_qos_egress_map_details_t::map
vl_api_qos_egress_map_t map
Definition: qos.api:197
qos_source_t
enum qos_source_t_ qos_source_t
QoS types.
send_qos_record_details
static walk_rc_t send_qos_record_details(u32 sw_if_index, qos_source_t input_source, void *c)
Definition: qos_api.c:95
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
qos_egress_map_send_walk_ctx_t
struct qos_egress_map_send_walk_ctx_t_ qos_egress_map_send_walk_ctx_t
qos_mark_send_walk_ctx_t
struct qos_mark_send_walk_ctx_t_ qos_mark_send_walk_ctx_t
qos_egress_map_walk
void qos_egress_map_walk(qos_egress_map_walk_cb_t fn, void *c)
Definition: qos_egress_map.c:127
vl_api_qos_record_details_t
Details of QoS recording configs.
Definition: qos.api:129
vl_api_qos_mark_details_t
QoS marking details.
Definition: qos.api:244
qos_mark_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:293
vl_api_qos_mark_enable_disable_t
Enable/Disable QoS marking.
Definition: qos.api:223
QOS_API_SOURCE_MPLS
@ QOS_API_SOURCE_MPLS
Definition: qos.api:37
qos_egress_map_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:227
qos_mark_send_walk_ctx_t_
Definition: qos_api.c:291
format_fns.h
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: qos_api.c:31
qos_store_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:157
qos_egress_map_update
void qos_egress_map_update(qos_egress_map_id_t mid, qos_source_t input_source, qos_bits_t *values)
Add a qos-egress map to an interface.
Definition: qos_egress_map.c:101
qos_store.h
u32
unsigned int u32
Definition: types.h:88
vl_api_qos_store_details_t::store
vl_api_qos_store_t store
Definition: qos.api:87
qos_egress_map_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:226
FOR_EACH_QOS_SOURCE
#define FOR_EACH_QOS_SOURCE(_src)
Definition: qos_types.h:54
vl_api_qos_egress_map_dump_t::client_index
u32 client_index
Definition: qos.api:187
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
qos_egress_map_delete
void qos_egress_map_delete(qos_egress_map_id_t mid)
Definition: qos_egress_map.c:113
vl_api_qos_store_dump_t
Dump the QoS store configs.
Definition: qos.api:75
api_helper_macros.h
qos_mark.h
vl_api_qos_mark_dump_t::context
u32 context
Definition: qos.api:237
value
u8 value
Definition: qos.api:54
vl_api_qos_mark_enable_disable_t::mark
vl_api_qos_mark_t mark
Definition: qos.api:228
vl_api_qos_egress_map_update_t
Update a QoS Map A QoS map, translates from the QoS value in the packet set by the 'record' feature,...
Definition: qos.api:164
vl_api_qos_egress_map_delete_t
Delete a Qos Map.
Definition: qos.api:175
qos_mark_enable
int qos_mark_enable(u32 sw_if_index, qos_source_t output_source, qos_egress_map_id_t mid)
enable QoS marking by associating a MAP with an interface.
Definition: qos_mark.c:79
vlib_main_t
Definition: main.h:102
qos_record.h
qos_record_send_walk_ctx_t
struct qos_record_send_walk_ctx_t_ qos_record_send_walk_ctx_t
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
qos_record_send_walk_ctx_t_
Definition: qos_api.c:88
qos_record_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:90
QOS_API_SOURCE_IP
@ QOS_API_SOURCE_IP
Definition: qos.api:38
qos_source_decode
static int qos_source_decode(vl_api_qos_source_t v, qos_source_t *q)
Definition: qos_api.c:37
qos_mark_disable
int qos_mark_disable(u32 sw_if_index, qos_source_t output_source)
Definition: qos_mark.c:103
qos_egress_map_id_t
u32 qos_egress_map_id_t
A QOS egress map translates from the COS bits stored in the packet's meta-data into a per-protocol CO...
Definition: qos_egress_map.h:32
vl_api_qos_record_dump_t_handler
static void vl_api_qos_record_dump_t_handler(vl_api_qos_record_dump_t *mp)
Definition: qos_api.c:114
vl_api_qos_egress_map_update_t_handler
void vl_api_qos_egress_map_update_t_handler(vl_api_qos_egress_map_update_t *mp)
Definition: qos_api.c:198
map_id
u32 map_id
Definition: qos.api:214
QOS_SOURCE_IP
@ QOS_SOURCE_IP
Definition: qos_types.h:38
rv
int __clib_unused rv
Definition: application.c:491
qos_egress_map_send_walk_ctx_t_
Definition: qos_api.c:224
vnet.h
api_errno.h
qos_record_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:91
vl_api_qos_mark_dump_t::client_index
u32 client_index
Definition: qos.api:236
qos_record_disable
int qos_record_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:81
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vl_api_qos_record_dump_t::client_index
u32 client_index
Definition: qos.api:122
vl_api_qos_egress_map_update_t::map
vl_api_qos_egress_map_t map
Definition: qos.api:168
vl_api_qos_record_enable_disable_t::record
vl_api_qos_record_t record
Definition: qos.api:114
vl_api_qos_store_enable_disable_t_handler
void vl_api_qos_store_enable_disable_t_handler(vl_api_qos_store_enable_disable_t *mp)
Definition: qos_api.c:130
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
qos_store_disable
int qos_store_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_store.c:88
vl_api_qos_record_enable_disable_t_handler
void vl_api_qos_record_enable_disable_t_handler(vl_api_qos_record_enable_disable_t *mp)
Definition: qos_api.c:65
vl_api_qos_store_details_t::context
u32 context
Definition: qos.api:86
qos_store_enable
int qos_store_enable(u32 sw_if_index, qos_source_t input_source, qos_bits_t value)
Definition: qos_store.c:64