Exemplo n.º 1
0
        public void When_1000_transactions_are_in_trying_state()
        {
            var m = new Mock<ISipMessageSender>();
            var l = new Mock<ISipListener>();
            var txTable = new SipClientTransactionTable();

            SipNonInviteClientTransaction ctx;
            for(int i=0;i <1000;i++)
            {
                /*provide a separate sequence so that each transaction has a unique ID*/
                var r = new SipRequestBuilder().WithCSeq(new SipCSeqHeaderBuilder().WithSequence(i).Build()).Build();
                ctx = new SipNonInviteClientTransaction(txTable, m.Object, l.Object, r, new TimerFactory());
                ctx.SendRequest(); /*go to state*/
            }

            Assert.IsTrue(txTable.Keys.Count == 1000);

            /*extra race condition check. Wait T1 time, so while disposing the transactions, their Retransmit is firing.*/
            var dateTime = DateTime.Now.AddMilliseconds(SipConstants.T1);
            while (dateTime > DateTime.Now) { };

            txTable.Values.ToList().ForEach(a => a.Dispose());

            Assert.IsTrue(txTable.Keys.Count == 0);
        }
Exemplo n.º 2
0
        public void When_1000_transactions_are_in_trying_state()
        {
            var m       = new Mock <ISipMessageSender>();
            var l       = new Mock <ISipListener>();
            var txTable = new SipClientTransactionTable();

            SipNonInviteClientTransaction ctx;

            for (int i = 0; i < 1000; i++)
            {
                /*provide a separate sequence so that each transaction has a unique ID*/
                var r = new SipRequestBuilder().WithCSeq(new SipCSeqHeaderBuilder().WithSequence(i).Build()).Build();
                ctx = new SipNonInviteClientTransaction(txTable, m.Object, l.Object, r, new TimerFactory());
                ctx.SendRequest(); /*go to state*/
            }

            Assert.IsTrue(txTable.Keys.Count == 1000);

            /*extra race condition check. Wait T1 time, so while disposing the transactions, their Retransmit is firing.*/
            var dateTime = DateTime.Now.AddMilliseconds(SipConstants.T1);

            while (dateTime > DateTime.Now)
            {
            }
            ;

            txTable.Values.ToList().ForEach(a => a.Dispose());

            Assert.IsTrue(txTable.Keys.Count == 0);
        }
Exemplo n.º 3
0
 public TxSpecificationBase()
 {
     Sender       = new Mock <ISipMessageSender>();
     Listener     = new Mock <ISipListener>();
     TxTable      = new SipClientTransactionTable();
     Request      = new SipRequestBuilder().Build();
     TimerFactory = new TimerFactoryMockBuilder().Build();
 }
Exemplo n.º 4
0
 public TxSpecificationBase()
 {
     Sender = new Mock<ISipMessageSender>();
     Listener = new Mock<ISipListener>();
     TxTable = new SipClientTransactionTable();
     Request = new SipRequestBuilder().Build();
     TimerFactory = new TimerFactoryMockBuilder().Build();
 }
Exemplo n.º 5
0
        //want follow the jain-sip implementation. I just use a guid. SipUtil.CreateCallId();
        //public SipCallIdHeader GetNewCallId()
        //{
        //    String callId = SipUtil.GenerateCallIdentifier(this.getListeningPoint()
        //            .getIPAddress());
        //    SipCallIdHeader callid = new SipCallIdHeader();

        //    return callid;
        //}

        internal SipProvider(SipStack stack, ISipContextSource contextSource)
        {
            Check.Require(stack, "stack");
            Check.Require(contextSource, "contextSource");

            _stack         = stack;
            _contextSource = contextSource;
            contextSource.NewContextReceived += (s, e) => OnNewContextReceived(e.Context);
            contextSource.UnhandledException += (s, e) => OnContextSourceUnhandledException(e.Exception);

            _ctxTable    = new SipClientTransactionTable();
            _stxTable    = new SipServerTransactionTable();
            _dialogTable = new SipDialogTable();
        }
Exemplo n.º 6
0
        //want follow the jain-sip implementation. I just use a guid. SipUtil.CreateCallId();
        //public SipCallIdHeader GetNewCallId()
        //{
        //    String callId = SipUtil.GenerateCallIdentifier(this.getListeningPoint()
        //            .getIPAddress());
        //    SipCallIdHeader callid = new SipCallIdHeader();
        //    return callid;
        //}
        internal SipProvider(SipStack stack, ISipContextSource contextSource)
        {
            Check.Require(stack, "stack");
            Check.Require(contextSource, "contextSource");

            _stack = stack;
            _contextSource = contextSource;
            contextSource.NewContextReceived +=(s,e) => OnNewContextReceived(e.Context);
            contextSource.UnhandledException += (s, e) => OnContextSourceUnhandledException(e.Exception);

            _ctxTable = new SipClientTransactionTable();
            _stxTable = new SipServerTransactionTable();
            _dialogTable = new SipDialogTable();
        }
Exemplo n.º 7
0
 public TxSpecificationBase()
 {
     MessageSenderMock = new Mock <ISipMessageSender>();
     TxTable           = new SipClientTransactionTable();
     Request           = new SipRequestBuilder()
                         .WithRequestLine
                         (
         new SipRequestLineBuilder()
         .WithMethod(SipMethods.Invite)
         .Build()
                         ).Build();
     TimerFactory   = new TimerFactoryMockBuilder().Build();
     ListenerMock   = new Mock <ISipListener>();
     HeaderFactory  = new SipHeaderFactory();
     MessageFactory = new SipMessageFactory();
 }
Exemplo n.º 8
0
        public void Test_Retransmit()
        {
            var s = new Mock<ISipMessageSender>();
            var l = new Mock<ISipListener>();
            var txTable = new SipClientTransactionTable();
            var request = new SipRequestBuilder().Build();
            SipNonInviteClientTransaction ctx = new SipNonInviteClientTransaction(txTable, s.Object, l.Object, request, new TimerFactoryMockBuilder().Build());
            ctx.SendRequest();

            var dateTime = DateTime.Now.AddMilliseconds(SipConstants.T1);
            while (dateTime > DateTime.Now) {};

            s.Verify(ss => ss.SendRequest(request), Times.Exactly(2));

            ctx.Dispose();
        }
Exemplo n.º 9
0
 public TxSpecificationBase()
 {
     MessageSenderMock = new Mock<ISipMessageSender>();
     TxTable = new SipClientTransactionTable();
     Request = new SipRequestBuilder()
         .WithRequestLine
         (
             new SipRequestLineBuilder()
             .WithMethod(SipMethods.Invite)
             .Build()
         ).Build();
     TimerFactory = new TimerFactoryMockBuilder().Build();
     ListenerMock = new Mock<ISipListener>();
     HeaderFactory = new SipHeaderFactory();
     MessageFactory = new SipMessageFactory();
 }
Exemplo n.º 10
0
        SipNonInviteClientTransaction(
            SipClientTransactionTable table,
            ISipMessageSender messageSender,
            ISipListener listener,
            SipRequest request,
            ITimerFactory timerFactory)
            : base(table, request, messageSender, listener, timerFactory)
        {
            Check.IsTrue(request.RequestLine.Method != SipMethods.Invite, "Method 'INVITE' is not allowed");
            Check.IsTrue(request.RequestLine.Method != SipMethods.Ack, "Method 'ACK' is not allowed");

            _logger = NLog.LogManager.GetCurrentClassLogger();

            ReTransmitTimer   = _timerFactory.CreateNonInviteCtxRetransmitTimer(OnReTransmit);
            TimeOutTimer      = _timerFactory.CreateNonInviteCtxTimeOutTimer(OnTimeOut);
            EndCompletedTimer = _timerFactory.CreateNonInviteCtxEndCompletedTimer(OnCompletedEnded);
        }
        internal SipNonInviteClientTransaction(
            SipClientTransactionTable table,
            ISipMessageSender messageSender,
            ISipListener listener,
            SipRequest request,
            ITimerFactory timerFactory)
            : base(table, request, messageSender, listener, timerFactory)
        {
            Check.IsTrue(request.RequestLine.Method != SipMethods.Invite, "Method 'INVITE' is not allowed");
            Check.IsTrue(request.RequestLine.Method != SipMethods.Ack, "Method 'ACK' is not allowed");

            _logger = NLog.LogManager.GetCurrentClassLogger();

            ReTransmitTimer = _timerFactory.CreateNonInviteCtxRetransmitTimer(OnReTransmit);
            TimeOutTimer = _timerFactory.CreateNonInviteCtxTimeOutTimer(OnTimeOut);
            EndCompletedTimer = _timerFactory.CreateNonInviteCtxEndCompletedTimer(OnCompletedEnded);
        }
        protected SipAbstractClientTransaction(
            SipClientTransactionTable table,
            SipRequest request, 
            ISipMessageSender messageSender,
            ISipListener listener,
            ITimerFactory timerFactory)
        {
            Check.Require(table, "table");
            Check.Require(messageSender, "messageSender");
            Check.Require(listener, "listener");
            Check.Require(request, "request");
            Check.Require(timerFactory, "timerFactory");

            _table = table;
            _messageSender = messageSender;
            _listener = listener;
            _request = request;
            _timerFactory = timerFactory;
        }
Exemplo n.º 13
0
        public void Test_Retransmit()
        {
            var s       = new Mock <ISipMessageSender>();
            var l       = new Mock <ISipListener>();
            var txTable = new SipClientTransactionTable();
            var request = new SipRequestBuilder().Build();
            SipNonInviteClientTransaction ctx = new SipNonInviteClientTransaction(txTable, s.Object, l.Object, request, new TimerFactoryMockBuilder().Build());

            ctx.SendRequest();

            var dateTime = DateTime.Now.AddMilliseconds(SipConstants.T1);

            while (dateTime > DateTime.Now)
            {
            }
            ;

            s.Verify(ss => ss.SendRequest(request), Times.Exactly(2));

            ctx.Dispose();
        }
Exemplo n.º 14
0
        internal SipInviteClientTransaction(
            SipClientTransactionTable table,
            ISipMessageSender messageSender,
            ISipListener listener,
            SipRequest request,
            ITimerFactory timerFactory,
            SipHeaderFactory headerFactory,
            SipMessageFactory messageFactory)
            : base(table, request, messageSender, listener, timerFactory)
        {
            Check.Require(headerFactory, "headerFactory");
            Check.Require(messageFactory, "messageFactory");

            Check.IsTrue(request.RequestLine.Method == SipMethods.Invite, "Method other then 'INVITE' is not allowed");

            _logger = NLog.LogManager.GetCurrentClassLogger();

            _headerFactory  = headerFactory;
            _messageFactory = messageFactory;

            ReTransmitTimer   = timerFactory.CreateInviteCtxRetransmitTimer(OnReTransmit);
            TimeOutTimer      = timerFactory.CreateInviteCtxTimeOutTimer(OnTimeOut);
            EndCompletedTimer = timerFactory.CreateInviteCtxEndCompletedTimer(OnCompletedEnded);
        }
Exemplo n.º 15
0
        internal SipInviteClientTransaction(
            SipClientTransactionTable table,
            ISipMessageSender messageSender,
            ISipListener listener, 
            SipRequest request, 
            ITimerFactory timerFactory, 
            SipHeaderFactory headerFactory,
            SipMessageFactory messageFactory)
            : base(table, request, messageSender, listener, timerFactory)
        {
            Check.Require(headerFactory, "headerFactory");
            Check.Require(messageFactory, "messageFactory");

            Check.IsTrue(request.RequestLine.Method == SipMethods.Invite, "Method other then 'INVITE' is not allowed");

            _logger = NLog.LogManager.GetCurrentClassLogger();

            _headerFactory = headerFactory;
            _messageFactory = messageFactory;

            ReTransmitTimer = timerFactory.CreateInviteCtxRetransmitTimer(OnReTransmit);
            TimeOutTimer = timerFactory.CreateInviteCtxTimeOutTimer(OnTimeOut);
            EndCompletedTimer = timerFactory.CreateInviteCtxEndCompletedTimer(OnCompletedEnded);
        }