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; }
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; }
switchlink_db_status_t switchlink_db_mac_get_intf(switchlink_mac_addr_t mac_addr, switchlink_handle_t bridge_h, switchlink_handle_t *intf_h) { switchlink_db_mac_obj_t * obj; uint32_t hash; uint8_t key[SWITCHLINK_MAC_KEY_LEN]; switchlink_db_mac_key_hash(mac_addr, bridge_h, key, &hash); obj = tommy_hashlin_search(&switchlink_db_mac_obj_hash, switchlink_db_mac_cmp, key, hash); if (!obj) { return SWITCHLINK_DB_STATUS_ITEM_NOT_FOUND; } *intf_h = obj->intf_h; return SWITCHLINK_DB_STATUS_SUCCESS; }
switchlink_db_status_t switchlink_db_mac_delete(switchlink_mac_addr_t mac_addr, switchlink_handle_t bridge_h) { switchlink_db_mac_obj_t *obj; uint32_t hash; uint8_t key[SWITCHLINK_MAC_KEY_LEN]; switchlink_db_mac_key_hash(mac_addr, bridge_h, key, &hash); obj = tommy_hashlin_search( &switchlink_db_mac_obj_hash, switchlink_db_mac_cmp, key, hash); if (!obj) { return SWITCHLINK_DB_STATUS_ITEM_NOT_FOUND; } tommy_hashlin_remove_existing(&switchlink_db_mac_obj_hash, &obj->hash_node); tommy_list_remove_existing(&switchlink_db_mac_obj_list, &obj->list_node); switchlink_free(obj); return SWITCHLINK_DB_STATUS_SUCCESS; }
void *cheap_tcam_search(cheap_tcam_t *tcam, uint8_t *key) { tommy_list *hashmaps = &tcam->hashmaps; tcam_hashmap_t *tcam_hashmap; int max_priority = -1; int priority; void *entry; void *result = NULL; uint32_t hash; uint8_t *masked_key = tcam->masked_key; tommy_node* elem = tommy_list_head(hashmaps); while(elem) { tcam_hashmap = (tcam_hashmap_t *) elem->data; int i; for (i = 0; i < tcam->key_size; i++) { masked_key[i] = key[i] & tcam_hashmap->mask[i]; } hash = hashlittle(masked_key, tcam->key_size, 0); /* TODO !!!: only returns the first one, what about priority !? */ entry = tommy_hashlin_search(&tcam_hashmap->hashmap, tcam->cmp, masked_key, hash); if(entry) { priority = tcam->get_priority(entry); if(priority > max_priority){ max_priority = priority; result = entry; } } elem = elem->next; } return result; }
void *find_hash_table(void *ht, void *key, int key_len, void *compare) { return tommy_hashlin_search(ht, compare, key, tommy_hash_u32(0, key, key_len)); }