User Tools

Site Tools


inbox:howto:packet.scheduler.experience

Packet scheduling, Hierarchical Token Bucket : an experience

A log about using the hierarchical token bucket packet scheduler (qdisc). Please have a look also in other articles of the openwrt wiki.

How to check if queue schedulers are attached

tc qdisc show

Attach a qdisc to an interface

  insmod sch_htb #or insmod <scheduler_module>
    #load the scheduler module in memory
    
  tc qdisc add dev br-wan root handle 1: htb default 50
    # tc, the command
    # qdisc, we want to add a schedulers
    # dev <iface>, on an interface
    # root : is the root of the hierarchy of qdiscs
    # handle 1: : the "hook" for attaching children classes is "1:"
    # htb: the type of the qdisc
    # default 50: the unclassified traffic will be assigned to the child class
    #             1:50

define children classes for the interface and the scheduler

  tc class add dev br-wan parent 1: classid 1:1 htb rate 300kbit burst 1500b
    # class : a class is a "category" to handle the packets in some way
    # add : add the class, define it
    # dev br-wan : on the interface br-wan
    # parent 1: it is child of the class/qdisc 1:
    # classid 1:1 : the identifier is 1:1
    # htb : the scheduling of the packets in this class is htb
    # rate 300kbit : the guaranteed bandwidth for this class and children 
    #   is 300kbit. Not bytes!
    # burst 1500b: in one time unit (one second), the allowed flow can
    #   increase (it is a sort of a delta) of 1500 bytes. So if the rate
    # is constant the increase (or "burst of packets") can be 1500b every second.
    # to avoid too fast increases.
  
  tc class add dev br-wan parent 1:1 classid 1:10 \
  htb rate 24kbit ceil 300Kbit burst 1500b prio 0
    # as before but with some changes. Now we have a class child of a class,
    # parent 1:1 means "this class is child of the classid 1:1".
    #
    # Then classes can have rates higher than the parent class, but
    # it is sensless (i agree with the author of the qdisc, if you want
    # to use sensless values, do it, don't expect warnings from the command).
    #
    # rate 24Kbit: is the garantueeded maximum rate of the class,
    #   actually all the children should have the sum of guaranteed
    #   rates equal or lower than the parent class.
    # ceil 300Kbit: this is the maximum bandwidth that the class can use,
    #   and should be equal or lower than the rate/ceil of the parent.
    # prio 0: means the priority of sending packets through the "root" qdisc,
    #   the lower is the priority (min 0) the higher is the precedence if there
    #   are packets waiting. The maximum prio seems 7 on openwrt.

to check more statistics of a class

  tc -s class show dev br-wan

to delete a class

  #just delete the signature that identify the class
  tc class del dev br-wan parent 1:1 classid 1:10
    # we need to identify the interface
    # then the parent
    # and the classid

to check more statistics of a qdisc

  tc -s qdisc show

assign packets to a class with iptables

  #for iptables: check the wiki of openwrt, there are nice articles.
  iptables -t mangle -I POSTROUTING 1 -s 192.168.10.11 -j CLASSIFY --set-class 1:60
    #iptables, the command.
    #-t mangle : the firewall table, in this case to modify a packet.
    #-I POSTROUTING: insert in the chain of packets that are leaving the router.
    #-s <ip address>: if the source of the packets is the ip address
    #-j CLASSIFY --set-class 1:60 :if the matching condition are satisfied,
    #  then modifiy the packet adding the information related to classification
    #  to match the class 1:60 .

a practical trial

  with the commands commented in this page, i have 
  (with tc qdisc show dev br-wan )
  qdisc htb 1: root refcnt 2 r2q 10 default 50 direct_packets_stat 73121
  (with tc class show dev br-wan )
  class htb 1:1 root rate 300000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:10 parent 1:1 prio 0 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:20 parent 1:1 prio 1 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:30 parent 1:1 prio 2 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:40 parent 1:1 prio 3 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:50 parent 1:1 prio 4 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  class htb 1:60 parent 1:1 prio 5 rate 24000bit ceil 300000bit burst 1500b cburst 1599b
  
  I created 6 similar classes, where the difference is the priority
  (so some classes will have their queue sent before, as long as they don't
  exceed the guaranteed rate). This to divide the use of the upload bandwidth
  (and therefore download) between the systems in a network.
  The systems that requires bandwidth but can use time will be assigned in the
  class 60. The unknown systems in the class 50 and systems that requires
  to be faster in higher (in priroity terms) classes.
  
  And then only one ip/system has to be slowed down:
  iptables -t mangle -I POSTROUTING 1 -s 192.168.10.11 -j CLASSIFY --set-class 1:60
  
inbox/howto/packet.scheduler.experience.txt · Last modified: 2016/01/17 10:36 by valentt