コード例 #1
0
int
main( int argc, char *argv[] ) {
  // Check if this application runs with root privilege
  if ( geteuid() != 0 ) {
    printf( "Sliceable switch must be run with root privilege.\n" );
    exit( EXIT_FAILURE );
  }

  // Initialize Trema world
  init_trema( &argc, &argv );
  // Init path management library (libpath)
  init_path();
  switch_options options;
  init_switch_options( &options, &argc, &argv );
  init_topology_service_interface_options( &argc, &argv );

  // Initialize sliceable_switch
  sliceable_switch *sliceable_switch = create_sliceable_switch( get_topology_service_interface_name(), &options );

  // Main loop
  start_trema();

  // Finalize sliceable_switch
  delete_sliceable_switch( sliceable_switch );
  // Finalize path management library (libpath)
  finalize_path();

  return 0;
}
コード例 #2
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;
}
コード例 #3
0
ファイル: repeater_hub.c プロジェクト: Milstein/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  set_packet_in_handler( handle_packet_in, NULL );
  start_trema();
  return 0;
}
コード例 #4
0
int
main( int argc, char *argv[] ) {
  // Check if this application runs with root privilege
  if ( geteuid() != 0 ) {
    printf( "Redirectable routing switch must be run with root privilege.\n" );
    exit( EXIT_FAILURE );
  }

  // Initialize Trema world
  init_trema( &argc, &argv );
  routing_switch_options options;
  init_routing_switch_options( &options, &argc, &argv );
  init_topology_service_interface_options( &argc, &argv );

  // Initialize routing_switch
  routing_switch *routing_switch = create_routing_switch( get_topology_service_interface_name(), &options );

  // Main loop
  start_trema();

  // Finalize routing_switch
  delete_routing_switch( routing_switch );

  return 0;
}
コード例 #5
0
ファイル: list_switches.c プロジェクト: n-tada/trema
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();
}
コード例 #6
0
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  dump_filter_strict();

  start_trema();
}
コード例 #7
0
ファイル: add_filter.c プロジェクト: Milstein/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  add_filter();

  start_trema();
}
コード例 #8
0
ファイル: list_switches.c プロジェクト: Milstein/trema
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();
}
コード例 #9
0
ファイル: features_request.c プロジェクト: Epictetus/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  set_switch_ready_handler( send_features_request, NULL );
  set_features_reply_handler( handle_features_reply, NULL );

  start_trema();

  return 0;
}
コード例 #10
0
ファイル: learning_switch.c プロジェクト: Milstein/trema
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;
}
コード例 #11
0
ファイル: switch_manager.c プロジェクト: TakumiKomada/trema
int
main( int argc, char *argv[] ) {
  bool ret;
  const char *switch_daemon = NULL;
  char *startup_dir;

  // get startup directory using absolute_path()
  startup_dir = get_current_dir_name();
  if ( startup_dir == NULL ) {
    die( "Failed to get_current_dir_name." );
  }

  init_trema( &argc, &argv ); // changes the current working directory

  init_listener_info( &listener_info );
  ret = parse_argument( &listener_info, argc, argv );
  if ( !ret ) {
    finalize_listener_info( &listener_info );
    exit( EXIT_FAILURE );
  }

  init_dpid_table();
  start_service_management();
  start_switch_management();

  switch_daemon = listener_info.switch_daemon;
  listener_info.switch_daemon = absolute_path( startup_dir, switch_daemon );
  xfree( ( void * ) ( uintptr_t ) switch_daemon );
  // free returned buffer of get_current_dir_name()
  free( startup_dir );

  catch_sigchild();

  // listener start (listen socket binding and listen)
  ret = secure_channel_listen_start( &listener_info );
  if ( !ret ) {
    finalize_listener_info( &listener_info );
    exit( EXIT_FAILURE );
  }

  set_fd_handler( listener_info.listen_fd, secure_channel_accept, &listener_info, NULL, NULL );
  set_readable( listener_info.listen_fd, true );

  start_trema();

  finalize_listener_info( &listener_info );
  stop_switch_management();
  stop_service_management();
  finalize_dpid_table();

  return 0;
}
コード例 #12
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();
}
コード例 #13
0
ファイル: controller.c プロジェクト: aigamo/trema
/*
 * In the context of trema framework invokes the scheduler to start its applications.
 */
static VALUE
controller_start_trema( VALUE self ) {
  struct itimerspec interval;
  interval.it_interval.tv_sec = 0;
  interval.it_interval.tv_nsec = 1000000;
  interval.it_value.tv_sec = 0;
  interval.it_value.tv_nsec = 0;
  add_timer_event_callback( &interval, thread_pass, NULL );

  start_trema();

  return self;
}
コード例 #14
0
ファイル: stdin_relay.c プロジェクト: axsh/trema-edge
int
main( int argc, char *argv[] ) {
  // Initialize the Trema world
  init_trema( &argc, &argv );
  init_stdin_relay( &argc, &argv );

  // Main loop
  start_trema();

  // Cleanup
  finalize_stdin_relay();

  return 0;
}
コード例 #15
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;
}
コード例 #16
0
ファイル: list_port.c プロジェクト: n-tada/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );
  init_topology_service_interface_options( &argc, &argv );
  init_libtopology( get_topology_service_interface_name() );

  get_all_port_status( print_all_port_status, NULL);
  start_trema();

  finalize_libtopology();
  finalize_topology_service_interface_options();

  return 0;
}
コード例 #17
0
ファイル: packetin_dispatcher.c プロジェクト: iqm/apps
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  services services;
  if ( !set_match_type( argc, argv, &services ) ) {
    usage();
    exit( EXIT_FAILURE );
  }

  set_packet_in_handler( handle_packet_in, &services );

  start_trema();

  return 0;
}
コード例 #18
0
ファイル: echo_request.c プロジェクト: axsh/trema-edge
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  if ( argc < 2 ) {
    usage();
    return -1;
  }

  int count = atoi( argv[ 1 ] );
  set_switch_ready_handler( send_echo_requests, &count );

  start_trema();

  return 0;
}
コード例 #19
0
ファイル: broadcast_helper.c プロジェクト: sunguoqiang/apps
int
main( int argc, char *argv[] ) {
  // Initialize Trema world
  init_trema( &argc, &argv );
  init_topology_service_interface_options( &argc, &argv );

  // Initialize broadcast_helper
  broadcast_helper *broadcast_helper = create_broadcast_helper( get_topology_service_interface_name() );

  // Main loop
  start_trema();

  // Finalize broadcast_helper
  delete_broadcast_helper( broadcast_helper );

  return 0;
}
コード例 #20
0
ファイル: delete_forward_entry.c プロジェクト: Milstein/trema
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;
}
コード例 #21
0
ファイル: packet_capture.c プロジェクト: Darma/trema
int
main( int argc, char *argv[] ) {
  // Initialize the Trema world
  init_trema( &argc, &argv );
  init_packet_capture( &argc, &argv );

  // Start packet capture
  start_packet_capture();

  // Main loop
  start_trema();

  // Cleanup
  stop_packet_capture();
  finalize_packet_capture();

  return 0;
}
コード例 #22
0
ファイル: routing_switch.c プロジェクト: sun-lei/trema
int
main( int argc, char *argv[] ) {
  // Initialize Trema world
  init_trema( &argc, &argv );
  routing_switch_options options;
  init_routing_switch_options( &options, &argc, &argv );
  init_topology_service_interface_options( &argc, &argv );

  // Initialize routing_switch
  routing_switch *routing_switch = create_routing_switch( get_topology_service_interface_name(), &options );

  // Main loop
  start_trema();

  // Finalize routing_switch
  delete_routing_switch( routing_switch );

  return 0;
}
コード例 #23
0
ファイル: traffic_monitor.c プロジェクト: Darma/trema
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;
}
コード例 #24
0
ファイル: packetin_filter.c プロジェクト: n-tada/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  init_match_table();

  // built-in packetin-filter-rule
  if ( !set_match_type( argc, argv ) ) {
    usage();
    finalize_match_table();
    exit( EXIT_FAILURE );
  }

  set_packet_in_handler( handle_packet_in, NULL );

  start_trema();

  finalize_match_table();

  return 0;
}
コード例 #25
0
ファイル: application.c プロジェクト: TakumiKomada/trema
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;
}
コード例 #26
0
ファイル: packetin_filter.c プロジェクト: Milstein/trema
int
main( int argc, char *argv[] ) {
  init_trema( &argc, &argv );

  init_packetin_match_table();

  // built-in packetin-filter-rule
  if ( !set_match_type( argc, argv ) ) {
    usage();
    finalize_packetin_match_table();
    exit( EXIT_FAILURE );
  }

  set_packet_in_handler( handle_packet_in, NULL );
  add_message_requested_callback( PACKETIN_FILTER_MANAGEMENT_SERVICE, handle_request );

  start_trema();

  finalize_packetin_match_table();

  return 0;
}
コード例 #27
0
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;
}
コード例 #28
0
ファイル: switch.c プロジェクト: Darma/trema
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;
  char management_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  // FIXME
#define VENDER_PREFIX "vendor::"
#define PACKET_IN_PREFIX "packet_in::"
#define PORTSTATUS_PREFIX "port_status::"
#define STATE_PREFIX "state_notify::"
  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[i], VENDER_PREFIX, strlen( VENDER_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( VENDER_PREFIX ) );
      insert_in_front( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PACKET_IN_PREFIX ) );
      insert_in_front( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PORTSTATUS_PREFIX ) );
      insert_in_front( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( STATE_PREFIX ) );
      insert_in_front( &switch_info.state_service_name_list, service_name );
    }
  }

  struct sigaction signal_exit;
  memset( &signal_exit, 0, sizeof( struct sigaction ) );
  signal_exit.sa_handler = handle_sigterm;
  sigaction( SIGINT, &signal_exit, NULL );
  sigaction( SIGTERM, &signal_exit, NULL );

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );

  set_fd_handler( switch_info.secure_channel_fd, secure_channel_read, NULL, secure_channel_write, NULL );
  set_readable( switch_info.secure_channel_fd, true );
  set_writable( switch_info.secure_channel_fd, false );

  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();
  switch_info.running_timer = false;
  switch_info.echo_request_xid = 0;

  init_xid_table();
  if ( switch_info.cookie_translation ) {
    init_cookie_table();
  }

  add_message_received_callback( get_trema_name(), service_recv );

  snprintf( management_service_name , MESSENGER_SERVICE_NAME_LENGTH,
            "%s.m", get_trema_name() );
  management_service_name[ MESSENGER_SERVICE_NAME_LENGTH - 1 ] = '\0';
  add_message_received_callback( management_service_name, management_recv );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }
  flush_secure_channel( &switch_info );

  start_trema();

  finalize_xid_table();
  if ( switch_info.cookie_translation ) {
    finalize_cookie_table();
  }

  if ( switch_info.secure_channel_fd >= 0 ) {
    delete_fd_handler( switch_info.secure_channel_fd );
  }

  return 0;
}
コード例 #29
0
ファイル: switch.c プロジェクト: Milstein/trema
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[ i ], VENDOR_PREFIX, strlen( VENDOR_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( VENDOR_PREFIX ) );
      append_to_tail( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( PACKET_IN_PREFIX ) );
      append_to_tail( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( PORTSTATUS_PREFIX ) );
      append_to_tail( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( STATE_PREFIX ) );
      append_to_tail( &switch_info.state_service_name_list, service_name );
    }
  }

  struct sigaction signal_exit;
  memset( &signal_exit, 0, sizeof( struct sigaction ) );
  signal_exit.sa_handler = handle_sigterm;
  sigaction( SIGINT, &signal_exit, NULL );
  sigaction( SIGTERM, &signal_exit, NULL );

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );

  set_fd_handler( switch_info.secure_channel_fd, secure_channel_read, NULL, secure_channel_write, NULL );
  set_readable( switch_info.secure_channel_fd, true );
  set_writable( switch_info.secure_channel_fd, false );

  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();
  switch_info.running_timer = false;
  switch_info.echo_request_xid = 0;

  init_xid_table();
  if ( switch_info.cookie_translation ) {
    init_cookie_table();
  }

  add_message_received_callback( get_trema_name(), service_recv );
  set_management_application_request_handler( management_recv, NULL );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }
  ret = flush_secure_channel( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to flush secure channel. Terminating %s.", argv[ 0 ] );
    return -1;
  }

  start_trema();

  // Note: init_event_forward_interface will be called on feature_reply.
  finalize_event_forward_interface();

  finalize_xid_table();
  if ( switch_info.cookie_translation ) {
    finalize_cookie_table();
  }

  if ( switch_info.secure_channel_fd >= 0 ) {
    delete_fd_handler( switch_info.secure_channel_fd );
  }

  return 0;
}
コード例 #30
0
ファイル: switch.c プロジェクト: s-zenke/trema
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;
  char management_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  // FIXME
#define VENDER_PREFIX "vendor::"
#define PACKET_IN_PREFIX "packet_in::"
#define PORTSTATUS_PREFIX "port_status::"
#define STATE_PREFIX "state_notify::"
  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[i], VENDER_PREFIX, strlen( VENDER_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( VENDER_PREFIX ) );
      insert_in_front( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PACKET_IN_PREFIX ) );
      insert_in_front( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PORTSTATUS_PREFIX ) );
      insert_in_front( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( STATE_PREFIX ) );
      insert_in_front( &switch_info.state_service_name_list, service_name );
    }
  }

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );
  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();

  init_xid_table();
  init_cookie_table();

  set_fd_set_callback( secure_channel_fd_set );
  set_check_fd_isset_callback( secure_channel_fd_isset );
  add_message_received_callback( get_trema_name(), service_recv );

  snprintf( management_service_name , MESSENGER_SERVICE_NAME_LENGTH,
            "%s.m", get_trema_name() );
  management_service_name[ MESSENGER_SERVICE_NAME_LENGTH - 1 ] = '\0';
  add_message_received_callback( management_service_name, management_recv );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }

  start_trema();

  finalize_xid_table();
  finalize_cookie_table();

  return 0;
}