2 * Copyright (c) 2017 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 #include <vnet/session/session_table.h>
17 #include <vnet/session/session.h>
20 * Pool of session tables
22 static session_table_t *lookup_tables;
25 session_table_alloc (void)
28 pool_get_aligned (lookup_tables, slt, CLIB_CACHE_LINE_BYTES);
29 memset (slt, 0, sizeof (*slt));
34 session_table_index (session_table_t * slt)
36 return (slt - lookup_tables);
40 session_table_get (u32 table_index)
42 if (vec_len (lookup_tables) <= table_index)
44 return vec_elt_at_index (lookup_tables, table_index);
47 #define foreach_hash_table_parameter \
48 _(v4,session,buckets,20000) \
49 _(v4,session,memory,(64<<20)) \
50 _(v6,session,buckets,20000) \
51 _(v6,session,memory,(64<<20)) \
52 _(v4,halfopen,buckets,20000) \
53 _(v4,halfopen,memory,(64<<20)) \
54 _(v6,halfopen,buckets,20000) \
55 _(v6,halfopen,memory,(64<<20))
58 * Initialize session table hash tables
60 * If vpp configured with set of table parameters it uses them,
61 * otherwise it uses defaults above.
64 session_table_init (session_table_t * slt)
66 #define _(af,table,parm,value) \
67 u32 configured_##af##_##table##_table_##parm = value;
68 foreach_hash_table_parameter;
71 #define _(af,table,parm,value) \
72 if (session_manager_main.configured_##af##_##table##_table_##parm) \
73 configured_##af##_##table##_table_##parm = \
74 session_manager_main.configured_##af##_##table##_table_##parm;
75 foreach_hash_table_parameter;
78 clib_bihash_init_16_8 (&slt->v4_session_hash, "v4 session table",
79 configured_v4_session_table_buckets,
80 configured_v4_session_table_memory);
81 clib_bihash_init_48_8 (&slt->v6_session_hash, "v6 session table",
82 configured_v6_session_table_buckets,
83 configured_v6_session_table_memory);
84 clib_bihash_init_16_8 (&slt->v4_half_open_hash, "v4 half-open table",
85 configured_v4_halfopen_table_buckets,
86 configured_v4_halfopen_table_memory);
87 clib_bihash_init_48_8 (&slt->v6_half_open_hash, "v6 half-open table",
88 configured_v6_halfopen_table_buckets,
89 configured_v6_halfopen_table_memory);
92 typedef struct _ip4_session_table_walk_ctx_t
94 ip4_session_table_walk_fn_t fn;
96 } ip4_session_table_walk_ctx_t;
99 ip4_session_table_walk_cb (clib_bihash_kv_16_8_t * kvp, void *arg)
101 ip4_session_table_walk_ctx_t *ctx = arg;
102 ctx->fn (kvp, ctx->ctx);
106 ip4_session_table_walk (clib_bihash_16_8_t * hash,
107 ip4_session_table_walk_fn_t fn, void *arg)
109 ip4_session_table_walk_ctx_t ctx = {
113 clib_bihash_foreach_key_value_pair_16_8 (hash, ip4_session_table_walk_cb,
119 * fd.io coding-style-patch-verification: ON
122 * eval: (c-set-style "gnu")