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 TestSocketReadWithTwoMessagesAndBytesToSkipTest() { 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 " + CRLF + " 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 + CRLF + "SUBSCRIBE sip:[email protected]"; byte[] testReceiveBytes = UTF8Encoding.UTF8.GetBytes(testReceive); Socket dummySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); dummySocket.Bind(new IPEndPoint(IPAddress.Any, 0)); SIPStreamConnection testConnection = new SIPStreamConnection(dummySocket, new IPEndPoint(IPAddress.Loopback, 0), SIPProtocolsEnum.tcp); int sipMessages = 0; testConnection.SIPMessageReceived += (chan, localEp, ep, buffer) => { sipMessages++; return(Task.FromResult(0)); }; Array.Copy(testReceiveBytes, 0, testConnection.RecvSocketArgs.Buffer, 0, testReceiveBytes.Length); MockSIPChannel mockChannel = new MockSIPChannel(new IPEndPoint(IPAddress.Any, 0)); testConnection.ExtractSIPMessages(mockChannel, testConnection.RecvSocketArgs.Buffer, testReceiveBytes.Length); string remainingBytes = Encoding.UTF8.GetString(testConnection.RecvSocketArgs.Buffer, testConnection.RecvStartPosn, testConnection.RecvEndPosn - testConnection.RecvStartPosn); logger.LogDebug("SocketBufferEndPosition=" + testConnection.RecvEndPosn + "."); logger.LogDebug("SocketBuffer=" + remainingBytes + "."); Assert.True(sipMessages == 2, "The number of SIP messages parsed was incorrect."); Assert.True(708 == testConnection.RecvStartPosn, $"The receive buffer start position was incorrect, was {testConnection.RecvStartPosn}."); Assert.True(734 == testConnection.RecvEndPosn, $"The receive buffer end position was incorrect, was {testConnection.RecvEndPosn}."); Assert.True(remainingBytes == "SUBSCRIBE sip:[email protected]", $"The leftover bytes in the socket buffer were incorrect {remainingBytes}."); }
public void CallWithAdjustedInviteHeaderTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); MockSIPChannel channel = new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0)); transport.AddSIPChannel(channel); SIPClientUserAgent userAgent = new SIPClientUserAgent( transport, new SIPEndPoint(new IPEndPoint(new IPAddress(new byte[] { 192, 168, 11, 50 }), 5060)), "owner", "admin", null); SIPContactHeader testHeader = new SIPContactHeader("Contact Name", new SIPURI("User", "Host", "Param=Value")); userAgent.AdjustInvite = invite => { invite.Header.Contact = new List <SIPContactHeader> { testHeader }; return(invite); }; var desc = new SIPCallDescriptor( "user", "pass", "sip:user@host", "sip:user@host", "sip:destination@destinationhost", null, new List <string>(), "user", SIPCallDirection.Out, null, null, null); userAgent.Call(desc); channel.SIPMessageSent.WaitOne(5000); Assert.Contains(testHeader.ToString(), channel.LastSIPMessageSent); }
public void RegisterWithAdjustedRegisterHeaderTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); MockSIPChannel channel = new MockSIPChannel(new System.Net.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" }); SIPContactHeader testHeader = new SIPContactHeader("Contact Name", new SIPURI("User", "Host", "Param=Value")); userAgent.AdjustRegister = register => { register.Header.Contact = new List <SIPContactHeader> { testHeader }; return(register); }; userAgent.Start(); channel.SIPMessageSent.WaitOne(5000); Assert.Contains(testHeader.ToString(), channel.LastSIPMessageSent); userAgent.Stop(); }
public void TestSocketReadWithBytesToSkipTest() { Console.WriteLine(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); Socket dummySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); dummySocket.Bind(new IPEndPoint(IPAddress.Any, 0)); SIPStreamConnection testConnection = new SIPStreamConnection(dummySocket, new IPEndPoint(IPAddress.Loopback, 0), SIPProtocolsEnum.tcp); int sipMessages = 0; testConnection.SIPMessageReceived += (chan, localEp, ep, buffer) => { sipMessages++; }; MockSIPChannel mockChannel = new MockSIPChannel(new IPEndPoint(IPAddress.Any, 0)); testConnection.ExtractSIPMessages(mockChannel, testReceiveBytes, testReceiveBytes.Length); Assert.True(sipMessages == 1, "The number of SIP messages parsed was incorrect, was " + sipMessages + "."); Assert.True(testConnection.RecvStartPosn == 0, $"The receive buffer start position was incorrect, was {testConnection.RecvStartPosn}."); Assert.True(testConnection.RecvEndPosn == 0, $"The receive buffer end position was incorrect, was {testConnection.RecvEndPosn}."); }
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 LooseRouteForProxyUnitTest() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = "INVITE sip:[email protected] SIP/2.0" + m_CRLF + "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF + "Route: <sip:82.195.148.216:5062;lr>,<sip:89.100.92.186:45270;lr>" + m_CRLF + "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF + "To: <sip:[email protected]>" + m_CRLF + "Contact: <sip:[email protected]:5065>" + m_CRLF + "Call-ID: [email protected]" + m_CRLF + "CSeq: 49429 INVITE" + m_CRLF + "Max-Forwards: 70" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "User-Agent: X-PRO release 1103v" + m_CRLF + m_CRLF; SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage); MockSIPChannel mockSIPChannel = new MockSIPChannel(IPSocket.ParseSocketString("82.195.148.216:5062")); SIPTransport mockSIPTransport = new SIPTransport(MockSIPDNSManager.Resolve, null, mockSIPChannel, false); mockSIPTransport.PreProcessRouteInfo(inviteReq); Assert.IsTrue(inviteReq.URI.ToString() == "sip:[email protected]", "The request URI was incorrectly modified."); Assert.IsTrue(inviteReq.Header.Routes.TopRoute.ToString() == "<sip:89.100.92.186:45270;lr>", "The request route information was not correctly preprocessed."); Assert.IsTrue(inviteReq.Header.Routes.Length == 1, "The route set was an incorrect length."); }