Пример #1
0
        public void ParseAsteriskTRYINGUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string sipMsg =
                "SIP/2.0 100 Trying" + m_CRLF +
                "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bKD+ta2mJ+C+VV/L50aPO1lFJnrag=" + m_CRLF +
                "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64193;branch=z9hG4bKB86FC8D2431F49E9862D1EE439C78AD8" + m_CRLF +
                "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=3272744142" + m_CRLF +
                "To: <sip:303@bluesipd>" + m_CRLF +
                "Call-ID: [email protected]" + m_CRLF +
                "CSeq: 45560 INVITE" + m_CRLF +
                "User-Agent: asterisk" + m_CRLF +
                "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" + m_CRLF +
                "Contact: <sip:[email protected]>" + m_CRLF +
                "Content-Length: 0" + m_CRLF + m_CRLF;

            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null);
            SIPResponse      tryingResp       = SIPResponse.ParseSIPResponse(sipMessageBuffer);

            Assert.True(tryingResp.Status == SIPResponseStatusCodesEnum.Trying, "The SIP response status was not parsed correctly.");

            logger.LogDebug("-----------------------------------------");
        }
Пример #2
0
        public void IPHeaderConstructionUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            IPv4Header header = new IPv4Header(ProtocolType.Udp, 4567, IPAddress.Parse("127.0.0.1"), IPAddress.Parse("127.0.0.1"));

            byte[] headerData = header.GetBytes();

            int count = 0;

            foreach (byte headerByte in headerData)
            {
                logger.LogDebug("0x{0,-2:x} ", headerByte);
                count++;
                if (count % 4 == 0)
                {
                    logger.LogDebug("\n");
                }
            }

            logger.LogDebug("\n");

            Assert.True(true, "True was false.");
        }
Пример #3
0
        async Task IListener.StartAsync(CancellationToken cancellationToken)
        {
retry:

            using (var scope = logger.BeginScope("IListener"))
            {
                var eventId = new Microsoft.Extensions.Logging.EventId(1);
                logger.LogInformation("StartAsync");

                try
                {
                    var credentials = CreatorService.GetCredentials(triggerAttribute);
                    var tasks       = Enumerable.Range(1, triggerAttribute.NrListeners).Select(c => StartListener(credentials, cancellationToken));

                    await Task.WhenAll(tasks);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, ex.Message);
                }
            }

            System.Threading.Thread.Sleep(30 * 1000);
            goto retry;
        }
        public void RoundtripRTCPReceiverResportUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            uint ssrc = 1;

            uint rrSsrc           = 5;
            byte fractionLost     = 6;
            int  packetsLost      = 7;
            uint highestSeqNum    = 8;
            uint jitter           = 9;
            uint lastSRTimestamp  = 10;
            uint delaySinceLastSR = 11;

            var rr = new ReceptionReportSample(rrSsrc, fractionLost, packetsLost, highestSeqNum, jitter, lastSRTimestamp, delaySinceLastSR);

            var receiverReport = new RTCPReceiverReport(ssrc, new List <ReceptionReportSample> {
                rr
            });

            byte[] buffer = receiverReport.GetBytes();

            RTCPReceiverReport parsedRR = new RTCPReceiverReport(buffer);

            Assert.Equal(ssrc, parsedRR.SSRC);

            Assert.Equal(rrSsrc, parsedRR.ReceptionReports.First().SSRC);
            Assert.Equal(fractionLost, parsedRR.ReceptionReports.First().FractionLost);
            Assert.Equal(packetsLost, parsedRR.ReceptionReports.First().PacketsLost);
            Assert.Equal(highestSeqNum, parsedRR.ReceptionReports.First().ExtendedHighestSequenceNumber);
            Assert.Equal(jitter, parsedRR.ReceptionReports.First().Jitter);
            Assert.Equal(lastSRTimestamp, parsedRR.ReceptionReports.First().LastSenderReportTimestamp);
            Assert.Equal(delaySinceLastSR, parsedRR.ReceptionReports.First().DelaySinceLastSenderReport);
        }
        public void RegisterStartWithCustomHeaderTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport   transport = new SIPTransport();
            MockSIPChannel channel   = new MockSIPChannel(new IPEndPoint(IPAddress.Any, 0));

            transport.AddSIPChannel(channel);
            SIPRegistrationUserAgent userAgent = new SIPRegistrationUserAgent(
                transport,
                null,
                new SIPURI("alice", "192.168.11.50", null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
                "alice",
                "password123",
                null,
                "192.168.11.50",
                new SIPURI(SIPSchemesEnum.sip, IPAddress.Any, 0),
                120,
                null,
                new[] { "My-Header: value" });

            userAgent.Start();

            channel.SIPMessageSent.WaitOne(5000);
            Assert.Contains("My-Header: value", channel.LastSIPMessageSent);

            userAgent.Stop();
        }
        public void TestSocketReadSingleMessageTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testReceive =
                "SUBSCRIBE sip:[email protected] SIP/2.0" + CRLF +
                "Via: SIP/2.0/TCP 10.1.1.5:62647;branch=z9hG4bKa58b912c426f415daa887289efda50cd;rport" + CRLF +
                "To: <sip:[email protected]>" + CRLF +
                "From: <sip:[email protected]>;tag=1902440575" + CRLF +
                "Call-ID: 1b569032-d1e4-4869-be9f-67d4ba8a4e3a" + CRLF +
                "CSeq: 3 SUBSCRIBE" + CRLF +
                "Contact: <sip:10.1.1.5:62647;transport=tcp>" + CRLF +
                "Max-Forwards: 70" + CRLF +
                "Expires: 600" + CRLF +
                "Content-Length: 15" + CRLF +
                "Content-Type: text/text" + CRLF +
                "Event: dialog" + CRLF +
                CRLF +
                "includesdp=true";

            byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive);

            SIPStreamConnection testConnection = new SIPStreamConnection(null, null, SIPProtocolsEnum.tcp);

            //Array.Copy(testReceiveBytes, 0, testConnection.RecvSocketArgs.Buffer, 0, testReceiveBytes.Length);

            testConnection.ExtractSIPMessages(null, testReceiveBytes, testReceiveBytes.Length);

            Assert.True(testConnection.RecvEndPosn == 0, "The receive buffer end position should have been 0.");
        }
        public void ParseTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SDPSecurityDescription c1 = SDPSecurityDescription.Parse("a=crypto:1 AES_CM_128_HMAC_SHA1_80  inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4    FEC_ORDER=FEC_SRTP");

            Assert.Equal("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4 FEC_ORDER=FEC_SRTP", c1.ToString());
            Assert.Equal(SDPSecurityDescription.Parse("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4 FEC_ORDER=FEC_SRTP").ToString(), c1.ToString());
            Assert.Equal(SDPSecurityDescription.Parse(c1.ToString()).ToString(), c1.ToString());
            Assert.Equal(1u, c1.Tag);
            Assert.Equal(4u, c1.KeyParams[0].MkiLength);
            Assert.Equal(1u, c1.KeyParams[0].MkiValue);
            Assert.Equal(Math.Pow(2, 20), c1.KeyParams[0].LifeTime);
            Assert.Equal("2^20", c1.KeyParams[0].LifeTimeString);
            Assert.Equal("WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz", c1.KeyParams[0].KeySaltBase64);
            Assert.Equal("FEC_ORDER=FEC_SRTP", c1.SessionParam.ToString());

            SDPSecurityDescription c2 = SDPSecurityDescription.Parse("a=crypto:2 F8_128_HMAC_SHA1_80  inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|2^20|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|2^20|2:4     FEC_ORDER=FEC_SRTP");

            Assert.Equal("a=crypto:2 F8_128_HMAC_SHA1_80 inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|2^20|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|2^20|2:4 FEC_ORDER=FEC_SRTP", c2.ToString());
            Assert.Equal(2, c2.KeyParams.Count);
            Assert.Equal(2u, c2.Tag);
            Assert.Equal(4u, c2.KeyParams[0].MkiLength);
            Assert.Equal(1u, c2.KeyParams[0].MkiValue);
            Assert.Equal(4u, c2.KeyParams[1].MkiLength);
            Assert.Equal(2u, c2.KeyParams[1].MkiValue);
            Assert.Equal((ulong)Math.Pow(2, 20), c2.KeyParams[0].LifeTime);
            Assert.Equal("2^20", c2.KeyParams[0].LifeTimeString);
            Assert.Equal((ulong)Math.Pow(2, 20), c2.KeyParams[1].LifeTime);
            Assert.Equal("2^20", c2.KeyParams[1].LifeTimeString);
            Assert.Equal("MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm", c2.KeyParams[0].KeySaltBase64);
            Assert.Equal("QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5", c2.KeyParams[1].KeySaltBase64);
            Assert.Equal("FEC_ORDER=FEC_SRTP", c2.SessionParam.ToString());

            SDPSecurityDescription c3 = SDPSecurityDescription.Parse("a=crypto:1 AES_CM_128_HMAC_SHA1_80  inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4");

            Assert.Equal("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", c3.ToString());
            Assert.Equal(SDPSecurityDescription.Parse("a=crypto:1 AES_CM_128_HMAC_SHA1_80  inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4").ToString(), c3.ToString());
            Assert.Equal(SDPSecurityDescription.Parse(c3.ToString()).ToString(), c3.ToString());
            Assert.Equal(1u, c3.Tag);
            Assert.Equal(4u, c3.KeyParams[0].MkiLength);
            Assert.Equal(1u, c3.KeyParams[0].MkiValue);
            Assert.Equal((ulong)Math.Pow(2, 20), c3.KeyParams[0].LifeTime);
            Assert.Equal("2^20", c3.KeyParams[0].LifeTimeString);
            Assert.Equal("PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR", c3.KeyParams[0].KeySaltBase64);
            Assert.Null(c3.SessionParam);

            Assert.Null(SDPSecurityDescription.Parse(null));
            Assert.Null(SDPSecurityDescription.Parse(""));

            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|2^20|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|2^20|2:4"));
            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("a=crypto: AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"));
            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("a=crypto:1  inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"));
            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("a=crypto:1 AES_CM_128_HMAC_SHA1_80 "));
            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("a=crypto:1 AES_CM_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"));
            Assert.Throws <FormatException>(() => SDPSecurityDescription.Parse("a=crypto:1 1 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4"));
        }
Пример #8
0
        public void CreateSelfSignedCertifcateUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var cert = DtlsUtils.CreateSelfSignedCert();

            Assert.NotNull(cert);
        }
        public void CreateClientInstanceUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            DtlsSrtpTransport dtlsTransport = new DtlsSrtpTransport(new DtlsSrtpClient());

            Assert.NotNull(dtlsTransport);
        }
Пример #10
0
        public void TrimTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            String myString = null;

            Assert.True(myString.IsNullOrBlank(), "String was not correctly detected as blank.");
        }
Пример #11
0
        public void ParsePortFromSocketTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            int port = IPSocket.ParsePortFromSocket("localhost:5060");

            logger.LogDebug("port=" + port);
            Assert.True(port == 5060, "The port was not parsed correctly.");
        }
Пример #12
0
        public void SampleTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            int initRandomNumber = Crypto.GetRandomInt();

            logger.LogDebug("Random int = " + initRandomNumber + ".");
            logger.LogDebug("-----------------------------------------");
        }
Пример #13
0
        public void CreateClientInstanceUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            (var tlsCert, var pvtKey) = DtlsUtils.CreateSelfSignedTlsCert();
            DtlsSrtpTransport dtlsTransport = new DtlsSrtpTransport(new DtlsSrtpClient(tlsCert, pvtKey));

            Assert.NotNull(dtlsTransport);
        }
Пример #14
0
        public void ParseWebRTCSTUNRequestTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] stunReq = new byte[] { 0x00, 0x01, 0x00, 0x60, 0x21, 0x12, 0xa4, 0x42, 0x66, 0x55, 0x55, 0x43, 0x4b, 0x48, 0x74, 0x73, 0x68, 0x4e, 0x71, 0x56,
                                          // Att1:
                                          0x00, 0x06, 0x00, 0x21,
                                          0x6d, 0x30, 0x71, 0x47, 0x77, 0x53, 0x71, 0x2f, 0x48, 0x56, 0x48, 0x71, 0x41, 0x62, 0x4b, 0x62, 0x3a, 0x73, 0x64, 0x43,
                                          0x48, 0x59, 0x6b, 0x35, 0x6e, 0x46, 0x34, 0x79, 0x44, 0x77, 0x55, 0x39, 0x53, 0x00, 0x00, 0x00,
                                          // Att2
                                          0x80, 0x2a, 0x00, 0x08,
                                          0xa0, 0x36, 0xc9, 0x6c, 0x30, 0xc6, 0x2f, 0xd2, 0x00, 0x25, 0x00, 0x00, 0x00, 0x24, 0x00, 0x04,
                                          0x6e, 0x7f, 0x1e, 0xff, 0x00, 0x08, 0x00, 0x14, 0x81, 0x4a, 0x4f, 0xaf, 0x3d, 0x99, 0x30, 0x67,
                                          0x66, 0xb9, 0x48, 0x67, 0x83, 0x72, 0xd5, 0xa0, 0x7a, 0x87, 0xb5, 0x3f, 0x80, 0x28, 0x00, 0x04,
                                          0x49, 0x7e, 0x51, 0x17 };

            STUNMessage stunMessage = STUNMessage.ParseSTUNMessage(stunReq, stunReq.Length);
            STUNHeader  stunHeader  = stunMessage.Header;

            logger.LogDebug("Request type = " + stunHeader.MessageType + ".");
            logger.LogDebug("Length = " + stunHeader.MessageLength + ".");
            logger.LogDebug("Transaction ID = " + BitConverter.ToString(stunHeader.TransactionId) + ".");

            Assert.Equal(STUNMessageTypesEnum.BindingRequest, stunHeader.MessageType);
            Assert.Equal(96, stunHeader.MessageLength);
            Assert.Equal(6, stunMessage.Attributes.Count);
        }
Пример #15
0
        public void GetLocalIPAddressUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var localAddress = NetServices.GetLocalAddressForRemote(IPAddress.Parse("192.168.11.48"));

            Assert.NotNull(localAddress);

            logger.LogDebug($"Local address {localAddress}.");
        }
Пример #16
0
        public void HasStringUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] sample = Encoding.ASCII.GetBytes("The quick brown fox jumped over...");

            bool hasFox = ByteBufferInfo.HasString(sample, 0, Int32.MaxValue, "fox", null);

            Assert.True(hasFox, "The string was not found in the buffer.");
        }
Пример #17
0
        public void CreateSelfSignedCertifcateUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            (var tlsCert, var pvtKey) = DtlsUtils.CreateSelfSignedTlsCert();

            logger.LogDebug(tlsCert.ToString());

            Assert.NotNull(tlsCert);
            Assert.NotNull(pvtKey);
        }
        public async Task CreateDialogueFromUasTxUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPEndPoint dummyEP = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 5060));

            string inviteReqStr =
                @"INVITE sip:[email protected]:12014 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27
To: <sip:[email protected]:12014>
From: <sip:[email protected]>;tag=2062917371
Call-ID: 8ae45c15425040179a4285d774ccbaf6
CSeq: 1 INVITE
Contact: <sip:127.0.0.1:1234>
Max-Forwards: 70
User-Agent: unittest
Content-Length: 5
Content-Type: application/sdp

dummy";
            var        sipReqBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummyEP, dummyEP);
            SIPRequest inviteReq    = SIPRequest.ParseSIPRequest(sipReqBuffer);

            string okRespStr =
                @"SIP/2.0 200 OK
Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27;rport=12013
To: <sip:[email protected]:12014>
From: <sip:[email protected]>;tag=2062917371
Call-ID: 8ae45c15425040179a4285d774ccbaf6
CSeq: 1 INVITE
Content-Length: 5
Content-Type: application/sdp

dummy";

            var         sipRespBuffer = SIPMessageBuffer.ParseSIPMessage(okRespStr, dummyEP, dummyEP);
            SIPResponse okResponse    = SIPResponse.ParseSIPResponse(sipRespBuffer);

            SIPTransport transport = new SIPTransport();

            transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint()));
            UASInviteTransaction uasTx = new UASInviteTransaction(transport, inviteReq, null);
            await uasTx.GotResponse(dummyEP, dummyEP, okResponse);

            var dialogue = new SIPDialogue(uasTx);

            Assert.NotNull(dialogue);
            Assert.Equal(SIPURI.ParseSIPURI("sip:127.0.0.1:1234"), dialogue.RemoteTarget);
            Assert.Equal(dummyEP, dialogue.RemoteSIPEndPoint);

            logger.LogDebug("---------------------------------------------------");
        }
        public void GenerateLocalOfferUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            RTCPeerConnection pc = new RTCPeerConnection(null);
            var offer            = pc.createOffer(new RTCOfferOptions());

            Assert.NotNull(offer);

            logger.LogDebug(offer.ToString());
        }
        public void ParamsInUserPortionURITest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPUserField userField = SIPUserField.ParseSIPUserField("<sip:C=on;[email protected]:5060;lr>");

            Assert.True("C=on;t=DLPAN" == userField.URI.User, "SIP user portion parsed incorrectly.");
            Assert.True("10.0.0.1:5060" == userField.URI.Host, "SIP host portion parsed incorrectly.");

            logger.LogDebug("-----------------------------------------");
        }
        public void GetAsXMLStringUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPEventDialogInfo dialogInfo = new SIPEventDialogInfo(0, SIPEventDialogInfoStateEnum.full, SIPURI.ParseSIPURI("sip:[email protected]"));

            dialogInfo.DialogItems.Add(new SIPEventDialog("abcde", "terminated", 487, SIPEventDialogStateEvent.Cancelled, 2));

            logger.LogDebug(dialogInfo.ToXMLText());

            logger.LogDebug("-----------------------------------------");
        }
Пример #22
0
        public void ParseNoSchemeNoPortTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            bool result = STUNUri.TryParse("stun.sipsorcery.com", out var stunUri);

            Assert.True(result);
            Assert.Equal(STUNSchemesEnum.stun, stunUri.Scheme);
            Assert.Equal("stun.sipsorcery.com", stunUri.Host);
            Assert.Equal(STUNConstants.DEFAULT_STUN_PORT, stunUri.Port);
            Assert.False(stunUri.ExplicitPort);
        }
Пример #23
0
        public async void LookupLocalhostTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            STUNUri.TryParse("localhost", out var stunUri);
            var result = await STUNDns.Resolve(stunUri);

            Assert.NotNull(result);
            Assert.Equal(IPAddress.Loopback, result.Address);

            logger.LogDebug($"STUN DNS lookup for {stunUri} {result}.");
        }
        public void ResolveHostFromServiceTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var result = SIPDNSManager.ResolveSIPService(SIPURI.ParseSIPURIRelaxed("sipsorcery.com"), false);

            SIPEndPoint resultEP = result.GetSIPEndPoint();

            Assert.NotNull(resultEP);

            logger.LogDebug($"resolved to SIP end point {resultEP}");
        }
Пример #25
0
        public void CreateChannelUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var udpChan = new SIPUDPChannel(IPAddress.Any, 0);

            logger.LogDebug($"Listening end point {udpChan.ListeningSIPEndPoint}.");

            udpChan.Close();

            logger.LogDebug("-----------------------------------------");
        }
Пример #26
0
        public void ParseHostCandidateUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var candidate = RTCIceCandidate.Parse("1390596646 1 udp 1880747346 192.168.11.50 61680 typ host generation 0");

            Assert.NotNull(candidate);
            Assert.Equal(RTCIceCandidateType.host, candidate.type);
            Assert.Equal(RTCIceProtocol.udp, candidate.protocol);

            logger.LogDebug(candidate.ToString());
        }
Пример #27
0
        public void ResolveHostFromServiceTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            CancellationTokenSource cts = new CancellationTokenSource();

            var result = SIPDns.ResolveAsync(SIPURI.ParseSIPURIRelaxed("sipsorcery.com"), false, cts.Token).Result;

            Assert.NotNull(result);

            logger.LogDebug($"resolved to SIP end point {result}.");
        }
Пример #28
0
        public async Task BlindTransferUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPTransport transport = new SIPTransport();

            transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)));

            SIPUserAgent userAgent = new SIPUserAgent(transport, null);

            string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF +
                                  "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF +
                                  "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF +
                                  "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF +
                                  "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF +
                                  "CSeq: 3532 INVITE" + m_CRLF +
                                  "Contact: <sip:[email protected]:60163;ob>" + m_CRLF +
                                  "Max-Forwards: 70" + m_CRLF +
                                  "User-Agent: MicroSIP/3.19.22" + m_CRLF +
                                  "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF +
                                  "Supported: replaces, 100rel, timer, norefersub" + m_CRLF +
                                  "Content-Length: 343" + m_CRLF +
                                  "Content-Type: application/sdp" + m_CRLF +
                                  "Session-Expires: 1800" + m_CRLF +
                                  "Min-SE: 90" + m_CRLF +
                                  "" + m_CRLF +
                                  "v=0" + m_CRLF +
                                  "o=- 3785527268 3785527269 IN IP4 192.168.11.50" + m_CRLF +
                                  "s=pjmedia" + m_CRLF +
                                  "t=0 0" + m_CRLF +
                                  "m=audio 4032 RTP/AVP 0 101" + m_CRLF +
                                  "c=IN IP4 192.168.11.50" + m_CRLF +
                                  "a=rtpmap:0 PCMU/8000" + m_CRLF +
                                  "a=rtpmap:101 telephone-event/8000" + m_CRLF +
                                  "a=fmtp:101 0-16" + m_CRLF +
                                  "a=sendrecv";

            SIPEndPoint      dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0));
            SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint);
            SIPRequest       inviteReq        = SIPRequest.ParseSIPRequest(sipMessageBuffer);

            UASInviteTransaction uasTx   = new UASInviteTransaction(transport, inviteReq, null);
            SIPServerUserAgent   mockUas = new SIPServerUserAgent(transport, null, null, null, SIPCallDirection.In, null, null, null, uasTx);
            await userAgent.Answer(mockUas, CreateMediaSession());

            CancellationTokenSource cts = new CancellationTokenSource();
            bool result = await userAgent.BlindTransfer(SIPURI.ParseSIPURIRelaxed("127.0.0.1"), TimeSpan.FromSeconds(2), cts.Token);

            Assert.False(result);
        }
Пример #29
0
        public void RoundtripRTCPCompoundPacketUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            uint  ssrc        = 23;
            ulong ntpTs       = 1;
            uint  rtpTs       = 2;
            uint  packetCount = 3;
            uint  octetCount  = 4;

            uint rrSsrc           = 5;
            byte fractionLost     = 6;
            int  packetsLost      = 7;
            uint highestSeqNum    = 8;
            uint jitter           = 9;
            uint lastSRTimestamp  = 10;
            uint delaySinceLastSR = 11;

            string cname = "dummy";

            ReceptionReportSample rr = new ReceptionReportSample(rrSsrc, fractionLost, packetsLost, highestSeqNum, jitter, lastSRTimestamp, delaySinceLastSR);
            var sr = new RTCPSenderReport(ssrc, ntpTs, rtpTs, packetCount, octetCount, new List <ReceptionReportSample> {
                rr
            });
            RTCPSDesReport sdesReport = new RTCPSDesReport(ssrc, cname);

            RTCPCompoundPacket compoundPacket = new RTCPCompoundPacket(sr, sdesReport);

            byte[] buffer = compoundPacket.GetBytes();

            RTCPCompoundPacket parsedCP = new RTCPCompoundPacket(buffer);
            RTCPSenderReport   parsedSR = parsedCP.SenderReport;

            Assert.Equal(ssrc, parsedSR.SSRC);
            Assert.Equal(ntpTs, parsedSR.NtpTimestamp);
            Assert.Equal(rtpTs, parsedSR.RtpTimestamp);
            Assert.Equal(packetCount, parsedSR.PacketCount);
            Assert.Equal(octetCount, parsedSR.OctetCount);
            Assert.True(parsedSR.ReceptionReports.Count == 1);

            Assert.Equal(rrSsrc, parsedSR.ReceptionReports.First().SSRC);
            Assert.Equal(fractionLost, parsedSR.ReceptionReports.First().FractionLost);
            Assert.Equal(packetsLost, parsedSR.ReceptionReports.First().PacketsLost);
            Assert.Equal(highestSeqNum, parsedSR.ReceptionReports.First().ExtendedHighestSequenceNumber);
            Assert.Equal(jitter, parsedSR.ReceptionReports.First().Jitter);
            Assert.Equal(lastSRTimestamp, parsedSR.ReceptionReports.First().LastSenderReportTimestamp);
            Assert.Equal(delaySinceLastSR, parsedSR.ReceptionReports.First().DelaySinceLastSenderReport);

            Assert.Equal(cname, parsedCP.SDesReport.CNAME);
        }
Пример #30
0
        public void RouteParamExtractTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string        routeParam       = ";lr;server=hippo";
            SIPParameters serverParam      = new SIPParameters(routeParam, ';');
            string        serverParamValue = serverParam.Get("server");

            logger.LogDebug("Parameter string=" + serverParam.ToString() + ".");
            logger.LogDebug("The server parameter is=" + serverParamValue + ".");

            Assert.True(serverParamValue == "hippo", "The server parameter was not correctly extracted.");
        }