A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / adj / adj_alloc.h
1 /*
2  * Copyright (c) 2016 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 #ifndef __adj_alloc_h__
17 #define __adj_alloc_h__
18
19 /**
20  * @brief
21  * Adjacency allocator: heap-like in that the code
22  * will dole out contiguous chunks of n items. In the interests of 
23  * thread safety, we don't bother about coalescing free blocks of size r
24  * into free blocks of size s, where r < s.
25  * 
26  * We include explicit references to worker thread barrier synchronization
27  * where necessary.  
28  */ 
29
30 #include <vppinfra/vec.h>
31 #include <vlib/vlib.h>
32 #include <vnet/ip/lookup.h>
33
34 typedef struct {
35   u32 ** free_indices_by_size;
36 } aa_header_t;
37
38 #define aa_aligned_header_bytes \
39   vec_aligned_header_bytes (sizeof (aa_header_t), sizeof (void *))
40
41 /* Pool header from user pointer */
42 static inline aa_header_t * aa_header (void * v)
43 {
44   return vec_aligned_header (v, sizeof (aa_header_t), sizeof (void *));
45 }
46
47 extern ip_adjacency_t *aa_alloc(void);
48 extern void aa_free (ip_adjacency_t * adj);
49 extern void aa_bootstrap (u32 n);
50
51 format_function_t format_adj_allocation;
52
53 #endif /* __adj_alloc_h__ */