Example #1
0
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;
}
Example #2
0
static void
test_secure_channel_listen_start_listen_failed() {
  setup();

  int listen_fd = 1;

  listener_info.listen_fd = -1;

  expect_value( mock_socket, domain, PF_INET );
  expect_value( mock_socket, type, SOCK_STREAM );
  expect_value( mock_socket, protocol, 0 );
  will_return( mock_socket, listen_fd );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, SOL_SOCKET, 1 );
  expect_value_count( mock_setsockopt, optname, SO_REUSEADDR, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, 0, 1 );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, IPPROTO_TCP, 1 );
  expect_value_count( mock_setsockopt, optname, TCP_NODELAY, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, 0, 1 );

  expect_value( mock_bind, sockfd, listen_fd );
  expect_not_value( mock_bind, addr_in, NULL );
  expect_value( mock_bind, addrlen, sizeof( struct sockaddr_in ) );
  expect_value( mock_bind, sin_family32, AF_INET );
  expect_value( mock_bind, sin_port32, ( uint32_t ) htons( OFP_TCP_PORT ) );
  expect_value( mock_bind, addr_in->sin_addr.s_addr, htonl( INADDR_ANY ) );
  will_return( mock_bind, 0 );

  expect_value( mock_listen, sockfd, listen_fd );
  expect_value( mock_listen, backlog, 128 );
  will_return( mock_listen, -1 );

  expect_value( mock_close, fd, listen_fd );
  will_return_void( mock_close );

  assert_false( secure_channel_listen_start( &listener_info ) );
  assert_true( listener_info.listen_fd == -1 );

  teardown();
}
Example #3
0
static void
test_secure_channel_listen_start_socket_failed() {
  setup();

  int listen_fd = 1;

  listener_info.listen_fd = listen_fd;

  expect_value( mock_close, fd, listen_fd );
  will_return_void( mock_close );

  expect_value( mock_socket, domain, PF_INET );
  expect_value( mock_socket, type, SOCK_STREAM );
  expect_value( mock_socket, protocol, 0 );
  will_return( mock_socket, -1 );

  assert_false( secure_channel_listen_start( &listener_info ) );
  assert_true( listener_info.listen_fd == -1 );

  teardown();
}