#
# ALLNET.ITALIA - Patton BRI SmartWare
# Template per connessione di un centralino 1 o 2 BRI punto-multipunto
# ad un provider VoIP con singolo account (emulazione BRI)
# e ricerca automatica della prima BRI libera in entrata
#
# IP Patton 		192.168.1.100
# IP GW rete e DNS 	192.168.1.1
# IP Centralino 	res.sip.twt.it
#
# Configurazione provider VoIP
# Esempio con trunk TWT
#

cli version 3.20
clock local default-offset +01:00
clock local dst-rule DST_ON +02:00 from 02:00 mar last sunday until 03:00 oct last sunday
webserver port 80 language en
sntp-client
sntp-client server primary 0.patton.pool.ntp.org port 123 version 4
sntp-client server secondary 1.patton.pool.ntp.org port 123 version 4
dns-client server 192.168.1.1

system

  ic voice 0
    low-bitrate-codec g729

system
  clock-source 1 bri 0 0
  clock-source 2 bri 0 1

profile ppp default

profile call-progress-tone defaultAlertingtone
  play 1 1000 425 -12
  pause 2 4000
  play 3 1000 425 -12
  pause 4 4000
  
profile call-progress-tone defaultBusytone
  play 1 500 425 -12
  pause 2 500
  play 3 500 425 -12
  pause 4 500

profile call-progress-tone defaultDialtone
  play 1 200 425 -12
  pause 2 200
  play 3 600 425 -12
  pause 4 1000

profile call-progress-tone defaultReleasetone
  play 1 200 425 -12
  pause 2 200
  play 3 200 425 -12
  pause 4 200

profile tone-set default
  map call-progress-tone dial-tone defaultDialtone
  map call-progress-tone ringback-tone defaultAlertingtone
  map call-progress-tone busy-tone defaultBusytone
  map call-progress-tone congestion-tone defaultReleasetone
  map call-progress-tone release-tone defaultReleasetone

profile voip default
  codec 1 g711alaw64k rx-length 20 tx-length 20
  codec 2 g711ulaw64k rx-length 20 tx-length 20

profile pstn default

profile sip default
  no autonomous-transitioning

profile aaa default
  method 1 local
  method 2 none

context ip router

  interface WAN_STATIC
    ipaddress 192.168.1.100 255.255.255.0
    tcp adjust-mss rx mtu
    tcp adjust-mss tx mtu

context ip router

	route 0.0.0.0 0.0.0.0 192.168.1.1 0
	
context cs switch
  international-prefix 00

  mapping-table calling-e164 to calling-e164 MP_REM_PREFIX
    map 0039(.%) to \1

  mapping-table called-type-of-number to called-type-of-number MP_CDTON
    map default to national

  mapping-table called-numbering-plan to called-numbering-plan MP_CDNP
    map default to isdn-telephony

  mapping-table called-e164 to called-e164 MP_CDREM0
    map 0(.%) to \1

  complex-function CF_ISDN_ADAPT
    execute 1 MP_CDNP
    execute 2 MP_CDTON
    execute 3 MP_CDREM0
    execute 4 MP_REM_PREFIX

  service hunt-group HG_TO_ISDN
  route call 1 dest-interface IF_ISDN_0
  route call 2 dest-interface IF_ISDN_1
 
  routing-table calling-e164 RT_TO_ISDN
   route default dest-service HG_TO_ISDN CF_ISDN_ADAPT
  
  routing-table called-e164 RT_DIG_COL_TO_SIP
  route .T dest-interface IF_SIP_0

  interface isdn IF_ISDN_0
    route call dest-table RT_DIG_COL_TO_SIP
    call-reroute emit
    diversion emit
    caller-name
	isdn-date-time
    user-side-ringback-tone
	
  interface isdn IF_ISDN_1
    route call dest-table RT_DIG_COL_TO_SIP
    call-reroute emit
    diversion emit
    caller-name
	isdn-date-time
    user-side-ringback-tone

  interface sip IF_SIP_0
    bind context sip-gateway GW_5060
    route call dest-table RT_TO_ISDN
    remote res.sip.twt.it
    early-disconnect
    address-translation outgoing-call from-header user-part fix 50511231234 host-part fix res.sip.twt.it
	address-translation incoming-call called-e164 to-header


context cs switch
  no shutdown

authentication-service AS_SIP
  username 50511231234 password abcdef12345!

location-service LS_SIP
  domain 1 res.sip.twt.it

  identity 50511231234

    authentication outbound
      authenticate 1 authentication-service AS_SIP username 50511231234

    registration outbound
      registrar res.sip.twt.it
      lifetime 300
      register auto


context sip-gateway GW_5060

  interface IF_GW_5060
    bind interface WAN_STATIC context router port 5060

context sip-gateway GW_5060
  bind location-service LS_SIP
  no shutdown

port ethernet 0 0
  medium auto
  encapsulation ip
  bind interface WAN_STATIC router
  no shutdown

port bri 0 0
  clock auto
  encapsulation q921

  q921
    protocol pmp
    uni-side auto
    encapsulation q931

    q931
      protocol dss1
      uni-side net
      bchan-number-order ascending
      encapsulation cc-isdn
      bind interface IF_ISDN_0 switch

port bri 0 0
  no shutdown

port bri 0 1
  clock auto
  encapsulation q921

  q921
    protocol pmp
    uni-side auto
    encapsulation q931

    q931
      protocol dss1
      uni-side net
      bchan-number-order ascending
      encapsulation cc-isdn
      bind interface IF_ISDN_1 switch

port bri 0 1
  no shutdown