/[resiprocate]/main/sip/resiprocate/test/testTls.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/test/testTls.cxx

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27