int ${pd_prefix}mirroring_mapping_add(p4_pd_mirror_id_t mirror_id, uint16_t egress_port ) { RMT_LOG(P4_LOG_LEVEL_VERBOSE, "adding mirroring mapping mirror_id -> egress_port: %d -> %d\n", mirror_id, egress_port); mirroring_mapping_t *mapping; mapping = tommy_hashlin_search(&mirroring_mappings, compare_mirroring_mappings, &mirror_id, tommy_inthash_u32(mirror_id)); if(mapping) { mapping->egress_port = egress_port; } else { mapping = malloc(sizeof(mirroring_mapping_t)); mapping->mirror_id = mirror_id; mapping->egress_port = egress_port; mapping->coalescing_session = NULL; tommy_hashlin_insert(&mirroring_mappings, &mapping->node, mapping, tommy_inthash_u32(mapping->mirror_id)); } return 0; }
int ${pd_prefix}mirroring_mapping_delete(p4_pd_mirror_id_t mirror_id) { mirroring_mapping_t *mapping = tommy_hashlin_remove(&mirroring_mappings, compare_mirroring_mappings, &mirror_id, tommy_inthash_u32(mirror_id)); free(mapping); return (mapping == NULL); /* 0 is success */ }
static inline mirroring_mapping_t* get_mirroring_mapping(const p4_pd_mirror_id_t mirror_id) { mirroring_mapping_t *mapping; mapping = tommy_hashlin_search(&mirroring_mappings, compare_mirroring_mappings, &mirror_id, tommy_inthash_u32(mirror_id)); return mapping; }
int ${pd_prefix}mirroring_mapping_add(int mirror_id, int egress_port){ RMT_LOG(P4_LOG_LEVEL_VERBOSE, "adding mirroring mapping mirror_id -> egress_port: %d -> %d\n", mirror_id, egress_port); mirroring_mapping_t *mapping = malloc(sizeof(mirroring_mapping_t)); mapping->mirror_id = mirror_id; mapping->egress_port = egress_port; tommy_hashlin_insert(&mirroring_mappings, &mapping->node, mapping, tommy_inthash_u32(mapping->mirror_id)); return 0; }
void* pcore_hash_search(phash_pool pool, const puint32 value) { if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return NULL; } plog_dbg("%s(): Поиск в пуле 0x%08X значения '%d'", __PRETTY_FUNCTION__, pool, value); phash_object ret = NULL; switch (pool->type) { case PHASH_FAST_SEARCH: ret = tommy_hashdyn_search((tommy_hashdyn *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; case PHASH_FAST_INSERT: default: ret = tommy_hashtable_search((tommy_hashtable *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; } return ret->data; }
void pcore_hash_insert(phash_pool pool, const puint32 value, void* const data) { if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return; } plog_dbg("%s(): Вставка ресурсов со значением '%d'", __PRETTY_FUNCTION__, value); phash_object object = pcore_hash_newObject(value, data); tommy_list_insert_tail(pool->list, &object->list_node, object); switch (pool->type) { case PHASH_FAST_SEARCH: tommy_hashdyn_insert((tommy_hashdyn *)pool->hash_struct, &object->hash_node, object, tommy_inthash_u32(object->value)); break; case PHASH_FAST_INSERT: default: tommy_hashtable_insert((tommy_hashtable *)pool->hash_struct, &object->hash_node, object, tommy_inthash_u32(object->value)); break; } }