Saturday, February 22, 2020

Peak Traffic Shaping on Cisco IOS

Cisco IOS routers support two types of shaping:
  • shape average
  • shape peak
In my first lesson I explained the basics of shaping and I demonstrated how to configure shape average. This time we will take a look at peak shaping which is often misunderstood and confusing for many networking students.


Shape Average

Here’s a quick recap of how shape average works:
shape token bucket bc be
We have a bucket and it can contain Bc and Be tokens. At the beginning of the Tc we will only fill the token bucket with the Bc but because it’s larger we can “save” tokens up to the Be level. The advantage of having a bigger bucket is that we can save tokens when we have periods of time where we send less bits than the configured shaping rate.
After a period of inactivity, we can send our Bc and Be tokens which allows us to burst for a short time. When we use a bucket that has Bc and Be, this is what our traffic pattern will look like:
shaping bc be explained
Above you can see that we start with a period where we are able to spend Bc and Be tokens, the next interval only the Bc tokens are renewed so we are only able to spend those. After awhile a period of inactivity allows us to fill our bucket again.

Shape Peak

Peak shaping uses the Be in a completely different way. We still have a token bucket that stores Bc + Be but will fill our token bucket with Bc and Be tokens each Tc and unused tokens will be discarded.
Here’s what our traffic pattern will look like:
Shaping Peak Visualized
Each Tc our Bc and Be tokens are renewed so we are able to spend them. A period of inactivity doesn’t mean anything.
Now you might be wondering why do we use this and what’s the point of it?
Depending on your traffic contract, an ISP might give you a CIR and PIR (Peak Information Rate). The rate is the guaranteed bandwidth that they offer you, the PIR is the maximum non-guaranteed rate that you could get when there is no congestion on the network. When there is congestion, this traffic might be dropped. ISPs typically use policing to enforce these traffic contracts.
The idea behind peak shaping is that we can configure shaping and take the CIR and PIR of the ISP into account.
When we send a lot of traffic, we will be spending the Bc and Be tokens each Tc and we are shaping up to the PIR. When there isn’t as much traffic to shape, we only spend Bc tokens and that’s when we are shaping up to the CIR.
Let’s look at an configuration example which will help to clarify things.

Configuration

I will use the following topology to demonstrate peak shaping:
shape peak topology iperf
Above we have two computers and two routers. The computers will be used to generate traffic with iPerf, I’ll configure peak shaping on R1. Let’s do a quick test with iPerf, time to start the server:
SERVER# iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
Now let’s generate some traffic:
CLIENT# iperf -c 192.168.2.2
------------------------------------------------------------
Client connecting to 192.168.2.2, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.1.1 port 42646 connected with 192.168.2.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   113 MBytes  94.9 Mbits/sec
Ok great, that’s close to 100 Mbit. That’s what we would expect from a FastEternet link. Now let’s take a look at the peak shaping configuration:
R1(config)#ip access-list extended IPERF_TRAFFIC
R1(config-ext-nacl)#permit tcp any any eq 5001
R1(config-ext-nacl)#exit

R1(config)#class-map IPERF
R1(config-cmap)#match access-group name IPERF_TRAFFIC
First we create an access-list that matches our iPerf traffic and we attach it to a class-map. Now we can configure the policy-map:
R1(config)#policy-map SHAPE_PEAK
R1(config-pmap)#class IPERF
R1(config-pmap-c)#shape peak ?
  <8000-154400000>  Target Bit Rate (bits/sec). (postfix k, m, g optional;
                    decimal point allowed)
  percent           % of interface bandwidth for Committed information rate
Above you see the shape peak command where we configure the target bit rate. The value that you specify here is the CIR, not the PIR! Let’s try a CIR of 128 Kbps:
R1(config-pmap-c)#shape peak 128000
Only thing left to do is to activate it on the interface:
R1(config)#interface FastEthernet 0/0
R1(config-if)#service-policy output SHAPE_PEAK
Now let’s try iPerf again:
CLIENT# iperf -c 192.168.2.2
SERVER#
[  5]  0.0-21.4 sec   640 KBytes   245 Kbits/sec
We can see that the shaper works since we only get a transfer rate of 245 Kbps. Let’s take a closer look at policy-map on R1:
R1#show policy-map interface FastEthernet 0/0
 FastEthernet0/0 

  Service-policy output: SHAPE_PEAK

    Class-map: IPERF (match-all)
      466 packets, 699180 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: access-group name IPERF_TRAFFIC
      Queueing
      queue limit 64 packets
      (queue depth/total drops/no-buffer drops) 0/9/0
      (pkts output/bytes output) 457/685554
      shape (peak) cir 128000, bc 512, be 512
      target shape rate 256000

    Class-map: class-default (match-any)
      32 packets, 3447 bytes
      5 minute offered rate 0 bps, drop rate 0 bps
      Match: any 
      
      queue limit 64 packets
      (queue depth/total drops/no-buffer drops) 0/0/0
      (pkts output/bytes output) 32/3447
Here’s what you see above:
Our CIR is 128000 bits per second (128 Kbps) which is what we configured with the shape peak command, our Bc and Be are 512 bits. Each TC our Bc and Be tokens are renewed, by using both we can shape up to the PIR of 256 Kbps. With the default settings, our Be and Bc have the same size so the PIR is 2 * CIR.

Conclusion

You have now seen how peak shaping works and how to configure it. Most students however are still confused after learning about peak shaping so let’s get a couple of things out of the way.
First of all, you need to keep in mind that the talk about CIR and PIR is only “cosmetic” when it comes to peak shaping. In the output of the router you can see a CIR and PIR but that’s it. It’s not like the router will automatically adapt its shaping rate up to the CIR or PIR or something. When we configure peak shaping, we set a maximum rate and the router will shape up to that rate…that’s it!
When there is a lot of traffic we will be shaping up to that maximum rate so we can say we are shaping up to the PIR of the ISP. When there isn’t as much traffic, maybe we are only using our Bc tokens so we can say that we are shaping up to the CIR but that’s it, it’s just talk.
One question I see all the time is that students ask if the following two commands will achieve the same thing:
  • shape peak 128000
  • shape average 256000
We have seen that shape peak 128000 gets us a PIR of 256 Kbps and shape average 256000 should get us a CIR of 256 kbps. Do we get the same result with both commands?
The answer is no although if you measure it, it will be insignificant. Let me explain this:
When we use shape average, each Tc we renew the Bc tokens which allows us to shape up to 256 Kbps. However after a period of inactivity and our bucket is full with Bc and Be tokens, we can spend both during a Tc which means we will shape up to 512 Kbps for a short time.
With peak shaping, we renew Bc and Be tokens each Tc, unused tokens are discarded so there is no way to get above 256 Kbps. Shape average would give a slightly better result but only after a period of inactivity.
The following commands however should give you the exact same result:
  • shape peak 128000
  • shape average 256000 1024 0
When you disable the Be tokens for shape average, it will be unable to burst so it can no longer get above 256 Kbps.
hostname R1
!
class-map match-all IPERF
 match access-group name IPERF_TRAFFIC
!
policy-map SHAPE_PEAK
 class IPERF
  shape peak 128000        
!
interface FastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
 duplex auto
 speed auto
 service-policy output SHAPE_PEAK
!
interface FastEthernet0/1
 ip address 192.168.1.254 255.255.255.0
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 192.168.12.2
!
ip access-list extended IPERF_TRAFFIC
 permit tcp any any eq 5001
!
end
hostname R2
!
interface FastEthernet0/0
 ip address 192.168.12.2 255.255.255.0
 duplex auto
 speed auto
!
interface FastEthernet0/1
 ip address 192.168.2.254 255.255.255.0
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 192.168.12.1
!
scheduler allocate 20000 1000
end
I hope this lesson has been useful, if you have any questions feel free to leave a comment!

No comments:

Post a Comment