policer: add api to bind policer to worker
[vpp.git] / src / vnet / policer / xlate.h
1 /*
2  * Copyright (c) 2015 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  * from gdp_logical_qos.h
17  *---------------------------------------------------------------------------
18  */
19
20 #ifndef __included_xlate_h__
21 #define __included_xlate_h__
22
23 #include <vnet/ip/ip_packet.h>
24 #include <vnet/policer/police.h>
25
26 /*
27  * edt: * enum qos_policer_type_en
28  *  Defines type of policer to be allocated
29  */
30 typedef enum qos_policer_type_en_
31 {
32   QOS_POLICER_TYPE_1R2C = 0,
33   QOS_POLICER_TYPE_1R3C_RFC_2697 = 1,
34   QOS_POLICER_TYPE_2R3C_RFC_2698 = 2,
35   QOS_POLICER_TYPE_2R3C_RFC_4115 = 3,
36   QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1 = 4,
37   QOS_POLICER_TYPE_MAX
38 } __clib_packed qos_policer_type_en;
39
40 /*
41  * edt: * enum
42  *  Enum used to define type of rounding used when calculating policer values
43  */
44 typedef enum
45 {
46   QOS_ROUND_TO_CLOSEST = 0,
47   QOS_ROUND_TO_UP,
48   QOS_ROUND_TO_DOWN,
49   QOS_ROUND_INVALID
50 } __clib_packed qos_round_type_en;
51
52 /*
53  * edt: * enum
54  *  Enum used to define type of rate for configuration, either pps or kbps.
55  *  If kbps, then burst is in bytes, if pps, then burst is in ms.
56  *
57  *  Default of zero is kbps, which is inline with how it is programmed
58  *  in actual hardware.  However, the warning is that this is reverse logic
59  *  of units_in_bits field in static_policer_parameters_st, which is
60  *  inline with sse_punt_drop.h.
61  */
62 typedef enum
63 {
64   QOS_RATE_KBPS = 0,
65   QOS_RATE_PPS,
66   QOS_RATE_INVALID
67 } __clib_packed qos_rate_type_en;
68
69 /*
70  * edt * struct qos_pol_action_params_st
71  * This structure is used to hold user configured police action parameters.
72  *
73  * element: action_type
74  *      Action type (see qos_action_type_en).
75  * element: dscp
76  *      DSCP value to set when action is QOS_ACTION_MARK_AND_TRANSMIT.
77  */
78 typedef struct qos_pol_action_params_st_
79 {
80   qos_action_type_en action_type;
81   ip_dscp_t dscp;
82 } qos_pol_action_params_st;
83
84 /*
85  * edt: * struct qos_pol_cfg_params_st
86  *
87  * Description:
88  * This structure is used to hold user configured policing parameters.
89  *
90  * element: cir_kbps
91  *      CIR in kbps.
92  * element: eir_kbps
93  *      EIR or PIR in kbps.
94  * element: cb_bytes
95  *      Committed Burst in bytes.
96  * element: eb_bytes
97  *      Excess or Peak Burst in bytes.
98  * element: cir_pps
99  *      CIR in pps.
100  * element: eir_pps
101  *      EIR or PIR in pps.
102  * element: cb_ms
103  *      Committed Burst in milliseconds.
104  * element: eb_ms
105  *      Excess or Peak Burst in milliseconds.
106  * element: rate_type
107  *      Indicates the union if in kbps/bytes or pps/ms.
108  * element: rfc
109  *      Policer algorithm - 1R2C, 1R3C (2697), 2R3C (2698) or 2R3C (4115). See
110  *      qos_policer_type_en
111  * element: rnd_type
112  *      Rounding type (see qos_round_type_en). Needed when policer values
113  *      need to be rounded. Caller can decide on type of rounding used
114  */
115 typedef struct qos_pol_cfg_params_st_
116 {
117   union
118   {
119     struct
120     {
121       u32 cir_kbps;
122       u32 eir_kbps;
123       u64 cb_bytes;
124       u64 eb_bytes;
125     } kbps;
126     struct
127     {
128       u32 cir_pps;
129       u32 eir_pps;
130       u64 cb_ms;
131       u64 eb_ms;
132     } pps;
133   } rb;                         /* rate burst config */
134   qos_rate_type_en rate_type;
135   qos_round_type_en rnd_type;
136   qos_policer_type_en rfc;
137   u8 color_aware;
138   u8 overwrite_bucket;          /* for debugging purposes */
139   u32 current_bucket;           /* for debugging purposes */
140   u32 extended_bucket;          /* for debugging purposes */
141   qos_pol_action_params_st conform_action;
142   qos_pol_action_params_st exceed_action;
143   qos_pol_action_params_st violate_action;
144 } qos_pol_cfg_params_st;
145
146 typedef struct qos_pol_hw_params_st_
147 {
148   u8 rfc;
149   u8 allow_negative;
150   u8 rate_exp;
151   u16 avg_rate_man;
152   u16 peak_rate_man;
153   u8 comm_bkt_limit_exp;
154   u8 comm_bkt_limit_man;
155   u8 extd_bkt_limit_exp;
156   u8 extd_bkt_limit_man;
157   u32 comm_bkt;
158   u32 extd_bkt;
159 } qos_pol_hw_params_st;
160
161 int pol_logical_2_physical (qos_pol_cfg_params_st *cfg,
162                             policer_read_response_type_st *phys);
163
164 #endif /* __included_xlate_h__ */
165
166 /*
167  * fd.io coding-style-patch-verification: ON
168  *
169  * Local Variables:
170  * eval: (c-set-style "gnu")
171  * End:
172  */