예제 #1
0
            public void MatchOnRequestAndResponseTest()
            {
                SIPTransactionEngine transactionEngine = new SIPTransactionEngine();
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest("INVITE sip:dummy@udp:127.0.0.1:12014 SIP/2.0" + m_CRLF +
                                                                      "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27" + m_CRLF +
                                                                      "To: <sip:dummy@udp:127.0.0.1:12014>" + m_CRLF +
                                                                      "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                      "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                      "CSeq: 1 INVITE" + m_CRLF +
                                                                      "Contact: <sip:127.0.0.1:1234>" + m_CRLF +
                                                                      "Max-Forwards: 70" + m_CRLF +
                                                                      "User-Agent: unittest" + m_CRLF +
                                                                      "Content-Length: 5" + m_CRLF +
                                                                      "Content-Type: application/sdp" + m_CRLF +
                                                                      m_CRLF +
                                                                      "dummy");

                SIPTransaction transaction = new UACInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                transactionEngine.AddTransaction(transaction);

                SIPResponse sipResponse = SIPResponse.ParseSIPResponse("SIP/2.0 603 Nothing listening" + m_CRLF +
                                                                       "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27;rport=12013" + m_CRLF +
                                                                       "To: <sip:dummy@udp:127.0.0.1:12014>" + m_CRLF +
                                                                       "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                       "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                       "CSeq: 1 INVITE" + m_CRLF +
                                                                       "Content-Length: 0" + m_CRLF +
                                                                       m_CRLF);

                Assert.IsNotNull(transactionEngine.GetTransaction(sipResponse), "Transaction should have matched, check the hashing mechanism.");
            }
예제 #2
0
            public void AckRecognitionUnitTest()
            {
                SIPTransport clientTransport = null;
                SIPTransport serverTransport = null;

                try
                {
                    SIPTransactionEngine clientEngine   = new SIPTransactionEngine();   // Client side of the INVITE.
                    SIPEndPoint          clientEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 12013));
                    clientTransport = new SIPTransport(MockSIPDNSManager.Resolve, clientEngine, new SIPUDPChannel(clientEndPoint.GetIPEndPoint()), false);
                    SetTransportTraceEvents(clientTransport);

                    SIPTransactionEngine serverEngine      = new SIPTransactionEngine(); // Server side of the INVITE.
                    UASInviteTransaction serverTransaction = null;
                    SIPEndPoint          serverEndPoint    = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 12014));
                    serverTransport = new SIPTransport(MockSIPDNSManager.Resolve, serverEngine, new SIPUDPChannel(serverEndPoint.GetIPEndPoint()), false);
                    SetTransportTraceEvents(serverTransport);
                    serverTransport.SIPTransportRequestReceived += (localEndPoint, remoteEndPoint, sipRequest) =>
                    {
                        Console.WriteLine("Server Transport Request In: " + sipRequest.Method + ".");
                        serverTransaction = serverTransport.CreateUASTransaction(sipRequest, remoteEndPoint, localEndPoint, null);
                        SetTransactionTraceEvents(serverTransaction);
                        serverTransaction.GotRequest(localEndPoint, remoteEndPoint, sipRequest);
                    };

                    SIPURI     dummyURI      = SIPURI.ParseSIPURI("sip:dummy@" + serverEndPoint);
                    SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI);
                    inviteRequest.LocalSIPEndPoint = clientTransport.GetDefaultTransportContact(SIPProtocolsEnum.udp);

                    // Send the invite to the server side.
                    UACInviteTransaction clientTransaction = new UACInviteTransaction(clientTransport, inviteRequest, serverEndPoint, clientEndPoint, null);
                    SetTransactionTraceEvents(clientTransaction);
                    clientEngine.AddTransaction(clientTransaction);
                    clientTransaction.SendInviteRequest(serverEndPoint, inviteRequest);

                    Thread.Sleep(500);

                    Assert.IsTrue(clientTransaction.TransactionState == SIPTransactionStatesEnum.Completed, "Client transaction in incorrect state.");
                    Assert.IsTrue(serverTransaction.TransactionState == SIPTransactionStatesEnum.Confirmed, "Server transaction in incorrect state.");
                }
                finally
                {
                    if (clientTransport != null)
                    {
                        clientTransport.Shutdown();
                    }

                    if (serverTransport != null)
                    {
                        serverTransport.Shutdown();
                    }
                }
            }
예제 #3
0
            public void DuplicateTransactionUnitTest()
            {
                SIPTransactionEngine clientEngine = new SIPTransactionEngine();

                SIPURI     dummyURI      = SIPURI.ParseSIPURI("sip:[email protected]");
                SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI);

                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                UACInviteTransaction clientTransaction = new UACInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                clientEngine.AddTransaction(clientTransaction);
                clientEngine.AddTransaction(clientTransaction);
            }
예제 #4
0
            public void CreateTransactionUnitTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                string sipRequestStr =
                    "INVITE sip:[email protected];switchtag=902888 SIP/2.0" + m_CRLF +
                    "Record-Route: <sip:2.3.4.5;ftag=9307C640-33C;lr=on>" + m_CRLF +
                    "Via: SIP/2.0/UDP  5.6.7.2:5060" + m_CRLF +
                    "Via: SIP/2.0/UDP 1.2.3.4;branch=z9hG4bKa7ac.2bfad091.0" + m_CRLF +
                    "From: \"unknown\" <sip:00.000.00.0>;tag=9307C640-33C" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Date: Thu, 21 Feb 2008 01:46:30 GMT" + m_CRLF +
                    "Call-ID: A8706191-DF5511DC-B886ED7B-395C3F7E" + m_CRLF +
                    "Supported: timer,100rel" + m_CRLF +
                    "Min-SE:  1800" + m_CRLF +
                    "Cisco-Guid: 2825897321-3746894300-3095653755-962346878" + m_CRLF +
                    "User-Agent: Cisco-SIPGateway/IOS-12.x" + m_CRLF +
                    "Allow: INVITE, OPTIONS, BYE, CANCEL, ACK, PRACK, COMET, REFER, SUBSCRIBE, NOTIFY, INFO" + m_CRLF +
                    "CSeq: 101 INVITE" + m_CRLF +
                    "Max-Forwards: 5" + m_CRLF +
                    "Timestamp: 1203558390" + m_CRLF +
                    "Contact: <sip:1.2.3.4:5060>" + m_CRLF +
                    "Expires: 180" + m_CRLF +
                    "Allow-Events: telephone-event" + m_CRLF +
                    "Content-Type: application/sdp" + m_CRLF +
                    "Content-Length: 370" + m_CRLF +
                    m_CRLF +
                    "v=0" + m_CRLF +
                    "o=CiscoSystemsSIP-GW-UserAgent 9312 7567 IN IP4 00.00.00.0" + m_CRLF +
                    "s=SIP Call" + m_CRLF +
                    "c=IN IP4 00.000.00.0" + m_CRLF +
                    "t=0 0" + m_CRLF +
                    "m=audio 16434 RTP/AVP 8 0 4 18 3 101" + m_CRLF +
                    "c=IN IP4 00.000.00.0" + m_CRLF +
                    "a=rtpmap:8 PCMA/8000" + m_CRLF +
                    "a=rtpmap:0 PCMU/8000" + m_CRLF +
                    "a=rtpmap:4 G723/8000" + m_CRLF +
                    "a=fmtp:4 annexa=no" + m_CRLF +
                    "a=rtpmap:18 G729/8000" + m_CRLF +
                    "a=fmtp:18 annexb=no" + m_CRLF +
                    "a=rtpmap:3 GSM/8000" + m_CRLF +
                    "a=rtpmap:101 telepho";

                SIPRequest           request           = SIPRequest.ParseSIPRequest(sipRequestStr);
                SIPTransactionEngine transactionEngine = new SIPTransactionEngine();
                SIPTransport         sipTransport      = new SIPTransport(MockSIPDNSManager.Resolve, transactionEngine);
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                SIPTransaction       transaction       = sipTransport.CreateUACTransaction(request, dummySIPEndPoint, dummySIPEndPoint, null);

                Assert.IsTrue(transaction.TransactionRequest.URI.ToString() == "sip:[email protected];switchtag=902888", "Transaction request URI was incorrect.");
            }
예제 #5
0
            public void AckRecognitionIIUnitTest()
            {
                SIPTransactionEngine engine = new SIPTransactionEngine();     // Client side of the INVITE.

                string inviteRequestStr =
                    "INVITE sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 INVITE" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "Content-Type: application/sdp" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest(inviteRequestStr);

                // Server has received the invite.
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                UASInviteTransaction serverTransaction = new UASInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                engine.AddTransaction(serverTransaction);

                //SIPResponse errorResponse = SIPTransport.GetResponse(inviteRequest.Header, SIPResponseStatusCodesEnum.Decline, "Unit Test", null, null);

                string ackRequestStr =
                    "ACK sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 ACK" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest ackRequest = SIPRequest.ParseSIPRequest(ackRequestStr);

                SIPTransaction matchingTransaction = engine.GetTransaction(ackRequest);

                Assert.IsTrue(matchingTransaction.TransactionId == serverTransaction.TransactionId, "ACK transaction did not match INVITE transaction.");
            }