This example application demonstrates the usage of various debug print functions of ODP API.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include <odp/helper/odph_api.h>
#define MAX_NAME_LEN 128
typedef struct test_global_t {
int system;
int shm;
int pool;
int queue;
int pktio;
int ipsec;
int timer;
int stash;
char pktio_name[MAX_NAME_LEN];
} test_global_t;
static test_global_t test_global;
static void print_usage(void)
{
printf("This example prints out debug information on various ODP objects.\n"
"Select debug functions to be called with options. All listed functions\n"
"are called when no options are given.\n"
"\n"
"OPTIONS:\n"
" -S, --system Call odp_sys_info_print() and odp_sys_config_print()\n"
" -s, --shm Create a SHM and call odp_shm_print()\n"
" -p, --pool Create various types of pools and call odp_pool_print()\n"
" -q, --queue Create various types of queues and call odp_queue_print()\n"
" -i, --interface <name> Start a packet IO interface, and call odp_pktio_print(),\n"
" odp_pktio_extra_stats_print(), etc. Uses loop interface by default.\n"
" -I, --ipsec Call odp_ipsec_print()\n"
" -t, --timer Call timer pool, timer and timeout print functions\n"
" -a, --stash Create stash and call odp_stash_print()\n"
" -h, --help Display help and exit.\n\n");
}
static int parse_options(int argc, char *argv[], test_global_t *global)
{
int opt;
char *str;
uint32_t str_len = 0;
const struct option longopts[] = {
{"system", no_argument, NULL, 'S'},
{"shm", no_argument, NULL, 's'},
{"pool", no_argument, NULL, 'p'},
{"queue", no_argument, NULL, 'q'},
{"interface", required_argument, NULL, 'i'},
{"ipsec", no_argument, NULL, 'I'},
{"timer", no_argument, NULL, 't'},
{"stash", no_argument, NULL, 'a'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
const char *shortopts = "+Sspqi:Itah";
int ret = 0;
while (1) {
opt = getopt_long(argc, argv, shortopts, longopts, NULL);
if (opt == -1)
break;
switch (opt) {
case 'S':
global->system = 1;
break;
case 's':
global->shm = 1;
break;
case 'p':
global->pool = 1;
break;
case 'q':
global->queue = 1;
break;
case 'i':
global->pktio = 1;
str = optarg;
str_len = strlen(str);
if (str_len && str_len < MAX_NAME_LEN)
strcpy(global->pktio_name, str);
break;
case 'I':
global->ipsec = 1;
break;
case 't':
global->timer = 1;
break;
case 'a':
global->stash = 1;
break;
case 'h':
default:
print_usage();
return -1;
}
}
if (global->pktio && (str_len == 0 || str_len >= MAX_NAME_LEN)) {
ODPH_ERR("Bad interface name length: %u\n", str_len);
ret = -1;
}
return ret;
}
static int shm_debug(void)
{
const char *name = "debug_shm";
ODPH_ERR("SHM reserve failed: %s\n", name);
return -1;
}
printf("\n");
printf("\n");
ODPH_ERR("SHM free failed: %s\n", name);
return -1;
}
return 0;
}
{
ODPH_ERR("Buffer alloc failed\n");
return -1;
}
printf("\n");
return 0;
}
{
ODPH_ERR("Packet alloc failed\n");
return -1;
}
printf("\n");
printf("\n");
return 0;
}
static int pool_debug(void)
{
const char *name;
int pkt_len = 100;
name = "debug_buffer_pool";
ODPH_ERR("Pool create failed: %s\n", name);
return -1;
}
printf("\n");
if (buffer_debug(pool))
return -1;
ODPH_ERR("Pool destroy failed: %s\n", name);
return -1;
}
name = "debug_packet_pool";
ODPH_ERR("Pool create failed: %s\n", name);
return -1;
}
printf("\n");
if (packet_debug(pool, pkt_len))
return -1;
ODPH_ERR("Pool destroy failed: %s\n", name);
return -1;
}
name = "debug_tmo_pool";
ODPH_ERR("Pool create failed: %s\n", name);
return -1;
}
printf("\n");
ODPH_ERR("Pool destroy failed: %s\n", name);
return -1;
}
return 0;
}
static int queue_debug(void)
{
const char *name;
int i;
int num = 3;
name = "plain_queue";
ODPH_ERR("Queue create failed: %s\n", name);
return -1;
}
printf("\n");
name = "parallel_sched_queue";
ODPH_ERR("Queue create failed: %s\n", name);
return -1;
}
printf("\n");
name = "atomic_sched_queue";
ODPH_ERR("Queue create failed: %s\n", name);
return -1;
}
printf("\n");
printf("\n");
printf("\n");
for (i = 0; i < num; i++) {
ODPH_ERR("Queue destroy failed: %i\n", i);
return -1;
}
}
return 0;
}
static int pktio_debug(test_global_t *global)
{
uint8_t mac[ODPH_ETHADDR_LEN];
int pkt_len = 100;
ODPH_ERR("Pool create failed\n");
return -1;
}
ODPH_ERR("Pktio open failed\n");
return -1;
}
ODPH_ERR("Packet input queue config failed\n");
return -1;
}
ODPH_ERR("Packet output queue config failed\n");
return -1;
}
ODPH_ERR("Pktio start failed\n");
return -1;
}
printf("\nWaiting link up");
for (int i = 0; i < 25; i++) {
break;
printf(".");
fflush(NULL);
}
printf("\n\n");
printf("Packet IO\n---------\n");
printf(" mac address: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2],
mac[3], mac[4], mac[5]);
}
printf("Link info\n---------\n");
printf(
" auto neg: %i\n", info.
autoneg);
printf(
" duplex: %i\n", info.
duplex);
printf(
" media: %s\n", info.
media);
printf(
" pause_rx: %i\n", info.
pause_rx);
printf(
" pause_tx: %i\n", info.
pause_tx);
printf(
" speed: %u Mbit/s\n", info.
speed);
printf(
" status: %i\n", info.
status);
}
printf("\n");
printf("\n");
ODPH_ERR("Pktio stop failed\n");
return -1;
}
ODPH_ERR("Pktio close failed\n");
return -1;
}
ODPH_ERR("Pool destroy failed\n");
return -1;
}
return 0;
}
static int ipsec_debug(void)
{
printf("\n");
return 0;
}
static int timer_debug(void)
{
uint64_t tick;
int started = 0;
ODPH_ERR("Pool create failed\n");
return -1;
}
ODPH_ERR("Timeout alloc failed\n");
return -1;
}
ODPH_ERR("Timer capa failed\n");
return -1;
}
ODPH_ERR("Timer resolution capability failed\n");
return -1;
}
if (timer_res_capa.
res_ns > res)
timer_param.
min_tmo = max_tmo / 10;
ODPH_ERR("Timer pool create failed\n");
return -1;
}
ODPH_ERR("Timer pool start failed\n");
return -1;
}
ODPH_ERR("Queue create failed.\n");
return -1;
}
printf("\n");
printf("\n");
started = 1;
else
ODPH_ERR("Timer start failed.\n");
printf("\n");
ODPH_ERR("Timer cancel failed\n");
return -1;
} else {
printf("\n");
}
ODPH_ERR("Timer free failed\n");
return -1;
}
ODPH_ERR("Queue destroy failed\n");
return -1;
}
ODPH_ERR("Pool destroy failed\n");
return -1;
}
return 0;
}
static int stash_debug(void)
{
uint32_t val = 0xdeadbeef;
ODPH_ERR("Stash create failed\n");
return -1;
}
ODPH_ERR("Stash put failed\n");
return -1;
}
printf("\n");
ODPH_ERR("Stash get failed\n");
return -1;
}
ODPH_ERR("Stash destroy failed\n");
return -1;
}
return 0;
}
int main(int argc, char *argv[])
{
test_global_t *global = &test_global;
printf("ODP debug example\n\n");
memset(global, 0, sizeof(test_global_t));
if (argc < 2) {
global->system = 1;
global->shm = 1;
global->pool = 1;
global->queue = 1;
global->pktio = 1;
global->ipsec = 1;
global->timer = 1;
global->stash = 1;
strcpy(global->pktio_name, "loop");
} else {
if (parse_options(argc, argv, global))
exit(EXIT_FAILURE);
}
ODPH_ERR("Global init failed.\n");
exit(EXIT_FAILURE);
}
ODPH_ERR("Local init failed.\n");
exit(EXIT_FAILURE);
}
ODPH_ERR("Schedule config failed\n");
exit(EXIT_FAILURE);
}
if (global->system) {
printf("\n");
printf("\n");
}
if (global->shm && shm_debug()) {
ODPH_ERR("SHM debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->pool && pool_debug()) {
ODPH_ERR("Pool debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->queue && queue_debug()) {
ODPH_ERR("Queue debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->pktio && pktio_debug(global)) {
ODPH_ERR("Packet debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->ipsec && ipsec_debug()) {
ODPH_ERR("IPSEC debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->timer && timer_debug()) {
ODPH_ERR("Timer debug failed.\n");
exit(EXIT_FAILURE);
}
if (global->stash && stash_debug()) {
ODPH_ERR("Stash debug failed.\n");
exit(EXIT_FAILURE);
}
ODPH_ERR("Local term failed.\n");
exit(EXIT_FAILURE);
}
ODPH_ERR("Global term failed.\n");
exit(EXIT_FAILURE);
}
return 0;
}
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.