#
# ALLNET.ITALIA - Patton BRI Trinity
# Template per connessione di un centralino 4 BRI punto-multipunto
# ad un provider VoIP con singolo account (emulazione BRI) in Selezione Passante
# 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 	192.168.1.50
#
# Configurazione provider VoIP
# Esempio con trunk Eutelia
#

cli version 4.00
clock local default-offset +01:00
clock local dst-rule DST_ON +01:00 from mar last sunday 02:00 2000 until oct last sunday 03:00 2036

profile aaa DEFAULT
  method 1 local
  method 2 none

console
  use profile aaa DEFAULT

telnet-server
  use profile aaa DEFAULT
  no shutdown

ssh-server
  use profile aaa DEFAULT
  no shutdown

snmp-server
  shutdown

web-server
  protocol http port 80
  no protocol https
  use profile aaa DEFAULT
  no shutdown

ntp
  server 0.patton.pool.ntp.org
  server 1.patton.pool.ntp.org
  server 2.patton.pool.ntp.org
  server 3.patton.pool.ntp.org
  no shutdown

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

dns-server
  relay dns-client
  shutdown

dns-client
  name-server 192.168.1.1

profile tls DEFAULT
  no authentication incoming
  no authentication outgoing
  private-key pki:private-key/DEFAULT
  own-certificate 1 pki:certificate/DEFAULT

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

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

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

profile tone-set DEFAULT

profile voip DEFAULT
  codec 1 g711alaw64k rx-length 20 tx-length 20
  codec 2 g711ulaw64k rx-length 20 tx-length 20
  codec 3 g729 rx-length 20 tx-length 20
  fax transmission 1 relay t38-udp
  fax transmission 2 bypass g711alaw64k rx-length 20 tx-length 20

profile pstn DEFAULT

profile rip DEFAULT

profile sip DEFAULT

context ip ROUTER

  interface WAN
    ipaddress WAN_STATIC 192.168.1.100/24
    accept default-route routing-table DEFAULT

  routing-table DEFAULT
    route 0.0.0.0/0 gateway 192.168.1.1 metric 0

  bgp
    shutdown

  rip
    shutdown

nodems-client
  server auto-discover
  resource any
  shutdown

profile ppp DEFAULT

cwmp-client
  shutdown

  stun
    shutdown

context cs SWITCH
  national-prefix 0
  international-prefix 00
  
# MP_CG_REM_PREFIX	Rimuove il previsso 0039 dal numero chiamante se presente
# MP_CDNP			Mappa in isdn-telephony / E.164 il numbering plan del numero chiamato (DID)
# MP_CD_REM_PREFIX	Rimuove i prefissi 0039 / 00390 / 0 / 50 dal numero chiamato (DID) se presenti
# MP_CDTON			Mappa su national il type of number del numero chiamato (DID)
  
  mapping-table calling-e164 to calling-e164 MP_CG_REM_PREFIX
    map 0039(.%) to \1

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

  mapping-table called-e164 to called-e164 MP_CD_REM_PREFIX
	map 00390(.%) to \1
	map 0(.%) to \1
	map 50(.%) to \1

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

  routing-table called-e164 RT_DIG_COL_TO_SIP
    route .T dest-interface IF_SIP_0
	
  routing-table called-e164 RT_TO_ISDN
    route default dest-service HG_TO_ISDN CF_ISDN_ADAPT
	
  complex-function CF_ISDN_ADAPT
    execute 1 MP_CDNP
    execute 2 MP_CDTON
    execute 3 MP_CD_REM_PREFIX
    execute 4 MP_CG_REM_PREFIX

  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 isdn IF_ISDN_2
    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_3
    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 voip.eutelia.it
    early-disconnect
    address-translation outgoing-call from-header user-part call host-part fix voip.eutelia.it
	address-translation incoming-call called-e164 to-header

  service hunt-group HG_TO_ISDN
    drop-cause normal-unspecified
    drop-cause no-circuit-channel-available
    drop-cause network-out-of-order
    drop-cause temporary-failure
    drop-cause switching-equipment-congestion
    drop-cause access-info-discarded
    drop-cause circuit-channel-not-available
    drop-cause resources-unavailable
    route call 1 dest-interface IF_ISDN_0
    route call 2 dest-interface IF_ISDN_1
	route call 3 dest-interface IF_ISDN_2
	route call 4 dest-interface IF_ISDN_3

context cs SWITCH
  no shutdown

authentication-service AS_SIP
  username 051112300 password abcdef12345!

location-service LS_SIP
  domain 1 voip.eutelia.it
  match-any-domain

  identity 051112300
	alias range 051112300 051112399

    authentication outbound
      authenticate 1 authentication-service AS_SIP username 051112300

    registration outbound
      registrar voip.eutelia.it
      lifetime 3600
      register auto

context sip-gateway GW_5060
  bind location-service LS_SIP

  interface IF_GW_5060
    transport-protocol udp+tcp 5060
    no transport-protocol tls
    bind ipaddress ROUTER WAN WAN_STATIC

context sip-gateway GW_5060
  no shutdown

sip-survivability
  shutdown

port ethernet 0 0
  bind interface ROUTER WAN
  no shutdown

port bri 0 0

  q921
    protocol pmp
    uni-side auto

    q931
      protocol dss1
      uni-side net
      max-calls 2
      channel-range 0 1
      bind interface SWITCH IF_ISDN_0

port bri 0 0
  no shutdown

port bri 0 1

  q921
    protocol pmp
    uni-side auto

    q931
      protocol dss1
      uni-side net
      max-calls 2
      channel-range 0 1
      bind interface SWITCH IF_ISDN_1

port bri 0 1
  no shutdown

port bri 0 2

  q921
    protocol pmp
    uni-side auto

    q931
      protocol dss1
      uni-side net
      max-calls 2
      channel-range 0 1
      bind interface SWITCH IF_ISDN_2

port bri 0 2
  no shutdown
  

port bri 0 3

  q921
    protocol pmp
    uni-side auto

    q931
      protocol dss1
      uni-side net
      max-calls 2
      channel-range 0 1
      bind interface SWITCH IF_ISDN_3

port bri 0 3
  no shutdown

