Beispiel #1
0
/**
 * @internal Worker thread
 *
 * @param ptr  Pointer to test arguments
 *
 * @return Pointer to exit status
 */
static void *run_thread(void *ptr)
{
	int thr;
	odp_pool_t msg_pool;
	test_globals_t *gbls;

	gbls = ptr;
	thr  = odp_thread_id();

	printf("Thread %i starts on cpu %i\n", thr, odp_cpu_id());

	/*
	 * Find the pool
	 */
	msg_pool = odp_pool_lookup("msg_pool");

	if (msg_pool == ODP_POOL_INVALID) {
		EXAMPLE_ERR("  [%i] msg_pool not found\n", thr);
		return NULL;
	}

	odp_barrier_wait(&gbls->test_barrier);

	test_abs_timeouts(thr, gbls);


	printf("Thread %i exits\n", thr);
	fflush(NULL);
	return NULL;
}
Beispiel #2
0
void* thread_stat_routine(void *arg)
{
    int i;
    while(1)
    {
        sleep(5);
        i = system("clear");
        printf("Port statistics(on cpu %d)\n", odp_cpu_id());
        for(i = 0; i < glb_param.nic.num; i++)
        {
            printf("Port %d:\n", i);
            printf(">>>>>>>>recv: %llu\n", (unsigned long long)port_stat.stat[i].recv);
            printf(">>>>>>>>send: %llu\n", (unsigned long long)port_stat.stat[i].send);
            printf(">>>>>>>>drop: %llu\n", (unsigned long long)port_stat.stat[i].drop);
            printf("====================\n");
        }
    }
}
Beispiel #3
0
static void *pkt_io_recv(void *arg)
{
	odp_pktin_queue_t pktin;
	odp_packet_t pkt, pkt_tbl[PKT_BURST_SIZE];
	int pkt_idx, pkt_cnt;
	struct pktio_thr_arg *thr_args;
	ofp_pkt_processing_func pkt_func;

	thr_args = arg;
	pkt_func = thr_args->pkt_func;
	pktin = thr_args->pktin;

	if (ofp_init_local()) {
		OFP_ERR("Error: OFP local init failed.\n");
		return NULL;
	}

	OFP_DBG("PKT-IO receive starting on cpu: %d", odp_cpu_id());

	while (1) {
		pkt_cnt = odp_pktin_recv(pktin, pkt_tbl, PKT_BURST_SIZE);

		for (pkt_idx = 0; pkt_idx < pkt_cnt; pkt_idx++) {
			pkt = pkt_tbl[pkt_idx];

			if (odp_unlikely(odp_packet_has_error(pkt))) {
				OFP_DBG("Packet with error dropped.\n");
				odp_packet_free(pkt);
				continue;
			}

			ofp_packet_input(pkt, ODP_QUEUE_INVALID, pkt_func);
		}
		ofp_send_pending_pkt();
	}

	/* Never reached */
	return NULL;
}
Beispiel #4
0
/* Initialise per-thread memory */
static per_thread_mem_t *thread_init(void)
{
	global_shared_mem_t *global_mem;
	per_thread_mem_t *per_thread_mem;
	odp_shm_t global_shm;
	uint32_t per_thread_mem_len;

	per_thread_mem_len = sizeof(per_thread_mem_t);
	per_thread_mem = malloc(per_thread_mem_len);
	memset(per_thread_mem, 0, per_thread_mem_len);

	per_thread_mem->delay_counter = 1;

	per_thread_mem->thread_id = odp_thread_id();
	per_thread_mem->thread_core = odp_cpu_id();

	global_shm = odp_shm_lookup(GLOBAL_SHM_NAME);
	global_mem = odp_shm_addr(global_shm);
	CU_ASSERT_PTR_NOT_NULL(global_mem);

	per_thread_mem->global_mem = global_mem;

	return per_thread_mem;
}
Beispiel #5
0
static void thread_test_odp_cpu_id(void)
{
	(void)odp_cpu_id();
	CU_PASS();
}
Beispiel #6
0
/* Copyright (c) 2015, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#include <test_debug.h>
#include <odp.h>
#include <odp/helper/linux.h>

#define NUMBER_WORKERS 16
static void *worker_fn(void *arg TEST_UNUSED)
{
	/* depend on the odp helper to call odp_init_local */

	printf("Worker thread on CPU %d\n", odp_cpu_id());

	/* depend on the odp helper to call odp_term_local */

	return 0;
}

/* Create additional dataplane threads */
int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
{
	odph_linux_pthread_t thread_tbl[NUMBER_WORKERS];
	odp_cpumask_t cpu_mask;
	int num_workers;
	int cpu;
	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
Beispiel #7
0
/* for local debug */
void ofp_print_packet_buffer(const char *comment, uint8_t *p)
{
	static int first = 1;
	FILE *f;
	struct ofp_ip *ip;
	uint16_t proto;
	char *g;

/*
 * Filter "noise"
 */
#if 0
	if (p[12] == 0x00 && p[13] == 0x27)
		return;
	if (p[12] == 0x01 && p[13] == 0x98)
		return;
#endif
	if (first) {
		f = fopen(DEFAULT_DEBUG_TXT_FILE_NAME, "w");
		fclose(f);
		first = 0;
	}

	f = fopen(DEFAULT_DEBUG_TXT_FILE_NAME, "a");

	if (!f)
		return;

	static struct timeval tv0;
	struct timeval tv;

	gettimeofday(&tv, NULL);
	if (tv0.tv_sec == 0)
		tv0 = tv;
	int ms = (tv.tv_sec*1000+tv.tv_usec/1000) -
		(tv0.tv_sec*1000+tv0.tv_usec/1000);

	ofp_printf(f, "\n*************\n");
	ofp_printf(f, "[%d] %s: %d.%03d\n", odp_cpu_id(), comment,
		       ms/1000, ms%1000);
	ofp_printf(f, "%s ->%s\n  ", ofp_print_mac(p+6), ofp_print_mac(p));

	if (p[12] == 0x81 && p[13] == 0x00) {
		ofp_printf(f, "VLAN %d ", (p[14]<<8)|p[15]);
		p += 4;
	}

	if (p[12] == 0x88 && p[13] == 0x47) {
		uint8_t *label = p+14;
		int i;

		ofp_printf(f, "MPLS ");
		while (1) {
			ofp_printf(f, "[label=%d ttl=%d] ",
				label[0]*16*256 + label[1]*16 + label[2]/16,
				label[3]);
			if (label[2] & 1)
				break;
			label += 4;
		}

		if ((label[4] & 0xf0) == 0x40) {
			label[2] = 0x08; /* ipv4 */
			label[3] = 0x00;
		} else {
			label[2] = 0x86; /* ipv6 */
			label[3] = 0xdd;
		}

		label++;
		for (i = 0; i < 12; i++)
			*label-- = p[11 - i];
		p = label+1;
	}

	if (p[12] == 0x08 && p[13] == 0x06) {
		print_arp(f, (char *)(p + L2_HEADER_NO_VLAN_SIZE));
	} else if (p[12] == 0x86 && p[13] == 0xdd) {
		print_ipv6(f, (char *)(p + L2_HEADER_NO_VLAN_SIZE));
	} else if (p[12] == 0x08 && p[13] == 0x00) {
		ip = (struct ofp_ip *)(p + L2_HEADER_NO_VLAN_SIZE);

		if (ip->ip_p == 47) { /* GRE */
			g = ((char *)ip) + (ip->ip_hl << 2);
			g += print_gre(f, g, &proto);
			if (proto == 0x0800)
				print_ipv4(f, g);
			else if (proto == 0x86dd)
				print_ipv6(f, g);
		} else
			print_ipv4(f, (char *)(p + L2_HEADER_NO_VLAN_SIZE));
	} else {
		ofp_printf(f, "UNKNOWN ETH PACKET TYPE 0x%02x%02x ",
			p[12], p[13]);
	}

	ofp_printf(f, "\n");
	fclose(f);
	fflush(stdout);
}
Beispiel #8
0
void* thread_fwd_routine(void *arg)
{
    odp_packet_t pkt_tbl[PACKET_IO_BURST];
    int rv_nb, sd_nb;
    int thr_id;
    int out_port;
    int tuple[5];
    int i;

    thr_id = odp_thread_id();
    printf("fwd thread %d start(on cpu %d)\n", thr_id, odp_cpu_id());
    //match to port id
    thr_id--;

    memset(&port_stat.stat[thr_id], 0 , 3 * sizeof(uint64_t));
    for(;;)
    {
        rv_nb = odp_pktio_recv(thr_data.nic_hdl[thr_id], pkt_tbl, 
                PACKET_IO_BURST);
        port_stat.stat[thr_id].recv += rv_nb;
#ifdef EXECUTE_CLASSIFICATION
        for(i = 0; i < rv_nb; i++)
        {
            if(extract_tuple(pkt_tbl[i], tuple) == 0)
            {
                int res;
                res = packet_classifier_search(tuple);
            }
        }
#endif
#ifdef EXECUTE_HASH_LOOKUP
        for(i = 0; i < rv_nb; i++)
        {
            if(extract_tuple(pkt_tbl[i], tuple) == 0)
            {
                int res;
                res = odph_hash_lookup(hs_tbl, (void*)tuple);
            }
        }
#endif
#ifdef EXECUTE_DPI
        unsigned char *payload;
        int payload_len;
        for(i = 0; i < rv_nb; i++)
        {
            if(get_payload(pkt_tbl[i], (unsigned char**)&payload, &payload_len) == 0)
            {
                int res;
		//printf("%d %d %s\n", thr_id, strlen(payload), payload);
                res = sm_search(sm_hdl, payload, payload_len);
                //printf("search res: %d\n", res);
            }
        }
#endif
        if((thr_id & 1) == 1)
        {
            out_port = thr_id - 1;
        }
        else
        {
            out_port = thr_id + 1 == glb_param.nic.num ? thr_id : thr_id + 1;
        }
        sd_nb = odp_pktio_send(thr_data.nic_hdl[out_port], pkt_tbl, rv_nb);
        port_stat.stat[thr_id].send += sd_nb;
        while(sd_nb < rv_nb)
        {
            odp_packet_free(pkt_tbl[sd_nb++]);
            port_stat.stat[thr_id].drop++;
        }
    }
    return NULL;
}