Exemple #1
0
        /// <summary>
        /// Executes the command set by the program's command line arguments.
        /// </summary>
        /// <param name="options">The options that dictate the SIP command to execute.</param>
        static async Task RunCommand(Options options)
        {
            try
            {
                logger.LogDebug($"RunCommand scenario {options.Scenario}, destination {options.Destination}");

                CancellationTokenSource cts = new CancellationTokenSource();
                int taskCount    = 0;
                int successCount = 0;

                List <Task> tasks = new List <Task>();

                for (int i = 0; i < options.Concurrent; i++)
                {
                    var task = Task.Run(async() =>
                    {
                        while (taskCount < options.Count && !cts.IsCancellationRequested)
                        {
                            int taskNum  = Interlocked.Increment(ref taskCount);
                            bool success = await RunTask(options, taskNum);

                            if (success)
                            {
                                Interlocked.Increment(ref successCount);
                            }
                            else if (options.BreakOnFail)
                            {
                                cts.Cancel();
                                break;
                            }
                            else if (options.Period > 0)
                            {
                                await Task.Delay(options.Period * 1000);
                            }
                        }
                    }, cts.Token);

                    tasks.Add(task);

                    // Spread the concurrent tasks out a tiny bit.
                    await Task.Delay(Crypto.GetRandomInt(500, 2000));
                }

                // Wait for all the concurrent tasks to complete.
                await Task.WhenAll(tasks.ToArray());

                DNSManager.Stop();

                // Give the transport half a second to shutdown (puts the log messages in a better sequence).
                await Task.Delay(500);

                logger.LogInformation($"=> Command completed task count {taskCount} success count {successCount}.");
            }
            catch (Exception excp)
            {
                logger.LogError($"Exception RunCommand. {excp.Message}");
            }
        }
Exemple #2
0
        /// <summary>
        /// Shutdown the SIP tranpsort layer and any other resources the SIP client is using. Typically called when the application exits.
        /// </summary>
        public void Shutdown()
        {
            if (m_sipTransport != null)
            {
                m_sipTransport.Shutdown();
            }

            DNSManager.Stop();
        }
        /// <summary>
        /// Shutdown the SIP tranpsort layer and any other resources. Should only be called when the application exits.
        /// </summary>
        public void Shutdown()
        {
            if (SIPTransport != null)
            {
                SIPTransport.Shutdown();
            }

            DNSManager.Stop();
        }
Exemple #4
0
        /// <summary>
        /// Shutdown the SIP tranpsort layer and any other resources the SIP client is using. Typically called when the application exits.
        /// </summary>
        public void Shutdown()
        {
            if (m_sipTransport != null)
            {
                m_sipTransport.Shutdown();
            }

            DNSManager.Stop();

            if (_audioChannel != null)
            {
                _audioChannel.Close();
            }
        }
        public void Stop()
        {
            try
            {
                logger.Debug("SIP Application Server stopping...");

                DNSManager.Stop();
                m_dialPlanEngine.StopScriptMonitoring = true;

                if (m_callManagerSvcHost != null)
                {
                    m_callManagerSvcHost.Close();
                }

                if (m_callManager != null)
                {
                    m_callManager.Stop();
                }

                if (m_monitorEventWriter != null)
                {
                    m_monitorEventWriter.Close();
                }

                // Shutdown the SIPTransport layer.
                m_sipTransport.Shutdown();

                m_sipSorceryPersistor.StopCDRWrites = true;

                logger.Debug("SIP Application Server stopped.");
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPAppServerDaemon Stop." + excp.Message);
            }
        }
Exemple #6
0
        /// <summary>
        /// Executes the command set by the program's command line arguments.
        /// </summary>
        /// <param name="options">The options that dictate the SIP command to execute.</param>
        static async Task RunCommand(Options options)
        {
            try
            {
                logger.LogDebug($"RunCommand {options.Destination}");

                (var dstEp, var dstUri) = ParseDestination(options.Destination);

                logger.LogDebug($"Destination IP end point {dstEp} and SIP URI {dstUri}");

                int  sendCount = 0;
                bool success   = true;

                do
                {
                    IPAddress  localAddress = (dstEp.Address.AddressFamily == AddressFamily.InterNetworkV6) ? IPAddress.IPv6Any : IPAddress.Any;
                    SIPChannel sipChannel   = null;

                    switch (dstEp.Protocol)
                    {
                    case SIPProtocolsEnum.tcp:
                        sipChannel = new SIPTCPChannel(new IPEndPoint(localAddress, DEFAULT_SIP_CLIENT_PORT));
                        (sipChannel as SIPTCPChannel).DisableLocalTCPSocketsCheck = true;     // Allow sends to listeners on this host.
                        break;

                    case SIPProtocolsEnum.tls:
                        var certificate = new X509Certificate2(@"localhost.pfx", "");
                        sipChannel = new SIPTLSChannel(certificate, new IPEndPoint(localAddress, DEFAULT_SIPS_CLIENT_PORT));
                        break;

                    case SIPProtocolsEnum.udp:
                        sipChannel = new SIPUDPChannel(new IPEndPoint(localAddress, DEFAULT_SIP_CLIENT_PORT));
                        break;

                    case SIPProtocolsEnum.ws:
                        sipChannel = new SIPClientWebSocketChannel();
                        break;

                    case SIPProtocolsEnum.wss:
                        sipChannel = new SIPClientWebSocketChannel();
                        break;

                    default:
                        throw new ApplicationException($"Don't know how to create SIP channel for transport {dstEp.Protocol}.");
                    }

                    SIPTransport sipTransport = new SIPTransport();
                    sipTransport.AddSIPChannel(sipChannel);

                    if (sendCount > 0 && options.Period > 0)
                    {
                        await Task.Delay(options.Period * 1000);
                    }

                    sendCount++;

                    DateTime sendTime = DateTime.Now;
                    var      sendTask = SendOptionsTaskAsync(sipTransport, dstUri);
                    var      result   = await Task.WhenAny(sendTask, Task.Delay(options.Timeout * 1000));

                    TimeSpan duration = DateTime.Now.Subtract(sendTime);

                    if (!sendTask.IsCompleted)
                    {
                        logger.LogWarning($"=> Request to {dstEp} did not get a response on send {sendCount} of {options.Count} after {duration.TotalMilliseconds.ToString("0")}ms.");
                        success = false;
                    }
                    else if (!sendTask.Result)
                    {
                        logger.LogWarning($"=> Request to {dstEp} did not get the expected response on request {sendCount} of {options.Count} after {duration.TotalMilliseconds.ToString("0")}ms.");
                        success = false;
                    }
                    else
                    {
                        logger.LogInformation($"=> Got correct response on send {sendCount} of {options.Count} in {duration.TotalMilliseconds.ToString("0")}ms.");
                    }

                    logger.LogDebug("Shutting down the SIP transport...");
                    sipTransport.Shutdown();

                    if (success == false)
                    {
                        break;
                    }
                }while (sendCount < options.Count);

                DNSManager.Stop();

                // Give the transport half a second to shutdown (puts the log messages in a better sequence).
                await Task.Delay(500);

                logger.LogInformation($"=> Command completed {((success) ? "successfully" : "with failure")}.");
            }
            catch (Exception excp)
            {
                logger.LogError($"Exception RunCommand. {excp.Message}");
            }
        }
        public void Stop()
        {
            try
            {
                logger.Debug("SIP Application Server stopping...");

                m_dialPlanEngine.StopScriptMonitoring = true;

                if (m_accessPolicyHost != null && m_accessPolicyHost.State == CommunicationState.Opened)
                {
                    m_accessPolicyHost.Close();
                }

                if (m_sipProvisioningHost != null && m_sipProvisioningHost.State == CommunicationState.Opened)
                {
                    m_sipProvisioningHost.Close();
                }

                if (m_callManagerSvcHost != null && m_callManagerSvcHost.State == CommunicationState.Opened)
                {
                    m_callManagerSvcHost.Close();
                }

                if (m_sipNotificationsHost != null && m_sipNotificationsHost.State == CommunicationState.Opened)
                {
                    m_sipNotificationsHost.Close();
                }

                if (m_callManager != null)
                {
                    m_callManager.Stop();
                }

                if (m_rtccCore != null)
                {
                    m_rtccCore.Stop();
                }

                //if (m_notifyManager != null)
                //{
                //    m_notifyManager.Stop();
                //}

                if (m_monitorEventWriter != null)
                {
                    m_monitorEventWriter.Close();
                }

                if (m_sipProxyDaemon != null)
                {
                    m_sipProxyDaemon.Stop();
                }

                if (m_sipMonitorDaemon != null)
                {
                    m_sipMonitorDaemon.Stop();
                }

                if (m_sipRegistrarDaemon != null)
                {
                    m_sipRegistrarDaemon.Stop();
                }

                if (m_sipNotifierDaemon != null)
                {
                    m_sipNotifierDaemon.Stop();
                }

                if (m_sipRegAgentDaemon != null)
                {
                    m_sipRegAgentDaemon.Stop();
                }

                if (m_sipNotifierDaemon != null)
                {
                    m_sipNotifierDaemon.Stop();
                }

                if (m_rateUpdater != null)
                {
                    m_rateUpdater.Stop();
                }

                // Shutdown the SIPTransport layer.
                m_sipTransport.Shutdown();
                DNSManager.Stop();

                m_sipSorceryPersistor.StopCDRWrites = true;

                logger.Debug("SIP Application Server stopped.");
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPAppServerDaemon Stop." + excp.Message);
            }
        }