Difference between revisions of "VPP/How To Use The Packet Generator and Packet Tracer"

From fd.io
< VPP
Jump to: navigation, search
(Use a PCAP file with PG)
 
(One intermediate revision by the same user not shown)
Line 13: Line 13:
 
==== Step 1. Start a debug version of vpp ====
 
==== Step 1. Start a debug version of vpp ====
  
From the command line, make the build-root directory the working directory and run vpp from the /bin directory as shown in the following example.  
+
From the command line, make the VPP source directory the working directory and run VPP as shown in the following example.  
  
 
In the following example, including the <code>dpdk</code> argument means that no physical interfaces will be discovered.
 
In the following example, including the <code>dpdk</code> argument means that no physical interfaces will be discovered.
  
  $ cd ../build-root
+
  $ ./build-root/install-vpp_debug-native/vpp/bin/vpp unix interactive plugins { plugin dpdk_plugin.so { disable } }
$ ./install-vpp_debug-native/vpp/bin/vpp unix interactive dpdk {no-pci no-huge num-mbufs 8192}
+
  
 
==== Step 2. Execute the arp4 setup script ====
 
==== Step 2. Execute the arp4 setup script ====
Line 24: Line 23:
 
From the vpp debug command-line, execute the arp4 script.
 
From the vpp debug command-line, execute the arp4 script.
  
  DBGvpp# exec /vpp/vnet/etc/scripts/arp4
+
  DBGvpp# exec src/scripts/vnet/arp4
  
 
==== Step 3. Examine the setup script ====
 
==== Step 3. Examine the setup script ====
Line 42: Line 41:
 
   }
 
   }
 
  }
 
  }
 
+
 
  trace add pg-input 100
 
  trace add pg-input 100
 
  loop create
 
  loop create
Line 52: Line 51:
 
  set int ip address loop1 2.0.0.1/24
 
  set int ip address loop1 2.0.0.1/24
  
The first stanza creates a packet generator stream called "x" which sends a single ipv4 icmp echo-request when enabled. The <code>trace add</code> command arranges to trace 100 packets originating at the <code>pg-input</code> graph node. If you want to trace packets originating at the "dpdk-input" node - which is probably the most typical real-world use-case - make the substitution for that graph node.
+
The first stanza creates a packet generator stream called "x" which sends a single ipv4 icmp echo-request when enabled. The <code>trace add</code> command arranges to trace 100 packets originating at the <code>pg-input</code> graph node. If you want to trace packets originating at the "ethernet-input" node - which is probably the most typical real-world use-case - make the substitution for that graph node.
  
 
Finally, the script configures a couple of loopback interfaces; primarily, so that ip4-input / ip4-lookup won't immediately ditch the generated packet.
 
Finally, the script configures a couple of loopback interfaces; primarily, so that ip4-input / ip4-lookup won't immediately ditch the generated packet.
Line 68: Line 67:
  
 
  DBGvpp# show trace
 
  DBGvpp# show trace
DBGvpp# show trace
+
  ------------------- Start of thread 0 vpp_main -------------------
  ------------------- Start of thread 0 -------------------
+
 
  Packet 1
 
  Packet 1
 
   
 
   
  00:02:37:928917: pg-input
+
  00:00:21:923147: pg-input
   stream x, 64 bytes
+
   stream x, 64 bytes, sw_if_index 1
   current data 0, length 64, free-list 2, trace 0x0
+
   current data 0, length 64, buffer-pool 0, ref-count 1, trace handle 0x0
 
   ICMP: 1.0.0.2 -> 2.0.0.2
 
   ICMP: 1.0.0.2 -> 2.0.0.2
     tos 0x00, ttl 64, length 64, checksum 0x77ba
+
     tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
 
     fragment id 0x0000
 
     fragment id 0x0000
   ICMP echo_request checksum 0x7a6e
+
   ICMP echo_request checksum 0x7a6e id 1
  00:02:37:928960: ip4-input
+
  00:00:21:923216: ip4-input
 
   ICMP: 1.0.0.2 -> 2.0.0.2
 
   ICMP: 1.0.0.2 -> 2.0.0.2
     tos 0x00, ttl 64, length 64, checksum 0x77ba
+
     tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
 
     fragment id 0x0000
 
     fragment id 0x0000
   ICMP echo_request checksum 0x7a6e
+
   ICMP echo_request checksum 0x7a6e id 1
  00:02:37:928979: ip4-arp
+
  00:00:21:923252: ip4-not-enabled
  fib: 0 adjacency: arp loop1 2.0.0.1/24 flow hash: 0x00000000
+
    ICMP: 1.0.0.2 -> 2.0.0.2
00:02:37:929005: loop1-output
+
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
  loop1
+
      fragment id 0x0000
  ARP: de:ad:00:00:00:01 -> ff:ff:ff:ff:ff:ff
+
    ICMP echo_request checksum 0x7a6e id 1
  request, type ethernet/IP4, address size 6/4
+
00:00:21:923261: error-drop
  de:ad:00:00:00:01/2.0.0.1 -> 00:00:00:00:00:00/2.0.0.2
+
  rx:pg0
  00:02:37:929010: error-drop
+
  00:00:21:923270: drop
   ip4-arp: ARP requests sent
+
   null-node: blackholed packets
  loop1-output: interface is down
+
  
==== Step 6. Examine the IPv4 default VRF table ====
+
==== Step 6. Analyze the information ====
  
Use the <code>show ip fib</code> command to see the VRF table.
+
You can see in the trace above that the packet goes through "ip4-not-enabled" before being dropped. This is because the interface used to inject the packet (pg0 by default) has no IPv4 configuration and hence ARP is not enabled.
 
+
Here's the contents of the IPv4 default VRF table after the arp4 script was executed:
+
 
+
DBGvpp# show ip fib
+
Table 0, fib_index 0, flow hash: src dst sport dport proto
+
      Destination        Packets          Bytes        Adjacency 
+
1.0.0.0/24                        0              0 weight 1, index 3
+
                                                      arp loop0 1.0.0.1/24
+
1.0.0.1/32                        0              0 weight 1, index 4
+
                                                      local 1.0.0.1/24
+
2.0.0.0/24                        0              0 weight 1, index 5
+
                                                      arp loop1 2.0.0.1/24
+
2.0.0.1/32                        0              0 weight 1, index 6
+
                                                    local 2.0.0.1/24
+
 
+
When we enable the packet generator stream, we observe a lookup hit on 2.0.0.0/24:
+
 
+
DBGvpp# sh ip fib
+
Table 0, fib_index 0, flow hash: src dst sport dport proto
+
      Destination        Packets          Bytes        Adjacency 
+
1.0.0.0/24                        0              0 weight 1, index 3
+
                                                      arp loop0 1.0.0.1/24
+
1.0.0.1/32                        0              0 weight 1, index 4
+
                                                      local 1.0.0.1/24
+
2.0.0.0/24                        1              78 weight 1, index 5
+
                                                      arp loop1 2.0.0.1/24
+
2.0.0.1/32                        0              0 weight 1, index 6
+
                                                    local 2.0.0.1/24
+
 
+
==== Step 7. Analyze the information ====
+
  
 
Inspecting the error counters you see what we might expect in light of the packet tracer output:
 
Inspecting the error counters you see what we might expect in light of the packet tracer output:
  
 
  DBGvpp# sh err
 
  DBGvpp# sh err
      Count                       Node                         Reason      
+
    Count                 Node                             Reason               Severity
              1                 ip4-arp                ARP requests sent
+
          1             null-node                      blackholed packets          error
              1              loop1-output              interface is down
+
  
 +
You can enable IPv4 on pg0 by configuring it as eg. unnumbered:
  
=== Convert a PCAP file to a PG file ===
+
DBGvpp# set int unnumbered pg0 use loop0
  
The below is a ping PCAP capture converted into Packet Generator (PG) format.
+
And look at the result when re-injecting the packet:
  
1. Use the PCAP2PG converter utility in the source tree
+
DBGvpp# clear trace
 
+
DBGvpp# trace add pg-input 10
  cd /vpp/build-root/build-vpp_debug-native/vnet/
+
  DBGvpp# packet-generator enable-stream
  ./pcap2pg -i vpp1.pcap > vpp1.pg
+
  DBGvpp# show trace
  edit vpp1.pg
+
  ------------------- Start of thread 0 vpp_main -------------------
 
+
Packet 1
2. Each line in the PCAP file is wrapped in Packet-Generator specific information:
+
 
+
00:05:44:786471: pg-input
  packet-generator new {
+
  stream x, 64 bytes, sw_if_index 1
    name s0
+
  current data 0, length 64, buffer-pool 0, ref-count 1, trace handle 0x0
    limit 1
+
  ICMP: 1.0.0.2 -> 2.0.0.2
    size 98-98
+
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    node ethernet-input
+
    fragment id 0x0000
    data {
+
  ICMP echo_request checksum 0x7a6e id 1
          0x0800: b66a.2a78.efb3 -> 02fe.6613.e729
+
00:05:44:786501: ip4-input
      hex 0x45000054c622400040011962ac100102ac1002020800cb807f4f00016cf0f756000000008514050000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 }
+
  ICMP: 1.0.0.2 -> 2.0.0.2
  }
+
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
 
+
    fragment id 0x0000
  packet-generator new {
+
  ICMP echo_request checksum 0x7a6e id 1
    name s1
+
00:05:44:786513: ip4-lookup
    limit 1
+
  fib 0 dpo-idx 3 flow hash: 0x00000000
    size 98-98
+
  ICMP: 1.0.0.2 -> 2.0.0.2
    node ethernet-input
+
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    data {
+
    fragment id 0x0000
          0x0800: 02fe.6613.e729 -> b66a.2a78.efb3
+
  ICMP echo_request checksum 0x7a6e id 1
      hex 0x450000543fee00003f01e096ac100202ac1001020000d3807f4f00016cf0f756000000008514050000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 }
+
00:05:44:786523: ip4-glean
  }
+
    ICMP: 1.0.0.2 -> 2.0.0.2
 
+
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
  packet-generator new {
+
      fragment id 0x0000
    name s2
+
    ICMP echo_request checksum 0x7a6e id 1
    limit 1
+
00:05:44:786547: ip4-drop
    size 98-98
+
    ICMP: 1.0.0.2 -> 2.0.0.2
    node ethernet-input
+
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    data {
+
      fragment id 0x0000
          0x0800: b66a.2a78.efb3 -> 02fe.6613.e729
+
    ICMP echo_request checksum 0x7a6e id 1
      hex 0x45000054c63540004001194fac100102ac10020208006d837f4f00026df0f75600000000e210050000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 }
+
  00:05:44:786568: error-drop
  }
+
  rx:pg0
 
+
00:05:44:786591: drop
3. Remove any lines of PCAP and add an interface. You can also change the limit to increase the number of packets (useful for testing dual loop)
+
  ip4-glean: ARP requests sent
  
  packet-generator new {
+
=== Use a PCAP file with PG ===
    name s0
+
    '''limit 1'''
+
    size 98-98
+
    node ethernet-input
+
    '''interface GigabitEthernet0/8/0'''
+
    data {
+
          0x0800: b66a.2a78.efb3 -> 02fe.6613.e729
+
      hex 0x45000054c622400040011962ac100102ac1002020800cb807f4f00016cf0f756000000008514050000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 }
+
  }
+
  
4. Proceed as per above example
+
The packet generator can also replay a pcap file directly, for example:
  
   DBGvpp# exec <fullpath>/vpp1.pg
+
   DBGvpp# create packet-generator interface pg0
   DBGvpp# packet-generator enable
+
  DBGvpp# packet-generator new pcap /tmp/mypcap.pcap source pg0 name s
  etc etc
+
   DBGvpp# packet-generator enable-stream

Latest revision as of 09:53, 25 February 2021

Introduction

The VPP platform includes packet generation and packet tracing facilities.

The following example shows steps that you might typically use to run a debug version of the vpp executable file, generate packets, and to analyze results.

Example with IP4 ARP Messages

In the following steps, the VPP executable does not need to be started with superuser permissions. The VPP executable will not discover physical devices when run as a normal user.

Step 1. Start a debug version of vpp

From the command line, make the VPP source directory the working directory and run VPP as shown in the following example.

In the following example, including the dpdk argument means that no physical interfaces will be discovered.

$ ./build-root/install-vpp_debug-native/vpp/bin/vpp unix interactive plugins { plugin dpdk_plugin.so { disable } }

Step 2. Execute the arp4 setup script

From the vpp debug command-line, execute the arp4 script.

DBGvpp# exec src/scripts/vnet/arp4

Step 3. Examine the setup script

Let's tale a look at the contents of the setup script that you just executed. The script .../vpp/vnet/etc/scripts/arp4 contains:

packet-generator new {
  name x
  limit 1
  node ip4-input
  size 64-64
  no-recycle
  data {
    ICMP: 1.0.0.2 -> 2.0.0.2
    ICMP echo_request
    incrementing 100
  }
}

trace add pg-input 100
loop create
loop create
set int state loop0 up
set int state loop1 up

set int ip address loop0 1.0.0.1/24
set int ip address loop1 2.0.0.1/24

The first stanza creates a packet generator stream called "x" which sends a single ipv4 icmp echo-request when enabled. The trace add command arranges to trace 100 packets originating at the pg-input graph node. If you want to trace packets originating at the "ethernet-input" node - which is probably the most typical real-world use-case - make the substitution for that graph node.

Finally, the script configures a couple of loopback interfaces; primarily, so that ip4-input / ip4-lookup won't immediately ditch the generated packet.

Step 4. Generate packets

On the vpp debug command-line, enable the packet generator.

DBGvpp# packet-generator enable


Step 5. Run the packet tracer

Use the show trace command to run the packet tracer.

DBGvpp# show trace
------------------- Start of thread 0 vpp_main -------------------
Packet 1

00:00:21:923147: pg-input
  stream x, 64 bytes, sw_if_index 1
  current data 0, length 64, buffer-pool 0, ref-count 1, trace handle 0x0
  ICMP: 1.0.0.2 -> 2.0.0.2
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    fragment id 0x0000
  ICMP echo_request checksum 0x7a6e id 1
00:00:21:923216: ip4-input
  ICMP: 1.0.0.2 -> 2.0.0.2
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    fragment id 0x0000
  ICMP echo_request checksum 0x7a6e id 1
00:00:21:923252: ip4-not-enabled
    ICMP: 1.0.0.2 -> 2.0.0.2
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
      fragment id 0x0000
    ICMP echo_request checksum 0x7a6e id 1
00:00:21:923261: error-drop
  rx:pg0
00:00:21:923270: drop
  null-node: blackholed packets

Step 6. Analyze the information

You can see in the trace above that the packet goes through "ip4-not-enabled" before being dropped. This is because the interface used to inject the packet (pg0 by default) has no IPv4 configuration and hence ARP is not enabled.

Inspecting the error counters you see what we might expect in light of the packet tracer output:

DBGvpp# sh err
   Count                  Node                              Reason               Severity
         1             null-node                      blackholed packets           error

You can enable IPv4 on pg0 by configuring it as eg. unnumbered:

DBGvpp# set int unnumbered pg0 use loop0

And look at the result when re-injecting the packet:

DBGvpp# clear trace
DBGvpp# trace add pg-input 10
DBGvpp# packet-generator enable-stream
DBGvpp# show trace
------------------- Start of thread 0 vpp_main -------------------
Packet 1

00:05:44:786471: pg-input
  stream x, 64 bytes, sw_if_index 1
  current data 0, length 64, buffer-pool 0, ref-count 1, trace handle 0x0
  ICMP: 1.0.0.2 -> 2.0.0.2
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    fragment id 0x0000
  ICMP echo_request checksum 0x7a6e id 1
00:05:44:786501: ip4-input
  ICMP: 1.0.0.2 -> 2.0.0.2
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    fragment id 0x0000
  ICMP echo_request checksum 0x7a6e id 1
00:05:44:786513: ip4-lookup
  fib 0 dpo-idx 3 flow hash: 0x00000000
  ICMP: 1.0.0.2 -> 2.0.0.2
    tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
    fragment id 0x0000
  ICMP echo_request checksum 0x7a6e id 1
00:05:44:786523: ip4-glean
    ICMP: 1.0.0.2 -> 2.0.0.2
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
      fragment id 0x0000
    ICMP echo_request checksum 0x7a6e id 1
00:05:44:786547: ip4-drop
    ICMP: 1.0.0.2 -> 2.0.0.2
      tos 0x00, ttl 64, length 64, checksum 0x77ba dscp CS0 ecn NON_ECN
      fragment id 0x0000
    ICMP echo_request checksum 0x7a6e id 1
00:05:44:786568: error-drop
  rx:pg0
00:05:44:786591: drop
  ip4-glean: ARP requests sent

Use a PCAP file with PG

The packet generator can also replay a pcap file directly, for example:

 DBGvpp# create packet-generator interface pg0
 DBGvpp# packet-generator new pcap /tmp/mypcap.pcap source pg0 name s
 DBGvpp# packet-generator enable-stream