Beispiel #1
0
void stat_signal(int origin_signal)
{
    struct ps_queue queue;
    uint64_t during;
    struct ps_handle handle = handles[my_cpu];
    static time_t last_sec = 0;
    static char first = 1;
    /*static long last_rx_bytes = 0;
    static long last_rx_pkts = 0;
    long diff_time = 0;
    double pps = 0.0, bps = 0.0;
    */

    gettimeofday(&end, NULL);
    if(end.tv_sec <= last_sec)
        return;
    //diff_time = end.tv_sec - last_sec;

    get_microsecond(&during, &start, &end);
    if(SIGINT == origin_signal || !first) {
        printf("xge%d:queue %d: bps: %3.5lf Gbps, pps: %3.5lf Mpps, rx chunks: %ld rx pkts: %ld, rx bytes: %ld, mean pkt per chunk: %lf\n",
		    	devices_attached[0], my_cpu,
                (handle.rx_bytes[my_cpu] + handle.rx_packets[my_cpu] * 24.0) * 8.0 / during / 1000,
                handle.rx_packets[my_cpu] * 1.0 / during,
                handle.rx_chunks[my_cpu],
                handle.rx_packets[my_cpu],
                handle.rx_bytes[my_cpu],
                handle.rx_packets[my_cpu] * 1.0 / handle.rx_chunks[my_cpu]);

        /*bps = handle.rx_bytes[my_cpu] - last_rx_bytes;
        last_rx_bytes = handle.rx_bytes[my_cpu];
        pps = handle.rx_packets[my_cpu] - last_rx_pkts;
        last_rx_pkts = handle.rx_packets[my_cpu];

        bps += pps * 24;
        bps = bps * 8;
        bps /= diff_time*1000000000;
        pps /= diff_time*1000000;
        printf("xge%d: queue %d: bps: %3.5lf Gbps, pps: %3.5lf Mpps\n",
                devices_attached[0], my_cpu, bps, pps);
        */
        if(SIGINT == origin_signal) {
            queue.ifindex = devices_attached[0];
            queue.qidx = my_cpu;
            ps_detach_rx_device(&handle, &queue);
            ps_close_handle(&handle);
            signal(SIGINT, SIG_DFL);
            kill(getpid(), SIGINT);
        }
    }
    
    //if(end.tv_sec > last_sec) {
        first = 0;
        last_sec = end.tv_sec;
    //}
}
Beispiel #2
0
void echo()
{
	struct ps_handle *handle = &handles[my_cpu];
	struct ps_chunk chunk;

	int i;
	int working = 0;

	assert(ps_init_handle(handle) == 0);

	for (i = 0; i < num_devices_attached; i++) {
		struct ps_queue queue;
		if (devices[devices_attached[i]].num_rx_queues <= my_cpu)
			continue;

		if (devices[devices_attached[i]].num_tx_queues <= my_cpu) {
			printf("WARNING: xge%d has not enough TX queues!\n",
					devices_attached[i]);
			continue;
		}

		working = 1;
		queue.ifindex = devices_attached[i];
		queue.qidx = my_cpu;

		printf("attaching RX queue xge%d:%d to CPU%d\n", queue.ifindex, queue.qidx, my_cpu);
		assert(ps_attach_rx_device(handle, &queue) == 0);
	}

	if (!working)
		goto done;

	assert(ps_alloc_chunk(handle, &chunk) == 0);

	chunk.recv_blocking = 1;

	for (;;) {
		int ret;
		
		chunk.cnt = 64;
		ret = ps_recv_chunk(handle, &chunk);

		if (ret < 0) {
			if (errno == EINTR)
				continue;

			if (!chunk.recv_blocking && errno == EWOULDBLOCK)
				break;

			assert(0);
		}

		if (!sink) {
			chunk.cnt = ret;
			ret = ps_send_chunk(handle, &chunk);
			assert(ret >= 0);
		}
	}

done:
	ps_close_handle(handle);
}
Beispiel #3
0
void send_packets(long packets,
                  int chunk_size,
                  int packet_size,
                  int num_flows)
{
    struct ps_handle *handle = &handles[my_cpu];
    struct ps_chunk chunk;
    char packet[MAX_FLOWS][MAX_PACKET_SIZE];
    int ret;

    int i, j;
    unsigned int next_flow[MAX_DEVICES];

    long sent = 0;
    uint64_t seed = 0;

    if (num_flows == 0)
        seed = time(NULL) + my_cpu;

    for (i = 0; i < num_flows; i++) {
        if (ip_version == 4)
            build_packet(packet[i], packet_size, &seed);
        else if (ip_version == 6)
            build_packet_v6(packet[i], packet_size, &seed);
    }

    assert(ps_init_handle(handle) == 0);

    for (i = 0; i < num_devices_registered; i++)
        next_flow[i] = 0;

    assert(ps_alloc_chunk(handle, &chunk) == 0);
    chunk.queue.qidx = my_cpu; /* CPU_i holds queue_i */

    assert(chunk.info);

    while (1) {
        int working = 0;

        for (i = 0; i < num_devices_registered; i++) {
            chunk.queue.ifindex = devices_registered[i];
            working = 1;

            for (j = 0; j < chunk_size; j++) {
                chunk.info[j].len = packet_size;
                chunk.info[j].offset = j * ALIGN(packet_size, 64);

                if (num_flows == 0) {
                    if (ip_version == 4) {
                        build_packet(chunk.buf + chunk.info[j].offset,
                                     packet_size, &seed);
                    } else {
                        build_packet_v6(chunk.buf + chunk.info[j].offset,
                                        packet_size, &seed);
                    }

                }
                else
                    memcpy_aligned(chunk.buf + chunk.info[j].offset,
                                   packet[(next_flow[i] + j) % num_flows],
                                   packet_size);
            }

            if (packets - sent < chunk_size)
                chunk.cnt = packets - sent;
            else
                chunk.cnt = chunk_size;

            ret = ps_send_chunk(handle, &chunk);
            assert(ret >= 0);

            update_stats(handle);
            sent += ret;

            if (packets <= sent)
                done();

            if (num_flows)
                next_flow[i] = (next_flow[i] + ret) % num_flows;
        }

        if (!working)
            break;
    }

    ps_close_handle(handle);
}
Beispiel #4
0
void echo()
{
	struct ps_handle *handle = &handles[my_cpu];
	struct ps_chunk chunk;

	int i;
	int working = 0;

	assert(ps_init_handle(handle) == 0);

	for (i = 0; i < num_devices_attached; i++) {
		struct ps_queue queue;
		if (devices[devices_attached[i]].num_rx_queues <= my_cpu)
			continue;

		if (devices[devices_attached[i]].num_tx_queues <= my_cpu) {
			printf("WARNING: xge%d has not enough TX queues!\n",
					devices_attached[i]);
			continue;
		}

		working = 1;
		queue.ifindex = devices_attached[i];
		queue.qidx = my_cpu;

		printf("attaching RX queue xge%d:%d to CPU%d\n", queue.ifindex, queue.qidx, my_cpu);
		assert(ps_attach_rx_device(handle, &queue) == 0);
	}

	if (!working)
		goto done;

	assert(ps_alloc_chunk(handle, &chunk) == 0);

	chunk.recv_blocking = 1;

	for (;;) {
		int ret, i, j;
		struct ethhdr *eth;

		chunk.cnt = 64;
		ret = ps_recv_chunk(handle, &chunk);

		if (ret < 0) {
			if (errno == EINTR)
				continue;

			if (!chunk.recv_blocking && errno == EWOULDBLOCK)
				break;

			assert(0);
		}

		if (!echo_as_is) {
			for (i = 0; i < ret; i++) {
				char tmp[6];
				bool drop = true;
				eth = (struct ethhdr *)chunk.buf + chunk.info[i].offset;

				if (!sink)
					for (j = 0; j < num_devices_attached; j++) {
						drop &= !(memcmp(devices[j].dev_addr, eth->h_dest, ETH_ALEN) == 0);
					}

				if (drop) {
					chunk.info[i].offset = -1;
				} else {
					memcpy(tmp, eth->h_dest, 6);
					memcpy(eth->h_dest, eth->h_source, 6);
					memcpy(eth->h_source, tmp, 6);
				}
			}
		}

		if (!sink) {
			chunk.cnt = ret;
			ret = ps_send_chunk(handle, &chunk);
			assert(ret >= 0);
		}
	}

done:
	ps_close_handle(handle);
}