static void test_insert_wildcards_entry_into_empty_table_succeeds() { oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) ); oxm_matches *bob = create_oxm_matches(); set_bob_match_entry( bob ); void *data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME ); void *data1 = lookup_match_entry( alice ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME ); assert_true( data0 == data1 ); assert_true( lookup_match_entry( bob ) == NULL ); void *data2 = delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ); assert_true( data2 != NULL ); assert_string_equal( ( char * ) data2, ALICE_MATCH_SERVICE_NAME ); assert_true( data1 == data2 ); XFREE( data2 ); delete_oxm_matches( alice ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob ); }
static void test_insert_existing_same_priority_wildcards_entry_succeeds() { oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) ); oxm_matches *bob = create_oxm_matches(); set_bob_match_entry( bob ); oxm_matches *bob_wildcards = create_oxm_matches(); set_bob_wildcards_entry( bob_wildcards ); assert_true( insert_match_entry( bob_wildcards, DEFAULT_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) ); void *data0 = lookup_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, BOB_MATCH_SERVICE_NAME ); void *data1 = lookup_match_entry( bob ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, BOB_MATCH_SERVICE_NAME ); assert_true( data0 == data1 ); oxm_matches *any_wildcards = create_oxm_matches(); set_any_wildcards_entry( any_wildcards ); assert_true( insert_match_entry( any_wildcards, DEFAULT_PRIORITY, xstrdup( ANY_MATCH_SERVICE_NAME ) ) ); oxm_matches *carol = create_oxm_matches(); set_carol_match_entry( carol ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); data0 = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, CAROL_MATCH_SERVICE_NAME ); data1 = lookup_match_entry( carol ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ANY_MATCH_SERVICE_NAME ); assert_true( data0 != data1 ); data1 = lookup_match_entry( alice ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME ); data1 = lookup_match_entry( bob ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, BOB_MATCH_SERVICE_NAME ); XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) ); XFREE( delete_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY ) ); XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) ); XFREE( delete_match_strict_entry( any_wildcards, DEFAULT_PRIORITY ) ); delete_oxm_matches( alice ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob ); delete_oxm_matches( bob_wildcards ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards ); delete_oxm_matches( any_wildcards ); }
static void test_insert_and_delete_of_exact_all_entry_failed() { setup(); struct ofp_match lookup_match; match_entry *match_entry; init_match_table(); intsert_alice_match_entry(); intsert_bob_match_entry(); intsert_carol_match_entry(); delete_carol_match_entry(); set_carol_match_entry( &lookup_match ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); delete_bob_match_entry(); set_bob_match_entry( &lookup_match ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); delete_alice_match_entry(); set_alice_match_entry( &lookup_match ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); finalize_match_table(); teardown(); }
static void test_insert_lowest_priority_wildcards_entry_succeeds() { oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) ); oxm_matches *bob_wildcards = create_oxm_matches(); set_bob_wildcards_entry( bob_wildcards ); assert_true( insert_match_entry( bob_wildcards, LOW_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) ); void *data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME ); void *data1 = lookup_match_entry( alice ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME ); assert_true( data0 == data1 ); oxm_matches *lldp_wildcards = create_oxm_matches(); set_lldp_wildcards_entry( lldp_wildcards ); assert_true( insert_match_entry( lldp_wildcards, LOW_PRIORITY, xstrdup( LLDP_MATCH_SERVICE_NAME ) ) ); data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME ); data1 = lookup_match_entry( alice ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME ); assert_true( data0 == data1 ); oxm_matches *any_wildcards = create_oxm_matches(); set_any_wildcards_entry( any_wildcards ); assert_true( insert_match_entry( any_wildcards, LOW_PRIORITY, xstrdup( ANY_MATCH_SERVICE_NAME ) ) ); data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ); assert_true( data0 != NULL ); assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME ); data1 = lookup_match_entry( alice ); assert_true( data1 != NULL ); assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME ); assert_true( data0 == data1 ); XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) ); XFREE( delete_match_strict_entry( bob_wildcards, LOW_PRIORITY ) ); XFREE( delete_match_strict_entry( lldp_wildcards, LOW_PRIORITY ) ); XFREE( delete_match_strict_entry( any_wildcards, LOW_PRIORITY ) ); delete_oxm_matches( alice ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob_wildcards ); delete_oxm_matches( lldp_wildcards ); delete_oxm_matches( any_wildcards ); }
static void test_update_nonexistent_wildcards_entry_fails() { oxm_matches *carol = create_oxm_matches(); set_carol_match_entry( carol ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_match_entry( alice_wildcards ); assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) ); assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); void *data = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ); assert_true( data == NULL ); data = lookup_match_entry( carol ); assert_true( data == NULL ); XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards ); delete_oxm_matches( alice_wildcards ); }
static void test_insert_and_lookup_of_exact_alice_entry_conflict() { setup(); struct ofp_match lookup_match; match_entry *match_entry; init_match_table(); intsert_alice_match_entry(); intsert_mallory_match_entry(); set_alice_match_entry( &lookup_match ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry != NULL ); assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) ); assert_string_equal( match_entry->service_name, ALICE_MATCH_SERVICE_NAME ); assert_string_equal( match_entry->entry_name, ALICE_MATCH_ENTRY_NAME ); finalize_match_table(); teardown(); }
static void test_insert_and_lookup_of_wildcard_lldp_entry() { setup(); struct ofp_match match, lookup_match; match_entry *match_entry; init_match_table(); intsert_lldp_match_entry(); memset( &lookup_match, 0, sizeof( struct ofp_match ) ); lookup_match.dl_type = ETH_ETHTYPE_LLDP; match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry != NULL ); set_lldp_match_entry( &match ); assert_memory_equal( &match_entry->ofp_match, &match, sizeof( struct ofp_match ) ); assert_true( match_entry->priority == LLDP_MATCH_PRIORITY ); assert_string_equal( match_entry->service_name, LLDP_MATCH_SERVICE_NAME ); assert_string_equal( match_entry->entry_name, LLDP_MATCH_ENTRY_NAME ); finalize_match_table(); teardown(); }
static void test_lookup_match_entry_dies_if_not_initialized() { assert_true( _match_table_head == NULL ); oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); expect_assert_failure( lookup_match_entry( alice ) ); delete_oxm_matches( alice ); }
static void test_reinsert_of_deleted_lowhest_priority_wildcards_entry_succeeds() { oxm_matches *carol = create_oxm_matches(); set_carol_match_entry( carol ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); assert_true( insert_match_entry( carol_wildcards, LOW_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); XFREE( delete_match_strict_entry( carol_wildcards, LOW_PRIORITY ) ); void *data = lookup_match_strict_entry( carol, LOW_PRIORITY ); assert_true( data == NULL ); data = lookup_match_entry( carol ); assert_true( data == NULL ); assert_true( insert_match_entry( carol_wildcards, LOW_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); data = lookup_match_entry( carol ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME ); XFREE( delete_match_strict_entry( carol_wildcards, LOW_PRIORITY ) ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards ); }
static void handle_packet_in( uint64_t datapath_id, uint32_t transaction_id, uint32_t buffer_id, uint16_t total_len, uint16_t in_port, uint8_t reason, const buffer *data, void *user_data ) { UNUSED( user_data ); char match_str[ 1024 ]; struct ofp_match ofp_match; // host order buffer *copy = NULL; packet_info *packet_info = data->user_data; debug( "Receive packet. ethertype=0x%04x, ipproto=0x%x", packet_info->eth_type, packet_info->ipv4_protocol ); if ( packet_type_ipv4_etherip( data ) ) { copy = parse_etherip( data ); } set_match_from_packet( &ofp_match, in_port, 0, copy != NULL ? copy : data ); if ( copy != NULL ) { free_buffer( copy ); copy = NULL; } match_to_string( &ofp_match, match_str, sizeof( match_str ) ); list_element *services = lookup_match_entry( ofp_match ); if ( services == NULL ) { debug( "match entry not found" ); return; } buffer *buf = create_packet_in( transaction_id, buffer_id, total_len, in_port, reason, data ); openflow_service_header_t *message; message = append_front_buffer( buf, sizeof( openflow_service_header_t ) ); message->datapath_id = htonll( datapath_id ); message->service_name_length = htons( 0 ); list_element *element; for ( element = services; element != NULL; element = element->next ) { const char *service_name = element->data; if ( !send_message( service_name, MESSENGER_OPENFLOW_MESSAGE, buf->data, buf->length ) ) { error( "Failed to send a message to %s ( match = %s ).", service_name, match_str ); free_buffer( buf ); return; } debug( "Sending a message to %s ( match = %s ).", service_name, match_str ); } free_buffer( buf ); }
static void test_update_exact_wildcards_succeeds() { oxm_matches *carol = create_oxm_matches(); set_carol_match_entry( carol ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); void *data = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_SERVICE_NAME ); data = lookup_match_entry( carol ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_SERVICE_NAME ); assert_true( update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); data = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME ); data = lookup_match_entry( carol ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME ); assert_true( update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); data = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_SERVICE_NAME ); data = lookup_match_entry( carol ); assert_true( data != NULL ); assert_string_equal( ( char * ) data, CAROL_MATCH_SERVICE_NAME ); XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards ); }
static void test_lookup_of_exact_alice_entry_failed() { setup(); struct ofp_match lookup_match; match_entry *match_entry; init_match_table(); set_alice_match_entry( &lookup_match ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); finalize_match_table(); teardown(); }
static void test_lookup_of_wildcard_lldp_entry_failed() { setup(); struct ofp_match lookup_match; match_entry *match_entry; init_match_table(); memset( &lookup_match, 0, sizeof( struct ofp_match ) ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); finalize_match_table(); teardown(); }
static void test_insert_and_delete_of_wildcard_any_entry() { setup(); struct ofp_match lookup_match; match_entry *match_entry; init_match_table(); intsert_any_match_entry(); delete_any_match_entry(); memset( &lookup_match, 0, sizeof( struct ofp_match ) ); match_entry = lookup_match_entry( &lookup_match ); assert_true( match_entry == NULL ); finalize_match_table(); teardown(); }
static void handle_packet_in( uint64_t datapath_id, uint32_t transaction_id, uint32_t buffer_id, uint16_t total_len, uint16_t in_port, uint8_t reason, const buffer *data, void *user_data ) { UNUSED( user_data ); char match_str[ 1024 ]; struct ofp_match ofp_match; // host order set_match_from_packet( &ofp_match, in_port, 0, data ); match_to_string( &ofp_match, match_str, sizeof( match_str ) ); match_entry *match_entry = lookup_match_entry( &ofp_match ); if ( match_entry == NULL ) { debug( "No match entry found." ); return; } buffer *buf = create_packet_in( transaction_id, buffer_id, total_len, in_port, reason, data ); openflow_service_header_t *message; message = append_front_buffer( buf, sizeof( openflow_service_header_t ) ); message->datapath_id = htonll( datapath_id ); message->service_name_length = htons( 0 ); if ( !send_message( match_entry->service_name, MESSENGER_OPENFLOW_MESSAGE, buf->data, buf->length ) ) { error( "Failed to send a message to %s ( entry_name = %s, match = %s ).", match_entry->service_name, match_entry->entry_name, match_str ); free_buffer( buf ); return; } debug( "Sending a message to %s ( entry_name = %s, match = %s ).", match_entry->service_name, match_entry->entry_name, match_str ); free_buffer( buf ); }