While writing an article about QoS, I realized that i needed at clarify some of the terminology used. In particular I want to discuss first about the different ways to control the amount of traffic we send out or receive in a particular interface, especially in the case when the CIR we contracted is less than the physical speed of our interface. I’m talking about Shaping and Policing.
Shaping and policing are two very different approaches and are configured also in a very different way even though they use similar terminology. In this article I will be focusing on the first of the two methods, traffic shaping.
With traffic shaping we configure the router to ensure that the bit rate of packets leaving an interface will not exceed the configured value. When the configured value is exceeded, the exceeding packets are queued in the shaping queue and forwarded on a later time. Therefore, traffic shaping can only be applied outbound.
Every device can send traffic out of a particular interface only at the serialization speed of the interface. For example, on a Serial interface that will be 1.544 Mbps, on a Ethernet will be 10 Mbps, on a FastEthernet 100 Mbps and so on. For this reason, the only way to limit the bit rate of an interface, is to interleave periods when traffic is sent at the serialization speed of the link, with periods of silence.
Let’s make an example. We want to limit an Ethernet link at 5 Mbps. Since the serialization on an Ethernet interface is 10 Mbps, to achieve only 5 Mbps we will need to send traffic for half second, and be quite for the other half. That, in average, will result on 5 Mbps since 10 Mbps * 0.5 s = 5 Mbps. The routers won’t be thinking in seconds, as a second is too big, instead they will think in a much smaller unit, the milliseconds (ms). Obviously, thinking in ms, we will have more than one interval within a seconds; those time intervals are called Tc.
Assuming for simplicity a Tc of 125 ms, we will have 8 intervals within a second (125 * 8 = 1000 ms = 1s). Within each interval, the router will send traffic at the maximum speed allowed by the interface and be silent so that, as explained before, the average over time, will be the configured shaped rate.
The Bc instead, is the amount of traffic (in bits) that can be sent out of the interface for every interval. The relation between Tc, Bc and Shaped rate is: Shaped rate = Bc / Tc. Most of the times we configure the CIR as the shaped rate, this will make the formula easier to read as : CIR = Bc / Tc. Particular attention needs to be placed on the units we use, as the CIR is usually in Kbps or Mbps, the Bc is in bps an the Tc in ms.
The following picture should be more explanatory (click on it to zoom it) :
All this considerations are perfect when the link is utilized above the shaping rate. The router, working as described before, is able to reduce the amount of traffic sent out the interface.
We know that most of the traffic, is usually not so uniform, we deal with moments of high utilization and moment of lower utilization. In this condition, traffic shaping, is able to queue excess packets, and transmit them later during an interval of low utilization. The maximum amount of traffic that can be sent during a low utilization interval is called Be.
The result of applying traffic shaping is a quite uniform distribution of the outgoing traffic as the picture below is showing:
The configuration of traffic shaping, in regards of Class Based (CB) is quite simple. Let see just a couple of examples and verifications. In the following examples we want to shape a FastEthernet link at 60 Mbps.
When the shaping rate is configured as an absolute value, we need to specify what this value is in bits per second. We can use the key letters k , m, g for Kbps, Mbps, Gbps respectively, but the value will be automatically converted in bits in the configuration.
Also, is to be noted, that the shaping rate is the only required and IOS actually explicitly recommends not to configure Bc and Be values.
Gateway(config)#policy-map SHAPING Gateway(config-pmap)#class class-default Gateway(config-pmap-c)#shape average 60m Gateway(config-pmap-c)#do sh run policy-map Building configuration... Current configuration : 75 bytes ! policy-map SHAPING class class-default shape average 60000000 ! end Gateway(config-pmap-c)# shape average 60000000 ? <32-154400000> bits per interval, sustained. Recommend not to configure, the algorithm will fi <cr> Gateway(config-pmap-c)#shape average 60000000 15000 ? <0-154400000> bits per interval, excess. (postfix k, m, g optional; decimal point allowed) <cr>
To apply the shaping, we need to go at the interface level, and apply the service policy in the outbound direction. Verification is done using the show service-policy interface command. We can there verify the Shaping rate as well the Be and Bc that have been automatically calculated by the router as per output below:
! interface FastEthernet0/0 bandwidth 60000 service-policy output SHAPING ! Gateway#sh policy-map interface fa0/0 FastEthernet0/0 Service-policy output: SHAPING Class-map: class-default (match-any) 2074764 packets, 499256528 bytes 30 second offered rate 1000 bps, drop rate 0 bps Match: any Queueing queue limit 64 packets (queue depth/total drops/no-buffer drops) 0/0/0 (pkts output/bytes output) 2074764/501145734 shape (average) cir 60000000, bc 240000, be 240000 target shape rate 60000000
Since Bc is 240000 bits and the CIR is 60000000, the Tc considered can be calculated and in this example is equal to 4ms
Shaping can also be configured as a relative percentage of the configured interface bandwidth. If the configured bandwidth changes, the policy-map will automatically adjust to the new relative shaping rate as per example below:
Gateway(config)#policy-map SHAPE-PERCENT Gateway(config-pmap)#class class-default Gateway(config-pmap-c)#shape average percent ? <1-100> percentage Gateway(config-pmap-c)#shape average percent 100 Gateway(config-pmap-c)#int fa0/0 Gateway(config-if)#no service-policy output SHAPING Gateway(config-if)#service-policy output SHAPE-PERCENT Gateway#sh int fa0/0 | i BW MTU 1500 bytes, BW 60000 Kbit/sec, DLY 100 usec, Gateway#sh policy-map interface fa0/0 FastEthernet0/0 Service-policy output: SHAPE-PERCENT Class-map: class-default (match-any) 38 packets, 5072 bytes 30 second offered rate 0 bps, drop rate 0 bps Match: any Queueing queue limit 64 packets (queue depth/total drops/no-buffer drops) 0/0/0 (pkts output/bytes output) 38/4056 shape (average) cir 60000000, bc 600000, be 600000 target shape rate 60000000 Gateway(config-pmap-c)#int fa0/0 Gateway(config-if)#bandwidth 80000 Gateway(config-if)#^Z Gateway#sh int fa0/0 | i BW MTU 1500 bytes, BW 80000 Kbit/sec, DLY 100 usec, Gateway#sh policy-map interface fa 0/0 FastEthernet0/0 Service-policy output: SHAPE-PERCENT Class-map: class-default (match-any) 53 packets, 6912 bytes 30 second offered rate 0 bps, drop rate 0 bps Match: any Queueing queue limit 64 packets (queue depth/total drops/no-buffer drops) 0/0/0 (pkts output/bytes output) 53/5648 shape (average) cir 80000000, bc 800000, be 800000 target shape rate 80000000