Asterisk notifications (solved)

Discussions about using SIP Sorcery on your own computer/server
Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Asterisk notifications (solved)

Post by Nebukadnezar » Mon Sep 27, 2010 1:52 pm

Every hour or so the console shows a bunch of incoming notifications from the Asterisk server of my provider:

Code: Select all

no: Forwarding NOTIFY request from sip:asterisk@84.243.xxx.xxx to registered binding at sip:xxxxx@xxx.xxx.xxx.xxx:5060, proxy udp:192.168.0.5:5060.
no: Forwarding NOTIFY request from sip:asterisk@84.243.xxx.xxx to registered binding at sip:xxxxx@xxx.xxx.xxx.xxx:5060, proxy udp:192.168.0.5:5060.
no: Forwarding NOTIFY request from sip:asterisk@84.243.xxx.xxx to registered binding at sip:xxxxx@xxx.xxx.xxx.xxx:5060, proxy udp:192.168.0.5:5060.
no: Forwarding NOTIFY request from sip:asterisk@84.243.xxx.xxx to registered binding at sip:xxxxx@xxx.xxx.xxx.xxx:5060, proxy udp:192.168.0.5:5060.
no: Forwarding NOTIFY request from sip:asterisk@84.243.xxx.xxx to registered binding at sip:xxxxx@xxx.xxx.xxx.xxx:5060, proxy udp:192.168.0.5:5060.
How can I determine the nature of these notifications? They are not stored in the database, but they seem to be queued somehow. It does results in a number of UDP listening ports on the sipsorcery-appsvr.exe per batch of notifications. After running the server for 24 hours there where 24 UDP ports attached to the executable:

Code: Select all

sipsorcery-appsvr.exe:2484	TCP	0.0.0.0:943		0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:2484	TCP	192.168.0.5:2060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:2484	TCP	192.168.0.5:5060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:2484	TCP	127.0.0.1:1333		127.0.0.1:3306	ESTABLISHED	
sipsorcery-appsvr.exe:2484	TCP	127.0.0.1:1340		127.0.0.1:3306	ESTABLISHED	
sipsorcery-appsvr.exe:2484	TCP	127.0.0.1:4224		127.0.0.1:3306	ESTABLISHED	
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:10001	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3358	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3349	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:2058	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1543	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1335	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1337	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1344	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1345	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:2032	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1359	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1363	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3561	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:2264	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1376	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1638	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3532	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3529	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3269	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1382	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:1947	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3743	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3229	*:*		
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3475	*:*
sipsorcery-appsvr.exe:2484	UDP	0.0.0.0:3623	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:5002	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:5001	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:5003	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:5065	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:2060	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:9001	*:*		
sipsorcery-appsvr.exe:2484	UDP	192.168.0.5:5060	*:*
The phones i use are simple DECT types connected to ATA's with no facilities for notifications. Is there a way to reject these notifications?
Last edited by Nebukadnezar on Thu Sep 30, 2010 5:22 pm, edited 1 time in total.

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Asterisk notifications

Post by Aaron » Mon Sep 27, 2010 8:52 pm

The NOTIFY requests are most voicemail likely message waiting indications (MWI) from your provider. You could block them in your proxy script, proxyscript.py, but I wouldn't bother they won't be generating any kind of load or cuasing any issues.

Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Re: Asterisk notifications

Post by Nebukadnezar » Tue Sep 28, 2010 11:05 am

Those MWI notifications I can understand, but are they related to the increase in the number of UDP listeners attached to the sipsorcery-appsvr.exe? I ran wireshark against those ports and could not detect any traffic on them.

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Asterisk notifications

Post by Aaron » Tue Sep 28, 2010 11:27 am

There shouldn't be any extra UDP sockets opened as a consequence of the NOTIFY requests.

I don't recognise the ports below and I suspect they are being used for DNS lookups as that's the only thing sipsorcery should be using arbitrary UDP sockets for.

sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:3358 *:*
sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:3349 *:*
sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:2058 *:*
sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:1543 *:*
sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:1335 *:*
sipsorcery-appsvr.exe:2484 UDP 0.0.0.0:1337 *:*

Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Re: Asterisk notifications

Post by Nebukadnezar » Wed Sep 29, 2010 2:26 pm

Aaron,

I cannot figure it out; the server starts with all TCP and UDP ports accounted for:

Code: Select all

sipsorcery-appsvr.exe:572	TCP	127.0.0.1:3990		127.0.0.1:3306	ESTABLISHED(MySQL)
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:2060	*:*	
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5060	*:*		
sipsorcery-appsvr.exe:572	TCP	192.168.0.5:5060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	UDP	0.0.0.0:10001		*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:9001	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5001	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5003	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5002	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5065	*:*		
sipsorcery-appsvr.exe:572	TCP	192.168.0.5:2060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	TCP	0.0.0.0:943		0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	TCP	127.0.0.1:3999		127.0.0.1:3306	ESTABLISHED(MySQL)	
Next, the following console messages appear:

Code: Select all

re: Register queued for sip:xxxxx@xxxxxxxxxx.org:5060.
re: Authentication failed stale nonce for realm=xxxxxxxxxx.org, username=xxxxx, uri=sip:xxxxxxxxxx.org:5060;transport=UDP, nonce=19148346071607540128, method=REGISTER.
re: Authentication required for xxxxx@xxxxxxxxxx.org from udp:xxx.xxx.140.230:5060.
re: register result=AuthenticationRequired, time=156.235ms, user=xxxxx.
Resending final response for REGISTER, sip:xxxxxxxxxx.org:5060;transport=UDP, cseq=8.
Resending final response for REGISTER, sip:xxxxxxxxxx.org:5060;transport=UDP, cseq=8.
Resending final response for REGISTER, sip:xxxxxxxxxx.org:5060;transport=UDP, cseq=8.
re: Register queued for sip:xxxxx@xxxxxxxxxx.org:5060.
re: Binding update request for xxxxx@xxxxxxxxxx.org from udp:xxx.xxx.140.230:5060, expiry requested 3600s granted 600s.
Transaction already exists, ignoring duplicate request, REGISTER sip:xxxxxxxxxx.org:5060;transport=UDP.
re: Binding update time for xxxxx@xxxxxxxxxx.org took 406.211ms.
re: Registration successful for xxxxx@xxxxxxxxxx.org from udp:xxx.xxx.140.230:5060 (proxy=udp:192.168.0.5:5060), expiry 600s.
re: register result=Authenticated, time=515.5755ms, user=xxxxx.
re: Register queued for sip:xxxxx@xxxxxxxxxx.org:5060.
re: Authentication failed stale nonce for realm=xxxxxxxxxx.org, username=xxxxx, uri=sip:xxxxxxxxxx.org:5060;transport=UDP, nonce=19148346071256984056, method=REGISTER.
re: Authentication required for xxxxx@xxxxxxxxxx.org from udp:xxx.xxx.214.200:5060.
re: register result=AuthenticationRequired, time=46.8705ms, user=xxxxx.
re: Register queued for sip:xxxxx@xxxxxxxxxx.org:5060.
re: Binding update request for xxxxx@xxxxxxxxxx.org from udp:xxx.xxx.214.200:5060, expiry requested 3600s granted 600s.
re: Binding update time for xxxxx@xxxxxxxxxx.org took 31.247ms.
re: Registration successful for xxxxx@xxxxxxxxxx.org from udp:xxx.1xxx.214.200:5060 (proxy=udp:192.168.0.5:5060), expiry 600s.
re: register result=Authenticated, time=78.1175ms, user=xxxxx.
And immediately after that, the process list is:

Code: Select all

sipsorcery-appsvr.exe:572	TCP	127.0.0.1:3990		127.0.0.1:3306	ESTABLISHED(MySQL)
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:2060	*:*	
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5060	*:*		
sipsorcery-appsvr.exe:572	TCP	192.168.0.5:5060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	UDP	0.0.0.0:10001		*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:9001	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5001	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5003	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5002	*:*		
sipsorcery-appsvr.exe:572	UDP	192.168.0.5:5065	*:*		
sipsorcery-appsvr.exe:572	TCP	192.168.0.5:2060	0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	TCP	0.0.0.0:943		0.0.0.0:0	LISTENING	
sipsorcery-appsvr.exe:572	UDP	0.0.0.0:3996		*:*	
sipsorcery-appsvr.exe:572	UDP	0.0.0.0:3997		*:*		
sipsorcery-appsvr.exe:572	UDP	0.0.0.0:3998		*:*		
sipsorcery-appsvr.exe:572	TCP	127.0.0.1:3999		127.0.0.1:3306	ESTABLISHED(MySQL)
I checked all sources with ‘new udpClient(’ and ‘new socket(’ (UDP) and even placed logger.Debug traces around those calls but it still eludes me. Resolver.cs opens and closes used ports, others are supposed to stay opened (SIPMonitorClientManager.cs, SIPMonitorEventWriter.cs, SIPMonitorMediator.cs, STUNClient.cs etc.).

Three lines in the console output above refer to ‘Resending final response for’, and three UDP ports are added to the server. I am currently trying to figure out the code of SIPTransport.cs, but any help would be very much appreciated.

I am using the latest SVN and the examples above occur each time I start the server. Those zombie UDP ports do not impair the functionality of the server, but the next day there will be 24 of those ports.

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Asterisk notifications

Post by Aaron » Wed Sep 29, 2010 11:08 pm

That's not a good situation and definitely warrants looking into. I'll try and replicate it on my own local sipsorcery instance.

What command are you using to print out your list of sockets? I can get the information with netstat but it's not formatted as nicely.

Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Re: Asterisk notifications

Post by Nebukadnezar » Thu Sep 30, 2010 6:47 am

Thanks Aaron. It is TcpView (formerly Sysinternals, now Microsoft): http://download.sysinternals.com/Files/TCPView.zip

I compiled the server using the latest SVN with vs2010 (Framework 4) under Windows 7(x64) for x86 environment. The server runs under Windows server 2003(x86) R2 SP2. The only change I made to the SVN is:

Posted earlier: viewtopic.php?f=14&t=2722

Code: Select all

as (36:56:671 70788): Using dialplan out for Out call to sip:xxxxx@metasip.internal:5060.
as (36:56:796 70788): Executing script dial plan for call to xxxxx.
as (36:56:875 70788): Error executing script dialplan for xxxxx. Invalid argument value
[color=#FF0000]Parameter name: ScriptRuntimeSetup must have at least one LanguageSetup[/color]
as (36:56:921 70788): UAS call failed with a response status of 500 and Dial plan exception starting script.
DialPlanExecutingScript.cs

Code: Select all

        [color=#FF0000]public string rubyPath = @"d:\\sip-compiled-svn\\sip\\app.config";[/color]

        public Action Cleanup;  // A function delegate that will be called when the script is completed to allow any cleanup actions to take place.

        public DialPlanExecutingScript(SIPMonitorLogDelegate logDelegate)
        {
            ScriptNumber = ++ScriptCounter % Int32.MaxValue;
            Id = Guid.NewGuid();

            var setup = ScriptRuntimeSetup.ReadConfiguration([color=#FF0000]rubyPath[/color]);
            var scriptRuntime = Ruby.CreateRuntime(setup);
            DialPlanScriptEngine = Ruby.GetEngine(scriptRuntime);

            //DialPlanScriptEngine = Ruby.CreateEngine();


            DialPlanScriptScope = DialPlanScriptEngine.CreateScope();

            LogDelegate = logDelegate;
        }
sipsorcery-appsvr.exe.config

Code: Select all

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
    <section name="sipappserver" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sipregistrar" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sipregistrationagent" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sipnotifier" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sipproxy" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sipmonitor" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
    <section name="sshserver" type="SIPSorcery.Sys.AppState, SIPSorcery.Sys"/>
  </configSections>
  <log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%m%n"/>
      </layout>
    </appender>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="D:\SIP-Compiled-SVN\SIP-Operational\logs\root.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="50MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ALL"/>
        <levelMax value="FATAL"/>
      </filter>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="DialPlanLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="D:\SIP-Compiled-SVN\SIP-Operational\logs\dialplan.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="50MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="ErrorRollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="D:\SIP-Compiled-SVN\SIP-Operational\logs\error.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="50MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ERROR"/>
        <levelMax value="FATAL"/>
      </filter>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="DispatcherRollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="D:\SIP-Compiled-SVN\SIP-Operational\logs\dispatcher.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="50MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <logger name="sipcalldispatcher">
      <appender-ref ref="DispatcherRollingLogFileAppender"/>
    </logger>
    <logger name="dialplan">
      <appender-ref ref="DialPlanLogFileAppender"/>
    </logger>
    <root>
      <priority value="DEBUG"/>
      <appender-ref ref="ConsoleAppender"/>
      <appender-ref ref="RollingLogFileAppender"/>
      <appender-ref ref="ErrorRollingLogFileAppender"/>
    </root>
  </log4net>
  <system.serviceModel>
    <services>
      <service name="SIPSorcery.Web.Services.CrossDomainService">
        <host>
          <baseAddresses>
            <add baseAddress="http://*:8080/"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="webHttpBinding" contract="SIPSorcery.Web.Services.ICrossDomain" behaviorConfiguration="HttpEnableBehavior"/>
      </service>
      <service name="SIPSorcery.Web.Services.SIPProvisioningWebService" behaviorConfiguration="PersistorTypeBehaviors">
        <host>
          <baseAddresses>
            <add baseAddress="http://*:8080/provisioning.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint address="" binding="basicHttpBinding" contract="SIPSorcery.Web.Services.IProvisioningService" bindingConfiguration="LargeMessagesBindingConfiguration"/>
      </service>
      <service name="SIPSorcery.Web.Services.CallManagerServices" behaviorConfiguration="GetServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://*:8080/callmanager.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="" behaviorConfiguration="HttpEnableBehavior" binding="webHttpBinding" contract="SIPSorcery.Web.Services.ICallManagerServices"/>
      </service>
      <service name="SIPSorcery.Web.Services.SIPNotifierService" behaviorConfiguration="PubSubServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://*:8080/notificationspull.svc"/>
          </baseAddresses>
        </host>
        <endpoint binding="basicHttpBinding" contract="SIPSorcery.Web.Services.INotifications"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
      <service name="SIPSorcery.Web.Services.SIPMonitorClientManagerHost" behaviorConfiguration="InternalNotificationsBehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8091/notifications"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeMessagesBindingConfiguration" contract="SIPSorcery.SIP.App.ISIPMonitorPublisher"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="LargeMessagesBindingConfiguration">
          <readerQuotas maxStringContentLength="40000"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PersistorTypeBehaviors">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="GetServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="PubSubServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceThrottling maxConcurrentSessions="1"/>
        </behavior>
        <behavior name="InternalNotificationsBehaviour">
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="HttpEnableBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <appSettings>
    <add key="PersistenceStorageType" value="SQLLinqMySQL"/>
    <add key="UserDataDBType" value="MySQL"/>
    <add key="PersistenceConnStr" value="Database=sipsorcery;Data Source=metasip;User Id=root;Password=xxxxx"/>
  </appSettings>
  <!-- SIP Proxy configuration. -->
  <sipproxy>
    <MonitorLoopbackPort value="10001"/>
    <ProxyScriptPath value="proxyscript.py"/>
    <NATKeepAliveSocket value="192.168.0.5:9001"/>
    <!-- <PublicIPAddress value="xxx.xxx.xxx.xxx" /> -->
    <STUNServerHostname value="stun.voipplanet.nl"/>
    <AppServerEndPointsPath value="appservers.txt"/>
    <sipsockets>
      <socket>192.168.0.5:5060</socket>
      <socket>192.168.0.5:2060</socket>
      <socket protocol="tcp">192.168.0.5:5060</socket>
      <socket protocol="tcp">192.168.0.5:2060</socket>
    </sipsockets>
  </sipproxy>
  <!--<socket protocol="tls" certificatepath="10.1.1.2.pfx">*:5061</socket>-->
  <!-- SIP Monitor configuration. -->
  <sipmonitor>
    <MonitorLoopbackPort value="10001"/>
  </sipmonitor>
  <!-- SIP Registrar configuration. -->
  <sipregistrar>
    <MonitorLoopbackPort value="10001"/>
    <MaximumAccountBindings value="100"/>
    <NATKeepAliveRelaySocket value="192.168.0.5:9001"/>
    <sipsockets>
      <sipsocket>192.168.0.5:5001</sipsocket>
    </sipsockets>
    <useragentconfigs>
      <useragent expiry="3600" contactlists="true">fring</useragent>
      <useragent expiry="3600" contactlists="false">Nokia</useragent>
      <useragent expiry="60" contactlists="false">Cisco-CP7960G/8.0</useragent>
      <useragent expiry="600" contactlists="true">Speedtouch 780</useragent>
      <useragent expiry="113">.*</useragent>
    </useragentconfigs>
  </sipregistrar>
  <!-- SIP Registration Agent configuration. -->
  <sipregistrationagent>
    <MonitorLoopbackPort value="10001"/>
    <OutboundProxy value=""/>
    <!-- <OutboundProxy value="192.168.0.5:5060"/> -->
    <sipsockets>
      <sipsocket>192.168.0.5:5002</sipsocket>
    </sipsockets>
  </sipregistrationagent>
  <!-- SIP Notifier Server configuration. -->
  <sipnotifier>
    <MonitorLoopbackPort value="10001"/>
    <OutboundProxy value=""/>
    <!-- <OutboundProxy value="192.168.0.5:5060"/> -->
    <sipsockets>
      <sipsocket>192.168.0.5:5003</sipsocket>
    </sipsockets>
  </sipnotifier>
  <!-- SIP Application Server configuration. -->
  <sipappserver>
    <MonitorLoopbackPort value="10001"/>
    <!-- <TraceDirectory value="D:\SIP-Compiled-SVN\SIP-Test Environment\logs\siptraces"/> -->
    <TraceDirectory value="D:\SIP-Compiled-SVN\SIP-Operational\logs\siptraces"/>
    <RubyScriptCommonPath value="dialplan-common.rby"/>
    <OutboundProxy value=""/>
    <!-- <OutboundProxy value="192.168.0.5:5060"/> -->
    <DialPlanEngineImpersonationUsername value="xxxxxxxxxx" />
    <DialPlanEngineImpersonationPassword value="xxxxxxxxxx" />
    <sipsockets>
      <socket>192.168.0.5:5065</socket>
    </sipsockets>
  </sipappserver>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
proxyscript.py

Code: Select all

import clr
clr.AddReference('SIPSorcery.SIP.Core')
from SIPSorcery.SIP import *

m_registrarSocket = "udp:192.168.0.5:5001"
m_regAgentSocket = "udp:192.168.0.5:5002"
m_notifierSocket = "udp:192.168.0.5:5003"
m_appServerSocket = "udp:192.168.0.5:5065"
m_proxySocketInternal = "udp:192.168.0.5:5060"
m_proxySocketLoopback = "udp:192.168.0.5:5060"

  #===== Utility functions to customise depending on deployment, such as single or mutliple server and private or public network. =====

def GetAppServer():
  return m_appServerSocket

def IsFromApplicationServer():
  return remoteEndPoint.ToString() == m_appServerSocket

def IsFromNotifierServer():
  return remoteEndPoint.ToString() == m_notifierSocket

  # Determines if a destination IP address is on the same local subnet or whether it's 
# on an external network.
#def IsLocalNetDestination(SIPEndPoint destinationAddress) :
def IsLocalNetDestination(destinationEP) :
  if destinationEP.Address.ToString().StartsWith("192."):
    return True
  else:
    return False

  #===== End of customisable utility functions =====

  #===== General utility functions =====

# Attempts to send a SIP request to an external user agent by first resolving the destination for the 
# request and then checking whether it is on the same subnet.
#def SendExternalRequest(SIPEndPoint receivedOn, SIPRequest req, String proxyBranch, IPAddress publicIP, bool sendTransparently):
def SendExternalRequest(receivedOn, req, proxyBranch, publicIP, sendTransparently):  
  lookupResult = sys.Resolve(req)
  if lookupResult.Pending:
    # Do nothing.
    sys.Log("DNS lookup pending for " + req.URI.Host + ".")
  elif lookupResult.LookupError != None or lookupResult.EndPointResults == None or lookupResult.EndPointResults.Count == 0:
    if req.Method.ToString() != "ACK":
      sys.Respond(req, SIPResponseStatusCodesEnum.DoesNotExistAnywhere, "Host " + req.URI.Host + " unresolvable")
  else:
    dest = lookupResult.EndPointResults[0].LookupEndPoint    
    if IsLocalNetDestination(dest):
      #sys.Log("Request destination " + dest.ToString() + " determined as local network.")
      if sendTransparently:
        sys.SendTransparent(dest, req, None) 
      else:
        sys.SendExternal(receivedOn, dest, req, proxyBranch, None) 
    else:
      #sys.Log("Request destination " + dest.ToString() + " determined as external network.")
      if sendTransparently:
        sys.SendTransparent(dest, req, publicIP) 
      else:
        sys.SendExternal(receivedOn, dest, req, proxyBranch, publicIP)

#def SendExternalResponse(SIPResponse resp, SIPEndPoint sendFromSIPEndPoint, IPAddress publicIP):
def SendExternalResponse(resp, sendFromSIPEndPoint, publicIP):
  dest = sys.Resolve(resp)
  #sys.Log("SendExternalResponse desination resolved to " + dest.ToString() + ".")
  if dest == None:
    sys.Log("The destination could not be resolved for a SIP response.")
    sys.Log(resp.ToString())
  elif IsLocalNetDestination(dest):
    sys.SendExternal(resp, sendFromSIPEndPoint, None)
  else:
    sys.SendExternal(resp, sendFromSIPEndPoint, publicIP)

  #===== End of general utility functions =====


if isreq:
  
  #===== SIP Request Processing =====

  #sys.Log("req " + summary)
  req.Header.MaxForwards = req.Header.MaxForwards - 1

  if req.Header.UserAgent == "Cisco-CP7965G/8.5.3" or req.Header.UserAgent == "Cisco-CP7911G/8.5.3":
    req.Header.Vias.TopViaHeader.ViaParameters.Remove("rport")

  if sipMethod == "REGISTER":
    if remoteEndPoint.ToString() == m_regAgentSocket:
      # The registration agent has indicated where it wants the REGISTER request sent to by adding a Route header.
      # Remove the header in case it confuses the SIP Registrar the REGISTER is being sent to.
      route = req.Header.Routes.PopRoute()
      if route == None:
        sys.Log("Registration agent request was missing Route header.\n" + req.ToString())
      else:
        destRegistrar = route.ToSIPEndPoint()
        req.Header.Routes = None
        sys.SendTransparent(destRegistrar, req, publicip)
    else:
      sys.SendInternal(remoteEndPoint, localEndPoint, m_registrarSocket, req, proxyBranch, m_proxySocketLoopback)
    
  elif sipMethod == "SUBSCRIBE":
    sys.SendInternal(remoteEndPoint, localEndPoint, m_notifierSocket, req, proxyBranch, m_proxySocketLoopback)

  elif sipMethod == "NOTIFY":
    if IsFromApplicationServer() or IsFromNotifierServer():
      # Request from a SIP Application or Notification server for an external user agent.
      SendExternalRequest(localEndPoint, req, proxyBranch, publicip, False)
    else:
      if req.Header.Event != None and req.Header.Event.StartsWith("refer"):
        # REFER notification for app server.
        sys.SendInternal(remoteEndPoint, localEndPoint, GetAppServer().ToString(), req, proxyBranch, m_proxySocketInternal)
      else:
        # A notification from an external notification server.
        sys.SendInternal(remoteEndPoint, localEndPoint, m_notifierSocket, req, proxyBranch, m_proxySocketLoopback)
  
  else:
    # All other requests are processed by the Application Server.
    if IsFromApplicationServer():
      # Request from a SIP Application Server for an external user agent.
      if req.Method.ToString() == "ACK" or req.Method.ToString() == "CANCEL" or req.Method.ToString() == "INVITE":
        SendExternalRequest(None, req, None, publicip, True)
      else:
        SendExternalRequest(localEndPoint, req, proxyBranch, publicip, False)
    else:
      # Request from an external user agent for an Application Server.
      dispatcherEndPoint = sys.DispatcherLookup(req)
      if dispatcherEndPoint != None:
        sys.SendInternal(remoteEndPoint, localEndPoint, dispatcherEndPoint.ToString(), req, proxyBranch, m_proxySocketInternal)
      else:
        appServer = GetAppServer()
        if appServer != None:
          sys.SendInternal(remoteEndPoint, localEndPoint, appServer.ToString(), req, proxyBranch, m_proxySocketInternal)
        else:
          sys.Respond(req, SIPResponseStatusCodesEnum.BadGateway, "No sipsorcery app servers available")

  #===== End SIP Request Processing =====

else:

  #===== SIP Response Processing =====

  #sys.Log("resp " + summary)
 
  if sipMethod == "REGISTER" and remoteEndPoint.ToString() == m_registrarSocket:
    # REGISTER response from SIP Registrar.
    sys.SendExternal(resp, outSocket)

  elif sipMethod == "REGISTER":
    # REGISTER response for SIP Registration Agent.
    sys.SendTransparent(remoteEndPoint, localEndPoint, resp, SIPEndPoint.ParseSIPEndPoint(m_proxySocketLoopback), m_regAgentSocket, topVia.Branch)

  elif sipMethod == "NOTIFY" or sipMethod == "SUBSCRIBE":
    if not IsFromNotifierServer() and not IsFromApplicationServer():
      # Responses for SIP Notifier Server.
      sys.SendInternal(remoteEndPoint, localEndPoint, resp, outSocket)
    else:
      # Subscribe and notify responses for external user agents.
      SendExternalResponse(resp, outSocket, publicip)

  else: 
    if IsFromApplicationServer():
      # Response from an Application Server for an external UA.
      SendExternalResponse(resp, outSocket, publicip)
    else:
      # Responses from external UAs for SIP Application Servers.
      if resp.Header.CSeqMethod.ToString() == "ACK" or resp.Header.CSeqMethod.ToString() == "CANCEL" or resp.Header.CSeqMethod.ToString() == "INVITE":
        dispatcherEndPoint = sys.DispatcherLookup(resp)
        if dispatcherEndPoint == None:
          dispatcherEndPoint = GetAppServer()
        sys.SendTransparent(remoteEndPoint, localEndPoint, resp, SIPEndPoint.ParseSIPEndPoint(m_proxySocketInternal), dispatcherEndPoint, topVia.Branch)
      else:
        sys.SendInternal(remoteEndPoint, localEndPoint, resp, SIPEndPoint.ParseSIPEndPoint(m_proxySocketInternal))

  #===== End SIP Response Processing =====
Wireshark is running around the clock, but no traffic to those ports.

If you need any other info, please let me know.

Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Re: Asterisk notifications

Post by Nebukadnezar » Thu Sep 30, 2010 10:32 am

The SipMonitorEventWriter class creates an udpClient with no arguments, so it would have a default (random) port.
When I start my server, the console displays six occurrences of listeners created on port 10001. The following sources all instantiate the SipMonitorEventWriter class:

SIPProxyDaemon
SIPMonitorMediator
SIPRegistrarDaemon
SIPRegAgentDaemon
SIPNotifierDaemon
SIPAppServerDaemon

This would result in six random UDP ports. The fact that they do not show up immediately, could be caused by the fact that the events required (registration, DNS lookup etc) had not occurred before.
I am just a novice C# student and a noob on VOIP SIP technology; just thinking out loud.
It still does not explain how I end up with 24 unaccounted ports.
(should I remove all (but one) of these line "<MonitorLoopbackPort value="10001"/>" from sipsorcery-appsvr.exe.config?)

Aaron
Site Admin
Posts: 4652
Joined: Thu Jul 12, 2007 12:13 am

Re: Asterisk notifications

Post by Aaron » Thu Sep 30, 2010 10:44 am

Ah yes I knew I must have been forgetting something.

The monitoring sockets are used to send messages from each of the agents to the monitor server process which in turn gets checked by the SSH server and the notifications web service. More than likely you're not using either of those so you can remove all the MonitorLoopbackPort settings and see if that stops the zombie sockets.

Nebukadnezar
Posts: 47
Joined: Tue Aug 10, 2010 1:46 pm

Re: Asterisk notifications

Post by Nebukadnezar » Thu Sep 30, 2010 10:49 am

Just did; removed all of them except the one under <sipappserver> and its running now for about 10 minutes. The first registrations just came by and DNS resolver messages and no zombie ports sofar.

I will check later today if it stays this way and report the status.

Thanks.

Post Reply