hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * RTnet UDP test
 *
 * Copyright (C) 2015 Gilles Chanteperdrix <gch@xenomai.org>
 *
 * SPDX-License-Identifier: MIT
 */
 
#include <netinet/in.h>
 
#include <sys/cobalt.h>
#include <smokey/smokey.h>
#include "smokey_net.h"
 
smokey_test_plugin(net_udp,
   SMOKEY_ARGLIST(
       SMOKEY_STRING(rtnet_driver),
       SMOKEY_STRING(rtnet_interface),
       SMOKEY_INT(rtnet_rate),
       SMOKEY_INT(rtnet_duration),
   ),
   "Check RTnet driver, using UDP packets, measuring round trip time\n"
   "\tand packet losses,\n"
   "\tthe rtnet_driver parameter allows choosing the network driver\n"
   "\tthe rtnet_interface parameter allows choosing the network interface\n"
   "\tthe rtnet_rate parameter allows choosing the packet rate\n"
   "\tthe rtnet_duration parameter allows choosing the test duration\n"
   "\tA server on the network must run the smokey_rtnet_server program."
);
 
static int
udp_create_socket(struct smokey_net_client *client)
{
   return smokey_check_errno(__RT(socket(PF_INET, SOCK_DGRAM, 0)));
}
 
static int
udp_prepare(struct smokey_net_client *client,
       void *buf, size_t len, const struct smokey_net_payload *payload)
{
   if (sizeof(*payload) < len)
       len = sizeof(*payload);
   memcpy(buf, payload, len);
   return len;
}
 
static int
udp_extract(struct smokey_net_client *client,
       struct smokey_net_payload *payload, const void *buf, size_t len)
{
   if (sizeof(*payload) < len)
       len = sizeof(*payload);
   memcpy(payload, buf, len);
   return len;
}
 
static int
run_net_udp(struct smokey_test *t, int argc, char *const argv[])
{
   struct smokey_net_client client = {
       .name = "UDP",
       .option = _CC_COBALT_NET_UDP,
       .create_socket = &udp_create_socket,
       .prepare = &udp_prepare,
       .extract = &udp_extract,
   };
 
   memset(&client.in_peer, '\0', sizeof(client.in_peer));
   client.in_peer.sin_family = AF_INET;
   client.in_peer.sin_port = htons(7); /* UDP echo port */
   client.in_peer.sin_addr.s_addr = htonl(INADDR_ANY);
   client.peer_len = sizeof(client.in_peer);
 
   return smokey_net_client_run(t, &client, argc, argv);
}