You are here: Foswiki>NetFPGA/OneGig/Projects Web>PacketGenerator (16 Apr 2010, Main.GlenGibb)EditAttach

Packet generator

This project provides a simple packet generator and capture tool. It is designed for use by anyone who wants to inject packets into a network and/or observe packets exiting a network.

The generation feature in the current implementation is a "playback" mechanism—a sequence of Ethernet frames is loaded from a PCAP dump file into the generator which then proceeds to transmit that sequence of frames. Delay between individual frames can be tightly controlled; by default the generator will use the delay specified in the pcap source file. A user can optionally specify a maximum data rate and/or a set delay between frames.

The packet generator also be used to report statistics on packets exiting the network and optionally to record the packets exiting the network. These feature are useful for analyzing throughput through a device and for analyzing whether the data exiting a network is correct.

Show Contents...Hide Contents...

Project summary

Status
Released
Current version
1.1.0 (Bitfile reported as release 2)
Known issues
A problem with the output queues prevents the packet generator from simultaneously generating and receiving traffic on all four ports at 4 Gbps. A version of the bitfile that fixes this can be obtained from: http://yuba.stanford.edu/~grg/packet_generator.bit Note that this version will not pass any packets up to the host.
Authors
Hardware: Glen Gibb (grg@stanford.edu)
Software: Adam Covington, Glen Gibb
NetFPGA package requirements:
Device ID Project Name Contact Description
0 Develop/Debug ID   Use it for your own personal tests or unreleased projects only
release 1.0.3 requires NetFPGA source 2.0
release 1.0.2 requires NetFPGA source 1.2.5

Download

Install from NetFPGA Yum repository

  1. Install the NetFPGA Base Package
  2. Install the packet generator
 yum install netfpga-packet_generator

Obtain Tarball from NetFPGA Distributions

Login account for the NetFPGA required for download. For a new account go to: http://netfpga.org/netfpgawiki/index.php?title=Special:UserLogin&type=signup

Download from NetFPGA beta distributions website (http://netfpga.org/beta/distributions/netfpga_packet_generator_1_0_3.tar.gz).

Regression Tests

The regression tests verify the functionality of the packet generator. In order to run the tests, you need to have the machine connected for the regression tests as stated in the Run Regression Tests section of the Guide.

After connecting the cables. Run the following command to run the regression tests.

 nf21_regress_test.pl --project packet_generator

Regression Tests

Test 1: Sending Packets

Name
test_send_pkts
Description
Load and send two pcap files from nf2c0 and nf2c1. Verify the counters
# Initialize netfpga hardware
# Load and send two pcap files from nf2c0 and nf2c1
# Check counters to verify number of packets sent. $ Location
projects/packet_generator/regress/test_send_pkts $ Output
 SUCCESS!

Test 2: Capture

Name
test_capture
Description
Send two pcap files from eth1 and eth2. Capture the output using the packet generator (capture mode) and verify the packets received.
# Initialize netfpga hardware
# Start packet generator in capture mode
# Send two pcap files from eth1 and eth2 using tcpreplay
# Compare the captured pcap files to the originals and find errors. $ Location
projects/packet_generator/regress/test_capture $ Output
 SUCCESS!

Test 3: Iterations

Name
test_iterations
Description
Load and send two pcap files from nf2c0 and nf2c1 with a specified number of iterations for each. Verify the packet sent counters.
# Initialize netfpga hardware
# Load and send two pcap files from nf2c0 and nf2c1 with 10 iterations for nf2c0 and 100 iterations for nf2c1
# Check counters to verify number of packets sent. $ Location
projects/packet_generator/regress/test_iterations $ Output
 SUCCESS!

Test 4: Rate Limiter

Name
test_rate_limiter
Description
Load and send two pcap files from nf2c0 and nf2c1 while setting the rate to 1 Mbps. Verify the sending rate.
# Initialize netfpga hardware
# Load and send two pcap files from nf2c0 and nf2c1 (specify 1 Mbps sending rate)
# Capture the sent packets to a pcap file
# Determine the sending rate from the pcap file generated $ Location
projects/packet_generator/regress/test_rate_limiter $ Output
 SUCCESS!

Usage

Preparation

Stand-alone package

Run the following command:

 packet_generator_setup.pl

NetFPGA source package

  1. Ensure that the NetFPGA kernel driver is loaded and that the CPCI has been reprogrammed.
  2. Download the packet generator bitfile:
 nf2_download packet_generator.bit

Packet generation/capture

The generator is controlled via the packet_generator.pl command:

   packet_generator.pl
        -q 
        [-r ] (Kbps)
        [-i ]
        [-d ] (ns)
        [-c 
 
   packet_generator.pl --help  - show detailed help

Options

Note: queue number should be a number between 0 and 3 inclusive, corresponding to nf2c0 through nf2c3. -q :

Specify the pcap file to load in and send from a queue

-r :

Specify the rate for each queue in Kbps

-i :

Specify the number of iterations per queue

-d :

Specify the delay between packets in ns. If not specified then the delay recorded in the pcap file is used. A value of 0 will disable the delay.

-c :

Specify the capture file.

Output

The example below is the output produced when sending data out port 2 (with port 2 linked directly to port 3). In this example the rate is limited to 1.000 Mbps:

 Limiting MAC Queue 2 to 1.000 Mbps (tokens = 1, clks = 1000)
 Loaded 1 packet(s) into MAC Queue 2
 Limiting CPU Queue 0 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 1 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 2 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 3 to 200.000 Mbps (tokens = 1, clks = 5)
 Sending packets...
 Last packet scheduled for transmission at 12.132 seconds
 12 seconds elapsed...
 
 Transmit statistics:
 ====================
 
 MAC Queue 2:
         Packets: 1000
         Completed iterations: 1000
 
 
 Receive statistics:
 ===================
 
 MAC Queue 0:
         Packets: 0
 MAC Queue 1:
         Packets: 0
 MAC Queue 2:
         Packets: 0
 MAC Queue 3:
         Packets: 1000
         Bytes: 1518000
         Time: 12.131868144 s
         Rate: 1.001 Mbps
The output shows that the last packet is estimated to be transmitted at time 12.144 seconds. The transmit statistics for queue 2 indicate that 1000 packets were sent and 1000 iterations were completed. The receive statistics for MAC queue 3 (nf2c3) indicate that 1000 packets were received which totaled 1518000 bytes. (In this example each packet was 1518 bytes.) The time between the reception of the first byte to the reception of the last byte was approximately 12.132 s. This corresponds to a rate of 1.001 Mbps.

Examples

Send the packets contained in a file called http.pcap out nf2c0:

 packet_generator.pl -q0 http.pcap

Send 10 iterations of the packets contained in http.pcap out nf2c0. Capture the data coming back in port nf2c1 into a file named "nf2c1.pcap":

 packet_generator.pl -q0 http.pcap -i0 10 -c1 nf2c1.pcap

Send the packets contained in http.pcap out nf2c0. Limit the rate to 1 Mbps (1000 Kbps):

 packet_generator.pl -q0 http.pcap -r0 1000

Send the packets contained in http.pcap out nf2c0. Set the delay between packets to 0 ns:

 packet_generator.pl -q0 http.pcap -d0 0

Send the packets contained in http0.pcap, http1.pcap, udp2.pcap and udp3.pcap out interfaces nf2c0, nf2c1, nf2c2 and nf2c3 respectively. Capture the data coming back on all four ports to files nf1c0.pcap, nf2c1.pcap, nf2c2.pcap and nf2c3.pcap:

 packet_generator.pl -q0 http0.pcap -q1 http1.pcap -q2 udp2.pcap -q3 udp3.pcap -c0 nf2c0.pcap -c1 nf2c1.pcap -c2 nf2c2.pcap -c3 nf2c3.pcap

Notes on packet measurement and capture

Timestamping

Timestamping of received packets is performed in hardware. This allows packets to be timestamped with the accuracy of the clock on the NetFPGA board. (The accuracy of timestamps produced by software tools such as tcpdump is significantly less since each packet must be transferred from hardware to software. The process of notifying the kernel of an available packet and then transferring that packet into the kernel introduces a (small) variable delay thus limiting the accuracy of timestamps reported by tcpdump .)

Note that timestamps recorded in the captured pcap file are based upon the hardware timestamp.

Measurement

All measurements are performed in hardware. The packet counter is 32 bits and the byte counter is 40 bits. The time reported during a measurement is reported with nanosecond precision—this is only as accurate as the clock on the NetFPGA. The time reported is the time from the beginning of the first bit of data to the end of the last bit of data received—the preamble before the first packet is not included.

An example of a measurement on MAC queue 3 (nf2c3) is:

 MAC Queue 3:
         Packets: 1000
         Bytes: 1518000
         Time: 12.131868144 s
         Rate: 1.001 Mbps

Capture

The hardware attempts to send all packets received (on the relevant ports) to software for processing when performing packet capture. Since the PCI bandwidth is less than the maximum combined receive bandwidth across all four Ethernet ports it is possible that some received packets will be dropped. Dropping of packets occurs when the buffers on the NetFPGA board overflow.

The measurement statistics are correct regardless of whether packet are dropped.

pcap files

Many programs have the ability to generate pcap files. Two such programs are tcpdump and Wireshark.

Additional Information

A more in depth description of the architecture can be found in the following paper.

FCCM 2009 Packet Generator Paper

Original Source

This project provides a simple packet generator and capture tool. It is designed for use by anyone who wants to inject packets into a network and/or observe packets exiting a network.

The generation feature in the current implementation is a "playback" mechanism—a sequence of Ethernet frames is loaded from a [http://wiki.wireshark.org/Development/LibpcapFileFormat PCAP dump file] into the generator which then proceeds to transmit that sequence of frames. Delay between individual frames can be tightly controlled; by default the generator will use the delay specified in the pcap source file. A user can optionally specify a maximum data rate and/or a set delay between frames.

The packet generator also be used to report statistics on packets exiting the network and optionally to record the packets exiting the network. These feature are useful for analyzing throughput through a device and for analyzing whether the data exiting a network is correct.

== Project summary ==

; Status
: Released.
; Known issues
: A problem with the output queues prevents the packet generator from simultaneously generating and receiving traffic on all four ports at 4 Gbps. A version of the bitfile that fixes this can be obtained from: http://yuba.stanford.edu/~grg/packet_generator.bit  Note that this version will '''not''' pass any packets up to the host.
; Version: 1.0.3 (Bitfile reported as release 2)
; Authors
:''Hardware:'' Glen Gibb ([mailto:grg@stanford.edu grg@stanford.edu])
:''Software:'' Adam Covington, Glen Gibb
; NetFPGA source (required only for project source release): 
:release 1.0.3 requires NetFPGA source 2.0
:release 1.0.2 requires NetFPGA source 1.2.5

== Download ==

=== Install from NetFPGA Yum repository ===
#Install the [http://netfpga.org/netfpgawiki/index.php/Guide#Install_NetFPGA_Base_Package NetFPGA Base Package]
#Install the packet generator
 yum install netfpga-packet_generator

=== Obtain Tarball from NetFPGA Distributions === 

Login account for the NetFPGA required for download.  For a new account go to: [http://netfpga.org/netfpgawiki/index.php?title=Special:UserLogin&type=signup http://netfpga.org/netfpgawiki/index.php?title=Special:UserLogin&type=signup]

Download from NetFPGA beta distributions website (http://netfpga.org/beta/distributions/netfpga_packet_generator_1_0_3.tar.gz).

== Regression Tests ==

The regression tests verify the functionality of the packet generator.  In order to run the tests, you need to have the machine connected for the regression tests as stated in the [http://netfpga.org/netfpgawiki/index.php/Guide#Run_Regression_Tests Run Regression Tests] section of the Guide.

After connecting the cables. Run the following command to run the regression tests.

 nf21_regress_test.pl --project packet_generator

=== Regression Tests === 

====Test 1: Sending Packets ====
:; Name: test_send_pkts
:; Description: Load and send two pcap files from nf2c0 and nf2c1. Verify the counters
::# Initialize netfpga hardware
::# Load and send two pcap files from nf2c0 and nf2c1
::# Check counters to verify number of packets sent.
:; Location
projects/packet_generator/regress/test_send_pkts
:; Output
 SUCCESS!

====Test 2: Capture ====
:; Name: test_capture
:; Description: Send two pcap files from eth1 and eth2. Capture the output using the packet generator (capture mode) and verify the packets received.
::# Initialize netfpga hardware
::# Start packet generator in capture mode
::# Send two pcap files from eth1 and eth2 using tcpreplay
::# Compare the captured pcap files to the originals and find errors.
:; Location
projects/packet_generator/regress/test_capture
:; Output
 SUCCESS!

====Test 3: Iterations ====
:; Name: test_iterations
:; Description: Load and send two pcap files from nf2c0 and nf2c1 with a specified number of iterations for each. Verify the packet sent counters.
::# Initialize netfpga hardware
::# Load and send two pcap files from nf2c0 and nf2c1 with 10 iterations for nf2c0 and 100 iterations for nf2c1
::# Check counters to verify number of packets sent.
:; Location
projects/packet_generator/regress/test_iterations
:; Output
 SUCCESS!

====Test 4: Rate Limiter ====
:; Name: test_rate_limiter
:; Description: Load and send two pcap files from nf2c0 and nf2c1 while setting the rate to 1 Mbps. Verify the sending rate.
::# Initialize netfpga hardware
::# Load and send two pcap files from nf2c0 and nf2c1 (specify 1 Mbps sending rate)
::# Capture the sent packets to a pcap file
::# Determine the sending rate from the pcap file generated
:; Location
projects/packet_generator/regress/test_rate_limiter
:; Output
 SUCCESS!

== Usage ==

=== Preparation ===

==== Stand-alone package ====

Run the following command:
 packet_generator_setup.pl

==== NetFPGA source package ====

# Ensure that the NetFPGA kernel driver is loaded and that the CPCI has been reprogrammed.
# Download the packet generator bitfile:
 nf2_download packet_generator.bit

=== Packet generation/capture ===

The generator is controlled via the <tt>packet_generator.pl</tt> command:
   packet_generator.pl
        -q<queue number> <pcap file>
        [-r<queue number> <rate>] (Kbps)
        [-i<queue number> <number of iterations>]
        [-d<queue number> <delay between packets>] (ns)
        [-c<queue number> <capture file>
 
   packet_generator.pl --help  - show detailed help

==== Options ====
Note: ''queue number'' should be a number between 0 and 3 inclusive, corresponding to nf2c0 through nf2c3.
;-q<queue number> <pcap file>
:Specify the pcap file to load in and send from a queue

;-r<queue number> <rate>
:Specify the rate for each queue in Kbps

;-i<queue number> <number of iterations>
:Specify the number of iterations per queue

;-d<queue number> <delay between packets>
:Specify the delay between packets in ns. If not specified then the delay recorded in the pcap file is used. A value of 0 will disable the delay.

;-c<port number> <capture file>
:Specify the capture file.

==== Output ====

The example below is the output produced when sending data out port 2 (with port 2 linked directly to port 3). In this example the rate is limited to 1.000 Mbps:
 Limiting MAC Queue 2 to 1.000 Mbps (tokens = 1, clks = 1000)
 Loaded 1 packet(s) into MAC Queue 2
 Limiting CPU Queue 0 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 1 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 2 to 200.000 Mbps (tokens = 1, clks = 5)
 Limiting CPU Queue 3 to 200.000 Mbps (tokens = 1, clks = 5)
 Sending packets...
 Last packet scheduled for transmission at 12.132 seconds
 12 seconds elapsed...
 
 Transmit statistics:
 ====================
 
 MAC Queue 2:
         Packets: 1000
         Completed iterations: 1000
 
 
 Receive statistics:
 ===================
 
 MAC Queue 0:
         Packets: 0
 MAC Queue 1:
         Packets: 0
 MAC Queue 2:
         Packets: 0
 MAC Queue 3:
         Packets: 1000
         Bytes: 1518000
         Time: 12.131868144 s
         Rate: 1.001 Mbps
The output shows that the last packet is estimated to be transmitted at time 12.144 seconds. The transmit statistics for queue 2 indicate that 1000 packets were sent and 1000 iterations were completed. The receive statistics for MAC queue 3 (nf2c3) indicate that 1000 packets were received which totaled 1518000 bytes. (In this example each packet was 1518 bytes.) The time between the reception of the first byte to the reception of the last byte was approximately 12.132 s. This corresponds to a rate of 1.001 Mbps.

==== Examples ====

Send the packets contained in a file called http.pcap out nf2c0:
 packet_generator.pl -q0 http.pcap


Send 10 iterations of the packets contained in http.pcap out nf2c0. Capture the data coming back in port nf2c1 into a file named "nf2c1.pcap":
 packet_generator.pl -q0 http.pcap -i0 10 -c1 nf2c1.pcap


Send the packets contained in http.pcap out nf2c0. Limit the rate to 1 Mbps (1000 Kbps):
 packet_generator.pl -q0 http.pcap -r0 1000


Send the packets contained in http.pcap out nf2c0. Set the delay between packets to 0 ns:
 packet_generator.pl -q0 http.pcap -d0 0


Send the packets contained in http0.pcap, http1.pcap, udp2.pcap and udp3.pcap out interfaces nf2c0, nf2c1, nf2c2 and nf2c3 respectively. Capture the data coming back on all four ports to files nf1c0.pcap, nf2c1.pcap, nf2c2.pcap and nf2c3.pcap:
 packet_generator.pl -q0 http0.pcap -q1 http1.pcap -q2 udp2.pcap -q3 udp3.pcap -c0 nf2c0.pcap -c1 nf2c1.pcap -c2 nf2c2.pcap -c3 nf2c3.pcap

== Notes on packet measurement and capture ==

=== Timestamping ===

Timestamping of received packets is performed in hardware. This allows packets to be timestamped with the accuracy of the clock on the NetFPGA board. (The accuracy of timestamps produced by software tools such as <tt>tcpdump</tt> is significantly less since each packet must be transferred from hardware to software. The process of notifying the kernel of an available packet and then transferring that packet into the kernel introduces a (small) variable delay thus limiting the accuracy of timestamps reported by <tt>tcpdump</tt>.)

Note that timestamps recorded in the captured pcap file are based upon the hardware timestamp.

=== Measurement ===

All measurements are performed in hardware. The packet counter is 32 bits and the byte counter is 40 bits. The time reported during a measurement is reported with nanosecond precision&mdash;this is only as accurate as the clock on the NetFPGA. The time reported is the time from the beginning of the first bit of ''data'' to the end of the last bit of ''data'' received&mdash;the preamble before the first packet is not included.

An example of a measurement on MAC queue 3 (nf2c3) is:
 MAC Queue 3:
         Packets: 1000
         Bytes: 1518000
         Time: 12.131868144 s
         Rate: 1.001 Mbps

=== Capture ===

The hardware attempts to send all packets received (on the relevant ports) to software for processing when performing packet capture. Since the PCI bandwidth is less than the maximum combined receive bandwidth across all four Ethernet ports it is possible that some received packets will be dropped. Dropping of packets occurs when the buffers on the NetFPGA board overflow.

The measurement statistics are correct regardless of whether packet are dropped.

== pcap files ==

Many programs have the ability to generate pcap files. Two such programs are [http://www.tcpdump.org/ tcpdump] and [http://www.wireshark.org/ Wireshark].

== Additional Information ==
A more in depth description of the architecture can be found in the following paper.

[http://netfpga.org/documents/NetFPGA-FCCM-2009-Packet_Generator.pdf FCCM 2009 Packet Generator Paper]
Topic revision: r2 - 16 Apr 2010 - 22:16:17 - Main.GlenGibb