Ejemplo n.º 1
0
static void
update_result_all_callback( enum efi_result result, void *user_data ) {
  UNUSED( user_data );
  if ( result == EFI_OPERATION_SUCCEEDED ) {
    info( "Operation Succeeded." );
    stop_trema();
  }
  else {
    error( "Operation Failed." );
    stop_trema();
    exit( EXIT_FAILURE );
  }
}
void
print_with_csv_format( void *param, size_t entries, const topology_link_status *s ) {
  size_t i;

  UNUSED( param );

  debug( "topology: entries %zu", entries );

  list_element *link;
  create_list( &link );

  for ( i = 0; i < entries; i++ ) {
    insert_data( &link, &s[ i ] );
  }

  printf( "f-dpid,f-port,t-dpid,t-port,stat\n" );
  list_element *element;
  for ( element = link; element != NULL; element = element->next ) {
    print_link_status( element->data );
  }

  delete_list( link );

  stop_trema();
}
static void
handle_features_reply( uint64_t datapath_id, uint32_t transaction_id, uint32_t n_buffers, uint8_t n_tables, uint32_t capabilities, uint32_t actions, const list_element *phy_ports, void *user_data) {
  UNUSED( transaction_id );
  UNUSED( n_buffers );
  UNUSED( n_tables );
  UNUSED( capabilities );
  UNUSED( actions );
  show_desc *show_desc = user_data;
  desc_entry *desc = lookup_hash_entry( show_desc->db, &datapath_id );
  if ( desc == NULL ) {
    return;
  }

  display_desc( &desc->desc_stats );
  display_datapath_id( datapath_id );
  list_element ports_list;
  memcpy( &ports_list, phy_ports, sizeof( list_element ) );
  for ( list_element *port = &ports_list; port != NULL; port = port->next ) {
    display_port( port->data );
  }

  delete_hash_entry( show_desc->db, &datapath_id );
  show_desc->count--;
  xfree( desc );

  if ( show_desc->count == 0 ) {
    stop_trema();
  }
}
static void
handle_desc_stats_reply( uint64_t datapath_id, uint32_t transaction_id,
                        uint16_t type, uint16_t flags, const buffer *data,
                       void *user_data ) {
  UNUSED( transaction_id );
  UNUSED( type );
  UNUSED( flags );
  show_desc *show_desc = user_data;

  if ( data->length < SIZE_OF_OFP_DESC ) {
    error( "invalid data" );

    stop_trema();
    return;
  }
  desc_entry *entry = xmalloc( sizeof( desc_entry ) );
  entry->datapath_id = datapath_id;
#ifdef TREMA_EDGE
  create_list( &entry->port_desc );
#endif
  memcpy( &entry->desc_stats, data->data, SIZE_OF_OFP_DESC );
  insert_hash_entry( show_desc->db, &entry->datapath_id, entry );

#ifdef TREMA_EDGE
  buffer *port_desc_request = create_port_desc_multipart_request( get_transaction_id(), 0 );
  send_openflow_message( datapath_id, port_desc_request );
  free_buffer( port_desc_request );
#else
  buffer *features_request = create_features_request( get_transaction_id() );
  send_openflow_message( datapath_id, features_request );
  free_buffer( features_request );
#endif
}
Ejemplo n.º 5
0
static void
timeout( void *user_data ) {
  UNUSED( user_data );

  error( "List switches request timeout." );
  stop_trema();
}
Ejemplo n.º 6
0
static void
stop_switch() {
  if ( switch_info.secure_channel_fd >= 0 ) {
    close( switch_info.secure_channel_fd );
    switch_info.secure_channel_fd = -1;
  }
  uint8_t state = MESSENGER_OPENFLOW_DISCONNECTED;
  if ( switch_info.state == SWITCH_STATE_CONNECTION_FAILED ) {
    state = MESSENGER_OPENFLOW_FAILD_TO_CONNECT;
  }
  service_send_state( &switch_info, &switch_info.datapath_id, state );
  flush_messenger();

  // free service name list
  iterate_list( switch_info.vendor_service_name_list, xfree_data, NULL );
  delete_list( switch_info.vendor_service_name_list );
  switch_info.vendor_service_name_list = NULL;
  iterate_list( switch_info.packetin_service_name_list, xfree_data, NULL );
  delete_list( switch_info.packetin_service_name_list );
  switch_info.packetin_service_name_list = NULL;
  iterate_list( switch_info.portstatus_service_name_list, xfree_data, NULL );
  delete_list( switch_info.portstatus_service_name_list );
  switch_info.portstatus_service_name_list = NULL;
  iterate_list( switch_info.state_service_name_list, xfree_data, NULL );
  delete_list( switch_info.state_service_name_list );
  switch_info.state_service_name_list = NULL;

  stop_trema();
}
Ejemplo n.º 7
0
static void
handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
  UNUSED( user_data );

  assert( tag == MESSENGER_MANAGEMENT_REPLY );
  assert( data != NULL );
  assert( length >= offsetof( management_application_reply, data ) );

  management_application_reply *reply = data;
  assert( ntohs( reply->header.type ) == MANAGEMENT_APPLICATION_REPLY );
  assert( ntohl( reply->header.length ) == length );
  uint32_t id = ntohl( reply->application_id );

  if ( reply->header.status == MANAGEMENT_REQUEST_SUCCEEDED ) {
    printf( "An application specific management command is executed successfully ( application_id = %#x ).\n", id );
  }
  else {
    printf( "Failed to execute an application specific management command ( application_id = %#x ).\n", id );
  }

  size_t data_length = length - offsetof( management_application_reply, data );
  if ( data_length > 0 ) {
    printf( "Data: " );
    for ( size_t i = 0; i < data_length; i++ ) {
      printf( "%02x", reply->data[ i ] );
    }
    printf( "\n" );
  }

  stop_trema();
}
Ejemplo n.º 8
0
static void
timeout( void *user_data ) {
  UNUSED( user_data );

  error( "Request timed out." );
  stop_trema();
  exit( EXIT_FAILURE );
}
Ejemplo n.º 9
0
Archivo: switch.c Proyecto: Darma/trema
static void
handle_sigterm( int signum ) {
  UNUSED( signum );

  if ( !set_external_callback( stop_switch_daemon ) ) {
    stop_trema();
  }
}
static void
timed_out( void *user_data ) {
  UNUSED( user_data );

  error( "timed out." );

  stop_trema();
}
Ejemplo n.º 11
0
static void
timeout( void *user_data ) {
  UNUSED( user_data );

  printf( "Timeout.\n" );

  delete_timer_event( timeout, NULL );

  stop_trema();
}
Ejemplo n.º 12
0
Archivo: utils.c Proyecto: Darma/trema
void
timeout( void *user_data ) {
  handler_data *data = user_data;
  char match_string[ 512 ];
  match_to_string( &data->match, match_string, sizeof( match_string ) );

  error( "Timeout ( match = [%s], service_name = %s, strict = %s ).",
         match_string, data->service_name, data->strict ? "true" : "false" );

  stop_trema();
}
Ejemplo n.º 13
0
static void
send_features_request( uint64_t datapath_id, void *user_data ) {
  UNUSED( user_data );

  buffer *features_request = create_features_request( get_transaction_id() );
  bool ret = send_openflow_message( datapath_id, features_request );
  if ( !ret ) {
    error( "Failed to send a features request message to the switch with datapath ID = %#" PRIx64 ".", datapath_id );
    stop_trema();
  }
  free_buffer( features_request );
}
Ejemplo n.º 14
0
Archivo: list_port.c Proyecto: iqm/apps
static void
print_all_port_status( void *param, size_t entries, const topology_port_status *s ) {
  size_t i;

  UNUSED( param );

  printf( "datapath-id      no    name         ethernet-address  state\n" );
  for ( i = 0; i < entries; i++ ) {
    print_port_status( &s[ i ] );
  }

  stop_trema();
}
Ejemplo n.º 15
0
static void
update_result_callback( event_forward_operation_result result, void *user_data) {
  UNUSED( user_data );

  if ( result.result != EFI_OPERATION_SUCCEEDED ) {
    error( "Operation Failed." );
    stop_trema();
    exit( EXIT_FAILURE );
  }
  else {
    if ( result.n_services == 0 ) {
      info( "Updated service name list is empty.");
    }
    else {
      info( "Updated service name list:" );
      unsigned i;
      for ( i = 0; i < result.n_services; ++i ) {
        info( "  %s", result.services[ i ] );
      }
    }
    stop_trema();
  }
}
Ejemplo n.º 16
0
static void
handle_list_switches_reply( const list_element *switches, void *user_data ) {
  UNUSED( user_data );

  unsigned int num_switch = list_length_of( switches );

  char *list = xmalloc( 20 * num_switch + 1 ); // 20 = dpid string (18 chars) + ", "
  list[ 0 ] = '\0';
  join( list, switches );
  info( "switches = %s", list );
  xfree( list );

  stop_trema();
}
Ejemplo n.º 17
0
Archivo: utils.c Proyecto: Darma/trema
void
add_filter_completed( int status, void *user_data ) {
  handler_data *data = user_data;
  char match_string[ 512 ];
  match_to_string( &data->match, match_string, sizeof( match_string ) );

  if ( status != PACKETIN_FILTER_OPERATION_SUCCEEDED ) {
    error( "Failed to add a packetin filter ( match = [%s], service_name = %s ).",
           match_string, data->service_name );
  }
  info( "A packetin filter was added ( match = [%s], service_name = %s ).",
        match_string, data->service_name );

  stop_trema();
}
Ejemplo n.º 18
0
Archivo: utils.c Proyecto: Darma/trema
void
delete_filter_completed( int status, int n_deleted, void *user_data ) {
  handler_data *data = user_data;
  char match_string[ 512 ];
  match_to_string( &data->match, match_string, sizeof( match_string ) );

  if ( status != PACKETIN_FILTER_OPERATION_SUCCEEDED ) {
    error( "Failed to delete packetin filters ( match = [%s], service_name = %s, strict = %s ).",
           match_string, data->service_name, data->strict ? "true" : "false" );
  }
  info( "%d packetin filter%s deleted ( match = [%s], service_name = %s, strict = %s ).",
        n_deleted, n_deleted > 1 ? "s were" : " was", match_string,
        data->service_name, data->strict ? "true" : "false" );

  stop_trema();
}
Ejemplo n.º 19
0
Archivo: switch.c Proyecto: Darma/trema
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;
}
Ejemplo n.º 20
0
void
print_with_graph_easy_format( void *param, size_t entries, const topology_link_status *s ) {
  size_t i;

  UNUSED( param );

  debug( "topology: entries %d", entries );

  hash_table *link_hash = create_hash( compare_link, hash_link );
  // show_topology graph-easy | graph-easy
  // Graph-Easy:
  //   http://search.cpan.org/~shlomif/Graph-Easy/bin/graph-easy
  printf("#! /usr/bin/env graph-easy\n" );

  for ( i = 0; i < entries; i++ ) {
    if ( s[ i ].status != TD_LINK_UP ) {
      continue;
    }
    topology_link_status r;
    r.from_dpid = s[ i ].to_dpid;
    r.from_portno = s[ i ].to_portno;
    r.to_dpid = s[ i ].from_dpid;
    r.to_portno = s[ i ].from_portno;

    topology_link_status *e = lookup_hash_entry( link_hash, &r );
    if ( e != NULL ) {
      delete_hash_entry( link_hash, e );
      print_link_status( e, true );
    } else {
      insert_hash_entry( link_hash, ( void * ) ( intptr_t ) &s[ i ], ( void *) ( intptr_t ) &s[ i ] );
    }
  }
  hash_iterator iter;
  init_hash_iterator( link_hash, &iter );
  hash_entry *e;
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    topology_link_status *le = e->value;
    print_link_status( le, false );
  }

  delete_hash( link_hash );

  stop_trema();
}
static void
handle_port_desc_reply( uint64_t datapath_id, uint32_t transaction_id,
                        uint16_t type, uint16_t flags, const buffer *data,
                       void *user_data ) {
  UNUSED( transaction_id );
  UNUSED( type );
  UNUSED( flags );
  show_desc *show_desc = user_data;

  desc_entry *desc = lookup_hash_entry( show_desc->db, &datapath_id );
  if ( desc == NULL ) {
    return;
  }
  append_to_tail( &desc->port_desc, duplicate_buffer( data ) );

  if ( more_requests( flags ) ) {
    return;
  }

  display_desc( &desc->desc_stats );
  display_datapath_id( datapath_id );
  for ( list_element *e = desc->port_desc; e != NULL; e = e->next ) {
    buffer *data = e->data;
    struct ofp_port *port = ( struct ofp_port  * ) data->data;
    size_t length = data->length;
    while ( length >= sizeof( struct ofp_port ) ) {
      display_port( port );
      length -= ( uint16_t ) sizeof( struct ofp_port );
      port++;
    }
    free_buffer( e->data );
  }
  delete_list( desc->port_desc );
  delete_hash_entry( show_desc->db, &datapath_id );
  show_desc->count--;
  xfree( desc );

  if ( show_desc->count == 0 ) {
    stop_trema();
  }
}
Ejemplo n.º 22
0
Archivo: utils.c Proyecto: Darma/trema
void
dump_filters( int status, int n_entries, packetin_filter_entry *entries, void *user_data ) {
  handler_data *data = user_data;
  char match_string[ 512 ];
  match_to_string( &data->match, match_string, sizeof( match_string ) );

  if ( status != PACKETIN_FILTER_OPERATION_SUCCEEDED ) {
    error( "Failed to dump packetin filters ( match = [%s], service_name = %s, strict = %s ).",
           match_string, data->service_name, data->strict ? "true" : "false" );
  }
  info( "%d packetin filter%s found ( match = [%s], service_name = %s, strict = %s ).",
        n_entries, n_entries > 1 ? "s" : "", match_string, data->service_name,
        data->strict ? "true" : "false" );
  for ( int i = 0; i < n_entries; i++ ) {
    match_to_string( &entries[ i ].match, match_string, sizeof( match_string ) );
    info( "[#%d] match = [%s], priority = %u, service_name = %s.",
          i, match_string, entries[ i ].priority, entries[ i ].service_name );
  }

  stop_trema();
}
Ejemplo n.º 23
0
static void
handle_features_reply (
  uint64_t datapath_id,
  uint32_t transaction_id,
  uint32_t n_buffers,
  uint8_t n_tables,
  uint32_t capabilities,
  uint32_t actions,
  const list_element *phy_ports,
  void *user_data
) {
  UNUSED( user_data );

  info( "datapath_id: %#" PRIx64, datapath_id );
  info( "transaction_id: %#lx", transaction_id );
  info( "n_buffers: %lu", n_buffers );
  info( "n_tables: %u", n_tables );
  info( "capabilities: %lu", capabilities );
  info( "actions: %lu", actions );
  info( "#ports: %d", list_length_of( phy_ports ) );

  stop_trema();
}
Ejemplo n.º 24
0
static void
timeout( void *user_data ) {
  UNUSED( user_data );

  stop_trema();
}
Ejemplo n.º 25
0
/*
 * @overload shutdown!
 *   In the context of trema framework stops this controller and its applications.
 */
static VALUE
controller_shutdown( VALUE self ) {
  stop_trema();
  return self;
}