21 #include <odp/helper/odph_api.h>
23 #define MAX_NAME_LEN 128
25 typedef struct test_global_t {
34 char pktio_name[MAX_NAME_LEN];
38 static test_global_t test_global;
40 static void print_usage(
void)
42 printf(
"This example prints out debug information on various ODP objects.\n"
43 "Select debug functions to be called with options. All listed functions\n"
44 "are called when no options are given.\n"
47 " -S, --system Call odp_sys_info_print() and odp_sys_config_print()\n"
48 " -s, --shm Create a SHM and call odp_shm_print()\n"
49 " -p, --pool Create various types of pools and call odp_pool_print()\n"
50 " -q, --queue Create various types of queues and call odp_queue_print()\n"
51 " -i, --interface <name> Start a packet IO interface, and call odp_pktio_print(),\n"
52 " odp_pktio_extra_stats_print(), etc. Uses loop interface by default.\n"
53 " -I, --ipsec Call odp_ipsec_print()\n"
54 " -t, --timer Call timer pool, timer and timeout print functions\n"
55 " -a, --stash Create stash and call odp_stash_print()\n"
56 " -h, --help Display help and exit.\n\n");
59 static int parse_options(
int argc,
char *argv[], test_global_t *global)
65 const struct option longopts[] = {
66 {
"system", no_argument, NULL,
'S'},
67 {
"shm", no_argument, NULL,
's'},
68 {
"pool", no_argument, NULL,
'p'},
69 {
"queue", no_argument, NULL,
'q'},
70 {
"interface", required_argument, NULL,
'i'},
71 {
"ipsec", no_argument, NULL,
'I'},
72 {
"timer", no_argument, NULL,
't'},
73 {
"stash", no_argument, NULL,
'a'},
74 {
"help", no_argument, NULL,
'h'},
77 const char *shortopts =
"+Sspqi:Itah";
81 opt = getopt_long(argc, argv, shortopts, longopts, NULL);
102 str_len = strlen(str);
104 if (str_len && str_len < MAX_NAME_LEN)
105 strcpy(global->pktio_name, str);
123 if (global->pktio && (str_len == 0 || str_len >= MAX_NAME_LEN)) {
124 ODPH_ERR(
"Bad interface name length: %u\n", str_len);
131 static int shm_debug(
void)
133 const char *name =
"debug_shm";
138 ODPH_ERR(
"SHM reserve failed: %s\n", name);
149 ODPH_ERR(
"SHM free failed: %s\n", name);
161 ODPH_ERR(
"Buffer alloc failed\n");
173 static int packet_debug(
odp_pool_t pool,
int len)
178 ODPH_ERR(
"Packet alloc failed\n");
193 static int pool_debug(
void)
200 name =
"debug_buffer_pool";
209 ODPH_ERR(
"Pool create failed: %s\n", name);
216 if (buffer_debug(pool))
220 ODPH_ERR(
"Pool destroy failed: %s\n", name);
224 name =
"debug_packet_pool";
234 ODPH_ERR(
"Pool create failed: %s\n", name);
241 if (packet_debug(pool, pkt_len))
245 ODPH_ERR(
"Pool destroy failed: %s\n", name);
249 name =
"debug_tmo_pool";
257 ODPH_ERR(
"Pool create failed: %s\n", name);
265 ODPH_ERR(
"Pool destroy failed: %s\n", name);
272 static int queue_debug(
void)
280 name =
"plain_queue";
287 ODPH_ERR(
"Queue create failed: %s\n", name);
294 name =
"parallel_sched_queue";
301 ODPH_ERR(
"Queue create failed: %s\n", name);
308 name =
"atomic_sched_queue";
315 ODPH_ERR(
"Queue create failed: %s\n", name);
328 for (i = 0; i < num; i++) {
330 ODPH_ERR(
"Queue destroy failed: %i\n", i);
338 static int pktio_debug(test_global_t *global)
344 uint8_t mac[ODPH_ETHADDR_LEN];
350 pool_param.
pkt.
len = pkt_len;
355 ODPH_ERR(
"Pool create failed\n");
362 ODPH_ERR(
"Pktio open failed\n");
368 ODPH_ERR(
"Packet input queue config failed\n");
373 ODPH_ERR(
"Packet output queue config failed\n");
378 ODPH_ERR(
"Pktio start failed\n");
382 printf(
"\nWaiting link up");
385 for (
int i = 0; i < 25; i++) {
396 printf(
"Packet IO\n---------\n");
401 printf(
" mac address: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2],
402 mac[3], mac[4], mac[5]);
411 printf(
"Link info\n---------\n");
412 printf(
" auto neg: %i\n", info.
autoneg);
413 printf(
" duplex: %i\n", info.
duplex);
414 printf(
" media: %s\n", info.
media);
415 printf(
" pause_rx: %i\n", info.
pause_rx);
416 printf(
" pause_tx: %i\n", info.
pause_tx);
417 printf(
" speed: %u Mbit/s\n", info.
speed);
418 printf(
" status: %i\n", info.
status);
428 ODPH_ERR(
"Pktio stop failed\n");
433 ODPH_ERR(
"Pktio close failed\n");
438 ODPH_ERR(
"Pool destroy failed\n");
445 static int ipsec_debug(
void)
453 static int timer_debug(
void)
479 ODPH_ERR(
"Pool create failed\n");
485 ODPH_ERR(
"Timeout alloc failed\n");
490 ODPH_ERR(
"Timer capa failed\n");
498 timer_res_capa.
max_tmo = max_tmo;
500 ODPH_ERR(
"Timer resolution capability failed\n");
504 if (timer_res_capa.
res_ns > res)
505 res = timer_res_capa.
res_ns;
509 timer_param.
min_tmo = max_tmo / 10;
517 ODPH_ERR(
"Timer pool create failed\n");
522 ODPH_ERR(
"Timer pool start failed\n");
532 ODPH_ERR(
"Queue create failed.\n");
541 timer =
odp_timer_alloc(timer_pool, queue, (
void *)(uintptr_t)0xdeadbeef);
549 start_param.
tick = tick;
550 start_param.
tmo_ev = event;
555 ODPH_ERR(
"Timer start failed.\n");
561 ODPH_ERR(
"Timer cancel failed\n");
573 ODPH_ERR(
"Timer free failed\n");
580 ODPH_ERR(
"Queue destroy failed\n");
585 ODPH_ERR(
"Pool destroy failed\n");
592 static int stash_debug(
void)
596 uint32_t val = 0xdeadbeef;
605 ODPH_ERR(
"Stash create failed\n");
610 ODPH_ERR(
"Stash put failed\n");
618 ODPH_ERR(
"Stash get failed\n");
623 ODPH_ERR(
"Stash destroy failed\n");
630 int main(
int argc,
char *argv[])
633 test_global_t *global = &test_global;
635 printf(
"ODP debug example\n\n");
636 memset(global, 0,
sizeof(test_global_t));
648 strcpy(global->pktio_name,
"loop");
650 if (parse_options(argc, argv, global))
655 ODPH_ERR(
"Global init failed.\n");
660 ODPH_ERR(
"Local init failed.\n");
666 ODPH_ERR(
"Schedule config failed\n");
670 if (global->system) {
678 if (global->shm && shm_debug()) {
679 ODPH_ERR(
"SHM debug failed.\n");
683 if (global->pool && pool_debug()) {
684 ODPH_ERR(
"Pool debug failed.\n");
688 if (global->queue && queue_debug()) {
689 ODPH_ERR(
"Queue debug failed.\n");
693 if (global->pktio && pktio_debug(global)) {
694 ODPH_ERR(
"Packet debug failed.\n");
698 if (global->ipsec && ipsec_debug()) {
699 ODPH_ERR(
"IPSEC debug failed.\n");
703 if (global->timer && timer_debug()) {
704 ODPH_ERR(
"Timer debug failed.\n");
708 if (global->stash && stash_debug()) {
709 ODPH_ERR(
"Stash debug failed.\n");
714 ODPH_ERR(
"Local term failed.\n");
719 ODPH_ERR(
"Global term failed.\n");
odp_buffer_t odp_buffer_alloc(odp_pool_t pool)
Buffer alloc.
void odp_buffer_free(odp_buffer_t buf)
Buffer free.
#define ODP_BUFFER_INVALID
Invalid buffer.
void odp_buffer_print(odp_buffer_t buf)
Print buffer metadata to STDOUT.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
void odp_ipsec_print(void)
Print global IPSEC configuration info.
int odp_pktio_mac_addr(odp_pktio_t pktio, void *mac_addr, int size)
Get the default MAC address of a packet IO interface.
uint64_t odp_pktio_ts_res(odp_pktio_t pktio)
Packet IO timestamp resolution in hertz.
int odp_pktio_promisc_mode(odp_pktio_t pktio)
Determine if promiscuous mode is enabled for a packet IO interface.
int odp_pktio_close(odp_pktio_t pktio)
Close a packet IO interface.
uint32_t odp_pktin_maxlen(odp_pktio_t pktio)
Maximum frame length at packet input.
int odp_pktio_link_info(odp_pktio_t pktio, odp_pktio_link_info_t *info)
Retrieve information about packet IO link status.
uint32_t odp_pktout_maxlen(odp_pktio_t pktio)
Maximum frame length at packet output.
void odp_pktio_extra_stats_print(odp_pktio_t pktio)
Print extra statistics for a packet IO interface.
odp_pktio_t odp_pktio_open(const char *name, odp_pool_t pool, const odp_pktio_param_t *param)
Open a packet IO interface.
void odp_pktio_print(odp_pktio_t pktio)
Print pktio info to the console.
int odp_pktio_start(odp_pktio_t pktio)
Start packet receive and transmit.
#define ODP_PKTIO_INVALID
Invalid packet IO handle.
int odp_pktio_stop(odp_pktio_t pktio)
Stop packet receive and transmit.
int odp_pktio_index(odp_pktio_t pktio)
Get pktio interface index.
odp_pktio_link_status_t odp_pktio_link_status(odp_pktio_t pktio)
Determine pktio link is up or down for a packet IO interface.
uint64_t odp_pktio_to_u64(odp_pktio_t pktio)
Get printable value for an odp_pktio_t.
int odp_pktin_queue_config(odp_pktio_t pktio, const odp_pktin_queue_param_t *param)
Configure packet input queues.
int odp_pktout_queue_config(odp_pktio_t pktio, const odp_pktout_queue_param_t *param)
Configure packet output queues.
@ ODP_PKTIO_LINK_STATUS_UP
Link status is up.
void odp_packet_print_data(odp_packet_t pkt, uint32_t offset, uint32_t len)
Print packet data.
odp_packet_t odp_packet_alloc(odp_pool_t pool, uint32_t len)
Allocate a packet from a packet pool.
void odp_packet_free(odp_packet_t pkt)
Free packet.
#define ODP_PACKET_INVALID
Invalid packet.
void odp_packet_print(odp_packet_t pkt)
Print packet debug information.
odp_pool_t odp_pool_create(const char *name, const odp_pool_param_t *param)
Create a pool.
void odp_pool_param_init(odp_pool_param_t *param)
Initialize pool params.
int odp_pool_destroy(odp_pool_t pool)
Destroy a pool previously created by odp_pool_create()
void odp_pool_print(odp_pool_t pool)
Print pool info.
#define ODP_POOL_INVALID
Invalid pool.
@ ODP_POOL_TIMEOUT
Timeout pool.
@ ODP_POOL_BUFFER
Buffer pool.
@ ODP_POOL_PACKET
Packet pool.
void odp_queue_param_init(odp_queue_param_t *param)
Initialize queue params.
#define ODP_QUEUE_INVALID
Invalid queue.
void odp_queue_print_all(void)
Print debug info about all queues.
odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param)
Queue create.
void odp_queue_print(odp_queue_t queue)
Print queue info.
int odp_queue_destroy(odp_queue_t queue)
Destroy ODP queue.
@ ODP_QUEUE_TYPE_SCHED
Scheduled queue.
@ ODP_QUEUE_TYPE_PLAIN
Plain queue.
#define ODP_SCHED_SYNC_ATOMIC
Atomic queue synchronization.
int odp_schedule_max_prio(void)
Maximum scheduling priority level.
int odp_schedule_config(const odp_schedule_config_t *config)
Global schedule configuration.
void odp_schedule_print(void)
Print debug info about scheduler.
void odp_shm_print_all(void)
Print all shared memory blocks.
int odp_shm_free(odp_shm_t shm)
Free a contiguous block of shared memory.
void odp_shm_print(odp_shm_t shm)
Print shared memory block info.
#define ODP_SHM_INVALID
Invalid shared memory block.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.
#define ODP_STASH_INVALID
Invalid stash handle.
void odp_stash_param_init(odp_stash_param_t *param)
Initialize stash params.
int odp_stash_destroy(odp_stash_t stash)
Destroy a stash.
int32_t odp_stash_put_u32(odp_stash_t stash, const uint32_t val[], int32_t num)
Put 32-bit integers into a stash.
int32_t odp_stash_get_u32(odp_stash_t stash, uint32_t val[], int32_t num)
Get 32-bit integers from a stash.
void odp_stash_print(odp_stash_t stash)
Print debug information about the stash.
odp_stash_t odp_stash_create(const char *name, const odp_stash_param_t *param)
Create a stash.
void odp_sys_info_print(void)
Print system info.
void odp_sys_config_print(void)
Print configuration.
@ ODP_THREAD_CONTROL
Control thread.
#define ODP_TIME_SEC_IN_NS
A second in nanoseconds.
void odp_time_wait_ns(uint64_t ns)
Wait the specified number of nanoseconds.
#define ODP_TIME_MSEC_IN_NS
A millisecond in nanoseconds.
void odp_timeout_free(odp_timeout_t tmo)
Timeout free.
int odp_timer_pool_start_multi(odp_timer_pool_t timer_pool[], int num)
Start timer pools.
void odp_timer_pool_print(odp_timer_pool_t timer_pool)
Print timer pool debug information.
void odp_timer_print(odp_timer_t timer)
Print timer debug information.
odp_timeout_t odp_timeout_alloc(odp_pool_t pool)
Timeout alloc.
int odp_timer_free(odp_timer_t timer)
Free a timer.
odp_timeout_t odp_timeout_from_event(odp_event_t ev)
Get timeout handle from a ODP_EVENT_TIMEOUT type event.
#define ODP_TIMER_POOL_INVALID
Invalid timer pool handle.
odp_timer_pool_t odp_timer_pool_create(const char *name, const odp_timer_pool_param_t *params)
Create a timer pool.
int odp_timer_cancel(odp_timer_t timer, odp_event_t *tmo_ev)
Cancel a timer.
int odp_timer_capability(odp_timer_clk_src_t clk_src, odp_timer_capability_t *capa)
Query timer capabilities per clock source.
uint64_t odp_timer_ns_to_tick(odp_timer_pool_t timer_pool, uint64_t ns)
Convert nanoseconds to timer ticks.
int odp_timer_start(odp_timer_t timer, const odp_timer_start_t *start_param)
Start a timer.
int odp_timer_res_capability(odp_timer_clk_src_t clk_src, odp_timer_res_capability_t *res_capa)
Timer resolution capability.
void odp_timeout_print(odp_timeout_t tmo)
Print timeout debug information.
odp_event_t odp_timeout_to_event(odp_timeout_t tmo)
Convert timeout handle to event handle.
#define ODP_TIMEOUT_INVALID
Invalid timeout handle.
odp_timer_t odp_timer_alloc(odp_timer_pool_t timer_pool, odp_queue_t queue, const void *user_ptr)
Allocate a timer.
#define ODP_CLOCK_DEFAULT
The default clock source.
void odp_timer_pool_param_init(odp_timer_pool_param_t *param)
Initialize timer pool parameters.
void odp_timer_pool_destroy(odp_timer_pool_t timer_pool)
Destroy a timer pool.
@ ODP_TIMER_SUCCESS
Timer operation succeeded.
@ ODP_TIMER_TICK_REL
Relative ticks.
Packet IO link information.
odp_pktio_link_pause_t pause_rx
Reception of pause frames.
odp_pktio_link_duplex_t duplex
Duplex mode.
uint32_t speed
Link speed in Mbps.
odp_pktio_link_autoneg_t autoneg
Link autonegotiation.
odp_pktio_link_pause_t pause_tx
Transmission of pause frames.
const char * media
Link media type.
odp_pktio_link_status_t status
Link status.
uint32_t num
Number of buffers in the pool.
uint32_t max_len
Maximum packet length that will be allocated from the pool.
struct odp_pool_param_t::@127 tmo
Parameters for timeout pools.
uint32_t size
Minimum buffer size in bytes.
odp_pool_type_t type
Pool type.
uint32_t len
Minimum length of 'num' packets.
struct odp_pool_param_t::@126 pkt
Parameters for packet pools.
struct odp_pool_param_t::@125 buf
Parameters for buffer pools.
odp_schedule_param_t sched
Scheduler parameters.
odp_queue_type_t type
Queue type.
odp_schedule_prio_t prio
Priority level.
odp_schedule_sync_t sync
Synchronization method.
uint32_t obj_size
Object handle size in bytes.
uint64_t num_obj
Number of object handles.
odp_timer_res_capability_t max_tmo
Maximum timeout length.
odp_bool_t queue_type_sched
Scheduled queue destination support.
uint64_t res_ns
Timeout resolution in nanoseconds.
uint64_t min_tmo
Minimum relative timeout in nanoseconds.
uint32_t num_timers
Number of timers in the pool.
odp_timer_clk_src_t clk_src
Clock source for timers.
uint64_t max_tmo
Maximum relative timeout in nanoseconds.
Timer resolution capability.
uint64_t max_tmo
Maximum relative timeout in nanoseconds.
uint64_t res_ns
Timeout resolution in nanoseconds.
uint64_t tick
Expiration time in ticks.
odp_event_t tmo_ev
Timeout event.
odp_timer_tick_type_t tick_type
Tick type.