X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Flb%2Flb.c;h=ab5e808ddab7b8ecaeac5cff5a0cb2359174da03;hb=93a7f63943ab6ed2460321f38c90246b1585f0c8;hp=fe7e54505127b27e2af41972b4f3bfc996f945e4;hpb=628aad38f89413d6d6cb5def0ee08af956aa897a;p=vpp.git diff --git a/src/plugins/lb/lb.c b/src/plugins/lb/lb.c index fe7e5450512..ab5e808ddab 100644 --- a/src/plugins/lb/lb.c +++ b/src/plugins/lb/lb.c @@ -18,6 +18,7 @@ #include #include #include +#include //GC runs at most once every so many seconds #define LB_GARBAGE_RUN 60 @@ -25,10 +26,13 @@ //After so many seconds. It is assumed that inter-core race condition will not occur. #define LB_CONCURRENCY_TIMEOUT 10 +// FIB source for adding routes +static fib_source_t lb_fib_src; + lb_main_t lb_main; -#define lb_get_writer_lock() do {} while(clib_atomic_test_and_set (lb_main.writer_lock)) -#define lb_put_writer_lock() clib_atomic_release (lb_main.writer_lock) +#define lb_get_writer_lock() clib_spinlock_lock (&lb_main.writer_lock) +#define lb_put_writer_lock() clib_spinlock_unlock (&lb_main.writer_lock) static void lb_as_stack (lb_as_t *as); @@ -289,7 +293,7 @@ static void lb_vip_garbage_collection(lb_vip_t *vip) lb_snat6_key_t m_key6; clib_bihash_kv_24_8_t kv6, value6; lb_snat_mapping_t *m = 0; - ASSERT (lbm->writer_lock[0]); + CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock); u32 now = (u32) vlib_time_now(vlib_get_main()); if (!clib_u32_loop_gt(now, vip->last_garbage_collection + LB_GARBAGE_RUN)) @@ -384,7 +388,7 @@ static void lb_vip_update_new_flow_table(lb_vip_t *vip) lb_as_t *as; lb_pseudorand_t *pr, *sort_arr = 0; - ASSERT (lbm->writer_lock[0]); //We must have the lock + CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock); // We must have the lock //Check if some AS is configured or not i = 0; @@ -442,7 +446,7 @@ out: //Let's create a new flow table vec_validate(new_flow_table, vip->new_flow_table_mask); for (i=0; ilast; pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask; - if (new_flow_table[last].as_index == ~0) { + if (new_flow_table[last].as_index == 0) { new_flow_table[last].as_index = pr->as_index; break; } @@ -496,7 +500,8 @@ int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen, { lb_main_t *lbm = &lb_main; lb_vip_t *vip; - ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned + /* This must be called with the lock owned */ + CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock); ip46_prefix_normalize(prefix, plen); pool_foreach(vip, lbm->vips, { if ((vip->flags & LB_AS_FLAGS_USED) && @@ -560,7 +565,8 @@ int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index) { lb_main_t *lbm = &lb_main; - ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned + /* This must be called with the lock owned */ + CLIB_SPINLOCK_ASSERT_LOCKED (&lbm->writer_lock); lb_as_t *as; u32 *asi; pool_foreach(asi, vip->as_indexes, { @@ -773,7 +779,7 @@ lb_flush_vip_as (u32 vip_index, u32 as_index) vlib_refcount_add(&lbm->as_refcount, thread_index, b->value[i], -1); vlib_refcount_add(&lbm->as_refcount, thread_index, 0, 1); b->vip[i] = ~0; - b->value[i] = ~0; + b->value[i] = 0; } } if (vip_index == ~0) @@ -857,7 +863,7 @@ static int lb_vip_prefix_index_alloc (lb_main_t *lbm) { /* - * Check for dynamically allocaetd instance number. + * Check for dynamically allocated instance number. */ u32 bit; @@ -900,6 +906,8 @@ static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip, if (!lb_vip_port_find_diff_port(&(vip->prefix), vip->plen, vip->protocol, vip->port, &vip_idx)) { + lb_vip_t *exists_vip = lb_vip_get_by_index(vip_idx); + *vip_prefix_index = exists_vip ? exists_vip->vip_prefix_index : ~0; return; } @@ -945,7 +953,7 @@ static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip, dpo_set(&dpo, dpo_type, proto, *vip_prefix_index); fib_table_entry_special_dpo_add(0, &pfx, - FIB_SOURCE_PLUGIN_HI, + lb_fib_src, FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); dpo_reset(&dpo); @@ -1034,7 +1042,7 @@ static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip) pfx.fp_len = vip->plen; pfx.fp_proto = FIB_PROTOCOL_IP6; } - fib_table_entry_special_remove(0, &pfx, FIB_SOURCE_PLUGIN_HI); + fib_table_entry_special_remove(0, &pfx, lb_fib_src); } int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index) @@ -1244,7 +1252,7 @@ int lb_vip_del(u32 vip_index) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, - .description = "Load Balancer", + .description = "Load Balancer (LB)", }; /* *INDENT-ON* */ @@ -1375,6 +1383,7 @@ lb_init (vlib_main_t * vm) //Allocate and init default VIP. lbm->vips = 0; pool_get(lbm->vips, default_vip); + default_vip->new_flow_table_mask = 0; default_vip->prefix.ip6.as_u64[0] = 0xffffffffffffffffL; default_vip->prefix.ip6.as_u64[1] = 0xffffffffffffffffL; default_vip->protocol = ~0; @@ -1383,8 +1392,7 @@ lb_init (vlib_main_t * vm) lbm->per_cpu = 0; vec_validate(lbm->per_cpu, tm->n_vlib_mains - 1); - lbm->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES); - lbm->writer_lock[0] = 0; + clib_spinlock_init (&lbm->writer_lock); lbm->per_cpu_sticky_buckets = LB_DEFAULT_PER_CPU_STICKY_BUCKETS; lbm->flow_timeout = LB_DEFAULT_FLOW_TIMEOUT; lbm->ip4_src_address.as_u32 = 0xffffffff; @@ -1418,6 +1426,12 @@ lb_init (vlib_main_t * vm) default_as->address.ip6.as_u64[0] = 0xffffffffffffffffL; default_as->address.ip6.as_u64[1] = 0xffffffffffffffffL; + /* Generate a valid flow table for default VIP */ + default_vip->as_indexes = NULL; + lb_get_writer_lock(); + lb_vip_update_new_flow_table(default_vip); + lb_put_writer_lock(); + lbm->vip_index_by_nodeport = hash_create_mem (0, sizeof(u16), sizeof (uword)); @@ -1436,6 +1450,11 @@ lb_init (vlib_main_t * vm) #define _(a,b,c) lbm->vip_counters[c].name = b; lb_foreach_vip_counter #undef _ + + lb_fib_src = fib_source_allocate("lb", + FIB_SOURCE_PRIORITY_HI, + FIB_SOURCE_BH_SIMPLE); + return NULL; }