Пример #1
0
/**
 * Main init function for the multi-process server app,
 * calls subfunctions to do each stage of the initialisation.
 */
int
init(int argc, char *argv[])
{
	int retval;
	const struct rte_memzone *mz;
	uint8_t i, total_ports;

	/* init EAL, parsing EAL args */
	retval = rte_eal_init(argc, argv);
	if (retval < 0)
		return -1;
	argc -= retval;
	argv += retval;

	/* initialise the nic drivers */
	retval = init_drivers();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot initialise drivers\n");

	/* get total number of ports */
	total_ports = rte_eth_dev_count();

	/* set up array for port data */
	mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports),
				rte_socket_id(), NO_FLAGS);
	if (mz == NULL)
		rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n");
	memset(mz->addr, 0, sizeof(*ports));
	ports = mz->addr;

	/* parse additional, application arguments */
	retval = parse_app_args(total_ports, argc, argv);
	if (retval != 0)
		return -1;

	/* initialise mbuf pools */
	retval = init_mbuf_pools();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

	/* now initialise the ports we will use */
	for (i = 0; i < ports->num_ports; i++) {
		retval = init_port(ports->id[i]);
		if (retval != 0)
			rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n",
					(unsigned)i);
	}

	check_all_ports_link_status(ports->num_ports, (~0x0));

	/* initialise the client queues/rings for inter-eu comms */
	init_shm_rings();

	return 0;
}
Пример #2
0
static void
app_init_nics(void)
{
	unsigned socket;
	uint32_t lcore;
	uint16_t port;
	uint8_t queue;
	int ret;
	uint32_t n_rx_queues, n_tx_queues;

	/* Init NIC ports and queues, then start the ports */
	for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
		struct rte_mempool *pool;
		uint16_t nic_rx_ring_size;
		uint16_t nic_tx_ring_size;
		struct rte_eth_rxconf rxq_conf;
		struct rte_eth_txconf txq_conf;
		struct rte_eth_dev_info dev_info;
		struct rte_eth_conf local_port_conf = port_conf;

		n_rx_queues = app_get_nic_rx_queues_per_port(port);
		n_tx_queues = app.nic_tx_port_mask[port];

		if ((n_rx_queues == 0) && (n_tx_queues == 0)) {
			continue;
		}

		/* Init port */
		printf("Initializing NIC port %u ...\n", port);
		rte_eth_dev_info_get(port, &dev_info);
		if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
			local_port_conf.txmode.offloads |=
				DEV_TX_OFFLOAD_MBUF_FAST_FREE;

		local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
			dev_info.flow_type_rss_offloads;
		if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
				port_conf.rx_adv_conf.rss_conf.rss_hf) {
			printf("Port %u modified RSS hash function based on hardware support,"
				"requested:%#"PRIx64" configured:%#"PRIx64"\n",
				port,
				port_conf.rx_adv_conf.rss_conf.rss_hf,
				local_port_conf.rx_adv_conf.rss_conf.rss_hf);
		}

		ret = rte_eth_dev_configure(
			port,
			(uint8_t) n_rx_queues,
			(uint8_t) n_tx_queues,
			&local_port_conf);
		if (ret < 0) {
			rte_panic("Cannot init NIC port %u (%d)\n", port, ret);
		}
		rte_eth_promiscuous_enable(port);

		nic_rx_ring_size = app.nic_rx_ring_size;
		nic_tx_ring_size = app.nic_tx_ring_size;
		ret = rte_eth_dev_adjust_nb_rx_tx_desc(
			port, &nic_rx_ring_size, &nic_tx_ring_size);
		if (ret < 0) {
			rte_panic("Cannot adjust number of descriptors for port %u (%d)\n",
				  port, ret);
		}
		app.nic_rx_ring_size = nic_rx_ring_size;
		app.nic_tx_ring_size = nic_tx_ring_size;

		rxq_conf = dev_info.default_rxconf;
		rxq_conf.offloads = local_port_conf.rxmode.offloads;
		/* Init RX queues */
		for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) {
			if (app.nic_rx_queue_mask[port][queue] == 0) {
				continue;
			}

			app_get_lcore_for_nic_rx(port, queue, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			pool = app.lcore_params[lcore].pool;

			printf("Initializing NIC port %u RX queue %u ...\n",
				port, queue);
			ret = rte_eth_rx_queue_setup(
				port,
				queue,
				(uint16_t) app.nic_rx_ring_size,
				socket,
				&rxq_conf,
				pool);
			if (ret < 0) {
				rte_panic("Cannot init RX queue %u for port %u (%d)\n",
					  queue, port, ret);
			}
		}

		txq_conf = dev_info.default_txconf;
		txq_conf.offloads = local_port_conf.txmode.offloads;
		/* Init TX queues */
		if (app.nic_tx_port_mask[port] == 1) {
			app_get_lcore_for_nic_tx(port, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			printf("Initializing NIC port %u TX queue 0 ...\n",
				port);
			ret = rte_eth_tx_queue_setup(
				port,
				0,
				(uint16_t) app.nic_tx_ring_size,
				socket,
				&txq_conf);
			if (ret < 0) {
				rte_panic("Cannot init TX queue 0 for port %d (%d)\n",
					port,
					ret);
			}
		}

		/* Start port */
		ret = rte_eth_dev_start(port);
		if (ret < 0) {
			rte_panic("Cannot start port %d (%d)\n", port, ret);
		}
	}

	check_all_ports_link_status(APP_MAX_NIC_PORTS, (~0x0));
}
Пример #3
0
int
main(int argc, char **argv)
{
    //struct lcore_queue_conf *qconf = NULL;
    //struct rte_eth_dev_info dev_info;
    struct lcore_env** envs;
    int ret;
    uint8_t n_ports;
    unsigned lcore_count;

    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
    argc -= ret;
    argv += ret;

    ret = l2sw_parse_args(argc, argv);
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "Invalid MARIO arguments\n");

    lcore_count = rte_lcore_count();
    n_ports = rte_eth_dev_count();
    //RTE_LOG(INFO, MARIO, "Find %u logical cores\n" , lcore_count);

    mbuf_pool = rte_mempool_create("mbuf_pool", NB_MBUF, MBUF_SIZE,
                                   32, sizeof(struct rte_pktmbuf_pool_private),
                                   rte_pktmbuf_pool_init, NULL,
                                   rte_pktmbuf_init, NULL,
                                   rte_socket_id(), 0);

    if (mbuf_pool == NULL)
        rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");

// init route_table
    route_table = create_route_table(ROUTE_ENTRY_SIZE);
    add_staticroute(route_table);

// init arp_table
    arp_table = create_arp_table(ARP_ENTRY_SIZE);



    n_ports = rte_eth_dev_count();
    if (n_ports == 0)
        rte_exit(EXIT_FAILURE, "No Ethernet ports - byte\n");
    //RTE_LOG(INFO, MARIO, "Find %u ethernet ports\n", n_ports);

    if (n_ports > RTE_MAX_ETHPORTS)
        n_ports = RTE_MAX_ETHPORTS;

    /* Each logical core is assigned a dedicated TX queue on each port. */
    /*
    for(uint8_t port_id = 0; port_id < n_ports; port_id++) {
      rte_eth_dev_info_get(port_id, &dev_info);
    }
    */
    /* Initialize the port/queue configuration of each logical core */
    /*
    for(uint8_t port_id = 0; port_id < n_ports; port_id++) {
      ;
    }
    */

    /* Initialize lcore_env */
    envs = (struct lcore_env**) rte_malloc(NULL,sizeof(struct lcore_env*),0);
    if (envs == NULL)
        rte_exit(EXIT_FAILURE, "Cannot allocate memory for core envs\n");

    uint8_t lcore_id;
    for (lcore_id = 0; lcore_id < lcore_count; lcore_id++) {
        struct lcore_env* env;
        env = (struct lcore_env*) rte_malloc(NULL,sizeof(struct lcore_env) +
                                             sizeof(struct mbuf_table) *n_ports,0);
        if (env == NULL)
            rte_exit(EXIT_FAILURE,
                     "Cannot allocate memory for %u core env\n", lcore_id);
        env->n_port = n_ports;
        env->lcore_id = lcore_id;
        memset(env->tx_mbufs, 0, sizeof(struct mbuf_table) * n_ports);
        envs[lcore_id] = env;
    }

    /* Initialise each port */
    uint8_t port_id;
    for(port_id = 0; port_id < n_ports; port_id++) {
        //RTE_LOG(INFO, MARIO, "Initializing port %u...", port_id);
        fflush(stdout);
        ret = rte_eth_dev_configure(port_id, lcore_count, lcore_count, &port_conf);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
                     ret, (unsigned)port_id);
        //RTE_LOG(INFO, MARIO, "done\n");
        rte_eth_macaddr_get(port_id, &port2eth[port_id]);

        /* init one RX queue */
        uint8_t core_id;
        for (core_id = 0; core_id < lcore_count; core_id++) {
            ret = rte_eth_rx_queue_setup(port_id, core_id, nb_rxd,
                                         rte_eth_dev_socket_id(port_id),
                                         NULL,
                                         mbuf_pool);
            if (ret < 0)
                rte_exit(EXIT_FAILURE,
                         "rte_eth_rx_queue_setup:err=%d, port=%u queue=%u\n",
                         ret, (unsigned) port_id, (unsigned) core_id);
        }

        /* init one TX queue */
        for (core_id = 0; core_id < lcore_count; core_id++) {
            ret = rte_eth_tx_queue_setup(port_id, core_id, nb_txd,
                                         rte_eth_dev_socket_id(port_id), NULL);
            if (ret < 0)
                rte_exit(EXIT_FAILURE,
                         "rte_eth_tx_queue_setup:err=%d, port=%u queue=%u\n",
                         ret, (unsigned) port_id, (unsigned) core_id);
        }

        /* Start device */
        ret = rte_eth_dev_start(port_id);
        if (ret < 0)
            rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
                     ret, (unsigned) port_id);

        rte_eth_promiscuous_enable(port_id);

        /*RTE_LOG(INFO, MARIO,
                "Port %u, MAC address %02x:%02x:%02x:%02x:%02x:%02x\n\n",
                port_id,
                port2eth[port_id].addr_bytes[0],
                port2eth[port_id].addr_bytes[1],
                port2eth[port_id].addr_bytes[2],
                port2eth[port_id].addr_bytes[3],
                port2eth[port_id].addr_bytes[4],
                port2eth[port_id].addr_bytes[5]);
        */
        memset(&port_statistics, 0, sizeof(port_statistics));
    }

    check_all_ports_link_status(n_ports);


    /* launch per-lcore init on every lcore */
    rte_eal_mp_remote_launch(l2sw_launch_one_lcore, envs, CALL_MASTER);
    {
        uint8_t lcore_id;
        RTE_LCORE_FOREACH_SLAVE(lcore_id) {
            if (rte_eal_wait_lcore(lcore_id) < 0)
                return -1;
        }
    }

    rte_free(arp_table);
    rte_free(route_table);

    return 0;
}
Пример #4
0
/**
 * Main init function for the multi-process server app,
 * calls subfunctions to do each stage of the initialisation.
 */
int
init(int argc, char *argv[])
{
	int retval;
	const struct rte_memzone *mz;
	unsigned i, total_ports;

	/* init EAL, parsing EAL args */
	retval = rte_eal_init(argc, argv);
	if (retval < 0)
		return -1;
	argc -= retval;
	argv += retval;

	/* get total number of ports */
	total_ports = rte_eth_dev_count();

	/* set up array for port data */
	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
	{
		mz = rte_memzone_lookup(MZ_PORT_INFO);
		if (mz == NULL)
			rte_exit(EXIT_FAILURE, "Cannot get port info structure\n");
		ports = mz->addr;
	}
	else /* RTE_PROC_PRIMARY */
	{
		mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports),
					rte_socket_id(), NO_FLAGS);
		if (mz == NULL)
			rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n");
		memset(mz->addr, 0, sizeof(*ports));
		ports = mz->addr;
	}

	/* parse additional, application arguments */
	retval = parse_app_args(total_ports, argc, argv);
	if (retval != 0)
		return -1;

	/* initialise mbuf pools */
	retval = init_mbuf_pools();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

	/* now initialise the ports we will use */	
	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
	{
		for (i = 0; i < ports->num_ports; i++) {
			retval = init_port(ports->id[i]);
			if (retval != 0)
				rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n",
						(unsigned)i);
		}
	}
	check_all_ports_link_status(ports->num_ports, (~0x0));

	/* initialise the client queues/rings for inter-eu comms */
	
	init_shm_rings();
	
	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
	{
		RTE_LOG(INFO, APP, "HOST SHARE MEM Init.\n");
		/* create metadata, output cmdline 
		if (rte_hostshmem_metadata_create(HOSTSHMEM_METADATA_NAME) < 0)
			rte_exit(EXIT_FAILURE, "Cannot create HOSTSHMEM metadata\n");
		if (rte_hostshmem_metadata_add_memzone(mz, HOSTSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add memzone to HOSTSHMEM metadata\n");					
		if (rte_hostshmem_metadata_add_mempool(pktmbuf_pool, HOSTSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to HOSTSHMEM metadata\n");	
		for (i = 0; i < num_clients; i++) 
		{
			if (rte_hostshmem_metadata_add_ring(clients[i].rx_q,
					HOSTSHMEM_METADATA_NAME) < 0)
				rte_exit(EXIT_FAILURE, "Cannot add ring client %d to HOSTSHMEM metadata\n", i);
		}
		generate_hostshmem_cmdline(HOSTSHMEM_METADATA_NAME);
		*/
		
		const struct rte_mem_config *mcfg;
		/* get pointer to global configuration */
		mcfg = rte_eal_get_configuration()->mem_config;

		for (i = 0; i < RTE_MAX_MEMSEG; i++) {
			if (mcfg->memseg[i].addr == NULL)
				break;

			printf("Segment %u: phys:0x%"PRIx64", len:%zu, "
				   "virt:%p, socket_id:%"PRId32", "
				   "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", "
				   "nrank:%"PRIx32"\n", i,
				   mcfg->memseg[i].phys_addr,
				   mcfg->memseg[i].len,
				   mcfg->memseg[i].addr,
				   mcfg->memseg[i].socket_id,
				   mcfg->memseg[i].hugepage_sz,
				   mcfg->memseg[i].nchannel,
				   mcfg->memseg[i].nrank);
		}
		
		RTE_LOG(INFO, APP, "HOST SHARE MEM Init. done\n");
		
		RTE_LOG(INFO, APP, "IV SHARE MEM Init.\n");
		/* create metadata, output cmdline */
		if (rte_ivshmem_metadata_create(IVSHMEM_METADATA_NAME) < 0)
			rte_exit(EXIT_FAILURE, "Cannot create IVSHMEM metadata\n");	
		if (rte_ivshmem_metadata_add_memzone(mz, IVSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add memzone to IVSHMEM metadata\n");					
		if (rte_ivshmem_metadata_add_mempool(pktmbuf_pool, IVSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to IVSHMEM metadata\n");				
		
		for (i = 0; i < num_clients; i++) 
		{
			if (rte_ivshmem_metadata_add_ring(clients[i].rx_q,
					IVSHMEM_METADATA_NAME) < 0)
				rte_exit(EXIT_FAILURE, "Cannot add ring client %d to IVSHMEM metadata\n", i);
		}
		generate_ivshmem_cmdline(IVSHMEM_METADATA_NAME);
		RTE_LOG(INFO, APP, "IV SHARE MEM Done.\n");
	}
	
	
	return 0;
}
Пример #5
0
static void
app_init_nics(void)
{
	unsigned socket;
	uint32_t lcore;
	uint8_t port, queue;
	int ret;
	uint32_t n_rx_queues, n_tx_queues;

	/* Init driver */
	printf("Initializing the PMD driver ...\n");
	if (rte_pmd_init_all() < 0) {
		rte_panic("Cannot init PMD\n");
	}

	if (rte_eal_pci_probe() < 0) {
		rte_panic("Cannot probe PCI\n");
	}

	/* Init NIC ports and queues, then start the ports */
	for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
		struct rte_mempool *pool;

		n_rx_queues = app_get_nic_rx_queues_per_port(port);
		n_tx_queues = app.nic_tx_port_mask[port];

		if ((n_rx_queues == 0) && (n_tx_queues == 0)) {
			continue;
		}

		/* Init port */
		printf("Initializing NIC port %u ...\n", (unsigned) port);
		ret = rte_eth_dev_configure(
			port,
			(uint8_t) n_rx_queues,
			(uint8_t) n_tx_queues,
			&port_conf);
		if (ret < 0) {
			rte_panic("Cannot init NIC port %u (%d)\n", (unsigned) port, ret);
		}
		rte_eth_promiscuous_enable(port);

		/* Init RX queues */
		for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) {
			if (app.nic_rx_queue_mask[port][queue] == 0) {
				continue;
			}

			app_get_lcore_for_nic_rx(port, queue, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			pool = app.lcore_params[lcore].pool;

			printf("Initializing NIC port %u RX queue %u ...\n",
				(unsigned) port,
				(unsigned) queue);
			ret = rte_eth_rx_queue_setup(
				port,
				queue,
				(uint16_t) app.nic_rx_ring_size,
				socket,
				&rx_conf,
				pool);
			if (ret < 0) {
				rte_panic("Cannot init RX queue %u for port %u (%d)\n",
					(unsigned) queue,
					(unsigned) port,
					ret);
			}
		}

		/* Init TX queues */
		if (app.nic_tx_port_mask[port] == 1) {
			app_get_lcore_for_nic_tx(port, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			printf("Initializing NIC port %u TX queue 0 ...\n",
				(unsigned) port);
			ret = rte_eth_tx_queue_setup(
				port,
				0,
				(uint16_t) app.nic_tx_ring_size,
				socket,
				&tx_conf);
			if (ret < 0) {
				rte_panic("Cannot init TX queue 0 for port %d (%d)\n",
					port,
					ret);
			}
		}

		/* Start port */
		ret = rte_eth_dev_start(port);
		if (ret < 0) {
			rte_panic("Cannot start port %d (%d)\n", port, ret);
		}
	}

	check_all_ports_link_status(APP_MAX_NIC_PORTS, (~0x0));
}
Пример #6
0
/**
 * Main init function for the multi-process distributor app,
 * calls subfunctions to do each stage of the initialisation.
 */
int
init(int argc, char *argv[])
{
	int retval;
	const struct rte_memzone *mz;
	uint8_t i, total_ports;

	/* init EAL, parsing EAL args */
	retval = rte_eal_init(argc, argv);
	if (retval < 0)
		return -1;
	argc -= retval;
	argv += retval;

	/* get total number of ports */
	total_ports = rte_eth_dev_count();

	/* set up array for port data */
	mz = rte_memzone_reserve(MZ_SHARED_INFO, sizeof(*info),
				rte_socket_id(), NO_FLAGS);
	if (mz == NULL)
		rte_exit(EXIT_FAILURE, "Cannot reserve memory zone "
				"for port information\n");
	memset(mz->addr, 0, sizeof(*info));
	info = mz->addr;

	/* parse additional, application arguments */
	retval = parse_app_args(total_ports, argc, argv);
	if (retval != 0)
		return -1;

	/* initialise mbuf pools */
	retval = init_mbuf_pools();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

	/* now initialise the ports we will use */
	for (i = 0; i < info->num_ports; i++) {
		retval = init_port(info->id[i]);
		if (retval != 0)
			rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n",
					(unsigned int) i);
	}

	check_all_ports_link_status(info->num_ports, (~0x0));

	/* initialise the node queues/rings for inter-eu comms */
	init_shm_rings();

	/* Create the flow distributor table */
	create_flow_distributor_table();

	/* Populate the flow distributor table */
	populate_flow_distributor_table();

	/* Share the total number of nodes */
	info->num_nodes = num_nodes;

	/* Share the total number of flows */
	info->num_flows = num_flows;
	return 0;
}
Пример #7
0
static int
test_pmd_perf(void)
{
	uint16_t nb_ports, num, nb_lcores, slave_id = (uint16_t)-1;
	uint16_t nb_rxd = MAX_TRAFFIC_BURST;
	uint16_t nb_txd = MAX_TRAFFIC_BURST;
	uint16_t portid;
	uint16_t nb_rx_queue = 1, nb_tx_queue = 1;
	int socketid = -1;
	int ret;

	printf("Start PMD RXTX cycles cost test.\n");

	signal(SIGUSR1, signal_handler);
	signal(SIGUSR2, signal_handler);

	nb_ports = rte_eth_dev_count();
	if (nb_ports < NB_ETHPORTS_USED) {
		printf("At least %u port(s) used for perf. test\n",
		       NB_ETHPORTS_USED);
		return -1;
	}

	if (nb_ports > RTE_MAX_ETHPORTS)
		nb_ports = RTE_MAX_ETHPORTS;

	nb_lcores = rte_lcore_count();

	memset(lcore_conf, 0, sizeof(lcore_conf));
	init_lcores();

	init_mbufpool(NB_MBUF);

	if (sc_flag == SC_CONTINUOUS) {
		nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
		nb_txd = RTE_TEST_TX_DESC_DEFAULT;
	}
	printf("CONFIG RXD=%d TXD=%d\n", nb_rxd, nb_txd);

	reset_count();
	num = 0;
	for (portid = 0; portid < nb_ports; portid++) {
		if (socketid == -1) {
			socketid = rte_eth_dev_socket_id(portid);
			slave_id = alloc_lcore(socketid);
			if (slave_id == (uint16_t)-1) {
				printf("No avail lcore to run test\n");
				return -1;
			}
			printf("Performance test runs on lcore %u socket %u\n",
			       slave_id, socketid);
		}

		if (socketid != rte_eth_dev_socket_id(portid)) {
			printf("Skip port %d\n", portid);
			continue;
		}

		/* port configure */
		ret = rte_eth_dev_configure(portid, nb_rx_queue,
					    nb_tx_queue, &port_conf);
		if (ret < 0)
			rte_exit(EXIT_FAILURE,
				"Cannot configure device: err=%d, port=%d\n",
				 ret, portid);

		rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
		printf("Port %u ", portid);
		print_ethaddr("Address:", &ports_eth_addr[portid]);
		printf("\n");

		/* tx queue setup */
		ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
					     socketid, &tx_conf);
		if (ret < 0)
			rte_exit(EXIT_FAILURE,
				"rte_eth_tx_queue_setup: err=%d, "
				"port=%d\n", ret, portid);

		/* rx queue steup */
		ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd,
						socketid, &rx_conf,
						mbufpool[socketid]);
		if (ret < 0)
			rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: err=%d,"
				 "port=%d\n", ret, portid);

		/* Start device */
		stop = 0;
		ret = rte_eth_dev_start(portid);
		if (ret < 0)
			rte_exit(EXIT_FAILURE,
				"rte_eth_dev_start: err=%d, port=%d\n",
				ret, portid);

		/* always eanble promiscuous */
		rte_eth_promiscuous_enable(portid);

		lcore_conf[slave_id].portlist[num++] = portid;
		lcore_conf[slave_id].nb_ports++;
	}
	check_all_ports_link_status(nb_ports, RTE_PORT_ALL);

	if (tx_burst == NULL) {
		tx_burst = (struct rte_mbuf **)
			rte_calloc_socket("tx_buff",
					  MAX_TRAFFIC_BURST * nb_ports,
					  sizeof(void *),
					  RTE_CACHE_LINE_SIZE, socketid);
		if (!tx_burst)
			return -1;
	}

	init_traffic(mbufpool[socketid],
		     tx_burst, MAX_TRAFFIC_BURST * nb_ports);

	printf("Generate %d packets @socket %d\n",
	       MAX_TRAFFIC_BURST * nb_ports, socketid);

	if (sc_flag == SC_CONTINUOUS) {
		/* do both rxtx by default */
		if (NULL == do_measure)
			do_measure = measure_rxtx;

		rte_eal_remote_launch(main_loop, NULL, slave_id);

		if (rte_eal_wait_lcore(slave_id) < 0)
			return -1;
	} else if (sc_flag == SC_BURST_POLL_FIRST ||
		   sc_flag == SC_BURST_XMIT_FIRST)
		if (exec_burst(sc_flag, slave_id) < 0)
			return -1;

	/* port tear down */
	for (portid = 0; portid < nb_ports; portid++) {
		if (socketid != rte_eth_dev_socket_id(portid))
			continue;

		rte_eth_dev_stop(portid);
	}

	return 0;
}
Пример #8
0
int
init(int argc, char *argv[]) {
        int retval;
        const struct rte_memzone *mz_nf;
        const struct rte_memzone *mz_port;
        const struct rte_memzone *mz_cores;
        const struct rte_memzone *mz_scp;
        const struct rte_memzone *mz_services;
        const struct rte_memzone *mz_nf_per_service;
        uint8_t i, total_ports, port_id;

        /* init EAL, parsing EAL args */
        retval = rte_eal_init(argc, argv);
        if (retval < 0)
                return -1;
        argc -= retval;
        argv += retval;

#ifdef RTE_LIBRTE_PDUMP
        rte_pdump_init(NULL);
#endif

        /* get total number of ports */
        total_ports = rte_eth_dev_count_avail();

        /* set up array for NF tx data */
        mz_nf = rte_memzone_reserve(MZ_NF_INFO, sizeof(*nfs) * MAX_NFS,
                                rte_socket_id(), NO_FLAGS);
        if (mz_nf == NULL)
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for nf information\n");
        memset(mz_nf->addr, 0, sizeof(*nfs) * MAX_NFS);
        nfs = mz_nf->addr;

        /* set up ports info */
        mz_port = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports),
                                    rte_socket_id(), NO_FLAGS);
        if (mz_port == NULL)
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n");
        ports = mz_port->addr;
  
        /* set up core status */
        mz_cores = rte_memzone_reserve(MZ_CORES_STATUS, sizeof(*cores) * onvm_threading_get_num_cores(),
                                    rte_socket_id(), NO_FLAGS);
        if (mz_cores == NULL)
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for core information\n");
        memset(mz_cores->addr, 0, sizeof(*cores) * 64);
        cores = mz_cores->addr;

        /* set up array for NF tx data */
        mz_services = rte_memzone_reserve(MZ_SERVICES_INFO, sizeof(uint16_t *) * num_services, rte_socket_id(), NO_FLAGS);
        if (mz_services == NULL)
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for services information\n");
        services = mz_services->addr;
        for (i = 0; i < num_services; i++) {
                services[i] = rte_calloc("one service NFs",
                        MAX_NFS_PER_SERVICE, sizeof(uint16_t), 0);
        }
        mz_nf_per_service = rte_memzone_reserve(MZ_NF_PER_SERVICE_INFO, sizeof(uint16_t) * num_services, rte_socket_id(), NO_FLAGS);
        if (mz_nf_per_service == NULL) {
                rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for NF per service information.\n");
        }
        nf_per_service_count = mz_nf_per_service->addr;

        /* parse additional, application arguments */
        retval = parse_app_args(total_ports, argc, argv);
        if (retval != 0)
                return -1;

        /* initialise mbuf pools */
        retval = init_mbuf_pools();
        if (retval != 0)
                rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

        /* initialise nf info pool */
        retval = init_nf_info_pool();
        if (retval != 0) {
                rte_exit(EXIT_FAILURE, "Cannot create nf info mbuf pool: %s\n", rte_strerror(rte_errno));
        }

        /* initialise pool for NF messages */
        retval = init_nf_msg_pool();
        if (retval != 0) {
                rte_exit(EXIT_FAILURE, "Cannot create nf message pool: %s\n", rte_strerror(rte_errno));
        }

        /* now initialise the ports we will use */
        for (i = 0; i < ports->num_ports; i++) {
                port_id = ports->id[i];
                rte_eth_macaddr_get(port_id, &ports->mac[port_id]);
                retval = init_port(port_id);
                if (retval != 0)
                        rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n", port_id);
                char event_msg_buf[20];
                sprintf(event_msg_buf, "Port %d initialized", port_id);
                onvm_stats_add_event(event_msg_buf, NULL);
        }

        check_all_ports_link_status(ports->num_ports, (~0x0));

        /* initialise the NF queues/rings for inter-eu comms */
        init_shm_rings();

        /* initialise a queue for newly created NFs */
        init_info_queue();

        /*initialize a default service chain*/
        default_chain = onvm_sc_create();
        retval = onvm_sc_append_entry(default_chain, ONVM_NF_ACTION_TONF, 1);
        if (retval == ENOSPC) {
                printf("chain length can not be larger than the maximum chain length\n");
                exit(1);
        }
        printf("Default service chain: send to sdn NF\n");

        /* set up service chain pointer shared to NFs*/
        mz_scp = rte_memzone_reserve(MZ_SCP_INFO, sizeof(struct onvm_service_chain *),
                                   rte_socket_id(), NO_FLAGS);
        if (mz_scp == NULL)
                rte_exit(EXIT_FAILURE, "Canot reserve memory zone for service chain pointer\n");
        memset(mz_scp->addr, 0, sizeof(struct onvm_service_chain *));
        default_sc_p = mz_scp->addr;
        *default_sc_p = default_chain;
        onvm_sc_print(default_chain);

        onvm_flow_dir_init();

        return 0;
}