Esempio n. 1
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  add_periodic_event_callback( 30, timeout, NULL );

  add_periodic_event_callback( 2, ( void ( * )( void * ) ) send_list_switches_request, NULL );
  set_list_switches_reply_handler( handle_list_switches_reply );

  start_trema();
}
static void
http_transaction_completed( int status, int code, const http_content *content, void *user_data ) {
  debug( "A HTTP transaction completed ( status = %d, code = %d, content = %p, user_data = %p ).",
         status, code, content, user_data );

  assert( user_data != NULL );

  transaction_entry *entry = user_data;

  entry->n_ongoing_http_requests--;

  if ( status == HTTP_TRANSACTION_FAILED ) {
    if ( !( ( entry->operation == OPERATION_ATTACH ) && ( code == 440 ) ) &&   // 440: Specified TEP has already been added.
         !( ( entry->operation == OPERATION_DETACH ) && ( code == 404 ) ) ) {  // 404: Already deleted.
      error( "HTTP transaction failed ( vni = %#x, datapath_id = %#" PRIx64 ", operation = %#x, port_wait_count = %d, "
             "n_ongoing_http_requests = %u, n_failed_http_requests = %u, status = %d, code = %d ).",
             entry->vni, entry->datapath_id, entry->operation, entry->port_wait_count,
             entry->n_ongoing_http_requests, entry->n_failed_http_requests, status, code );
      entry->n_failed_http_requests++;
    }
  }

  if ( entry->n_ongoing_http_requests > 0 ) {
    return;
  }

  assert( entry->n_ongoing_http_requests == 0 );

  if ( entry->n_failed_http_requests == 0 ) {
    if ( entry->callback != NULL ) {
      if ( entry->operation == OPERATION_ATTACH ) {
        add_periodic_event_callback( 1, wait_for_port_to_be_added, entry );
        return;
      }
      else if ( entry->operation == OPERATION_DETACH ) {
        add_periodic_event_callback( 1, wait_for_port_to_be_deleted, entry );
        return;
      }
    }
  }
  else {
    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_transaction( entry->datapath_id, entry->vni );
}
Esempio n. 3
0
static void
confirm_self_dpid_is_registered( const list_element *switches, void *user_data ) {
  struct switch_info *sw_info = user_data;

  switch_unset_timeout( registration_timeout, sw_info );

  debug( "Received switch manager's switch list." );
  bool found = false;
  for ( const list_element *e = switches; e != NULL; e = e->next ) {
    if ( sw_info->datapath_id == *( uint64_t * ) e->data ) {
      // self dpid registered
      debug( "Self dpid found" );
      found = true;
      break;
    }
  }
  if ( found ) {
    sw_info->state = SWITCH_STATE_COMPLETED;

    finalize_openflow_application_interface();

    // notify state and datapath_id to controllers
    service_send_state( sw_info, &sw_info->datapath_id, MESSENGER_OPENFLOW_READY );
    debug( "send ready state" );

    add_periodic_event_callback( ECHO_REQUEST_INTERVAL, echo_request_interval, sw_info );
  }
  else {
    debug( "Self dpid not found. Retrying..." );
    switch_set_timeout( REGISTRATION_RETRY, registration_retry, sw_info );
  }
}
Esempio n. 4
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  add_periodic_event_callback( 1, send_request, NULL );
  add_message_replied_callback( get_trema_name(), recv_reply );
  start_trema();
}
Esempio n. 5
0
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_periodic_event_callback( age_cookie_table );
      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 );
  }
}
Esempio n. 6
0
int
main( int argc, char *argv[] ) {
  // Initialize the Trema world
  init_trema( &argc, &argv );

  // =============================== Monitoring Manager ===============================
  /* Setup a timer to send request for querying port loading */
  add_periodic_event_callback( 10, send_my_port_loading_request, NULL );
  /* Setup a handler for the reply of query port loading  */
  add_callback_port_loading_requested( handle_port_loading_reply, NULL );
  /* Subscribe the port and flow notification */
  add_callback_port_loading_notified( alert_port_loading, NULL );
  add_callback_flow_loading_notified( alert_flow_loading, NULL );
  
  init_monitoring();
  send_monitoring_subscribe_request();
  // =============================== Monitoring Manager ===============================
  
  // Main loop
  start_trema();

  // Finalize monitoring
  finalize_monitoring();

  return 0;
}
Esempio n. 7
0
static void
add_filter( void ) {
  struct ofp_match match;
  memset( &match, 0, sizeof( struct ofp_match ) );
  match.wildcards = OFPFW_DL_SRC | OFPFW_DL_DST;
  match.in_port = 1;
  match.dl_type = 0x0800;
  match.dl_vlan = 0xffff;
  match.dl_vlan_pcp = 0;
  match.nw_src = 0x0a000001;
  match.nw_dst = 0x0a000002;
  match.nw_tos = 0;
  match.nw_proto = 0x0a;
  match.tp_src = 1024;
  match.tp_dst = 2048;

  static handler_data data;
  data.match = match;
  snprintf( data.service_name, sizeof( data.service_name ), "dumper" );
  data.service_name[ sizeof( data.service_name ) - 1 ] = '\0';

  bool ret = add_packetin_filter( data.match, UINT16_MAX, data.service_name, add_filter_completed, &data );
  if ( ret == false ) {
    error( "Failed to add a packetin filter ( ret = %d ).", ret );
  }
  else {
    add_periodic_event_callback( 5, timeout, &data );
  }
}
Esempio n. 8
0
static void
dump_filter_strict( void ) {
  oxm_matches *match = create_oxm_matches();
  append_oxm_match_in_port( match, 1 );
  append_oxm_match_eth_type( match, 0x0800 );
  append_oxm_match_vlan_vid( match, 0, 0 );
  append_oxm_match_ipv4_src( match, 0x0a000001, 0 );
  append_oxm_match_ipv4_dst( match, 0x0a000002, 0 );
  append_oxm_match_ip_dscp( match, 0 );
  append_oxm_match_ip_ecn( match, 0 );
  append_oxm_match_ip_proto( match, 0x6 );
  append_oxm_match_tcp_src( match, 1024 );
  append_oxm_match_tcp_dst( match, 2048 );

  static handler_data data;
  data.match = match;
  snprintf( data.service_name, sizeof( data.service_name ), "dumper" );
  data.service_name[ sizeof( data.service_name ) - 1 ] = '\0';
  data.strict = true;

  bool ret = dump_packetin_filter( data.match, OFP_HIGH_PRIORITY, data.service_name, data.strict,
                                   dump_filters, &data );
  if ( ret == false ) {
    error( "Failed to dump packetin filters ( ret = %d ).", ret );
  }
  else {
    add_periodic_event_callback( 5, timeout, &data );
  }
}
Esempio n. 9
0
static void
test_clock_gettime_fail_einval() {
  init_timer();

  char user_data[] = "It's time!!!";
  will_return_count( mock_clock_gettime, -1, -1 );
  assert_false( add_periodic_event_callback( 1, mock_timer_event_callback, user_data ) );

  finalize_timer();
}
Esempio n. 10
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  hash_table *forwarding_db = create_hash( compare_forwarding_entry, hash_forwarding_entry );
  add_periodic_event_callback( AGING_INTERVAL, update_forwarding_db, forwarding_db );
  set_packet_in_handler( handle_packet_in, forwarding_db );

  start_trema();

  return 0;
}
Esempio n. 11
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  init_packetin_filter_interface();

  add_periodic_event_callback( 5, timeout, NULL );

  add_filter();

  start_trema();

  finalize_packetin_filter_interface();
}
Esempio n. 12
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  hash_table *switch_db = create_hash( compare_datapath_id, hash_datapath_id );
  add_periodic_event_callback( AGING_INTERVAL, update_all_switches, switch_db );
  set_switch_ready_handler( handle_switch_ready, switch_db );
  set_switch_disconnected_handler( handle_switch_disconnected, switch_db );
  set_packet_in_handler( handle_packet_in, switch_db );

  start_trema();

  return 0;
}
Esempio n. 13
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  parse_argument( argc, argv );

  init_event_forward_interface();

  send_efi_request();

  add_periodic_event_callback( 30, timeout, NULL );

  start_trema();

  finalize_event_forward_interface();

  return 0;
}
Esempio n. 14
0
static void
dump_filter( void ) {
  oxm_matches *match = create_oxm_matches();

  static handler_data data;
  data.match = match;
  snprintf( data.service_name, sizeof( data.service_name ), "dumper" );
  data.service_name[ sizeof( data.service_name ) - 1 ] = '\0';
  data.strict = false;

  bool ret = dump_packetin_filter( data.match, UINT16_MAX, data.service_name, data.strict,
                                   dump_filters, &data );
  if ( ret == false ) {
    error( "Failed to dump packetin filters ( ret = %d ).", ret );
  }
  else {
    add_periodic_event_callback( 5, timeout, &data );
  }
}
Esempio n. 15
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  traffic db;
  db.counter = create_counter();
  db.fdb = create_fdb();

  add_periodic_event_callback( 10, show_counter, &db );

  set_packet_in_handler( handle_packet_in, &db );
  set_flow_removed_handler( handle_flow_removed, &db );

  start_trema();

  delete_fdb( db.fdb );
  delete_counter( db.counter );

  return 0;
}
Esempio n. 16
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();
}
Esempio n. 17
0
bool
init_redirector() {
  if ( !init_tun( TUN_INTERFACE ) ) {
    error( "Cannot create a tun interface." );
    return false;
  }

  if ( host_db != NULL ) {
    error( "Host database is already created." );
    return false;
  }

  host_db = create_hash( compare_ip_address, hash_ip_address );

  set_fd_handler( fd, read_tun_fd, NULL, NULL, NULL );
  set_readable( fd, true );

  add_periodic_event_callback( HOST_DB_AGING_INTERVAL, age_host_db, NULL );

  return true;
}
Esempio n. 18
0
static void
delete_filter( void ) {
  struct ofp_match match;
  memset( &match, 0, sizeof( struct ofp_match ) );
  match.wildcards = OFPFW_ALL;

  static handler_data data;
  data.match = match;
  snprintf( data.service_name, sizeof( data.service_name ), "dumper" );
  data.service_name[ sizeof( data.service_name ) - 1 ] = '\0';
  data.strict = false;

  bool ret = delete_packetin_filter( data.match, UINT16_MAX, data.service_name, data.strict,
                                     delete_filter_completed, &data );
  if ( ret == false ) {
    error( "Failed to delete a packetin filter ( ret = %d ).", ret );
  }
  else {
    add_periodic_event_callback( 5, timeout, &data );
  }
}
Esempio n. 19
0
int
main( int argc, char *argv[] ) {
  // Initialize the Trema world
  init_trema( &argc, &argv );

  // Parse arguments
  parse_arguments( argc, argv );

  // Set a handler to handle application specific management reply
  add_message_replied_callback( get_trema_name(), handle_reply );

  // Send an application specific management request
  send_application_request();

  // Set timeout
  add_periodic_event_callback( 5, timeout, NULL );

  // Main loop
  start_trema();

  return EXIT_SUCCESS;
}
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  show_desc show_desc;
  show_desc.db = create_hash( compare_datapath_id, hash_datapath_id );
  show_desc.count = 0;

  set_list_switches_reply_handler( handle_list_switches_reply );
#ifdef TREMA_EDGE
  set_multipart_reply_handler( handle_stats_reply, &show_desc );
#else
  set_stats_reply_handler( handle_stats_reply, &show_desc );
  set_features_reply_handler( handle_features_reply, &show_desc );
#endif
  add_periodic_event_callback( 10, timed_out, NULL );

  send_list_switches_request( &show_desc );


  start_trema();

  return 0;
}
Esempio n. 21
0
File: switch.c Progetto: Darma/trema
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_COMPLETED;

    // 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_trema_process_from_name( new_service_name );
    if ( pid > 0 ) {
      // duplicated
      if ( !terminate_trema_process( pid ) ) {
        return -1;
      }
    }
    // rename service_name of messenger
    rename_message_received_callback( get_trema_name(), new_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 );

    // notify state and datapath_id
    service_send_state( sw_info, &sw_info->datapath_id, MESSENGER_OPENFLOW_READY );
    debug( "send ready state" );

    ret = ofpmsg_send_setconfig( sw_info );
    if ( ret < 0 ) {
      return ret;
    }
    if ( switch_info.flow_cleanup ) {
      ret = ofpmsg_send_delete_all_flows( sw_info );
      if ( ret < 0 ) {
        return ret;
      }
    }
    add_periodic_event_callback( ECHO_REQUEST_INTERVAL, echo_request_interval, sw_info );
    break;

  case SWITCH_STATE_COMPLETED:
    // NOP
    break;

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

    break;
  }

  return 0;
}
Esempio n. 22
0
File: fdb.c Progetto: mq24705/apps
void
init_age_fdb( hash_table *fdb ) {
    assert( fdb != NULL );
    add_periodic_event_callback( FDB_AGING_INTERVAL, age_fdb, fdb );
}
Esempio n. 23
0
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 );
}