Example #1
0
sai_status_t
sai_api_initialize(
    _In_ uint64_t flags,
    _In_ const service_method_table_t* services) {
    sai_status_t status =  SAI_STATUS_SUCCESS;
    unsigned int num_ports = 32;
    if(!initialized) {
        SAI_LOG(SAI_LOG_WARN, SAI_API_UNSPECIFIED, "INIT device");
#ifndef BMV2
        bmi_port_create_mgr(&port_mgr);
        rmt_init();
        rmt_logger_set((p4_logging_f) printf);
        status = load_config("port.cfg", &num_ports, &log_level);
        if(status != 0)
            return status;
        rmt_log_level_set(log_level);
        rmt_transmit_register(transmit_wrapper);
#endif
        switch_api_init(0, num_ports);
        start_switch_api_packet_driver();
        initialized = 1;
        sai_initialize();
#ifndef BMV2
        bmi_set_packet_handler(port_mgr, packet_handler);
#endif
    }

    services = &sai_services;
    return status;
}
Example #2
0
int init_smt(struct s_smc *smc, u_char *mac_addr)

{
	int	p ;

#if defined(DEBUG) && !defined(DEBUG_BRD)
	debug.d_smt = 0 ;
	debug.d_smtf = 0 ;
	debug.d_rmt = 0 ;
	debug.d_ecm = 0 ;
	debug.d_pcm = 0 ;
	debug.d_cfm = 0 ;

	debug.d_plc = 0 ;
#ifdef	ESS
	debug.d_ess = 0 ;
#endif
#ifdef	SBA
	debug.d_sba = 0 ;
#endif
#endif	

	
	for ( p = 0; p < NUMPHYS; p ++ ) {
		smc->y[p].mib = & smc->mib.p[p] ;
	}

	set_oem_spec_val(smc) ;	
	(void) smt_set_mac_opvalues(smc) ;
	init_fddi_driver(smc,mac_addr) ;	
	smt_fixup_mib(smc) ;		

	ev_init(smc) ;			
#ifndef	SLIM_SMT
	smt_init_evc(smc) ;		
#endif	
	smt_timer_init(smc) ;		
	smt_agent_init(smc) ;		

	pcm_init(smc) ;			
	ecm_init(smc) ;			
	cfm_init(smc) ;			
	rmt_init(smc) ;			

	for (p = 0 ; p < NUMPHYS ; p++) {
		pcm(smc,p,0) ;		
	}
	ecm(smc,0) ;			
	cfm(smc,0) ;			
	rmt(smc,0) ;			

	smt_agent_task(smc) ;		

        PNMI_INIT(smc) ;                

	return(0) ;
}
Example #3
0
/*
 * Init SMT
 */
int init_smt(struct s_smc *smc, u_char *mac_addr)
/* u_char *mac_addr;	canonical address or NULL */
{
	int	p ;

#if defined(DEBUG) && !defined(DEBUG_BRD)
	debug.d_smt = 0 ;
	debug.d_smtf = 0 ;
	debug.d_rmt = 0 ;
	debug.d_ecm = 0 ;
	debug.d_pcm = 0 ;
	debug.d_cfm = 0 ;

	debug.d_plc = 0 ;
#ifdef	ESS
	debug.d_ess = 0 ;
#endif
#ifdef	SBA
	debug.d_sba = 0 ;
#endif
#endif	/* DEBUG && !DEBUG_BRD */

	/* First initialize the ports mib->pointers */
	for ( p = 0; p < NUMPHYS; p ++ ) {
		smc->y[p].mib = & smc->mib.p[p] ;
	}

	set_oem_spec_val(smc) ;	
	(void) smt_set_mac_opvalues(smc) ;
	init_fddi_driver(smc,mac_addr) ;	/* HW driver */
	smt_fixup_mib(smc) ;		/* update values that depend on s.sas */

	ev_init(smc) ;			/* event queue */
#ifndef	SLIM_SMT
	smt_init_evc(smc) ;		/* evcs in MIB */
#endif	/* no SLIM_SMT */
	smt_timer_init(smc) ;		/* timer package */
	smt_agent_init(smc) ;		/* SMT frame manager */

	pcm_init(smc) ;			/* PCM state machine */
	ecm_init(smc) ;			/* ECM state machine */
	cfm_init(smc) ;			/* CFM state machine */
	rmt_init(smc) ;			/* RMT state machine */

	for (p = 0 ; p < NUMPHYS ; p++) {
		pcm(smc,p,0) ;		/* PCM A state machine */
	}
	ecm(smc,0) ;			/* ECM state machine */
	cfm(smc,0) ;			/* CFM state machine */
	rmt(smc,0) ;			/* RMT state machine */

	smt_agent_task(smc) ;		/* NIF FSM etc */

        PNMI_INIT(smc) ;                /* PNMI initialization */

	return(0) ;
}
Example #4
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;
}