forked from ikhorn/plget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplget.h
209 lines (174 loc) · 4.48 KB
/
plget.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (C) 2017
* Authors: Ivan Khoronzhuk <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef PLGET_H
#define PLGET_H
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <net/if.h>
#include <string.h>
#include <sys/time.h>
#include "stat.h"
#ifndef XDP_RX_RING
#include "linux/if_xdp.h"
#endif
#define ts_correct(ts) ((ts)->tv_nsec || (ts)->tv_sec)
#define NSEC_PER_SEC 1000000000ULL
#define USEC_PER_SEC 1000000ULL
#define MAGIC 0x34
#define SEQ_ID_MASK 0x3fff
#define STREAM_ID_SHIFT 14
extern struct stats tx_app_v;
extern struct stats *tx_sch_v;
extern struct stats tx_sw_v;
extern struct stats tx_hw_v;
extern struct stats rx_app_v;
extern struct stats rx_sw_v;
extern struct stats rx_hw_v;
extern struct stats temp;
extern struct plgett *plget;
#define BIT(X) (1 << (X))
#define PLF_TITLE BIT(0)
#define PLF_PTP BIT(1)
#define PLF_AVTP BIT(2)
#define PLF_PLAIN_FORMAT BIT(3)
#define PLF_HW_STAT BIT(4)
#define PLF_IPGAP_STAT BIT(5)
#define PLF_LATENCY_STAT BIT(6)
#define PLF_PRIO BIT(7)
#define PLF_BUSYPOLL BIT(8)
#define PLF_SCHED_STAT BIT(9)
#define PLF_QUEUE BIT(10)
#define PLF_ZERO_COPY BIT(11)
#define PLF_DIS_HW_TS BIT(12)
#define PLF_ADDR_SET BIT(13)
#define PLF_PROG_LOADED BIT(14)
#define PLF_RT_PRINT BIT(15)
#define PLF_SW_POLL BIT(16)
#define PLF_RTIME BIT(17)
#define PLF_STRICT_ID_ORDER BIT(18)
#define PLF_PRINTOUT (PLF_HW_STAT |\
PLF_IPGAP_STAT |\
PLF_LATENCY_STAT |\
PLF_SCHED_STAT)
#define CONTROL_LEN 512
enum pkt_type {
PKT_UDP = 1,
PKT_ETH,
PKT_XDP,
PKT_RAW,
};
enum test_mod {
RX_LAT = 1,
TX_LAT = 2,
RTT_MOD = 3, /* round trip time mode (external latency) */
ECHO_LAT = 4,
PKT_GEN = 5,
RX_RATE = 6,
};
struct plgett {
union {
struct in_addr iaddr;
struct sockaddr_ll iaddr2;
struct sockaddr_xdp iaddr3;
};
struct ether_addr macaddr;
struct ether_addr if_addr;
struct sockaddr_ll sk_addr;
enum test_mod mod;
struct timespec interval;
struct timespec rtime;
char if_name[IFNAMSIZ];
int ifidx;
int phc_idx;
enum pkt_type pkt_type;
int frame_size;
int pkt_num;
int sk_payload_size; /* socket payload size */
int sfd;
int port;
int flags;
int prio;
int queue; /* must be used by XDP socket */
int busypoll_time;
int stream_id;
int dev_deep;
int timer_fd;
struct xsock *xsk; /* xdp soket info */
/* rt print */
unsigned long icnt; /* current iteration for progress bar */
unsigned long inum; /* number of iterations for progress bar */
/* packet related info */
char *pkt;
char *rx_pkt;
int off_sid_wr; /* PTP sequential id */
int off_tid_wr; /* wr offset for ts id for identification */
int off_tid_rd; /* rd offset for ts id for identification */
int off_magic_rd; /* rd offset for magic num for validation */
/* rx packet related info */
char data[ETH_DATA_LEN];
char control[CONTROL_LEN];
struct iovec iov;
struct msghdr msg;
int off_tid_rx_rd; /* rx rd offset for ts id for identification */
int off_magic_rx_rd; /* rx rd offset magic num for validation */
};
int setup_sock(int sfd, int flags);
int plget_create_timer(void);
int plget_start_timer(void);
void plget_stop_timer(void);
struct stats *plget_best_rx_vect(void);
struct stats *plget_best_tx_vect(void);
static inline char *magic_rx_rd(void)
{
return (char *)(plget->rx_pkt + plget->off_magic_rx_rd);
}
static inline char *magic_rd(void)
{
return (char *)(plget->data + plget->off_magic_rd);
}
static inline void tid_wr(__u32 tid)
{
char *p;
p = (char *)(plget->off_tid_wr + plget->pkt);
tid = htonl(tid);
memcpy(p, &tid, sizeof(tid));
}
static inline __u32 tid_rd(void)
{
__u32 tid;
char *p;
p = (char *)(plget->data + plget->off_tid_rd);
memcpy(&tid, p, sizeof(tid));
tid = ntohl(tid);
return tid;
}
static inline __u32 tid_rx_rd(void)
{
__u32 tid;
char *p;
p = (char *)(plget->rx_pkt + plget->off_tid_rx_rd);
memcpy(&tid, p, sizeof(tid));
tid = ntohl(tid);
return tid;
}
static inline void sid_wr(__u16 sid)
{
char *p1, *p2;
p1 = (char *)&sid;
p2 = plget->off_sid_wr + plget->pkt;
*p2++ = *p1++;
*p2 = *p1;
}
#endif