Announcement

Collapse
No announcement yet.

QoS - begränsad bandbredd

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Network] QoS - begränsad bandbredd

    På portnivå (bandwidth limitation based on ports) - och det fungerar verkligen (and yes, it really works)!

    (bla bla) Därför bestämde jag mig precis för att klistra in det här eftersom just den här sortens väldigt betydelsefull kod alltid försvinner för mig. Fasiken så härligt att det funkar igen! Jag minns iofs att jag hade en konfiguration för ip-nivå också, men det får jag väl tyvärr återkomma med...

    Källa: http://lartc.org/howto/lartc.qdisc.classful.html


    IP-nivå-hanteringen bör dock ligga här.

    Code:
    #!/bin/sh
    
    ## Bandwidth Limiting.
    
    nntp="10"
    echo "NNTP Config: ${nntp}Mbit"
    
    # This part installs the root and the customary 1:1 class.
    # The 1:1 class is bounded, so the total bandwidth can't exceed 6mbit.
    
    # Kill classes if any
    echo "Cleanup"
    tc qdisc del dev eth0 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc del dev eth1 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc del dev eth2 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    
    # Install the root classes
    echo "Installing root for eth0-eth2"
    tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc add dev eth1 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc add dev eth2 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    
    # Install the customary 1:10 class
    echo "Installing 1:10/usenet throttler"
    tc class add dev eth2 parent 1:0 classid 1:10 cbq bandwidth 100Mbit \
        rate ${nntp}Mbit weight 0.5Mbit prio 8 allot 1514 cell 8 maxburst 20 \
        avpkt 1000 bounded
    
    # HTB/ Leaf classes. Scale the weight with the configured rate
    # Both classes are not bounded, but they are connected to class 1:1 which is bounded.
    # The classids need to be within the same major number as the parent qdisc, by the way!
    
    echo "Installing leaf for usenet throttler"
    tc class add dev eth2 parent 1:10 classid 1:13 cbq bandwidth 100Mbit   \
        rate ${nntp}Mbit weight 0.5Mbit prio 5 allot 1514 cell 8 maxburst 20 \
        avpkt 1000
    
    echo "Adding qdisc/sfq for usenet throttler"
    tc qdisc add dev eth2 parent 1:13 handle 30: sfq
    
    # These commands, attached directly to the root, send traffic to the right qdiscs.
    echo "Installing filter, port 119, for usenet throttler"
    tc filter add dev eth2 parent 1:0 protocol ip prio 1 u32 match ip sport 119 0xffff flowid 1:13



    -
    (Original ) Originalkoden, delar upp 6Mbit mellan mail och web (splits up 6Mbit between mail & web)...

    Code:
    # This configuration limits webserver traffic to 5mbit and SMTP traffic to 3 mbit.
    # Together, they may not get more than 6mbit. We have a 100mbit NIC and the classes
    # may borrow bandwidth from each other.
    
    
    # This part installs the root and the customary 1:1 class.
    # The 1:1 class is bounded, so the total bandwidth can't exceed 6mbit.
    
    # Install the root class
    tc qdisc add dev eth0 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc add dev eth1 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    tc qdisc add dev eth2 root handle 1:0 cbq bandwidth 100Mbit avpkt 1000 cell 8
    
    # Install the customary 1:1 class
    
    tc class add dev eth0 parent 1:0 classid 1:1 cbq bandwidth 100Mbit \
        rate 6Mbit weight 0.6Mbit prio 8 allot 1514 cell 8 maxburst 20 \
        avpkt 1000 bounded
    
    # HTB/ Leaf classes. Scale the weight with the configured rate
    # Both classes are not bounded, but they are connected to class 1:1 which is bounded.
    # The sum of bandwith of the 2 classes will never be more than 6mbit.
    # The classids need to be within the same major number as the parent qdisc, by the way!
    
    tc class add dev eth0 parent 1:1 classid 1:3 cbq bandwidth 100Mbit  \
        rate 5Mbit weight 0.5Mbit prio 5 allot 1514 cell 8 maxburst 20      \
        avpkt 1000
    
    tc class add dev eth0 parent 1:1 classid 1:4 cbq bandwidth 100Mbit  \
        rate 3Mbit weight 0.3Mbit prio 5 allot 1514 cell 8 maxburst 20      \
        avpkt 1000
    
    # Both classes have a FIFO qdisc by default.
    # But we replaced these with an SFQ queue so each flow of data is treated equally.
    
    tc qdisc add dev eth0 parent 1:3 handle 30: sfq
    tc qdisc add dev eth0 parent 1:4 handle 40: sfq
    
    # These commands, attached directly to the root, send traffic to the right qdiscs.
    
    tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 80 0xffff flowid 1:3
    tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip sport 25 0xffff flowid 1:4
    Last edited by Tornevall; 2007-11-01, 11:40. Reason: Translation. For foreign members.
    -
Sorry, you are not authorized to view this page
Working...
X