Skip to contentSkip to conversation

How to limit bandwidth by port?

LARTC David Coello 3 participants 3 messages Dec 12, 2002 – Jan 3, 2003

lore
Share & tools
lore
#1 lore raw

DOWNLINK"0
UPLINK5
DEV=ppp0

tc qdisc add dev $DEV root handle 1: htb default 10

tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6

tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
ceil $[UPLINK}kbit burst 6k prio 1

tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[3*$UPLINK/10]kbit\

    ceil $[9*$UPLINK/10]kbit burst 6k prio 2

tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10

tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \

         match ip dport 8080 0xffff flowid 1:20

traffic to dport 80 will get 3/10 of bandwith (with possibility to borrow up to 9/10)
andrea

Quoted 6 lines · David Coello

Hi again

I am making all the test and probes i cann´t imagine but i begin to think it´s imposible to limit bandwidth by port. Anybody could put me a code example that makes this please?

Quoted 9 lines

Thanks and regards
David Coello

_______________________________________________
LARTC mailing list / [email protected]
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

_______________________________________________
LARTC mailing list / [email protected]
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

#2 lore raw
In reply to David Coello
Quoted 17 lines · Andrea Rossato

DOWNLINK=220
UPLINK=125
DEV=ppp0

tc qdisc add dev $DEV root handle 1: htb default 10

tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6

tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
ceil $[UPLINK}kbit burst 6k prio 1

tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[3*$UPLINK/10]kbit\

    ceil $[9*$UPLINK/10]kbit burst 6k prio 2

tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10

Quoted 7 lines

tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \

         match ip dport 8080 0xffff flowid 1:20

traffic to dport 80 will get 3/10 of bandwith (with possibility to borrow up to 9/10)
andrea

Andrea,

I have another script (attached) Im just wondering how i could implement the above script into it. Im not the most knowledgable on shaping in general :)

thanks
-mdew (resent-again)

#! /bin/sh

EXT_IFACE=eth0

modprobe imq numdevs=1

# del the qdisc already loaded (if there)
tc qdisc del dev imq0 root

tc qdisc add dev imq0 handle 1: root htb default 12 r2q 1

# [ HTB queue ]
# |
# |
# [256] (class 1:1)

#             /  |  \
#            /   |   \
#           /    |    \
#          /     |     \
#         /      |      \
#     [64]       [64]    [128] (note: these add up the the parent's 256)
#     (1:10)     (1:11)  (1:12)
#       |        |        |
#       |        |        |
#     [sfq]    [sfq]    [sfq]
#     (20:0)   (21:0)   (22:0)

# The main link: 252kbit (less is better)
tc class add dev imq0 parent 1: classid 1:1 htb rate 254kbit
# For 10.0.0.9 - 64kbit all to itself - Paul
tc class add dev imq0 parent 1:1 classid 1:10 htb rate 20kbit burst 1kbit prio 1 ceil 36kbit # For 10.0.0.2 - 64kbit all to itself - Mark
tc class add dev imq0 parent 1:1 classid 1:11 htb rate 20kbit burst 1kbit prio 1 ceil 60kbit # For 10.0.0.3 and 10.0.0.8 - 128kbit between them - Ryan - Mike
tc class add dev imq0 parent 1:1 classid 1:12 htb rate 200kbit burst 10kbit prio 1 ceil 252kb it

# SFQ makes things a bit fairer (in theory)
tc qdisc add dev imq0 parent 1:10 handle 20:0 sfq
tc qdisc add dev imq0 parent 1:11 handle 21:0 sfq
tc qdisc add dev imq0 parent 1:12 handle 22:0 sfq

# Match iptables mark 1 and send to class 1:10 (64kbit A)
tc filter add dev imq0 protocol ip pref 1 parent 1: handle 1 fw classid 1:10 # Match iptables mark 2 and send to class 1:11 (64kbit B)
tc filter add dev imq0 protocol ip pref 2 parent 1: handle 2 fw classid 1:11 # Match iptables mark 3 and send to class 1:12 (128kbit)
tc filter add dev imq0 protocol ip pref 3 parent 1: handle 3 fw classid 1:12

# The IMQ device must be up before this will work...

# ip link set imq0 up (set below)

iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -N incoming
iptables -t mangle -A incoming -d 10.0.0.9 -j MARK --set-mark 1 iptables -t mangle -A incoming -d 10.0.0.2 -j MARK --set-mark 2 iptables -t mangle -A incoming -m mark --mark 1 -j RETURN iptables -t mangle -A incoming -m mark --mark 2 -j RETURN iptables -t mangle -A incoming -j MARK --set-mark 3 iptables -t mangle -A FORWARD -i $EXT_IFACE -j incoming iptables -t mangle -A FORWARD -i $EXT_IFACE -j IMQ

ip link set imq0 up

tc -s -d class show dev imq0