comparison freeDiameter/tests/testsctp.c @ 477:4e4ed23028ca

Add a simple test to verify ticket #12
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 09 Aug 2010 18:06:09 +0900
parents
children b65f32c20e6d
comparison
equal deleted inserted replaced
476:47bd114fc55e 477:4e4ed23028ca
1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
4 * *
5 * Copyright (c) 2010, WIDE Project and NICT *
6 * All rights reserved. *
7 * *
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
9 * permitted provided that the following conditions are met: *
10 * *
11 * * Redistributions of source code must retain the above *
12 * copyright notice, this list of conditions and the *
13 * following disclaimer. *
14 * *
15 * * Redistributions in binary form must reproduce the above *
16 * copyright notice, this list of conditions and the *
17 * following disclaimer in the documentation and/or other *
18 * materials provided with the distribution. *
19 * *
20 * * Neither the name of the WIDE Project or NICT nor the *
21 * names of its contributors may be used to endorse or *
22 * promote products derived from this software without *
23 * specific prior written permission of WIDE Project and *
24 * NICT. *
25 * *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/
35
36 #include "tests.h"
37
38 #include <cnxctx.h>
39
40 #ifndef TEST_PORT
41 #define TEST_PORT 3868
42 #endif /* TEST_PORT */
43
44 #ifndef NB_STREAMS
45 #define NB_STREAMS 10
46 #endif /* NB_STREAMS */
47
48
49
50 /* Main test routine */
51 int main(int argc, char *argv[])
52 {
53 #ifdef DISABLE_SCTP
54 /* In this case, we don't perform this simple test */
55 PASSTEST();
56 #endif
57 int sock, srvsock, clisock;
58 char buf1[]="abcdef";
59 char *buf2;
60 size_t sz;
61 struct fd_list eps = FD_LIST_INITIALIZER(eps);
62 uint32_t status = 0;
63 uint16_t str;
64 int ev;
65
66 /* Initialize the server addresses */
67 {
68 struct addrinfo hints, *ai, *aip;
69 memset(&hints, 0, sizeof(hints));
70 hints.ai_flags = AI_NUMERICSERV;
71 hints.ai_family = AF_INET;
72 CHECK( 0, getaddrinfo("localhost", _stringize(TEST_PORT), &hints, &ai) );
73 aip = ai;
74 while (aip) {
75 CHECK( 0, fd_ep_add_merge( &eps, aip->ai_addr, aip->ai_addrlen, EP_FL_DISC | EP_ACCEPTALL ));
76 aip = aip->ai_next;
77 };
78 freeaddrinfo(ai);
79 }
80
81 /* First, initialize the daemon modules */
82 INIT_FD();
83
84 /* Restrain the # of streams */
85 fd_g_config->cnf_sctp_str = NB_STREAMS;
86
87 /* Create the server socket */
88 CHECK( 0, fd_sctp_create_bind_server( &sock, AF_INET, &eps, TEST_PORT ));
89
90 /* Accept incoming clients */
91 CHECK( 0, fd_sctp_listen( sock ));
92
93 /* Now, create the client socket */
94 CHECK( 0, fd_sctp_client( &clisock, 0, TEST_PORT, &eps ));
95
96 /* Accept this connection */
97 srvsock = accept(sock, NULL, NULL);
98
99 /* Send a first message */
100 CHECK( 0, fd_sctp_sendstr(srvsock, 1, (uint8_t *)buf1, sizeof(buf1), &status) );
101 CHECK( 0, status);
102
103 /* Receive this message */
104 CHECK( 0, fd_sctp_recvmeta(clisock, &str, (uint8_t **)&buf2, &sz, &ev, &status) );
105 CHECK( FDEVP_CNX_MSG_RECV, ev);
106 CHECK( 0, status);
107 CHECK( 1, str);
108 CHECK( sizeof(buf1), sz );
109 CHECK( 0, memcmp(buf1, buf2, sz) );
110 free(buf2); buf2 = NULL;
111
112 /* Send in the other direction */
113 CHECK( 0, fd_sctp_sendstr(clisock, 2, (uint8_t *)buf1, sizeof(buf1), &status) );
114 CHECK( 0, status);
115
116 /* Receive this message */
117 CHECK( 0, fd_sctp_recvmeta(srvsock, &str, (uint8_t **)&buf2, &sz, &ev, &status) );
118 CHECK( FDEVP_CNX_MSG_RECV, ev);
119 CHECK( 0, status);
120 CHECK( 2, str);
121 CHECK( sizeof(buf1), sz );
122 CHECK( 0, memcmp(buf1, buf2, sz) );
123 free(buf2); buf2 = NULL;
124
125 /* That's all for the tests yet */
126 PASSTEST();
127 }
128
"Welcome to our mercurial repository"