This is the first revision of my automated bandwidth testing script. It will run 4 sequential tests, TCP downstream, TCP upstream, UDP downstream, and UDP upstream. You may configure the duration for each test by protocol. You may also configure the RX and TX packet sizes for UDP tests. Depending on how your network is setup, you may have to tweak the beginning of the script to obtain the btest server address. It is currently setup to use the gateway address of the default route.
Once all tests have been completed, the results are logged to the system logging facility. From there it is up to you how you want to aggregate the information. We use syslog servers for message convergence which seems to be the most ideal for us so far. A basic way to get started with it would be to use the scheduler feature to schedule an execution of this script.
Be cautious of your scheduling strategy! It’s important to remember that these tests can often saturate an Ethernet link depending on it’s capacity and the testing equipment capabilities.
I am going to use this for automated testing of a fixed wireless network in the big picture. My next revision will have a scheduling component to offset these tests across a network automatically to prevent excessive link saturation and skewed test results. Let me know if you’re interested and I’ll be sure to share it’s progress back.
{
:local timestampLabel "$[/system clock get date] $[/system clock get time]"
:local routeID [/ip route find dst-address=0.0.0.0/0]
# BTest Server Settings
:local btestServer { username="btest" ; password="Ek4@C;f%(-(P3+~5" ; hostname=[/ip route get $routeID value-name=gateway] }
# TCP Test Settings
:local tcpOptions { duration="5s" ; "updateInterval"="1s" }
# UDP Test Settings
:local udpOptions { duration="5s" ; "updateInterval"="1s" ; "rxSize"=1000 ; "txSize"=1000 }
# Test Results
:local tcpRxTest { start="" ; updated="" ; end="" ; peak=0 ; current=0 ; average=0 ; "lostPackets"=0 ; size=0 }
:local tcpTxTest { start="" ; updated="" ; end="" ; peak=0 ; current=0 ; average=0 ; "lostPackets"=0 ; size=0 }
:local udpRxTest { start="" ; updated="" ; end="" ; peak=0 ; current=0 ; average=0 ; "lostPackets"=0 ; size=0 }
:local udpTxTest { start="" ; updated="" ; end="" ; peak=0 ; current=0 ; average=0 ; "lostPackets"=0 ; size=0 }
# TCP Downstream Test
:set ($tcpRxTest->"start") "$[/system clock get date] $[/system clock get time]"
/tool bandwidth-test ($btestServer->"hostname") protocol=tcp random-data=no direction=receive duration=($tcpOptions->"duration") user=($btestServer->"username") password=($btestServer->"password") do={
:set ($tcpRxTest->"updated") "$[/system clock get date] $[/system clock get time]"
:set ($tcpRxTest->"current") ($"rx-current" / 1000000)
:set ($tcpRxTest->"average") ($"rx-total-average" / 1000000)
:set ($tcpRxTest->"lostPackets") ($"lost-packets" / 1)
:set ($tcpRxTest->"size") ($"rx-size" / 1)
:if ( ($tcpRxTest->"peak") < ($tcpRxTest->"current") ) do={
:set ($tcpRxTest->"peak") ($tcpRxTest->"current")
}
}
:set ($tcpRxTest->"end") "$[/system clock get date] $[/system clock get time]"
# TCP Upstream Test
:set ($tcpTxTest->"start") "$[/system clock get date] $[/system clock get time]"
/tool bandwidth-test ($btestServer->"hostname") protocol=tcp random-data=no direction=transmit duration=($tcpOptions->"duration") user=($btestServer->"username") password=($btestServer->"password") do={
:set ($tcpTxTest->"updated") "$[/system clock get date] $[/system clock get time]"
:set ($tcpTxTest->"current") ($"tx-current" / 1000000)
:set ($tcpTxTest->"average") ($"tx-total-average" / 1000000)
:set ($tcpTxTest->"lostPackets") ($"lost-packets" / 1)
:set ($tcpTxTest->"size") ($"tx-size" / 1)
:if ( ($tcpTxTest->"peak") < ($tcpTxTest->"current") ) do={
:set ($tcpTxTest->"peak") ($tcpTxTest->"current")
}
}
:set ($tcpTxTest->"end") "$[/system clock get date] $[/system clock get time]"
# UDP Downstream Test
:set ($udpRxTest->"start") "$[/system clock get date] $[/system clock get time]"
/tool bandwidth-test ($btestServer->"hostname") protocol=udp random-data=no direction=receive duration=($udpOptions->"duration") user=($btestServer->"username") password=($btestServer->"password") remote-udp-tx-size=($udpOptions->"rxSize") do={
:set ($udpRxTest->"updated") "$[/system clock get date] $[/system clock get time]"
:set ($udpRxTest->"current") ($"rx-current" / 1000000)
:set ($udpRxTest->"average") ($"rx-total-average" / 1000000)
:set ($udpRxTest->"lostPackets") ($"lost-packets" / 1)
:set ($udpRxTest->"size") ($"rx-size" / 1)
:if ( ($udpRxTest->"peak") < ($udpRxTest->"current") ) do={
:set ($udpRxTest->"peak") ($udpRxTest->"current")
}
}
:set ($udpRxTest->"end") "$[/system clock get date] $[/system clock get time]"
# UDP Upstream Test
:set ($udpTxTest->"start") "$[/system clock get date] $[/system clock get time]"
/tool bandwidth-test ($btestServer->"hostname") protocol=udp random-data=no direction=transmit duration=($udpOptions->"duration") user=($btestServer->"username") password=($btestServer->"password") local-udp-tx-size=($udpOptions->"txSize") do={
:set ($udpTxTest->"updated") "$[/system clock get date] $[/system clock get time]"
:set ($udpTxTest->"current") ($"tx-current" / 1000000)
:set ($udpTxTest->"average") ($"tx-total-average" / 1000000)
:set ($udpTxTest->"lostPackets") ($"lost-packets" / 1)
:set ($udpTxTest->"size") ($"tx-size" / 1)
:if ( ($udpTxTest->"peak") < ($udpTxTest->"current") ) do={
:set ($udpTxTest->"peak") ($udpTxTest->"current")
}
}
:set ($udpTxTest->"end") "$[/system clock get date] $[/system clock get time]"
# Report results via system log facility, syslog aggregation will handle the rest
# Log TCP Test Results
:log info ("Bandwidth test of TCP Downstream; Started: " . ($tcpRxTest->"start") . "; Completed: " . ($tcpRxTest->"end") . "; Server: " . ($btestServer->"hostname") . "; Peak: " . ($tcpRxTest->"peak") . " Mbps; Average: " . ($tcpRxTest->"average") . " Mbps; Duration: " . ($tcpOptions->"duration") . ";")
:log info ("Bandwidth test of TCP Upstream; Started: " . ($tcpTxTest->"start") . "; Completed: " . ($tcpTxTest->"end") . "; Server: " . ($btestServer->"hostname") . "; Peak: " . ($tcpTxTest->"peak") . " Mbps; Average: " . ($tcpTxTest->"average") . " Mbps; Duration: " . ($tcpOptions->"duration") . ";")
# Log UDP Test Results
:log info ("Bandwidth test of UDP Downstream; Started: " . ($udpRxTest->"start") . "; Completed: " . ($udpRxTest->"end") . "; Server: " . ($btestServer->"hostname") . "; Peak: " . ($udpRxTest->"peak") . " Mbps; Average: " . ($udpRxTest->"average") . " Mbps; Packet Size: " . ($udpRxTest->"size") . "; Duration: " . ($udpOptions->"duration") . "; Lost Packets: " . ($udpRxTest->"lostPackets") . ";")
:log info ("Bandwidth test of UDP Upstream; Started: " . ($udpTxTest->"start") . "; Completed: " . ($udpTxTest->"end") . "; Server: " . ($btestServer->"hostname") . "; Peak: " . ($udpTxTest->"peak") . " Mbps; Average: " . ($udpTxTest->"average") . " Mbps; Packet Size: " . ($udpTxTest->"size") . "; Duration: " . ($udpOptions->"duration") . ";")
}