FD.io VPP  v16.06
Vector Packet Processing
config.h
Go to the documentation of this file.
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  * config.h: feature configuration
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_vnet_config_h
41 #define included_vnet_config_h
42 
43 #include <vlib/vlib.h>
44 #include <vppinfra/heap.h>
45 
46 typedef struct {
47  /* Features are prioritized by index. Smaller indices get
48  performed first. */
50 
51  /* VLIB node which performs feature. */
53 
54  /* Next index relative to previous node or main node. */
56 
57  /* Opaque per feature configuration data. */
60 
61 always_inline void
63 { vec_free (f->feature_config); }
64 
65 typedef struct {
66  /* Sorted vector of features for this configuration. */
68 
69  /* Config string as vector for hashing. */
71 
72  /* Config string including all next indices and feature data as a vector. */
73  u32 config_string_heap_index, config_string_heap_handle;
74 
75  /* Index in main pool. */
77 
78  /* Number of interfaces/traffic classes that reference this config. */
81 
82 typedef struct {
83  /* Pool of configs. Index 0 is always null config and is never deleted. */
85 
86  /* Hash table mapping vector config string to config pool index. */
88 
89  /* Global heap of configuration data. */
91 
92  /* Node index which starts/ends feature processing. */
93  u32 * start_node_indices, end_node_index;
94 
95  /* Interior feature processing nodes (not including start and end nodes). */
97 
98  /* Temporary vector for holding config strings. Used to avoid continually
99  allocating vectors. */
102 
103 always_inline void
105 {
107  vec_foreach (f, c->features)
109  vec_free (c->features);
112 }
113 
114 always_inline void *
116  u32 * config_index,
117  u32 * next_index,
118  u32 n_data_bytes)
119 {
120  u32 i, n, * d;
121 
122  i = *config_index;
123 
125 
126  n = round_pow2 (n_data_bytes, sizeof (d[0])) / sizeof (d[0]);
127 
128  /* Last 32 bits are next index. */
129  *next_index = d[n];
130 
131  /* Advance config index to next config. */
132  *config_index = (i + n + 1);
133 
134  /* Return config data to user for this feature. */
135  return (void *) d;
136 }
137 
138 void vnet_config_init (vlib_main_t * vm,
139  vnet_config_main_t * cm,
140  char * start_node_names[],
141  int n_start_node_names,
142  char * feature_node_names[],
143  int n_feature_node_names);
144 
145 /* Calls to add/delete features from configurations. */
147  vnet_config_main_t * cm,
148  u32 config_id,
149  u32 feature_index,
150  void * feature_config,
151  u32 n_feature_config_bytes);
152 
154  vnet_config_main_t * cm,
155  u32 config_id,
156  u32 feature_index,
157  void * feature_config,
158  u32 n_feature_config_bytes);
159 
160 #endif /* included_vnet_config_h */
always_inline uword round_pow2(uword x, uword pow2)
Definition: clib.h:255
u32 vnet_config_add_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_id, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:233
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
vnet_config_feature_t * features
Definition: config.h:67
#define heap_elt_at_index(v, index)
Definition: heap.h:267
u32 config_string_heap_handle
Definition: config.h:73
void vnet_config_init(vlib_main_t *vm, vnet_config_main_t *cm, char *start_node_names[], int n_start_node_names, char *feature_node_names[], int n_feature_node_names)
Definition: config.c:161
u32 * config_string_vector
Definition: config.h:70
u32 * node_index_by_feature_index
Definition: config.h:96
#define always_inline
Definition: clib.h:84
always_inline void vnet_config_free(vnet_config_main_t *cm, vnet_config_t *c)
Definition: config.h:104
u32 * start_node_indices
Definition: config.h:93
u32 vnet_config_del_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_id, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:284
u32 * config_string_heap
Definition: config.h:90
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
always_inline void vnet_config_feature_free(vnet_config_feature_t *f)
Definition: config.h:62
unsigned int u32
Definition: types.h:88
void heap_dealloc(void *v, uword handle)
Definition: heap.c:478
u32 index
Definition: config.h:76
u64 uword
Definition: types.h:112
u32 * config_string_temp
Definition: config.h:100
vnet_config_t * config_pool
Definition: config.h:84
#define vec_foreach(var, vec)
Vector iterator.
u32 reference_count
Definition: config.h:79
always_inline void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
Definition: config.h:115
uword * config_string_hash
Definition: config.h:87
u32 config_string_heap_index
Definition: config.h:73
u32 * feature_config
Definition: config.h:58