static void echo_reply_timeout( void *user_data ) { UNUSED( user_data ); error( "Echo request timeout ( datapath id %#" PRIx64 ").", switch_info.datapath_id ); switch_event_disconnected( &switch_info ); }
int switch_event_disconnect_request( uint64_t *datapath_id ) { if ( *datapath_id != switch_info.datapath_id ) { error( "Invalid datapath id %#" PRIx64 ".", *datapath_id ); return -1; } return switch_event_disconnected( &switch_info ); }
static void registration_timeout( void *user_data ) { struct switch_info *sw_info = user_data; sw_info->running_timer = false; error( "Registration timeout ( datapath id %#" PRIx64 " ).", sw_info->datapath_id ); switch_event_disconnected( sw_info ); }
static void secure_channel_write( int fd, void* data ) { UNUSED( fd ); UNUSED( data ); if ( flush_secure_channel( &switch_info ) < 0 ) { switch_event_disconnected( &switch_info ); return; } }
static void registration_retry( void *user_data ) { struct switch_info *sw_info = user_data; if ( sw_info->retry_count == 0 ) { switch_event_disconnected( sw_info ); return; } sw_info->retry_count--; sw_info->running_timer = false; debug( "Checking switch manager's switch list." ); set_list_switches_reply_handler( confirm_self_dpid_is_registered ); if ( send_list_switches_request( sw_info ) ) { switch_set_timeout( REGISTRATION_TIMEOUT, registration_timeout, sw_info ); } else { error( "Failed to send switch list request to switch manager." ); switch_event_disconnected( sw_info ); } }
static void secure_channel_fd_isset( fd_set *read_set, fd_set *write_set ) { if ( switch_info.secure_channel_fd < 0 ) { return; } if ( FD_ISSET( switch_info.secure_channel_fd, read_set ) ) { if ( recv_from_secure_channel( &switch_info ) < 0 ) { switch_event_disconnected( &switch_info ); return; } } if ( FD_ISSET( switch_info.secure_channel_fd, write_set ) ) { if ( flush_secure_channel( &switch_info ) < 0 ) { switch_event_disconnected( &switch_info ); return; } } if ( switch_info.recv_queue->length > 0 ) { handle_messages_from_secure_channel( &switch_info ); } }
static void switch_event_timeout_features_reply( void *user_data ) { UNUSED( user_data ); if ( switch_info.state != SWITCH_STATE_WAIT_FEATURES_REPLY ) { return; } switch_info.running_timer = false; error( "Features Reply timeout. state:%d, dpid:%#" PRIx64 ", fd:%d.", switch_info.state, switch_info.datapath_id, switch_info.secure_channel_fd ); switch_event_disconnected( &switch_info ); }
static void switch_event_timeout_hello( void *user_data ) { UNUSED( user_data ); if ( switch_info.state != SWITCH_STATE_WAIT_HELLO ) { return; } switch_info.running_timer = false; error( "Hello timeout. state:%d, dpid:%#" PRIx64 ", fd:%d.", switch_info.state, switch_info.datapath_id, switch_info.secure_channel_fd ); switch_event_disconnected( &switch_info ); }
static void switch_event_timeout_hello( void *user_data ) { UNUSED( user_data ); if ( switch_info.state != SWITCH_STATE_WAIT_HELLO ) { return; } // delete to hello_wait-timeout timer switch_unset_timeout( switch_event_timeout_hello ); error( "Hello timeout. state:%d, dpid:%#" PRIx64 ", fd:%d.", switch_info.state, switch_info.datapath_id, switch_info.secure_channel_fd ); switch_event_disconnected( &switch_info ); }
static void secure_channel_read( int fd, void* data ) { UNUSED( fd ); UNUSED( data ); if ( recv_from_secure_channel( &switch_info ) < 0 ) { switch_event_disconnected( &switch_info ); return; } if ( switch_info.recv_queue->length > 0 ) { int ret = handle_messages_from_secure_channel( &switch_info ); if ( ret < 0 ) { stop_event_handler(); stop_messenger(); } } }
static void echo_request_interval( void *user_data ) { struct switch_info *sw_info = user_data; buffer *buf = alloc_buffer(); echo_body *body = append_back_buffer( buf, sizeof( echo_body ) ); body->datapath_id = htonll( switch_info.datapath_id ); struct timespec now; clock_gettime( CLOCK_MONOTONIC, &now ); body->sec = htonl( ( uint32_t ) now.tv_sec ); body->nsec = htonl( ( uint32_t ) now.tv_nsec ); sw_info->echo_request_xid = generate_xid(); int err = ofpmsg_send_echorequest( sw_info, sw_info->echo_request_xid, buf ); if ( err < 0 ) { switch_event_disconnected( &switch_info ); return; } switch_set_timeout( ECHO_REPLY_TIMEOUT, echo_reply_timeout, NULL ); }
static void stop_switch_daemon( void ) { switch_event_disconnected( &switch_info ); }