Skip to content

Commit 9baf870

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 file found in this project. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent f49bd13 commit 9baf870

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

echo-client.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ static void signal_handler(int sig)
382382
do_exit = true;
383383
}
384384

385+
static int set_sock_priority(int sock)
386+
{
387+
int priority = random() % 8;
388+
int ret = 0;
389+
390+
ret = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &priority,
391+
sizeof(priority));
392+
if (ret < 0) {
393+
perror("Cannot set socket priority");
394+
}
395+
396+
return ret;
397+
}
398+
385399
extern int optind, opterr, optopt;
386400
extern char *optarg;
387401

@@ -393,7 +407,7 @@ extern char *optarg;
393407
int main(int argc, char**argv)
394408
{
395409
int c, ret, fd, i = 0, timeout = -1, port = SERVER_PORT;
396-
bool flood = false, multicast = false;
410+
bool flood = false, multicast = false, classify = false;
397411
struct sockaddr_in6 addr6_send = { 0 }, addr6_recv = { 0 };
398412
struct sockaddr_in addr4_send = { 0 }, addr4_recv = { 0 };
399413
struct sockaddr *addr_send, *addr_recv;
@@ -413,11 +427,16 @@ int main(int argc, char**argv)
413427

414428
opterr = 0;
415429

416-
while ((c = getopt(argc, argv, "Fi:p:ethr")) != -1) {
430+
while ((c = getopt(argc, argv, "Fci:p:ethr")) != -1) {
417431
switch (c) {
418432
case 'F':
419433
flood = true;
420434
break;
435+
case 'c':
436+
classify = true;
437+
gettimeofday(&start_time, NULL);
438+
srandom(start_time.tv_usec);
439+
break;
421440
case 'i':
422441
interface = optarg;
423442
break;
@@ -453,6 +472,9 @@ int main(int argc, char**argv)
453472
printf("-t Use TCP, default is to use UDP only\n");
454473
printf("-p Use this port, default port is %d\n", SERVER_PORT);
455474
printf("-r Send random packet lengths\n");
475+
printf("-c Classify (use 802.1Q defined priorities) the sent "
476+
"packets. The packet priority is used for UDP. "
477+
"This also requires VLAN to be used.\n");
456478
printf("-F (flood) option will prevent the client from "
457479
"waiting the data.\n"
458480
" The -F option will stress test the server.\n");
@@ -563,6 +585,8 @@ int main(int argc, char**argv)
563585
perror("connect");
564586
exit(-errno);
565587
}
588+
589+
classify = false;
566590
}
567591

568592
again:
@@ -613,9 +637,17 @@ int main(int argc, char**argv)
613637
sent += len;
614638
pos += ret;
615639
} while (sent < len);
616-
} else
640+
} else {
641+
if (classify) {
642+
ret = set_sock_priority(fd);
643+
if (ret < 0)
644+
goto out;
645+
}
646+
617647
ret = sendto(fd, buf_ptr, len, 0, addr_send,
618648
addr_len);
649+
}
650+
619651
if (ret < 0) {
620652
perror("send");
621653
goto out;

0 commit comments

Comments
 (0)