Skip to content

Commit c4fedea

Browse files
committed
echo-client: Add VLAN specific classify packet option
Add -c option which tells the echo-client to set the socket priority so that the system can set the VLAN priority of the sent packet. This requires that net-setup.sh is started with VLAN support and the system is set to map socket priority to VLAN priority. One such config file is zeth-vlan-priority.conf config file. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 1c4fdba commit c4fedea

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

echo-client.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,20 @@ static void signal_handler(int sig)
421421
do_exit = true;
422422
}
423423

424+
static int set_sock_priority(int sock)
425+
{
426+
int priority = random() % 8;
427+
int ret = 0;
428+
429+
ret = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &priority,
430+
sizeof(priority));
431+
if (ret < 0) {
432+
perror("Cannot set socket priority");
433+
}
434+
435+
return ret;
436+
}
437+
424438
extern int optind, opterr, optopt;
425439
extern char *optarg;
426440

@@ -432,7 +446,7 @@ extern char *optarg;
432446
int main(int argc, char**argv)
433447
{
434448
int c, ret, fd, i = 0, timeout = -1, port = SERVER_PORT;
435-
bool flood = false, multicast = false;
449+
bool flood = false, multicast = false, classify = false;
436450
struct sockaddr_in6 addr6_send = { 0 }, addr6_recv = { 0 };
437451
struct sockaddr_in addr4_send = { 0 }, addr4_recv = { 0 };
438452
struct sockaddr *addr_send, *addr_recv;
@@ -452,11 +466,14 @@ int main(int argc, char**argv)
452466

453467
opterr = 0;
454468

455-
while ((c = getopt(argc, argv, "Fi:p:eth")) != -1) {
469+
while ((c = getopt(argc, argv, "Fci:p:eth")) != -1) {
456470
switch (c) {
457471
case 'F':
458472
flood = true;
459473
break;
474+
case 'c':
475+
classify = true;
476+
break;
460477
case 'i':
461478
interface = optarg;
462479
break;
@@ -491,6 +508,9 @@ int main(int argc, char**argv)
491508
printf("-p Use this port, default port is %d\n", SERVER_PORT);
492509
printf("-r Check data by reversing it (needed when checking "
493510
"legacy stack\n");
511+
printf("-c Classify (use 802.1Q defined priorities) the sent "
512+
"packets. The packet priority is used for UDP. "
513+
"This also requires VLAN to be used.\n");
494514
printf("-F (flood) option will prevent the client from "
495515
"waiting the data.\n"
496516
" The -F option will stress test the server.\n");
@@ -601,6 +621,8 @@ int main(int argc, char**argv)
601621
perror("connect");
602622
exit(-errno);
603623
}
624+
625+
classify = false;
604626
}
605627

606628
again:
@@ -625,9 +647,17 @@ int main(int argc, char**argv)
625647
sent += data[i].len;
626648
pos += ret;
627649
} while (sent < data[i].len);
628-
} else
650+
} else {
651+
if (classify) {
652+
ret = set_sock_priority(fd);
653+
if (ret < 0)
654+
goto out;
655+
}
656+
629657
ret = sendto(fd, data[i].buf, data[i].len, 0,
630658
addr_send, addr_len);
659+
}
660+
631661
if (ret < 0) {
632662
perror("send");
633663
goto out;

0 commit comments

Comments
 (0)