Esempio n. 1
0
        private void Provisional(SipTransportType transportType)
        {
            TestCore        serverCore = null;
            TestCore        clientCore = null;
            SipServerAgent  serverAgent;
            SipClientAgent  clientAgent;
            SipCoreSettings settings;
            SipRequest      request;
            SipResponse     response;
            SipResult       result;

            try
            {
                // Initialize the test cores

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:5060"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:5060"), 0)
                };

                serverCore  = new TestCore(settings);
                serverAgent = new SipServerAgent(serverCore, serverCore);
                serverCore.Start(serverAgent);
                serverCore.SetHandler(new SipRequestDelegate(OnRequest));

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:0"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:0"), 0)
                };

                clientCore  = new TestCore(settings);
                clientAgent = new SipClientAgent(clientCore, clientCore);
                clientCore.Start(clientAgent);
                clientCore.SetHandler(new SipResponseDelegate(OnResponse));

                // Verify a transaction with a single provisional response.
                //
                // I'm also going to verify that setting SipRequest.ViaInstanceParam
                // resulted in the "instance" parameter being added to the requests
                // Via header.

                Clear();

                request = new SipRequest(SipMethod.Register, string.Format("sip:127.0.0.1:5060;transport={0}", transportType.ToString().ToLowerInvariant()), null);
                request.AddHeader(SipHeader.To, "sip:[email protected]");
                request.AddHeader(SipHeader.From, "sip:[email protected]");

                serverOp = ServerOp.ProvisionalOK;
                result   = clientAgent.Request(request, null);
                Thread.Sleep(100);

                Assert.AreEqual(SipStatus.OK, result.Status);

                // Verify the response headers

                request  = result.Request;
                response = result.Response;

                Assert.AreEqual(1, requestArgs.Count);
                Assert.AreEqual(2, responseArgs.Count);
                Assert.AreEqual(SipStatus.Trying, responseArgs[0].Response.Status);
                Assert.AreEqual(SipStatus.OK, responseArgs[1].Response.Status);

                Assert.AreEqual(request.Headers[SipHeader.To].Text, new SipValue(request.Headers[SipHeader.To].Text).Text);
                Assert.IsTrue(string.IsNullOrWhiteSpace(new SipValue(response.Headers[SipHeader.To].Text)["tag"]));

                Assert.AreEqual(request.Headers[SipHeader.From].Text, response.Headers[SipHeader.From].Text);
                Assert.AreEqual(request.Headers[SipHeader.CallID].Text, response.Headers[SipHeader.CallID].Text);
                Assert.AreEqual(request.Headers[SipHeader.CSeq].Text, response.Headers[SipHeader.CSeq].Text);
                Assert.AreEqual(request.Headers[SipHeader.Via].Text, response.Headers[SipHeader.Via].Text);

                // Verify a transaction with two provisional responses

                Clear();

                request = new SipRequest(SipMethod.Register, string.Format("sip:127.0.0.1:5060;transport={0}", transportType.ToString().ToLowerInvariant()), null);
                request.AddHeader(SipHeader.To, "sip:[email protected]");
                request.AddHeader(SipHeader.From, "sip:[email protected]");

                serverOp = ServerOp.ProvisionalProvisionalOK;
                result   = clientAgent.Request(request, null);
                Thread.Sleep(100);

                Assert.AreEqual(SipStatus.OK, result.Status);

                // Verify the response headers

                request  = result.Request;
                response = result.Response;

                Assert.AreEqual(1, requestArgs.Count);
                Assert.AreEqual(3, responseArgs.Count);
                Assert.AreEqual(SipStatus.Trying, responseArgs[0].Response.Status);
                Assert.AreEqual("0", responseArgs[0].Response["Test"].Text);
                Assert.AreEqual(SipStatus.Trying, responseArgs[1].Response.Status);
                Assert.AreEqual("1", responseArgs[1].Response["Test"].Text);
                Assert.AreEqual(SipStatus.OK, responseArgs[2].Response.Status);
                Assert.AreEqual("2", responseArgs[2].Response["Test"].Text);

                Assert.AreEqual(request.Headers[SipHeader.To].Text, new SipValue(request.Headers[SipHeader.To].Text).Text);
                Assert.IsTrue(string.IsNullOrWhiteSpace(new SipValue(response.Headers[SipHeader.To].Text)["tag"]));

                Assert.AreEqual(request.Headers[SipHeader.From].Text, response.Headers[SipHeader.From].Text);
                Assert.AreEqual(request.Headers[SipHeader.CallID].Text, response.Headers[SipHeader.CallID].Text);
                Assert.AreEqual(request.Headers[SipHeader.CSeq].Text, response.Headers[SipHeader.CSeq].Text);
                Assert.AreEqual(request.Headers[SipHeader.Via].Text, response.Headers[SipHeader.Via].Text);
            }
            finally
            {
                if (clientCore != null)
                {
                    clientCore.Stop();
                }

                if (serverCore != null)
                {
                    serverCore.Stop();
                }
            }
        }
Esempio n. 2
0
        private void Blast(SipTransportType transportType)
        {
            TestCore        serverCore = null;
            TestCore        clientCore = null;
            SipServerAgent  serverAgent;
            SipClientAgent  clientAgent;
            SipCoreSettings settings;
            SipRequest      request;
            SipResponse     response;
            SipResult       result;

            try
            {
                // Initialize the test cores

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:5060"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:5060"), 0)
                };

                serverCore  = new TestCore(settings);
                serverAgent = new SipServerAgent(serverCore, serverCore);
                serverCore.Start(serverAgent);
                serverCore.SetHandler(new SipRequestDelegate(OnRequest));

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:0"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:0"), 0)
                };

                clientCore  = new TestCore(settings);
                clientAgent = new SipClientAgent(clientCore, clientCore);
                clientCore.Start(clientAgent);
                clientCore.SetHandler(new SipResponseDelegate(OnResponse));

                // Do a bunch of requests

                for (int i = 0; i < 1000; i++)
                {
                    Clear();

                    request = new SipRequest(SipMethod.Register, string.Format("sip:127.0.0.1:5060;transport={0}", transportType.ToString().ToLowerInvariant()), null);
                    request.AddHeader(SipHeader.To, "sip:[email protected]");
                    request.AddHeader(SipHeader.From, "sip:[email protected]");
                    request.Contents = new byte[] { (byte)i };

                    serverOp = ServerOp.OK;
                    result   = clientAgent.Request(request, null);
                    response = result.Response;
                    Thread.Sleep(100);

                    Assert.AreEqual(SipStatus.OK, result.Status);
                    CollectionAssert.AreEqual(request.Contents, response.Contents);
                }
            }
            finally
            {
                if (clientCore != null)
                {
                    clientCore.Stop();
                }

                if (serverCore != null)
                {
                    serverCore.Stop();
                }
            }
        }
Esempio n. 3
0
        //---------------------------------------------------------------------
        // Tests

        private void Basic(SipTransportType transportType)
        {
            TestCore        serverCore = null;
            TestCore        clientCore = null;
            SipServerAgent  serverAgent;
            SipClientAgent  clientAgent;
            SipCoreSettings settings;
            SipRequest      request;
            SipResponse     response;
            SipResult       result;

            try
            {
                // Initialize the test cores

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:5060"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:5060"), 0)
                };

                serverCore  = new TestCore(settings);
                serverAgent = new SipServerAgent(serverCore, serverCore);
                serverCore.Start(serverAgent);
                serverCore.SetHandler(new SipRequestDelegate(OnRequest));

                settings = new SipCoreSettings();
                settings.TransportSettings = new SipTransportSettings[] {
                    new SipTransportSettings(SipTransportType.UDP, NetworkBinding.Parse("ANY:0"), 0),
                    new SipTransportSettings(SipTransportType.TCP, NetworkBinding.Parse("ANY:0"), 0)
                };

                clientCore  = new TestCore(settings);
                clientAgent = new SipClientAgent(clientCore, clientCore);
                clientCore.Start(clientAgent);
                clientCore.SetHandler(new SipResponseDelegate(OnResponse));

                // Verify a basic Request/OK transaction

                Clear();

                request = new SipRequest(SipMethod.Register, string.Format("sip:127.0.0.1:5060;transport={0}", transportType.ToString().ToLowerInvariant()), null);
                request.AddHeader(SipHeader.To, "sip:[email protected]");
                request.AddHeader(SipHeader.From, "sip:[email protected]");

                serverOp = ServerOp.OK;
                result   = clientAgent.Request(request, null);
                Thread.Sleep(100);

                Assert.AreEqual(SipStatus.OK, result.Status);

                // Verify the response headers

                request  = result.Request;
                response = result.Response;

                Assert.AreEqual(1, requestArgs.Count);
                Assert.AreEqual(1, responseArgs.Count);

                Assert.AreEqual(request.Headers[SipHeader.To].Text, new SipValue(request.Headers[SipHeader.To].Text).Text);
                Assert.IsTrue(string.IsNullOrWhiteSpace(new SipValue(response.Headers[SipHeader.To].Text)["tag"]));

                Assert.AreEqual(request.Headers[SipHeader.From].Text, response.Headers[SipHeader.From].Text);
                Assert.AreEqual(request.Headers[SipHeader.CallID].Text, response.Headers[SipHeader.CallID].Text);
                Assert.AreEqual(request.Headers[SipHeader.CSeq].Text, response.Headers[SipHeader.CSeq].Text);
                Assert.AreEqual(request.Headers[SipHeader.Via].Text, response.Headers[SipHeader.Via].Text);

                // Verify that "Max-Forwards: 70" headers were added to the request message.

                Assert.AreEqual(SipHelper.MaxForwards, requestArgs[0].Request.GetHeaderText(SipHeader.MaxForwards));

                // Verify requests that result in errors.

                Clear();

                request = new SipRequest(SipMethod.Register, string.Format("sip:127.0.0.1:5060;transport={0}", transportType.ToString().ToLowerInvariant()), null);
                request.AddHeader(SipHeader.To, "sip:[email protected]");
                request.AddHeader(SipHeader.From, "sip:[email protected]");

                serverOp = ServerOp.Error;
                result   = clientAgent.Request(request, null);
                Thread.Sleep(100);

                Assert.AreEqual(SipStatus.NotImplemented, result.Status);

                // Verify the response headers

                request  = result.Request;
                response = result.Response;

                Assert.AreEqual(1, requestArgs.Count);
                Assert.AreEqual(1, responseArgs.Count);

                Assert.AreEqual(request.Headers[SipHeader.To].Text, new SipValue(request.Headers[SipHeader.To].Text).Text);
                Assert.IsTrue(string.IsNullOrWhiteSpace(new SipValue(response.Headers[SipHeader.To].Text)["tag"]));

                Assert.AreEqual(request.Headers[SipHeader.From].Text, response.Headers[SipHeader.From].Text);
                Assert.AreEqual(request.Headers[SipHeader.CallID].Text, response.Headers[SipHeader.CallID].Text);
                Assert.AreEqual(request.Headers[SipHeader.CSeq].Text, response.Headers[SipHeader.CSeq].Text);
                Assert.AreEqual(request.Headers[SipHeader.Via].Text, response.Headers[SipHeader.Via].Text);
            }
            finally
            {
                if (clientCore != null)
                {
                    clientCore.Stop();
                }

                if (serverCore != null)
                {
                    serverCore.Stop();
                }
            }
        }