|
reSIProcate/stack
9694
|
00001 #include <iostream> 00002 #include <memory> 00003 00004 #include "rutil/DataStream.hxx" 00005 #include "resip/stack/SipMessage.hxx" 00006 #include "resip/stack/ConnectionBase.hxx" 00007 00008 #include "resip/stack/Helper.hxx" 00009 #include "resip/stack/Uri.hxx" 00010 #include "resip/stack/Helper.hxx" 00011 #include "resip/stack/Transport.hxx" 00012 #include "resip/stack/SdpContents.hxx" 00013 #include "resip/stack/test/TestSupport.hxx" 00014 #include "resip/stack/PlainContents.hxx" 00015 #include "resip/stack/UnknownHeaderType.hxx" 00016 #include "resip/stack/UnknownParameterType.hxx" 00017 #include "rutil/Logger.hxx" 00018 #include "rutil/ParseBuffer.hxx" 00019 #include "rutil/Random.hxx" 00020 00021 00022 using namespace resip; 00023 using namespace std; 00024 00025 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00026 #define CRLF "\r\n" 00027 00028 class FakeTransport : public Transport 00029 { 00030 public: 00031 FakeTransport(Fifo<TransactionMessage>& rxFifo, 00032 int portNum, 00033 IpVersion version, 00034 const Data& interfaceObj, 00035 const Data& tlsDomain = Data::Empty) : 00036 Transport(rxFifo, portNum, version, interfaceObj, tlsDomain) 00037 {} 00038 00039 virtual TransportType transport() const { return TCP; } 00040 virtual bool isFinished() const { assert(0); return true; } 00041 virtual void process(FdSet& fdset) { assert(0); } 00042 virtual void process() { assert(0); } 00043 virtual void processTransmitQueue() { assert(0); } 00044 virtual void buildFdSet( FdSet& fdset) { assert(0); } 00045 00046 virtual bool isReliable() const { assert(0); return true; } 00047 virtual bool isDatagram() const { assert(0); return true; } 00048 virtual bool shareStackProcessAndSelect() const { assert(0); return true;} 00049 virtual void startOwnProcessing() { assert(0); } 00050 virtual bool hasDataToSend() const { assert(0); return false; } 00051 virtual void setPollGrp(FdPollGrp* grp) { assert(0); } 00052 virtual unsigned int getFifoSize() const { assert(0); return 0; } 00053 00054 virtual void send(std::auto_ptr<SendData> data) { assert(0); } 00055 void flush() {mStateMachineFifo.flush();} 00056 }; 00057 00058 class TestConnection : public ConnectionBase 00059 { 00060 public: 00061 TestConnection(Transport* transport,const Tuple& who, const Data& bytes) : 00062 ConnectionBase(transport,who), 00063 mTestStream(bytes), 00064 mStreamPos(0) 00065 {} 00066 00067 bool read(unsigned int minChunkSize, unsigned int maxChunkSize) 00068 { 00069 unsigned int chunk = Random::getRandom() % maxChunkSize; 00070 chunk = resipMax(chunk, minChunkSize); 00071 chunk = resipMin(chunk, maxChunkSize); 00072 unsigned int chunkPos = mTestStream.size() - mStreamPos; 00073 chunk = resipMin(chunk, chunkPos); 00074 assert(chunk > 0); 00075 std::pair<char*, size_t> writePair = getWriteBuffer(); 00076 memcpy(writePair.first, mTestStream.data() + mStreamPos, chunk); 00077 mStreamPos += chunk; 00078 assert(mStreamPos <= mTestStream.size()); 00079 00080 preparseNewBytes(chunk); 00081 return mStreamPos != mTestStream.size(); 00082 } 00083 00084 private: 00085 Data mTestStream; 00086 unsigned int mStreamPos; 00087 // Fifo<TransactionMessage>& mRxFifo; 00088 }; 00089 00090 int 00091 main(int argc, char** argv) 00092 { 00093 Log::initialize(Log::Cout, Log::Info, argv[0]); 00094 00095 Data bytes("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n" 00096 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n" 00097 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n" 00098 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n" 00099 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n" 00100 "Call-ID: 6c64b42fce01b007\r\n" 00101 "CSeq: 2 INVITE\r\n" 00102 "Route: <sip:proxy@192.168.2.220:5060;lr>\r\n" 00103 "Contact: <sip:192.168.2.15:5100>\r\n" 00104 "Content-Length: 0\r\n" 00105 "\r\n" 00106 "\r\n\r\n" //keepalive 00107 "INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n" 00108 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n" 00109 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n" 00110 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n" 00111 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n" 00112 "Call-ID: 6c64b42fce01b007\r\n" 00113 "CSeq: 2 INVITE\r\n" 00114 "Record-Route: <sip:proxy@192.168.2.220:5060;lr>\r\n" 00115 "Contact: <sip:192.168.2.15:5100>\r\n" 00116 "Max-Forwards: 69\r\n" 00117 "Content-Type: application/sdp\r\n" 00118 "Content-Length: 307\r\n" 00119 "\r\n" 00120 "v=0\r\n" 00121 "o=M2TUA 1589993278 1032390928 IN IP4 192.168.2.15\r\n" 00122 "s=-\r\n" 00123 "c=IN IP4 192.168.2.15\r\n" 00124 "t=0 0\r\n" 00125 "m=audio 9000 RTP/AVP 103 97 100 101 0 8 102\r\n" 00126 "a=rtpmap:103 ISAC/16000\r\n" 00127 "a=rtpmap:97 IPCMWB/16000\r\n" 00128 "a=rtpmap:100 EG711U/8000\r\n" 00129 "a=rtpmap:101 EG711A/8000\r\n" 00130 "a=rtpmap:0 PCMU/8000\r\n" 00131 "a=rtpmap:8 PCMA/8000\r\n" 00132 "a=rtpmap:102 iLBC/8000\r\n"); 00133 00134 Fifo<TransactionMessage> testRxFifo; 00135 FakeTransport fake(testRxFifo, 5060, V4, Data::Empty); 00136 Tuple who(fake.getTuple()); 00137 00138 int chunkRange = 700; 00139 unsigned int runs = 100; 00140 00141 for (unsigned int i=0; i < runs; i++) 00142 { 00143 TestConnection cBase(&fake,who, bytes); 00144 int minChunk = (Random::getRandom() % chunkRange)+1; 00145 int maxChunk = (Random::getRandom() % chunkRange)+1; 00146 if (maxChunk < minChunk) swap(maxChunk, minChunk); 00147 while(cBase.read(minChunk, maxChunk)); 00148 } 00149 fake.flush(); 00150 assert(testRxFifo.size() == runs * 3); 00151 00152 cerr << "\nTEST OK" << endl; 00153 return 0; 00154 } 00155 00156 /* ==================================================================== 00157 * The Vovida Software License, Version 1.0 00158 * 00159 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00160 * 00161 * Redistribution and use in source and binary forms, with or without 00162 * modification, are permitted provided that the following conditions 00163 * are met: 00164 * 00165 * 1. Redistributions of source code must retain the above copyright 00166 * notice, this list of conditions and the following disclaimer. 00167 * 00168 * 2. Redistributions in binary form must reproduce the above copyright 00169 * notice, this list of conditions and the following disclaimer in 00170 * the documentation and/or other materials provided with the 00171 * distribution. 00172 * 00173 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00174 * and "Vovida Open Communication Application Library (VOCAL)" must 00175 * not be used to endorse or promote products derived from this 00176 * software without prior written permission. For written 00177 * permission, please contact vocal@vovida.org. 00178 * 00179 * 4. Products derived from this software may not be called "VOCAL", nor 00180 * may "VOCAL" appear in their name, without prior written 00181 * permission of Vovida Networks, Inc. 00182 * 00183 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00184 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00185 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00186 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00187 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00188 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00189 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00190 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00191 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00192 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00193 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00194 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00195 * DAMAGE. 00196 * 00197 * ==================================================================== 00198 * 00199 * This software consists of voluntary contributions made by Vovida 00200 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00201 * Inc. For more information on Vovida Networks, Inc., please see 00202 * <http://www.vovida.org/>. 00203 * 00204 */
1.7.5.1