Saturday, February 22, 2020

Cisco IOS IP SLA Traffic Generator

IP SLA is a great tool that you can use to make things like static routing more reliable but did you know you can also use it as a traffic generator?
When you configure IP SLA with the correct number of packets and payload sizes, you can use it to create certain traffic streams. This can be very useful when you want to practice QoS since you don’t have to mess around with traffic generator tools.
Before we look at the configuration, let’s do some calculations. Imagine we want to send 16 kbps of traffic from one router to another over Ethernet. How many packets should we send and what should the payload size be? Let’s take a look at the different header sizes first:
Ethernet Ip Udp Payload Sizes
Here is an example of a frame, an Ethernet header has 14 bytes, IP is 20 bytes and UDP is 8 bytes.

Calculate total frame size

Total frame size = L2 header + L3 header + L4 header + payload
My routers will be connected using Ethernet so that’s 14 bytes. IP adds another 20 bytes and UDP requires 8 bytes. The reason that I use UDP is that I will configure IP SLA to use UDP jitter.
14 + 20 + 8 = 42 bytes.
To keep the calculation simple, I’ll use a payload of 58 bytes so that the total packet will be 42 + 58 = 100 bytes.

Calculate Bandwidth

Bandwidth = frame size x number of packets
We know our frame size is 100 bytes so how many packets should we send per second? Our goal is to generate 16 kbps of traffic, that’s 16.000 bits per second. This is how we calculate it:
Number of packets = bandwidth / frame size
Before we can do this, we need to convert our 16.000 bits to bytes:
16.000 bits / 8 = 2000 bytes.
Our packet size is 100 bytes and we need 2000 bytes per second to reach 16 kbps:
2000 / 100 = 20
We need to send 20 packets per second with a frame size of 100 bytes to hit 16 kbps!
So far so good? Let’s start the configuration…

Configuration

To demonstrate IP SLA we will use two routers connected to each other with Ethernet, R1 and R2:
R1 R2
Let’s start with the configuration of R1:
ip sla 1
 udp-jitter 192.168.12.2 17001 num-packets 20
 request-data-size 58
 threshold 500
 timeout 500
 frequency 1
ip sla schedule 1 life forever start-time now
As calculated we will send 20 packets per second with a payload size of 58. This will be good for 16 kbps but I will show you how to verify this in a bit. I used destination port 17002 (pick whatever you like) for this instance.
Let me give you another example for a bandwidth rate of 32 kbps:
ip sla 2
 udp-jitter 192.168.12.2 17002 num-packets 20
 request-data-size 158
 threshold 500
 timeout 500
 frequency 1
ip sla schedule 2 life forever start-time now
The total frame size is 14 + 20 + 8 + 158 = 200 bytes.  We multiply 200 by 20 packets per second which gives us 4000 bytes per second. 4000 x 8 = 32.000 bps or 32 kbps. Note that I’m using another destination port number here.
Let’s add one for 64 kbps as well:
ip sla 3
 udp-jitter 192.168.12.2 17003 num-packets 20
 request-data-size 358
 threshold 500
 timeout 500
 frequency 1
ip sla schedule 3 life forever start-time now
Total frame size is 14 + 20 + 8 + 358 = 400 bytes. 400 x 20 = 8.000 bytes per second. 8.000 x 8 = 64.000 bps or 64 kbps. And while we are at it, let’s add one more for 128 kbps:
ip sla 4
 udp-jitter 192.168.12.2 17004 num-packets 20
 request-data-size 758
 threshold 500
 timeout 500
 frequency 1
ip sla schedule 4 life forever start-time now
Frame size is 14 + 20 + 8 + 758 = 800 bytes. 800 x 20 = 16.000 bytes per second. 16.000 x 8 = 128.000 bps or 128 kbps.
R1 is now generating a 16, 32 ,64 and 128 kbps stream. Let’s head to R2 and verify our work.

Verification

A good method to measure the incoming bandwidth rate is to use a policy-map. We will configure an access-list for each bandwidth rate and match it using the port number we used for each IP SLA instance. Each access-list is attached to a class-map and we add all class-maps to a policy-map without any actions. This is what it looks like:
ip access-list extended IP_SLA_1
 permit udp any host 192.168.12.2 eq 17001

ip access-list extended IP_SLA_2
 permit udp any host 192.168.12.2 eq 17002

ip access-list extended IP_SLA_3
 permit udp any host 192.168.12.2 eq 17003

ip access-list extended IP_SLA_4
 permit udp any host 192.168.12.2 eq 17004

class-map match-all IP_SLA_1
 match access-group name IP_SLA_1

class-map match-all IP_SLA_2
 match access-group name IP_SLA_2

class-map match-all IP_SLA_3
 match access-group name IP_SLA_3

class-map match-all IP_SLA_4
 match access-group name IP_SLA_4

policy-map TRAFFIC_METER
 class IP_SLA_1
 class IP_SLA_2
 class IP_SLA_3
 class IP_SLA_4
Don’t forget to attach the policy-map to the interface:
R2(config)#interface fastEthernet 0/0
R2(config-if)#service-policy input TRAFFIC_METER
R2(config-if)#load-interval 30
The load-interval command tells the router to update the interface statistics every 30 seconds. By default it’s 60 seconds so this speeds things up a little. Let’s look at the policy-map:
R2#show policy-map interface fastEthernet 0/0
 FastEthernet0/0 

  Service-policy input: TRAFFIC_METER

    Class-map: IP_SLA_1 (match-all)
      60066 packets, 6006600 bytes
      30 second offered rate 16000 bps
      Match: access-group name IP_SLA_1

    Class-map: IP_SLA_2 (match-all)
      60060 packets, 12012000 bytes
      30 second offered rate 32000 bps
      Match: access-group name IP_SLA_2

    Class-map: IP_SLA_3 (match-all)
      60060 packets, 24024000 bytes
      30 second offered rate 64000 bps
      Match: access-group name IP_SLA_3

    Class-map: IP_SLA_4 (match-all)
      60060 packets, 48048000 bytes
      30 second offered rate 128000 bps
      Match: access-group name IP_SLA_4
          
    Class-map: class-default (match-any)
      12013 packets, 1129222 bytes
      30 second offered rate 3000 bps, drop rate 0 bps
      Match: any 
Excellent, we have exactly 16, 32, 64 and 128 kbps and it’s measured every 30 seconds!
I hope this tutorial has been helpful to you. If you have any questions feel free to leave a comment and if you enjoyed it, please share it with your friends.

No comments:

Post a Comment