Mercurial > hg > freeDiameter
comparison tests/testsctp.c @ 706:4ffbc9f1e922
Large UNTESTED commit with the following changes:
* Improved DiameterIdentity handling (esp. interationalization issues),
and improve efficiency of some string operations in peers, sessions,
and dictionary modules (closes #7)
* Cleanup in the session module to free only unreferenced sessions (#16)
* Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
* Improved peer state machine algorithm to counter SCTP multistream race
condition.
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 09 Feb 2011 15:26:58 +0900 |
parents | 2e94ef0515d7 |
children | 5d8ac5da7092 |
comparison
equal
deleted
inserted
replaced
705:f0cb8f465763 | 706:4ffbc9f1e922 |
---|---|
53 #ifdef DISABLE_SCTP | 53 #ifdef DISABLE_SCTP |
54 INIT_FD(); | 54 INIT_FD(); |
55 /* In this case, we don't perform this simple test */ | 55 /* In this case, we don't perform this simple test */ |
56 PASSTEST(); | 56 PASSTEST(); |
57 #else /* DISABLE_SCTP */ | 57 #else /* DISABLE_SCTP */ |
58 int sock, srvsock, clisock; | 58 struct cnxctx cli, srv; /* we use only their cc_socket & cc_state */ |
59 int sock; | |
59 char buf1[]="abcdef"; | 60 char buf1[]="abcdef"; |
60 char *buf2; | 61 char *buf2; |
61 size_t sz; | 62 size_t sz; |
62 struct fd_list eps = FD_LIST_INITIALIZER(eps); | 63 struct fd_list eps = FD_LIST_INITIALIZER(eps); |
63 uint32_t status = 0; | |
64 uint16_t str; | 64 uint16_t str; |
65 int ev; | 65 int ev; |
66 | 66 |
67 /* Initialize the server addresses */ | 67 /* Initialize the server addresses */ |
68 { | 68 { |
77 aip = aip->ai_next; | 77 aip = aip->ai_next; |
78 }; | 78 }; |
79 freeaddrinfo(ai); | 79 freeaddrinfo(ai); |
80 } | 80 } |
81 | 81 |
82 memset(&cli, 0, sizeof(cli)); | |
83 memset(&srv, 0, sizeof(srv)); | |
84 | |
82 /* First, initialize the daemon modules */ | 85 /* First, initialize the daemon modules */ |
83 INIT_FD(); | 86 INIT_FD(); |
84 | 87 |
85 /* Restrain the # of streams */ | 88 /* Restrain the # of streams */ |
86 fd_g_config->cnf_sctp_str = NB_STREAMS; | 89 fd_g_config->cnf_sctp_str = NB_STREAMS; |
90 | 93 |
91 /* Accept incoming clients */ | 94 /* Accept incoming clients */ |
92 CHECK( 0, fd_sctp_listen( sock )); | 95 CHECK( 0, fd_sctp_listen( sock )); |
93 | 96 |
94 /* Now, create the client socket */ | 97 /* Now, create the client socket */ |
95 CHECK( 0, fd_sctp_client( &clisock, 0, TEST_PORT, &eps )); | 98 CHECK( 0, fd_sctp_client( &cli.cc_socket, 0, TEST_PORT, &eps )); |
96 | 99 |
97 /* Accept this connection */ | 100 /* Accept this connection */ |
98 srvsock = accept(sock, NULL, NULL); | 101 srv.cc_socket = accept(sock, NULL, NULL); |
99 | 102 |
100 /* Send a first message */ | 103 /* Send a first message */ |
101 CHECK( 0, fd_sctp_sendstr(srvsock, 1, (uint8_t *)buf1, sizeof(buf1), &status) ); | 104 CHECK( 0, fd_sctp_sendstr(&srv, 1, (uint8_t *)buf1, sizeof(buf1) ) ); |
102 CHECK( 0, status); | 105 CHECK( 0, srv.cc_state); |
103 | 106 |
104 /* Receive this message */ | 107 /* Receive this message */ |
105 redo1: | 108 redo1: |
106 CHECK( 0, fd_sctp_recvmeta(clisock, &str, (uint8_t **)&buf2, &sz, &ev, &status) ); | 109 CHECK( 0, fd_sctp_recvmeta(&cli, &str, (uint8_t **)&buf2, &sz, &ev) ); |
107 if (ev == FDEVP_CNX_EP_CHANGE) | 110 if (ev == FDEVP_CNX_EP_CHANGE) |
108 goto redo1; | 111 goto redo1; |
109 CHECK( FDEVP_CNX_MSG_RECV, ev); | 112 CHECK( FDEVP_CNX_MSG_RECV, ev); |
110 CHECK( 0, status); | 113 CHECK( 0, cli.cc_state); |
111 CHECK( 1, str); | 114 CHECK( 1, str); |
112 CHECK( sizeof(buf1), sz ); | 115 CHECK( sizeof(buf1), sz ); |
113 CHECK( 0, memcmp(buf1, buf2, sz) ); | 116 CHECK( 0, memcmp(buf1, buf2, sz) ); |
114 free(buf2); buf2 = NULL; | 117 free(buf2); buf2 = NULL; |
115 | 118 |
116 /* Send in the other direction */ | 119 /* Send in the other direction */ |
117 CHECK( 0, fd_sctp_sendstr(clisock, 2, (uint8_t *)buf1, sizeof(buf1), &status) ); | 120 CHECK( 0, fd_sctp_sendstr(&cli, 2, (uint8_t *)buf1, sizeof(buf1)) ); |
118 CHECK( 0, status); | 121 CHECK( 0, cli.cc_state); |
119 | 122 |
120 /* Receive this message */ | 123 /* Receive this message */ |
121 redo2: | 124 redo2: |
122 CHECK( 0, fd_sctp_recvmeta(srvsock, &str, (uint8_t **)&buf2, &sz, &ev, &status) ); | 125 CHECK( 0, fd_sctp_recvmeta(&srv, &str, (uint8_t **)&buf2, &sz, &ev) ); |
123 if (ev == FDEVP_CNX_EP_CHANGE) | 126 if (ev == FDEVP_CNX_EP_CHANGE) |
124 goto redo2; | 127 goto redo2; |
125 CHECK( FDEVP_CNX_MSG_RECV, ev); | 128 CHECK( FDEVP_CNX_MSG_RECV, ev); |
126 CHECK( 0, status); | 129 CHECK( 0, srv.cc_state); |
127 CHECK( 2, str); | 130 CHECK( 2, str); |
128 CHECK( sizeof(buf1), sz ); | 131 CHECK( sizeof(buf1), sz ); |
129 CHECK( 0, memcmp(buf1, buf2, sz) ); | 132 CHECK( 0, memcmp(buf1, buf2, sz) ); |
130 free(buf2); buf2 = NULL; | 133 free(buf2); buf2 = NULL; |
131 | 134 |