Skip to content

Commit

Permalink
eflatency: add -V for vlan tag in ethernet header
Browse files Browse the repository at this point in the history
  • Loading branch information
Trammell Hudson authored and osresearch committed Aug 7, 2024
1 parent 8e586b6 commit bf7d196
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/tests/ef_vi/eflatency.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static inline void rx_wait_with_ts(struct eflatency_vi*);

static int cfg_verbose = 0;
static int cfg_validate = 0;
static int cfg_vlan = 0;
static int cfg_iter = 100000;
static int cfg_warmups = 10000;
static int cfg_payload_len = DEFAULT_PAYLOAD_SIZE;
Expand All @@ -65,7 +66,8 @@ static enum ef_vi_flags cfg_vi_flags = 0;
#define BUF_SIZE 2048
#define MAX_UDP_PAYLEN (1500 - sizeof(ci_ip4_hdr) - sizeof(ci_udp_hdr))
/* Protocol header length: Ethernet + IP + UDP. */
#define HEADER_SIZE (14 + 20 + 8)
#define ETH_HEADER_SIZE (cfg_vlan ? sizeof(ci_ethhdr_vlan_t) : sizeof(ci_ethhdr_t))
#define HEADER_SIZE (ETH_HEADER_SIZE + sizeof(ci_ip4_hdr) + sizeof(ci_udp_hdr))


struct pkt_buf {
Expand Down Expand Up @@ -103,8 +105,7 @@ const uint16_t port_he = 8080;

static void checksum_udp_pkt(void * pkt_buf)
{
ci_ether_hdr * const eth = (ci_ether_hdr*) pkt_buf;
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) eth + 14);
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) pkt_buf + ETH_HEADER_SIZE);
ci_udp_hdr * const udp = (void*) (ip4 + 1);
struct iovec iov = {
.iov_base = udp + 1,
Expand All @@ -118,8 +119,9 @@ static void checksum_udp_pkt(void * pkt_buf)

static void init_udp_pkt(void* pkt_buf, int paylen)
{
ci_ether_hdr * const eth = (ci_ether_hdr*) pkt_buf;
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) eth + 14);
ci_ethhdr_t * const eth = pkt_buf;
ci_ethhdr_vlan_t * const eth_vlan = pkt_buf;
ci_ip4_hdr * const ip4 = (void*) ((uintptr_t) pkt_buf + ETH_HEADER_SIZE);
ci_udp_hdr * const udp = (void*) (ip4 + 1);
const size_t ip_len = sizeof(*ip4) + sizeof(*udp) + paylen;

Expand All @@ -130,6 +132,13 @@ static void init_udp_pkt(void* pkt_buf, int paylen)
memcpy(eth->ether_dhost, remote_mac, sizeof(remote_mac));
ef_vi_get_mac(&rx_vi.vi, driver_handle, eth->ether_shost);
eth->ether_type = htons(0x0800);

if (cfg_vlan) {
eth_vlan->ether_type = htons(0x0800);
eth_vlan->ether_vtype = htons(0x8100);
eth_vlan->ether_vtag = htons(cfg_vlan);
}

ci_ip4_hdr_init(ip4, CI_NO_OPTS, ip_len, 0, IPPROTO_UDP, htonl(laddr_he),
htonl(raddr_he), 0);
ci_udp_hdr_init(udp, ip4, htons(port_he), htons(port_he), udp + 1, paylen, 0);
Expand Down Expand Up @@ -737,6 +746,7 @@ static CI_NORETURN usage(const char* fmt, ...)
fprintf(stderr, " -n <iterations> - set number of iterations\n");
fprintf(stderr, " -s <message-size> - set udp payload size. Accepts Python slices\n");
fprintf(stderr, " -w <iterations> - set number of warmup iterations\n");
fprintf(stderr, " -V <vlan-tag> - add vlan tag to ethernet header\n");
fprintf(stderr, " -c <cut-through> - CTPIO cut-through threshold\n");
fprintf(stderr, " -p - CTPIO no-poison mode\n");
fprintf(stderr, " -m <modes> - allow mode of the set: [c]tpio, \n");
Expand Down Expand Up @@ -782,7 +792,7 @@ int main(int argc, char* argv[])
p = (unsigned int)__v; \
} while( 0 );

while( (c = getopt (argc, argv, "n:s:w:c:pm:t:o:vr")) != -1 )
while( (c = getopt (argc, argv, "n:s:w:c:pm:t:o:V:vr")) != -1 )
switch( c ) {
case 'n':
OPT_INT(optarg, cfg_iter);
Expand All @@ -807,6 +817,9 @@ int main(int argc, char* argv[])
case 'c':
OPT_UINT(optarg, cfg_ctpio_thresh);
break;
case 'V':
OPT_INT(optarg, cfg_vlan);
break;
case 'p':
cfg_ctpio_no_poison = 1;
break;
Expand Down Expand Up @@ -941,6 +954,7 @@ int main(int argc, char* argv[])
printf("# warmups: %d\n", cfg_warmups);
printf("# frame len: %d\n", tx_frame_len);
printf("# mode: %s\n", t->name);
printf("# vlan: %d\n", cfg_vlan);
printf("# validating: %s\n", cfg_validate ? "yes" : "no");
if( ping )
printf("paylen\tmean\tmin\t50%%\t95%%\t99%%\tmax\n");
Expand Down

0 comments on commit bf7d196

Please sign in to comment.