Simple traffic shaping

Problem this snippet solves:

What the rule does is looks at duration of the flow and evaluates the number of bytes the server has sent for the flow. If the flow meets the specified conditions it is pinned to a rate class.

This iRule has been used for internet bound traffic going through proxy servers.

Requirements:

  1. Want to emulate, in the simplest way possible, a Packeteer without purchasing that product.
  2. Want the rule to work for all protocols.
  3. Want this to work on a per flow basis so regular browsing of the internet by the same user is not affected.

This rule is not perfect and it makes some specific assumptions.

Assumptions are:

  1. Clients will use a single flow to pull data. Even if it is multiple flows, all flows that violate the conditions will be pinned to a rate class.
  2. It is ok for the client to bust for 10 seconds.
  3. Most flows are less than 10 seconds in duration.
  4. Most flows will try to reach the upper-bound in the first couple of windows of the flow.

Code :

when SERVER_DATA {
  set srvAge [IP::stats age]
  set srvBytes [IP::stats bytes in]
  # change 10000ms/10s to your desired time        
  if {$srvAge > 10000 } {
    # change the recieved bytes if needed
    if {$srvBytes > 3000000 } { 
      # makesure you create the rate class
      rateclass bandHog
      #log local0. "Bandwidth Hog: [IP::client_addr] server bytes $srvBytes"
    }
  }              
  #log local0. " [IP::client_addr]:[TCP::client_port] server age: $srvAge server bytes: $srvBytes"
}
Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment