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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27