Skip to content

Commit

Permalink
echo-client: Add VLAN specific classify packet option
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jukkar committed May 14, 2020
1 parent 1c4fdba commit c4fedea
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions echo-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ static void signal_handler(int sig)
do_exit = true;
}

static int set_sock_priority(int sock)
{
int priority = random() % 8;
int ret = 0;

ret = setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &priority,
sizeof(priority));
if (ret < 0) {
perror("Cannot set socket priority");
}

return ret;
}

extern int optind, opterr, optopt;
extern char *optarg;

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

opterr = 0;

while ((c = getopt(argc, argv, "Fi:p:eth")) != -1) {
while ((c = getopt(argc, argv, "Fci:p:eth")) != -1) {
switch (c) {
case 'F':
flood = true;
break;
case 'c':
classify = true;
break;
case 'i':
interface = optarg;
break;
Expand Down Expand Up @@ -491,6 +508,9 @@ int main(int argc, char**argv)
printf("-p Use this port, default port is %d\n", SERVER_PORT);
printf("-r Check data by reversing it (needed when checking "
"legacy stack\n");
printf("-c Classify (use 802.1Q defined priorities) the sent "
"packets. The packet priority is used for UDP. "
"This also requires VLAN to be used.\n");
printf("-F (flood) option will prevent the client from "
"waiting the data.\n"
" The -F option will stress test the server.\n");
Expand Down Expand Up @@ -601,6 +621,8 @@ int main(int argc, char**argv)
perror("connect");
exit(-errno);
}

classify = false;
}

again:
Expand All @@ -625,9 +647,17 @@ int main(int argc, char**argv)
sent += data[i].len;
pos += ret;
} while (sent < data[i].len);
} else
} else {
if (classify) {
ret = set_sock_priority(fd);
if (ret < 0)
goto out;
}

ret = sendto(fd, data[i].buf, data[i].len, 0,
addr_send, addr_len);
}

if (ret < 0) {
perror("send");
goto out;
Expand Down

0 comments on commit c4fedea

Please sign in to comment.