example/generator/odp_generator.c
static int gen_send_thread(void *arg)
{
	int thr;
	int ret = 0;
	thread_args_t *thr_args;
	odp_pktout_queue_t pktout;
	odp_pktout_config_opt_t *pktout_cfg;
	odp_packet_t pkt_ref_array[MAX_UDP_TX_BURST];
	odp_packet_t pkt_array[MAX_UDP_TX_BURST];
	int pkt_array_size, seq_step;
	int burst_start, burst_size;
	setup_pkt_ref_fn_t setup_pkt_ref = NULL;
	setup_pkt_fn_t setup_pkt = NULL;
	void *setup_pkt_arg = NULL;
	counters_t *counters;
	uint64_t pkt_count_max = 0;

	thr = odp_thread_id();
	thr_args = arg;
	pktout = thr_args->tx.pktout;
	pktout_cfg = thr_args->tx.pktout_cfg;
	counters = &thr_args->counters;

	/* Create reference packets*/
	if (args->appl.mode == APPL_MODE_UDP) {
		setup_pkt_ref = setup_udp_pkt_ref;
		setup_pkt = setup_udp_pkt;
		seq_step = args->tx_burst_size * (args->thread_cnt - 1);
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number / args->thread_cnt +
				(args->appl.number % args->thread_cnt ? 1 : 0);
		setup_pkt_arg = &thr_args->tx.udp_param;
	} else if (args->appl.mode == APPL_MODE_PING) {
		setup_pkt_ref = setup_icmp_pkt_ref;
		setup_pkt = setup_icmp_pkt;
		seq_step = 0;
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number;
	} else {
		ODPH_ERR("  [%02i] Error: invalid processing mode %d\n", thr,
			 args->appl.mode);
		return -1;
	}
	pkt_array_size = args->tx_burst_size;

	if (setup_pkt_ref_array(thr_args->pool, pktout_cfg,
				pkt_ref_array, pkt_array_size,
				setup_pkt_ref)) {
		ODPH_ERR("[%02i] Error: failed to create reference packets\n",
			 thr);
		return -1;
	}

	printf("  [%02i] created mode: SEND\n", thr);

	odp_barrier_wait(&args->barrier);

	for (;;) {
		if (thr_args->stop)
			break;

		if (pkt_count_max && counters->ctr_pkt_snd > pkt_count_max) {
			sleep(1); /* wait for stop command */
			continue;
		}

		/* Setup TX burst*/
		if (setup_pkt_array(pktout_cfg, counters,
				    pkt_ref_array, pkt_array,
				    pkt_array_size, setup_pkt, setup_pkt_arg)) {
			ODPH_ERR("[%02i] Error: failed to setup packets\n",
				 thr);
			break;
		}

		/* Send TX burst*/
		for (burst_start = 0, burst_size = pkt_array_size;;) {
			ret = odp_pktout_send(pktout, &pkt_array[burst_start],
					      burst_size);
			if (ret == burst_size) {
				burst_size = 0;
				break;
			} else if (ret >= 0 && ret < burst_size) {
				thr_args->counters.ctr_pkt_snd_drop +=
					burst_size - ret;

				burst_start += ret;
				burst_size -= ret;
				continue;
			}
			ODPH_ERR("  [%02i] packet send failed\n", thr);
			odp_packet_free_multi(&pkt_array[burst_start],
					      burst_size);
			break;
		}

		counters->ctr_pkt_snd += pkt_array_size - burst_size;

		if (args->appl.interval != 0)
			odp_time_wait_ns((uint64_t)args->appl.interval *
					 ODP_TIME_MSEC_IN_NS);
		counters->ctr_seq += seq_step;
	}

	odp_packet_free_multi(pkt_ref_array, pkt_array_size);

	return 0;
}
/**
 * Packet IO loopback worker thread using ODP queues
 *
 * @param arg  thread arguments of type 'thread_args_t *'
 */
Packet IO loopback worker thread using ODP queues
@param arg  thread arguments of type 'thread_args_t *'
Packet IO loopback worker thread using ODP queues @param arg thread arguments of type ' thread_args_t * '
static int gen_send_thread(void *arg)
{
	int thr;
	int ret = 0;
	thread_args_t *thr_args;
	odp_pktout_queue_t pktout;
	odp_pktout_config_opt_t *pktout_cfg;
	odp_packet_t pkt_ref_array[MAX_UDP_TX_BURST];
	odp_packet_t pkt_array[MAX_UDP_TX_BURST];
	int pkt_array_size, seq_step;
	int burst_start, burst_size;
	setup_pkt_ref_fn_t setup_pkt_ref = NULL;
	setup_pkt_fn_t setup_pkt = NULL;
	void *setup_pkt_arg = NULL;
	counters_t *counters;
	uint64_t pkt_count_max = 0;
	thr = odp_thread_id();
	thr_args = arg;
	pktout = thr_args->tx.pktout;
	pktout_cfg = thr_args->tx.pktout_cfg;
	counters = &thr_args->counters;
	if (args->appl.mode == APPL_MODE_UDP) {
		setup_pkt_ref = setup_udp_pkt_ref;
		setup_pkt = setup_udp_pkt;
		seq_step = args->tx_burst_size * (args->thread_cnt - 1);
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number / args->thread_cnt +
				(args->appl.number % args->thread_cnt ? 1 : 0);
		setup_pkt_arg = &thr_args->tx.udp_param;
	} else if (args->appl.mode == APPL_MODE_PING) {
		setup_pkt_ref = setup_icmp_pkt_ref;
		setup_pkt = setup_icmp_pkt;
		seq_step = 0;
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number;
	} else {
		ODPH_ERR("  [%02i] Error: invalid processing mode %d\n", thr,
			 args->appl.mode);
		return -1;
	}
	pkt_array_size = args->tx_burst_size;
	if (setup_pkt_ref_array(thr_args->pool, pktout_cfg,
				pkt_ref_array, pkt_array_size,
				setup_pkt_ref)) {
		ODPH_ERR("[%02i] Error: failed to create reference packets\n",
			 thr);
		return -1;
	}
	printf("  [%02i] created mode: SEND\n", thr);
	odp_barrier_wait(&args->barrier);
	for (;;) {
		if (thr_args->stop)
			break;
		if (pkt_count_max && counters->ctr_pkt_snd > pkt_count_max) {
			sleep(1); 
			continue;
		}
		if (setup_pkt_array(pktout_cfg, counters,
				    pkt_ref_array, pkt_array,
				    pkt_array_size, setup_pkt, setup_pkt_arg)) {
			ODPH_ERR("[%02i] Error: failed to setup packets\n",
				 thr);
			break;
		}
		for (burst_start = 0, burst_size = pkt_array_size;;) {
			ret = odp_pktout_send(pktout, &pkt_array[burst_start],
					      burst_size);
			if (ret == burst_size) {
				burst_size = 0;
				break;
			} else if (ret >= 0 && ret < burst_size) {
				thr_args->counters.ctr_pkt_snd_drop +=
					burst_size - ret;
				burst_start += ret;
				burst_size -= ret;
				continue;
			}
			ODPH_ERR("  [%02i] packet send failed\n", thr);
			odp_packet_free_multi(&pkt_array[burst_start],
					      burst_size);
			break;
		}
		counters->ctr_pkt_snd += pkt_array_size - burst_size;
		if (args->appl.interval != 0)
			odp_time_wait_ns((uint64_t)args->appl.interval *
					 ODP_TIME_MSEC_IN_NS);
		counters->ctr_seq += seq_step;
	}
	odp_packet_free_multi(pkt_ref_array, pkt_array_size);
	return 0;
}
static int gen_send_thread ( void * arg ) { int thr ; int ret = 0 ; thread_args_t * thr_args ; odp_pktout_queue_t pktout ; odp_pktout_config_opt_t * pktout_cfg ; odp_packet_t pkt_ref_array [ MAX_UDP_TX_BURST ] ; odp_packet_t pkt_array [ MAX_UDP_TX_BURST ] ; int pkt_array_size , seq_step ; int burst_start , burst_size ; setup_pkt_ref_fn_t setup_pkt_ref = NULL ; setup_pkt_fn_t setup_pkt = NULL ; void * setup_pkt_arg = NULL ; counters_t * counters ; uint64_t pkt_count_max = 0 ; thr = odp_thread_id ( ) ; thr_args = arg ; pktout = thr_args -> tx . pktout ; pktout_cfg = thr_args -> tx . pktout_cfg ; counters = & thr_args -> counters ; if ( args -> appl . mode == APPL_MODE_UDP ) { setup_pkt_ref = setup_udp_pkt_ref ; setup_pkt = setup_udp_pkt ; seq_step = args -> tx_burst_size * ( args -> thread_cnt - 1 ) ; if ( args -> appl . number != -1 ) pkt_count_max = args -> appl . number / args -> thread_cnt + ( args -> appl . number % args -> thread_cnt ? 1 : 0 ) ; setup_pkt_arg = & thr_args -> tx . udp_param ; } else if ( args -> appl . mode == APPL_MODE_PING ) { setup_pkt_ref = setup_icmp_pkt_ref ; setup_pkt = setup_icmp_pkt ; seq_step = 0 ; if ( args -> appl . number != -1 ) pkt_count_max = args -> appl . number ; } else { ODPH_ERR ( " \n " , thr , args -> appl . mode ) ; return -1 ; } pkt_array_size = args -> tx_burst_size ; if ( setup_pkt_ref_array ( thr_args -> pool , pktout_cfg , pkt_ref_array , pkt_array_size , setup_pkt_ref ) ) { ODPH_ERR ( " \n " , thr ) ; return -1 ; } printf ( " \n " , thr ) ; odp_barrier_wait ( & args -> barrier ) ; for ( ; ; ) { if ( thr_args -> stop ) break ; if ( pkt_count_max && counters -> ctr_pkt_snd > pkt_count_max ) { sleep ( 1 ) ; continue ; } if ( setup_pkt_array ( pktout_cfg , counters , pkt_ref_array , pkt_array , pkt_array_size , setup_pkt , setup_pkt_arg ) ) { ODPH_ERR ( " \n " , thr ) ; break ; } for ( burst_start = 0 , burst_size = pkt_array_size ; ; ) { ret = odp_pktout_send ( pktout , & pkt_array [ burst_start ] , burst_size ) ; if ( ret == burst_size ) { burst_size = 0 ; break ; } else if ( ret >= 0 && ret < burst_size ) { thr_args -> counters . ctr_pkt_snd_drop += burst_size - ret ; burst_start += ret ; burst_size -= ret ; continue ; } ODPH_ERR ( " \n " , thr ) ; odp_packet_free_multi ( & pkt_array [ burst_start ] , burst_size ) ; break ; } counters -> ctr_pkt_snd += pkt_array_size - burst_size ; if ( args -> appl . interval != 0 ) odp_time_wait_ns ( ( uint64_t ) args -> appl . interval * ODP_TIME_MSEC_IN_NS ) ; counters -> ctr_seq += seq_step ; } odp_packet_free_multi ( pkt_ref_array , pkt_array_size ) ; return 0 ; }
Packet IO loopback worker thread using ODP queues
 @param arg  thread arguments of type 'thread_args_t *'
Packet IO loopback worker thread using ODP queues @param arg thread arguments of type ' thread_args_t * '
/* Create reference packets*/ /* wait for stop command */ /* Setup TX burst*/ /* Send TX burst*/