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

Contents of /main/resip/stack/test/testUdp.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: 7373 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 #include <iostream>
6
7 #if defined (HAVE_POPT_H)
8 #include <popt.h>
9 #else
10 #ifndef WIN32
11 #warning "will not work very well without libpopt"
12 #endif
13 #endif
14
15 #include "resip/stack/UdpTransport.hxx"
16 #include "resip/stack/Helper.hxx"
17 #include "resip/stack/SipMessage.hxx"
18 #include "resip/stack/Uri.hxx"
19 #include "rutil/Data.hxx"
20 #include "rutil/DnsUtil.hxx"
21 #include "rutil/Logger.hxx"
22 #include "rutil/DataStream.hxx"
23
24 using namespace resip;
25 using namespace std;
26
27 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
28
29 int
30 main(int argc, char* argv[])
31 {
32 char* logType = 0;
33 char* logLevel = 0;
34 int runs = 100;
35 int window = 10;
36 int seltime = 100;
37
38 #if defined (HAVE_POPT_H)
39 struct poptOption table[] = {
40 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
41 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
42 {"num-runs", 'r', POPT_ARG_INT, &runs, 0, "number of calls in test", 0},
43 {"window-size", 'w', POPT_ARG_INT, &window, 0, "number of registrations in test", 0},
44 {"select-time", 's', POPT_ARG_INT, &seltime, 0, "number of runs in test", 0},
45 POPT_AUTOHELP
46 { NULL, 0, 0, NULL, 0 }
47 };
48
49 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
50 poptGetNextOpt(context);
51 #endif
52
53 #ifdef WIN32
54 Log::initialize(Log::Cout, Log::Debug, argv[0]);
55 initNetwork();
56 #else
57 Log::initialize(logType, logLevel, argv[0]);
58 #endif
59
60 cout << "Performing " << runs << " runs." << endl;
61
62 Fifo<TransactionMessage> txFifo;
63 UdpTransport* sender = new UdpTransport(txFifo, 5070, V4, StunDisabled, Data::Empty);
64
65 Fifo<TransactionMessage> rxFifo;
66 UdpTransport* receiver = new UdpTransport(rxFifo, 5080, V4, StunDisabled, Data::Empty);
67
68 NameAddr target;
69 target.uri().scheme() = "sip";
70 target.uri().user() = "fluffy";
71 target.uri().host() = "bremen.internal.xten.net";
72 target.uri().port() = 5080;
73 target.uri().param(p_transport) = "udp";
74
75 NameAddr from = target;
76 from.uri().port() = 5070;
77
78 InfoLog (<< "Creating messages");
79
80 list<SipMessage*> messages;
81 {
82 UInt64 startTime = Timer::getTimeMs();
83 for (int i=0; i<runs; i++)
84 {
85 SipMessage* m = Helper::makeInvite( target, from, from);
86 //m->header(h_Vias).front().transport() = Tuple::toData(sender->transport());
87 //m->header(h_Vias).front().sentHost() = "localhost";
88 //m->header(h_Vias).front().sentPort() = sender->port();
89 messages.push_back(m);
90 }
91
92 UInt64 elapsed = Timer::getTimeMs() - startTime;
93 cout << runs << " calls peformed in " << elapsed << " ms, a rate of "
94 << runs / ((float) elapsed / 1000.0) << " calls per second.]" << endl;
95
96 InfoLog (<< "Messages created");
97 }
98
99
100 in_addr in;
101 DnsUtil::inet_pton("127.0.0.1", in);
102 Tuple dest(in, target.uri().port(), UDP);
103 InfoLog (<< "Sending to " << dest);
104
105 UInt64 startTime = Timer::getTimeMs();
106
107 int tid=1;
108 int outstanding=0;
109 int count=0;
110 while (!messages.empty())
111 {
112 if (count > 500) exit(0);
113 // load up the send window
114 while (outstanding < window)
115 {
116 Data encoded;
117 {
118 DataStream strm(encoded);
119 SipMessage* next = messages.front();
120 messages.pop_front();
121 next->encode(strm);
122 outstanding++;
123 }
124 std::auto_ptr<SendData> toSend(sender->makeSendData(dest, encoded, Data(tid++), Data::Empty));
125 sender->send(toSend);
126 }
127
128 FdSet fdset;
129 receiver->buildFdSet(fdset);
130 //sender->buildFdSet(fdset);
131 fdset.selectMilliSeconds(seltime);
132
133 receiver->process(fdset);
134 sender->process(fdset);
135
136 Message* msg;
137 if (rxFifo.messageAvailable())
138 {
139 msg = rxFifo.getNext();
140 SipMessage* received = dynamic_cast<SipMessage*>(msg);
141 if (received)
142 {
143 received->encode(resipCout);
144 outstanding--;
145
146 assert (received->header(h_RequestLine).uri().host() == "localhost");
147 assert (received->header(h_To).uri().host() == "localhost");
148 assert (received->header(h_From).uri().host() == "localhost");
149 //assert (!received->header(h_Vias).begin()->sentHost().empty());
150 assert(received->header(h_Vias).begin()->param(p_received) == "127.0.0.1");
151 assert (received->header(h_Contacts).begin()->uri().host() == "localhost");
152 assert (!received->header(h_CallId).value().empty());
153 delete received;
154 }
155 }
156 }
157
158 UInt64 elapsed = Timer::getTimeMs() - startTime;
159 cout << runs << " calls peformed in " << elapsed << " ms, a rate of "
160 << runs / ((float) elapsed / 1000.0) << " calls per second.]" << endl;
161
162 return 0;
163 }
164 /* ====================================================================
165 * The Vovida Software License, Version 1.0
166 *
167 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
168 *
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
171 * are met:
172 *
173 * 1. Redistributions of source code must retain the above copyright
174 * notice, this list of conditions and the following disclaimer.
175 *
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in
178 * the documentation and/or other materials provided with the
179 * distribution.
180 *
181 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
182 * and "Vovida Open Communication Application Library (VOCAL)" must
183 * not be used to endorse or promote products derived from this
184 * software without prior written permission. For written
185 * permission, please contact vocal@vovida.org.
186 *
187 * 4. Products derived from this software may not be called "VOCAL", nor
188 * may "VOCAL" appear in their name, without prior written
189 * permission of Vovida Networks, Inc.
190 *
191 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
192 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
194 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
195 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
196 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
197 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
199 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
200 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
201 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
202 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
203 * DAMAGE.
204 *
205 * ====================================================================
206 *
207 * This software consists of voluntary contributions made by Vovida
208 * Networks, Inc. and many individuals on behalf of Vovida Networks,
209 * Inc. For more information on Vovida Networks, Inc., please see
210 * <http://www.vovida.org/>.
211 *
212 */

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