static bool compare_match_entry( const void *x, const void *y ) { const struct ofp_match *xofp_match = x; const struct ofp_match *yofp_match = y; return compare_match( xofp_match, yofp_match ); }
match_entry * lookup_match_entry( struct ofp_match *ofp_match ) { match_entry *entry; list_element *list; pthread_mutex_lock( match_table_head.mutex ); entry = lookup_hash_entry( match_table_head.exact_table, ofp_match ); if ( entry != NULL ) { pthread_mutex_unlock( match_table_head.mutex ); return entry; } for ( list = match_table_head.wildcard_table; list != NULL; list = list->next ) { entry = list->data; if ( compare_match( &entry->ofp_match, ofp_match ) ) { pthread_mutex_unlock( match_table_head.mutex ); return entry; } } pthread_mutex_unlock( match_table_head.mutex ); return NULL; }
void delete_match_entry( struct ofp_match *ofp_match ) { match_entry *delete_entry; list_element *list; pthread_mutex_lock( match_table_head.mutex ); assert( ofp_match != NULL ); if ( !ofp_match->wildcards ) { delete_entry = delete_hash_entry( match_table_head.exact_table, ofp_match ); if ( delete_entry == NULL ) { pthread_mutex_unlock( match_table_head.mutex ); return; } } else { for ( list = match_table_head.wildcard_table; list != NULL; list = list->next ) { delete_entry = list->data; if ( ( ( ( delete_entry->ofp_match.wildcards ^ ofp_match->wildcards ) & OFPFW_ALL ) == 0 ) && compare_match( &delete_entry->ofp_match, ofp_match ) ) { break; } } if ( list == NULL ) { pthread_mutex_unlock( match_table_head.mutex ); return; } delete_element( &match_table_head.wildcard_table, delete_entry ); } free_match_entry( delete_entry ); pthread_mutex_unlock( match_table_head.mutex ); }
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 match_entry * lookup_wildcards_match_entry( list_element *wildcards_table, struct ofp_match *match ) { assert( match != NULL ); list_element *element; for ( element = wildcards_table; element != NULL; element = element->next ) { match_entry *entry = element->data; if ( compare_match( &entry->match, match ) ) { return entry; } } return NULL; }
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; }
/* * Compare context of {Match} self with {Match} other. * * @example * def packet_in datapath_id, message * match = Match.new( :dl_type => 0x0800, :nw_src => "192.168.0.1" ) * if match.compare( ExactMatch.from( message ) ) * info "Received packet from 192.168.0.1" * end * end * * @return [Boolean] true if the {Match} match */ static VALUE match_compare( VALUE self, VALUE other ) { return compare_match( get_match( self ), get_match( other ) ) ? Qtrue : Qfalse; }