Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bf7d196

Browse files
Trammell Hudsonosresearch
Trammell Hudson
authored andcommitted
eflatency: add -V for vlan tag in ethernet header
1 parent 8e586b6 commit bf7d196

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

‎src/tests/ef_vi/eflatency.c‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static inline void rx_wait_with_ts(struct eflatency_vi*);
3939

4040
static int cfg_verbose = 0;
4141
static int cfg_validate = 0;
42+
static int cfg_vlan = 0;
4243
static int cfg_iter = 100000;
4344
static int cfg_warmups = 10000;
4445
static int cfg_payload_len = DEFAULT_PAYLOAD_SIZE;
@@ -65,7 +66,8 @@ static enum ef_vi_flags cfg_vi_flags = 0;
6566
#define BUF_SIZE 2048
6667
#define MAX_UDP_PAYLEN (1500 - sizeof(ci_ip4_hdr) - sizeof(ci_udp_hdr))
6768
/* Protocol header length: Ethernet + IP + UDP. */
68-
#define HEADER_SIZE (14 + 20 + 8)
69+
#define ETH_HEADER_SIZE (cfg_vlan ? sizeof(ci_ethhdr_vlan_t) : sizeof(ci_ethhdr_t))
70+
#define HEADER_SIZE (ETH_HEADER_SIZE + sizeof(ci_ip4_hdr) + sizeof(ci_udp_hdr))
6971

7072

7173
struct pkt_buf {
@@ -103,8 +105,7 @@ const uint16_t port_he = 8080;
103105

104106
static void checksum_udp_pkt(void * pkt_buf)
105107
{
106-
ci_ether_hdr * const eth = (ci_ether_hdr*) pkt_buf;
107-
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) eth + 14);
108+
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) pkt_buf + ETH_HEADER_SIZE);
108109
ci_udp_hdr * const udp = (void*) (ip4 + 1);
109110
struct iovec iov = {
110111
.iov_base = udp + 1,
@@ -118,8 +119,9 @@ static void checksum_udp_pkt(void * pkt_buf)
118119

119120
static void init_udp_pkt(void* pkt_buf, int paylen)
120121
{
121-
ci_ether_hdr * const eth = (ci_ether_hdr*) pkt_buf;
122-
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) eth + 14);
122+
ci_ethhdr_t * const eth = pkt_buf;
123+
ci_ethhdr_vlan_t * const eth_vlan = pkt_buf;
124+
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) pkt_buf + ETH_HEADER_SIZE);
123125
ci_udp_hdr * const udp = (void*) (ip4 + 1);
124126
const size_t ip_len = sizeof(*ip4) + sizeof(*udp) + paylen;
125127

@@ -130,6 +132,13 @@ static void init_udp_pkt(void* pkt_buf, int paylen)
130132
memcpy(eth->ether_dhost, remote_mac, sizeof(remote_mac));
131133
ef_vi_get_mac(&rx_vi.vi, driver_handle, eth->ether_shost);
132134
eth->ether_type = htons(0x0800);
135+
136+
if (cfg_vlan) {
137+
eth_vlan->ether_type = htons(0x0800);
138+
eth_vlan->ether_vtype = htons(0x8100);
139+
eth_vlan->ether_vtag = htons(cfg_vlan);
140+
}
141+
133142
ci_ip4_hdr_init(ip4, CI_NO_OPTS, ip_len, 0, IPPROTO_UDP, htonl(laddr_he),
134143
htonl(raddr_he), 0);
135144
ci_udp_hdr_init(udp, ip4, htons(port_he), htons(port_he), udp + 1, paylen, 0);
@@ -737,6 +746,7 @@ static CI_NORETURN usage(const char* fmt, ...)
737746
fprintf(stderr, " -n <iterations> - set number of iterations\n");
738747
fprintf(stderr, " -s <message-size> - set udp payload size. Accepts Python slices\n");
739748
fprintf(stderr, " -w <iterations> - set number of warmup iterations\n");
749+
fprintf(stderr, " -V <vlan-tag> - add vlan tag to ethernet header\n");
740750
fprintf(stderr, " -c <cut-through> - CTPIO cut-through threshold\n");
741751
fprintf(stderr, " -p - CTPIO no-poison mode\n");
742752
fprintf(stderr, " -m <modes> - allow mode of the set: [c]tpio, \n");
@@ -782,7 +792,7 @@ int main(int argc, char* argv[])
782792
p = (unsigned int)__v; \
783793
} while( 0 );
784794

785-
while( (c = getopt (argc, argv, "n:s:w:c:pm:t:o:vr")) != -1 )
795+
while( (c = getopt (argc, argv, "n:s:w:c:pm:t:o:V:vr")) != -1 )
786796
switch( c ) {
787797
case 'n':
788798
OPT_INT(optarg, cfg_iter);
@@ -807,6 +817,9 @@ int main(int argc, char* argv[])
807817
case 'c':
808818
OPT_UINT(optarg, cfg_ctpio_thresh);
809819
break;
820+
case 'V':
821+
OPT_INT(optarg, cfg_vlan);
822+
break;
810823
case 'p':
811824
cfg_ctpio_no_poison = 1;
812825
break;
@@ -941,6 +954,7 @@ int main(int argc, char* argv[])
941954
printf("# warmups: %d\n", cfg_warmups);
942955
printf("# frame len: %d\n", tx_frame_len);
943956
printf("# mode: %s\n", t->name);
957+
printf("# vlan: %d\n", cfg_vlan);
944958
printf("# validating: %s\n", cfg_validate ? "yes" : "no");
945959
if( ping )
946960
printf("paylen\tmean\tmin\t50%%\t95%%\t99%%\tmax\n");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /