static void test_packet_type_ether() { buffer *buf = alloc_buffer_with_length( sizeof( struct iphdr ) ); calloc_packet_info( buf ); assert_false( packet_type_ether( buf ) ); packet_info *packet_info = buf->user_data; packet_info->format |= ETH_DIX; assert_true( packet_type_ether( buf ) ); packet_info->format = 0; packet_info->format |= ETH_8023_RAW; assert_true( packet_type_ether( buf ) ); packet_info->format = 0; packet_info->format |= ETH_8023_LLC; assert_true( packet_type_ether( buf ) ); packet_info->format = 0; packet_info->format |= ETH_8023_SNAP; assert_true( packet_type_ether( buf ) ); packet_info->format = 0; free_buffer( buf ); }
static void handle_packet_in( uint64_t datapath_id, packet_in message ) { if ( !packet_type_ether( message.data ) ) { return; } struct key new_key; packet_info packet_info = get_packet_info( message.data ); memcpy( new_key.mac, packet_info.eth_macsa, OFP_ETH_ALEN ); new_key.datapath_id = datapath_id; hash_table *forwarding_db = message.user_data; learn( forwarding_db, new_key, message.in_port ); struct key search_key; memcpy( search_key.mac, packet_info.eth_macda, OFP_ETH_ALEN ); search_key.datapath_id = datapath_id; forwarding_entry *destination = lookup_hash_entry( forwarding_db, &search_key ); if ( destination == NULL ) { do_flooding( message ); } else { send_packet( destination->port_no, message ); } }
static void handle_packet_in( uint64_t datapath_id, packet_in message ) { info("got packet to handle"); if ( message.data == NULL ) { error( "data must not be NULL" ); return; } if ( !packet_type_ether( message.data ) ) { return; } uint32_t in_port = get_in_port_from_oxm_matches( message.match ); if ( in_port == 0 ) { return; } info("got a packet to handle from, %d",datapath_id); /* 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, OFPP_ALL, 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"); */ }