static bool insert_wildcards_match_entry( list_element **wildcards_table, struct ofp_match *match, uint16_t priority, void *data ) { assert( match != NULL ); list_element *element; for ( element = *wildcards_table; element != NULL; element = element->next ) { match_entry *entry = element->data; if ( entry->priority < priority ) { break; } assert( entry != NULL ); if ( entry->priority == priority && compare_match_strict( &entry->match, match ) ) { char match_string[ MATCH_STRING_LENGTH ]; match_to_string( match, match_string, sizeof( match_string ) ); warn( "wildcards match entry already exists ( match = [%s], priority = %u )", match_string, priority ); return false; } } match_entry *new_entry = allocate_match_entry( match, priority, data ); if ( element == NULL ) { // tail append_to_tail( wildcards_table, new_entry ); } else if ( element == *wildcards_table ) { // head insert_in_front( wildcards_table, new_entry ); } else { // insert before insert_before( wildcards_table, element->data, new_entry ); } return true; }
static bool compare_exact_match_entry( const void *x, const void *y ) { assert( x != NULL ); assert( y != NULL ); const struct ofp_match *xofp_match = x; const struct ofp_match *yofp_match = y; return compare_match_strict( xofp_match, yofp_match ); }
static list_element * lookup_flow_entries_with_table_id( const uint8_t table_id, const match *match, const uint16_t priority, const bool strict, const bool update_counters ) { assert( valid_table_id( table_id ) ); if ( get_logging_level() >= LOG_DEBUG ) { debug( "Looking up flow entries ( table_id = %#x, match = %p, priority = %u, strict = %s, update_counters = %s ).", table_id, match, priority, strict ? "true" : "false", update_counters ? "true" : "false" ); if ( match != NULL ) { dump_match( match, debug ); } } flow_table *table = get_flow_table( table_id ); if ( table == NULL ) { return NULL; } if ( update_counters ) { increment_lookup_count( table_id ); } list_element *head = NULL; create_list( &head ); for ( list_element *e = table->entries; e != NULL; e = e->next ) { flow_entry *entry = e->data; assert( entry != NULL ); if ( strict ) { if ( entry->priority < priority ) { break; } if ( priority == entry->priority && compare_match_strict( match, entry->match ) ) { if ( update_counters ) { increment_matched_count( table_id ); } append_to_tail( &head, entry ); break; } } else { if ( compare_match( match, entry->match ) ) { if ( update_counters ) { increment_matched_count( table_id ); } append_to_tail( &head, entry ); } } } return head; }
static OFDPE insert_flow_entry( flow_table *table, flow_entry *entry, const uint16_t flags ) { assert( table != NULL ); assert( entry != NULL ); list_element *element = table->entries; while( element != NULL ) { list_element *next = element->next; flow_entry *e = element->data; assert( e != NULL ); if ( e->priority < entry->priority ) { break; } if ( e->priority == entry->priority ) { if ( e->table_miss && !entry->table_miss ) { break; } if ( ( flags & OFPFF_CHECK_OVERLAP ) != 0 && compare_match( e->match, entry->match ) ) { return ERROR_OFDPE_FLOW_MOD_FAILED_OVERLAP; } if ( compare_match_strict( e->match, entry->match ) ) { if ( ( flags & OFPFF_RESET_COUNTS ) != 0 ) { entry->byte_count = e->byte_count; entry->packet_count = e->packet_count; } flow_table *table = get_flow_table( e->table_id ); assert( table != NULL ); delete_flow_entry_from_table( table, e, 0, false ); } } element = next; } if ( element == NULL ) { // tail append_to_tail( &table->entries, entry ); } else if ( element == table->entries ) { // head insert_in_front( &table->entries, entry ); } else { // insert before insert_before( &table->entries, element->data, entry ); } increment_active_count( table->features.table_id ); return OFDPE_SUCCESS; }
static match_entry * lookup_wildcards_match_strict_entry( list_element *wildcards_table, struct ofp_match *match, uint16_t priority ) { assert( match != NULL ); list_element *element; for ( element = wildcards_table; element != NULL; element = element->next ) { match_entry *entry = element->data; if ( entry->priority < priority ) { break; } if ( entry->priority == priority && compare_match_strict( &entry->match, match ) ) { return entry; } } return NULL; }