aboutsummaryrefslogtreecommitdiff
path: root/test/linux-generic/pktio_ipc/ipc_common.h
blob: ca78b684689ed315dc7a2b51e368d8d3da4d1d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Copyright (c) 2015, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#define _POSIX_C_SOURCE 200809L

#define _GNU_SOURCE
#include <sched.h>

#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>

#include <example_debug.h>

#include <odp.h>
#include <odp/helper/odph_api.h>

/** @def SHM_PKT_POOL_SIZE
 * @brief Size of the shared memory block
 */
#define SHM_PKT_POOL_SIZE      8192

/** @def SHM_PKT_POOL_BUF_SIZE
 * @brief Buffer size of the packet pool buffer
 */
#define SHM_PKT_POOL_BUF_SIZE  100

/** @def MAX_PKT_BURST
 * @brief Maximum number of packet bursts
 */
#define MAX_PKT_BURST          16

/** Get rid of path in filename - only for unix-type paths using '/' */
#define NO_PATH(file_name) (strrchr((file_name), '/') ? \
			    strrchr((file_name), '/') + 1 : (file_name))

#define TEST_SEQ_MAGIC		0x92749451
#define TEST_SEQ_MAGIC_2	0x81638340

#define TEST_ALLOC_MAGIC	0x1234adcd

#define TEST_IPC_PKTIO_NAME	"ipc:ipktio"
#define TEST_IPC_PKTIO_PID_NAME "ipc:%d:ipktio"

/** Can be any name, same or not the same. */
#define TEST_IPC_POOL_NAME "ipc_packet_pool"

/** magic number and sequence at start of packet payload */
typedef struct ODP_PACKED {
	odp_u32be_t magic;
	odp_u32be_t seq;
} pkt_head_t;

/** magic number at end of packet payload */
typedef struct ODP_PACKED {
	odp_u32be_t magic;
} pkt_tail_t;

/** Application argument */
char *pktio_name;

/** Run time in seconds */
int run_time_sec;

/** PID of the master process */
int master_pid;

/* helper funcs */
void parse_args(int argc, char *argv[]);
void print_info(char *progname);
void usage(char *progname);

/**
 * Create a ipc pktio handle.
 *
 * @param pool Pool to associate with device for packet RX/TX
 * @param master_pid Pid of master process
 *
 * @return The handle of the created pktio object.
 * @retval ODP_PKTIO_INVALID if the create fails.
 */
odp_pktio_t create_pktio(odp_pool_t pool, int master_pid);

/** Spin and send all packet from table
 *
 * @param pktio		pktio device
 * @param pkt_tbl	packets table
 * @param num		number of packets
 */
int ipc_odp_packet_send_or_free(odp_pktio_t pktio,
				odp_packet_t pkt_tbl[],
				int num);