{"id":1098,"date":"2010-11-25T17:37:04","date_gmt":"2010-11-25T17:37:04","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=1098"},"modified":"2015-02-21T09:18:54","modified_gmt":"2015-02-21T09:18:54","slug":"understanding-traffic-shaping","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=1098","title":{"rendered":"Understanding Traffic Shaping"},"content":{"rendered":"<p>Traffic Shaping involves in queueing traffic rather than dropping it. Traffic Shaping terminology is:<!--more--><\/p>\n<ul>\n<li><span> <\/span><strong>Tc &#8211; <\/strong>Time interval (in milliseconds) over which the committed burst (Bc) can be sent. Tc = Bc\/CIR<\/li>\n<li><span> <\/span><strong>Bc &#8211; <\/strong>Committed burst size (in bits). This is the amount of traffic that can be sent over an interval Tc<\/li>\n<li><span> <\/span><strong>CIR &#8211; <\/strong>Committed Information Rate (in bits per second). The rate defined in the traffic contract<\/li>\n<li><span> <\/span><strong>Shaped Rate &#8211; <\/strong>The rate at which a particular traffic is shaped. It could be same as CIR or higher than CIR.<\/li>\n<li><span> <\/span><strong>Be &#8211; <\/strong>Excess burst size (in bits). This is the number of bits that can be sent beyond Bc<\/li>\n<\/ul>\n<p><a href=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-2.PNG\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1100\" title=\"Traffic Shaping-2\" src=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-2.PNG\" alt=\"Traffic Shaping-2\" width=\"688\" height=\"198\" srcset=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-2.PNG 688w, http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-2-300x86.PNG 300w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>A  Cisco router divides 1 second into multiple sub-seconds. Above, 1  second is divided into 8 intervals (125ms each). Each interval is called  Tc. During each Tc, the router sends a burst of traffic which is called  Bc.<\/p>\n<p>For example, to achieve a CIR (contract rate) of 128Kbps,  the Cisco router will send 16000 bits (Bc = 128000 * 0.125) during the  first interval and stop sending any further traffic until the next  interval. So, if the access link speed is 1.544Mbps, it will take the  Cisco router 10.3ms to send 16000 bits. For the rest of the interval, it  will not send any traffic.<\/p>\n<p><span style=\"font-size: small;\"><strong>Traffic Shaping with no Excess Burst:<\/strong><\/span><\/p>\n<p>Traffic shaping involves the concept of <em><strong>Token Bucket<\/strong><\/em>.  In the token bucket scenario, each token lets you send 1 bit. The size  of the token bucket is Bc. There are two actions that revolve around  token bucket and the tokens-<\/p>\n<ol>\n<li>Re-filling of bucket with new tokens<\/li>\n<li>Consumption of tokens by the Shaper to earn the right to send packets<\/li>\n<\/ol>\n<p>At  the beginning of each Tc interval, the token bucket is filled with  tokens, but no more than Bc. If there is not enough room in the bucket  as the tokens were not used up in the previous interval, some tokens  spill out. Those spilled tokens cant be used.<\/p>\n<p>Every time a  packet is sent, the Shaper spends tokens from the bucket to buy the  right to forward the packet. When the Shaper tries to send the packet,  and there are not enough tokens in the bucket, the Shaper must wait  until the next interval when the bucket is refilled.<\/p>\n<p>In Cisco IOS, traffic shaping with no excess burst can be configured using <em><strong>shape average &lt;shaping-rate&gt;<\/strong><\/em> command from policy-map configuration mode. The &#8220;shaping-rate&#8221; could be  same as CIR or slightly higher than CIR but less than access-link rate.<\/p>\n<p>The  following example shows the configuration of average traffic shaping.  Traffic shaping is applied to outgoing TCP traffic generated via Iperf.<\/p>\n<div>\n<div style=\"width: 100%;\">\n<h4>Traffic shaping with no excess burst<\/h4>\n<div>\n<div>\n<div dir=\"ltr\"><code>class-map P5001<\/code><br \/>\n<code> match access-group 101<\/code><br \/>\n<code>!<\/code><br \/>\n<strong><code>policy-map SHAPE<\/code><\/strong><br \/>\n<code> <strong>class 5001<\/strong><\/code><br \/>\n<code> <strong style=\"background-color: #ffff00;\">shape average percent 50<\/strong><\/code><br \/>\n<code>!<\/code><br \/>\n<code>interface fastethernet 0\/1<\/code><br \/>\n<code> bandwidth 1000<\/code><br \/>\n<code> <strong>service-policy output SHAPE<\/strong><\/code><br \/>\n<code>!<\/code><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Cisco  recommends only the shaping rate should be specified and the inbuilt  algorithm will calculate appropriate Bc. Cisco IOS chooses Tc=24ms here.  The Bc is calculated as 12000 bits. The <strong>Increment<\/strong> value indicates the number of tokens replenished every Tc interval. Also note, the <strong>Shaping Active<\/strong> suggests no shaping. The reason being if there is no traffic flowing through the interface, shaping will not be in effect. The <strong>Byte Limit<\/strong> indicates the size of the token bucket.<\/p>\n<div>\n<div style=\"width: 100%;\">\n<h4>output<\/h4>\n<div>\n<div>\n<div dir=\"ltr\"><strong><code>Router# show policy-map interface fastethernet 0\/1<\/code><br \/>\n<code> FastEthernet0\/1<\/code><\/strong><\/p>\n<p><code> Service-policy output: SHAPE<\/code><\/p>\n<p><code> Class-map: P5001 (match-all)<\/code><br \/>\n<code> 5368 packets, 7598188 bytes<\/code><br \/>\n<code> 5 minute offered rate 99000 bps, drop rate 0 bps<\/code><br \/>\n<code> Match: access-group 101<\/code><br \/>\n<code> <strong>Traffic Shaping<\/strong><\/code><strong><br \/>\n<\/strong><code><strong> Target\/Average <\/strong> <strong>Byte<\/strong> <strong>Sustain<\/strong> Excess\u00a0\u00a0\u00a0 <strong>Interval<\/strong> <strong>Increment<\/strong><\/code><br \/>\n<code> Rate\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<strong> Limit<\/strong> bits\/int\u00a0 bits\/int\u00a0 (ms)\u00a0\u00a0\u00a0\u00a0\u00a0 (bytes)<\/code><br \/>\n<code> 50 (%)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 (ms)\u00a0\u00a0\u00a0\u00a0\u00a0 0 (ms)<\/code><br \/>\n<code> <span style=\"background-color: #ffff00;\">500000\/500000<\/span> <span style=\"background-color: #ffff00;\">3000<\/span> <span style=\"background-color: #ffff00;\">12000<\/span> 12000\u00a0\u00a0\u00a0\u00a0 <span style=\"background-color: #ffff00;\">24<\/span> <span style=\"background-color: #ffff00;\">1500<\/span><\/code><\/p>\n<p><code> Adapt\u00a0 Queue\u00a0\u00a0\u00a0\u00a0 Packets\u00a0\u00a0 Bytes\u00a0\u00a0\u00a0\u00a0 Packets\u00a0\u00a0 Bytes\u00a0\u00a0\u00a0\u00a0 Shaping<\/code><br \/>\n<code> Active Depth\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Delayed\u00a0\u00a0 Delayed\u00a0\u00a0 Active<\/code><br \/>\n<code> -\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5367\u00a0\u00a0\u00a0\u00a0\u00a0 7597242\u00a0\u00a0 5343\u00a0\u00a0\u00a0\u00a0\u00a0 7587026\u00a0\u00a0 no<\/code><\/p>\n<p><code> Class-map: class-default (match-any)<\/code><br \/>\n<code> 457 packets, 33974 bytes<\/code><br \/>\n<code> 5 minute offered rate 0 bps, drop rate 0 bps<\/code><br \/>\n<code> Match: any<\/code><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>When  Iperf was initiated to generate TCP traffic with 4 different flows, the  maximum throughput it could achieve was 481kbps (~500kbps). This is  almost equal to the shaping rate 500kbps.<\/p>\n<div>\n<div style=\"width: 100%;\">\n<h4>Iperf output<\/h4>\n<div>\n<div>\n<div dir=\"ltr\"><strong><code>C:\\&gt;iperf -c 192.168.2.10 -p 5001 -P 4 -t 60<\/code><\/strong><br \/>\n<code>------------------------------------------------------------<\/code><br \/>\n<code>Client connecting to 192.168.2.10, TCP port 5001<\/code><br \/>\n<code>TCP window size: 8.00 KByte (default)<\/code><br \/>\n<code>------------------------------------------------------------<\/code><br \/>\n<code>[1912] local 192.168.1.10 port 1053 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1880] local 192.168.1.10 port 1054 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1864] local 192.168.1.10 port 1055 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1848] local 192.168.1.10 port 1056 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[ ID] Interval\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Transfer\u00a0\u00a0\u00a0\u00a0 Bandwidth<\/code><br \/>\n<code>[1864]\u00a0 0.0-60.5 sec\u00a0\u00a0 888 KBytes\u00a0\u00a0 120 Kbits\/sec<\/code><br \/>\n<code>[1848]\u00a0 0.0-60.9 sec\u00a0\u00a0 896 KBytes\u00a0\u00a0 120 Kbits\/sec<\/code><br \/>\n<code>[1880]\u00a0 0.0-61.2 sec\u00a0\u00a0 904 KBytes\u00a0\u00a0 121 Kbits\/sec<\/code><br \/>\n<code>[1912]\u00a0 0.0-61.2 sec\u00a0\u00a0 904 KBytes\u00a0\u00a0 121 Kbits\/sec<\/code><br \/>\n<strong><code>[SUM]\u00a0 0.0-61.2 sec\u00a0 3.51 MBytes\u00a0\u00a0 <span style=\"background-color: #ffff00;\">481 Kbits\/sec<\/span><\/code><\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small;\"><strong>Traffic Shaping with Excess Burst:<\/strong><\/span><\/p>\n<p>Traffic  shaping implements Be by making the token bucket bigger; of the size of  (Bc + Be). There are now Bc+Be worth of tokens in the bucket. Still, at  the start of each interval Tc, the Shaper fills the bucket with Bc  amount of tokens. However, if due to inactivity during some interval  (like in figure 1 above), the bucket can accommodate those Bc worth of  tokens since its size has been increased. Now, in the next Tc interval,  if there are more bits to send, the Shaper can use these Bc+Be tokens to  send that amount of bits. In essence, exceed the shaping rate as long  as there are extra tokens left in the bucket.<\/p>\n<p>The diagram below  shows that since there was no activity during fifth Tc interval, the  Shaper used up those extra tokens and sent Bc+Be worth of bits in the  sixth interval.<\/p>\n<p><a href=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-With-Be.PNG\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1103\" title=\"Traffic Shaping With Be\" src=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-With-Be.PNG\" alt=\"Traffic Shaping With Be\" width=\"688\" height=\"198\" srcset=\"http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-With-Be.PNG 688w, http:\/\/darenmatthews.com\/blog\/wp-content\/uploads\/2010\/11\/Traffic-Shaping-With-Be-300x86.PNG 300w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p><span style=\"font-size: small;\"><strong>Shaping at Peak rate:<\/strong><\/span><\/p>\n<p>With <strong>shape peak<\/strong>,  CB shaping allows Bc+Be bits to be sent every interval even if there  has been no period of inactivity. The Shaper replenishes Bc+Be tokens  into the bucket.<\/p>\n<p>In Cisco IOS, peak traffic shaping can be configured using <em><strong>shape peak &lt;shaping-rate&gt;<\/strong><\/em> command from policy-map configuration mode.<\/p>\n<p>The following example shows the configuration of peak traffic shaping. Traffic shaping is applied to outgoing TCP traffic generated via Iperf.<\/p>\n<div>\n<div style=\"width: 100%;\">\n<h4>peak traffic shaping<\/h4>\n<div>\n<div>\n<div dir=\"ltr\"><code>class-map P5001<\/code><br \/>\n<code> match access-group 101<\/code><br \/>\n<code>!<\/code><br \/>\n<strong><code>policy-map SHAPE<\/code><\/strong><br \/>\n<code> class 5001<\/code><br \/>\n<code> <strong style=\"background-color: #ffff00;\">shape peak percent 50<\/strong><\/code><br \/>\n<code>!<\/code><br \/>\n<code>interface fastethernet 0\/1<\/code><br \/>\n<code> bandwidth 1000<\/code><br \/>\n<code> <strong>service-policy output SHAPE<\/strong><\/code><br \/>\n<code>!<\/code><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Again, the Cisco IOS calculates the appropriate Bc and Be values. It uses Tc=24ms.<\/p>\n<div>\n<div style=\"width: 100%;\">\n<h4>Router output<\/h4>\n<div>\n<div>\n<div dir=\"ltr\"><strong><code>Router# show policy-map interface fastethernet 0\/1<\/code><\/strong><br \/>\n<code> FastEthernet0\/1<\/code><\/p>\n<p><code> Service-policy output: SHAPE<\/code><\/p>\n<p><code> Class-map: P5001 (match-all)<\/code><br \/>\n<code> 5335 packets, 7555414 bytes<\/code><br \/>\n<code> 5 minute offered rate 95000 bps, drop rate 0 bps<\/code><br \/>\n<code> Match: access-group 101<\/code><br \/>\n<code> <strong>Traffic Shaping<\/strong><\/code><br \/>\n<code> <strong>Target\/Average<\/strong> Byte\u00a0\u00a0 <strong>Sustain<\/strong> <strong>Excess<\/strong> <strong>Interval<\/strong> Increment<\/code><br \/>\n<code> Rate\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Limit\u00a0 <strong>bits\/int<\/strong> <strong>bits\/int<\/strong> <strong>(ms)<\/strong> (bytes)<\/code><br \/>\n<code> 50 (%)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 (ms)\u00a0\u00a0\u00a0\u00a0\u00a0 0 (ms)<\/code><br \/>\n<code> <span style=\"background-color: #ffff00;\">1000000\/500000<\/span> 3000\u00a0\u00a0 <span style=\"background-color: #ffff00;\">12000<\/span> <span style=\"background-color: #ffff00;\">12000<\/span> <span style=\"background-color: #ffff00;\">24<\/span> 3000<\/code><\/p>\n<p><code> Adapt\u00a0 Queue\u00a0\u00a0\u00a0\u00a0 Packets\u00a0\u00a0 Bytes\u00a0\u00a0\u00a0\u00a0 Packets\u00a0\u00a0 Bytes\u00a0\u00a0\u00a0\u00a0 Shaping<\/code><br \/>\n<code> Active Depth\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Delayed\u00a0\u00a0 Delayed\u00a0\u00a0 Active<\/code><br \/>\n<code> -\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5334\u00a0\u00a0\u00a0\u00a0\u00a0 7554468\u00a0\u00a0 5317\u00a0\u00a0\u00a0\u00a0\u00a0 7550502\u00a0\u00a0 no<\/code><\/p>\n<p><code> Class-map: class-default (match-any)<\/code><br \/>\n<code> 170 packets, 12700 bytes<\/code><br \/>\n<code> 5 minute offered rate 0 bps, drop rate 0 bps<\/code><br \/>\n<code> Match: any<\/code><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The Iperf output shows that the maximum throughput achieved this time is almost double than average shaping rate.<\/p>\n<h4>Iperf output<\/h4>\n<p><strong><code>C:\\&gt;iperf -c 192.168.2.10 -p 5001 -P 4 -t 60<\/code><\/strong><br \/>\n<code>------------------------------------------------------------<\/code><br \/>\n<code>Client connecting to 192.168.2.10, TCP port 5001<\/code><br \/>\n<code>TCP window size: 8.00 KByte (default)<\/code><br \/>\n<code>------------------------------------------------------------<\/code><br \/>\n<code>[1912] local 192.168.1.10 port 1061 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1880] local 192.168.1.10 port 1062 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1864] local 192.168.1.10 port 1063 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[1848] local 192.168.1.10 port 1064 connected with 192.168.2.10 port 5001<\/code><br \/>\n<code>[ ID] Interval\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Transfer\u00a0\u00a0\u00a0\u00a0 Bandwidth<\/code><br \/>\n<code>[1864]\u00a0 0.0-60.4 sec\u00a0 1.73 MBytes\u00a0\u00a0 240 Kbits\/sec<\/code><br \/>\n<code>[1880]\u00a0 0.0-60.5 sec\u00a0 1.73 MBytes\u00a0\u00a0 240 Kbits\/sec<\/code><br \/>\n<code>[1912]\u00a0 0.0-60.5 sec\u00a0 1.73 MBytes\u00a0\u00a0 240 Kbits\/sec<\/code><br \/>\n<code>[1848]\u00a0 0.0-60.5 sec\u00a0 1.73 MBytes\u00a0\u00a0 240 Kbits\/sec<\/code><br \/>\n<strong><code>[SUM]\u00a0 0.0-60.5 sec\u00a0 6.93 MBytes\u00a0\u00a0 <span style=\"background-color: #ffff00;\">960 Kbits\/sec<\/span><\/code><\/strong><\/p>\n<p><strong><span style=\"background-color: #ffff00;\"> <\/span><\/strong><br \/>\nKINDLY REPRODUCED FROM SOURCE: http:\/\/sites.google.com\/site\/amitsciscozone\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Traffic Shaping involves in queueing traffic rather than dropping it. Traffic Shaping terminology is:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83,76],"tags":[21],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1098"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1098"}],"version-history":[{"count":8,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1098\/revisions"}],"predecessor-version":[{"id":2125,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1098\/revisions\/2125"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1098"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}