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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7081 - (show annotations) (download)
Tue Apr 17 14:46:38 2007 UTC (12 years, 7 months ago) by bcampen
File MIME type: text/plain
File size: 6077 byte(s)
Reverting rev 7077 until it can get some review.
1 #ifndef WIN32
2 #include <sys/time.h>
3 #include <unistd.h>
4 #include <sys/socket.h>
5 #include <netinet/in.h>
6 #include <arpa/inet.h>
7 #endif
8
9 #include <sys/types.h>
10 #include <iostream>
11 #include <memory>
12
13 #include "resip/stack/Helper.hxx"
14 #include "resip/stack/SipMessage.hxx"
15 #include "resip/stack/Uri.hxx"
16 #include "resip/stack/SipStack.hxx"
17 #include "rutil/Logger.hxx"
18 #include "rutil/ThreadIf.hxx"
19
20 using namespace resip;
21 using namespace std;
22
23 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
24
25 class Server : public ThreadIf
26 {
27 public:
28
29 Server(SipStack& stack, int numCalls, TransportType transport)
30 : mStack(stack),
31 mNumCalls(numCalls),
32 mTransport(transport)
33 {}
34
35 void thread()
36 {
37 InfoLog(<<"This is the Server");
38
39 UInt64 startTime = Timer::getTimeMs();
40
41 NameAddr contact;
42 contact.uri().scheme() = "sip";
43 contact.uri().user() = "fluffy";
44
45 contact.uri().host() = SipStack::getHostname();
46 contact.uri().port() = 5070;
47 contact.uri().param(p_transport) = Tuple::toData(mTransport);
48
49 int calls = mNumCalls;
50 while(calls > 0)
51 {
52 FdSet fdset;
53 mStack.buildFdSet(fdset);
54 int err = fdset.selectMilliSeconds(0);
55 assert (err != -1);
56 mStack.process(fdset);
57
58 SipMessage* received = mStack.receive();
59 if (received)
60 {
61 auto_ptr<SipMessage> forDel(received);
62 MethodTypes meth = received->header(h_RequestLine).getMethod();
63 ErrLog ( << "Server received: " << getMethodName(meth));
64 if ( meth == INVITE )
65 {
66 Data localTag = Helper::computeTag(4);
67 auto_ptr<SipMessage> msg180(Helper::makeResponse(*received, 180, contact));
68 msg180->header(h_To).param(p_tag) = localTag;
69 ErrLog( << "Sent 180");
70 mStack.send( *msg180);
71
72 auto_ptr<SipMessage> msg200(Helper::makeResponse(*received, 200, contact));
73 msg200->header(h_To).param(p_tag) = localTag;
74 ErrLog( << "Sent 200");
75 mStack.send(*msg200);
76 }
77 if ( meth == BYE)
78 {
79 auto_ptr<SipMessage> msg200(Helper::makeResponse(*received, 200, contact));
80 calls--;
81 ErrLog( << "Sent 200 to BYE");
82 mStack.send(*msg200);
83 }
84 }
85 }
86 UInt64 endTime = Timer::getTimeMs();
87
88 CritLog(<< "Completed: " << mNumCalls << " calls in " << endTime - startTime << "ms, "
89 << mNumCalls*1000 / (float)(endTime - startTime) << " CPS");
90 }
91 private:
92 SipStack& mStack;
93 int mNumCalls;
94 TransportType mTransport;
95 };
96
97 int
98 main(int argc, char* argv[])
99 {
100 if (argc != 4)
101 {
102 cerr << argv[0] << " LOG_LEVEL NUM_CALLS PROTOCOL" << endl;
103 exit(-1);
104 }
105 Log::initialize(Log::Cout, Log::toLevel(argv[1]), argv[0]);
106 SipStack stack;
107
108
109 TransportType protocol = UDP;
110 if (strcasecmp(argv[3], "UDP") == 0)
111 {
112 protocol = UDP;
113 }
114 else if (strcasecmp(argv[3], "TCP") == 0)
115 {
116 protocol = TCP;
117 }
118 else
119 {
120 cerr << argv[0] << " LOG_LEVEL TARGET_URI PROTOCOL" << endl;
121 }
122
123 stack.addTransport(protocol, 5070);
124
125
126 int numCalls = atoi(argv[2]);
127
128 if (numCalls == 0)
129 {
130 cerr << argv[0] << " LOG_LEVEL NUM_CALLS" << endl;
131 exit(-1);
132 }
133
134 ::Server server(stack, numCalls, protocol);
135
136 server.run();
137 server.join();
138 return 0;
139 }
140 /* ====================================================================
141 * The Vovida Software License, Version 1.0
142 *
143 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
144 *
145 * Redistribution and use in source and binary forms, with or without
146 * modification, are permitted provided that the following conditions
147 * are met:
148 *
149 * 1. Redistributions of source code must retain the above copyright
150 * notice, this list of conditions and the following disclaimer.
151 *
152 * 2. Redistributions in binary form must reproduce the above copyright
153 * notice, this list of conditions and the following disclaimer in
154 * the documentation and/or other materials provided with the
155 * distribution.
156 *
157 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
158 * and "Vovida Open Communication Application Library (VOCAL)" must
159 * not be used to endorse or promote products derived from this
160 * software without prior written permission. For written
161 * permission, please contact vocal@vovida.org.
162 *
163 * 4. Products derived from this software may not be called "VOCAL", nor
164 * may "VOCAL" appear in their name, without prior written
165 * permission of Vovida Networks, Inc.
166 *
167 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
168 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
170 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
171 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
172 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
173 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
174 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
175 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
176 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
178 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
179 * DAMAGE.
180 *
181 * ====================================================================
182 *
183 * This software consists of voluntary contributions made by Vovida
184 * Networks, Inc. and many individuals on behalf of Vovida Networks,
185 * Inc. For more information on Vovida Networks, Inc., please see
186 * <http://www.vovida.org/>.
187 *
188 */

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