Sunday 27 May 2012

IOS Based traffic generation with tcp-small-servers

Recently I was watching the INE vSeminar on OER - 7.5 hours of well I wouldn't exactly call it joy but it is certainly enlightening on how the performance routing (the current name for optimized edge routing) "works" in an IOS 12.4(15)T environment.   The version number is of relevance as that is currently what the CCIE Lab uses, however based on my own experiences and seeing the vSeminar, while quite powerful and flexible, it is also kind of fragile while you try to develop your configuration.

Anyway one of the interesting things that came out of it wasn't directly related to OER itself except that it needed some traffic flows to take actions upon and rather than purely using on pings, Brian demoed a different technique that used TCP traffic flows by enable "service tcp-small-servers" on the router you would like to generate the traffic from, and telneting on port 19 from where you would like the traffic sent.


Here's a quick demo with two routers:

R1
hostname R1
interface Loopback0
 ip address 1.1.1.1 255.255.255.255
!
interface Serial0/0
 no ip address
 encapsulation frame-relay
 no frame-relay inverse-arp
!
interface Serial0/0.12 point-to-point
 description R2 S0/0.21
 ip address 10.1.12.1 255.255.255.0
 frame-relay interface-dlci 102
!
router ospf 1
 log-adjacency-changes
 network 1.1.1.1 0.0.0.0 area 0
 network 10.1.12.1 0.0.0.0 area 0
!

R2
hostname R2
interface Loopback0
 ip address 2.2.2.2 255.255.255.255
!
interface Serial0/0
 no ip address
 encapsulation frame-relay
 no frame-relay inverse-arp
!
interface Serial0/0.21 point-to-point
 description R1 S0/0.12
 ip address 10.1.12.2 255.255.255.0
 frame-relay interface-dlci 201
!
router ospf 1
 log-adjacency-changes
 network 2.2.2.2 0.0.0.0 area 0
 network 10.1.12.2 0.0.0.0 area 0
!

First lets verify connectivity:

R2#ping 1.1.1.1 source 2.2.2.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 2.2.2.2
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms

Enabling tcp-small-servers enables the chargen service on TCP Port 19.  Other services such as echo, discard and daytime are enabled but aren't so helpful when it comes to traffic generation.


R1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#service tcp-small-servers

We cant see it but the router is listening to TCP Port 19

R1(config)#do sh tcp brief all
TCB       Local Address               Foreign Address             (state)
674596C8  *.80                        *.*                         LISTEN
 

R2#telnet 1.1.1.1 chargen /source-interface lo0
Trying 1.1.1.1, 19 ... Open
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghi
#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij
.....

The output on R2 is the chargen service on R1 which will run forever (or at least the session is closed) On R1 we can see the session is up and running.

R1(config)#do sh tcp brief all
TCB       Local Address               Foreign Address             (state)
665DEFFC  1.1.1.1.19                  2.2.2.2.20844               ESTAB
674596C8  *.80                        *.*                         LISTEN

Lets see how fast R1 is pushing out traffic

R1(config)#policy-map Monitor
R1(config-pmap)#class class-default
R1(config)#int s0/0.12
R1(config-subif)#service-policy output Monitor
R1(config-subif)#int s0/0
R1(config-if)#load-interval 30

We wait for a short period and see how fast R1 is going

R1(config-if)#do sh policy-map int s0/0.12 out

 Serial0/0.12

  Service-policy output: Monitor

    Class-map: class-default (match-any)
      10441 packets, 1232016 bytes
      30 second offered rate 56000 bps, drop rate 0 bps
      Match: any

Lets shape the outbound TCP traffic to 32kbps


R1(config)#ip access-list extended TCP
R1(config-ext-nacl)#permit tcp any any
R1(config-ext-nacl)#class TCP
R1(config-cmap)#match access-group name TCP
R1(config-cmap)#policy-map SHAPE_TCP
R1(config-pmap)#class TCP
R1(config-pmap-c)#shape average 32000
R1(config)#int s0/0.12
R1(config-subif)#no service-policy output Monitor
R1(config-subif)#service-policy output SHAPE_TCP

And leave things for a minute or so to see how things are operating

R1(config-subif)#do sh policy-map int s0/0.12 out

 Serial0/0.12

  Service-policy output: SHAPE_TCP

    Class-map: TCP (match-all)
      3810 packets, 449510 bytes
      30 second offered rate 32000 bps, drop rate 0 bps
      Match: access-group name TCP
      Traffic Shaping
           Target/Average   Byte   Sustain   Excess    Interval  Increment
             Rate           Limit  bits/int  bits/int  (ms)      (bytes)
            32000/32000     2000   8000      8000      250       1000

        Adapt  Queue     Packets   Bytes     Packets   Bytes     Shaping
        Active Depth                         Delayed   Delayed   Active
        -      26        3784      446442    3740      441320    yes

    Class-map: class-default (match-any)
      28 packets, 3320 bytes
      30 second offered rate 0 bps, drop rate 0 bps
      Match: any

TCP is adapting to the link bandwidth giving us a 32kbps stream we can play with elsewhere in our network.


If for whatever reason we found that the typical telnet escape sequence (Control+Shift+6 x) didn't work on R2, we can close the session from R1

R1(config)#do sh tcp brief all
TCB       Local Address               Foreign Address             (state)
665DEFFC  1.1.1.1.19                  2.2.2.2.20844               ESTAB
674596C8  *.80                        *.*                         LISTEN
R1(config-if)#do clear tcp local 1.1.1.1 19 remote 2.2.2.2 20844
[confirm]
 [OK]
R1(config-subif)#do sh tcp br all
TCB       Local Address               Foreign Address             (state)
674596C8  *.80                        *.*                         LISTEN

Probably not something useful for the CCIE Lab itself but for testing QoS in your own environment it may be useful.

No comments:

Post a Comment