switch_status_t switch_neighbor_init(switch_device_t device) { UNUSED(device); switch_neighbor_array = NULL; tommy_hashtable_init(&switch_dmac_rewrite_table, SWITCH_DMAC_REWRITE_HASH_TABLE_SIZE); tommy_hashtable_init(&switch_neighbor_dmac_table, SWITCH_NEIGHBOR_DMAC_HASH_KEY_SIZE); dmac_rewrite_index_allocator = switch_api_id_allocator_new(SWITCH_DMAC_REWRITE_HASH_TABLE_SIZE, FALSE); return switch_handle_type_init(SWITCH_HANDLE_TYPE_ARP, (64 * 1024)); }
switch_status_t switch_l3_init(switch_device_t device) { UNUSED(device); // IP + VRF Hash table init (V4 only for now!) tommy_hashtable_init(&switch_l3_hash_table, SWITCH_L3_HASH_TABLE_SIZE); switch_handle_type_init(SWITCH_HANDLE_TYPE_URPF, (4096)); return SWITCH_STATUS_SUCCESS; }
switch_status_t switch_nhop_init(switch_device_t device) { switch_nhop_array = NULL; ecmp_select = switch_api_id_allocator_new(64 * 1024/ 32, FALSE); switch_handle_type_init(SWITCH_HANDLE_TYPE_NHOP, (16*1024)); tommy_hashtable_init(&switch_nhop_hash_table, SWITCH_NHOP_HASH_TABLE_SIZE); switch_nhop_create(); return SWITCH_STATUS_SUCCESS; }
tcam_cache_t *tcam_cache_create(int size, int key_size, int expiration_secs) { tcam_cache_t *cache = malloc(sizeof(tcam_cache_t)); cache->bitmap_size = ((size + 63) / 64); cache->size = cache->bitmap_size * size; cache->key_size = key_size; cache->expiration_secs = expiration_secs; cache->nb_entries = 0; cache->entries = calloc(cache->size, sizeof(cache_entry_t)); tommy_hashtable_init(&cache->hashtable, 2 * cache->size); cache->bitmap_used = calloc(cache->bitmap_size, sizeof(unsigned long)); pthread_mutex_init(&cache->lock, NULL); return cache; };
phash_pool pcore_hash_init(const puint8 type) { plog_dbg("%s(): Инициализация пула типа %d", __PRETTY_FUNCTION__, type); phash_pool pool = pmalloc_check(__PRETTY_FUNCTION__, sizeof(struct s_phash_pool)); if (!pool) { return NULL; } pool->type = type; tommy_list *list = pmalloc_check(__PRETTY_FUNCTION__, sizeof(tommy_list)); if (!list) { free(pool); return NULL; } void *hash_struct; switch (type) { case PHASH_FAST_SEARCH: hash_struct = pmalloc_check(__PRETTY_FUNCTION__, sizeof(tommy_hashdyn)); if (!hash_struct) { free(pool); free(list); return NULL; } tommy_hashdyn_init(hash_struct); break; case PHASH_FAST_INSERT: default: hash_struct = pmalloc_check(__PRETTY_FUNCTION__, sizeof(tommy_hashtable)); if (!hash_struct) { free(pool); free(list); return NULL; } tommy_hashtable_init(hash_struct, 1024); break; } tommy_list_init(list); pool->list = list; pool->hash_struct = hash_struct; plog_dbg("%s(): Пул 0x%08X успешно создан", __PRETTY_FUNCTION__, pool); return pool; }
/* * Internal Router MAC API's * These API's will be used intenrally in SDK to manage * the rmac groups */ switch_status_t switch_router_mac_init(switch_device_t device) { p4_pd_entry_hdl_t smac_hdl = 0; switch_mac_addr_t temp_mac; unsigned char mac[ETH_LEN] = {0x00, 0x77, 0x66, 0x55, 0x44, 0x33}; switch_rmac_array = NULL; //switch_pd_mac_rewrite_table_add_entry(device, smac_idx, mac); tommy_hashtable_init(&smac_rewrite_table, SWITCH_SMAC_REWRITE_HASH_TABLE_SIZE); smac_rewrite_index_allocator = switch_api_id_allocator_new(SWITCH_SMAC_REWRITE_HASH_TABLE_SIZE, TRUE); switch_handle_type_init(SWITCH_HANDLE_TYPE_MY_MAC, (512)); memcpy(&temp_mac.mac_addr, &mac, ETH_LEN); switch_pd_tunnel_smac_rewrite_table_add_entry(0, 1, &temp_mac, &smac_hdl); return SWITCH_STATUS_SUCCESS; }
void test_hashtable(void) { tommy_list list; tommy_hashtable hashtable; struct object_hash* HASH; unsigned i, n; tommy_node* p; unsigned limit; unsigned count; HASH = malloc(MAX * sizeof(struct object_hash)); for(i=0;i<MAX;++i) { HASH[i].value = i; } START("hashtable stack"); limit = 10 * sqrt(MAX); for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashtable_init(&hashtable, limit / 2); /* insert */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashtable_foreach_arg(&hashtable, count_arg, &count); if (count != n) abort(); /* remove */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } tommy_hashtable_done(&hashtable); } STOP(); START("hashtable queue"); limit = sqrt(MAX) / 8; for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashtable_init(&hashtable, limit / 2); /* insert first run */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashtable_foreach_arg(&hashtable, count_arg, &count); if (count != n) abort(); /* insert all the others */ for(;i<MAX;++i) { struct object_hash* obj; /* insert one */ tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); /* remove one */ p = tommy_list_head(&list); obj = p->data; tommy_list_remove_existing(&list, p); tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } /* remove remaining */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } tommy_hashtable_done(&hashtable); } STOP(); }