2 *------------------------------------------------------------------
3 * cnat_va_db.h - definition for virtual assembly database
5 * Copyright (c) 2013 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #ifndef __CNAT_VA_DB_H__
21 #define __CNAT_VA_DB_H__
23 #include <clib_lite.h>
27 /* virtual assemble hash database size ~ 16B x 64K = 1MB */
29 #define VA_TOTAL_ENTRIES (64*1024)
30 #define VA_ENTRY_PER_BUCKET (8) /* make sure size is power of 2 for circular FIFO */
31 #define VA_BUCKET_MASK (VA_ENTRY_PER_BUCKET -1)
32 #define VA_BUCKETS (VA_TOTAL_ENTRIES / VA_ENTRY_PER_BUCKET)
33 #define VA_KEY_SIZE 12
35 typedef struct _va_entry {
36 /* key: top 12 bytes */
39 u16 vrf; /* overloaded with protocol info with top two bits */
47 typedef struct _va_keys {
48 u64 key64; /* src & dst IP */
49 u32 key32; /* vrf, protocol and ip_id */
57 typedef struct _va_bucket_t {
59 u32 next_available_entry; /* ~0 for empty bucket */
60 u32 new_entry_counter; /* for debug purpose */
61 va_entry_t va_entry[VA_ENTRY_PER_BUCKET];
64 extern va_bucket_t va_bucket[]; /* hash table in cnat_va_db.c */
66 void va_bucket_init ();
68 inline void va_db_add_new_entry (u32 bucket_index, va_lookup_key * );
69 inline int va_db_delete_entry (u32 bucket_index, va_lookup_key * );
70 inline va_entry_t * va_db_lookup (u32 bucket_index, va_lookup_key * key);
74 #define FRAG_DEBUG_PRINTF1(a) \
75 if (frag_debug_flag) { \
76 PLATFORM_DEBUG_PRINT(a); \
79 #define FRAG_DEBUG_PRINTF2(a, b) \
80 if (frag_debug_flag) { \
81 PLATFORM_DEBUG_PRINT(a, b); \
84 #define FRAG_DEBUG_PRINTF3(a, b, c) \
85 if (frag_debug_flag) { \
86 PLATFORM_DEBUG_PRINT(a, b, c); \
89 #define FRAG_DEBUG_PRINTF4(a, b, c, d) \
90 if (frag_debug_flag) { \
91 PLATFORM_DEBUG_PRINT(a, b, c, d); \
94 #define FRAG_DEBUG_PRINTF5(a, b, c, d, e) \
95 if (frag_debug_flag) { \
96 PLATFORM_DEBUG_PRINT(a, b, c, d, e); \
99 #define FRAG_DEBUG_PRINTF6(a, b, c, d, e, f) \
100 if (frag_debug_flag) { \
101 PLATFORM_DEBUG_PRINT(a, b, c, d, e, f); \
105 #define FRAG_DEBUG_PRINTF1(a)
107 #define FRAG_DEBUG_PRINTF2(a, b)
109 #define FRAG_DEBUG_PRINTF3(a, b, c)
111 #define FRAG_DEBUG_PRINTF4(a, b, c, d)
113 #define FRAG_DEBUG_PRINTF5(a, b, c, d, e)
115 #define FRAG_DEBUG_PRINTF6(a, b, c, d, e, f)
119 #endif /* __CNAT_VA_DB_H__ */