FD.io VPP  v19.04.2-12-g66b1689
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_mark.h>
25 
26 #include <vnet/vnet_msg_enum.h>
27 
28 #define vl_typedefs /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
30 #undef vl_typedefs
31 
32 #define vl_endianfun /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
34 #undef vl_endianfun
35 
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #define vl_printfun
39 #include <vnet/vnet_all_api_h.h>
40 #undef vl_printfun
41 
43 
44 
45 #define foreach_qos_api_msg \
46  _(QOS_RECORD_ENABLE_DISABLE, qos_record_enable_disable) \
47  _(QOS_EGRESS_MAP_DELETE, qos_egress_map_delete) \
48  _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update) \
49  _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable)
50 
51 static int
52 qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
53 {
54  v = ntohl (v);
55 
56  switch (v)
57  {
58  case QOS_API_SOURCE_EXT:
59  *q = QOS_SOURCE_EXT;
60  return 0;
62  *q = QOS_SOURCE_VLAN;
63  return 0;
65  *q = QOS_SOURCE_MPLS;
66  return 0;
67  case QOS_API_SOURCE_IP:
68  *q = QOS_SOURCE_IP;
69  return 0;
70  }
71 
72  return (VNET_API_ERROR_INVALID_VALUE);
73 }
74 
75 void
77  * mp)
78 {
79  vl_api_qos_record_enable_disable_reply_t *rmp;
80  qos_source_t qs;
81  int rv = 0;
82 
83  rv = qos_source_decode (mp->input_source, &qs);
84 
85  if (0 == rv)
86  {
87  if (mp->enable)
88  rv = qos_record_enable (ntohl (mp->sw_if_index), qs);
89  else
90  rv = qos_record_disable (ntohl (mp->sw_if_index), qs);
91  }
92 
93  REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
94 }
95 
96 void
98 {
99  vl_api_qos_egress_map_update_reply_t *rmp;
100  qos_source_t qs;
101  int rv = 0;
102 
104  {
105  qos_egress_map_update (ntohl (mp->map_id), qs, &mp->rows[qs].outputs[0]);
106  }
107 
108  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_UPDATE_REPLY);
109 }
110 
111 void
113 {
114  vl_api_qos_egress_map_delete_reply_t *rmp;
115  int rv = 0;
116 
117  qos_egress_map_delete (ntohl (mp->map_id));
118 
119  REPLY_MACRO (VL_API_QOS_EGRESS_MAP_DELETE_REPLY);
120 }
121 
122 void
125 {
126  vl_api_qos_mark_enable_disable_reply_t *rmp;
127  qos_source_t qs;
128  int rv = 0;
129 
130  rv = qos_source_decode (mp->output_source, &qs);
131 
132  if (0 == rv)
133  {
134  if (mp->enable)
135  rv =
136  qos_mark_enable (ntohl (mp->sw_if_index), qs, ntohl (mp->map_id));
137  else
138  rv = qos_mark_disable (ntohl (mp->sw_if_index), qs);
139  }
140 
141  REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
142 }
143 
144 #define vl_msg_name_crc_list
145 #include <vnet/qos/qos.api.h>
146 #undef vl_msg_name_crc_list
147 
148 static void
150 {
151 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
152  foreach_vl_msg_name_crc_qos;
153 #undef _
154 }
155 
156 static clib_error_t *
158 {
159  api_main_t *am = &api_main;
160 
161 #define _(N,n) \
162  vl_msg_api_set_handlers(VL_API_##N, #n, \
163  vl_api_##n##_t_handler, \
164  vl_noop_handler, \
165  vl_api_##n##_t_endian, \
166  vl_api_##n##_t_print, \
167  sizeof(vl_api_##n##_t), 1);
169 #undef _
170 
171  /*
172  * Set up the (msg_name, crc, message-id) table
173  */
175 
176  return 0;
177 }
178 
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "gnu")
186  * End:
187  */
static int qos_source_decode(vl_api_qos_source_t v, qos_source_t *q)
Definition: qos_api.c:52
Delete a Qos Map.
Definition: qos.api:77
vl_api_qos_egress_map_row_t rows[4]
Definition: qos.api:71
vl_api_qos_source_t output_source
Definition: qos.api:101
static clib_error_t * qos_api_hookup(vlib_main_t *vm)
Definition: qos_api.c:157
void vl_api_qos_egress_map_update_t_handler(vl_api_qos_egress_map_update_t *mp)
Definition: qos_api.c:97
void vl_api_qos_egress_map_delete_t_handler(vl_api_qos_egress_map_delete_t *mp)
Definition: qos_api.c:112
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
static void setup_message_id_table(api_main_t *am)
Definition: qos_api.c:149
Some external source, e.g.
Definition: qos_types.h:35
VLIB_API_INIT_FUNCTION(qos_api_hookup)
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
#define foreach_qos_api_msg
Definition: qos_api.c:45
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.
#define REPLY_MACRO(t)
Enable/Disable QoS recording The QoS bits from the packet at the specified input layer are copied int...
Definition: qos.api:41
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
vlib_main_t * vm
Definition: buffer.c:312
enum qos_source_t_ qos_source_t
QoS types.
int qos_record_disable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:85
Enable/Disable QoS marking The QoS bits from the packet are mapped (using the desired egress map) int...
Definition: qos.api:95
void vl_api_qos_mark_enable_disable_t_handler(vl_api_qos_mark_enable_disable_t *mp)
Definition: qos_api.c:124
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:66
int qos_record_enable(u32 sw_if_index, qos_source_t input_source)
Definition: qos_record.c:71
vl_api_qos_source_t input_source
Definition: qos.api:46
api_main_t api_main
Definition: api_shared.c:35
void vl_api_qos_record_enable_disable_t_handler(vl_api_qos_record_enable_disable_t *mp)
Definition: qos_api.c:76