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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (show annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 8 months ago) by dworley
File MIME type: text/plain
File size: 5828 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 #include <memory>
2
3 #include "rutil/Logger.hxx"
4 #include "rutil/Timer.hxx"
5 #include "resip/stack/DeprecatedDialog.hxx"
6 #include "resip/stack/SipMessage.hxx"
7 #include "resip/stack/Helper.hxx"
8 #include "Resolver.hxx"
9
10
11 #include "InviteClient.hxx"
12 #include "Transceiver.hxx"
13
14 using namespace resip;
15 using namespace Loadgen;
16 using namespace std;
17
18 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
19
20 InviteClient::InviteClient(Transceiver& transceiver, const resip::Uri& proxy,
21 int firstExtension, int lastExtension,
22 int numInvites)
23 : mTransceiver(transceiver),
24 mProxy(proxy),
25 mFirstExtension(firstExtension),
26 mLastExtension(lastExtension),
27 mNumInvites(numInvites)
28 {
29 if (mNumInvites == 0)
30 {
31 mNumInvites = (mLastExtension - mFirstExtension) / 2;
32 }
33 }
34
35 void
36 InviteClient::go()
37 {
38 int numInvited = 0;
39
40 Resolver target(mProxy);
41
42 NameAddr to;
43 to.uri() = mProxy;
44
45 NameAddr from;
46 from.uri() = mProxy;
47
48 NameAddr contact;
49 contact.uri() = mTransceiver.contactUri();
50
51 UInt64 startTime = Timer::getTimeMs();
52 InfoLog(<< "Invite client is attempting " << mNumInvites << " calls.");
53 while (numInvited < mNumInvites)
54 {
55 for (int i=mFirstExtension; i < mLastExtension-1 && numInvited < mNumInvites; i+=2)
56 {
57 contact.uri().user() = Data(i);
58 from.uri().user() = Data(i);
59 to.uri().user() = Data(i+1);
60
61 auto_ptr<SipMessage> invite(Helper::makeInvite(to, from, contact));
62
63 mTransceiver.send(target, *invite);
64
65 try
66 {
67 auto_ptr<SipMessage> i_100(waitForResponse(100, 1000));
68 auto_ptr<SipMessage> i_180(waitForResponse(180, 1000));
69 auto_ptr<SipMessage> i_200(waitForResponse(200, 1000));
70
71 DebugLog(<< "Creating dialog.");
72
73 DeprecatedDialog dlog(contact);
74
75 DebugLog(<< "Creating dialog as UAC.");
76 dlog.createDialogAsUAC(*i_200);
77
78 DebugLog(<< "making ack.");
79 auto_ptr<SipMessage> ack(dlog.makeAck(*invite));
80 DebugLog(<< "making bye.");
81 auto_ptr<SipMessage> bye(dlog.makeBye());
82
83 DebugLog(<< "Sending ack: << *ack");
84
85 mTransceiver.send(*ack);
86 mTransceiver.send(*bye);
87 auto_ptr<SipMessage> b_200(waitForResponse(200, 1000));
88 numInvited++;
89 }
90 catch(Exception e)
91 {
92 ErrLog(<< "Proxy not responding.");
93 exit(-1);
94 }
95 }
96 }
97 UInt64 elapsed = Timer::getTimeMs() - startTime;
98 cout << mNumInvites << " peformed in " << elapsed << " ms, a rate of "
99 << mNumInvites / ((float) elapsed / 1000.0) << " calls per second." << endl;
100 }
101
102 SipMessage*
103 InviteClient::waitForResponse(int responseCode,
104 int waitMs)
105 {
106 DebugLog(<< "Waiting for a " << responseCode << " for " << waitMs << "ms");
107 SipMessage* reg = mTransceiver.receive(waitMs);
108 DebugLog(<< "Finished waiting for " << responseCode);
109 if(reg)
110 {
111 if (reg->isResponse() &&
112 reg->header(h_StatusLine).responseCode() == responseCode)
113 {
114 return reg;
115 }
116 else
117 {
118 throw Exception("Invalid response.", __FILE__, __LINE__);
119 }
120 }
121 else
122 {
123 throw Exception("Timed out.", __FILE__, __LINE__);
124 }
125 }
126
127 /* ====================================================================
128 * The Vovida Software License, Version 1.0
129 *
130 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
131 *
132 * Redistribution and use in source and binary forms, with or without
133 * modification, are permitted provided that the following conditions
134 * are met:
135 *
136 * 1. Redistributions of source code must retain the above copyright
137 * notice, this list of conditions and the following disclaimer.
138 *
139 * 2. Redistributions in binary form must reproduce the above copyright
140 * notice, this list of conditions and the following disclaimer in
141 * the documentation and/or other materials provided with the
142 * distribution.
143 *
144 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
145 * and "Vovida Open Communication Application Library (VOCAL)" must
146 * not be used to endorse or promote products derived from this
147 * software without prior written permission. For written
148 * permission, please contact vocal@vovida.org.
149 *
150 * 4. Products derived from this software may not be called "VOCAL", nor
151 * may "VOCAL" appear in their name, without prior written
152 * permission of Vovida Networks, Inc.
153 *
154 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
155 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
156 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
157 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
158 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
159 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
160 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
161 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
162 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
163 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
164 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
165 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
166 * DAMAGE.
167 *
168 * ====================================================================
169 *
170 * This software consists of voluntary contributions made by Vovida
171 * Networks, Inc. and many individuals on behalf of Vovida Networks,
172 * Inc. For more information on Vovida Networks, Inc., please see
173 * <http://www.vovida.org/>.
174 *
175 */

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