Shaping

Shaping is used to limit the bandwidth of traffic at egress.

Traffic that exceeds the configured bandwidth is buffered in the queue system.

Shapers are implemented by using a tc qdisc.

1. Port Shaping

A port shaper limits the bandwidth of all traffic that is egressing at a port and is implemented by a tbf qdisc.

A tbf qdisc that implements a port shaper must be attached to the root:

# tc qdisc add dev eth0 root handle 1:0 tbf \
  rate 10000000 burst 8192 limit 1m

The parameters have the following meaning:

  • rate - The bitrate is specified in bits per second.

  • burst - The burst size in bytes.

  • limit - Buffer size. This parameter is not offloaded (and ignored) but is required by the tc command.

In the example above a tbf qdisc is created with a rate of 10 megabits per second and a burst size of 8192 bytes.

2. Priority Shaping

A priority shaper limits the bandwidth of a specific priority that is egressing at a port and is implemented by either a tbf qdisc or a cbs qdisc.

The main difference between these two is the way that bursts are handled.

The tbf qdisc is continuously assigned new credit according to the configured shaper rate. This implies that after an idle period a burst of data is allowed when there are again data to transmit.

The cbs qdisc implements the shaper algorithm described in IEEE Std 802.1Q-2018 Section 8.6.8.2, and is only assigned new credit when there is data to send. This lowers the possibility of large bursts.

2.1. tbf

A tbf qdisc that implements a priority shaper must be attached to one of the classes on a parent qdisc, which can be either mqprio, taprio or ets:

# tc qdisc replace dev eth0 parent 1:5 handle 2:0 tbf \
  rate 10000000 burst 8192 limit 1m

The parameters have the same meaning as in the port shaper.

In the example above a tbf qdisc is created in traffic class 1:5 of the parent, which corresponds to priority queue 4.

2.2. cbs

Sparx5: does currently not support the credit based shaper. This will be added in a future release.

A cbs qdisc must always be attached to one of the classes on a parent qdisc, which can be either mqprio, taprio or ets:

# tc qdisc replace dev eth0 parent 1:5 handle 2:0 cbs \
  idleslope 10000 sendslope -990000 hicredit 15 locredit -990 offload 1

The parameters have the following meaning:

  • idleslope - The rate of credits accumulated (in kilobits per second) when there is at least one frame waiting for transmission.

  • sendslope - The rate of credits depleted when a transmission is occurring.

  • hicredit - The maximum amount of credits (in bytes) that can be accumulated.

  • locredit - The minimum amount of credits (in bytes) that can be reached.

  • offload - Set to 1 to enable HW offload.

In the example above a cbs qdisc is created in traffic class 1:5 of the parent, which corresponds to priority queue 4.

The interface runs at 1 Gbps and the bit rate is 10000 kbps.

Please see IEEE Std 802.1Q-2018 Section 8.6.8.2 and Annex L on how to calculate the parameters.