/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
{
session_table_t *slt;
pool_get_aligned (lookup_tables, slt, CLIB_CACHE_LINE_BYTES);
- memset (slt, 0, sizeof (*slt));
+ clib_memset (slt, 0, sizeof (*slt));
return slt;
}
session_table_t *
session_table_get (u32 table_index)
{
- if (vec_len (lookup_tables) <= table_index)
+ if (pool_is_free_index (lookup_tables, table_index))
return 0;
- return vec_elt_at_index (lookup_tables, table_index);
+ return pool_elt_at_index (lookup_tables, table_index);
}
#define foreach_hash_table_parameter \
_(v6,halfopen,buckets,20000) \
_(v6,halfopen,memory,(64<<20))
+void
+session_table_free (session_table_t *slt, u8 fib_proto)
+{
+ u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
+ int i;
+
+ for (i = 0; i < TRANSPORT_N_PROTOS; i++)
+ session_rules_table_free (&slt->session_rules[i]);
+
+ vec_free (slt->session_rules);
+
+ if (fib_proto == FIB_PROTOCOL_IP4 || all)
+ {
+ clib_bihash_free_16_8 (&slt->v4_session_hash);
+ clib_bihash_free_16_8 (&slt->v4_half_open_hash);
+ }
+ if (fib_proto == FIB_PROTOCOL_IP6 || all)
+ {
+ clib_bihash_free_48_8 (&slt->v6_session_hash);
+ clib_bihash_free_48_8 (&slt->v6_half_open_hash);
+ }
+
+ pool_put (lookup_tables, slt);
+}
+
/**
* Initialize session table hash tables
*
session_table_init (session_table_t * slt, u8 fib_proto)
{
u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
+ int i;
#define _(af,table,parm,value) \
u32 configured_##af##_##table##_table_##parm = value;
#undef _
#define _(af,table,parm,value) \
- if (session_manager_main.configured_##af##_##table##_table_##parm) \
+ if (session_main.configured_##af##_##table##_table_##parm) \
configured_##af##_##table##_table_##parm = \
- session_manager_main.configured_##af##_##table##_table_##parm;
+ session_main.configured_##af##_##table##_table_##parm;
foreach_hash_table_parameter;
#undef _
if (fib_proto == FIB_PROTOCOL_IP4 || all)
{
- clib_bihash_init_16_8 (&slt->v4_session_hash, "v4 session table",
- configured_v4_session_table_buckets,
- configured_v4_session_table_memory);
- clib_bihash_init_16_8 (&slt->v4_half_open_hash, "v4 half-open table",
- configured_v4_halfopen_table_buckets,
- configured_v4_halfopen_table_memory);
+ clib_bihash_init2_args_16_8_t _a, *a = &_a;
+
+ memset (a, 0, sizeof (*a));
+ a->h = &slt->v4_session_hash;
+ a->name = "v4 session table";
+ a->nbuckets = configured_v4_session_table_buckets;
+ a->memory_size = configured_v4_session_table_memory;
+ a->dont_add_to_all_bihash_list = 1;
+ a->instantiate_immediately = 1;
+ clib_bihash_init2_16_8 (a);
+
+ memset (a, 0, sizeof (*a));
+ a->h = &slt->v4_half_open_hash;
+ a->name = "v4 half-open table";
+ a->nbuckets = configured_v4_halfopen_table_buckets;
+ a->memory_size = configured_v4_halfopen_table_memory;
+ a->dont_add_to_all_bihash_list = 1;
+ a->instantiate_immediately = 1;
+ clib_bihash_init2_16_8 (a);
}
if (fib_proto == FIB_PROTOCOL_IP6 || all)
{
- clib_bihash_init_48_8 (&slt->v6_session_hash, "v6 session table",
- configured_v6_session_table_buckets,
- configured_v6_session_table_memory);
- clib_bihash_init_48_8 (&slt->v6_half_open_hash, "v6 half-open table",
- configured_v6_halfopen_table_buckets,
- configured_v6_halfopen_table_memory);
+ clib_bihash_init2_args_48_8_t _a, *a = &_a;
+
+ memset (a, 0, sizeof (*a));
+ a->h = &slt->v6_session_hash;
+ a->name = "v6 session table";
+ a->nbuckets = configured_v6_session_table_buckets;
+ a->memory_size = configured_v6_session_table_memory;
+ a->dont_add_to_all_bihash_list = 1;
+ a->instantiate_immediately = 1;
+ clib_bihash_init2_48_8 (a);
+
+ memset (a, 0, sizeof (*a));
+ a->h = &slt->v6_half_open_hash;
+ a->name = "v6 half-open table";
+ a->nbuckets = configured_v6_halfopen_table_buckets;
+ a->memory_size = configured_v6_halfopen_table_memory;
+ a->dont_add_to_all_bihash_list = 1;
+ a->instantiate_immediately = 1;
+ clib_bihash_init2_48_8 (a);
}
- session_rules_table_init (&slt->session_rules);
+
+ vec_validate (slt->session_rules, TRANSPORT_N_PROTOS - 1);
+ for (i = 0; i < TRANSPORT_N_PROTOS; i++)
+ session_rules_table_init (&slt->session_rules[i]);
}
typedef struct _ip4_session_table_walk_ctx_t
void *ctx;
} ip4_session_table_walk_ctx_t;
-void
+static int
ip4_session_table_walk_cb (clib_bihash_kv_16_8_t * kvp, void *arg)
{
ip4_session_table_walk_ctx_t *ctx = arg;
ctx->fn (kvp, ctx->ctx);
+ return (BIHASH_WALK_CONTINUE);
}
void
&ctx);
}
+u32
+session_table_memory_size (session_table_t *st)
+{
+ u64 total_size = 0;
+
+ if (clib_bihash_is_initialised_16_8 (&st->v4_session_hash))
+ {
+ clib_bihash_alloc_chunk_16_8_t *c = st->v4_session_hash.chunks;
+ while (c)
+ {
+ total_size += c->size;
+ c = c->next;
+ }
+ c = st->v4_half_open_hash.chunks;
+ while (c)
+ {
+ total_size += c->size;
+ c = c->next;
+ }
+ }
+
+ if (clib_bihash_is_initialised_48_8 (&st->v6_session_hash))
+ {
+ clib_bihash_alloc_chunk_48_8_t *c = st->v6_session_hash.chunks;
+ while (c)
+ {
+ total_size += c->size;
+ c = c->next;
+ }
+ c = st->v6_half_open_hash.chunks;
+ while (c)
+ {
+ total_size += c->size;
+ c = c->next;
+ }
+ }
+
+ return total_size;
+}
+
+u8 *
+format_session_table (u8 *s, va_list *args)
+{
+ session_table_t *st = va_arg (*args, session_table_t *);
+
+ if (clib_bihash_is_initialised_16_8 (&st->v4_session_hash))
+ {
+ s = format (s, "%U", format_bihash_16_8, &st->v4_session_hash, 0);
+ s = format (s, "%U", format_bihash_16_8, &st->v4_half_open_hash, 0);
+ }
+
+ if (clib_bihash_is_initialised_48_8 (&st->v6_session_hash))
+ {
+ s = format (s, "%U", format_bihash_48_8, &st->v6_session_hash, 0);
+ s = format (s, "%U", format_bihash_48_8, &st->v6_half_open_hash, 0);
+ }
+
+ return s;
+}
+
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON