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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * config.h: feature configuration
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
40 #ifndef included_vnet_config_h
41 #define included_vnet_config_h
43 #include <vlib/vlib.h>
44 #include <vppinfra/heap.h>
47 /* Features are prioritized by index. Smaller indices get
51 /* VLIB node which performs feature. */
54 /* Next index relative to previous node or main node. */
57 /* Opaque per feature configuration data. */
59 } vnet_config_feature_t;
62 vnet_config_feature_free (vnet_config_feature_t * f)
63 { vec_free (f->feature_config); }
66 /* Sorted vector of features for this configuration. */
67 vnet_config_feature_t * features;
69 /* Config string as vector for hashing. */
70 u32 * config_string_vector;
72 /* Config string including all next indices and feature data as a vector. */
73 u32 config_string_heap_index, config_string_heap_handle;
75 /* Index in main pool. */
78 /* Number of interfaces/traffic classes that reference this config. */
83 /* Pool of configs. Index 0 is always null config and is never deleted. */
84 vnet_config_t * config_pool;
86 /* Hash table mapping vector config string to config pool index. */
87 uword * config_string_hash;
89 /* Global heap of configuration data. */
90 u32 * config_string_heap;
92 /* Node index which starts/ends feature processing. */
93 u32 * start_node_indices, end_node_index;
95 /* Interior feature processing nodes (not including start and end nodes). */
96 u32 * node_index_by_feature_index;
98 /* vnet_config pool index by user index */
99 u32 * config_pool_index_by_user_index;
101 /* Temporary vector for holding config strings. Used to avoid continually
102 allocating vectors. */
103 u32 * config_string_temp;
104 } vnet_config_main_t;
107 vnet_config_free (vnet_config_main_t * cm, vnet_config_t * c)
109 vnet_config_feature_t * f;
110 vec_foreach (f, c->features)
111 vnet_config_feature_free (f);
112 vec_free (c->features);
113 heap_dealloc (cm->config_string_heap, c->config_string_heap_handle);
114 vec_free (c->config_string_vector);
118 vnet_get_config_data (vnet_config_main_t * cm,
127 d = heap_elt_at_index (cm->config_string_heap, i);
129 n = round_pow2 (n_data_bytes, sizeof (d[0])) / sizeof (d[0]);
131 /* Last 32 bits are next index. */
134 /* Advance config index to next config. */
135 *config_index = (i + n + 1);
137 /* Return config data to user for this feature. */
141 void vnet_config_init (vlib_main_t * vm,
142 vnet_config_main_t * cm,
143 char * start_node_names[],
144 int n_start_node_names,
145 char * feature_node_names[],
146 int n_feature_node_names);
148 /* Calls to add/delete features from configurations. */
149 u32 vnet_config_add_feature (vlib_main_t * vm,
150 vnet_config_main_t * cm,
153 void * feature_config,
154 u32 n_feature_config_bytes);
156 u32 vnet_config_del_feature (vlib_main_t * vm,
157 vnet_config_main_t * cm,
160 void * feature_config,
161 u32 n_feature_config_bytes);
163 #endif /* included_vnet_config_h */