Showing posts with label SLA. Show all posts
Showing posts with label SLA. Show all posts

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.

IP SLA (Service-Level Agreement) on Cisco IOS

IP SLA (Service-Level Agreement) is a great feature on Cisco IOS devices that can be used to “measure” network performance.
This can be something simple like a ping where we check the round-trip time or something more advanced like a VoIP RTP packet where we check the delay, jitter and calculate a MOS score that gives you an indication what the voice quality will be like.
Measuring network performance is pretty cool but what makes IP SLA even more powerful is that you can combine it with static routes, policy based routing and routing protocols like OSPF or EIGRP.
Let me give you an example why this is a great feature to use. Take a look at the image below:
Customer ISP1 ISP2 Default Route
Above we have a customer router connected to two ISPs. Somewhere on the Internet there’s a server we’d like to reach. In a scenario like this, typically we use two default routes with different ADs. Whenever ISP1 fails, we switch over to ISP2.
The problem with this setup is that it’s not very reliable. The default route will be in the routing table as long as the interface is up and/or the next hop is reachable. It’s possible that ISP1 is having connectivity issues and unable to reach that remote server but we still use them for all our traffic.
To prevent this from happening we can combine default routes with IP SLA. Here’s an example:
Customer ISP1 ISP2 IP SLA ICMP
Our customer router is now using IP SLA to ping the remote server. As long as we get a reply, we will keep using ISP1 as our main route. When the ping fails, we switch over to ISP2. This method is far more reliable as we check end-to-end connectivity.
Here’s another example where IP SLA might be useful:
HQ Branch IP SLA RTP Probe
Above we have two ISPs that we can use to reach a remote branch router. Instead of a simple ping, we can send RTP packets and check these for a certain delay, jitter and calculate a MOS score. When we get below a certain threshold we will switch from ISP1 to ISP2.
Each measurement that we do with IP SLA is called an operation. For each operation we have to configure the type of traffic, source IP, destination IP, port numbers, etc. We can then configure when to run the operation…24/7, 9-to-5, etc.
When you use IP SLA for a simple ping then you only have to configure your local router. However when you want to use it for some more advanced things like sending RTP packets then you have to configure the remote router to respond to your IP SLA traffic.
Besides pings and RTP, there are a lot of different operations we can use:
  • TCP Connections
  • UDP
  • DNS
  • DHCP
  • HTTP
  • FTP
Now you have an idea what IP SLA is about, let’s take a look how we can configure an operation.

Configuration

I will show you two examples so you will learn how to configure IP SLA operations. We’ll try an example with pings and an example with UDP jitter.

ICMP echo Operation

We will use the following topology:
R1 R2 FastEthernet
All I need is two routers, R1 will send ICMP echo requests and R2 will reply to them. Here’s how to configure IP SLA:
R1(config)#ip sla 1
R1(config-ip-sla)#?
IP SLAs entry configuration commands:
  dhcp         DHCP Operation
  dns          DNS Query Operation
  ethernet     Ethernet Operations
  exit         Exit Operation Configuration
  ftp          FTP Operation
  http         HTTP Operation
  icmp-echo    ICMP Echo Operation
  icmp-jitter  ICMP Jitter Operation
  mpls         MPLS Operation
  path-echo    Path Discovered ICMP Echo Operation
  path-jitter  Path Discovered ICMP Jitter Operation
  tcp-connect  TCP Connect Operation
  udp-echo     UDP Echo Operation
  udp-jitter   UDP Jitter Operation
  voip         Voice Over IP Operation
First we have to choose an operation number, let’s pick number 1. You can see that there are a lot of different operations we can choose from. Let’s start with the icmp echo:
R1(config-ip-sla)#icmp-echo 192.168.12.2 
R1(config-ip-sla-echo)#?  
IP SLAs Icmp Echo Configuration Commands:
  default            Set a command to its defaults
  exit               Exit operation configuration
  frequency          Frequency of an operation
  history            History and Distribution Data
  no                 Negate a command or set its defaults
  owner              Owner of Entry
  request-data-size  Request data size
  tag                User defined tag
  threshold          Operation threshold in milliseconds
  timeout            Timeout of an operation
  tos                Type Of Service
  verify-data        Verify data
  vrf                Configure IP SLAs for a VPN Routing/Forwarding instance
Let’s send ICMP echos to 192.168.12.2. There are a lot of optional parameters you can configure for an operation, for example let’s change the frequency:
R1(config-ip-sla-echo)#frequency 10
We’ll send an ICMP echo every 10 seconds. The only thing left to do is to start our IP SLA operation. This is how you do it:
R1(config)#ip sla schedule 1 ?
  ageout      How long to keep this Entry when inactive
  life        Length of time to execute in seconds
  recurring   Probe to be scheduled automatically every day
  start-time  When to start this entry
  <cr>
You have to use the ip sla schedule command to start your operation. You can schedule it but we will start our operation right now and let it run forever:
R1(config)#ip sla schedule 1 start-time ?
  after     Start after a certain amount of time from now
  hh:mm     Start time (hh:mm)
  hh:mm:ss  Start time (hh:mm:ss)
  now       Start now
  pending   Start pending
R1(config)#ip sla schedule 1 start-time now ?
  ageout     How long to keep this Entry when inactive
  life       Length of time to execute in seconds
  recurring  Probe to be scheduled automatically every day
R1(config)#ip sla schedule 1 start-time now life ?
  <0-2147483647>  Life seconds (default 3600)
  forever         continue running forever
R1(config)#ip sla schedule 1 start-time now life forever
It should now be up and running. You can check your IP SLA configuration like this:
R1#show ip sla configuration 
IP SLAs Infrastructure Engine-III
Entry number: 1
Owner: 
Tag: 
Operation timeout (milliseconds): 5000
Type of operation to perform: icmp-echo
Target address/Source address: 192.168.12.2/0.0.0.0
Type Of Service parameter: 0x0
Request size (ARR data portion): 28
Verify data: No
Vrf Name: 
Schedule:
   Operation frequency (seconds): 10  (not considered if randomly scheduled)
   Next Scheduled Start Time: Start Time already passed
   Group Scheduled : FALSE
   Randomly Scheduled : FALSE
   Life (seconds): Forever
   Entry Ageout (seconds): never
   Recurring (Starting Everyday): FALSE
   Status of entry (SNMP RowStatus): Active
Threshold (milliseconds): 5000
Distribution Statistics:
   Number of statistic hours kept: 2
   Number of statistic distribution buckets kept: 1
   Statistic distribution interval (milliseconds): 20
Enhanced History:
History Statistics:
   Number of history Lives kept: 0
   Number of history Buckets kept: 15
   History Filter Type: None
Above you can see the details of our IP SLA operation. A lot of parameters are configured by default. This is how you can check if it’s running or not:
R1#show ip sla statistics 
IPSLAs Latest Operation Statistics

IPSLA operation id: 1
 Latest RTT: 1 milliseconds
Latest operation start time: 13:51:18 UTC Tue Jul 7 2015
Latest operation return code: OK
Number of successes: 5
Number of failures: 1
Operation time to live: Forever
Use the show ip sla statistics command to see the results. You can see my pings are successful and our round trip time is only 1 ms.
hostname R1
!
interface FastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
ip sla 1
 icmp-echo 192.168.12.2 
 frequency 10
!
ip sla schedule 1 start-time now life forever
!
end
hostname R2
!
interface FastEthernet0/0
 ip address 192.168.12.2 255.255.255.0
!
end

Let’s try another example!

UDP Jitter Operation

We’ll use the same topology:
R1 R2 FastEthernet
This time we’ll use UDP packets to simulate G711 VoIP traffic. Let’s start another operation:
R1(config)#ip sla 2
R1(config-ip-sla)#udp-jitter 192.168.12.2 16384 codec g711alaw 
R1(config-ip-sla-jitter)#frequency 60
R1(config-ip-sla-jitter)#tos 184
For this operation I used destination 192.168.12.2 and source port 16384. The codec is G711alaw. We’ll send a probe every 60 seconds and the TOS byte is 184 (equals DSCP 46 or EF). Let’s start it:
R1(config)#ip sla schedule 2 life forever start-time now
This finishes our configuration on R1 but we still have something to do on R2:
R2(config)#ip sla responder
The ip sla responder command is required on R2 otherwise it will drop our UDP packets. Let’s verify our work:
R1#show ip sla configuration 2
IP SLAs Infrastructure Engine-III
Entry number: 2
Owner: 
Tag: 
Operation timeout (milliseconds): 5000
Type of operation to perform: udp-jitter
Target address/Source address: 192.168.12.2/0.0.0.0
Target port/Source port: 16384/0
Type Of Service parameter: 0xB8
Codec Type: g711alaw
Codec Number Of Packets: 1000
Codec Packet Size: 172
Codec Interval (milliseconds): 20
Advantage Factor: 0
Verify data: No
Vrf Name: 
Control Packets: enabled
Schedule:
   Operation frequency (seconds): 60  (not considered if randomly scheduled)
   Next Scheduled Start Time: Start Time already passed
   Group Scheduled : FALSE
   Randomly Scheduled : FALSE
   Life (seconds): Forever
   Entry Ageout (seconds): never
   Recurring (Starting Everyday): FALSE
   Status of entry (SNMP RowStatus): Active
Threshold (milliseconds): 5000
Distribution Statistics:
   Number of statistic hours kept: 2
   Number of statistic distribution buckets kept: 1
   Statistic distribution interval (milliseconds): 20
Enhanced History:
Above you can see the complete configuration for this operation. If you want to see the statistics, take a look below:
R1#show ip sla statistics 2
IPSLAs Latest Operation Statistics

IPSLA operation id: 2
Type of operation: udp-jitter
 Latest RTT: 2 milliseconds
Latest operation start time: 14:21:27 UTC Tue Jul 7 2015
Latest operation return code: OK
RTT Values:
 Number Of RTT: 1000  RTT Min/Avg/Max: 2/2/3 milliseconds
Latency one-way time:
 Number of Latency one-way Samples: 0
 Source to Destination Latency one way Min/Avg/Max: 0/0/0 milliseconds
 Destination to Source Latency one way Min/Avg/Max: 0/0/0 milliseconds
Jitter Time:
 Number of SD Jitter Samples: 999
 Number of DS Jitter Samples: 999
 Source to Destination Jitter Min/Avg/Max: 0/1/1 milliseconds
 Destination to Source Jitter Min/Avg/Max: 0/1/1 milliseconds
Packet Loss Values:
 Loss Source to Destination: 0
 Source to Destination Loss Periods Number: 0
 Source to Destination Loss Period Length Min/Max: 0/0
 Source to Destination Inter Loss Period Length Min/Max: 0/0
        Loss Destination to Source: 0
 Destination to Source Loss Periods Number: 0
 Destination to Source Loss Period Length Min/Max: 0/0
 Destination to Source Inter Loss Period Length Min/Max: 0/0
 Out Of Sequence: 0 Tail Drop: 0
 Packet Late Arrival: 0 Packet Skipped: 0
Voice Score Values:
 Calculated Planning Impairment Factor (ICPIF): 1
 MOS score: 4.34
Number of successes: 2
Number of failures: 1
Operation time to live: Forever
Above you can see our results, how often these probes have been sent and at the bottom you can see the MOS score which was calculated. This is based on a scale from 1 – 5 so 4.34 is pretty good.
hostname R1
!
interface FastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
ip sla 2
 udp-jitter 192.168.12.2 16384 codec g711alaw 
 frequency 60
 tos 184
!
ip sla schedule 2 life forever start-time now
!
end
hostname R2
!
interface FastEthernet0/0
 ip address 192.168.12.2 255.255.255.0
!
ip sla responder
!
end

Conclusion

You have now seen how you can use IP SLA operations to measure your network performance. In other lessons I will show you how you can combine IP SLA with static routes, PBR and a routing protocol.
If you have any questions, feel free to leave a comment!

Thursday, February 20, 2020

Reliable Static Routing with IP SLA

IP SLA is a great tool on Cisco routers that allows us to generate traffic which can be used to check delay/latency, jitter but can also be combined with object tracking. This allows us to check the reachability of a certain IP address (by pinging) or a certain service by connecting to it (using TCP). If the IP address/service is unreachable we can apply a certain action. A simple example to demonstrate IP SLA is when you have a single router that is connected to two ISPs:
R1-ISP1-ISP2
Above we have a router (R1) that is connected to two ISPs. We want to use ISP1 as the primary and ISP2 as the backup link. All traffic will be sent towards ISP1 but when it’s unreachable we’ll switch over to ISP2. You can achieve this by using two default routes:
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.2
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.13.3 2
By default a static route has an AD (Administrative Distance) of 1, that’s why I configured the second static route towards ISP2 to have an AD of 2. Having a static route with a higher administrative distance is also called a floating static route. When we look at the routing table of R1 this is what you’ll see:
R1#show ip route static 
S*   0.0.0.0/0 [1/0] via 192.168.12.2
Above you will only see the route towards ISP1 because it has a lower AD. Now let’s shut the interface towards ISP1 to see what will happen with the routing table:
R1(config)#interface fa0/0
R1(config-if)#shutdown
R1(config-if)#exit
This is what you will find:
R1#show ip route static 
S*   0.0.0.0/0 [2/0] via 192.168.13.3
Now everything will be sent towards ISP2 which is great. This solution is quick and simple but it has some potential problems…a static route will always remain in the routing table unless the interface goes down. It’s possible that the link towards ISP1 is up and running but that the ISP1 router itself is unreachable or that ISP1 has problems on their network that prevents us from reaching the Internet through them. This is why we’ll use IP SLA to make our default route more reliable. First let’s unshut the interface:
R1(config)#interface fa0/0
R1(config-if)#no shutdown
I will create an IP SLA instance that pings the IP address of the ISP1 router:
R1(config)#ip sla 1
R1(config-ip-sla)#icmp-echo 192.168.12.2 
R1(config-ip-sla-echo)#timeout 100
R1(config-ip-sla-echo)#frequency 1
R1(config-ip-sla-echo)#exit
R1(config)#ip sla schedule 1 start-time now life forever 
We will ping IP address 192.168.12.2 each second and when we don’t get a response within 100 Ms we will believe it’s unreachable. You might want to play with these values a bit on a production network. Let’s see if IP SLA works:
R1#show ip sla statistics 

Round Trip Time (RTT) for Index 1
 Latest RTT: 4 milliseconds
Latest operation start time: *00:09:07.235 UTC Fri Mar 1 2002
Latest operation return code: OK
Number of successes: 43
Number of failures: 1
Operation time to live: Forever
It seems to be working, right now it only takes 4 milliseconds to get a response. As long as it stays below 100 milliseconds we’ll be fine. Let’s configure the default route to use IP SLA:
R1(config)#no ip route 0.0.0.0 0.0.0.0 192.168.12.2
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.2 track 1
First I’ll remove the old default route and replace it with one that says “track 1”. I can’t connect IP SLA directly with the static route, I have to do this with object tracking. This is how you combine object tracking with IP SLA:
R1(config)#track 1 rtr 1
The command above combines object tracking instance 1 with the IP SLA instance that I configured. Let’s see if this will work…
R1#show ip route static 
S*   0.0.0.0/0 [1/0] via 192.168.12.2
Right now everything is working as it should, we use ISP1 for the default route. Curious what happens once ISP1 becomes unreachable?
ISP1(config)#interface fastEthernet 0/0
ISP1(config-if)#shutdown
We’ll shut the interface on ISP1 and this is what you will find on R1:
R1#
%TRACKING-5-STATE: 1 rtr 1 state Up->Down
Object tracking will kick in because we are no longer able to ping the IP address of ISP1. This is what you’ll see in the routing table:
R1#show ip route static   
S*   0.0.0.0/0 [2/0] via 192.168.13.3
We now send all traffic towards ISP2. What will happen once ISP1 is reachable again?
ISP1(config)#interface fastEthernet 0/0
ISP1(config-if)#no shutdown
Bring back the interface to the land of the living and this is what you’ll discover on R1:
R1#
%TRACKING-5-STATE: 1 rtr 1 state Down->Up
Object tracking tells us that we can reach ISP1 again and the routing table will be updated:
R1#show ip route static 
S*   0.0.0.0/0 [1/0] via 192.168.12.2
There we go, ISP1 is being used again as the primary ISP.
Instead of pinging the ISP’s router IP address it might be a better idea to ping something on the Internet or to configure IP SLA to connect to a device using TCP. Pinging the ISP proves that we can reach the ISP but doesn’t necessarily mean that we can reach the Internet.
hostname ISP1
!
interface FastEthernet0/0
 ip address 192.168.12.2 255.255.255.0
!
end
hostname ISP2
!
interface FastEthernet0/0
 ip address 192.168.13.3 255.255.255.0
!
end
hostname R1
!
interface FastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
interface FastEthernet0/1
 ip address 192.168.13.1 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 192.168.12.2 track 1
ip route 0.0.0.0 0.0.0.0 192.168.13.3 2
!
ip sla 1
 icmp-echo 192.168.12.2 
 timeout 100
 frequency 1
!
ip sla schedule 1 start-time now life forever 
!
track 1 rtr 1
!
end

I hope this is useful to you, if you have any questions feel free to ask by leaving a comment!