Пример #1
0
bool
init_management_interface() {
  if ( initialized ) {
    error( "Management interface is already initialized." );
    return false;
  }

  add_message_requested_callback( get_management_service_name( get_trema_name() ), handle_request );

  initialized = true;

  debug( "Management interface is initialized ( trema_name = %s, service_name = %s ).",
         get_trema_name(), get_management_service_name( get_trema_name() ) );

  return true;
}
Пример #2
0
static void
parse_arguments( int argc, char **argv ) {
  assert( argv != NULL );

  if ( argc < 3 || argc > 4 ) {
    print_usage_and_exit();
  }

  if ( argv[ 1 ] == NULL || ( argv[ 1 ] != NULL && strlen( argv[ 1 ] ) == 0 ) ) {
    print_usage_and_exit();
  }

  if ( argv[ 2 ] == NULL ) {
    print_usage_and_exit();
  }

  memset( service_name, '\0', MESSENGER_SERVICE_NAME_LENGTH );
  snprintf( service_name, MESSENGER_SERVICE_NAME_LENGTH, "%s", get_management_service_name( argv[ 1 ] ) );

  char *endp = NULL;
  application_id = ( uint32_t ) strtoul( argv[ 2 ], &endp, 0 );
  if ( *endp != '\0' ) {
    print_usage_and_exit();
  }

  if ( argc >= 4 && argv[ 3 ] != NULL ) {
    hex_string_to_data( argv[ 3 ] );
    if ( data == NULL ) {
      print_usage_and_exit();
    }
  }
}
Пример #3
0
bool
finalize_management_interface() {
  if ( !initialized ) {
    error( "Management interface is not initialized yet or already finalized." );
    return false;
  }

  delete_message_requested_callback( get_management_service_name( get_trema_name() ), handle_request );

  initialized = false;

  debug( "Management interface is finalized ( trema_name = %s ).", get_trema_name() );

  return true;
}
Пример #4
0
int
switch_event_recv_featuresreply( struct switch_info *sw_info, uint64_t *dpid ) {
  int ret;
  char new_service_name[ SWITCH_MANAGER_PREFIX_STR_LEN + SWITCH_MANAGER_DPID_STR_LEN + 1 ];
  const uint16_t new_service_name_len = SWITCH_MANAGER_PREFIX_STR_LEN + SWITCH_MANAGER_DPID_STR_LEN + 1;

  switch ( sw_info->state ) {
  case SWITCH_STATE_WAIT_FEATURES_REPLY:

    sw_info->datapath_id = *dpid;
    sw_info->state = SWITCH_STATE_WAIT_REGISTRATION;

    // cancel to features_reply_wait-timeout timer
    switch_unset_timeout( switch_event_timeout_features_reply, NULL );

    // TODO: set keepalive-timeout
    snprintf( new_service_name, new_service_name_len, "%s%#" PRIx64, SWITCH_MANAGER_PREFIX, sw_info->datapath_id );

    // checking duplicate service
    pid_t pid = get_pid_by_trema_name( new_service_name );
    if ( pid > 0 ) {
      debug( "duplicated datapath-id %#" PRIx64, sw_info->datapath_id );
      if ( !terminate_trema_process( pid ) ) {
        return -1;
      }
    }
    // rename service_name of messenger
    rename_message_received_callback( get_trema_name(), new_service_name );

    // rename management service name
    char *management_service_name = xstrdup( get_management_service_name( get_trema_name() ) );
    char *new_management_service_name = xstrdup( get_management_service_name( new_service_name ) );
    rename_message_requested_callback( management_service_name, new_management_service_name );
    xfree( management_service_name );
    xfree( new_management_service_name );

    debug( "Rename service name from %s to %s.", get_trema_name(), new_service_name );
    if ( messenger_dump_enabled() ) {
      stop_messenger_dump();
      start_messenger_dump( new_service_name, DEFAULT_DUMP_SERVICE_NAME );
    }
    set_trema_name( new_service_name );

    // reset to default config
    ret = ofpmsg_send_setconfig( sw_info );
    if ( ret < 0 ) {
      error( "Failed to send setconfig." );
      return ret;
    }
    if ( switch_info.flow_cleanup ) {
      debug( "Deleting all flows." );
      ret = ofpmsg_send_delete_all_flows( sw_info );
      if ( ret < 0 ) {
        error( "Failed to send delete all flows." );
        return ret;
      }
    }

    // switch_ready to switch_manager
    debug( "Notify switch_ready to switch manager." );
    char switch_manager[] =  SWITCH_MANAGER;
    list_element switch_manager_only_list;
    switch_manager_only_list.next = NULL;
    switch_manager_only_list.data = switch_manager;
    service_send_to_application( &switch_manager_only_list, MESSENGER_OPENFLOW_READY, &sw_info->datapath_id, NULL );

    init_event_forward_interface();
    // Check switch_manager registration
    debug( "Checking switch manager's switch list." );
    sw_info->retry_count = REGISTRATION_RETRY_COUNT;
    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." );
      return -1;
    }
    break;

  case SWITCH_STATE_WAIT_REGISTRATION:
  case SWITCH_STATE_COMPLETED:
    // NOP
    break;

  default:
    notice( "Invalid event 'features reply' from a switch." );
    return -1;

    break;
  }

  return 0;
}