static void test_map_entry_if_match_set_nw_prefix() { oxm_matches *nw_src_prefix_20 = create_oxm_matches(); set_nw_src_prefix_20_wildcards_entry( nw_src_prefix_20 ); assert_true( insert_match_entry( nw_src_prefix_20, DEFAULT_PRIORITY, xstrdup( NW_SRC_PREFIX_20_SERVICE_NAME ) ) ); oxm_matches *nw_dst_prefix_20 = create_oxm_matches(); set_nw_dst_prefix_20_wildcards_entry( nw_dst_prefix_20 ); assert_true( insert_match_entry( nw_dst_prefix_20, DEFAULT_PRIORITY, xstrdup( NW_DST_PREFIX_20_SERVICE_NAME ) ) ); oxm_matches *nw_prefix_24 = create_oxm_matches(); set_nw_prefix_24_wildcards_entry( nw_prefix_24 ); assert_true( insert_match_entry( nw_prefix_24, DEFAULT_PRIORITY, xstrdup( NW_PREFIX_24_SERVICE_NAME ) ) ); oxm_matches *nw_prefix_28 = create_oxm_matches(); set_nw_prefix_28_wildcards_entry( nw_prefix_28 ); assert_true( insert_match_entry( nw_prefix_28, DEFAULT_PRIORITY, xstrdup( NW_PREFIX_28_SERVICE_NAME ) ) ); oxm_matches *match = create_oxm_matches(); set_nw_prefix_24_wildcards_entry( match ); char *user_data = xstrdup( USER_DATA ); count = 0; map_match_table( match, test_map_entry_if_match_set_nw_prefix_helper, user_data ); assert_int_equal( count, 2 ); XFREE( user_data ); delete_oxm_matches( nw_src_prefix_20 ); delete_oxm_matches( nw_dst_prefix_20 ); delete_oxm_matches( nw_prefix_24 ); delete_oxm_matches( nw_prefix_28 ); delete_oxm_matches( match ); }
static void handle_delete_filter_request( const messenger_context_handle *handle, delete_packetin_filter_request *request ) { assert( handle != NULL ); assert( request != NULL ); buffer *buf = alloc_buffer_with_length( sizeof( delete_packetin_filter_reply ) ); delete_packetin_filter_reply *reply = append_back_buffer( buf, sizeof( delete_packetin_filter_reply ) ); reply->status = PACKETIN_FILTER_OPERATION_SUCCEEDED; reply->n_deleted = 0; struct ofp_match match; ntoh_match( &match, &request->criteria.match ); uint16_t priority = ntohs( request->criteria.priority ); if ( request->flags & PACKETIN_FILTER_FLAG_MATCH_STRICT ) { int n_deleted = delete_packetin_match_entry( match, priority, request->criteria.service_name ); reply->n_deleted += ( uint32_t ) n_deleted; } else { map_match_table( match, delete_filter_walker, buf ); } reply->n_deleted = htonl( reply->n_deleted ); bool ret = send_reply_message( handle, MESSENGER_DELETE_PACKETIN_FILTER_REPLY, buf->data, buf->length ); free_buffer( buf ); if ( ret == false ) { error( "Failed to send a dump filter reply." ); } }
static void test_map_entry_if_match_set_nw_src() { add_all_exact_entry(); add_all_wildcards_entry(); oxm_matches *match = create_oxm_matches(); append_oxm_match_eth_type( match, ETHERTYPE_IP ); append_oxm_match_ipv4_src( match, 0x0a000101, 0 ); char *user_data = xstrdup( USER_DATA ); count = 0; map_match_table( match, test_map_entry_if_match_set_nw_src_helper, user_data ); assert_int_equal( count, 2 ); XFREE( user_data ); delete_oxm_matches( match ); }
static void handle_dump_filter_request( const messenger_context_handle *handle, dump_packetin_filter_request *request ) { assert( handle != NULL ); assert( request != NULL ); buffer *buf = alloc_buffer_with_length( 2048 ); dump_packetin_filter_reply *reply = append_back_buffer( buf, offsetof( dump_packetin_filter_reply, entries ) ); reply->status = PACKETIN_FILTER_OPERATION_SUCCEEDED; reply->n_entries = 0; struct ofp_match match; ntoh_match( &match, &request->criteria.match ); uint16_t priority = ntohs( request->criteria.priority ); if ( request->flags & PACKETIN_FILTER_FLAG_MATCH_STRICT ) { list_element *services = lookup_match_strict_entry( match, priority ); while ( services != NULL ) { if ( strcmp( services->data, request->criteria.service_name ) == 0 ) { packetin_filter_entry *entry = append_back_buffer( buf, sizeof( packetin_filter_entry ) ); reply->n_entries++; entry->match = request->criteria.match; entry->priority = request->criteria.priority; strncpy( entry->service_name, services->data, sizeof( entry->service_name ) ); entry->service_name[ sizeof( entry->service_name ) - 1 ] = '\0'; } services = services->next; } } else { map_match_table( match, dump_filter_walker, buf ); } reply->n_entries = htonl( reply->n_entries ); bool ret = send_reply_message( handle, MESSENGER_DUMP_PACKETIN_FILTER_REPLY, buf->data, buf->length ); free_buffer( buf ); if ( ret == false ) { error( "Failed to send a dump packetin filter reply." ); } }