public void IPv4LoopbackSendReceiveTest() { logger.LogDebug("IPv4LoopbackSendReceiveTest commencing..."); CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(); var serverChannel = new SIPUDPChannel(IPAddress.Loopback, 6060); var clientChannel = new SIPUDPChannel(IPAddress.Loopback, 6061); var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer); }); var clientTask = Task.Run(async() => { await RunClient(clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sip, IPAddress.Loopback), testComplete); }); Task.WhenAny(new Task[] { serverTask, clientTask, Task.Delay(TRANSPORT_TEST_TIMEOUT) }).Wait(); if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); logger.LogDebug("Test complete."); }
public async Task PlaceCallUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport serverTransport = new SIPTransport(); SIPUDPChannel udpChannel = new SIPUDPChannel(IPAddress.Loopback, 0); serverTransport.AddSIPChannel(udpChannel); // Set up two user agents: one to answer the test call and one to place it. SIPUserAgent userAgentServer = new SIPUserAgent(serverTransport, null); SIPUserAgent userAgentClient = new SIPUserAgent(new SIPTransport(), null); serverTransport.SIPTransportRequestReceived += async(lep, rep, req) => { logger.LogDebug("Request received: " + req.StatusLine); var uas = userAgentServer.AcceptCall(req); RtpAudioSession serverAudioSession = new RtpAudioSession( new AudioSourceOptions { AudioSource = AudioSourcesEnum.None }, new List <SDPMediaFormatsEnum> { SDPMediaFormatsEnum.PCMU }); var answerResult = await userAgentServer.Answer(uas, serverAudioSession); logger.LogDebug($"Server agent answer result {answerResult}."); Assert.True(answerResult); }; var dstUri = udpChannel.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 0))); logger.LogDebug($"Attempting call to {dstUri.ToString()}."); RtpAudioSession clientAudioSession = new RtpAudioSession( new AudioSourceOptions { AudioSource = AudioSourcesEnum.None }, new List <SDPMediaFormatsEnum> { SDPMediaFormatsEnum.PCMU }); var callResult = await userAgentClient.Call(dstUri.ToString(), null, null, clientAudioSession); logger.LogDebug($"Client agent answer result {callResult }."); Assert.True(callResult); Assert.Equal(SIPDialogueStateEnum.Confirmed, userAgentClient.Dialogue.DialogueState); Assert.Equal(SIPDialogueStateEnum.Confirmed, userAgentServer.Dialogue.DialogueState); }
public void IPv6LoopbackSendReceiveTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); if (!Socket.OSSupportsIPv6) { logger.LogDebug("Test skipped as OS does not support IPv6."); } else { ManualResetEventSlim serverReadyEvent = new ManualResetEventSlim(false); CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); var serverChannel = new SIPUDPChannel(IPAddress.IPv6Loopback, 0); var clientChannel = new SIPUDPChannel(IPAddress.IPv6Loopback, 0); var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer, serverReadyEvent); }); var clientTask = Task.Run(async() => { #pragma warning disable RCS1090 // Add call to 'ConfigureAwait' (or vice versa). await RunClient( clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.IPv6Loopback, 0))), testComplete, cancelServer, serverReadyEvent); #pragma warning restore RCS1090 // Add call to 'ConfigureAwait' (or vice versa). }); serverReadyEvent.Wait(); if (!Task.WhenAny(new Task[] { serverTask, clientTask }).Wait(TRANSPORT_TEST_TIMEOUT)) { logger.LogWarning($"Tasks timed out"); } if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); } }
public async Task PlaceCallMismatchedCapabilitiesUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport serverTransport = new SIPTransport(); SIPUDPChannel udpChannel = new SIPUDPChannel(IPAddress.Loopback, 0); serverTransport.AddSIPChannel(udpChannel); // Set up two user agents: one to answer the test call and one to place it. SIPUserAgent userAgentServer = new SIPUserAgent(serverTransport, null); SIPUserAgent userAgentClient = new SIPUserAgent(new SIPTransport(), null); serverTransport.SIPTransportRequestReceived += async(lep, rep, req) => { logger.LogDebug("Request received: " + req.StatusLine); var uas = userAgentServer.AcceptCall(req); var serverAudioSession = CreateMockVoIPMediaEndPoint(new List <AudioCodecsEnum> { AudioCodecsEnum.PCMU }); var answerResult = await userAgentServer.Answer(uas, serverAudioSession); logger.LogDebug($"Server agent answer result {answerResult}."); Assert.False(answerResult); }; var dstUri = udpChannel.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 0))); logger.LogDebug($"Attempting call to {dstUri.ToString()}."); var clientMediaEndPoint = CreateMockVoIPMediaEndPoint(new List <AudioCodecsEnum> { AudioCodecsEnum.G722 }); var callResult = await userAgentClient.Call(dstUri.ToString(), null, null, clientMediaEndPoint); logger.LogDebug($"Client agent answer result {callResult }."); Assert.False(callResult); }
public void GetDefaultContactURIUnitTest() { 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}."); var contactURI = udpChan.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(udpChan.SIPProtocol, SIPChannel.InternetDefaultAddress, 0)); Assert.NotNull(contactURI); logger.LogDebug($"Contact URI: {contactURI}."); udpChan.Close(); logger.LogDebug("-----------------------------------------"); }
public void IPv4LoopbackSendReceiveTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); ManualResetEventSlim serverReadyEvent = new ManualResetEventSlim(false); CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(); var serverChannel = new SIPUDPChannel(IPAddress.Loopback, 0); var clientChannel = new SIPUDPChannel(IPAddress.Loopback, 0); var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer, serverReadyEvent); }); var clientTask = Task.Run(async() => { await RunClient( clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 0))), testComplete, cancelServer, serverReadyEvent); }); serverReadyEvent.Wait(); if (!Task.WhenAny(new Task[] { serverTask, clientTask }).Wait(TRANSPORT_TEST_TIMEOUT)) { logger.LogWarning($"Tasks timed out"); } if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); logger.LogDebug("Test complete."); }