Failover and load blancing using mwan3 package

Greetings everyone!

I'm currently involved in a project with OpenWRT, and my main objectives are to establish failover and load balancing functionalities. So far, I've been able to implement both features separately. I have a fiber connection and a cellular connection, and my primary goal is to achieve redundancy by enabling automatic failover from fiber to cellular whenever the fiber connection becomes unavailable.

In addition to failover, I also want to implement load balancing for users connected to the LAN network of OpenWRT. This means that different users should be able to utilize different paths for their traffic, with some users being directed through the fiber connection and others through the cellular connection.

In the event of a fiber connection failure, all users should automatically switch to the cellular connection, and vice versa, ensuring continuous and reliable internet access.

Unfortunately, at the moment, when the fiber connection fails, the users connected to it do not seamlessly fallback to the cellular connection, leading to the failure of the overall failover mechanism.

If anyone has experience or expertise in OpenWRT configurations and can offer guidance on how to achieve seamless integration of failover and load balancing, I would greatly appreciate your insights and assistance!

root@OpenWrt:/etc/config# cat network 

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd11:fb67:2772::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option netmask '255.255.255.0'
        option ipaddr '192.168.90.1'
        option delegate '0'

config interface 'wan'
        option device 'eth1'
        option proto 'static'
        option ipaddr '192.168.100.236'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        option metric '2'

config interface 'wan6'
        option device 'eth1'
        option proto 'dhcpv6'
        option auto '0'
        option reqaddress 'try'
        option reqprefix 'auto'
        option defaultroute '0'

config interface 'wan2'
        option proto 'static'
        option device 'eth2'
        option ipaddr '192.168.80.10'
        option netmask '255.255.255.0'
        option gateway '192.168.80.1'
        option metric '1'

config route
        option interface 'wan2'
        option target '0.0.0.0/0'
        option gateway '192.168.80.1'

config interface 'wan2_ip'
        option proto 'static'
        option device 'eth2'
root@OpenWrt:/etc/config# cat mwan3

config globals 'globals'
        option mmx_mask '0x3F00'

config interface 'wan'
        option enabled '1'
        option initial_state 'online'
        option family 'ipv4'
        option track_method 'ping'
        option reliability '1'
        option count '1'
        option size '56'
        option max_ttl '60'
        option timeout '4'
        option interval '10'
        option failure_interval '5'
        option recovery_interval '5'
        option down '5'
        option up '5'
        list track_ip '8.8.8.8'
        list track_ip '1.1.1.1'

config interface 'wan2'
        option enabled '1'
        option initial_state 'online'
        option family 'ipv4'
        option track_method 'ping'
        option reliability '1'
        option count '1'
        option size '56'
        option max_ttl '60'
        option timeout '4'
        option interval '10'
        option failure_interval '5'
        option recovery_interval '5'
        option down '5'
        option up '5'
        list track_ip '8.8.8.8'
        list track_ip '1.1.1.1'

config member 'wan_cellular'
        option interface 'wan'
        option weight '1'
        option metric '2'

config member 'wan_fiber'
        option interface 'wan2'
        option metric '1'
        option weight '1'

config policy 'Load_balance'
        list use_member 'wan_cellular'
        list use_member 'wan_fiber'
        option last_resort 'default'

config policy 'wan_only'
        list use_member 'wan_cellular'
        option last_resort 'wan_fallback'

config policy 'wan2_only'
        list use_member 'wan_fiber'
        option last_resort 'wan2_fallback'

config policy 'wan_fallback'
        list use_member 'wan_fiber'
        option last_resort 'default'

config policy 'wan2_fallback'
        list use_member 'wan_cellular'
        option last_resort 'default'

config rule 'company_laptop'
        option src_ip '192.168.90.5'
        option family 'ipv4'
        option proto 'all'
        option sticky '0'
        option use_policy 'wan2_only'

config rule 'my_laptop'
        option src_ip '192.168.90.6'
        option family 'ipv4'
        option proto 'all'
        option sticky '0'
        option use_policy 'wan_only'

config rule 'https'
        option sticky '1'
        option use_policy 'Load_balance'
        option proto 'all'

config rule 'default_rule_v4'
        option dest_ip '0.0.0.0/0'
        option use_policy 'balanced'
        option family 'ipv4'

config rule 'default_rule_v6'
        option dest_ip '::/0'
        option use_policy 'balanced'
        option family 'ipv6'

Any kind of lead would be very helpful!

Remove this from /etc/config/network/.

For load balancing, both members must have the same metric. This policy is currently wan2_to_wan.

These are not valid values for the last_resort option. Consult the guide.

This rule is intended to be used for https traffic only. After your changes, it covers everything. Remove it or use the default one.

Here are some examples:

config globals 'globals'
        option mmx_mask '0x3F00'

config interface 'wan'
		...
		
config interface 'wan2'
		...		

config member 'wan_m1_w1'
        option interface 'wan'
        option metric '1'
		option weight '1'

config member 'wan2_m1_w1'
        option interface 'wan2'
        option metric '1'
        option weight '1'
		
config member 'wan_m2_w1'
        option interface 'wan'
        option metric '2'
        option weight '1'

config member 'wan2_m2_w1'
        option interface 'wan2'
        option metric '2'
        option weight '1'

config policy 'balanced'
        list use_member 'wan_m1_w1'
        list use_member 'wan2_m1_w1'
        
config policy 'wan_to_wan2'
        list use_member 'wan_m1_w1'
        list use_member 'wan2_m2_w1'
		
config policy 'wan2_to_wan'
        list use_member 'wan_m2_w1'
        list use_member 'wan2_m1_w1'

config policy 'wan_only'
        list use_member 'wan_m1_w1'
        option last_resort 'default'

config policy 'wan2_only'
        list use_member 'wan2_m1_w1'
        option last_resort 'default'

config rule 'company_laptop'
        option src_ip '192.168.90.5'
        option family 'ipv4'
        option use_policy 'wan2_only'

config rule 'my_laptop'
        option src_ip '192.168.90.6'
        option family 'ipv4'
        option use_policy 'wan_only'

config rule 'default_rule_v4'
        option dest_ip '0.0.0.0/0'
        option use_policy 'balanced'
        option family 'ipv4'
1 Like
config member 'wan_cellular'
        option interface 'wan'
        option weight '1'
        option metric '2'

config member 'wan_fiber'
        option interface 'wan2'
        option metric '1'
        option weight '1

The metrics are not the same because I want to achieve failover.

config policy 'wan_only'
        list use_member 'wan_cellular'
        option last_resort 'wan_fallback'

config policy 'wan2_only'
        list use_member 'wan_fiber'
        option last_resort 'wan2_fallback'

The intention of giving last resort wan2_fallback and wan_fallback is that when one of the interfaces is not available, it should take the other interface.

config policy 'wan_fallback'
        list use_member 'wan_fiber'
        option last_resort 'default'

config policy 'wan2_fallback'
        list use_member 'wan_cellular'
        option last_resort 'default'

Below works for me for Load-balancing + Failover [I think failover is anyway implied]

Basically same metric for failover to work.
The usage ratio intended is 1:1, hence the same weights too.

config member 'wan_m1_w3'
	option interface 'wan'
	option metric '1'
	option weight '3'

config member 'wwan_m1_w3'
	option interface 'wwan'
	option metric '1'
	option weight '3'

config policy 'balanced'
	list use_member 'wan_m1_w3'
	list use_member 'wwan_m1_w3'

config rule 'default_rule'
	option dest_ip '0.0.0.0/0'
	option use_policy 'balanced'

Thank you for your response.
But I was trying to achieve load balancing based on the number of users connected to the interface.
As in, there are two interfaces: 1. fiber; 2. cellular

The LAN network is in 192.168.90.0
I wanted user 1 with this IP : 192.168.90.2, to route their traffic through fiber and
User2 with IP: 192.168.90.3 to route traffic through cellular

Also, to get redundancy, in case the fiber connection fails, user 1 should be able to route the traffic through cellular. This is what I want to achieve.

The wan1_fallback and wan2_fallback policies are given for this purpose, but unfortunately, they aren't working as intended.

thanks for your input!