#include <vnet/ip/reass/ip4_sv_reass.h>
#include <vppinfra/bihash_16_8.h>
#include <nat/nat44/ed_inlines.h>
+#include <vnet/ip/ip_table.h>
#include <vpp/app/version.h>
static u32 nat_calc_bihash_buckets (u32 n_elts);
-static u32 nat_calc_bihash_memory (u32 n_buckets, uword kv_size);
-
u8 *format_static_mapping_kvp (u8 * s, va_list * args);
u8 *format_ed_session_kvp (u8 * s, va_list * args);
sm->max_users_per_thread = c.users;
sm->user_buckets = nat_calc_bihash_buckets (c.users);
- if (!c.user_memory)
- {
- c.user_memory =
- nat_calc_bihash_memory (c.users, sizeof (clib_bihash_8_8_t));
- }
- sm->user_memory_size = c.user_memory;
-
if (!c.sessions)
{
// default value based on legacy setting of load factor 10 * default
sm->max_translations_per_thread = c.sessions;
sm->translation_buckets = nat_calc_bihash_buckets (c.sessions);
- if (!c.session_memory)
- {
- c.session_memory =
- nat_calc_bihash_memory
- (sm->translation_buckets, sizeof (clib_bihash_16_8_t));
- }
- sm->translation_memory_size = c.session_memory;
vec_add1 (sm->max_translations_per_fib, sm->max_translations_per_thread);
sm->max_translations_per_user
= c.user_sessions ? c.user_sessions : sm->max_translations_per_thread;
sm->icmp_match_in2out_cb = icmp_match_in2out_ed;
clib_bihash_init_16_8 (&sm->out2in_ed, "out2in-ed",
- sm->translation_buckets,
- sm->translation_memory_size);
+ sm->translation_buckets, 0);
clib_bihash_set_kvp_format_fn_16_8 (&sm->out2in_ed,
format_ed_session_kvp);
sm->enabled = 1;
-
- nat_log_err ("nat44 enable");
+ nat_log_info ("nat44 enable");
return 0;
}
static u32
nat_calc_bihash_buckets (u32 n_elts)
{
- return 1 << (max_log2 (n_elts >> 1) + 1);
-}
-
-static u32
-nat_calc_bihash_memory (u32 n_buckets, uword kv_size)
-{
- return n_buckets * (8 + kv_size * 4);
+ n_elts = n_elts / 2.5;
+ u64 lower_pow2 = 1;
+ while (lower_pow2 * 2 < n_elts)
+ {
+ lower_pow2 = 2 * lower_pow2;
+ }
+ u64 upper_pow2 = 2 * lower_pow2;
+ if ((upper_pow2 - n_elts) < (n_elts - lower_pow2))
+ {
+ if (upper_pow2 <= UINT32_MAX)
+ {
+ return upper_pow2;
+ }
+ }
+ return lower_pow2;
}
u32
sm->translation_buckets =
nat_calc_bihash_buckets (sm->max_translations_per_thread);
- if (!sm->translation_memory_size_set)
- {
- sm->translation_memory_size =
- nat_calc_bihash_memory (sm->translation_buckets,
- sizeof (clib_bihash_16_8_t));
- }
-
nat44_sessions_clear ();
return 0;
}
if (sm->endpoint_dependent)
{
clib_bihash_init_16_8 (&tsm->in2out_ed, "in2out-ed",
- sm->translation_buckets,
- sm->translation_memory_size);
+ sm->translation_buckets, 0);
clib_bihash_set_kvp_format_fn_16_8 (&tsm->in2out_ed,
format_ed_session_kvp);
}
else
{
- clib_bihash_init_8_8 (&tsm->in2out, "in2out",
- sm->translation_buckets,
- sm->translation_memory_size);
+ clib_bihash_init_8_8 (&tsm->in2out, "in2out", sm->translation_buckets,
+ 0);
clib_bihash_set_kvp_format_fn_8_8 (&tsm->in2out, format_session_kvp);
- clib_bihash_init_8_8 (&tsm->out2in, "out2in",
- sm->translation_buckets,
- sm->translation_memory_size);
+ clib_bihash_init_8_8 (&tsm->out2in, "out2in", sm->translation_buckets,
+ 0);
clib_bihash_set_kvp_format_fn_8_8 (&tsm->out2in, format_session_kvp);
}
// TODO: ED nat is not using these
// before removal large refactor required
pool_alloc (tsm->list_pool, sm->max_translations_per_thread);
- clib_bihash_init_8_8 (&tsm->user_hash, "users", sm->user_buckets,
- sm->user_memory_size);
+ clib_bihash_init_8_8 (&tsm->user_hash, "users", sm->user_buckets, 0);
clib_bihash_set_kvp_format_fn_8_8 (&tsm->user_hash, format_user_kvp);
}
{
clib_bihash_free_16_8 (&sm->out2in_ed);
clib_bihash_init_16_8 (&sm->out2in_ed, "out2in-ed",
- clib_max (1, sm->num_workers) *
- sm->translation_buckets,
- clib_max (1, sm->num_workers) *
- sm->translation_memory_size);
+ clib_max (1,
+ sm->num_workers) *
+ sm->translation_buckets, 0);
clib_bihash_set_kvp_format_fn_16_8 (&sm->out2in_ed,
format_ed_session_kvp);
}