static void management_recv( uint16_t tag, void *data, size_t data_len ) { UNUSED( data ); UNUSED( data_len ); switch ( tag ) { case DUMP_XID_TABLE: dump_xid_table(); break; case DUMP_COOKIE_TABLE: dump_cookie_table(); break; case TOGGLE_COOKIE_AGING: if ( age_cookie_table_enabled ) { delete_timer_event( age_cookie_table, NULL ); age_cookie_table_enabled = false; } else { add_periodic_event_callback( COOKIE_TABLE_AGING_INTERVAL, age_cookie_table, NULL ); age_cookie_table_enabled = true; } break; default: error( "Undefined management message tag ( tag = %#x )", tag ); } }
static void test_timer_event_callback() { init_timer(); will_return_count( mock_clock_gettime, 0, -1 ); char user_data[] = "It's time!!!"; struct itimerspec interval; interval.it_value.tv_sec = 1; interval.it_value.tv_nsec = 1000; interval.it_interval.tv_sec = 2; interval.it_interval.tv_nsec = 2000; assert_true( add_timer_event_callback( &interval, mock_timer_event_callback, user_data ) ); timer_callback_info *callback = find_timer_callback( mock_timer_event_callback ); assert_true( callback != NULL ); assert_true( callback->function == mock_timer_event_callback ); assert_string_equal( callback->user_data, "It's time!!!" ); assert_int_equal( callback->interval.tv_sec, 2 ); assert_int_equal( callback->interval.tv_nsec, 2000 ); delete_timer_event( mock_timer_event_callback, user_data ); assert_true( find_timer_callback( mock_timer_event_callback ) == NULL ); finalize_timer(); }
static void switch_unset_timeout( timer_callback callback, void *user_data ) { if ( switch_info.running_timer ) { switch_info.running_timer = false; delete_timer_event( callback, user_data ); } }
bool finalize_redirector() { hash_iterator iter; hash_entry *entry; host_entry *host_entry; if ( host_db != NULL ) { delete_timer_event( age_host_db, NULL ); init_hash_iterator( host_db, &iter ); while ( ( entry = iterate_hash_next( &iter ) ) != NULL ) { host_entry = entry->value; if ( host_entry != NULL ) { delete_host_route( host_entry->ip ); xfree( host_entry ); } } delete_hash( host_db ); } host_db = NULL; if ( fd >= 0 ) { set_readable( fd, false ); delete_fd_handler( fd ); } return finalize_tun(); }
static void timeout( void *user_data ) { UNUSED( user_data ); printf( "Timeout.\n" ); delete_timer_event( timeout, NULL ); stop_trema(); }
bool finalize_transaction_manager() { debug( "Finalizing transaction manager." ); delete_transaction_db(); delete_timer_event( age_transaction_entries, NULL ); debug( "Finalization completed." ); return true; }
static void wait_for_port_to_be_deleted( void *user_data ) { transaction_entry *entry = user_data; debug( "Waiting for a tunnel port to be deleted ( entry = %p, datapath_id = %#" PRIx64 ", vni = %#x ).", entry, entry != NULL ? entry->datapath_id : 0, entry != NULL ? entry->vni : 0 ); assert( user_data != NULL ); uint16_t port_no = 0; char name[ IFNAMSIZ ]; memset( name, '\0', sizeof( name ) ); snprintf( name, sizeof( name ), "vxlan%u", entry->vni & VNI_MASK ); bool ret = get_port_no_by_name( entry->datapath_id, name, &port_no ); if ( ret ) { if ( entry->port_wait_count >= 10 ) { warn( "A tunnel port is not deleted from a switch ( datapath_id = %#" PRIx64 ", vni = %#x, name = %s ).", entry->datapath_id, entry->vni, name ); if ( entry->callback != NULL ) { debug( "Calling a callback function ( calback = %p, user_data = %p ).", entry->callback, entry->user_data ); entry->callback( OVERLAY_NETWORK_OPERATION_FAILED, entry->user_data ); } delete_timer_event( wait_for_port_to_be_deleted, entry ); delete_transaction( entry->datapath_id, entry->vni ); } else { entry->port_wait_count++; debug( "port_wait_count = %d.", entry->port_wait_count ); } return; } debug( "A tunnel port is successfully deleted from a switch ( datapath_id = %#" PRIx64 ", vni = %#x, name = %s, port_no = %u ).", entry->datapath_id, entry->vni, name, port_no ); if ( entry->callback != NULL ) { debug( "Calling a callback function ( calback = %p, user_data = %p ).", entry->callback, entry->user_data ); entry->callback( OVERLAY_NETWORK_OPERATION_SUCCEEDED, entry->user_data ); } delete_timer_event( wait_for_port_to_be_deleted, entry ); delete_transaction( entry->datapath_id, entry->vni ); }
void _switch_response_handler( event_forward_operation_result result, void *user_data ) { struct txinfo *txinfo = user_data; const uint64_t dpid = txinfo->dpid; const uint32_t txid = txinfo->txid; delete_timer_event( _switch_response_timeout, txinfo ); xfree( txinfo ); txinfo = NULL; debug( "txid %#x switch %#" PRIx64 " response.", txid, dpid ); all_sw_tx *tx = lookup_hash_entry( efi_tx_table, &txid ); if ( tx == NULL ) { // transaction already failed. Do nothing. return; } uint64_t *dpid_in_list = lookup_hash_entry( tx->waiting_dpid, &dpid ); if ( dpid_in_list == NULL ) { // probably timed out. Do nothing. return; } delete_hash_entry( tx->waiting_dpid, &dpid ); xfree( dpid_in_list ); dpid_in_list = NULL; if ( result.result == EFI_OPERATION_FAILED ) { warn( "txid %#x Setting event forwarding entry to switch %#" PRIx64 " failed.", txid, dpid ); tx->tx_result = EFI_OPERATION_FAILED; } bool tx_ended = check_tx_result_and_respond( tx ); if ( tx_ended ) return; struct event_forward_operation_to_all_request_param *all_param = tx->request_param; if ( hash_table_is_empty( tx->waiting_dpid ) ) { // was last element in tx. callback result. if ( all_param->callback != NULL ) { all_param->callback( tx->tx_result, all_param->user_data ); } info( "txid %#x complete.", tx->txid ); // remove and cleanup tx delete_hash_entry( efi_tx_table, &tx->txid ); xfree_all_sw_tx( tx ); return; } }
int switch_event_disconnected( struct switch_info *sw_info ) { int old_state = sw_info->state; sw_info->state = SWITCH_STATE_DISCONNECTED; if ( old_state == SWITCH_STATE_COMPLETED ) { delete_timer_event( echo_request_interval, sw_info ); } if ( sw_info->fragment_buf != NULL ) { free_buffer( sw_info->fragment_buf ); sw_info->fragment_buf = NULL; } if ( sw_info->send_queue != NULL ) { delete_message_queue( sw_info->send_queue ); sw_info->send_queue = NULL; } if ( sw_info->recv_queue != NULL ) { delete_message_queue( sw_info->recv_queue ); sw_info->recv_queue = NULL; } if ( sw_info->secure_channel_fd >= 0 ) { set_readable( switch_info.secure_channel_fd, false ); set_writable( switch_info.secure_channel_fd, false ); delete_fd_handler( switch_info.secure_channel_fd ); close( sw_info->secure_channel_fd ); sw_info->secure_channel_fd = -1; } if ( old_state != SWITCH_STATE_COMPLETED ) { service_send_state( sw_info, &sw_info->datapath_id, MESSENGER_OPENFLOW_FAILD_TO_CONNECT ); } else { // send secure channle disconnect state to application service_send_state( sw_info, &sw_info->datapath_id, MESSENGER_OPENFLOW_DISCONNECTED ); } flush_messenger(); stop_trema(); return 0; }
static void test_periodic_event_callback() { init_timer(); char user_data[] = "It's time!!!"; will_return_count( mock_clock_gettime, 0, -1 ); assert_true( add_periodic_event_callback( 1, mock_timer_event_callback, user_data ) ); timer_callback_info *callback = find_timer_callback( mock_timer_event_callback ); assert_true( callback != NULL ); assert_true( callback->function == mock_timer_event_callback ); assert_string_equal( callback->user_data, "It's time!!!" ); assert_int_equal( callback->interval.tv_sec, 1 ); assert_int_equal( callback->interval.tv_nsec, 0 ); delete_timer_event( mock_timer_event_callback, user_data ); assert_true( find_timer_callback( mock_timer_event_callback ) == NULL ); finalize_timer(); }
static void test_nonexistent_timer_event_callback() { assert_false( delete_timer_event( mock_timer_event_callback, NULL ) ); }
static void management_recv( const messenger_context_handle *handle, uint32_t command, void *data, size_t data_len, void *user_data ) { UNUSED( user_data ); switch ( command ) { case DUMP_XID_TABLE: { dump_xid_table(); } break; case DUMP_COOKIE_TABLE: { if ( !switch_info.cookie_translation ) { break; } dump_cookie_table(); } break; case TOGGLE_COOKIE_AGING: { if ( !switch_info.cookie_translation ) { break; } if ( age_cookie_table_enabled ) { delete_timer_event( age_cookie_table, NULL ); age_cookie_table_enabled = false; } else { add_periodic_event_callback( COOKIE_TABLE_AGING_INTERVAL, age_cookie_table, NULL ); age_cookie_table_enabled = true; } } break; case EVENT_FORWARD_ENTRY_ADD: case EVENT_FORWARD_ENTRY_DELETE: case EVENT_FORWARD_ENTRY_DUMP: case EVENT_FORWARD_ENTRY_SET: { event_forward_operation_request *req = data; req->n_services = ntohl( req->n_services ); management_event_forward_entry_operation( handle, command, req, data_len ); return; } break; default: { error( "Undefined management command ( %#x )", command ); management_application_reply *reply = create_management_application_reply( MANAGEMENT_REQUEST_FAILED, command, NULL, 0 ); send_management_application_reply( handle, reply ); xfree( reply ); return; } } management_application_reply *reply = create_management_application_reply( MANAGEMENT_REQUEST_SUCCEEDED, command, NULL, 0 ); send_management_application_reply( handle, reply ); xfree( reply ); }