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 ); delete_actions( actions ); }
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 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 ); }
OFDPE update_or_add_flow_entry( const uint8_t table_id, const match *key, const uint64_t cookie, const uint64_t cookie_mask, const uint16_t priority, const uint16_t idle_timeout, const uint16_t hard_timeout, const uint16_t flags, const bool strict, instruction_set *instructions ) { if ( !valid_table_id( table_id ) ) { return ERROR_OFDPE_FLOW_MOD_FAILED_BAD_TABLE_ID; } if ( key == NULL ) { error( "Invalid match ( %p ).", key ); return ERROR_INVALID_PARAMETER; } if ( instructions == NULL ) { error( "Invalid instruction set ( %p ).", instructions ); return ERROR_INVALID_PARAMETER; } if ( !lock_pipeline() ) { return ERROR_LOCK; } flow_table *table = get_flow_table( table_id ); assert( table != NULL ); OFDPE ret = validate_instruction_set( instructions, table->features.metadata_write ); if ( ret != OFDPE_SUCCESS ) { error( "Invalid instruction set ( ret = %#x, instructions = %p ).", ret, instructions ); unlock_pipeline(); return ret; } list_element *list = lookup_flow_entries_with_table_id( table_id, key, priority, strict, false ); if ( list != NULL ) { update_flow_entries_in_list( list, cookie, cookie_mask, flags, instructions ); delete_list( list ); } else { match *duplicated_match = duplicate_match( key ); instruction_set *duplicated_instructions = duplicate_instructions( instructions ); flow_entry *entry = alloc_flow_entry( duplicated_match, duplicated_instructions, priority, idle_timeout, hard_timeout, flags, cookie ); if ( entry != NULL ) { ret = add_flow_entry( table_id, entry, flags ); if ( ret != OFDPE_SUCCESS ) { error( "Failed to add flow entry ( table_id = %#x, entry = %p, flags = %#x ).", table_id, entry, flags ); } } else { delete_match( duplicated_match ); delete_instructions( duplicated_instructions ); ret = OFDPE_FAILED; } } if ( !unlock_pipeline() ) { return ERROR_UNLOCK; } return ret; }
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 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"); }