static void assert_table_feature_prop_next_tables( const struct ofp_table_feature_prop_next_tables const *tfpnt, uint16_t type ) { uint16_t expected_len = ( uint16_t ) sizeof( *tfpnt ); assert_int_equal( tfpnt->type, type ); expected_len = ( uint16_t ) ( expected_len + PADLEN_TO_64( expected_len ) ); assert_int_equal( tfpnt->length, expected_len ); }
static void assert_table_feature_prop_actions( const struct ofp_table_feature_prop_actions const *tfpa, uint16_t type ) { uint16_t expected_len = ( uint16_t ) sizeof( *tfpa ); assert_int_equal( tfpa->type, type ); const struct ofp_action_header const *ac_id = tfpa->action_ids; assert_int_equal( ac_id->type, OFPAT_OUTPUT ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 1 ]; assert_int_equal( ac_id->type, OFPAT_SET_QUEUE ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 2 ]; assert_int_equal( ac_id->type, OFPAT_GROUP ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 3 ]; assert_int_equal( ac_id->type, OFPAT_PUSH_VLAN ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 4 ]; assert_int_equal( ac_id->type, OFPAT_POP_VLAN ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 5 ]; assert_int_equal( ac_id->type, OFPAT_PUSH_MPLS ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 6 ]; assert_int_equal( ac_id->type, OFPAT_POP_MPLS ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 7 ]; assert_int_equal( ac_id->type, OFPAT_PUSH_PBB ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); ac_id = &tfpa->action_ids[ 8 ]; assert_int_equal( ac_id->type, OFPAT_POP_PBB ); assert_int_equal( ac_id->len, sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *ac_id ) ); expected_len = ( uint16_t ) ( expected_len + PADLEN_TO_64( expected_len ) ); assert_int_equal( tfpa->length, expected_len ); }
static void test_retrieve_flow_stats( void **state ) { UNUSED( state ); uint16_t total_len = ( uint16_t ) ( sizeof( struct ofp_match ) + OXM_LENGTH( OXM_OF_IN_PORT ) + sizeof( uint32_t ) + OXM_LENGTH( OXM_OF_IN_PHY_PORT ) + sizeof( uint32_t ) + OXM_LENGTH ( OXM_OF_METADATA ) ); total_len = ( uint16_t ) ( total_len + PADLEN_TO_64( total_len ) ); struct ofp_match *ofp_match = ( struct ofp_match * ) ( xmalloc( total_len ) ); ofp_match->type = OFPMT_OXM; ofp_match->length = total_len; uint32_t *oxm_id = ( uint32_t * ) ( ( char * ) ofp_match->oxm_fields ); *oxm_id = OXM_OF_IN_PORT; uint32_t *in_port = ( uint32_t * ) ( ( char * ) oxm_id + sizeof( *oxm_id ) ); *in_port = PORT_NO; oxm_id = ( uint32_t * ) ( ( char * ) in_port + OXM_LENGTH( OXM_OF_IN_PORT ) ); *oxm_id = OXM_OF_IN_PHY_PORT; uint32_t *in_phy_port = ( uint32_t * ) ( ( char * ) oxm_id + sizeof( *oxm_id ) ); *in_phy_port = PORT_NO; oxm_id = ( uint32_t * ) ( ( char * ) in_phy_port + OXM_LENGTH( OXM_OF_IN_PHY_PORT ) ); *oxm_id = OXM_OF_METADATA; uint64_t *metadata = ( uint64_t * ) ( ( char * ) oxm_id + sizeof( *oxm_id ) ); uint64_t dummy_metadata = 0x1122334455667788; memcpy( metadata, &dummy_metadata, sizeof( uint64_t ) ); uint32_t nr_stats = 0; uint8_t table_id = TABLE_ID; uint32_t out_port = PORT_NO; uint32_t out_group = GROUP_ID; uint64_t cookie = COOKIE; uint64_t cookie_mask = 0xffffffffffffffff; init_table_manager(); retrieve_flow_stats( &nr_stats, table_id, out_port, out_group, cookie, cookie_mask, ofp_match ); assert_int_equal( nr_stats, 0 ); }
static void unpack_flow_multipart_reply( VALUE r_attributes, void *data ) { assert( data ); const struct ofp_flow_stats *flow_stats = data; HASH_SET( r_attributes, "length", UINT2NUM( flow_stats->length ) ); HASH_SET( r_attributes, "table_id", UINT2NUM( flow_stats->table_id ) ); HASH_SET( r_attributes, "duration_sec", UINT2NUM( flow_stats->duration_sec ) ); HASH_SET( r_attributes, "duration_nsec", UINT2NUM( flow_stats->duration_nsec ) ); HASH_SET( r_attributes, "priority", UINT2NUM( flow_stats->priority ) ); HASH_SET( r_attributes, "idle_timeout", UINT2NUM( flow_stats->idle_timeout ) ); HASH_SET( r_attributes, "hard_timeout", UINT2NUM( flow_stats->hard_timeout ) ); HASH_SET( r_attributes, "flags", UINT2NUM( flow_stats->flags ) ); HASH_SET( r_attributes, "cookie", ULL2NUM( flow_stats->cookie ) ); HASH_SET( r_attributes, "packet_count", ULL2NUM( flow_stats->packet_count ) ); HASH_SET( r_attributes, "byte_count", ULL2NUM( flow_stats->byte_count ) ); VALUE r_match = ofp_match_to_r_match( &flow_stats->match ); if ( !NIL_P( r_match ) ) { HASH_SET( r_attributes, "match", r_match ); } uint16_t match_length = ( uint16_t ) ( flow_stats->match.length + PADLEN_TO_64( flow_stats->match.length ) ); size_t offset = offsetof( struct ofp_flow_stats, match ) + match_length; size_t instructions_length = flow_stats->length - offset; VALUE r_instruction_ary = rb_ary_new(); while ( instructions_length > sizeof( struct ofp_instruction ) ) { const struct ofp_instruction *inst_src = ( const struct ofp_instruction * ) ( ( const char * ) flow_stats + offset ); uint16_t part_length = inst_src->len; if ( instructions_length < part_length ) { break; } unpack_instruction( inst_src, r_instruction_ary ); instructions_length -= part_length; offset += part_length; } if ( RARRAY_LEN( r_instruction_ary ) ) { HASH_SET( r_attributes, "instructions", r_instruction_ary ); } }
static void assert_table_feature_prop_instructions( const struct ofp_table_feature_prop_instructions *tfpi, uint16_t type ) { uint16_t expected_len = ( uint16_t ) sizeof( *tfpi ); assert_int_equal( tfpi->type, type ); const struct ofp_instruction const *instruction = &tfpi->instruction_ids[ 0 ]; assert_int_equal( instruction->type, OFPIT_METER ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); instruction = &tfpi->instruction_ids[ 1 ]; assert_int_equal( instruction->type, OFPIT_APPLY_ACTIONS ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); instruction = &tfpi->instruction_ids[ 2 ]; assert_int_equal( instruction->type, OFPIT_CLEAR_ACTIONS ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); instruction = &tfpi->instruction_ids[ 3 ]; assert_int_equal( instruction->type, OFPIT_WRITE_ACTIONS ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); instruction = &tfpi->instruction_ids[ 4 ]; assert_int_equal( instruction->type, OFPIT_WRITE_METADATA ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); instruction = &tfpi->instruction_ids[ 5 ]; assert_int_equal( instruction->type, OFPIT_GOTO_TABLE ); assert_int_equal( instruction->len, sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + sizeof( *instruction ) ); expected_len = ( uint16_t ) ( expected_len + PADLEN_TO_64( expected_len ) ); assert_int_equal( tfpi->length, expected_len ); }
static void assert_table_feature_prop_oxm( const struct ofp_table_feature_prop_oxm const *tfpo, uint16_t type ) { uint16_t expected_len = ( uint16_t ) sizeof( *tfpo ); assert_int_equal( tfpo->type, type ); const uint32_t const *oxm_id = ( const uint32_t const * ) &tfpo->oxm_ids[ 0 ]; assert_int_equal( *oxm_id, OXM_OF_IN_PORT ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IN_PHY_PORT ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_METADATA ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ETH_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ETH_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ETH_TYPE ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_VLAN_VID ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_VLAN_PCP ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IP_DSCP ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IP_ECN ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IP_PROTO ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV4_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV4_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_TCP_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_TCP_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_UDP_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_UDP_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_SCTP_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_SCTP_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ICMPV4_TYPE ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ICMPV4_CODE ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ARP_OP ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ARP_SPA ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ARP_TPA ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ARP_SHA ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ARP_THA ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_SRC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_DST ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_FLABEL ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ICMPV6_TYPE ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_ICMPV6_CODE ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_ND_TARGET ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_ND_SLL ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_ND_TLL ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_MPLS_LABEL ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_MPLS_TC ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_MPLS_BOS ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); // comment out until datapath's match field is created // oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); // assert_int_equal( *oxm_id, OXM_OF_PBB_ISID ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_TUNNEL_ID ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); oxm_id = ( const uint32_t const * ) ( ( const char const * ) oxm_id + sizeof( uint32_t ) ); assert_int_equal( *oxm_id, OXM_OF_IPV6_EXTHDR ); expected_len = ( uint16_t ) ( expected_len + sizeof( *oxm_id ) ); expected_len = ( uint16_t ) ( expected_len + PADLEN_TO_64( expected_len ) ); assert_int_equal( tfpo->length, expected_len ); }
while ( elem != NULL ) { src = ( oxm_match_header * ) elem->data; hton_oxm_match( dst, src ); oxm_len = ( uint16_t ) ( sizeof( oxm_match_header ) + OXM_LENGTH( *src ) ); oxms_len = ( uint16_t ) ( oxms_len + oxm_len ); dst = ( oxm_match_header * ) ( ( char * ) dst + oxm_len ); elem = elem->next; } } ofp_match_len = ( uint16_t ) ( offsetof( struct ofp_match, oxm_fields ) + oxms_len ); match->type = htons( OFPMT_OXM ); match->length = htons( ( uint16_t ) ( ofp_match_len ) ); // exclude padding length pad_len = ( uint16_t ) PADLEN_TO_64( ofp_match_len ); if ( pad_len > 0 ) { memset( ( char * ) match + ofp_match_len, 0, pad_len ); } } oxm_matches * duplicate_oxm_matches( oxm_matches *matches ) { assert( matches != NULL ); uint16_t oxm_len = 0; oxm_match_header *dst, *src; list_element *elem = matches->list; oxm_matches *dup = create_oxm_matches();
static void test_finalize_packetin_filter_interface_fails_if_not_initialized() { assert_false( finalize_packetin_filter_interface() ); } /******************************************************************************** * add_packetin_filter() tests. ********************************************************************************/ static void test_add_packetin_filter_succeeds() { uint16_t match_len = ( uint16_t ) ( offsetof( struct ofp_match, oxm_fields ) + get_oxm_matches_length( MATCH ) ); uint16_t match_pad_len = ( uint16_t ) ( match_len + PADLEN_TO_64( match_len ) ); uint16_t entry_len = ( uint16_t ) ( offsetof( packetin_filter_entry, match ) + match_pad_len ); uint16_t req_len = ( uint16_t ) ( offsetof( add_packetin_filter_request, entry ) + entry_len ); add_packetin_filter_request *expected_data = xcalloc( 1, req_len ); memset( expected_data, 0, req_len ); expected_data->length = htons( req_len ); expected_data->entry.length = htons( entry_len ); expected_data->entry.priority = htons( PRIORITY ); strncpy( expected_data->entry.service_name, SERVICE_NAME, sizeof( expected_data->entry.service_name ) ); construct_ofp_match( &expected_data->entry.match, MATCH ); expect_string( mock_send_request_message, to_service_name, PACKETIN_FILTER_MANAGEMENT_SERVICE ); expect_string( mock_send_request_message, from_service_name, CLIENT_SERVICE_NAME ); expect_value( mock_send_request_message, tag32, MESSENGER_ADD_PACKETIN_FILTER_REQUEST ); expect_memory( mock_send_request_message, data, expected_data, req_len ); expect_value( mock_send_request_message, len, req_len );