1 /* SCTP kernel Implementation
2 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
5 * This file does send and receive for 500 threads on a unique association for
6 * THREAD_SND_RCV_LOOPS = 10 many times. To change the number of threads
7 * change the THREADS valuen and loop change the THREAD_SND_RCV_LOOPS.
9 * The SCTP implementation is free software;
10 * you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * The SCTP implementation is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * ************************
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
26 * Please send any bug reports or fixes you make to the
28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
33 * Any bugs reported given to us we will try to fix... any fixes shared will
34 * be incorporated into the next SCTP release
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h> /* for sockaddr_in */
46 #include <arpa/inet.h>
48 #include <netinet/sctp.h>
50 #include <linux/socket.h>
53 #define THREADS 10 /* FIXME should be 500 instead of 10 */
54 #define THREAD_SND_RCV_LOOPS 10
56 char *TCID = __FILE__;
63 struct sockaddr_in conn_addr;
64 char *message = "hello, world!\n";
69 struct msghdr inmessage;
71 char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
74 memset(&inmessage, 0, sizeof(inmessage));
77 iov.iov_base = buffer;
79 inmessage.msg_iov = &iov;
80 inmessage.msg_iovlen = 1;
81 inmessage.msg_control = incmsg;
82 inmessage.msg_controllen = sizeof(incmsg);
84 cnt = test_recvmsg(acpt_sk,&inmessage, MSG_WAITALL);
85 test_check_msg_data(&inmessage, cnt, strlen(message) + 1, MSG_EOR,
91 struct msghdr outmessage;
92 struct sctp_sndrcvinfo *sinfo;
96 char outcmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))];
98 memset(&outmessage, 0, sizeof(outmessage));
99 buffer_snd = malloc(100);
101 outmessage.msg_name = &conn_addr;
102 outmessage.msg_namelen = sizeof(conn_addr);
103 outmessage.msg_iov = &out_iov;
104 outmessage.msg_iovlen = 1;
105 outmessage.msg_control = outcmsg;
106 outmessage.msg_controllen = sizeof(outcmsg);
107 outmessage.msg_flags = 0;
109 cmsg = CMSG_FIRSTHDR(&outmessage);
110 cmsg->cmsg_level = IPPROTO_SCTP;
111 cmsg->cmsg_type = SCTP_SNDRCV;
112 cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
113 outmessage.msg_controllen = cmsg->cmsg_len;
115 sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
116 memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
117 outmessage.msg_iov->iov_base = message;
118 outmessage.msg_iov->iov_len = (strlen(message) + 1);
120 test_sendmsg(client_sk, &outmessage, 0, strlen(message)+1);
123 void * relay (int id) {
126 } else if (id == THREADS -1) {
142 pthread_t thread[THREADS];
147 struct sockaddr_in lstn_addr;
148 socklen_t len = sizeof(struct sockaddr_in);
149 struct sockaddr_in svr_addr;
151 pthread_attr_init(&attr);
152 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
154 server_sk = test_socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
155 client_sk = test_socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
157 lstn_addr.sin_family = AF_INET;
158 lstn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
159 lstn_addr.sin_port = htons(SCTP_TESTPORT_1);
161 conn_addr.sin_family = AF_INET;
162 conn_addr.sin_addr.s_addr = SCTP_IP_LOOPBACK;
163 conn_addr.sin_port = htons(SCTP_TESTPORT_1);
165 test_bind(server_sk, (struct sockaddr *)&lstn_addr,
166 sizeof(struct sockaddr_in));
168 test_listen(server_sk,10);
170 test_connect(client_sk,(struct sockaddr *)&conn_addr,len);
172 acpt_sk = test_accept(server_sk, (struct sockaddr *)&svr_addr, &len);
174 for ( i = 0; i < THREAD_SND_RCV_LOOPS; i++ ) {
175 for (cnt = 1; cnt < THREADS; cnt++) {
176 status = pthread_create(&thread[cnt], &attr,
177 (void *)relay, (void*)cnt);
179 tst_brkm(TBROK, tst_exit, "pthread_create "
180 "failed status:%d, errno:%d", status,
184 pthread_attr_destroy(&attr);
185 for (cnt = 1; cnt < THREADS ; cnt++) {
186 exit_status = pthread_join (thread[cnt], &result);
187 if (exit_status == -1)
188 tst_brkm(TBROK, tst_exit, "pthread_join "
189 "Thread #%d exited with status:%d",
194 tst_resm(TPASS, "send and receive data across multiple threads - "