Debian Codegraph @

src/apps/nagle_rcv.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2002, 2003
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
6 * Copyright (c) 2001 Nokia, Inc.
7 *
8 * The SCTP implementation is free software;
9 * you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * The SCTP implementation is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * ************************
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
24 *
25 * Please send any bug reports or fixes you make to the
26 * email address(es):
27 * lksctp developers <[email protected]>
28 *
29 * Or submit a bug report through the following website:
30 * https://github.com/sctp/lksctp-tools/
31 *
32 * Any bugs reported to us we will try to fix... any fixes shared will
33 * be incorporated into the next SCTP release.
34 *
35 * Written or modified by:
36 * Ardelle Fan <[email protected]>
37 * Sridhar Samudrala <[email protected]>
38 */
39
40 /* This is a receiver for the performance test to verify Nagle's algorithm.
41 * It creates a socket, binds to a address specified as a parameter and
42 * goes into a receive loop waiting for 1,000,000 packets. Then it calculates
43 * the packet receive rate, i.e. packets/second.
44 */
45
46 #include <stdio.h>
47 #include <unistd.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <sys/types.h>
51 #include <sys/socket.h>
52 #include <sys/uio.h>
53 #include <netinet/in.h>
54 #include <errno.h>
55 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
56 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
57 #include <getopt.h>
58 #include <netdb.h>
59 #include <time.h>
60
61 char *TCIDcxx . . $ TCID. = __FILE__;
62 int TST_TOTALcxx . . $ TST_TOTAL. = 1;
63 int TST_CNTcxx . . $ TST_CNT. = 0;
64
65 void
66 usagecxx . . $ usage(fda57c8427c60377).(char *progname)
67 {
68 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Usage: %s -H hostname [-P port]\n", progname);
69 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -H, --local\t\t local hostname,\n");
70 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " -P, --local-port\t local port,\n");
71 }
72
73 int
74 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
75 {
76 int sk, i;
77 struct addrinfocxx . . $ addrinfo# *hst_res;
78 sockaddr_storage_tcxx . . $ sockaddr_storage_t# host;
79 sockaddr_storage_tcxx . . $ sockaddr_storage_t# msgname;
80 struct ioveccxx . . $ iovec# iov;
81 struct msghdrcxx . . $ msghdr# inmessage;
82 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
83 int error, pf_class;
84 char *big_buffer;
85 char *local_host = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
86 int local_port = SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!;
87 char port_buffer[10];
88 int option_index = 0;
89 time_tcxx . . $ time_t# from, to;
90 int bytes_received = 0;
91 int c;
92 static struct optioncxx . . $ option# long_options[] = {
93 {"local", 1, 0, 1},
94 {"local-port", 1, 0, 2},
95 {0, 0, 0, 0}
96 };
97
98 /* Rather than fflush() throughout the code, set stdout to
99 * be unbuffered.
100 */
101 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, _IONBFcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!, 0);
102
103 /* Parse the arguments. */
104 while (1) {
105 c = getopt_longcxx . . $ getopt_long(41f665c090816971). (argc, argv, "H:P:",
106 long_options, &option_index);
107 if (c == -1)
108 break;
109
110 switch (c) {
111 case 0:
112 printfcxx . . $ printf(581fddd72a8db8fc).("option %s", long_options[option_index].namecxx . . $ option#name.);
113 if (optargcxx . . $ optarg.) {
114 printfcxx . . $ printf(581fddd72a8db8fc).(" with arg %s", optargcxx . . $ optarg.);
115 }
116 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
117 break;
118 case 1: /* local host */
119 case 'H':
120 local_host = optargcxx . . $ optarg.;
121 break;
122 case 2: /* local port */
123 case 'P':
124 local_port = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
125 break;
126 case '?':
127 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
128 exitcxx . . $ exit(3ca292c338df9bb3).(0);
129
130 default:
131 printfcxx . . $ printf(581fddd72a8db8fc). ("%s: unrecognized option 0%c\n", argv[0], c);
132 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
133 exitcxx . . $ exit(3ca292c338df9bb3).(1);
134 }
135 }
136
137 if (optindcxx . . $ optind. < argc)
138 {
139 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: non-option arguments are illegal: ",
140 argv[0]);
141 while (optindcxx . . $ optind. < argc)
142 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s ", argv[optindcxx . . $ optind.++]);
143 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n");
144 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
145 exitcxx . . $ exit(3ca292c338df9bb3).(1);
146 }
147
148 if (!local_host) {
149 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: : option -H, --local is required\n",
150 argv[0]);
151 usagecxx . . $ usage(fda57c8427c60377).(argv[0]);
152 exitcxx . . $ exit(3ca292c338df9bb3).(1);
153 }
154
155 /* Set some basic values which depend on the address family. */
156 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(local_host, "0"))
157 local_host = "0.0.0.0";
158
159 snprintfcxx . . $ snprintf(ea502d73e74c754c).(port_buffer, 10, "%d", local_port);
160 error = getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(local_host, port_buffer, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &hst_res);
161 if (error) {
162 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: getaddrinfo failed: %s\n", argv[0], local_host);
163 exitcxx . . $ exit(3ca292c338df9bb3).(1);
164 }
165
166 pf_class = hst_res->ai_familycxx . . $ addrinfo#ai_family.;
167 switch (pf_class) {
168 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
169 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
170 memcpycxx . . $ memcpy(cc817cb175f282d).(&host.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., hst_res->ai_addrcxx . . $ addrinfo#ai_addr., hst_res->ai_addrlencxx . . $ addrinfo#ai_addrlen.);
171 break;
172 default:
173 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Invalid address type.\n");
174 exitcxx . . $ exit(3ca292c338df9bb3).(1);
175 break;
176 }
177
178 freeaddrinfocxx . . $ freeaddrinfo(aadc8f19092a28e8).(hst_res);
179
180 /* Create the endpoint which will talk to nagle_snd. */
181 sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
182
183 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
184 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk);
185
186 /* Bind the sockets to the test port. */
187 test_bindcxx . . $ test_bind(18e507052d945257).(sk, &host.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(host));
188
189 /* Mark sk as being able to accept new associations. */
190 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(sk, 1);
191
192 printfcxx . . $ printf(581fddd72a8db8fc).("Listening on port:%d\n", local_port);
193
194 /* Initialize inmessage for receives. */
195 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
196 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
197 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
198 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
199 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
200 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
201 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
202 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
203 inmessage.msg_namecxx . . $ msghdr#msg_name. = &msgname;
204 inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(msgname);
205 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&msgname, 0, sizeof(msgname));
206
207 /* Get the communication up message on sk. */
208 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
209 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
210 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
211 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
212
213 printfcxx . . $ printf(581fddd72a8db8fc).("Established connection with ");
214 if (AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`! == msgname.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa..sa_familycxx . . $ sockaddr#sa_family.)
215 printfcxx . . $ printf(581fddd72a8db8fc).("%d.%d.%d.%d(%d)\n", NIPQUADcxx . . $ `src/testlib/sctputil.h:83:9`!(msgname.v4.sin_addr),
216 ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(msgname.v4.sin_port));
217 if (AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`! == msgname.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa..sa_familycxx . . $ sockaddr#sa_family.)
218 printfcxx . . $ printf(581fddd72a8db8fc).("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x(%d)\n",
219 NIP6cxx . . $ `src/testlib/sctputil.h:90:9`!(msgname.v6.sin6_addr), ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(msgname.v6.sin6_port));
220
221 timecxx . . $ time(7f38134db6521d23).(&from);
222 for (i=0; i<1000000; i++) {
223 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
224 inmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(msgname);
225 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
226 if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_NOTIFICATIONcxx . . $ `<external>/17169092326581286071/sctp.h:181:9`!)
227 break;
228 printfcxx . . $ printf(581fddd72a8db8fc).("Received %d bytes of data\n", error);
229 bytes_received += error;
230 }
231 timecxx . . $ time(7f38134db6521d23).(&to);
232
233 printfcxx . . $ printf(581fddd72a8db8fc).("\t%d messages(%d bytes) successfully received in %ld "
234 "seconds.\n", i, bytes_received, to - from);
235 printfcxx . . $ printf(581fddd72a8db8fc).("The receive rate is %ld bytes/second\n",
236 bytes_received/(to - from));
237
238 /* Shut down the link. */
239 error = 0;
240 closecxx . . $ close(7864480464b09eea).(sk);
241
242 return 0;
243 }