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_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 test_map_entry_if_match_set_nw_src_helper( oxm_matches *match, uint16_t priority, void *data, void *user_data ) { oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); switch ( ++count ) { case 1: assert_string_equal( ( char * ) data, ALICE_MATCH_SERVICE_NAME ); assert_true( priority == HIGH_PRIORITY ); assert_true( compare_oxm_match_strict( match, alice ) ); XFREE( data ); break; case 2: assert_string_equal( ( char * ) data, ALICE_MATCH_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, alice_wildcards ) ); XFREE( data ); break; default: assert_true( false ); break; } assert_string_equal( ( char * ) user_data, USER_DATA ); delete_oxm_matches( alice ); delete_oxm_matches( alice_wildcards ); }
static void test_map_entry_if_match_set_nw_prefix_helper( oxm_matches *match, uint16_t priority, void *data, void *user_data ) { oxm_matches *nw_prefix_24 = create_oxm_matches(); set_nw_prefix_24_wildcards_entry( nw_prefix_24 ); oxm_matches *nw_prefix_28 = create_oxm_matches(); set_nw_prefix_28_wildcards_entry( nw_prefix_28 ); switch ( ++count ) { case 1: assert_string_equal( ( char * ) data, NW_PREFIX_24_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, nw_prefix_24 ) ); XFREE( data ); break; case 2: assert_string_equal( ( char * ) data, NW_PREFIX_28_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, nw_prefix_28 ) ); XFREE( data ); break; default: assert_true( false ); break; } assert_string_equal( ( char * ) user_data, USER_DATA ); delete_oxm_matches( nw_prefix_24 ); delete_oxm_matches( nw_prefix_28 ); }
static void add_all_wildcards_entry() { 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, DEFAULT_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) ); 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 ) ) ); 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 ) ) ); oxm_matches *lldp_wildcards = create_oxm_matches(); set_lldp_wildcards_entry( lldp_wildcards ); assert_true( insert_match_entry( lldp_wildcards, HIGH_PRIORITY, xstrdup( LLDP_MATCH_SERVICE_NAME ) ) ); assert_true( update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob_wildcards ); delete_oxm_matches( carol_wildcards ); delete_oxm_matches( any_wildcards ); delete_oxm_matches( lldp_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_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_foreach_entry_if_wildcards_table_only_helper( oxm_matches *match, uint16_t priority, void *data, void *user_data ) { oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); oxm_matches *bob_wildcards = create_oxm_matches(); set_bob_wildcards_entry( bob_wildcards ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); oxm_matches *any_wildcards = create_oxm_matches(); set_any_wildcards_entry( any_wildcards ); oxm_matches *lldp_wildcards = create_oxm_matches(); set_lldp_wildcards_entry( lldp_wildcards ); switch ( ++count ) { case 2: assert_string_equal( ( char * ) data, ALICE_MATCH_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, alice_wildcards ) ); break; case 3: assert_string_equal( ( char * ) data, BOB_MATCH_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, bob_wildcards ) ); break; case 4: assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME ); assert_true( priority == DEFAULT_PRIORITY ); assert_true( compare_oxm_match_strict( match, carol_wildcards ) ); break; case 5: assert_string_equal( ( char * ) data, ANY_MATCH_SERVICE_NAME ); assert_true( priority == LOW_PRIORITY ); assert_true( compare_oxm_match_strict( match, any_wildcards ) ); break; case 1: assert_string_equal( ( char * ) data, LLDP_MATCH_SERVICE_NAME ); assert_true( priority == HIGH_PRIORITY ); assert_true( compare_oxm_match_strict( match, lldp_wildcards ) ); break; default: assert_true( false ); break; } assert_string_equal( ( char * ) user_data, USER_DATA ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob_wildcards ); delete_oxm_matches( carol_wildcards ); delete_oxm_matches( any_wildcards ); delete_oxm_matches( lldp_wildcards ); }
static void test_delete_of_deleted_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( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) ); assert_true( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) == NULL ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards ); }
static void test_update_different_priority_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( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY + 1, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) ); delete_oxm_matches( carol ); delete_oxm_matches( carol_wildcards );}
static void test_insert_existing_same_match_same_priority_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( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); assert_true( !insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); void *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 add_all_exact_entry() { oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); assert_true( insert_match_entry( alice, HIGH_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) ); oxm_matches *bob = create_oxm_matches(); set_bob_match_entry( bob ); assert_true( insert_match_entry( bob, HIGH_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) ); oxm_matches *carol = create_oxm_matches(); set_carol_match_entry( carol ); assert_true( insert_match_entry( carol, HIGH_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) ); assert_true( update_match_entry( carol, HIGH_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) ); delete_oxm_matches( alice ); delete_oxm_matches( bob ); delete_oxm_matches( carol ); }
static void test_delete_match_strict_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( delete_match_strict_entry( alice, DEFAULT_PRIORITY ) ); delete_oxm_matches( alice ); }
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 handle_packet_in( uint64_t datapath_id, packet_in message ) { if ( message.data == NULL ) { error( "data must not be NULL" ); return; } uint32_t in_port = get_in_port_from_oxm_matches( message.match ); if ( in_port == 0 ) { return; } openflow_actions *actions = create_actions(); append_action_output( actions, OFPP_ALL, OFPCML_NO_BUFFER ); openflow_instructions *insts = create_instructions(); append_instructions_apply_actions( insts, actions ); oxm_matches *match = create_oxm_matches(); set_match_from_packet( match, in_port, 0, message.data ); buffer *flow_mod = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 60, 0, OFP_HIGH_PRIORITY, message.buffer_id, 0, 0, OFPFF_SEND_FLOW_REM, match, insts ); send_openflow_message( datapath_id, flow_mod ); free_buffer( flow_mod ); delete_oxm_matches( match ); delete_instructions( insts ); if ( message.buffer_id == OFP_NO_BUFFER ) { buffer *frame = duplicate_buffer( message.data ); fill_ether_padding( frame ); buffer *packet_out = create_packet_out( get_transaction_id(), message.buffer_id, in_port, actions, frame ); send_openflow_message( datapath_id, packet_out ); free_buffer( packet_out ); free_buffer( frame ); } delete_actions( actions ); }
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_update_match_entry_dies_if_not_initialized() { assert_true( _match_table_head == NULL ); oxm_matches *alice = create_oxm_matches(); set_alice_match_entry( alice ); void *data = xstrdup( ALICE_MATCH_SERVICE_NAME ); expect_assert_failure( update_match_entry( alice, DEFAULT_PRIORITY, data ) ); XFREE( data ); 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 send_packet( uint32_t destination_port, packet_in packet_in, uint32_t in_port ) { openflow_actions *actions = create_actions(); append_action_output( actions, destination_port, OFPCML_NO_BUFFER ); openflow_instructions *insts = create_instructions(); append_instructions_apply_actions( insts, actions ); oxm_matches *match = create_oxm_matches(); set_match_from_packet( match, in_port, NULL, packet_in.data ); buffer *flow_mod = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 60, 0, OFP_HIGH_PRIORITY, packet_in.buffer_id, 0, 0, OFPFF_SEND_FLOW_REM, match, insts ); send_openflow_message( packet_in.datapath_id, flow_mod ); free_buffer( flow_mod ); delete_oxm_matches( match ); delete_instructions( insts ); if ( packet_in.buffer_id == OFP_NO_BUFFER ) { buffer *frame = duplicate_buffer( packet_in.data ); fill_ether_padding( frame ); buffer *packet_out = create_packet_out( get_transaction_id(), packet_in.buffer_id, in_port, actions, frame ); send_openflow_message( packet_in.datapath_id, packet_out ); free_buffer( packet_out ); free_buffer( frame ); } delete_actions( actions ); }
static void delete_all_wildcards_entry() { oxm_matches *alice_wildcards = create_oxm_matches(); set_alice_wildcards_entry( alice_wildcards ); XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) ); oxm_matches *bob_wildcards = create_oxm_matches(); set_bob_wildcards_entry( bob_wildcards ); XFREE( delete_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY ) ); oxm_matches *carol_wildcards = create_oxm_matches(); set_carol_wildcards_entry( carol_wildcards ); XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) ); oxm_matches *any_wildcards = create_oxm_matches(); set_any_wildcards_entry( any_wildcards ); XFREE( delete_match_strict_entry( any_wildcards, LOW_PRIORITY ) ); oxm_matches *lldp_wildcards = create_oxm_matches(); set_lldp_wildcards_entry( lldp_wildcards ); XFREE( delete_match_strict_entry( lldp_wildcards, HIGH_PRIORITY ) ); delete_oxm_matches( alice_wildcards ); delete_oxm_matches( bob_wildcards ); delete_oxm_matches( carol_wildcards ); delete_oxm_matches( any_wildcards ); delete_oxm_matches( lldp_wildcards ); }
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 ); }
buffer * pack_aggregate_multipart_request( VALUE options ) { uint32_t xid = get_transaction_id(); VALUE r_xid = HASH_REF( options, transaction_id ); if ( !NIL_P( r_xid ) ) { xid = NUM2UINT( r_xid ); } uint16_t flags = 0; VALUE r_flags = HASH_REF( options, flags ); if ( !NIL_P( r_flags ) ) { flags = ( uint16_t ) NUM2UINT( r_flags ); } uint8_t table_id = OFPTT_ALL; VALUE r_table_id = HASH_REF( options, table_id ); if ( !NIL_P( r_table_id ) ) { table_id = ( uint8_t ) NUM2UINT( r_table_id ); } uint32_t out_port = OFPP_ANY; VALUE r_out_port = HASH_REF( options, out_port ); if ( !NIL_P( r_out_port ) ) { out_port = NUM2UINT( r_out_port ); } uint32_t out_group = OFPG_ANY; VALUE r_out_group = HASH_REF( options, out_group ); if ( !NIL_P( r_out_group ) ) { out_group = NUM2UINT( r_out_group ); } uint64_t cookie = 0; VALUE r_cookie = HASH_REF( options, cookie ); if ( !NIL_P( r_cookie ) ) { cookie = ( uint64_t ) NUM2ULL( r_cookie ); } uint64_t cookie_mask = 0; VALUE r_cookie_mask = HASH_REF( options, cookie_mask ); if ( !NIL_P( r_cookie_mask ) ) { cookie_mask = ( uint64_t ) NUM2ULL( r_cookie_mask ); } VALUE r_match = HASH_REF( options, match ); oxm_matches *oxm_match = NULL; if ( !NIL_P( r_match ) ) { oxm_match = create_oxm_matches(); r_match_to_oxm_match( r_match, oxm_match ); } buffer *aggregate_multipart_request = create_aggregate_multipart_request( xid, flags, table_id, out_port, out_group, cookie, cookie_mask, oxm_match ); if ( oxm_match != NULL ) { delete_oxm_matches( oxm_match ); } return aggregate_multipart_request; }
static void handle_switch_ready( uint64_t datapath_id, void *user_data ) { UNUSED( user_data ); openflow_actions *actions = create_actions(); append_action_output( actions, OFPP_CONTROLLER, OFPCML_NO_BUFFER ); openflow_instructions *insts = create_instructions(); append_instructions_apply_actions( insts, actions ); buffer *flow_mod = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_LOW_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, NULL, insts ); send_openflow_message( datapath_id, flow_mod ); free_buffer( flow_mod ); delete_instructions( insts ); // sleep(2000); info("sending ARP config to %d",datapath_id); uint32_t dest = OFPP_ALL; oxm_matches *match2 = create_oxm_matches(); append_oxm_match_eth_type( match2, 0x0806); openflow_actions *actions2 = create_actions(); append_action_output( actions2, dest, OFPCML_NO_BUFFER ); openflow_instructions *insts2 = create_instructions(); append_instructions_apply_actions( insts2, actions2 ); buffer *flow_mod2 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match2, insts2 ); send_openflow_message( datapath_id, flow_mod2 ); free_buffer( flow_mod2 ); delete_oxm_matches( match2 ); delete_instructions( insts2 ); // sleep(2000); info("sending second config: ipv4"); oxm_matches *match3 = create_oxm_matches(); append_oxm_match_eth_type( match3, 0x0800); // append_oxm_match_in_port( match2, 2); // dest = 1; openflow_actions *actions3 = create_actions(); append_action_push_mpls(actions3,0x8847); append_action_set_field_mpls_label(actions3,4120955); append_action_output( actions3, dest, OFPCML_NO_BUFFER ); openflow_instructions *insts3 = create_instructions(); append_instructions_apply_actions( insts3, actions3 ); buffer *flow_mod3 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match3, insts3 ); send_openflow_message( datapath_id, flow_mod3 ); free_buffer( flow_mod3 ); delete_oxm_matches( match3 ); delete_instructions( insts3 ); info("done sending"); // sleep(2000); info("sending third config"); oxm_matches *match4 = create_oxm_matches(); append_oxm_match_eth_type( match4, 0x8847); append_oxm_match_mpls_label(match4, 4120955); openflow_actions *actions4 = create_actions(); append_action_pop_mpls(actions4, 0x0800); append_action_output( actions4, dest, OFPCML_NO_BUFFER ); openflow_instructions *insts4 = create_instructions(); append_instructions_apply_actions( insts4, actions4 ); buffer *flow_mod4 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match4, insts4 ); send_openflow_message( datapath_id, flow_mod4); free_buffer( flow_mod4 ); delete_oxm_matches( match4 ); delete_instructions( insts4 ); info("done sending"); }
static void free_MATCH() { delete_oxm_matches( MATCH ); }
static void handle_switch_ready( uint64_t datapath_id, void *user_data ) { UNUSED( user_data ); openflow_actions *actions = create_actions(); append_action_output( actions, OFPP_CONTROLLER, OFPCML_NO_BUFFER ); openflow_instructions *insts = create_instructions(); append_instructions_apply_actions( insts, actions ); buffer *flow_mod = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_LOW_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, NULL, insts ); send_openflow_message( datapath_id, flow_mod ); free_buffer( flow_mod ); delete_instructions( insts ); // sleep(2000); info("sending ARP config: flood - %d",datapath_id); uint32_t dest = OFPP_ALL; oxm_matches *match2 = create_oxm_matches(); append_oxm_match_eth_type( match2, 0x0806); openflow_actions *actions2 = create_actions(); append_action_output( actions2, dest, OFPCML_NO_BUFFER ); openflow_instructions *insts2 = create_instructions(); append_instructions_apply_actions( insts2, actions2 ); buffer *flow_mod2 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match2, insts2 ); send_openflow_message( datapath_id, flow_mod2 ); free_buffer( flow_mod2 ); delete_oxm_matches( match2 ); delete_instructions( insts2 ); // sleep(2000); info("sending second config: match on eth src"); uint8_t eth_src[ OFP_ETH_ALEN ] = {0x0,0x24,0xe8,0x77,0xa5,0x32}; uint8_t set_src[ OFP_ETH_ALEN ] = {0x0,0x10,0x18,0x56,0xab,0xc2}; uint8_t eth_mask[ OFP_ETH_ALEN ] = {0xff,0xff,0xff,0xff,0xff,0xff}; oxm_matches *match3 = create_oxm_matches(); append_oxm_match_eth_type( match3, 0x0800); append_oxm_match_eth_src( match3,eth_src,eth_mask); // append_oxm_match_in_port( match2, 2); // dest = 1; openflow_actions *actions3 = create_actions(); append_action_set_field_eth_src( actions3, set_src ); append_action_push_mpls(actions3,0x8847); append_action_set_field_mpls_label(actions3,412095); append_action_output( actions3, 3, OFPCML_NO_BUFFER ); openflow_instructions *insts3 = create_instructions(); append_instructions_apply_actions( insts3, actions3 ); buffer *flow_mod3 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match3, insts3 ); send_openflow_message( datapath_id, flow_mod3 ); free_buffer( flow_mod3 ); delete_oxm_matches( match3 ); delete_instructions( insts3 ); info("done sending"); // sleep(2000); info("sending config:match mpls label -> pop mpls, set dest eth"); oxm_matches *match4 = create_oxm_matches(); append_oxm_match_eth_type( match4, 0x8847); append_oxm_match_mpls_label(match4, 412095); uint8_t set_src2[ OFP_ETH_ALEN ] = {0x0,0x24,0xe8,0x77,0xa5,0x32}; openflow_actions *actions4 = create_actions(); append_action_pop_mpls(actions4, 0x0800); append_action_output( actions4, 1, OFPCML_NO_BUFFER ); append_action_set_field_eth_src( actions4, set_src2 ); openflow_instructions *insts4 = create_instructions(); append_instructions_apply_actions( insts4, actions4 ); buffer *flow_mod4 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match4, insts4 ); send_openflow_message( 0x00101856ab98 , flow_mod4); free_buffer( flow_mod4 ); delete_oxm_matches( match4 ); delete_instructions( insts4 ); info("sending second config: match on eth src"); uint8_t set_src3[ OFP_ETH_ALEN ] = {0x0,0x10,0x18,0x56,0xab,0xc2}; oxm_matches *match5 = create_oxm_matches(); append_oxm_match_eth_type( match5, 0x0800); // append_oxm_match_eth_src( match3,eth_src,eth_mask); // append_oxm_match_in_port( match2, 2); // dest = 1; openflow_actions *actions5 = create_actions(); append_action_set_field_eth_src( actions5, set_src3 ); append_action_push_mpls(actions5,0x8847); append_action_set_field_mpls_label(actions5,442095); append_action_output( actions5, 3, OFPCML_NO_BUFFER ); openflow_instructions *insts5 = create_instructions(); append_instructions_apply_actions( insts5, actions5 ); buffer *flow_mod5 = create_flow_mod( get_transaction_id(), get_cookie(), 0, 0, OFPFC_ADD, 0, 0, OFP_HIGH_PRIORITY, OFP_NO_BUFFER, 0, 0, OFPFF_SEND_FLOW_REM, match5, insts5 ); send_openflow_message( datapath_id, flow_mod5 ); free_buffer( flow_mod5 ); delete_oxm_matches( match5 ); delete_instructions( insts5 ); info("done sending"); }