To avoid duplicating extensions in multiple FreeSWITCH servers, you can use OpenSIPS as a SIP proxy to handle call routing and distribution. OpenSIPS can be configured to load balance traffic to multiple FreeSWITCH servers and route calls based on specific criteria.
Here's an example configuration using OpenSIPS and FreeSWITCH:
OpenSIPS configuration:
# Define the FreeSWITCH servers
# Replace 192.168.1.10 and 192.168.1.11 with the IP addresses of your FreeSWITCH servers
dynamic_route("freeswitch", "load_balance") {
if (uri == "sip:extension@192.168.1.10") {
seturi("sip:extension@192.168.1.10");
t_on_failure("1");
} else if (uri == "sip:extension@192.168.1.11") {
seturi("sip:extension@192.168.1.11");
t_on_failure("1");
}
}
# Define the load balancing algorithm
load_balance {
# Replace 192.168.1.10 and 192.168.1.11 with the IP addresses of your FreeSWITCH servers
group("freeswitch", "hash");
# Define the hashing algorithm (e.g. "source", "destination", "random")
hash_load_factor("1");
}
FreeSWITCH Configuration:
# Define the extension
<extension name="extension">
<condition field="destination_number" expression="extension">
<action application="bridge" data="sofia/gateway/OpenSIPS/extension"/>
</condition>
</extension>
# Define the SIP gateway
<gateway name="OpenSIPS">
<param name="username" value="username"/>
<param name="password" value="password"/>
<param name="realm" value="opensips.example.com"/>
<param name="from-user" value="freeswitch"/>
<param name="from-domain" value="freeswitch.example.com"/>
<param name="expire-seconds" value="300"/>
<param name="retry-seconds" value="60"/>
<param name="register" value="true"/>
<param name="register-transport" value="udp"/>
<param name="register-proxy" value="opensips.example.com"/>
<param name="caller-id-in-from" value="true"/>
</gateway>
In this configuration, OpenSIPS is configured to load balance traffic to two FreeSWITCH servers with IP addresses 192.168.1.10 and 192.168.1.11. The load balancing algorithm uses a hashing algorithm to evenly distribute traffic between the servers.
The FreeSWITCH configuration defines an extension that bridges the call to the OpenSIPS gateway using the SIP URI "sofia/gateway/OpenSIPS/extension". The OpenSIPS gateway is configured with the necessary SIP credentials and registration information.
With this configuration, you can define extensions in the FreeSWITCH configuration without having to duplicate them across multiple FreeSWITCH servers. OpenSIPS handles call routing and distribution, ensuring that calls are routed to the appropriate server based on the load balancing algorithm.