The single leaky bucket meter is the most basic meter: ``tokens'' enter the bucket at rate cir, until the bucket reaches the size cbs. At this point, further tokens are discarded. A packet conforms to the meter if the number of tokens in the bucket corresponds to at least the size of the packet. In this case, the respective number of tokens is subtracted from the bucket, and the packet has passed the conformance test. Otherwise, the packet has failed the test, and no tokens are subtracted.
We illustrate the operation of a single leaky bucket meter in figure 2.2, by using the analogy of a bucket that contains water, and where a faucet is briefly opened whenever a packet is accepted, to let go of the corresponding quantity of water.
Meters are generated by a macro whose name is the abbreviated meter name, e.g. SLB. Typically, the meter is assigned to a variable, e.g.
$slb = SLB(cir 100kbps,cbs 10kB);
SLB takes the following parameters:
|cbs||Bytes||Committed burst size|
|cir||bps||Committed information rate|
|mpu||Bytes||Minimum policed unit|
Only mpu is optional, all other parameters are required.
There are two functions for testing a single or double bucket meter: meter_ok tests whether the meter has detected conformance or not, and returns the corresponding truth value. Example:
#include "fields.tc" #include "meters.tc" $foo_meter = SLB(cir 50kbps,cbs 20kB); ... class (<$foo_class>) if ip_src == host "foo.mydomain.net" && SLB_ok($foo_meter);
meter_else_drop performs the same test, but drops the packet if detecting non-conformance.
#include "fields.tc" #include "meters.tc" $icmp_meter = SLB(cir 10kbps,cbs 20kB,pir 100kbps,pbs 5kB); $icmp_meter = SLB(cir 10kbps,cbs 20kB); ... class (<$icmp_class>) if ip_proto == IPPROTO_ICMP && SLB_else_drop($icmp_meter);
Note that terms of equal precedence in an expressions are evaluated from left to right, so that
... if tcp_sport == 80 && SLB_ok($x);
... if SLB_ok($x) && tcp_sport == 80;
are not equivalent. In the latter expression, the conformance test is always performed when reaching this if condition, and if successful, the corresponding tokens are removed from the bucket, even if the following test of tcp_sport fails.