FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
session_table.c
Go to the documentation of this file.
1 /*
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:
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 
17 #include <vnet/session/session.h>
18 
19 /**
20  * Pool of session tables
21  */
23 
25 _get_session_tables (void)
26 {
27  return lookup_tables;
28 }
29 
32 {
33  session_table_t *slt;
35  memset (slt, 0, sizeof (*slt));
36  return slt;
37 }
38 
39 u32
41 {
42  return (slt - lookup_tables);
43 }
44 
46 session_table_get (u32 table_index)
47 {
48  if (pool_is_free_index (lookup_tables, table_index))
49  return 0;
50  return pool_elt_at_index (lookup_tables, table_index);
51 }
52 
53 #define foreach_hash_table_parameter \
54  _(v4,session,buckets,20000) \
55  _(v4,session,memory,(64<<20)) \
56  _(v6,session,buckets,20000) \
57  _(v6,session,memory,(64<<20)) \
58  _(v4,halfopen,buckets,20000) \
59  _(v4,halfopen,memory,(64<<20)) \
60  _(v6,halfopen,buckets,20000) \
61  _(v6,halfopen,memory,(64<<20))
62 
63 /**
64  * Initialize session table hash tables
65  *
66  * If vpp configured with set of table parameters it uses them,
67  * otherwise it uses defaults above.
68  */
69 void
71 {
72  u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
73  int i;
74 
75 #define _(af,table,parm,value) \
76  u32 configured_##af##_##table##_table_##parm = value;
78 #undef _
79 
80 #define _(af,table,parm,value) \
81  if (session_manager_main.configured_##af##_##table##_table_##parm) \
82  configured_##af##_##table##_table_##parm = \
83  session_manager_main.configured_##af##_##table##_table_##parm;
85 #undef _
86 
87  if (fib_proto == FIB_PROTOCOL_IP4 || all)
88  {
89  clib_bihash_init_16_8 (&slt->v4_session_hash, "v4 session table",
90  configured_v4_session_table_buckets,
91  configured_v4_session_table_memory);
92  clib_bihash_init_16_8 (&slt->v4_half_open_hash, "v4 half-open table",
93  configured_v4_halfopen_table_buckets,
94  configured_v4_halfopen_table_memory);
95  }
96  if (fib_proto == FIB_PROTOCOL_IP6 || all)
97  {
98  clib_bihash_init_48_8 (&slt->v6_session_hash, "v6 session table",
99  configured_v6_session_table_buckets,
100  configured_v6_session_table_memory);
101  clib_bihash_init_48_8 (&slt->v6_half_open_hash, "v6 half-open table",
102  configured_v6_halfopen_table_buckets,
103  configured_v6_halfopen_table_memory);
104  }
105 
106  for (i = 0; i < TRANSPORT_N_PROTO; i++)
107  session_rules_table_init (&slt->session_rules[i]);
108 }
109 
110 typedef struct _ip4_session_table_walk_ctx_t
111 {
113  void *ctx;
115 
116 void
118 {
120  ctx->fn (kvp, ctx->ctx);
121 }
122 
123 void
124 ip4_session_table_walk (clib_bihash_16_8_t * hash,
125  ip4_session_table_walk_fn_t fn, void *arg)
126 {
128  .fn = fn,
129  .ctx = arg,
130  };
131  clib_bihash_foreach_key_value_pair_16_8 (hash, ip4_session_table_walk_cb,
132  &ctx);
133 }
134 
135 /* *INDENT-ON* */
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "gnu")
141  * End:
142  */
struct _ip4_session_table_walk_ctx_t ip4_session_table_walk_ctx_t
void session_rules_table_init(session_rules_table_t *srt)
session_table_t * session_table_alloc(void)
Definition: session_table.c:31
int(* ip4_session_table_walk_fn_t)(clib_bihash_kv_16_8_t *kvp, void *ctx)
Definition: session_table.h:62
int i
unsigned char u8
Definition: types.h:56
#define foreach_hash_table_parameter
Definition: session_table.c:53
static session_table_t * lookup_tables
Pool of session tables.
Definition: session_table.c:22
unsigned int u32
Definition: types.h:88
void session_table_init(session_table_t *slt, u8 fib_proto)
Initialize session table hash tables.
Definition: session_table.c:70
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:270
session_table_t * session_table_get(u32 table_index)
Definition: session_table.c:46
long ctx[MAX_CONNS]
Definition: main.c:126
void ip4_session_table_walk(clib_bihash_16_8_t *hash, ip4_session_table_walk_fn_t fn, void *arg)
void ip4_session_table_walk_cb(clib_bihash_kv_16_8_t *kvp, void *arg)
struct _session_lookup_table session_table_t
u32 session_table_index(session_table_t *slt)
Definition: session_table.c:40
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:62