Round robin on mwan3

mwan3 default behavior is to keep using the same WAN when new TCP connections are made for the same destination IP, until timeout is reached, then it randomly chooses what WAN to route the new connection.

Is it possible to create a rule so that, when timeout is reached and a new connection is made, it tries to avoid using the same WAN and gives preference to another WAN?

I have a Ookla Speedtest monitor running on my server, and it keeps using the same WAN repeatedly over hours, even with different sponsors being chosen. My guess is that Speedtest tests latency and somehow keeps choosing the same route it had chosen before.

I wanna make it more varied. I tried setting preferred WANs for some sponsors IPs and it worked, but then I get these sponsors always measuring a unique WAN. I'd like to make mwan3 force connections to use different route than previous period, instead of forcing to use the same as before.

Your best chance is to disable sticky, if enabled, by default it is disabled, and use same metric among the member interfaces. I don't think it can remember which connection was used previously. If many lan hosts are accessing the uplinks, then A might use uplink-a then B will use uplink-b and the second time A tries to open a connection it will be the turn of uplink-a again to be used. I suppose this can be worked around by having a rule that will catch only one lan host.

1 Like

Is it possible to set mwan3 rules from uci? I tried to move a rule to mwan3.user but it fails, it seems the file uses different format from main one.

If I can set rules from uci, I could write a program in python to dynamically add or remove a few rules based on latest speedtest measures then restart mwan3. When some ISP has few measures, I add a rule setting a sponsor IP to only be reached by that ISP, and on server I force that sponsor to be used, then I'll be able to force a few measures on that ISP.

In example, how would I set this rule using uci?

config rule 'spt_wan'
	option proto 'all'
	option sticky '1'
	option timeout '120'
	option use_policy 'wan_only'
	option dest_ip '131.108.88.35'

if not, is there any config to include other config file where more rules are set? Then I could rewrite that file and restart.

I did it. I had to delete and reset default_rule, otherwise it preceeds the Speedtest rule. In case somebody is interested:

#!/usr/bin/python

import subprocess
import requests
import datetime
import urllib3
import random
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

import os
import json
from types import SimpleNamespace

import locale
locale.setlocale(locale.LC_NUMERIC, 'pt_BR.UTF-8')



shortage = requests.get("https://myserver.lan/mon/view/ws/readSpeedtestShortage.php", headers = {'content-type' : 'application/json'}, verify=False);
print("Response raw:",shortage.text);

shortage = json.loads(shortage.text, object_hook=lambda d: SimpleNamespace(**d));
#print("jsonified:",shortage);
print("Response:",shortage.response);


#https://stackoverflow.com/questions/3730964/python-script-execute-commands-in-terminal
os.system("uci delete mwan3.spt_shortage");
os.system("uci delete mwan3.default_rule");


if(shortage.userMessages.error==False and shortage.response):
	os.system("uci set mwan3.spt_shortage=rule");
	os.system("uci set mwan3.spt_shortage.proto='all'");
	os.system("uci set mwan3.spt_shortage.sticky='1'");
	os.system("uci set mwan3.spt_shortage.timeout='600'");
	os.system("uci set mwan3.spt_shortage.dest_ip='131.108.88.35'");
	
	if("Telefk"==shortage.response):
		os.system("uci set mwan3.spt_shortage.use_policy='wan_only'");
		print("wan_only");
	elif("MERD"==shortage.response):
		os.system("uci set mwan3.spt_shortage.use_policy='wanb_only'");
		print("wanb_only");
	elif("EXS"==shortage.response):
		os.system("uci set mwan3.spt_shortage.use_policy='wanc_only'");
		print("wanc_only");


os.system("uci set mwan3.default_rule=rule");
os.system("uci set mwan3.default_rule.proto='all'");
os.system("uci set mwan3.default_rule.sticky='1'");
os.system("uci set mwan3.default_rule.timeout='120'");
os.system("uci set mwan3.default_rule.dest_ip='0.0.0.0/0'");
os.system("uci set mwan3.default_rule.use_policy='balanced'");

os.system("uci commit");
os.system("mwan3 restart");

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.