#
# ALLNET.ITALIA - Patton FXS Trinity
# Template per generazione di 4 linee analogiche
# a partire da un centralino VoIP con 4 account (emulazione FXS)
# separati per FXS (routing mediante routing-table)
#
# IP Patton 		192.168.1.100
# IP GW rete e DNS 	192.168.1.1
# IP Centralino 	192.168.1.50
#
# Esempio con centralino VoIP (interni 270:273)
#

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

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 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

context cs SWITCH
  national-prefix 0
  international-prefix 00

  routing-table called-e164 RT_DIG_COL_TO_SIP
    route .T dest-interface IF_SIP_0
	
  routing-table called-e164 SIP_TO_FXS
    route 270 dest-interface IF_FXS_0
	route 271 dest-interface IF_FXS_1
	route 272 dest-interface IF_FXS_2
	route 273 dest-interface IF_FXS_3

  interface fxs IF_FXS_0
    route call dest-table RT_DIG_COL_TO_SIP
	
  interface fxs IF_FXS_1
    route call dest-table RT_DIG_COL_TO_SIP
	
  interface fxs IF_FXS_2
    route call dest-table RT_DIG_COL_TO_SIP

  interface fxs IF_FXS_3
    route call dest-table RT_DIG_COL_TO_SIP

  interface sip IF_SIP_0
    bind context sip-gateway GW_5060
    route call dest-table SIP_TO_FXS
    remote 192.168.1.50 5060
    early-disconnect
    address-translation outgoing-call from-header user-part call host-part fix 192.168.1.50

context cs SWITCH
  no shutdown

authentication-service AS_SIP
  username 270 password Cambiami2021!
  username 271 password Cambiami2021!
  username 272 password Cambiami2021!
  username 273 password Cambiami2021!

location-service LS_SIP
  domain 1 192.168.1.50
  match-any-domain

  identity-group DEFAULT

    registration outbound
      registrar 192.168.1.50 5060
      lifetime 3600
      register auto
	  
  identity 270 inherits DEFAULT
  
    authentication outbound
      authenticate 1 authentication-service AS_SIP username 270
	  
  identity 271 inherits DEFAULT
  
    authentication outbound
      authenticate 1 authentication-service AS_SIP username 271
	  
  identity 272 inherits DEFAULT
  
    authentication outbound
      authenticate 1 authentication-service AS_SIP username 272
	  
  identity 273 inherits DEFAULT
  
    authentication outbound
      authenticate 1 authentication-service AS_SIP username 273

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

port ethernet 0 0
  bind interface ROUTER WAN
  no shutdown

port fxs 0 0  
  subscriber-number 270
  bind interface SWITCH IF_FXS_0
  no shutdown

port fxs 0 1
  
  subscriber-number 271
  bind interface SWITCH IF_FXS_1
  no shutdown

port fxs 0 2
  subscriber-number 272
  bind interface SWITCH IF_FXS_2
  no shutdown

port fxs 0 3
  
  subscriber-number 273
  bind interface SWITCH IF_FXS_3
  no shutdown
