/[resiprocate]/main/resip/stack/test/testTls.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testTls.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9485 - (show annotations) (download)
Sat Apr 7 00:34:03 2012 UTC (7 years, 7 months ago) by dpocock
File MIME type: text/plain
File size: 7710 byte(s)
Switch over to autotools build system from dpocock-autotools branch
1 #if defined(HAVE_CONFIG_H)
2 #include "config.h"
3 #endif
4
5 #if defined (HAVE_POPT_H)
6 #include <popt.h>
7 #else
8 #ifndef WIN32
9 #warning "will not work very well without libpopt"
10 #endif
11 #endif
12
13 #include <sys/types.h>
14 #include <unistd.h> // for sleep
15 #include <iostream>
16 #include <memory>
17
18 #ifdef __MINGW32__
19 #define sleep(x) Sleep((x)*1000)
20 #endif
21
22 #include "rutil/DnsUtil.hxx"
23 #include "rutil/Inserter.hxx"
24 #include "rutil/Logger.hxx"
25 #include "resip/stack/Helper.hxx"
26 #include "resip/stack/SipMessage.hxx"
27 #include "resip/stack/SipStack.hxx"
28 #include "resip/stack/Uri.hxx"
29
30 using namespace resip;
31 using namespace std;
32
33 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
34
35 int
36 main(int argc, char* argv[])
37 {
38 #ifdef USE_SSL
39 char logType[] = "cout";
40 char logLevel[] = "DEBUG";
41
42 int window = 5*20;
43 int seltime = 100;
44
45 const int MaxStacks=100;
46 int numStacks=20;
47
48 //logLevel = "ALERT";
49 //logLevel = "INFO";
50
51 #if defined(HAVE_POPT_H)
52 struct poptOption table[] = {
53 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
54 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
55 {"num-stacks", 'r', POPT_ARG_INT, &numStacks, 0, "number of calls in test", 0},
56 {"window-size", 'w', POPT_ARG_INT, &window, 0, "number of concurrent transactions", 0},
57 {"select-time", 's', POPT_ARG_INT, &seltime, 0, "number of runs in test", 0},
58 POPT_AUTOHELP
59 { NULL, 0, 0, NULL, 0 }
60 };
61
62 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
63 poptGetNextOpt(context);
64 #endif
65
66 int runs = 3*numStacks*numStacks;
67
68 runs = 1;
69
70 Log::initialize(logType, logLevel, argv[0]);
71 cout << "Performing " << runs << " runs." << endl;
72
73 IpVersion version = V4;
74 Data bindInterface;
75 //bindInterface = Data( "127.0.0.1" );
76
77 SipStack* stack[MaxStacks];
78 for ( int s=0; s<numStacks; s++)
79 {
80 stack[s] = new SipStack;
81
82 Data domain = Data("example") + Data(s) +".com";
83
84 #ifdef USE_DTLS
85 stack[s]->addTransport(DTLS, 25000+s,version, StunDisabled, bindInterface, domain);
86 #else
87 stack[s]->addTransport(TLS, 25000+s,version, StunDisabled, bindInterface, domain);
88 #endif
89 }
90
91 NameAddr target;
92 target.uri().scheme() = "sip";
93 target.uri().user() = "fluffy";
94 target.uri().host() = Data("127.0.0.1");
95 target.uri().port() = 25000;
96 #ifdef USE_DTLS
97 target.uri().param(p_transport) = "dtls";
98 #else
99 target.uri().param(p_transport) = "tls";
100 #endif
101
102 NameAddr contact;
103 contact.uri().scheme() = "sip";
104 contact.uri().user() = "fluffy";
105 contact.uri().host() = Data("127.0.0.1");
106 contact.uri().port() = 25000;
107
108 NameAddr from = target;
109 from.uri().port() = 25000;
110
111 UInt64 startTime = Timer::getTimeMs();
112 int outstanding=0;
113 int count = 0;
114 int sent = 0;
115 int msgMod=0;
116
117 while (count < runs)
118 {
119 //InfoLog (<< "count=" << count << " messages=" << messages.size());
120
121 // load up the send window
122 while (sent < runs && outstanding < window)
123 {
124 DebugLog (<< "Sending " << count << " / " << runs << " (" << outstanding << ")");
125
126 // send from stack s to to stack r
127 int s = msgMod%numStacks;
128 int r = (msgMod/numStacks)%numStacks;
129 msgMod++;
130 if ( s == r )
131 {
132 continue;
133 }
134
135 target.uri().port() = 25000+r;
136 from.uri().port() = 25000+s;
137 contact.uri().port() = 25000+s;
138
139 SipMessage* msg = Helper::makeRegister( target, from, contact);
140 msg->header(h_Vias).front().sentPort() = 25000+s;
141 stack[s]->send(*msg);
142 outstanding++;
143 sent++;
144 delete msg;
145 }
146
147 FdSet fdset;
148 for ( int s=0; s<numStacks; s++)
149 {
150 stack[s]->buildFdSet(fdset);
151 }
152 fdset.selectMilliSeconds(seltime);
153 for ( int s=0; s<numStacks; s++)
154 {
155 stack[s]->process(fdset);
156 }
157
158 for ( int s=0; s<numStacks; s++)
159 {
160 SipMessage* msg = stack[s]->receive();
161
162 if ( msg )
163 {
164 if ( msg->isRequest() )
165 {
166 assert(msg->isRequest());
167 assert(msg->header(h_RequestLine).getMethod() == REGISTER);
168
169 SipMessage* response = Helper::makeResponse(*msg, 200);
170 stack[s]->send(*response);
171 delete response;
172 delete msg;
173 }
174 else
175 {
176 assert(msg->isResponse());
177 assert(msg->header(h_CSeq).method() == REGISTER);
178 assert(msg->header(h_StatusLine).statusCode() == 200);
179 outstanding--;
180 count++;
181 delete msg;
182 }
183 }
184 }
185 }
186 InfoLog (<< "Finished " << count << " runs");
187
188 UInt64 elapsed = Timer::getTimeMs() - startTime;
189 cout << runs << " registrations peformed in " << elapsed << " ms, a rate of "
190 << runs / ((float) elapsed / 1000.0) << " transactions per second.]" << endl;
191 #if defined(HAVE_POPT_H)
192 poptFreeContext(context);
193 #endif
194
195 while (true)
196 {
197 sleep(10);
198 }
199 #endif
200
201 return 0;
202 }
203 /* ====================================================================
204 * The Vovida Software License, Version 1.0
205 *
206 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
207 *
208 * Redistribution and use in source and binary forms, with or without
209 * modification, are permitted provided that the following conditions
210 * are met:
211 *
212 * 1. Redistributions of source code must retain the above copyright
213 * notice, this list of conditions and the following disclaimer.
214 *
215 * 2. Redistributions in binary form must reproduce the above copyright
216 * notice, this list of conditions and the following disclaimer in
217 * the documentation and/or other materials provided with the
218 * distribution.
219 *
220 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
221 * and "Vovida Open Communication Application Library (VOCAL)" must
222 * not be used to endorse or promote products derived from this
223 * software without prior written permission. For written
224 * permission, please contact vocal@vovida.org.
225 *
226 * 4. Products derived from this software may not be called "VOCAL", nor
227 * may "VOCAL" appear in their name, without prior written
228 * permission of Vovida Networks, Inc.
229 *
230 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
231 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
232 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
233 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
234 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
235 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
236 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
237 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
238 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
239 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
240 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
241 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
242 * DAMAGE.
243 *
244 * ====================================================================
245 *
246 * This software consists of voluntary contributions made by Vovida
247 * Networks, Inc. and many individuals on behalf of Vovida Networks,
248 * Inc. For more information on Vovida Networks, Inc., please see
249 * <http://www.vovida.org/>.
250 *
251 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27