VPP-189 More coverity bug fixes
[vpp.git] / vnet / vnet / policer / policer.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 #ifndef __included_policer_h__
16 #define __included_policer_h__
17
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20
21 #include <vnet/policer/xlate.h>
22 #include <vnet/policer/police.h>
23
24 typedef struct {
25   /* policer pool, aligned */
26   policer_read_response_type_st  * policers;
27
28   /* config + template h/w policer instance parallel pools */
29   sse2_qos_pol_cfg_params_st * configs;
30   policer_read_response_type_st * policer_templates;
31   
32   /* Config by name hash */
33   uword * policer_config_by_name;
34
35   /* Policer by name hash */
36   uword * policer_index_by_name;
37
38   /* Policer by sw_if_index vector */
39   u32 * policer_index_by_sw_if_index;
40
41   /* convenience */
42   vlib_main_t * vlib_main;
43   vnet_main_t * vnet_main;
44 } vnet_policer_main_t;
45
46 vnet_policer_main_t vnet_policer_main;
47
48 typedef enum {
49   VNET_POLICER_INDEX_BY_SW_IF_INDEX,
50   VNET_POLICER_INDEX_BY_OPAQUE,
51   VNET_POLICER_INDEX_BY_EITHER,
52 } vnet_policer_index_t;
53
54 typedef enum {
55   VNET_POLICER_NEXT_TRANSMIT,
56   VNET_POLICER_NEXT_DROP,
57   VNET_POLICER_N_NEXT,
58 } vnet_policer_next_t;
59
60 #define foreach_vnet_dscp \
61   _(0 , CS0,  "CS0")  \
62   _(8 , CS1,  "CS1")  \
63   _(10, AF11, "AF11") \
64   _(12, AF12, "AF12") \
65   _(14, AF13, "AF13") \
66   _(16, CS2,  "CS2")  \
67   _(18, AF21, "AF21") \
68   _(20, AF22, "AF22") \
69   _(22, AF23, "AF23") \
70   _(24, CS3,  "CS3")  \
71   _(26, AF31, "AF31") \
72   _(28, AF32, "AF32") \
73   _(30, AF33, "AF33") \
74   _(32, CS4,  "CS4")  \
75   _(34, AF41, "AF41") \
76   _(36, AF42, "AF42") \
77   _(38, AF43, "AF43") \
78   _(40, CS5,  "CS5")  \
79   _(46, EF,   "EF")   \
80   _(48, CS6,  "CS6")  \
81   _(50, CS7,  "CS7")
82
83 typedef enum {
84 #define _(v,f,str) VNET_DSCP_##f = v,
85   foreach_vnet_dscp
86 #undef _
87 } vnet_dscp_t;
88
89 u8 * format_policer_instance (u8 * s, va_list * va);
90 clib_error_t * policer_add_del (vlib_main_t *vm,
91                                 u8 * name,
92                                 sse2_qos_pol_cfg_params_st * cfg,
93                                 u32 * policer_index,
94                                 u8 is_add);
95
96 #endif /* __included_policer_h__ */