in case I have a ISDN connection and as well as a SIP connection terminating on our CUBE/Voice gateway. In case of the SIP connection goes down, the client wants the calls be automatically routed via your ISDN line
Apart from the advice already given, it’s of importants that you’re client understands that you only have control of this for outbound calls. For inbound calls from PSTN it’s the service provider that controls this and it’s not very likely that they would have the ability to route the calls primarily via SIP and use the ISDN as backup. It’s at least nothing I’ve ever came across.
In addition to all the comments I also suggest reducing the SIP timers and retries under sip-ua. This is to prevent excessive delay is the SIP service goes down, before the Options Ping polling shuts down the dial peer. Default timers/retries would have it trying for something like 30 seconds. I normally use two retries and a reasonably short timer, the exact figure would depend on how quickly your provider normally responds. Remember the timer doubles on each retry, so this example would timeout after 1.75 seconds ..