40 #ifndef NO_BULK_LOGGING 42 #define PORT_TO_CACHE(y, z) ((y)/(z)) 44 #define CACHE_TO_PORT(x, z) (((x)& 0x7FFF) * (z)) 45 #define IS_CACHE_ENTRY_FULL(x) ((x) & 0x8000) 46 #define MARK_CACHE_ENTRY_AS_FULL(x) ((x) = ((x) | 0x8000)) 47 #define UNMARK_CACHE_ENTRY_AS_FULL(x) ((x) = ((x) & 0x7FFF)) 48 #define CACHE_ENTRY_WITHOUT_FULL_STAT(x) ((x) & 0x7FFF) 51 #define NUM_BULK_CHECK 128 57 #define HAVE_BULK_PORT_STATS 1 59 #ifdef HAVE_BULK_PORT_STATS 75 i16 printed_so_far = 0;
81 u_ki.
k.
k.
vrf = in_vrfid;
93 if(vrfmap->
i_vrf == in_vrfid) {
117 memset(prev_bulks, 0,
sizeof(prev_bulks));
131 for(i=0; i < printed_so_far; i++) {
132 if(prev_bulks[i] == bm_index)
goto next_entry;
145 prev_bulks[printed_so_far] = bm_index;
174 #ifdef HAVE_BULK_PORT_STATS 181 "Number of times pre-allocated bulk port found from cache %lld\n",
184 "Number of times mapped port (static) allocations made %lld\n",
193 #ifdef HAVE_BULK_PORT_STATS 207 #ifdef DEBUG_BULK_PORT 221 #ifdef DEBUG_BULK_PORT 254 u16 static_port_range,
261 int unmark_full_status = 0;
270 #ifdef DEBUG_BULK_PORT 280 base_port = base_port/bulk_size;
281 base_port = base_port * bulk_size;
283 my_pm->
bm, base_port, bulk_size))) {
285 unmark_full_status = 1;
288 *nfv9_log_req = base_port;
296 if(unmark_full_status) {
301 #ifdef DEBUG_BULK_PORT 303 "Clearing cache for client 0x%x, bulk port %d\n",
318 i16 num_pos = 0, num_bits, iterations;
321 i16 num_uwords = bulk_size/
BITS(my_pm->
bm[0]);
325 num_bits = bulk_size;
330 num_bits =
BITS(my_pm->
bm[0]);
335 (bulk_start + iterations *
BITS(my_pm->
bm[0])), num_bits);
336 #ifdef DEBUG_BULK_PORT_DETAIL 338 __func__, __LINE__, bulk_start, num_bits, bulk_ports);
353 for(; num_pos < num_bits; num_pos = num_pos + inc) {
354 if(!((bulk_ports >> num_pos) & 1))
359 (pair_type ==
PORT_PAIR) && ((num_pos & 0x1) ||
360 (!((bulk_ports >> (num_pos + 1)) & 1)))))
364 if(num_pos < num_bits)
365 return (num_pos + iterations *
BITS(my_pm->
bm[0]));
367 num_bits =
BITS(my_pm->
bm[0]);
368 bulk_size -=
BITS(my_pm->
bm[0]);
370 if(iterations >= num_uwords) iterations = 0;
371 }
while (bulk_size > 0);
382 u16 static_port_range
400 i16 attempts_so_far = 0;
403 memset(prev_bulks, 0,
sizeof(prev_bulks));
417 for(i=0; i < attempts_so_far; i++) {
418 if(prev_bulks[i] == bm_index) {
433 bulk_start, bulk_size, pair_type);
438 prev_bulks[attempts_so_far] = bm_index;
445 *port_available = bulk_start + port_pos;
484 u16 static_port_range,
494 u16 port_available = 0;
520 bulk_start, bulk_size, pair_type);
525 #ifdef DEBUG_BULK_PORT 532 port_available = bulk_start+ port_pos;
533 #ifdef DEBUG_BULK_PORT 535 "Found port from cache : IP 0x%x, port %d %d iterations\n",
538 #ifdef HAVE_BULK_PORT_STATS 547 bulk_size, &port_available,
549 goto ALLCOATE_NEW_BULK;
551 #ifdef DEBUG_BULK_PORT 564 *o_port = port_available;
566 #ifdef HAVE_BULK_PORT_STATS 572 #ifdef DEBUG_BULK_PORT 575 "No port available from bulk cache, bulk size %d\n", bulk_size);
580 o_ipv4_address, o_port, static_port_range, bulk_size, nfv9_log_req,
581 ip_n_to_1, rseed_ip);
590 #ifdef HAVE_BULK_PORT_STATS 607 u16 static_port_range,
637 uword bit_test_result, start_bit;
642 i_port >= static_port_range ) {
649 goto ALLOCATE_NEW_BULK_STATIC;
653 start_bit= ((i_port/bulk_size) * bulk_size);
655 start_bit, bulk_size);
657 goto ALLOCATE_NEW_BULK_STATIC;
665 if(i == BULK_RANGE_CACHE_SIZE) {
668 goto ALLOCATE_NEW_BULK_STATIC;
684 goto ALLOCATE_NEW_BULK_STATIC;
693 #ifdef HAVE_BULK_PORT_STATS 697 #ifdef DEBUG_BULK_PORT 700 __LINE__, *o_ipv4_address, *o_port);
705 ALLOCATE_NEW_BULK_STATIC:
706 #ifdef DEBUG_BULK_PORT 712 i_port, index, o_ipv4_address, o_port, static_port_range,
713 bulk_size, nfv9_log_req,ip_n_to_1);
721 #ifdef HAVE_BULK_PORT_STATS 749 atype, index, ipv4_address, port, nfv9_log_req, bulk_size, ip_n_to_1);
756 port = port*bulk_size;
757 port = port/bulk_size;
763 if( i == BULK_RANGE_CACHE_SIZE) {
767 #ifdef HAVE_BULK_PORT_STATS 783 u16 static_port_range,
803 u32 start_port1, end_port1, start_port2, end_port2;
807 u16 port_available = 0;
826 if (i_port <= 9999) {
827 start_port1 = static_port_range;
836 start_port2 = static_port_range;
840 start_port1 = static_port_range;
860 u32 start_range = start_port1;
861 u32 end_range = end_port1;
862 for(range_loop = 0; range_loop < 2; range_loop++) {
864 goto ALLOCATE_NEW_RTSP_PORTS;
875 if(bulk_start < start_port1 || bulk_start >= end_port1) {
880 bulk_start, bulk_size, pair_type);
888 port_available = bulk_start+ port_pos;
889 #ifdef DEBUG_BULK_PORT 891 "Found port from cache : IP 0x%x, port %d %d iterations\n",
894 #ifdef HAVE_BULK_PORT_STATS 907 goto ALLOCATE_NEW_RTSP_PORTS;
909 #ifdef DEBUG_BULK_PORT 921 *o_port = port_available;
923 #ifdef HAVE_BULK_PORT_STATS 928 ALLOCATE_NEW_RTSP_PORTS:
931 (pm, atype, pair_type,
932 start_range, end_range,index, o_ipv4_address,
933 o_port, bulk_size, nfv9_log_req,rseed_ip))) {
938 #ifdef HAVE_BULK_PORT_STATS 945 start_range = start_port2;
946 end_range = end_port2;
cnat_main_db_entry_t * cnat_main_db
sll srl srl sll sra u16x4 i
static u32 randq1(u32 prev)
Fixed length block allocator.
static i16 get_suiting_port_pos_from_range(cnat_portmap_v2_t *my_pm, u16 bulk_start, i16 bulk_size, port_pair_t pair_type)
static uword cgn_clib_bitmap_get_bits(uword *ai, u16 start, unsigned char num_bits)
u16 cnat_static_port_range
cnat_errno_t cnat_dynamic_port_alloc_rtsp_bulk(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, cnat_user_db_entry_t *udb, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u32 *rseed_ip)
static uword clib_bitmap_get_no_check(uword *ai, uword i)
Gets the ith bit value from a bitmap Does not sanity-check the bit position.
cnat_errno_t cnat_static_port_alloc_v2_bulk(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 i_ipv4_address, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, cnat_user_db_entry_t *udb, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1)
void show_bulk_port_stats()
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
cnat_errno_t cnat_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 i_ipv4_address, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1)
void cnat_port_free_v2(cnat_portmap_v2_t *pm, int index, port_pair_t pair_type, u16 base_port, u16 static_port_range)
#define BULK_RANGE_CACHE_SIZE
#define BULK_RANGE_INVALID
#define CACHE_TO_PORT(x, z)
cnat_errno_t cnat_mapped_static_port_alloc_v2_bulk(cnat_portmap_v2_t *pm, port_alloc_t atype, u32 *index, u32 ipv4_address, u16 port, cnat_user_db_entry_t *udb, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1)
#define MIN_STATIC_PORT_RANGE_FOR_RTSP
#define MARK_CACHE_ENTRY_AS_FULL(x)
#define CACHE_ENTRY_WITHOUT_FULL_STAT(x)
void cnat_port_free_v2_bulk(cnat_portmap_v2_t *pm, int index, port_pair_t ptype, u16 base_port, cnat_user_db_entry_t *udb, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req)
void cnat_update_bulk_range_cache(cnat_user_db_entry_t *udb, u16 o_port, bulk_alloc_size_t bulk_size)
#define CACHE_ALLOC_NO_LOG_REQUIRED
cnat_errno_t cnat_dynamic_port_alloc_v2_bulk(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, cnat_user_db_entry_t *udb, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1, u32 *rseed_ip)
#define IS_CACHE_ENTRY_FULL(x)
u32 translation_list_head_index
#define PORT_TO_CACHE(y, z)
cnat_errno_t cnat_dynamic_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1, u32 *rseed_ip)
#define UNMARK_CACHE_ENTRY_AS_FULL(x)
static uword cgn_clib_bitmap_clear_no_check(uword *a, uword i)
void show_bulk_port_allocation(u16 in_vrfid, u32 inside_ip)
#define BULKSIZE_FROM_VRFMAP(vrfmap)
#define BULK_ALLOC_NOT_ATTEMPTED
static uword bulk_cache_hit_count
static u32 bulk_port_rand_across
static uword bulk_port_alloc_count
Bitmaps built as vectors of machine words.
i16 bulk_port_range_cache[BULK_RANGE_CACHE_SIZE]
static uword bulk_port_use_count
cnat_vrfmap_t * cnat_map_by_vrf
uword bm[(BITS_PER_INST+BITS(uword)-1)/BITS(uword)]
cnat_user_db_entry_t * cnat_user_db_lookup_entry(cnat_db_key_bucket_t *uki)
static uword mapped_port_alloc_count
static cnat_errno_t try_bulk_port_from_non_cache(cnat_user_db_entry_t *udb, cnat_portmap_v2_t *my_pm, port_pair_t pair_type, bulk_alloc_size_t bulk_size, u16 *port_available, u16 static_port_range)
cnat_errno_t cnat_mapped_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, u32 *index, u32 ipv4_address, u16 port, int *nfv9_log_req, bulk_alloc_size_t bulk_size, u16 ip_n_to_1)
static uword cgn_clib_bitmap_check_if_all(uword *ai, u16 start, i16 num_bits)
cnat_errno_t cnat_dynamic_port_alloc_rtsp(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u16 start_range, u16 end_range, u32 *index, u32 *o_ipv4_address, u16 *o_port, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u32 *rseed_ip)
void clear_bulk_port_stats()
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".