shaping: introduce downstream shaping

This commit is contained in:
Astro 2017-02-05 03:22:06 +01:00
parent ab68c6c879
commit 64685f254f
5 changed files with 29 additions and 9 deletions

View File

@ -1,6 +1,6 @@
upstream:
interface: ipredator
nat66-interface: ipredator
up-bandwidth: 10000
flow-keys: nfct-src
up-bandwidth: 10400
down-bandwidth: 180000
flows: 4096

View File

@ -1,6 +1,6 @@
upstream:
interface: up1
nat66-interface: 6to4
up-bandwidth: 6200
flow-keys: nfct-src
up-bandwidth: 6000
down-bandwidth: 95000
flows: 2048

View File

@ -2,7 +2,7 @@ upstream:
interface: up2
nat66-interface: up2
up-bandwidth: 12400
flow-keys: nfct-src
down-bandwidth: 195000
flows: 2048
port-forwarding:

View File

@ -1,9 +1,9 @@
#!/bin/sh
if [ "$IFACE" = "{{ pillar['upstream']['interface'] }}" ]; then
if [ "$IFACE" = "{{ iface }}" ]; then
tc qdisc del dev $IFACE root 2> /dev/null > /dev/null
tc qdisc add dev $IFACE root handle 1 hfsc default 1
tc class add dev $IFACE parent 1: classid 1:1 hfsc sc rate {{ pillar['upstream']['up-bandwidth'] }}kbit ul rate {{ pillar['upstream']['up-bandwidth'] }}kbit
tc class add dev $IFACE parent 1: classid 1:1 hfsc sc rate {{ bandwidth }}kbit ul rate {{ bandwidth }}kbit
tc qdisc add dev $IFACE parent 1:1 handle 11: fq_codel flows {{ pillar['upstream']['flows'] }}
tc filter add dev $IFACE parent 11: handle 11 protocol all flow hash keys {{ pillar['upstream']['flow-keys'] }} divisor {{ pillar['upstream']['flows'] }}
tc filter add dev $IFACE parent 11: handle 11 protocol all flow hash keys {{ flow_keys }} divisor {{ pillar['upstream']['flows'] }}
fi

View File

@ -3,10 +3,30 @@
iproute2:
pkg.installed: []
/etc/network/if-up.d/shaping:
{%- if upstream.get('up-bandwidth') %}
/etc/network/if-up.d/up-shaping:
file.managed:
- source: salt://upstream/shaping
- template: 'jinja'
- context:
iface: {{ pillar['upstream']['interface'] }}
bandwidth: {{ pillar['upstream']['up-bandwidth'] }}
flow_keys: nfct-src
- mode: 755
- require:
- pkg: iproute2
{%- endif %}
{%- if upstream.get('down-bandwidth') %}
/etc/network/if-up.d/down-shaping:
file.managed:
- source: salt://upstream/shaping
- template: 'jinja'
- context:
iface: core
bandwidth: {{ pillar['upstream']['down-bandwidth'] }}
flow_keys: nfct-dst
- mode: 755
- require:
- pkg: iproute2
{%- endif %}