9612fb133fd513c9eadac5be9489572272732faa
[vpp.git] / src / vnet / lisp-cp / gid_dictionary.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 VNET_LISP_GPE_GID_DICTIONARY_H_
17 #define VNET_LISP_GPE_GID_DICTIONARY_H_
18
19 #include <vnet/vnet.h>
20 #include <vnet/lisp-cp/lisp_types.h>
21 #include <vppinfra/bihash_24_8.h>
22 #include <vppinfra/bihash_template.h>
23
24 #define GID_LOOKUP_MISS ((u32)~0)
25 #define GID_LOOKUP_MISS_L2 ((u64)~0)
26
27 /* Default size of the ip4 hash table */
28 #define IP4_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
29 #define IP4_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20)
30
31 /* Default size of the ip6 hash table */
32 #define IP6_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
33 #define IP6_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20)
34
35 /* Default size of the MAC hash table */
36 #define MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
37 #define MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20)
38
39 /* Default size of the ARP hash table */
40 #define ARP_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
41 #define ARP_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20)
42
43 typedef void (*foreach_subprefix_match_cb_t) (u32, void *);
44
45 typedef struct
46 {
47   BVT (clib_bihash) ip4_lookup_table;
48
49   /* bitmap/vector of mask widths to search */
50   uword *ip4_non_empty_dst_address_length_bitmap;
51   u8 *ip4_prefix_lengths_in_search_order;
52   ip4_address_t ip4_fib_masks[33];
53   u32 ip4_prefix_len_refcount[33];
54
55   /* ip4 lookup table config parameters */
56   u32 ip4_lookup_table_nbuckets;
57   uword ip4_lookup_table_size;
58   u32 count;
59 } gid_ip4_table_t;
60
61 typedef struct
62 {
63   BVT (clib_bihash) ip6_lookup_table;
64
65   /* bitmap/vector of mask widths to search */
66   uword *ip6_non_empty_dst_address_length_bitmap;
67   u8 *ip6_prefix_lengths_in_search_order;
68   ip6_address_t ip6_fib_masks[129];
69   u64 ip6_prefix_len_refcount[129];
70
71   /* ip6 lookup table config parameters */
72   u32 ip6_lookup_table_nbuckets;
73   uword ip6_lookup_table_size;
74   u64 count;
75 } gid_ip6_table_t;
76
77 typedef struct gid_mac_table
78 {
79   BVT (clib_bihash) mac_lookup_table;
80
81   /* mac lookup table config parameters */
82   u32 mac_lookup_table_nbuckets;
83   uword mac_lookup_table_size;
84   u64 count;
85 } gid_mac_table_t;
86
87 typedef struct
88 {
89   BVT (clib_bihash) arp_lookup_table;
90   u32 arp_lookup_table_nbuckets;
91   uword arp_lookup_table_size;
92   u64 count;
93 } gid_l2_arp_table_t;
94
95 typedef struct
96 {
97   /** L2 ARP table */
98   gid_l2_arp_table_t arp_table;
99
100   /** destination IP LPM ip4 lookup table */
101   gid_ip4_table_t dst_ip4_table;
102
103   /** pool of source IP LPM ip4 lookup tables */
104   gid_ip4_table_t *src_ip4_table_pool;
105
106   /** destination IP LPM ip6 lookup table */
107   gid_ip6_table_t dst_ip6_table;
108
109   /** pool of source IP LPM ip6 lookup tables */
110   gid_ip6_table_t *src_ip6_table_pool;
111
112   /** flat source/dest mac lookup table */
113   gid_mac_table_t sd_mac_table;
114
115 } gid_dictionary_t;
116
117 u32
118 gid_dictionary_add_del (gid_dictionary_t * db, gid_address_t * key, u64 value,
119                         u8 is_add);
120
121 u64 gid_dictionary_lookup (gid_dictionary_t * db, gid_address_t * key);
122 u32 gid_dictionary_sd_lookup (gid_dictionary_t * db, gid_address_t * dst,
123                               gid_address_t * src);
124
125 void gid_dictionary_init (gid_dictionary_t * db);
126
127 void
128 gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid,
129                             foreach_subprefix_match_cb_t cb, void *arg);
130
131 void
132 gid_dict_foreach_l2_arp_entry (gid_dictionary_t * db, void (*cb)
133                                (BVT (clib_bihash_kv) * kvp, void *arg),
134                                void *ht);
135
136 #endif /* VNET_LISP_GPE_GID_DICTIONARY_H_ */
137
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */