예제 #1
0
파일: Controller_Module.C 프로젝트: 0mk/non
/** attempt to transform this controller into a spatialization
    controller and connect to the given module's spatialization
    control inputs. Returns true on success, false if given module
    does not accept spatialization inputs. */
bool
Controller_Module::connect_spatializer_to ( Module *m )
{
    connect_spatializer_radius_to( m );
    
    /* these are for detecting related parameter groups which can be
       better represented by a single control */
    Port *azimuth_port = NULL;
    float azimuth_value = 0.0f;
    Port *elevation_port = NULL;
    float elevation_value = 0.0f;

    for ( unsigned int i = 0; i < m->control_input.size(); ++i )
    {
        Port *p = &m->control_input[i];

        if ( !strcasecmp( "Azimuth", p->name() ) &&
             180.0f == p->hints.maximum &&
             -180.0f == p->hints.minimum )
        {
            azimuth_port = p;
            azimuth_value = p->control_value();
            continue;
        }
        else if ( !strcasecmp( "Elevation", p->name() ) &&
                  90.0f == p->hints.maximum &&
                  -90.0f == p->hints.minimum )
        {
            elevation_port = p;
            elevation_value = p->control_value();
            continue;
        }
    }
    
    if ( ! ( azimuth_port && elevation_port ) )
        return false;

    if ( control_output.size() != 3 )
    {
        control_output.clear();
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
    }

    control_output[0].connect_to( azimuth_port );
    control_output[1].connect_to( elevation_port );

    maybe_create_panner();
    
    Panner *o = (Panner*)control;

    o->point( 0 )->azimuth( azimuth_value );
    o->point( 0 )->elevation( elevation_value );
   
    if ( Mixer::spatialization_console )
        Mixer::spatialization_console->update();

    return true;
}
예제 #2
0
int
main(int argc, char** argv)
{
    if (argc != 3) {
        fprintf(stderr, "usage: ./test-wire <name> <pipeline>\n\n");
        fprintf(stderr, " Arguments:\n");
        fprintf(stderr, "    name       the symbolic name of the dataplane\n");
        fprintf(stderr, "    pipeline   the absolute path to a pipeline module\n");
        return -1;
    }

    char const* name = argv[1];
    char const* path = argv[2];

    fp_error_t err;
    struct fp_dataplane* dp = fp_dataplane_create(name, path, &err);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        return -1;
    }


    /* Create the ports. */
    struct fp_port* port1 = add_port(dp, 5000);
    if (!port1)
        return -1;
    struct fp_port* port2 = add_port(dp, 5001);
    if (!port2)
        return -1;

    /* Start the data plane. */
    bool ok = true;
    err = fp_dataplane_start(dp);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        ok = false;
    }

    /* Stop the data plane. */
    err = fp_dataplane_stop(dp);
    if (fp_error(err)) {
        fprintf(stderr, "error: %s\n", fp_strerror(err));
        ok = false;
    }

    /* Clean up the data plane. */
    fp_dataplane_delete(dp, &err);

    return ok ? 0 : -1;
}
예제 #3
0
AUX_Module::AUX_Module ( ) : JACK_Module ( false )
{
    is_default( false );

    _number = 0;

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Gain (dB)" );
        p.hints.type = Port::Hints::LOGARITHMIC;
        p.hints.ranged = true;
        p.hints.minimum = -70.0f;
        p.hints.maximum = 6.0f;
        p.hints.default_value = 0.0f;
        
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    log_create();

    color( FL_DARK1 );

    copy_label( "Aux" );
}
예제 #4
0
static int probe_port(struct usb_ctlr *usbctlr, const int params[])
{
	enum periph_id id;
	int utmi = 0;

	/*
	 * Get the periph id. Port 1 has an internal transceiver, port 3 is
	 * external
	 */
	switch ((u32)usbctlr) {
	case NV_PA_USB1_BASE:
		id = PERIPH_ID_USBD;
		break;

	case NV_PA_USB3_BASE:
		id = PERIPH_ID_USB3;
		utmi = 1;
		break;

	default:
		printf("tegrausb: probe_port: no such port %p\n", usbctlr);
		return -1;
	}

	return add_port(id, usbctlr, params, utmi);
}
static void
create_port_desc( void **state ) {
  UNUSED( state );

  int ret = init_port_manager( SELECT_TIMEOUT_USEC, MAX_SEND_QUEUE, MAX_RECV_QUEUE );
  if ( ret != OFDPE_SUCCESS ) {
   return;
  }

  expect_string( mock_create_ether_device, name, DEV_NAME );
  expect_value( mock_create_ether_device, max_send_queue, MAX_SEND_QUEUE );
  expect_value( mock_create_ether_device, max_recv_queue, MAX_RECV_QUEUE );
  switch_port *port = ( switch_port * ) xmalloc( sizeof( switch_port ) );
  port->device = ( ether_device * ) xmalloc( sizeof( ether_device ) );
  memcpy( port->device->name, DEV_NAME, sizeof( port->device->name ) );
  memcpy( port->device->hw_addr, HW_ADDR, sizeof( port->device->hw_addr ) );
  will_return( mock_create_ether_device, port->device );

  expect_value( mock_send_for_notify_port_config, port_no, PORT_NO );
  expect_value( mock_send_for_notify_port_config, reason, OFPPR_ADD );

  char *device_name = xstrdup( DEV_NAME );
  ret = add_port( PORT_NO, device_name );
  xfree( device_name );
}
예제 #6
0
Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default )
    : Module ( is_default, 50, 100, name() )
{
    box( FL_FLAT_BOX );
    color( FL_BLACK );

    _disable_context_menu = false;
    _pad = true;
    control_value = 0;

    add_port( Port( this, Port::INPUT, Port::CONTROL ) );

    control_input[0].hints.visible = false;

    dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
    dpm_pack->color( FL_BACKGROUND_COLOR );
    dpm_pack->box( FL_FLAT_BOX );
    dpm_pack->type( FL_HORIZONTAL );

    end();

    control_value = new float[1];
    *control_value = -70.0f;

    align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );

    clear_visible_focus();
}
예제 #7
0
static void
port_status_updated( void *user_data, const topology_port_status *status ) {
  assert( user_data != NULL );
  assert( status != NULL );

  broadcast_helper *broadcast_helper = user_data;

  debug( "Port status updated: dpid:%#" PRIx64 ", port:%u, %s, %s",
         status->dpid, status->port_no,
         ( status->status == TD_PORT_UP ? "up" : "down" ),
         ( status->external == TD_PORT_EXTERNAL ? "external" : "internal or inactive" ) );

  if ( status->port_no > OFPP_MAX && status->port_no != OFPP_LOCAL ) {
    warn( "Ignore this update ( port = %u )", status->port_no );
    return;
  }

  port_info *p = lookup_port( broadcast_helper->switches, status->dpid, status->port_no );

  if ( status->status == TD_PORT_UP ) {
    if ( p != NULL ) {
      update_port( p, status->external );
      return;
    }
    add_port( &broadcast_helper->switches, status->dpid, status->port_no, status->external );
  }
  else {
    if ( p == NULL ) {
      debug( "Ignore this update (not found nor already deleted)" );
      return;
    }
    delete_port( &broadcast_helper->switches, p );
  }
}
예제 #8
0
int board_usb_init(const void *blob)
{
	struct fdt_usb config;
	unsigned osc_freq = clock_get_rate(CLOCK_ID_OSC);
	enum clock_osc_freq freq;
	int node_list[USB_PORTS_MAX];
	int node, count, i;

	/* Set up the USB clocks correctly based on our oscillator frequency */
	freq = clock_get_osc_freq();
	config_clock(usb_pll[freq]);

	/* count may return <0 on error */
	count = fdtdec_find_aliases_for_id(blob, "usb",
			COMPAT_NVIDIA_TEGRA20_USB, node_list, USB_PORTS_MAX);
	for (i = 0; i < count; i++) {
		debug("USB %d: ", i);
		node = node_list[i];
		if (!node)
			continue;
		if (fdt_decode_usb(blob, node, osc_freq, &config)) {
			debug("Cannot decode USB node %s\n",
			      fdt_get_name(blob, node, NULL));
			return -1;
		}

		if (add_port(&config, usb_pll[freq]))
			return -1;
		set_host_mode(&config);
	}

	return 0;
}
예제 #9
0
static void
init_ports( list_element **switches, size_t n_entries, const topology_port_status *s ) {
  for ( size_t i = 0; i < n_entries; i++ ) {
    if ( s[ i ].status == TD_PORT_UP ) {
      add_port( switches, s[ i ].dpid, s[ i ].port_no, s[ i ].name, s[ i ].external );
    }
  }
}
예제 #10
0
파일: Controller_Module.C 프로젝트: 0mk/non
bool
Controller_Module::connect_spatializer_radius_to ( Module *m )
{
    Port *radius_port = NULL;
    float radius_value = 0.0f;

    for ( unsigned int i = 0; i < m->control_input.size(); ++i )
    {
        Port *p = &m->control_input[i];

        if ( !strcasecmp( "Radius", p->name() ) )
                  /* 90.0f == p->hints.maximum && */
                  /* -90.0f == p->hints.minimum ) */
        {
            radius_port = p;
            radius_value = p->control_value();
            continue;
        }
    }

    if ( ! radius_port )
        return false;

    if ( control_output.size() != 3 )
    {
        control_output.clear();
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
        add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
    }

    
    control_output[2].connect_to( radius_port );

    maybe_create_panner();
    
    Panner *o = (Panner*)control;

    o->point( 0 )->radius( radius_value );
   
    if ( Mixer::spatialization_console )
        Mixer::spatialization_console->update();

    return true;
}
예제 #11
0
파일: lac.c 프로젝트: sevennothing/lros
/*---------------------------------------------------------------------------*/
extern Boolean lac_create_port(Lac_system *system, Port_no port_no,
                               Lac_port  **port)
{
    Lac_port *p;

    *port = NULL;
    p = &system->ports;
    while ((p = p->next) != &system->ports)
        if (p->port_no == port_no) return(False);

    /* else */
    if (!sysmalloc(sizeof(Lac_port), &p)) return(False);

    *port = p;
    p->port_no = port_no;

    init_node(&p->mac, (void *)p);
    p->mac.rx_fn        = &mac_rx;
    p->mac.rx_status_fn = &mac_status;
    p->mac.tx_status_fn = &mac_status;

    init_node(&p->mux, (void *)p);

    add_port(system, p);

    p->actor_admin.port_priority         = Default_port_priority;
    p->actor_admin.port_no               = port_no;
    p->actor_admin.system_priority       = Default_system_priority;
    p->actor_admin.system_id             = p->system->id;
    p->actor_admin.key                   = Default_key;
    p->actor_admin.state.lacp_activity   = Default_lacp_activity;
    p->actor_admin.state.lacp_timeout    = Default_lacp_timeout;
    p->actor_admin.state.aggregation     = Default_aggregation;
    p->actor_admin.state.synchronization = False;
    p->actor_admin.state.defaulted       = True;
    p->actor_admin.state.expired         = False;

    p->partner_admin.port_priority         = Default_port_priority;
    p->partner_admin.port_no               = port_no;
    p->partner_admin.system_priority       = Default_system_priority;
    p->partner_admin.system_id             = Null_system;
    p->partner_admin.key                   = p->port_no;
    p->partner_admin.state.lacp_activity   = False; /* Passive      */
    p->partner_admin.state.lacp_timeout    = False; /* Long timeout */
    p->partner_admin.state.aggregation     = False; /* Individual   */
    p->partner_admin.state.synchronization = True;
    p->partner_admin.state.collecting      = True;
    p->partner_admin.state.distributing    = True;
    p->partner_admin.state.defaulted       = True;
    p->partner_admin.state.expired         = False;

    lac_init_port(system, port_no, Lacp_enabled);

    return(True);
}
예제 #12
0
void
NodeModel::add_child(SharedPtr<ObjectModel> c)
{
	assert(c->parent().get() == this);

	//ObjectModel::add_child(c);

	SharedPtr<PortModel> pm = PtrCast<PortModel>(c);
	assert(pm);
	add_port(pm);
}
예제 #13
0
void
PatchModel::add_child(SharedPtr<ObjectModel> c)
{
	assert(c->parent().get() == this);

	SharedPtr<PortModel> pm = PtrCast<PortModel>(c);
	if (pm) {
		add_port(pm);
		return;
	}

	SharedPtr<NodeModel> nm = PtrCast<NodeModel>(c);
	if (nm)
		INGEN_EMIT_THIS(new_node, nm);
}
예제 #14
0
static void
port_status_updated( void *user_data, const topology_port_status *status ) {
  assert( user_data != NULL );
  assert( status != NULL );

  sliceable_switch *sliceable_switch = user_data;
  if ( sliceable_switch->second_stage_down == false ) {
    return;
  }

  debug( "Port status updated: dpid:%#" PRIx64 ", port:%u(%s), %s, %s",
         status->dpid, status->port_no, status->name,
         ( status->status == TD_PORT_UP ? "up" : "down" ),
         ( status->external == TD_PORT_EXTERNAL ? "external" : "internal or inactive" ) );

  if ( status->port_no > OFPP_MAX && status->port_no != OFPP_LOCAL ) {
    warn( "Ignore this update ( port = %u )", status->port_no );
    return;
  }

  port_info *p = lookup_port( sliceable_switch->switches, status->dpid, status->port_no );

  delete_fdb_entries( sliceable_switch->fdb, status->dpid, status->port_no );

  if ( status->status == TD_PORT_UP ) {
    if ( p != NULL ) {
      update_port( p, status->external );
      return;
    }
    add_port( &sliceable_switch->switches, status->dpid, status->port_no, status->name, status->external );
  }
  else {
    if ( p == NULL ) {
      debug( "Ignore this update (not found nor already deleted)" );
      return;
    }
    delete_port( &sliceable_switch->switches, p );
    struct ofp_match match;
    memset( &match, 0, sizeof( struct ofp_match ) );
    match.wildcards = OFPFW_ALL;
    match.wildcards &= ~OFPFW_IN_PORT;
    match.in_port = status->port_no;
    teardown_path_by_match( match );
  }
}
예제 #15
0
파일: JACK_Module.C 프로젝트: EQ4/non
bool
JACK_Module::configure_inputs ( int n )
{
    if ( n > 0 )
    {
        if ( is_default() )
            control_input[0].hints.minimum = 1;

        output_connection_handle->show();
    }
  
    int on = audio_input.size();

    if ( n > on )
    {
        for ( int i = on; i < n; ++i )
        {
            if ( add_aux_audio_output(_prefix, i ) )
            {
                add_port( Port( this, Port::INPUT, Port::AUDIO ) );
            }
        }
    }
    else
    {
        for ( int i = on; i > n; --i )
        {
            audio_input.back().disconnect();
            audio_input.pop_back();
            aux_audio_output.back().jack_port()->shutdown();
            delete aux_audio_output.back().jack_port();
            aux_audio_output.pop_back();
        }
    }

    _connection_handle_outputs[0][0] = 0;
    _connection_handle_outputs[0][1] = aux_audio_output.size();

    if ( is_default() )
        control_input[0].control_value_no_callback( n );

    return true;
}
예제 #16
0
파일: JACK_Module.C 프로젝트: EQ4/non
bool
JACK_Module::configure_outputs ( int n )
{
    int on = audio_output.size();
   
    if ( n > 0 )
    {
        input_connection_handle->show();
    }
   
    if ( n > on )
    {
        for ( int i = on; i < n; ++i )
        {
            if ( add_aux_audio_input(_prefix, i ) )
            {
                add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
            }
        }
    }
    else
    {
        for ( int i = on; i > n; --i )
        {
            audio_output.back().disconnect();
            audio_output.pop_back();
            aux_audio_input.back().jack_port()->shutdown();
            delete aux_audio_input.back().jack_port();
            aux_audio_input.pop_back();
        }
    }

    if ( is_default() )
        control_input[1].control_value_no_callback( n );

    if ( n > 0 && is_default() )
    {
        dec_button->show();
        inc_button->show();
    }
    return true;
}
예제 #17
0
파일: Controller_Module.C 프로젝트: 0mk/non
Controller_Module::Controller_Module ( bool is_default ) : Module( is_default, 50, 100, name() )
{
//    label( "" );
    box( FL_NO_BOX );

    _horizontal = true;
    _pad = true;
    control = 0;
    control_value =0.0f;

    add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );

    _mode = GUI;

//    mode( GUI );
//    mode( CV );
//    configure_inputs( 1 );

    end();

//    clear_visible_focus();
    log_create();
}
예제 #18
0
bool
AUX_Module::configure_outputs ( int n )
{
  int on = audio_output.size();

    if ( n > on )
    {
        for ( int i = on; i < n; ++i )
        {
            add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
        }
    }
    else
    {
        for ( int i = on; i > n; --i )
        {
            audio_output.back().disconnect();
            audio_output.pop_back();
        }
    }

    return true;
}
예제 #19
0
Controller_Module::Controller_Module ( bool is_default ) : Module( is_default, 50, 100, name() )
{
//    label( "" );
    box( FL_NO_BOX );

    _pad = true;
    control = 0;
    control_value =0.0f;

    add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );

    _mode = GUI;

//    mode( GUI );
//    mode( CV );
//    configure_inputs( 1 );

    end();

    Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this );

    log_create();
}
예제 #20
0
파일: eroute.c 프로젝트: JasonCC/Openswan
int
main(int argc, char **argv)
{
/*	int fd; */
	char *endptr;
/*	int ret; */
	int c;
	const char* error_s;

	int error = 0;

	char ipaddr_txt[ADDRTOT_BUF];                
	struct sadb_ext *extensions[K_SADB_EXT_MAX + 1];
	struct sadb_msg *pfkey_msg;
	ip_address pfkey_address_s_ska;
	/*struct sockaddr_in pfkey_address_d_ska;*/
	ip_address pfkey_address_sflow_ska;
	ip_address pfkey_address_dflow_ska;
	ip_address pfkey_address_smask_ska;
	ip_address pfkey_address_dmask_ska;

	int transport_proto = 0;
	int src_port = 0;
	int dst_port = 0;
	ip_said said;
	ip_subnet s_subnet, d_subnet;
 	int eroute_af = 0;
 	int said_af = 0;
	int sa_flags=0;

	int argcount = argc;


	progname = argv[0];

	memset(&pfkey_address_s_ska, 0, sizeof(ip_address));
	memset(&pfkey_address_sflow_ska, 0, sizeof(ip_address));
	memset(&pfkey_address_dflow_ska, 0, sizeof(ip_address));
	memset(&pfkey_address_smask_ska, 0, sizeof(ip_address));
	memset(&pfkey_address_dmask_ska, 0, sizeof(ip_address));
	memset(&said, 0, sizeof(ip_said));
	memset(&s_subnet, 0, sizeof(ip_subnet));
	memset(&d_subnet, 0, sizeof(ip_subnet));

	eroute_af_opt = said_af_opt = edst_opt = spi_opt = proto_opt = said_opt = dst_opt = src_opt = NULL;

	while((c = getopt_long(argc, argv, ""/*"acdD:e:i:hprs:S:f:vl:+:g"*/, longopts, 0)) != EOF) {
		switch(c) {
		case 'g':
			debug = 1;
			pfkey_lib_debug = PF_KEY_DEBUG_PARSE_MAX;
			argcount--;
			break;
		case 'a':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--replacein', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_SETEROUTE;
			break;
		case 'A':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--replacein', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_INEROUTE;
			break;
		case 'r':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--replacein', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_REPLACEROUTE;
			break;
		case 'E':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--replacein', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_INREPLACEROUTE;
			break;
		case 'c':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_CLREROUTE;
			break;
		case 'd':
			if(action_type) {
				fprintf(stderr, "%s: Only one of '--add', '--addin', '--replace', '--clear', or '--del' options permitted.\n",
					progname);
				exit(1);
			}
			action_type = EMT_DELEROUTE;
			break;
		case 'e':
			if(said_opt) {
				fprintf(stderr, "%s: Error, EDST parameter redefined:%s, already defined in SA:%s\n",
					progname, optarg, said_opt);
				exit (1);
			}				
			if(edst_opt) {
				fprintf(stderr, "%s: Error, EDST parameter redefined:%s, already defined as:%s\n",
					progname, optarg, edst_opt);
				exit (1);
			}				
			error_s = ttoaddr(optarg, 0, said_af, &said.dst);
			if(error_s != NULL) {
				fprintf(stderr, "%s: Error, %s converting --edst argument:%s\n",
					progname, error_s, optarg);
				exit (1);
			}
			edst_opt = optarg;
			break;
		case 'h':
		case '?':
			usage(progname);
			exit(1);
		case 's':
			if(said_opt) {
				fprintf(stderr, "%s: Error, SPI parameter redefined:%s, already defined in SA:%s\n",
					progname, optarg, said_opt);
				exit (1);
			}				
			if(spi_opt) {
				fprintf(stderr, "%s: Error, SPI parameter redefined:%s, already defined as:%s\n",
					progname, optarg, spi_opt);
				exit (1);
			}				
			said.spi = htonl(strtoul(optarg, &endptr, 0));
			if(!(endptr == optarg + strlen(optarg))) {
				fprintf(stderr, "%s: Invalid character in SPI parameter: %s\n",
					progname, optarg);
				exit (1);
			}
			if(ntohl(said.spi) < 0x100) {
				fprintf(stderr, "%s: Illegal reserved spi: %s => 0x%x Must be larger than 0x100.\n",
					progname, optarg, ntohl(said.spi));
				exit(1);
			}
			spi_opt = optarg;
			break;
		case 'p':
			if(said_opt) {
				fprintf(stderr, "%s: Error, PROTO parameter redefined:%s, already defined in SA:%s\n",
					progname, optarg, said_opt);
				exit (1);
			}				
			if(proto_opt) {
				fprintf(stderr, "%s: Error, PROTO parameter redefined:%s, already defined as:%s\n",
					progname, optarg, proto_opt);
				exit (1);
			}
#if 0
			if(said.proto) {
				fprintf(stderr, "%s: Warning, PROTO parameter redefined:%s\n",
					progname, optarg);
				exit (1);
			}
#endif
			if(!strcmp(optarg, "ah"))
				said.proto = SA_AH;
			if(!strcmp(optarg, "esp"))
				said.proto = SA_ESP;
			if(!strcmp(optarg, "tun"))
				said.proto = SA_IPIP;
			if(!strcmp(optarg, "comp"))
				said.proto = SA_COMP;
			if(said.proto == 0) {
				fprintf(stderr, "%s: Invalid PROTO parameter: %s\n",
					progname, optarg);
				exit (1);
			}
			proto_opt = optarg;
			break;
		case 'I':
			if(said_opt) {
				fprintf(stderr, "%s: Error, SAID parameter redefined:%s, already defined in SA:%s\n",
					progname, optarg, said_opt);
				exit (1);
			}				
			if(proto_opt) {
				fprintf(stderr, "%s: Error, PROTO parameter redefined in SA:%s, already defined as:%s\n",
					progname, optarg, proto_opt);
				exit (1);
			}
			if(edst_opt) {
				fprintf(stderr, "%s: Error, EDST parameter redefined in SA:%s, already defined as:%s\n",
					progname, optarg, edst_opt);
				exit (1);
			}
			if(spi_opt) {
				fprintf(stderr, "%s: Error, SPI parameter redefined in SA:%s, already defined as:%s\n",
					progname, optarg, spi_opt);
				exit (1);
			}
			if(said_af_opt) {
				fprintf(stderr, "%s: Error, address family parameter redefined in SA:%s, already defined as:%s\n",
					progname, optarg, said_af_opt);
				exit (1);
			}
			error_s = ttosa(optarg, 0, &said);
			if(error_s != NULL) {
				fprintf(stderr, "%s: Error, %s converting --sa argument:%s\n",
					progname, error_s, optarg);
				exit (1);
			} else if(ntohl(said.spi) < 0x100){
				fprintf(stderr, "%s: Illegal reserved spi: %s => 0x%x Must be larger than or equal to 0x100.\n",
					progname, optarg, said.spi);
				exit(1);
			}
			said_af = addrtypeof(&said.dst);
			said_opt = optarg;
			break;
		case 'v':
			fprintf(stdout, "%s %s\n", me, ipsec_version_code());
			fprintf(stdout, "See `ipsec --copyright' for copyright information.\n");
			exit(1);
		case 'D':
			if(dst_opt) {
				fprintf(stderr, "%s: Error, --dst parameter redefined:%s, already defined as:%s\n",
					progname, optarg, dst_opt);
				exit (1);
			}				
			error_s = ttosubnet(optarg, 0, eroute_af, &d_subnet);
			if (error_s != NULL) {
				fprintf(stderr, "%s: Error, %s converting --dst argument: %s\n",
					progname, error_s, optarg);
				exit (1);
			}
			dst_opt = optarg;
			break;
		case 'S':
			if(src_opt) {
				fprintf(stderr, "%s: Error, --src parameter redefined:%s, already defined as:%s\n",
					progname, optarg, src_opt);
				exit (1);
			}				
			error_s = ttosubnet(optarg, 0, eroute_af, &s_subnet);
			if (error_s != NULL) {
				fprintf(stderr, "%s: Error, %s converting --src argument: %s\n",
					progname, error_s, optarg);
				exit (1);
			}
			src_opt = optarg;
			break;
		case 'P':
			if (transport_proto_opt) {
				fprintf(stderr, "%s: Error, --transport-proto"
					" parameter redefined:%s, "
					"already defined as:%s\n",
					progname, optarg,
					transport_proto_opt);
				exit(1);
			}
			transport_proto_opt = optarg;
			break;
		case 'Q':
			if (src_port_opt) {
				fprintf(stderr, "%s: Error, --src-port"
					" parameter redefined:%s, "
					"already defined as:%s\n",
					progname, optarg, src_port_opt);
				exit(1);
			}
			src_port_opt = optarg;
			break;
		case 'R':
			if (dst_port_opt) {
				fprintf(stderr, "%s: Error, --dst-port"
					" parameter redefined:%s, "
					"already defined as:%s\n",
					progname, optarg, dst_port_opt);
				exit(1);
			}
			dst_port_opt = optarg;
			break;
		case 'l':
			progname = malloc(strlen(argv[0])
					      + 10 /* update this when changing the sprintf() */
					      + strlen(optarg));
			sprintf(progname, "%s --label %s",
				argv[0],
				optarg);
			argcount -= 2;
			break;
		case 'i': /* specifies the address family of the SAID, stored in said_af */
			if(said_af_opt) {
				fprintf(stderr, "%s: Error, address family of SAID redefined:%s, already defined as:%s\n",
					progname, optarg, said_af_opt);
				exit (1);
			}				
			if(!strcmp(optarg, "inet"))
				said_af = AF_INET;
			if(!strcmp(optarg, "inet6"))
				said_af = AF_INET6;
			if(said_af == 0) {
				fprintf(stderr, "%s: Invalid address family parameter for SAID: %s\n",
					progname, optarg);
				exit (1);
			}
			said_af_opt = optarg;
			break;
		case 'f': /* specifies the address family of the eroute, stored in eroute_af */
			if(eroute_af_opt) {
				fprintf(stderr, "%s: Error, address family of eroute redefined:%s, already defined as:%s\n",
					progname, optarg, eroute_af_opt);
				exit (1);
			}				
			if(!strcmp(optarg, "inet"))
				eroute_af = AF_INET;
			if(!strcmp(optarg, "inet6"))
				eroute_af = AF_INET6;
			if(eroute_af == 0) {
				fprintf(stderr, "%s: Invalid address family parameter for eroute: %s\n",
					progname, optarg);
				exit (1);
			}
			eroute_af_opt = optarg;
			break;
		case '+': /* optionsfrom */
			optionsfrom(optarg, &argc, &argv, optind, stderr);
			/* no return on error */
			break;
		default:
			break;
		}
	}

	if(debug) {
		fprintf(stdout, "%s: DEBUG: argc=%d\n", progname, argc);
	}
	
        if(argcount == 1) {
                struct stat sts;
                if ( ((stat ("/proc/net/pfkey", &sts)) == 0) )  {
                         fprintf(stderr, "%s: NETKEY does not support eroute table.\n",progname);

                        exit(1);
                }
                else {
			int ret = 1;
			if ((stat ("/proc/net/ipsec_eroute", &sts)) != 0)  {
				fprintf(stderr, "%s: No eroute table - no IPsec support in kernel (are the modules loaded?)\n", progname);
			} else {
				ret = system("cat /proc/net/ipsec_eroute");
				ret = ret != -1 && WIFEXITED(ret) ? WEXITSTATUS(ret) : 1;
			}
			exit(ret);
                }
        }
	

	/* Sanity checks */

	if(debug) {
		fprintf(stdout, "%s: DEBUG: action_type=%d\n", progname, action_type);
	}

	if (transport_proto_opt != 0) {
	     struct protoent * proto = getprotobyname(transport_proto_opt);
	     if (proto != 0) {
		  transport_proto = proto->p_proto;
	     } else {
		  transport_proto = strtoul(transport_proto_opt, &endptr, 0);
		  if ((*endptr != '\0') 
		      || (transport_proto == 0 && endptr == transport_proto_opt)) {
		       fprintf(stderr, "%s: Invalid character in --transport-proto parameter: %s\n",
			       progname, transport_proto_opt);
		       exit (1);
		  }
		  if (transport_proto > 255) {
		       fprintf(stderr, "%s: --transport-proto parameter: %s must be in the range 0 to 255 inclusive\n",
			       progname, transport_proto_opt);
		       exit (1);
		  }
	     }
	}

        if (src_port_opt != 0 || dst_port_opt != 0) {
		switch (transport_proto) {
		case IPPROTO_UDP:
		case IPPROTO_TCP:
			break;
		default:
			fprintf(stderr, "%s: --transport-proto with either UDP or TCP must be specified if --src-port or --dst-port is used\n", progname);
			exit(1);
		}
        }

	if (src_port_opt) {
	     struct servent * ent = getservbyname(src_port_opt, 0);
	     if (ent != 0) {
		  src_port = ent->s_port;
	     } else {
		  src_port = strtoul(src_port_opt, &endptr, 0);
		  if ((*endptr != '\0')
		      || (src_port == 0 && endptr == src_port_opt)) {
		       fprintf(stderr, "%s: Invalid character in --src-port parameter: %s\n",
			       progname, src_port_opt);
		       exit (1);
		  }
		  if (src_port > 65535) {
		       fprintf(stderr, "%s: --src-port parameter: %s must be in the range 0 to 65535 inclusive\n",
			       progname, src_port_opt);
		  }
		  src_port = htons(src_port);
	     }
	}

	if (dst_port_opt) {
	     struct servent * ent = getservbyname(dst_port_opt, 0);
	     if (ent != 0) {
		  dst_port = ent->s_port;
	     } else {
		  dst_port = strtoul(dst_port_opt, &endptr, 0);
		  if ((*endptr != '\0')
		      || (dst_port == 0 && endptr == dst_port_opt)) {
		       fprintf(stderr, "%s: Invalid character in --dst-port parameter: %s\n",
			       progname, dst_port_opt);
		       exit (1);
		  }
		  if (dst_port > 65535) {
		       fprintf(stderr, "%s: --dst-port parameter: %s must be in the range 0 to 65535 inclusive\n",
			       progname, dst_port_opt);
		  }
		  dst_port = htons(dst_port);
	     }
	}

	switch(action_type) {
	case EMT_SETEROUTE:
	case EMT_REPLACEROUTE:
	case EMT_INEROUTE:
	case EMT_INREPLACEROUTE:
		if(!(said_af_opt && edst_opt && spi_opt && proto_opt) && !(said_opt)) {
			fprintf(stderr, "%s: add and addin options must have SA specified.\n",
				progname);
			exit(1);
		}
	case EMT_DELEROUTE:
		if(!src_opt) {
			fprintf(stderr, "%s: Error -- %s option '--src' is required.\n",
				progname, (action_type == EMT_SETEROUTE) ? "add" : "del");
			exit(1);
		}
		if(!dst_opt) {
			fprintf(stderr, "%s: Error -- %s option '--dst' is required.\n",
				progname, (action_type == EMT_SETEROUTE) ? "add" : "del");
			exit(1);
		}
	case EMT_CLREROUTE:
		break;
	default:
		fprintf(stderr, "%s: exactly one of '--add', '--addin', '--replace', '--del' or '--clear' options must be specified.\n"
			"Try %s --help' for usage information.\n",
			progname, progname);
		exit(1);
	}

	pfkey_sock = pfkey_open_sock_with_error();
	if(pfkey_sock == -1) {
		exit(1);
	}

	if(debug) {
		fprintf(stdout, "%s: DEBUG: PFKEYv2 socket successfully openned=%d.\n", progname, pfkey_sock);
	}

	/* Build an SADB_X_ADDFLOW or SADB_X_DELFLOW message to send down. */
	/* It needs <base, SA, address(SD), flow(SD), mask(SD)> minimum. */
	pfkey_extensions_init(extensions);
	if((error = pfkey_msg_hdr_build(&extensions[0],
					(action_type == EMT_SETEROUTE
					 || action_type == EMT_REPLACEROUTE
					 || action_type == EMT_INREPLACEROUTE
					 || action_type == EMT_INEROUTE)
					? SADB_X_ADDFLOW : SADB_X_DELFLOW,
					proto2satype(said.proto),
					0,
					++pfkey_seq,
					getpid()))) {
		fprintf(stderr, "%s: Trouble building message header, error=%d.\n",
			progname, error);
		pfkey_extensions_free(extensions);
		exit(1);
	}

	if(debug) {
		fprintf(stdout, "%s: DEBUG: pfkey_msg_hdr_build successfull.\n", progname);
	}

	switch(action_type) {
	case EMT_CLREROUTE:
		sa_flags = SADB_X_SAFLAGS_CLEARFLOW;
		goto sa_build;

	case EMT_REPLACEROUTE:
		sa_flags = SADB_X_SAFLAGS_REPLACEFLOW;
		goto sa_build;

	case EMT_INREPLACEROUTE:
		sa_flags = SADB_X_SAFLAGS_REPLACEFLOW | SADB_X_SAFLAGS_INFLOW;
		goto sa_build;

	case EMT_INEROUTE:
		sa_flags = SADB_X_SAFLAGS_INFLOW;
		goto sa_build;

	case EMT_SETEROUTE:
	sa_build:
		if((error = pfkey_sa_build(&extensions[SADB_EXT_SA],
					   SADB_EXT_SA,
					   said.spi, /* in network order */
					   0,
					   0,
					   0,
					   0,
					   sa_flags))) {
			fprintf(stderr, "%s: Trouble building sa extension, error=%d.\n",
				progname, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_sa_build successful.\n", progname);
		}

	default:
		break;
	}

	switch(action_type) {
	case EMT_SETEROUTE:
	case EMT_REPLACEROUTE:
	case EMT_INEROUTE:
	case EMT_INREPLACEROUTE:
		anyaddr(said_af, &pfkey_address_s_ska);
		if((error = pfkey_address_build(&extensions[SADB_EXT_ADDRESS_SRC],
						SADB_EXT_ADDRESS_SRC,
						0,
						0,
						sockaddrof(&pfkey_address_s_ska)))) {
			addrtot(&pfkey_address_s_ska, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_s extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for src.\n", progname);
		}

		if((error = pfkey_address_build(&extensions[SADB_EXT_ADDRESS_DST],
						SADB_EXT_ADDRESS_DST,
						0,
						0,
						sockaddrof(&said.dst)))) {
			addrtot(&said.dst, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_d extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for dst.\n", progname);
		}
	default:
		break;
	}
	
	switch(action_type) {
	case EMT_SETEROUTE:
	case EMT_REPLACEROUTE:
	case EMT_INEROUTE:
	case EMT_INREPLACEROUTE:
	case EMT_DELEROUTE:
		networkof(&s_subnet, &pfkey_address_sflow_ska); /* src flow */
		add_port(eroute_af, &pfkey_address_sflow_ska, src_port);
		if((error = pfkey_address_build(&extensions[SADB_X_EXT_ADDRESS_SRC_FLOW],
						SADB_X_EXT_ADDRESS_SRC_FLOW,
						0,
						0,
						sockaddrof(&pfkey_address_sflow_ska)))) {
			addrtot(&pfkey_address_sflow_ska, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_sflow extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for src flow.\n", progname);
		}
	
		networkof(&d_subnet, &pfkey_address_dflow_ska); /* dst flow */
		add_port(eroute_af, &pfkey_address_dflow_ska, dst_port);
		if((error = pfkey_address_build(&extensions[SADB_X_EXT_ADDRESS_DST_FLOW],
						SADB_X_EXT_ADDRESS_DST_FLOW,
						0,
						0,
						sockaddrof(&pfkey_address_dflow_ska)))) {
			addrtot(&pfkey_address_dflow_ska, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_dflow extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for dst flow.\n", progname);
		}
		
		maskof(&s_subnet, &pfkey_address_smask_ska); /* src mask */
		add_port(eroute_af, &pfkey_address_smask_ska, src_port ? ~0:0);
		if((error = pfkey_address_build(&extensions[SADB_X_EXT_ADDRESS_SRC_MASK],
						SADB_X_EXT_ADDRESS_SRC_MASK,
						0,
						0,
						sockaddrof(&pfkey_address_smask_ska)))) {
			addrtot(&pfkey_address_smask_ska, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_smask extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for src mask.\n", progname);
		}
		
		maskof(&d_subnet, &pfkey_address_dmask_ska); /* dst mask */
		add_port(eroute_af, &pfkey_address_dmask_ska, dst_port ? ~0:0);
		if((error = pfkey_address_build(&extensions[SADB_X_EXT_ADDRESS_DST_MASK],
						SADB_X_EXT_ADDRESS_DST_MASK,
						0,
						0,
						sockaddrof(&pfkey_address_dmask_ska)))) {
			addrtot(&pfkey_address_dmask_ska, 0, ipaddr_txt, sizeof(ipaddr_txt));
			fprintf(stderr, "%s: Trouble building address_dmask extension (%s), error=%d.\n",
				progname, ipaddr_txt, error);
			pfkey_extensions_free(extensions);
			exit(1);
		}
		if(debug) {
			fprintf(stdout, "%s: DEBUG: pfkey_address_build successful for dst mask.\n", progname);
		}
	}
	
	if (transport_proto != 0) {
		if ((error = pfkey_x_protocol_build(&extensions[SADB_X_EXT_PROTOCOL],
						    transport_proto))) {
			fprintf(stderr, "%s: Trouble building transport"
				" protocol extension, error=%d.\n",
				progname, error);
			exit(1);
		}
	}

	if((error = pfkey_msg_build(&pfkey_msg, extensions, EXT_BITS_IN))) {
		fprintf(stderr, "%s: Trouble building pfkey message, error=%d.\n",
			progname, error);
		pfkey_extensions_free(extensions);
		pfkey_msg_free(&pfkey_msg);
		exit(1);
	}
	if(debug) {
		fprintf(stdout, "%s: DEBUG: pfkey_msg_build successful.\n", progname);
	}

	if((error = write(pfkey_sock,
				pfkey_msg,
				pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN)) !=
	   (ssize_t)(pfkey_msg->sadb_msg_len * IPSEC_PFKEYv2_ALIGN)) {
		fprintf(stderr, "%s: pfkey write failed, returning %d with errno=%d.\n",
			progname, error, errno);
		pfkey_extensions_free(extensions);
		pfkey_msg_free(&pfkey_msg);
		switch(errno) {
		case EINVAL:
			fprintf(stderr, "Invalid argument, check kernel log messages for specifics.\n");
			break;
		case ENXIO:
			if((action_type == EMT_SETEROUTE) ||
			   (action_type == EMT_REPLACEROUTE)) {
				fprintf(stderr, "Invalid mask.\n");
				break;
			}
			if(action_type == EMT_DELEROUTE) {
				fprintf(stderr, "Mask not found.\n");
				break;
			}
		case EFAULT:
			if((action_type == EMT_SETEROUTE) ||
			   (action_type == EMT_REPLACEROUTE)) {
				fprintf(stderr, "Invalid address.\n");
				break;
			}
			if(action_type == EMT_DELEROUTE) {
				fprintf(stderr, "Address not found.\n");
				break;
			}
		case EACCES:
			fprintf(stderr, "access denied.  ");
			if(getuid() == 0) {
				fprintf(stderr, "Check permissions.  Should be 600.\n");
			} else {
				fprintf(stderr, "You must be root to open this file.\n");
			}
			break;
		case EUNATCH:
			fprintf(stderr, "KLIPS not loaded.\n");
			break;
		case EBUSY:
			fprintf(stderr, "KLIPS is busy.  Most likely a serious internal error occured in a previous command.  Please report as much detail as possible to development team.\n");
			break;
		case ENODEV:
			fprintf(stderr, "KLIPS not loaded or enabled.\n");
			fprintf(stderr, "No device?!?\n");
			break;
		case ENOBUFS:
			fprintf(stderr, "No kernel memory to allocate SA.\n");
			break;
		case ESOCKTNOSUPPORT:
			fprintf(stderr, "Algorithm support not available in the kernel.  Please compile in support.\n");
			break;
		case EEXIST:
			fprintf(stderr, "eroute already in use.  Delete old one first.\n");
			break;
		case ENOENT:
			if(action_type == EMT_INEROUTE || action_type == EMT_INREPLACEROUTE) {
				fprintf(stderr, "non-existant IPIP SA.\n");
				break;
			}
			fprintf(stderr, "eroute doesn't exist.  Can't delete.\n");
			break;
		case ENOSPC:
			fprintf(stderr, "no room in kernel SAref table.  Cannot process request.\n");
			break;
		case ESPIPE:
			fprintf(stderr, "kernel SAref table internal error.  Cannot process request.\n");
			break;
		default:
			fprintf(stderr, "Unknown socket write error %d.  Please report as much detail as possible to development team.\n", errno);
		}
/*		fprintf(stderr, "%s: socket write returned errno %d\n",
		progname, errno);*/
		exit(1);
	}
	if(debug) {
		fprintf(stdout, "%s: DEBUG: pfkey write successful.\n", progname);
	}

	if(pfkey_msg) {
		pfkey_extensions_free(extensions);
		pfkey_msg_free(&pfkey_msg);
	}

	(void) close(pfkey_sock);  /* close the socket */

	if(debug) {
		fprintf(stdout, "%s: DEBUG: write ok\n", progname);
	}

	exit(0);
}
예제 #21
0
int board_usb_init(const void *blob)
{
#ifdef CONFIG_OF_CONTROL
	struct fdt_usb config;
	int clk_done = 0;
	int node, upto = 0;
	unsigned osc_freq = clock_get_rate(CLOCK_ID_OSC);
#if defined(CONFIG_TEGRA3)
	struct usb_ctlr *usb1ctlr;
#endif
	do {
		node = fdt_decode_next_alias(blob, "usb",
				COMPAT_NVIDIA_TEGRA250_USB, &upto);
		if (node < 0)
			break;
		if (fdt_decode_usb(blob, node, osc_freq, &config))
			return -1;
		if (!config.enabled)
			continue;

		/* The first port we find gets to set the clocks */
		if (!clk_done) {
			config_clock(config.params);
			clk_done = 1;
		}
		if (config.host_mode) {
			/* Only one host-dev port is supported */
			if (host_dev_ctlr)
				return -1;
			host_dev_ctlr = config.reg;
		}
		if (add_port(config.periph_id, config.reg, config.params,
			    config.utmi))
			return -1;
#if defined(CONFIG_TEGRA3)
		fdt_setup_gpio(&config.vbus_gpio);
		fdt_setup_gpio(&config.vbus_pullup_gpio);

		usb1ctlr = (struct usb_ctlr *)NV_PA_USB1_BASE;
		/*
		 * BIAS Pad Power Down is common among all 3 USB
		 * controllers and can be controlled from USB1 only.
		 */
		bf_writel(UTMIP_BIASPD, 0, &usb1ctlr->utmip_bias_cfg0);
#endif
	} while (node);
#else
	enum clock_osc_freq freq;
	const int *params;

	/* Get the Oscillator frequency */
	freq = clock_get_osc_freq();

	/* Enable PLL U for USB */
	params = &usb_pll[freq][0];
	config_clock(params);

	/* Set up our two ports */
#ifdef CONFIG_TEGRA2_USB1_HOST
	host_dev_ctlr = (struct usb_ctlr *)NV_PA_USB1_BASE;
#endif
	probe_port((struct usb_ctlr *)CONFIG_TEGRA2_USB0, params);
	probe_port((struct usb_ctlr *)CONFIG_TEGRA2_USB1, params);
#endif /* CONFIG_OF_CONTROL */
	usb_set_host_mode();
	port_current = -1;
	return 0;
}
예제 #22
0
int 
main(int argc, char** argv)
{
  if (argc != 5) {
    fprintf(stderr, "usage: ./test-nadk <name> <pipeline>\n\n");
    fprintf(stderr, " Arguments:\n");
    fprintf(stderr, "    name       the symbolic name of the dataplane\n");
    fprintf(stderr, "    pipeline   the absolute path to a pipeline module\n");
    fprintf(stderr, "    dprc       the name of the NADK resource container\n");
    fprintf(stderr, "    test_type  0: Reflect; 1: XRefelct; "
                    "2:Loopback, 3:XLoopback, 4: Dataplane\n");
    return -1;
  }

  char const* name = argv[1];
  char const* path = argv[2];
  char const* dprc = argv[3];
  const test_type_t test = atoi(argv[4]);

  /* Asynchronous signals that result in attempted graceful exit */
  install_signal_handler();

  fp_error_t err;
  struct fp_dataplane* dp = fp_dataplane_create(name, path, &err);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    return -1;
  }

  /* Hack to initialize NADK framework with passed-in DPRC */
  fp_nadk_init(dprc);

  /* Add ports to the dataplane. */
  struct fp_port* port1 = add_port(dp, 0);
  if (!port1)
    return -1;
  struct fp_port* port2 = add_port(dp, 1);
  if (!port2)
    return -1;

  /* Start the data plane. */
  bool ok = true;
  err = fp_dataplane_start(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Enter test loop until Ctrl-C (SIGINT) is received */
  printf("Entering packet I/O loop until Ctrl-C (SIGINT) is received\n");
  int i = 0;
  while(!received_sigint) {
    // choose which test to run by run-time parameter:
    switch(test) {
    case TEST_REFLECT:
      reflect_test(port1, port2);
      break;
    case TEST_XREFLECT:
      xreflect_test(port1, port2);
      break;
    case TEST_LOOPBACK:
      loopback_test(port1, port2);
      break;
    case TEST_XLOOPBACK:
      xloopback_test(port1, port2);
      break;
    case TEST_DATAPLANE:
      dataplane_test(dp, port1, port2);
      break;
    default:
      printf("Invalid test_type: %d...\n", test);
      received_sigint = 1;
      break;
    }
  }
  printf("Broke out of processing loop\n");
  
  /* Stop the data plane. */
  err = fp_dataplane_stop(dp);
  if (fp_error(err)) {
    fprintf(stderr, "error: %s\n", fp_strerror(err));
    ok = false;
  }

  /* Clean up the data plane. */
  fp_dataplane_delete(dp, &err);

  return ok ? 0 : -1;
}
예제 #23
0
int divert_ioctl(unsigned int cmd, struct divert_cf __user *arg)
{
	struct divert_cf	div_cf;
	struct divert_blk	*div_blk;
	struct net_device	*dev;
	int			ret;

	switch (cmd) {
	case SIOCGIFDIVERT:
		DVDBG("SIOCGIFDIVERT, copy_from_user");
		if (copy_from_user(&div_cf, arg, sizeof(struct divert_cf)))
			return -EFAULT;
		DVDBG("before check_args");
		ret = check_args(&div_cf, &dev);
		if (ret)
			return ret;
		DVDBG("after checkargs");
		div_blk = dev->divert;
			
		DVDBG("befre switch()");
		switch (div_cf.cmd) {
		case DIVCMD_GETSTATUS:
			/* Now, just give the user the raw divert block
			 * for him to play with :)
			 */
			if (copy_to_user(div_cf.arg1.ptr, dev->divert,
					 sizeof(struct divert_blk)))
				return -EFAULT;
			break;

		case DIVCMD_GETVERSION:
			DVDBG("GETVERSION: checking ptr");
			if (div_cf.arg1.ptr == NULL)
				return -EINVAL;
			DVDBG("GETVERSION: copying data to userland");
			if (copy_to_user(div_cf.arg1.ptr,
					 sysctl_divert_version, 32))
				return -EFAULT;
			DVDBG("GETVERSION: data copied");
			break;

		default:
			return -EINVAL;
		}

		break;

	case SIOCSIFDIVERT:
		if (copy_from_user(&div_cf, arg, sizeof(struct divert_cf)))
			return -EFAULT;

		ret = check_args(&div_cf, &dev);
		if (ret)
			return ret;

		div_blk = dev->divert;

		switch(div_cf.cmd) {
		case DIVCMD_RESET:
			div_blk->divert = 0;
			div_blk->protos = DIVERT_PROTO_NONE;
			memset(div_blk->tcp_dst, 0,
			       MAX_DIVERT_PORTS * sizeof(u16));
			memset(div_blk->tcp_src, 0,
			       MAX_DIVERT_PORTS * sizeof(u16));
			memset(div_blk->udp_dst, 0,
			       MAX_DIVERT_PORTS * sizeof(u16));
			memset(div_blk->udp_src, 0,
			       MAX_DIVERT_PORTS * sizeof(u16));
			return 0;
				
		case DIVCMD_DIVERT:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ENABLE:
				if (div_blk->divert)
					return -EALREADY;
				div_blk->divert = 1;
				break;

			case DIVARG1_DISABLE:
				if (!div_blk->divert)
					return -EALREADY;
				div_blk->divert = 0;
				break;

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_IP:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ENABLE:
				if (div_blk->protos & DIVERT_PROTO_IP)
					return -EALREADY;
				div_blk->protos |= DIVERT_PROTO_IP;
				break;

			case DIVARG1_DISABLE:
				if (!(div_blk->protos & DIVERT_PROTO_IP))
					return -EALREADY;
				div_blk->protos &= ~DIVERT_PROTO_IP;
				break;

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_TCP:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ENABLE:
				if (div_blk->protos & DIVERT_PROTO_TCP)
					return -EALREADY;
				div_blk->protos |= DIVERT_PROTO_TCP;
				break;

			case DIVARG1_DISABLE:
				if (!(div_blk->protos & DIVERT_PROTO_TCP))
					return -EALREADY;
				div_blk->protos &= ~DIVERT_PROTO_TCP;
				break;

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_TCPDST:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ADD:
				return add_port(div_blk->tcp_dst,
						div_cf.arg2.uint16);
				
			case DIVARG1_REMOVE:
				return remove_port(div_blk->tcp_dst,
						   div_cf.arg2.uint16);

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_TCPSRC:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ADD:
				return add_port(div_blk->tcp_src,
						div_cf.arg2.uint16);

			case DIVARG1_REMOVE:
				return remove_port(div_blk->tcp_src,
						   div_cf.arg2.uint16);

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_UDP:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ENABLE:
				if (div_blk->protos & DIVERT_PROTO_UDP)
					return -EALREADY;
				div_blk->protos |= DIVERT_PROTO_UDP;
				break;

			case DIVARG1_DISABLE:
				if (!(div_blk->protos & DIVERT_PROTO_UDP))
					return -EALREADY;
				div_blk->protos &= ~DIVERT_PROTO_UDP;
				break;

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_UDPDST:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ADD:
				return add_port(div_blk->udp_dst,
						div_cf.arg2.uint16);

			case DIVARG1_REMOVE:
				return remove_port(div_blk->udp_dst,
						   div_cf.arg2.uint16);

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_UDPSRC:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ADD:
				return add_port(div_blk->udp_src,
						div_cf.arg2.uint16);

			case DIVARG1_REMOVE:
				return remove_port(div_blk->udp_src,
						   div_cf.arg2.uint16);

			default:
				return -EINVAL;
			}

			break;

		case DIVCMD_ICMP:
			switch(div_cf.arg1.int32) {
			case DIVARG1_ENABLE:
				if (div_blk->protos & DIVERT_PROTO_ICMP)
					return -EALREADY;
				div_blk->protos |= DIVERT_PROTO_ICMP;
				break;

			case DIVARG1_DISABLE:
				if (!(div_blk->protos & DIVERT_PROTO_ICMP))
					return -EALREADY;
				div_blk->protos &= ~DIVERT_PROTO_ICMP;
				break;

			default:
				return -EINVAL;
			}

			break;

		default:
			return -EINVAL;
		}

		break;

	default:
		return -EINVAL;
	}

	return 0;
}
예제 #24
0
파일: JACK_Module.C 프로젝트: EQ4/non
JACK_Module::JACK_Module ( bool log )
    : Module ( 25, 25, name() )
{
    _prefix = 0;

    _connection_handle_outputs[0][0] = 0;
    _connection_handle_outputs[0][1] = 0;
    _connection_handle_outputs[1][0] = 0;
    _connection_handle_outputs[1][1] = 0;


    align( FL_ALIGN_TOP | FL_ALIGN_INSIDE );

    if ( log )
    {
        /* FIXME: how do Controls find out that a connected value has changed? How does this work in ladspa? */
        {
            Port p( this, Port::INPUT, Port::CONTROL, "Inputs" );
            p.hints.type = Port::Hints::INTEGER;
            p.hints.minimum = 0;
            p.hints.maximum = 16;
            p.hints.ranged = true;
            p.hints.visible = false;

            p.connect_to( new float );
            p.control_value_no_callback( 0 );

            add_port( p );
        }

        {
            Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
            p.hints.type = Port::Hints::INTEGER;
            p.hints.minimum = 0;
            p.hints.maximum = 16;
            p.hints.ranged = true;
            p.hints.visible = false;

            p.connect_to( new float );
            p.control_value_no_callback( 0 );

            add_port( p );
        }

        color( FL_DARK1 );

        log_create();
    }


    { Fl_Scalepack *o = new Fl_Scalepack( x() +  Fl::box_dx(box()),
                                          y() + Fl::box_dy(box()),
                                          w() - Fl::box_dw(box()),
                                          h() - Fl::box_dh(box()) );
        o->type( Fl_Pack::VERTICAL );
        o->spacing(0);


        { Fl_Scalepack *o = new Fl_Scalepack( x() +  Fl::box_dx(box()),
                                              y() + Fl::box_dy(box()),
                                              w(),
                                              24 - Fl::box_dh(box()) );
            o->type( Fl_Pack::HORIZONTAL );
    
            o->spacing( 0 );


            { Fl_Box *o = input_connection_handle = new Fl_Box( x(), y(), 18, 18 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->hide();
                o->image( input_connector_image ? input_connector_image : input_connector_image = new Fl_PNG_Image( "input_connector", img_io_input_connector_10x10_png, img_io_input_connector_10x10_png_len ) );
     
            }        

            { Fl_Box *o = new Fl_Box( x() + 10, y(), w() - 20, h() );
                Fl_Group::current()->resizable(o);
            }


            { Fl_Button *o = dec_button = new Fl_Button( 0, 0, 12, h(), "-" );
                o->callback( cb_button, this );
                o->labelsize(10);
                o->labelfont( FL_HELVETICA_BOLD );
                o->hide();
            }        
            { Fl_Button *o = inc_button = new Fl_Button( 0,0, 12, h(), "+" );
                o->labelsize(10);
                o->labelfont( FL_HELVETICA_BOLD );
                o->callback( cb_button, this );
                o->hide();
            }

            { Fl_Box *o = output_connection_handle = new Fl_Box( x(), y(), 12, 12 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->image( output_connector_image ? output_connector_image : output_connector_image = new Fl_PNG_Image( "output_connector", img_io_output_connector_10x10_png, img_io_output_connector_10x10_png_len ) );
                o->hide();
            }

            { Fl_Box *o = output_connection2_handle = new Fl_Box( x(), y(), 12, 12 );
                o->tooltip( "Drag and drop to make and break JACK connections.");
                o->image( output_connector_image ? output_connector_image : output_connector_image = new Fl_PNG_Image( "output_connector", img_io_output_connector_10x10_png, img_io_output_connector_10x10_png_len ) );
                o->hide();
            }

            o->end();
        }

        {
            Fl_Browser *o = connection_display = new Fl_Browser( 0, 0, w(), h() );
            o->has_scrollbar(Fl_Browser_::VERTICAL);
            o->textsize( 10 );
            o->textcolor( FL_LIGHT3 );
            o->textfont( FL_COURIER );
            o->box( FL_FLAT_BOX );
            o->color( FL_DARK1 );
            // o->color( fl_color_add_alpha( fl_rgb_color( 10, 10, 10 ), 100 ));
            
            Fl_Group::current()->resizable(o);
        }
        o->end();
        resizable(o);
    }
    end();    
}
예제 #25
0
파일: main.c 프로젝트: nbastin/ivs
int
main(int argc, char *argv[])
{
    sk = create_genl_socket();
    sk2 = create_genl_socket();

    /* Resolve generic netlink families. */
    ovs_datapath_family = genl_ctrl_resolve(sk, OVS_DATAPATH_FAMILY);
    ovs_packet_family = genl_ctrl_resolve(sk, OVS_PACKET_FAMILY);
    ovs_vport_family = genl_ctrl_resolve(sk, OVS_VPORT_FAMILY);
    ovs_flow_family = genl_ctrl_resolve(sk, OVS_FLOW_FAMILY);
    if (ovs_datapath_family < 0 || ovs_packet_family < 0 ||
        ovs_vport_family < 0 || ovs_flow_family < 0) {
        fprintf(stderr, "Failed to resolve Open vSwitch generic netlink families; module not loaded?\n");
        return 1;
    }

    parse_options(argc, argv);

    argc -= optind;
    argv += optind;

    if (argc < 1) {
        help();
        return 1;
    }

    const char *cmd = argv[0];

    if (!strcmp(cmd, "help")) {
        help();
    } else if (!strcmp(cmd, "show")) {
        show();
    } else if (!strcmp(cmd, "add-port") ||!strcmp(cmd, "add-if")) {
        if (argc != 2) {
            fprintf(stderr, "Wrong number of arguments for the %s command (try help)\n", cmd);
            return 1;
        }
        add_port(datapath_name, argv[1]);
    } else if (!strcmp(cmd, "add-internal-port")) {
        if (argc != 2) {
            fprintf(stderr, "Wrong number of arguments for the %s command (try help)\n", cmd);
            return 1;
        }
        add_internal_port(datapath_name, argv[1]);
    } else if (!strcmp(cmd, "del-port") ||!strcmp(cmd, "del-if")) {
        if (argc != 2) {
            fprintf(stderr, "Wrong number of arguments for the %s command (try help)\n", cmd);
            return 1;
        }
        del_port(datapath_name, argv[1]);
    } else if (!strcmp(cmd, "del-br") ||!strcmp(cmd, "del-dp")) {
        if (argc != 1) {
            fprintf(stderr, "Wrong number of arguments for the %s command (try help)\n", cmd);
            return 1;
        }
        del_dp(datapath_name);
    } else {
        fprintf(stderr, "Unknown command '%s' (try help)\n", cmd);
        return 1;
    }

    return 0;
}
예제 #26
0
/** attempt to transform this controller into a spatialization
    controller and connect to the given module's spatialization
    control inputs. Returns true on success, false if given module
    does not accept spatialization inputs. */
bool
Controller_Module::connect_spatializer_to ( Module *m )
{
    /* these are for detecting related parameter groups which can be
       better represented by a single control */
    Port *azimuth_port = NULL;
    float azimuth_value = 0.0f;
    Port *elevation_port = NULL;
    float elevation_value = 0.0f;

    for ( unsigned int i = 0; i < m->control_input.size(); ++i )
    {
        Port *p = &m->control_input[i];

        if ( !strcasecmp( "Azimuth", p->name() ) &&
             180.0f == p->hints.maximum &&
             -180.0f == p->hints.minimum )
        {
            azimuth_port = p;
            azimuth_value = p->control_value();
            continue;
        }
        else if ( !strcasecmp( "Elevation", p->name() ) &&
                  90.0f == p->hints.maximum &&
                  -90.0f == p->hints.minimum )
        {
            elevation_port = p;
            elevation_value = p->control_value();
            continue;
        }
    }

    if ( ! ( azimuth_port && elevation_port ) )
        return false;

    control_output.clear();
    add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
    add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );

    control_output[0].connect_to( azimuth_port );
    control_output[1].connect_to( elevation_port );

    {
        clear();

        Panner *o = new Panner( 0,0, 100, 100 );

        o->box(FL_THIN_UP_BOX);
        o->color(FL_GRAY0);
        o->selection_color(FL_BACKGROUND_COLOR);
        o->labeltype(FL_NORMAL_LABEL);
        o->labelfont(0);
        o->labelcolor(FL_FOREGROUND_COLOR);
        o->align(FL_ALIGN_TOP);
        o->when(FL_WHEN_CHANGED);
        label( "Spatialization" );

        o->align(FL_ALIGN_TOP);
        o->labelsize( 10 );
//        o->callback( cb_panner_value_handle, new callback_data( this, azimuth_port_number, elevation_port_number ) );

        o->point( 0 )->azimuth( azimuth_value );
        o->point( 0 )->elevation( elevation_value );

        o->callback( cb_spatializer_handle, this );

        control = (Fl_Valuator*)o;

        if ( _pad )
        {
            Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( o );
            flg->position( x(), y() );
            flg->set_visible_focus();
            size( flg->w(), flg->h() );
            add( flg );
        }
        else
        {
            o->resize( x(), y(), w(), h() );
            add( o );
            resizable( o );
            init_sizes();
        }

        _type = SPATIALIZATION;
        return true;
    }
}
예제 #27
0
bool
Spatializer_Module::configure_inputs ( int n )
{
    output_connection_handle->show();
    output_connection_handle->tooltip( "Late Reverb" );
    output_connection2_handle->show();
    output_connection2_handle->tooltip( "Early Reverb" );

    int on = audio_input.size();

    if ( n > on )
    {
        for ( int i = n - on; i--; )
        {
            {    filter *o = new filter();
                o->sample_rate( sample_rate() );
                _lowpass.push_back( o );
            }

            {
                filter *o = new filter();
                o->sample_rate( sample_rate() );
                _highpass.push_back( o );
            }
            {
                delay *o = new delay( max_distance / 340.29f );
                o->sample_rate( sample_rate() );
                _delay.push_back( o );
            }

            add_port( Port( this, Port::INPUT, Port::AUDIO ) );
        }
    }
    else if ( n < on )
    {

        for ( int i = on - n; i--; )
        {
            delete _lowpass.back();
            _lowpass.pop_back();
            delete _highpass.back();
            _highpass.pop_back();
            delete _delay.back();
            _delay.pop_back();

            audio_input.pop_back();
        }
    }

//    control_input[4].hints.visible = audio_input.size() == 2;

    control_input[4].hints.default_value = audio_input.size() == 2 ? 90.0f : 0.0f;

    if ( n == 0 )
    {
        remove_aux_audio_outputs();
        audio_output.clear();
        audio_input.clear();
    }
    else
    {
        if ( audio_output.size() != 4 )
        {
            for ( int i = 0; i < 4; i++ )
            {
                add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
            }
        }

        if ( aux_audio_output.size() != 5 )
        {
            add_aux_audio_output( "late reverb", 0 );
            add_aux_audio_output( "early reverb", 0 );
            add_aux_audio_output( "early reverb", 1 );
            add_aux_audio_output( "early reverb", 2 );
            add_aux_audio_output( "early reverb", 3 );
        }
    }

    _connection_handle_outputs[0][0] = 0;
    _connection_handle_outputs[0][1] = 1;
    _connection_handle_outputs[1][0] = 1;
    _connection_handle_outputs[1][1] = aux_audio_output.size();

    return true;
}
예제 #28
0
Spatializer_Module::Spatializer_Module ( ) : JACK_Module ( false )
{
    is_default( false );

    _panner = 0;
    _early_panner = 0;

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Azimuth" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = -180.0f;
        p.hints.maximum = 180.0f;
        p.hints.default_value = 0.0f;

        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Elevation" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = -90.0f;
        p.hints.maximum = 90.0f;
        p.hints.default_value = 0.0f;

        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Radius" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = 0.0f;
        p.hints.maximum = max_distance;
        p.hints.default_value = 1.0f;

        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Highpass (Hz)" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = 0.0f;
        p.hints.maximum = 600.0f;
        p.hints.default_value = 0.0f;
        p.hints.visible = false;

        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Width" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = -90.0f;
        p.hints.maximum = 90.0f;
        p.hints.default_value = 90.0f;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Angle" );
        p.hints.type = Port::Hints::LINEAR;
        p.hints.ranged = true;
        p.hints.minimum = -180.0f;
        p.hints.maximum = +180.0f;
        p.hints.default_value = 0.0f;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Advanced Options" );
        p.hints.type = Port::Hints::BOOLEAN;
        p.hints.ranged = true;
        p.hints.minimum = 0.0f;
        p.hints.maximum = 1.0f;
        p.hints.default_value = 0.0f;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Speed of Sound" );
        p.hints.type = Port::Hints::BOOLEAN;
        p.hints.ranged = true;
        p.hints.minimum = 0.0f;
        p.hints.maximum = 1.0f;
        p.hints.default_value = 1.0f;
        p.hints.visible = false;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Late Gain (dB)" );
        p.hints.type = Port::Hints::LOGARITHMIC;
        p.hints.ranged = true;
        p.hints.minimum = -70.0f;
        p.hints.maximum = 6.0f;
        p.hints.default_value = 0.0f;
        p.hints.visible = false;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    {
        Port p( this, Port::INPUT, Port::CONTROL, "Early Gain (dB)" );
        p.hints.type = Port::Hints::LOGARITHMIC;
        p.hints.ranged = true;
        p.hints.minimum = -70.0f;
        p.hints.maximum = 6.0f;
        p.hints.default_value = 0.0f;
        p.hints.visible = false;
        p.connect_to( new float );
        p.control_value( p.hints.default_value );

        add_port( p );
    }

    log_create();

    _panner = new ambisonic_panner();
    _early_panner = new ambisonic_panner();

    labelsize(9);

    color( FL_DARK1 );

    copy_label( "Spatializer" );
    align(FL_ALIGN_LEFT|FL_ALIGN_TOP|FL_ALIGN_INSIDE);

    gain_smoothing.sample_rate( sample_rate() );
    late_gain_smoothing.sample_rate( sample_rate() );
    early_gain_smoothing.sample_rate( sample_rate() );
    delay_smoothing.cutoff( 0.5f );
    delay_smoothing.sample_rate( sample_rate() );
}
예제 #29
0
int
main(int argc, char* argv[])
{
    int rv = 0;
    char veth_name[16];
    int n_veth;

    CHECK(bmi_port_create_mgr(&port_mgr));

    srand (time(NULL));

    parse_options(argc, argv);

    /*************************************************************
     * Check for root access as uses veth interfaces
     * @fixme allow specifying vpi names as runtime config
     ************************************************************/
    if (geteuid() != 0) {
        fprintf(stderr, "This uses (v)eth interfaces; run under sudo\n");
        return 1;
    }

    if (!dpid) {
        int r1 = rand();
        int r2 = rand();
        dpid = (((uint64_t) r1) << 32) | ((uint64_t) r2);
    }

    if (!pd_server_str) {
        fprintf(stderr, "No PD RPC server address specified, "
                "using 127.0.0.1:%u\n", PD_SERVER_DEFAULT_PORT);
        parse_connection("127.0.0.1", &pd_server_addr, PD_SERVER_DEFAULT_PORT);
    } else {
        if (parse_connection(pd_server_str, &pd_server_addr,
                             PD_SERVER_DEFAULT_PORT) != 0)
            return -1;
        fprintf(stderr, "PD server address is %s:%u\n",
                pd_server_addr.ip, pd_server_addr.port);
    }

    if (!listener_str) {
        fprintf(stderr, "No listener specified, switch will run in "
                "standalone mode\n");
        if (p4nsdb_str) {
            fprintf(stderr, "P4NSDB will be ignored\n");
            free(p4nsdb_str);
            p4nsdb_str = NULL;
        }
    }

    /*************************************************************
     * Initialize Modules.
     ************************************************************/

    rmt_init();
    rmt_logger_set((p4_logging_f) printf);
    rmt_log_level_set(P4_LOG_LEVEL_TRACE);
    rmt_transmit_register(transmit_wrapper);

    /* Start up the PD RPC server */
    CHECK(start_p4_pd_rpc_server(pd_server_addr.port));

    /* Start up the API RPC server */
#ifdef SWITCHAPI_ENABLE
    CHECK(switch_api_init(0));
    CHECK(start_switch_api_rpc_server());
    CHECK(start_switch_api_packet_driver());
#endif /* SWITCHAPI_DISABLE */

#ifdef SWITCHSAI_ENABLE
    CHECK(start_p4_sai_thrift_rpc_server(SWITCH_SAI_THRIFT_RPC_SERVER_PORT));
#endif /*SWITCHSAI_ENABLE */

#ifdef SWITCHLINK_ENABLE
    CHECK(switchlink_init());
#endif /* SWITCHLINK_ENABLE */

    if (!listener_str && !no_veth) {  /* standalone mode */
        for (n_veth = 0; n_veth < NUM_VETH_INTERFACES; n_veth++) {
            sprintf(veth_name, "veth%d", n_veth*2);
            char pcap_filename[1024];
            pcap_filename[0] = 0;
            if (dump_pcap) {
                snprintf(pcap_filename, 1024,
                         "p4ns.%s-port%.2d.pcap", datapath_name, n_veth);
            }
            CHECK(bmi_port_interface_add(port_mgr, veth_name, n_veth,
                                         pcap_filename));
        }
    }

#ifdef SWITCHAPI_ENABLE
    if (!listener_str) {
        // add CPU port, port 64
        char pcap_filename[1024];
        pcap_filename[0] = 0;
        if (dump_pcap) {
            snprintf(pcap_filename, 1024,
                     "p4ns.%s-port%.2d.pcap", datapath_name, 64);
        }
        CHECK(bmi_port_interface_add(port_mgr, "veth250", 64, pcap_filename));
    }
#endif /* SWITCHAPI_ENABLE */

    if (listener_str) {
        parse_connection(listener_str, &listener_addr, 0);
        if(listener_addr.port == 0) {
            fprintf(stderr, "No port was specified for the listener");
            return -1;
        }

        if (!p4nsdb_str) {
            fprintf(stderr, "No p4nsdb address specified, using 127.0.0.1:%u\n",
                    P4NSDB_DEFAULT_PORT);
            parse_connection("127.0.0.1", &p4nsdb_addr, P4NSDB_DEFAULT_PORT);
        }
        else {
            if (parse_connection(p4nsdb_str, &p4nsdb_addr,
                                 P4NSDB_DEFAULT_PORT) != 0)
                return -1;
            fprintf(stderr, "p4nsdb address is %s:%u\n",
                    p4nsdb_addr.ip, p4nsdb_addr.port);
        }

        struct sigaction sa;
        sa.sa_handler = clean_up_on_signal;
        sigaction(SIGINT, &sa, &old_action_SIGINT);
        sigaction(SIGTERM, &sa, &old_action_SIGTERM);

        p4ns_db_cxt_t c = connect_to_p4nsdb();
        if (!c) return -1;
        if (p4ns_db_add_datapath(c, datapath_name, dpid)) {
            fprintf(stderr, "P4NSDB: could not create datapath, %s already "
                    "exists\n", datapath_name);
            return -1;
        }
        atexit(clean_up);
        p4ns_db_set_listener(c, datapath_name, &listener_addr);

        /* TODO: improve this code */
        uint16_t port_no = 0;
        /* Add interfaces from command line */
        struct entry *np;
        for (np = interfaces.tqh_first; np != NULL; np = np->entries.tqe_next) {
            printf("Adding interface %s (port %d)\n", np->str, port_no);
            if(add_port(np->str, port_no) < 0) {
                printf("Failed to add interface %s\n", np->str);
                return -1;
            }
            p4ns_db_add_port(c, datapath_name, np->str, port_no);
            port_no++;
        }

        p4ns_db_free(c);

        pthread_create(&ctl_listener_thread, NULL,
                       ctl_listen, (void *) &listener_addr);
    } else if (no_veth) {
        uint16_t port_no = 0;
        struct entry *np;
        for (np = interfaces.tqh_first; np != NULL; np = np->entries.tqe_next) {
            printf("Adding interface %s (port %d)\n", np->str, port_no);
            if(add_port(np->str, port_no) < 0) {
                printf("Failed to add interface %s\n", np->str);
                return -1;
            }
            port_no++;
        }
    }

    CHECK(bmi_set_packet_handler(port_mgr, packet_handler));

    while (1) pause();

    bmi_port_destroy_mgr(port_mgr);

    return rv;
}