public void ParseMissingCSeqOptionsResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "To: <sip:[email protected]:5060>;tag=eba877fbb8dd284bi0" + m_CRLF + "From: <sip:213.168.225.133:5060>;tag=5880003940" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK1702000048" + m_CRLF + "Server: Linksys/RT31P2-2.0.10(LIc)" + m_CRLF + "Content-Length: 0" + m_CRLF + "Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER" + m_CRLF + "Supported: x-sipura" + m_CRLF + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse optionsResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); logger.LogDebug("CSeq=" + optionsResp.Header.CSeq + "."); logger.LogDebug("CSeq Method=" + optionsResp.Header.CSeqMethod + "."); Assert.True(optionsResp.Header.CSeq == -1, "Response CSeq was incorrect."); Assert.True(optionsResp.Header.CSeqMethod == SIPMethodsEnum.NONE, "Response CSeq method was incorrect."); logger.LogDebug("-----------------------------------------"); }
public void RFC5118_4_10_2() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "OPTIONS sip:user@[2001:db8::192.0.2.1] SIP/2.0" + CRLF + "To: sip:user@[2001:db8::192.0.2.1]" + CRLF + "From: sip:[email protected];tag=810x2" + CRLF + "Via: SIP/2.0/UDP lab1.east.example.com;branch=z9hG4bKas3-111" + CRLF + "Call-ID: G9559905523997077@hlau_4100" + CRLF + "CSeq: 689 OPTIONS" + CRLF + "Max-Forwards: 70" + CRLF + "Content-Length: 0"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.OPTIONS, sipRequest.Method); IPAddress ip6; Assert.NotEmpty(sipRequest.Header.Vias.Via); Assert.False(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6)); Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); logger.LogDebug("-----------------------------------------"); }
public void ParseMultipleContactsResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.32:64226;branch=z9hG4bK-d87543-ac7a6a75bc519655-1--d87543-;rport=64226;received=89.100.104.191" + m_CRLF + "To: \"253989\"<sip:[email protected]>;tag=cb2000b247d89723001a836145f3b053.5b6c" + m_CRLF + "From: \"253989\"<sip:[email protected]>;tag=9812dd2f" + m_CRLF + "Call-ID: ODllYWY1NDJiNGMwYmQ1MjVmZmViMmEyMDViMGM0Y2Y." + m_CRLF + "CSeq: 2 REGISTER" + m_CRLF + "Date: Fri, 17 Nov 2006 17:15:35 GMT" + m_CRLF + "Contact: <sip:[email protected]>;q=0.1;expires=3298, \"Joe Bloggs\"<sip:[email protected]:64226;rinstance=5720c5fed8cbcd34>;q=0.1;expires=3600" + m_CRLF + "Content-Length: 0" + m_CRLF + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); logger.LogDebug("To: " + okResp.Header.To.ToString()); Assert.True(SIPResponseStatusCodesEnum.Ok == okResp.Status, "Response should have been ok."); Assert.True(okResp.Header.Contact.Count == 2, "Response should have had two contacts."); Assert.True(okResp.Header.Contact[0].ContactURI.ToString() == "sip:[email protected]", "The contact URI for the first contact header was incorrect."); Assert.True(okResp.Header.Contact[0].Expires == 3298, "The expires value for the first contact header was incorrect."); Assert.True(okResp.Header.Contact[0].Q == "0.1", "The q value for the first contact header was incorrect."); Assert.True(okResp.Header.Contact[1].ContactName == "Joe Bloggs", "The contact name for the first contact header was incorrect."); Assert.True(okResp.Header.Contact[1].ContactURI.ToString() == "sip:[email protected]:64226;rinstance=5720c5fed8cbcd34", "The contact URI for the first contact header was incorrect."); Assert.True(okResp.Header.Contact[1].Expires == 3600, "The expires value for the second contact header was incorrect."); Assert.True(okResp.Header.Contact[1].Q == "0.1", "The q value for the second contact header was incorrect."); logger.LogDebug("-----------------------------------------"); }
public async Task IncomingCallNoSdpUnitTest() { 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 + "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF + "Supported: replaces, 100rel, timer, norefersub" + m_CRLF + "Content-Length: 0" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Session-Expires: 1800" + m_CRLF + m_CRLF; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); var uas = userAgent.AcceptCall(inviteReq); await userAgent.Answer(uas, CreateMockVoIPMediaEndPoint()); // The call attempt should timeout while waiting for the ACK request with the SDP answer. Assert.False(userAgent.IsCallActive); }
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("-----------------------------------------"); }
public void ParseOptionsBodyResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK10a1fab0" + m_CRLF + "From: \"Unknown\" <sip:[email protected]>;tag=as18338373" + m_CRLF + "To: <sip:[email protected]>;tag=OLg-20481" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 102 OPTIONS" + m_CRLF + "content-type: application/sdp" + m_CRLF + "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, INFO, REFER, NOTIFY" + m_CRLF + "Content-Length: 217" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=0 5972727 56415 IN IP4 0.0.0.0" + m_CRLF + "s=SIP Call" + m_CRLF + "c=IN IP4 0.0.0.0" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 0 RTP/AVP 18 0 8 4 2" + m_CRLF + "a=rtpmap:18 G729/8000" + m_CRLF + "a=rtpmap:0 pcmu/8000" + m_CRLF + "a=rtpmap:8 pcma/8000" + m_CRLF + "a=rtpmap:4 g723/8000" + m_CRLF + "a=rtpmap:2 g726/8000" + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(okResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly."); Assert.True(okResp.Body.Length == 217, "The SIP response body length was not correct."); logger.LogDebug("-----------------------------------------"); }
public void RFC5118_4_9() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "INVITE sip:[email protected] SIP/2.0" + CRLF + "To: sip:[email protected]" + CRLF + "From: sip:[email protected];tag=81x2" + CRLF + "Via: SIP/2.0/UDP [::ffff:192.0.2.10]:19823;branch=z9hG4bKbh19" + CRLF + "Via: SIP/2.0/UDP [::ffff:192.0.2.2];branch=z9hG4bKas3-111" + CRLF + "Call-ID: SSG9559905523997077@hlau_4100" + CRLF + "Contact: \"T. desk phone\" <sip:ted@[::ffff:192.0.2.2]>" + CRLF + "CSeq: 612 INVITE" + CRLF + "Max-Forwards: 70" + CRLF + "Content-Type: application/sdp" + CRLF + "Content-Length: 236" + CRLF + CRLF + "v=0" + CRLF + "o=assistant 971731711378798081 0 IN IP6 ::ffff:192.0.2.2" + CRLF + "s=Call me soon, please!" + CRLF + "c=IN IP6 ::ffff:192.0.2.2" + CRLF + "t=3338481189 3370017201" + CRLF + "m=audio 6000 RTP/AVP 2" + CRLF + "a=rtpmap:2 G726-32/8000" + CRLF + "m=video 6024 RTP/AVP 107" + CRLF + "a=rtpmap:107 H263-1998/90000"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.INVITE, sipRequest.Method); IPAddress ip6; Assert.NotEmpty(sipRequest.Header.Vias.Via); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.Host, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.Equal(19823, sipRequest.Header.Vias.TopViaHeader.Port); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.BottomViaHeader.ReceivedFromAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.NotEmpty(sipRequest.Header.Contact); Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.False(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6)); Assert.False(string.IsNullOrWhiteSpace(sipRequest.Body)); SDP sdp = SDP.ParseSDPDescription(sipRequest.Body); Assert.NotNull(sdp); Assert.NotNull(sdp.Connection); Assert.True(IPAddress.TryParse(sdp.Connection.ConnectionAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.NotEmpty(sdp.Media); logger.LogDebug("-----------------------------------------"); }
public async Task UacTxCheckRemoteSocketProxyReceivedUnitTestUnitTest() { 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 Contact: <sip:127.0.0.1:1234> CSeq: 1 INVITE Content-Length: 5 Content-Type: application/sdp Proxy-ReceivedFrom: udp:192.168.0.50:5080 dummy"; var sipRespBuffer = SIPMessageBuffer.ParseSIPMessage(okRespStr, dummyEP, dummyEP); SIPResponse okResponse = SIPResponse.ParseSIPResponse(sipRespBuffer); SIPTransport transport = new SIPTransport(); transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint())); UACInviteTransaction uacTx = new UACInviteTransaction(transport, inviteReq, null); await uacTx.GotResponse(dummyEP, dummyEP, okResponse); var dialogue = new SIPDialogue(uacTx); Assert.NotNull(dialogue); Assert.Equal(SIPURI.ParseSIPURI("sip:127.0.0.1:1234"), dialogue.RemoteTarget); Assert.Equal(SIPEndPoint.ParseSIPEndPoint("udp:192.168.0.50:5080"), dialogue.RemoteSIPEndPoint); logger.LogDebug("---------------------------------------------------"); }
public async Task BlindTransferCancelUnitTest() { 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(); var blindTransferTask = userAgent.BlindTransfer(SIPURI.ParseSIPURIRelaxed("127.0.0.1"), TimeSpan.FromSeconds(2), cts.Token); cts.Cancel(); Assert.False(await blindTransferTask); //await Assert.ThrowsAnyAsync<TaskCanceledException>(async () => { bool result = ; }); }
public async Task HandleInvalidSdpPortOnAnswerUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); SIPUserAgent userAgent = new SIPUserAgent(transport, null); string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0 Via: SIP/2.0/UDP 0.0.0.0;branch=z9hG4bK57441c4980b94e1686a06ae080be2935;rport To: <sip:[email protected]> From: <sip:0.0.0.0:0>;tag=MYILIYPHQD Call-ID: ddf0e5a9687b4745925438da9000445d CSeq: 1 INVITE Max-Forwards: 70 Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE Content-Length: 0 v=0 o=- 1838015445 0 IN IP4 127.0.0.1 s=- c=IN IP4 127.0.0.1 t=0 0 m=audio 79762 RTP/AVP 0 a=rtpmap:0 PCMU/8000 a=sendrecv"; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); var uas = userAgent.AcceptCall(inviteReq); RTPSession rtpSession = new RTPSession(false, false, false); MediaStreamTrack audioTrack = new MediaStreamTrack(SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.PCMU) }); rtpSession.addTrack(audioTrack); var result = await userAgent.Answer(uas, rtpSession); Assert.False(result); rtpSession.Close("normal"); }
public void ParseMultiLineRecordRouteResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 10.0.0.100:5060;rport=61540;branch=z9hG4bK40661a8b4a2d4973ae75fa52f1940383" + m_CRLF + "From: <sip:[email protected]>;tag=1014391101" + m_CRLF + "To: <sip:[email protected]>;tag=gj-2k5-490f768a-00005cf1-00002e1aR2f0f2383.b" + m_CRLF + "Call-ID: 1960514b216a465fb900e2966d30e9bb" + m_CRLF + "CSeq: 2 INVITE" + m_CRLF + "Record-Route: <sip:77.75.25.44:5060;lr=on>" + m_CRLF + "Record-Route: <sip:77.75.25.45:5060;lr=on;ftag=1014391101>" + m_CRLF + "Accept: application/sdp, application/isup, application/dtmf, application/dtmf-relay, multipart/mixed" + m_CRLF + "Contact: <sip:[email protected]:5060>" + m_CRLF + "Allow: INVITE,ACK,CANCEL,BYE,REGISTER,REFER,INFO,SUBSCRIBE,NOTIFY,PRACK,UPDATE,OPTIONS" + m_CRLF + "Supported: timer" + m_CRLF + "Session-Expires: 600;refresher=uas" + m_CRLF + "Content-Length: 232" + m_CRLF + "Content-Disposition: session; handling=required" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=Sonus_UAC 4125 3983 IN IP4 64.152.60.78" + m_CRLF + "s=SIP Media Capabilities" + m_CRLF + "c=IN IP4 64.152.60.164" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 19144 RTP/AVP 0 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-15" + m_CRLF + "a=sendrecv" + m_CRLF + "a=ptime:20" + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(okResp.Header.RecordRoutes.Length == 2, "The wrong number of Record-Route headers were present in the parsed response."); Assert.True(okResp.Header.RecordRoutes.PopRoute().ToString() == "<sip:77.75.25.44:5060;lr=on>", "The top Record-Route header was incorrect."); SIPRoute nextRoute = okResp.Header.RecordRoutes.PopRoute(); Assert.True(nextRoute.ToString() == "<sip:77.75.25.45:5060;lr=on;ftag=1014391101>", "The second Record-Route header was incorrect, " + nextRoute.ToString() + "."); logger.LogDebug("-----------------------------------------"); }
public void RFC5118_4_7() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "BYE sip:[email protected] SIP/2.0" + CRLF + "Via: SIP/2.0/UDP [2001:db8::9:1]:6050;branch=z9hG4bKas3-111" + CRLF + "Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKjhja8781hjuaij65144" + CRLF + "Via: SIP/2.0/TCP [2001:db8::9:255];branch=z9hG4bK451jj;received=192.0.2.200" + CRLF + "Call-ID: 997077@lau_4100" + CRLF + "Max-Forwards: 70" + CRLF + "CSeq: 89187 BYE" + CRLF + "To: sip:[email protected];tag=9817--94" + CRLF + "From: sip:[email protected];tag=81x2" + CRLF + "Content-Length: 0"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.BYE, sipRequest.Method); IPAddress ip6, ip4; Assert.NotEmpty(sipRequest.Header.Vias.Via); Assert.True(sipRequest.Header.Vias.Length == 3); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.Equal(SIPProtocolsEnum.udp, sipRequest.Header.Vias.TopViaHeader.Transport); Assert.Equal(6050, sipRequest.Header.Vias.TopViaHeader.Port); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.BottomViaHeader.Host, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.BottomViaHeader.ReceivedFromIPAddress, out ip4)); Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily); Assert.Equal(SIPProtocolsEnum.tcp, sipRequest.Header.Vias.BottomViaHeader.Transport); sipRequest.Header.Vias.PopTopViaHeader(); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip4)); Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily); Assert.Equal(SIPProtocolsEnum.udp, sipRequest.Header.Vias.TopViaHeader.Transport); Assert.False(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6)); logger.LogDebug("-----------------------------------------"); }
public void ShortTorturousInvite() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); Assert.True(File.Exists("wsinv.dat"), "The wsinv.dat torture test input file was missing."); string raw = File.ReadAllText("wsinv.dat"); logger.LogDebug(raw); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(raw), null, null); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(raw); Assert.NotNull(sipMessageBuffer); Assert.NotNull(inviteReq); logger.LogDebug("-----------------------------------------"); }
public void ParseAsteriskOKUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bKT36BdhXPlT5cqPFQQr81yMmZ37U=" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64216;branch=z9hG4bK7D8B6549580844AEA104BD4A837049DD" + m_CRLF + "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=630217013" + m_CRLF + "To: <sip:303@bluesipd>;tag=as46f418e9" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 27481 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-Type: application/sdp" + m_CRLF + "Content-Length: 352" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=root 24710 24712 IN IP4 213.168.225.133" + m_CRLF + "s=session" + m_CRLF + "c=IN IP4 213.168.225.133" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 18656 RTP/AVP 0 8 18 3 97 111 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:8 PCMA/8000" + m_CRLF + "a=rtpmap:18 G729/8000" + m_CRLF + "a=rtpmap:3 GSM/8000" + m_CRLF + "a=rtpmap:97 iLBC/8000" + m_CRLF + "a=rtpmap:111 G726-32/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-16" + m_CRLF + "a=silenceSupp:off - - - -" + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(okResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly."); Assert.True(okResp.Body.Length == 352, "The SIP response body length was not correct."); logger.LogDebug("-----------------------------------------"); }
public async Task TestSetRequestCustomHeaderFuncUnitTest() { 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); using (var transport = new SIPTransport()) { transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint())); string contactHost = "devcall.sipsorcery.com"; transport.CustomiseRequestHeader = (local, dst, req) => { var hdr = req.Header.Copy(); hdr.Contact[0].ContactURI.Host = contactHost; return(hdr); }; await transport.SendRequestAsync(inviteReq); logger.LogDebug(inviteReq.ToString()); Assert.Equal(contactHost, inviteReq.Header.Contact[0].ContactURI.Host); } }
public void ParseMultiLineViaResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 194.213.29.100:5060;branch=z9hG4bK5feb18267ce40fb05969b4ba843681dbfc9ffcff, SIP/2.0/UDP 194.213.29.54:5061;branch=z9hG4bK52b6a8b7" + m_CRLF + "Record-Route: <sip:194.213.29.100:5060;lr>" + m_CRLF + "From: Unknown <sip:[email protected]:5061>;tag=as58cbdbd1" + m_CRLF + "To: <sip:[email protected]:5060>;tag=1144090013" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 102 INVITE" + m_CRLF + "Contact: <sip:[email protected]:5060>" + m_CRLF + "Server: Patton SN4634 3BIS 00A0BA04469B R5.3 2009-01-15 H323 SIP BRI M5T SIP Stack/4.0.28.28" + m_CRLF + "Supported: replaces" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Content-Length: 298" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=MxSIP 0 56 IN IP4 10.10.10.155" + m_CRLF + "s=SIP Call" + m_CRLF + "c=IN IP4 10.10.10.155" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 4974 RTP/AVP 0 18 8 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:18 G729/8000" + m_CRLF + "a=rtpmap:8 PCMA/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:18 annexb=no" + m_CRLF + "a=fmtp:101 0-16" + m_CRLF + "a=sendrecv" + m_CRLF + "m=video 0 RTP/AVP 31 34 103 99"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(okResp.Header.Vias.Length == 2, "The wrong number of Record-Route headers were present in the parsed response."); Assert.True(okResp.Header.Vias.TopViaHeader.ContactAddress == "194.213.29.100:5060", "The top via contact address was not correctly parsed."); logger.LogDebug("-----------------------------------------"); }
public void ParseMSCOkResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "From: Blue Face<sip:[email protected]>;tag=as5fd53de7" + m_CRLF + "To: sip:[email protected];tag=MTHf2-ol1Yn0" + m_CRLF + "Call-ID: [email protected]:5061" + m_CRLF + "CSeq: 102 INVITE" + m_CRLF + "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bKG+WGOVwLyT6vOW9s" + m_CRLF + "Via: SIP/2.0/UDP 213.168.225.133:5061;branch=z9hG4bK09db9c73" + m_CRLF + "Contact: +3535xxx<sip:[email protected]:5061>" + m_CRLF + "User-Agent: MSC/VC510 Build-Date Nov 7 2005" + m_CRLF + "Allow: INVITE,BYE,CANCEL,OPTIONS,PRACK,NOTIFY,UPDATE,REFER" + m_CRLF + "Supported: timer,replaces" + m_CRLF + "Record-Route: <sip:213.168.225.133:5060;lr>,<sip:213.168.225.133:5061;lr>" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Content-Length: 182" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=xxxxxxxxx 75160 1 IN IP4 127.127.127.30" + m_CRLF + "s=-" + m_CRLF + "c=IN IP4 127.127.127.30" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 8002 RTP/AVP 0 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=ptime:20"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse okResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); logger.LogDebug("To: " + okResp.Header.To.ToString()); Assert.True(SIPResponseStatusCodesEnum.Ok == okResp.Status, "Response should have been ok."); Assert.True("127.0.0.1" == okResp.Header.To.ToURI.Host, "To URI host was not parsed correctly."); logger.LogDebug("-----------------------------------------"); }
public void BinarySerialisationRoundTripTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPURI uri = new SIPURI("dummy", "dummy", null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp); SIPRequest req = SIPRequest.GetRequest(SIPMethodsEnum.MESSAGE, uri); SIPResponse resp = SIPResponse.GetResponse(req, SIPResponseStatusCodesEnum.Ok, null); resp.Header.ContentType = "application/octet-stream"; resp.BodyBuffer = new byte[100]; Crypto.GetRandomBytes(resp.BodyBuffer); string bodyHash = null; using (var sha256 = new SHA256Managed()) { bodyHash = sha256.ComputeHash(resp.BodyBuffer).HexStr(); } logger.LogDebug(resp.ToString()); logger.LogDebug($"Body sha256: {bodyHash}."); SIPMessageBuffer msgBuffer = SIPMessageBuffer.ParseSIPMessage(resp.GetBytes(), SIPEndPoint.Empty, SIPEndPoint.Empty); SIPResponse rndTripResp = SIPResponse.ParseSIPResponse(msgBuffer); string rndTripBodyHash = null; using (var sha256 = new SHA256Managed()) { rndTripBodyHash = sha256.ComputeHash(rndTripResp.BodyBuffer).HexStr(); } logger.LogDebug(rndTripResp.ToString()); logger.LogDebug($"Round Trip Body sha256: {rndTripBodyHash}."); Assert.Equal(bodyHash, rndTripBodyHash); }
public void RFC5118_4_3() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "REGISTER sip:[2001:db8::10:5070] SIP/2.0" + CRLF + "To: sip:[email protected]" + CRLF + "From: sip:[email protected];tag=81x2" + CRLF + "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF + "Call-ID: SSG9559905523997077@hlau_4100" + CRLF + "Contact: \"Caller\" <sip:caller@[2001:db8::1]>" + CRLF + "Max-Forwards: 70" + CRLF + "CSeq: 98176 REGISTER" + CRLF + "Content-Length: 0"; //parsing is correct, but port is ambiguous, //intention was to target port 5070 //but that's nothing a program can find out SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.REGISTER, sipRequest.Method); IPAddress ip6; Assert.NotEmpty(sipRequest.Header.Vias.Via); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.NotEmpty(sipRequest.Header.Contact); Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); logger.LogDebug("-----------------------------------------"); }
public void ParseForbiddenResponse() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 403 Forbidden" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.1;branch=z9hG4bKbcb78f72d221beec" + m_CRLF + "From: <sip:sip.blueface.ie>;tag=9a4c86234adcc297" + m_CRLF + "To: <sip:sip.blueface.ie>;tag=as6900b876" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 100 REGISTER" + 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 forbiddenResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(forbiddenResp.Status == SIPResponseStatusCodesEnum.Forbidden, "The SIP response status was not parsed correctly."); Console.WriteLine("-----------------------------------------"); }
public void ParseResponseNoEndDoubleCRLFUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 100 Trying" + CRLF + "Via: SIP/2.0/UDP 213.168.225.135:5060;branch=z9hG4bKD+ta2mJ+C+VV/L50aPO1lFJnrag=" + CRLF + "Via: SIP/2.0/UDP 192.168.1.2:5065;received=220.240.255.198:64193;branch=z9hG4bKB86FC8D2431F49E9862D1EE439C78AD8" + CRLF + "From: bluesipd <sip:bluesipd@bluesipd:5065>;tag=3272744142" + CRLF + "To: <sip:303@bluesipd>" + CRLF + "Call-ID: [email protected]" + CRLF + "CSeq: 45560 INVITE" + CRLF + "User-Agent: asterisk" + CRLF + "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" + CRLF + "Contact: <sip:[email protected]>" + CRLF + "Content-Length: 0" + CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); Console.WriteLine("-----------------------------------------"); }
public void RFC5118_4_2() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "REGISTER sip:2001:db8::10 SIP/2.0" + CRLF + "To: sip:[email protected]" + CRLF + "From: sip:[email protected];tag=81x2" + CRLF + "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF + "Call-ID: SSG9559905523997077@hlau_4100" + CRLF + "Max-Forwards: 70" + CRLF + "Contact: \"Caller\" <sip:caller@[2001:db8::1]>" + CRLF + "CSeq: 98176 REGISTER" + CRLF + "Content-Length: 0"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); Assert.Throws <SIPValidationException>(() => SIPRequest.ParseSIPRequest(sipMessageBuffer)); logger.LogDebug("-----------------------------------------"); }
public void ParseOptionsResponse() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + m_CRLF + "Via: SIP/2.0/UDP 194.213.29.11:5060;branch=z9hG4bK330f55c874" + m_CRLF + "From: Anonymous <sip:194.213.29.11:5060>;tag=6859154930" + m_CRLF + "To: <sip:[email protected]:10062>;tag=0013c339acec0fe007b80bbf-30071da3" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "Date: Mon, 01 May 2006 13:47:24 GMT" + m_CRLF + "CSeq: 915 OPTIONS" + m_CRLF + "Server: CSCO/7" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Content-Length: 247" + m_CRLF + "Allow: OPTIONS,INVITE,BYE,CANCEL,REGISTER,ACK,NOTIFY,REFER" + m_CRLF + m_CRLF + "v=0" + m_CRLF + "o=Cisco-SIPUA (null) (null) IN IP4 192.168.1.100" + m_CRLF + "s=SIP Call" + m_CRLF + "c=IN IP4 192.168.1.100" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 1 RTP/AVP 0 8 18 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:8 PCMA/8000" + m_CRLF + "a=rtpmap:18 G729/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-15" + m_CRLF + m_CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse optionsResp = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(optionsResp.Status == SIPResponseStatusCodesEnum.Ok, "The SIP response status was not parsed correctly."); logger.LogDebug("-----------------------------------------"); }
public void ParseCiscoOptionsResponseUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "SIP/2.0 200 OK" + CRLF + "Via: SIP/2.0/UDP 213.168.225.133:5060;branch=z9hG4bK7ae332e73550dbdf2f159061651e7ed5bb88ac52, SIP/2.0/UDP 194.213.29.52:5064;branch=z9hG4bK1121681627" + CRLF + "From: <sip:[email protected]:5064>;tag=8341482660" + CRLF + "To: <sip:[email protected]:5060>;tag=000e38e46c60ef28651381fe-201e6ab1" + CRLF + "Call-ID: [email protected]" + CRLF + "Date: Wed, 29 Nov 2006 22:31:58 GMT" + CRLF + "CSeq: 148 OPTIONS" + CRLF + "Server: CSCO/7" + CRLF + "Content-Type: application/sdp" + CRLF + "Allow: OPTIONS,INVITE,BYE,CANCEL,REGISTER,ACK,NOTIFY,REFER" + CRLF + "Content-Length: 193" + CRLF + CRLF + "v=0" + CRLF + "o=Cisco-SIPUA (null) (null) IN IP4 87.198.196.121" + CRLF + "s=SIP Call" + CRLF + "c=IN IP4 87.198.196.121" + CRLF + "t=0 0" + CRLF + "m=audio 1 RTP/AVP 18 0 8" + CRLF + "a=rtpmap:18 G729/8000" + CRLF + "a=rtpmap:0 PCMU/8000" + CRLF + "a=rtpmap:8 PCMA/8000" + CRLF + CRLF; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPResponse sipResponse = SIPResponse.ParseSIPResponse(sipMessageBuffer); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); Assert.True(sipResponse.Header.Vias.Length == 2, "The SIP reponse did not end up with the right number of Via headers."); logger.LogDebug("-----------------------------------------"); }
public async Task AnswerAudioOnlyUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); SIPUserAgent userAgent = new SIPUserAgent(transport, null); string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0 Via: SIP/2.0/UDP 0.0.0.0;branch=z9hG4bK57441c4980b94e1686a06ae080be2935;rport To: <sip:[email protected]> From: <sip:0.0.0.0:0>;tag=MYILIYPHQD Call-ID: ddf0e5a9687b4745925438da9000445d CSeq: 1 INVITE Max-Forwards: 70 Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE Content-Length: 0 v=0 o=- 1838015445 0 IN IP4 127.0.0.1 s=- c=IN IP4 127.0.0.1 t=0 0 m=audio 19762 RTP/AVP 0 a=rtpmap:0 PCMU/8000 a=sendrecv"; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); var uas = userAgent.AcceptCall(inviteReq); var result = await userAgent.Answer(uas, CreateMediaSession()); Assert.True(result); }
public async Task TestSetResponseContactHostIPAddressUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPEndPoint dummyEP = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 5060)); 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 Contact: <sip:127.0.0.1:1234> CSeq: 1 INVITE Content-Length: 5 Content-Type: application/sdp dummy"; var sipRespBuffer = SIPMessageBuffer.ParseSIPMessage(okRespStr, dummyEP, dummyEP); SIPResponse okResponse = SIPResponse.ParseSIPResponse(sipRespBuffer); using (var transport = new SIPTransport()) { transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint())); transport.ContactHost = "192.168.0.12"; await transport.SendResponseAsync(okResponse); logger.LogDebug(okResponse.ToString()); Assert.Equal($"{transport.ContactHost}:5060", okResponse.Header.Contact[0].ContactURI.Host); } }
public async Task IncomingCallNoSdpWithACKUnitTest() { 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))); var dummySep = SIPEndPoint.ParseSIPEndPoint("udp:127.0.0.1:5060"); SIPUserAgent userAgent = new SIPUserAgent(transport, null); string inviteReqStr = @"INVITE sip:[email protected] SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bKbeed9b0cde8d43cc8a2aae91526b6a1d;rport To: <sip:[email protected]> From: <sip:[email protected]>;tag=GCLNRILCDU Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2 CSeq: 1 INVITE Contact: <sip:127.0.0.1:51200> Max-Forwards: 70 User-Agent: www.sipsorcery.com Content-Length: 0 Content-Type: application/sdp" + m_CRLF + m_CRLF; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); var uas = userAgent.AcceptCall(inviteReq); var mediaSession = CreateMediaSession(); _ = Task.Run(() => { Task.Delay(2000).Wait(); string ackReqStr = @"ACK sip:127.0.0.1:5060 SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:51200;branch=z9hG4bK76dfb1480ea14f778bd24afed1c8ded0;rport To: <sip:[email protected]>;tag=YWPNZPMLPB From: <sip:[email protected]>;tag=GCLNRILCDU Call-ID: 7265e19f53a146a1bacdf4f4f8ea70b2 CSeq: 1 ACK Max-Forwards: 70 Content-Length: 160 v=0 o=- 67424 0 IN IP4 127.0.0.1 s=- c=IN IP4 127.0.0.1 t=0 0 m=audio 16976 RTP/AVP 8 101 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=sendrecv" + m_CRLF + m_CRLF; uas.ClientTransaction.ACKReceived(dummySep, dummySep, SIPRequest.ParseSIPRequest(ackReqStr)); }); await userAgent.Answer(uas, mediaSession); Assert.True(userAgent.IsCallActive); }
public async Task HangupUserAgentUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(false, MockSIPDNSManager.Resolve); MockSIPChannel mockChannel = new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)); transport.AddSIPChannel(mockChannel); 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.Loopback, 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()); // Incremented Cseq and modified Via header from original request. Means the request is the same dialog but different tx. string inviteReqStr2 = "BYE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF + "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3700" + m_CRLF + "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF + "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF + "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF + "CSeq: 3533 BYE" + 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 + ""; mockChannel.FireMessageReceived(dummySipEndPoint, dummySipEndPoint, Encoding.UTF8.GetBytes(inviteReqStr2)); }
public void ParseCryptoSIPMessage() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "INVITE sip:[email protected]:5061;transport=tls SIP/2.0" + CRLF + "Via: SIP/2.0/TLS 10.2.19.102:58179;rport;branch=z9hG4bKPj9893426a070f4c26ab494ceb746836a6" + CRLF + "Max-Forwards: 70" + CRLF + "From: <sip:[email protected]>;tag=b0d60b9dda9043818dea1f0e8ff9667c" + CRLF + "To: <sip:[email protected]>" + CRLF + "Contact: <sip:[email protected]:58179;ob>" + CRLF + "Call-ID: 6410bc5eb6724efd8717831ac2af5c35" + CRLF + "CSeq: 9941 INVITE" + CRLF + "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + CRLF + "Supported: replaces, 100rel, timer, norefersub" + CRLF + "Session-Expires: 1800" + CRLF + "Min-SE: 90" + CRLF + "User-Agent: MicroSIP/3.19.8" + CRLF + "Content-Type: application/sdp" + CRLF + "Content-Length: 720" + CRLF + "" + CRLF + "v=0" + CRLF + "o=- 3784977145 3784977145 IN IP4 10.2.19.102" + CRLF + "s=pjmedia" + CRLF + "b=AS:84" + CRLF + "t=0 0" + CRLF + "a=X-nat:0" + CRLF + "m=audio 4000 RTP/AVP 8 0 101" + CRLF + "c=IN IP4 10.2.19.102" + CRLF + "b=TIAS:64000" + CRLF + "a=rtcp:4001 IN IP4 10.2.19.102" + CRLF + "a=sendrecv" + CRLF + "a=rtpmap:8 PCMA/8000" + CRLF + "a=rtpmap:0 PCMU/8000" + CRLF + "a=rtpmap:101 telephone-event/8000" + CRLF + "a=fmtp:101 0-16" + CRLF + "a=ssrc:370289018 cname:089912e5446c1847" + CRLF + "a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:i/aQZXuTQXF8NcIPG/8ClKLXjzJZiZkFqNerJJaWtX9ShjuamMQgFocXUEkWCQ==" + CRLF + "a=crypto:2 AES_256_CM_HMAC_SHA1_32 inline:WEXYOzOomH16+KpVRc8RKHkGUEW6DdvYHWSFKePVy9RzC5DB2Ciw+4t9huV8KA==" + CRLF + "a=crypto:3 AES_CM_128_HMAC_SHA1_80 inline:6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r" + CRLF + "a=crypto:4 AES_CM_128_HMAC_SHA1_32 inline:SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle" ; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.INVITE, sipRequest.Method); Assert.Equal(SIPProtocolsEnum.tls, sipRequest.URI.Protocol); SDP sdp = SDP.ParseSDPDescription(sipRequest.Body); Assert.NotNull(sdp); Assert.Equal("10.2.19.102", sdp.Connection.ConnectionAddress); Assert.Equal("-", sdp.Username); Assert.Equal("pjmedia", sdp.SessionName); Assert.Equal(SDPMediaTypesEnum.audio, sdp.Media[0].Media); Assert.Equal(MediaStreamStatusEnum.SendRecv, sdp.Media[0].MediaStreamStatus); Assert.NotEmpty(sdp.Media[0].SecurityDescriptions); Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_256_CM_HMAC_SHA1_80, sdp.Media[0].SecurityDescriptions[0].CryptoSuite); Assert.NotEmpty(sdp.Media[0].SecurityDescriptions[0].KeyParams); Assert.Null(sdp.Media[0].SecurityDescriptions[0].SessionParam); Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_256_CM_HMAC_SHA1_32, sdp.Media[0].SecurityDescriptions[1].CryptoSuite); Assert.Equal(2u, sdp.Media[0].SecurityDescriptions[1].Tag); Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_CM_128_HMAC_SHA1_80, sdp.Media[0].SecurityDescriptions[2].CryptoSuite); Assert.Equal("6wGxadTFLGO9iKPSC8XfRQsOFDRFgJdmpBfdWp9r", sdp.Media[0].SecurityDescriptions[2].KeyParams[0].KeySaltBase64); Assert.Equal(SDPSecurityDescription.CryptoSuites.AES_CM_128_HMAC_SHA1_32, sdp.Media[0].SecurityDescriptions[3].CryptoSuite); Assert.Equal("SdihJallj5frjwWc5yeXbMZlJSLlS+o2bkH3Jsle", sdp.Media[0].SecurityDescriptions[3].KeyParams[0].KeySaltBase64); }
public void RFC5118_4_8() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "INVITE sip:user@[2001:db8::10] SIP/2.0" + CRLF + "To: sip:user@[2001:db8::10]" + CRLF + "From: sip:[email protected];tag=81x2" + CRLF + "Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111" + CRLF + "Call-ID: SSG9559905523997077@hlau_4100" + CRLF + "Contact: \"Caller\" <sip:caller@[2001:db8::9:1]>" + CRLF + "Max-Forwards: 70" + CRLF + "CSeq: 8912 INVITE" + CRLF + "Content-Type: application/sdp" + CRLF + "Content-Length: 181" + CRLF + CRLF + "v=0" + CRLF + "o=bob 280744730 28977631 IN IP4 host.example.com" + CRLF + "s=" + CRLF + "t=0 0" + CRLF + "m=audio 22334 RTP/AVP 0" + CRLF + "c=IN IP4 192.0.2.1" + CRLF + "m=video 6024 RTP/AVP 107" + CRLF + "c=IN IP6 2001:db8::1" + CRLF + "a=rtpmap:107 H263-1998/90000"; SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); Assert.True(sipMessageBuffer != null, "The SIP message not parsed correctly."); SIPRequest sipRequest = SIPRequest.ParseSIPRequest(sipMessageBuffer); Assert.Equal(SIPMethodsEnum.INVITE, sipRequest.Method); IPAddress ip6, ip4; Assert.NotEmpty(sipRequest.Header.Vias.Via); Assert.True(IPAddress.TryParse(sipRequest.Header.Vias.TopViaHeader.ReceivedFromAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.NotEmpty(sipRequest.Header.Contact); Assert.True(IPAddress.TryParse(sipRequest.Header.Contact[0].ContactURI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.True(IPAddress.TryParse(sipRequest.URI.HostAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); Assert.False(string.IsNullOrWhiteSpace(sipRequest.Body)); SDP sdp = SDP.ParseSDPDescription(sipRequest.Body); Assert.NotNull(sdp); Assert.NotNull(sdp.Connection); Assert.True(IPAddress.TryParse(sdp.Connection.ConnectionAddress, out ip4)); Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily); Assert.NotEmpty(sdp.Media); Assert.NotNull(sdp.Media[0].Connection); Assert.True(IPAddress.TryParse(sdp.Media[0].Connection.ConnectionAddress, out ip4)); Assert.Equal(AddressFamily.InterNetwork, ip4.AddressFamily); Assert.NotNull(sdp.Media[1].Connection); Assert.True(IPAddress.TryParse(sdp.Media[1].Connection.ConnectionAddress, out ip6)); Assert.Equal(AddressFamily.InterNetworkV6, ip6.AddressFamily); logger.LogDebug("-----------------------------------------"); }