FD.io VPP  v20.01-48-g3e0dafb74
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 {
370  api_main_t *am = vlibapi_get_main ();
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  */
static int qos_source_decode(vl_api_qos_source_t v, qos_source_t *q)
Definition: qos_api.c:58
vl_api_qos_source_t output_source
Definition: qos.api:215
Delete a Qos Map.
Definition: qos.api:175
void qos_record_walk(qos_record_walk_cb_t fn, void *c)
Definition: qos_record.c:104
static void vl_api_qos_store_dump_t_handler(vl_api_qos_store_dump_t *mp)
Definition: qos_api.c:203
bool enable[default=true]
Definition: qos.api:227
static clib_error_t * qos_api_hookup(vlib_main_t *vm)
Definition: qos_api.c:368
void qos_egress_map_walk(qos_egress_map_walk_cb_t fn, void *c)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
void vl_api_qos_egress_map_update_t_handler(vl_api_qos_egress_map_update_t *mp)
Definition: qos_api.c:219
vl_api_qos_record_t record
Definition: qos.api:132
u32 map_id
Definition: qos.api:214
void vl_api_qos_egress_map_delete_t_handler(vl_api_qos_egress_map_delete_t *mp)
Definition: qos_api.c:235
void * vl_msg_api_alloc_zero(int nbytes)
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
unsigned char u8
Definition: types.h:56
void qos_egress_map_delete(qos_egress_map_id_t mid)
int qos_mark_disable(u32 sw_if_index, qos_source_t output_source)
Definition: qos_mark.c:103
#define clib_memcpy(d, s, n)
Definition: string.h:180
static void setup_message_id_table(api_main_t *am)
Definition: qos_api.c:360
Some external source, e.g.
Definition: qos_types.h:35
Dump the QoS egress maps.
Definition: qos.api:185
enum walk_rc_t_ walk_rc_t
Walk return code.
vl_api_registration_t * reg
Definition: qos_api.c:314
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_interface_index_t sw_if_index
Definition: gre.api:59
VLIB_API_INIT_FUNCTION(qos_api_hookup)
vl_api_registration_t * reg
Definition: qos_api.c:111
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
#define FOR_EACH_QOS_SOURCE(_src)
Definition: qos_types.h:54
unsigned int u32
Definition: types.h:88
void qos_store_walk(qos_store_walk_cb_t fn, void *c)
Definition: qos_store.c:111
vl_api_qos_source_t input_source
Definition: qos.api:53
#define foreach_qos_api_msg
Definition: qos_api.c:46
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.
static vl_api_qos_source_t qos_source_encode(qos_source_t q)
Definition: qos_api.c:80
long ctx[MAX_CONNS]
Definition: main.c:144
bool enable[default=true]
Definition: qos.api:113
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
vl_api_qos_store_t store
Definition: qos.api:87
static void vl_api_qos_record_dump_t_handler(vl_api_qos_record_dump_t *mp)
Definition: qos_api.c:135
#define REPLY_MACRO(t)
vl_api_registration_t * reg
Definition: qos_api.c:247
vlib_main_t * vm
Definition: in2out_ed.c:1810
struct qos_record_send_walk_ctx_t_ qos_record_send_walk_ctx_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_registration_t * reg
Definition: qos_api.c:177
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:225
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
#define BAD_SW_IF_INDEX_LABEL
svmdb_client_t * c
enum qos_source_t_ qos_source_t
QoS types.
Dump QoS marking configs.
Definition: qos.api:234
static walk_rc_t send_qos_record_details(u32 sw_if_index, qos_source_t input_source, void *c)
Definition: qos_api.c:116
struct qos_egress_map_send_walk_ctx_t_ qos_egress_map_send_walk_ctx_t
vl_api_qos_mark_t mark
Definition: qos.api:228
QoS map details.
Definition: qos.api:194
vl_api_qos_egress_map_t map
Definition: qos.api:197
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
struct qos_store_send_walk_ctx_t_ qos_store_send_walk_ctx_t
For a given output source a table maps each value of every input source.
Enable/Disable QoS storing The QoS bits from the packet at the specified input layer are copied into ...
Definition: qos.api:64
u8 value
Definition: qos.api:54
Dump the QoS record configs.
Definition: qos.api:120
Details of QoS recording configs.
Definition: qos.api:129
struct qos_mark_send_walk_ctx_t_ qos_mark_send_walk_ctx_t
vl_api_qos_record_t record
Definition: qos.api:114
vl_api_qos_store_t store
Definition: qos.api:69
int qos_record_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:85
vl_api_qos_egress_map_t map
Definition: qos.api:168
int qos_store_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_store.c:88
Enable/Disable QoS marking.
Definition: qos.api:223
void vl_api_qos_mark_enable_disable_t_handler(vl_api_qos_mark_enable_disable_t *mp)
Definition: qos_api.c:291
QoS marking details.
Definition: qos.api:244
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_qos_mark_t mark
Definition: qos.api:247
Update a QoS Map A QoS map, translates from the QoS value in the packet set by the &#39;record&#39; feature...
Definition: qos.api:164
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:378
static void vl_api_qos_mark_dump_t_handler(vl_api_qos_mark_dump_t *mp)
Definition: qos_api.c:340
void qos_mark_walk(qos_mark_walk_cb_t fn, void *c)
Definition: qos_mark.c:121
int qos_record_enable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:71
void vl_api_qos_store_enable_disable_t_handler(vl_api_qos_store_enable_disable_t *mp)
Definition: qos_api.c:151
int qos_store_enable(u32 sw_if_index, qos_source_t input_source, qos_bits_t value)
Definition: qos_store.c:64
Dump the QoS store configs.
Definition: qos.api:75
qos_bits_t qem_output[QOS_N_SOURCES][256]
The array of output mapped values; output = eq_qos[input-source][input-value].
u8 qos_bits_t
Type, er, safety for us water based entities.
Definition: qos_types.h:68
bool enable[default=true]
Definition: qos.api:68
u32 qos_egress_map_id_t
A QOS egress map translates from the COS bits stored in the packet&#39;s meta-data into a per-protocol CO...
#define VALIDATE_SW_IF_INDEX(mp)
void vl_api_qos_record_enable_disable_t_handler(vl_api_qos_record_enable_disable_t *mp)
Definition: qos_api.c:86
Details of QoS recording configs.
Definition: qos.api:84