FD.io VPP  v21.06-3-gbb25fbf28
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/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 
45 
46 #define foreach_qos_api_msg \
47  _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
48  _(QOS_RECORD_DUMP, qos_record_dump) \
49  _(QOS_STORE_ENABLE_DISABLE, qos_store_enable_disable) \
50  _(QOS_STORE_DUMP, qos_store_dump) \
51  _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
52  _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
53  _(QOS_EGRESS_MAP_DUMP, qos_egress_map_dump) \
54  _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable) \
55  _(QOS_MARK_DUMP, qos_mark_dump)
56 
57 static int
58 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
59 {
60  switch (v)
61  {
62  case QOS_API_SOURCE_EXT:
63  *q = QOS_SOURCE_EXT;
64  return 0;
66  *q = QOS_SOURCE_VLAN;
67  return 0;
69  *q = QOS_SOURCE_MPLS;
70  return 0;
71  case QOS_API_SOURCE_IP:
72  *q = QOS_SOURCE_IP;
73  return 0;
74  }
75 
76  return (VNET_API_ERROR_INVALID_VALUE);
77 }
78 
79 static vl_api_qos_source_t
81 {
82  return ((vl_api_qos_source_t) q);
83 }
84 
85 void
87  * mp)
88 {
89  vl_api_qos_record_enable_disable_reply_t *rmp;
90  qos_source_t qs;
91  int rv = 0;
92 
94 
95  rv = qos_source_decode (mp->record.input_source, &qs);
96 
97  if (0 == rv)
98  {
99  if (mp->enable)
100  rv = qos_record_enable (ntohl (mp->record.sw_if_index), qs);
101  else
102  rv = qos_record_disable (ntohl (mp->record.sw_if_index), qs);
103  }
104 
106  REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
107 }
108 
110 {
114 
115 static walk_rc_t
117 {
120 
121  ctx = c;
122  mp = vl_msg_api_alloc_zero (sizeof (*mp));
123 
124  mp->_vl_msg_id = ntohs (VL_API_QOS_RECORD_DETAILS);
125  mp->context = ctx->context;
126  mp->record.sw_if_index = htonl (sw_if_index);
127  mp->record.input_source = qos_source_encode (input_source);
128 
129  vl_api_send_msg (ctx->reg, (u8 *) mp);
130 
131  return (WALK_CONTINUE);
132 }
133 
134 static void
136 {
138 
140  if (!reg)
141  return;
142 
144  .reg = reg,
145  .context = mp->context,
146  };
148 }
149 
150 void
152  * mp)
153 {
154  vl_api_qos_store_enable_disable_reply_t *rmp;
155  qos_source_t qs;
156  int rv = 0;
157 
158  VALIDATE_SW_IF_INDEX (&(mp->store));
159 
160  rv = qos_source_decode (mp->store.input_source, &qs);
161 
162  if (0 == rv)
163  {
164  if (mp->enable)
165  rv = qos_store_enable (ntohl (mp->store.sw_if_index), qs,
166  mp->store.value);
167  else
168  rv = qos_store_disable (ntohl (mp->store.sw_if_index), qs);
169  }
170 
172  REPLY_MACRO (VL_API_QOS_STORE_ENABLE_DISABLE_REPLY);
173 }
174 
176 {
180 
181 static walk_rc_t
184 {
187 
188  ctx = c;
189  mp = vl_msg_api_alloc_zero (sizeof (*mp));
190 
191  mp->_vl_msg_id = ntohs (VL_API_QOS_STORE_DETAILS);
192  mp->context = ctx->context;
193  mp->store.sw_if_index = htonl (sw_if_index);
194  mp->store.input_source = qos_source_encode (input_source);
195  mp->store.value = value;
196 
197  vl_api_send_msg (ctx->reg, (u8 *) mp);
198 
199  return (WALK_CONTINUE);
200 }
201 
202 static void
204 {
206 
208  if (!reg)
209  return;
210 
212  .reg = reg,
213  .context = mp->context,
214  };
216 }
217 
218 void
220 {
221  vl_api_qos_egress_map_update_reply_t *rmp;
222  qos_source_t qs;
223  int rv = 0;
224 
226  {
227  qos_egress_map_update (ntohl (mp->map.id), qs,
228  &mp->map.rows[qs].outputs[0]);
229  }
230 
231  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
232 }
233 
234 void
236 {
237  vl_api_qos_egress_map_delete_reply_t *rmp;
238  int rv = 0;
239 
240  qos_egress_map_delete (ntohl (mp->id));
241 
242  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
243 }
244 
246 {
250 
251 static walk_rc_t
253  const qos_egress_map_t * m, void *c)
254 {
257  u8 ii;
258 
259  ctx = c;
260  mp = vl_msg_api_alloc_zero (sizeof (*mp));
261 
262  mp->_vl_msg_id = ntohs (VL_API_QOS_EGRESS_MAP_DETAILS);
263  mp->context = ctx->context;
264  mp->map.id = htonl (id);
265 
266  for (ii = 0; ii < 4; ii++)
267  clib_memcpy (mp->map.rows[ii].outputs, m->qem_output[ii], 256);
268 
269  vl_api_send_msg (ctx->reg, (u8 *) mp);
270 
271  return (WALK_CONTINUE);
272 }
273 
274 static void
276 {
278 
280  if (!reg)
281  return;
282 
284  .reg = reg,
285  .context = mp->context,
286  };
288 }
289 
290 void
292  mp)
293 {
294  vl_api_qos_mark_enable_disable_reply_t *rmp;
295  qos_source_t qs;
296  int rv = 0;
297 
298  rv = qos_source_decode (mp->mark.output_source, &qs);
299 
300  if (0 == rv)
301  {
302  if (mp->enable)
303  rv = qos_mark_enable (ntohl (mp->mark.sw_if_index),
304  qs, ntohl (mp->mark.map_id));
305  else
306  rv = qos_mark_disable (ntohl (mp->mark.sw_if_index), qs);
307  }
308 
309  REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
310 }
311 
313 {
317 
318 static walk_rc_t
321 {
324 
325  ctx = c;
326  mp = vl_msg_api_alloc_zero (sizeof (*mp));
327 
328  mp->_vl_msg_id = ntohs (VL_API_QOS_MARK_DETAILS);
329  mp->context = ctx->context;
330  mp->mark.sw_if_index = htonl (sw_if_index);
331  mp->mark.output_source = qos_source_encode (output_source);
332  mp->mark.map_id = htonl (map_id);
333 
334  vl_api_send_msg (ctx->reg, (u8 *) mp);
335 
336  return (WALK_CONTINUE);
337 }
338 
339 static void
341 {
343 
345  if (!reg)
346  return;
347 
349  .reg = reg,
350  .context = mp->context,
351  };
353 }
354 
355 #define vl_msg_name_crc_list
356 #include <vnet/qos/qos.api.h>
357 #undef vl_msg_name_crc_list
358 
359 static void
361 {
362 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
363  foreach_vl_msg_name_crc_qos;
364 #undef _
365 }
366 
367 static clib_error_t *
369 {
371 
372 #define _(N,n) \
373  vl_msg_api_set_handlers(VL_API_##N, #n, \
374  vl_api_##n##_t_handler, \
375  vl_noop_handler, \
376  vl_api_##n##_t_endian, \
377  vl_api_##n##_t_print, \
378  sizeof(vl_api_##n##_t), 1);
380 #undef _
381 
382  /*
383  * Set up the (msg_name, crc, message-id) table
384  */
386 
387  return 0;
388 }
389 
391 
392 /*
393  * fd.io coding-style-patch-verification: ON
394  *
395  * Local Variables:
396  * eval: (c-set-style "gnu")
397  * End:
398  */
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:340
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:235
qos_api_hookup
static clib_error_t * qos_api_hookup(vlib_main_t *vm)
Definition: qos_api.c:368
vl_api_qos_store_dump_t::context
u32 context
Definition: qos.api:78
foreach_qos_api_msg
#define foreach_qos_api_msg
Definition: qos_api.c:46
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
qos_store_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:177
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:252
qos_source_encode
static vl_api_qos_source_t qos_source_encode(qos_source_t q)
Definition: qos_api.c:80
am
app_main_t * am
Definition: application.c:489
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:315
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:291
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:275
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:203
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
vnet_msg_enum.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:182
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
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:319
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: qos_api.c:360
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
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
qos_store_send_walk_ctx_t_
Definition: qos_api.c:175
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:116
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
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
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:314
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:248
qos_mark_send_walk_ctx_t_
Definition: qos_api.c:312
qos_store_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:178
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:247
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:109
qos_record_send_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: qos_api.c:111
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:58
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
vnet_all_api_h.h
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:135
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:219
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:245
vnet.h
api_errno.h
qos_record_send_walk_ctx_t_::context
u32 context
Definition: qos_api.c:112
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:151
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:86
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