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

Contents of /main/resip/stack/test/testNonInviteServerTx.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: 6389 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 #include "resip/stack/SipStack.hxx"
2 #include "resip/stack/Transport.hxx"
3 #include "resip/stack/Uri.hxx"
4 #include "resip/stack/Helper.hxx"
5 #include "resip/stack/UdpTransport.hxx"
6
7 #include "rutil/Logger.hxx"
8 #include "rutil/DataStream.hxx"
9
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13
14
15 using namespace resip;
16 using namespace std;
17
18 #define RESIPROCATE_SUBSYSTEM Subsystem::APP
19 #define CRLF "\r\n"
20
21
22 SipStack* client=0;
23 Fifo<Message> received;
24 UdpTransport* server=0;
25
26 void
27 doit(int serverResponse, int expectedRetrans, int expectedClientResponse);
28
29
30 int
31 main(int argc, char *argv[])
32 {
33 Log::initialize(Log::Cout, Log::Debug, argv[0]);
34
35 InfoLog( << "Starting up, making stack");
36
37 client = new SipStack();
38 client->addTransport(UDP, 5060);
39
40 server = new UdpTransport("localhost", 5070, "default", received);
41
42
43 // Test 1:
44 // client sends a reg, server does nothing, client should retransmit 10
45 // times, client should receive 408
46
47 // Test 2:
48 // client sends a reg, server sends 100, client should retransmit 7 times
49 // client should receive 408
50
51 // Test 3:
52 // client sends a reg, server sends 200, client shouldn't retransmit at all
53 // client should receive 200
54
55 // Test 4:
56 // client sends a reg, server sends 400, client shouldn't retransmit at all
57 // client should receive 400
58
59 //doit(100, 7, 408);
60 doit(200, 1, 200);
61 doit(400, 1, 400);
62 doit(0, 10, 408);
63
64 return 0;
65 }
66
67
68 void
69 doit(int serverResponse, int expectedRetrans, int expectedClientResponse)
70 {
71 InfoLog (<< "Running test: " << serverResponse << " " << expectedRetrans << " " << expectedClientResponse);
72
73 NameAddr me;
74 me.uri().host() = "localhost";
75 me.uri().port() = 5070;
76 SipMessage* reg = Helper::makeRegister(me, me);
77 Data encoded(2048, true);
78 DataStream strm(encoded);
79 reg->encode(strm);
80 strm.flush();
81
82 client->send(*reg);
83
84 Data encodedResponse(2048, true);
85
86 int count=0;
87 while (1)
88 {
89 struct timeval tv;
90 fd_set fdReadSet;
91 int fdSetSize = 0;
92
93 // Init the fd_set for the select()
94 FD_ZERO(&fdReadSet);
95
96 fdSetSize = 0;
97 client->buildFdSet(&fdReadSet, &fdSetSize);
98 server->buildFdSet(&fdReadSet, &fdSetSize);
99
100 // block on fdset
101 tv.tv_sec = 0;
102 tv.tv_usec = 1000 * client->getTimeTillNextProcess();
103
104 // get the sip message that we just sent and process it
105 int err = select(fdSetSize, &fdReadSet, 0, 0, &tv);
106 assert (err != -1);
107
108 client->process(&fdReadSet);
109 server->process(&fdReadSet);
110
111 SipMessage* sipMessage = client->receive();
112
113 if (sipMessage)
114 {
115 InfoLog( << "got message (client)" << *sipMessage);
116 assert(sipMessage->isResponse());
117 assert(sipMessage->header(h_StatusLine).responseCode() == expectedClientResponse);
118 assert(count == expectedRetrans);
119 return;
120 }
121
122 client->process(&fdReadSet);
123 if (received.messageAvailable())
124 {
125 count++;
126
127 SipMessage* sip = dynamic_cast<SipMessage*>(received.getNext());
128 assert(sip);
129 InfoLog( << "got message (server)" << *sip);
130
131 if (serverResponse)
132 {
133 SipMessage* response = Helper::makeResponse(*sip, serverResponse);
134 DebugLog (<< "server sending response = " << endl << *response);
135
136 DataStream strm(encodedResponse);
137 response->encode(strm);
138 strm.flush();
139
140 // create address to send to
141 struct sockaddr_in sa;
142
143 sa.sin_family = PF_INET;
144 sa.sin_addr.s_addr = inet_addr("127.0.0.1");
145 sa.sin_port = htons(5060);
146
147 server->send(sa, encodedResponse);
148 }
149
150 delete sip;
151
152 }
153
154 usleep(20);
155 }
156 }
157 /* ====================================================================
158 * The Vovida Software License, Version 1.0
159 *
160 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
161 *
162 * Redistribution and use in source and binary forms, with or without
163 * modification, are permitted provided that the following conditions
164 * are met:
165 *
166 * 1. Redistributions of source code must retain the above copyright
167 * notice, this list of conditions and the following disclaimer.
168 *
169 * 2. Redistributions in binary form must reproduce the above copyright
170 * notice, this list of conditions and the following disclaimer in
171 * the documentation and/or other materials provided with the
172 * distribution.
173 *
174 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
175 * and "Vovida Open Communication Application Library (VOCAL)" must
176 * not be used to endorse or promote products derived from this
177 * software without prior written permission. For written
178 * permission, please contact vocal@vovida.org.
179 *
180 * 4. Products derived from this software may not be called "VOCAL", nor
181 * may "VOCAL" appear in their name, without prior written
182 * permission of Vovida Networks, Inc.
183 *
184 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
185 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
186 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
187 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
188 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
189 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
190 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
191 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
192 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
193 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
194 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
195 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
196 * DAMAGE.
197 *
198 * ====================================================================
199 *
200 * This software consists of voluntary contributions made by Vovida
201 * Networks, Inc. and many individuals on behalf of Vovida Networks,
202 * Inc. For more information on Vovida Networks, Inc., please see
203 * <http://www.vovida.org/>.
204 *
205 */

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