Automatic OSPF cost change after bandwidth test

hello all,

I recently found this script in MT documentation:

/system script add name=bandtest source={
:global i
/tool bandwidth-test 10.122.255.4
direction=transmit
duration=14s
do={
:if ($status=“running”) do={
:set i $tx-current
}
}
}

Lets say that 10.122.255.4 is a wireless interface on a direct connected MT router.
Lets say also that we use the following table for OSPF cost calculation:

Link speed		OSPF COST
108	mbps	6
100	mbps	7
54	mbps	13
48	mbps	15
36	mbps	19
24	mbps	29
22	mbps	32
18	mbps	39
12	mbps	58
11	mbps	64
9	mbps	78
6	mbps	117
5,5	mbps	127
2	mbps	350
1	mbps	700

So we have to compare the script result to the values of the table and if for example bw-test reports 21.3 mbps adjust the OSPF cost on this interface to the nearest lower one (in this example 18mbps with cost 39).

how ? :laughing:
Can the ScriptMonsters help ?

This is very important to our local community wireless network… We have MT routers with 2-3 or 4 wireless interfaces, so, proper ospf costs which are adjusted dynamically is essential…

You just have to change this script - adding a lot of IF/Else statements:


/system script add name=bandtest source={
:global i
/tool bandwidth-test 10.122.255.4
direction=transmit
duration=14s
do={
:if ($status=“running”) do={
:set i $tx-current
}
}
/routing ospf {
:if ($i>100) do={set metric-static=6}
else={:if ($i>54) do={set metric-static=7}
else={:if ($i>48) do={set metric-static=13}

}
}
}
}

something like this.

Edgars

just one note - you will NEVER get reliable results from such throughput tests. You are influenced by too many factors you don’t, can’t and won’t take into consideration : momentary intereference in air, cpu/system utilization with radio, amount of viruses your clients have and their activity, bandwidth your customers are using etc. The list goes on. I wouldn’t do this - you have to know your network and based on this, you can set up and REVISE this finding let’s say once a week, once a month or depending to your needs. I wouldn’t let any script do this, besides I don’t have such a script :slight_smile:

bye, mp3turbo.

We are adding statistics that will give the info you want. They are primarilly for Nstreme, but they will also be shown for 802.11

John

is there any way to add a log entry in the above script ?

for example “Setting ospf cost to $i” ?

:log message=(“Setting ospf cost to” . $i)

Edgars

hello all,

I recently found this script in MT documentation:

/system script add name=bandtest source={
:global i
/tool bandwidth-test 10.122.255.4
direction=transmit
duration=14s
do={
:if ($status=“running”) do={
:set i $tx-current
}
}
}

Lets say that 10.122.255.4 is a wireless interface on a direct connected MT router.
Lets say also that we use the following table for OSPF cost calculation:
Code:

Link speed OSPF COST
108 mbps 6
100 mbps 7
54 mbps 13
48 mbps 15
36 mbps 19
24 mbps 29
22 mbps 32
18 mbps 39
12 mbps 58
11 mbps 64
9 mbps 78
6 mbps 117
5,5 mbps 127
2 mbps 350
1 mbps 700



So we have to compare the script result to the values of the table and if for example bw-test reports 21.3 mbps adjust the OSPF cost on this interface to the nearest lower one (in this example 18mbps with cost 39).

how ?
Can the ScriptMonsters help ?

This is very important to our local community wireless network… We have MT routers with 2-3 or 4 wireless interfaces, so, proper ospf costs which are adjusted dynamically is essential…

you should try something like this my friend

:global h
/tool 
bandwidth-test wireless_mikrotik_ip_address user=yourusername password=yourpassword direction=transmit protocol=tcp duration=30s do={:if ($status="running") do={:set h $tx-total-average}}
/ routing ospf interface
:if ($h<108000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=6 }
:if ($h<100000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=7 }
:if ($h<54000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=13 }
:if ($h<48000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=15 }
:if ($h<36000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=19 }
:if ($h<24000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=29 }
:if ($h<22000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=32 }
:if ($h<18000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=39 }
:if ($h<12000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=58 }
:if ($h<11000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=64 }
:if ($h<9000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=78 }
:if ($h<6000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=117 }
:if ($h<5500000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=127 }
:if ($h<2000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=350 }
:if ($h<1000000) do={set	[/ routing ospf interface find interface "your_interface_NAME"] cost=700 }

and replace these:
wireless_mikrotik_ip_address
yourusername
yourpassword
your_interface_NAME

hehe