Bandwidth Management
My need for bandwidth management (aka Traffic Shaping) is a result of my desire to live in the countryside. Low population means little incentive for commercial companies to install fibre. No fibre means slow broadband over a piece of overhead wire installed in the 1970s.
I found various articles about traffic shaping on Mikrotik routers but few of them seemed to describe my scenario, although I’m fairly confident that my scenario is common to the majority of people who want to manage their bandwidth!
The scenario
I have a Routerboard with multiple Ethernet ports. The ports all run at 1Gb/s except the one facing my Openreach modem that runs at 100Mb/s. That’s more than adequate as my Internet connection peaks at around 25Mb/s. I want traffic between interfaces to be unregulated, except for traffic coming from the Internet. I also don’t want to restrict (cap) the bandwidth from the Internet to any particular interface or protocol. I just want to give priority to some traffic at busy times.
Packet Tagging
The overall bandwidth management exercise can be broken down into two sections: Packet Tagging and Queue Management. Packet Tagging is concerned with identifying the traffic. Lets start by putting a rule in place to measure the traffic coming off the Internet interface. From now on I’m going to call this interface AAISP because that’s the name I use for it.
/ip firewall mangle
add chain=forward action=passthrough in-interface=AAISP
The above rule does nothing to the incoming packets. It simply enables some stats gathering of traffic coming in from the AAISP interface (the Internet). The stats can be viewed with a print stats command.
print stats
Flags: X - disabled, I - invalid, D - dynamic
# CHAIN ACTION BYTES PACKETS
forward passthrough 35 567 80
As we create rules to tag traffic, the above metric is useful to determine if the total inbound traffic roughly matches the sum of the rules.
Next, we’ll create two proper tagging rules. This example will tag packets as ether2 if they are destined for the ether2 interface and likewise for ether3.
add chain=forward action=mark-packet new-packet-mark=ether2 passthrough=yes in-interface=AAISP out-interface=ether2
add chain=forward action=mark-packet new-packet-mark=ether3 passthrough=yes in-interface=AAISP out-interface=ether3
This tagging method is really powerful. While this example tags all traffic to a specific interface, we could just as easily tag it by protocol or source address.
Issue another print stats command and you’ll see metrics relating to ether2 and ether3. It’s a good idea to add a comment to each metric so you can identify its purpose.
Queue Management
Now our inbound packets are tagged, we can apply priorities to the tags.
/queue tree
add name=ether2 parent=global packet-mark=ether2 priority=2
add name=ether3 parent=global packet-mark=ether3 priority=4
We’ve now granted higher priority to traffic going from AAISP to ether2 compared to traffic going from AAISP to ether3. Priorities are in the range 1-8 with 1 being the highest. Stats can be viewed using the print stats command.
print stats
Flags: X - disabled, I - invalid
0 name="ether2" parent=global packet-mark=ether2 rate=17928 packet-rate=5 queued-bytes=0 queued-packets=0 bytes=520252348 packets=482842 dropped=0
1 name="ether3" parent=global packet-mark=ether3 rate=0 packet-rate=0 queued-bytes=0 queued-packets=0 bytes=16021459119 packets=11916305 dropped=463600