Network Wizard for VHDL Test Benches
PCAP library

PCAP

The PCAP library provides functions for reading network packets from PCAP files captured by tcpdump, Wireshark etc. These packets can then be used as stimuli in test benches. A collection of PCAP files can be found at for example PacketLife.

Functionality

  • Read network packets from PCAP and PCAPNG files
  • Count captured packets in PCAP/PCAPNG files

Limitations

  • No support for reading metadata (use e.g. Wireshark to explore PCAP files).
  • Only first section in PCAPNG files can be accessed.


More details in nw_pcap_pkg

Example use

Include the libraries:

library nw_util;
context nw_util.nw_util_context;
library nw_pcap;
use nw_pcap.nw_pcap_pkg.all;

Define file name of PCAP file:

constant C_FNAME : string := "/home/user/ddos_attack.pcap";

Now, assume we have a procedure called schedule_pkt() that will send a packet across an interface to the DUT. Such procedures are readily available in verification frameworks like UVVM. The code below will schedule all the network packets in the PCAP file for transmission in the test bench:

for i in 0 to f_pcap_get_pkt_cnt(C_FNAME) - 1 loop
schedule_pkt(f_pcap_get_pkt(C_FNAME, i, f_pcap_get_pkt_len(C_FNAME, i)));
end loop;

The packets in PCAP files do not always contain all the information normally transmitted on a physical link. For example captured ethernet packets do not have preamble and often not the FCS. NetWiz can fix this for supported network protocols. Include ethernet library to fix captured ethernet packets:

library nw_ethernet;
use nw_ethernet.nw_ethernet_pkg.all;

Add preamble and FCS to packets before scheduling:

for i in 0 to f_pcap_get_pkt_cnt(C_FNAME) - 1 loop
v_len := f_pcap_get_pkt_len(C_FNAME, i); -- get length of packet #i
array_8bit(0 to v_len -1) := f_pcap_get_pkt(C_FNAME, i, v_len); -- get packet
v_header := f_eth_get_header(array_8bit(0 to v_len - 1)); -- extract header
v_header.mac_dest := f_eth_mac_2_slv_arr("a2:34:56:f1:30:00"); -- maybe modify the header
schedule_pkt(f_concat(C_ETH_PREAMBLE, f_eth_create_pkt(v_header, f_eth_get_payload(array_8bit(0 to v_len -1))))); -- add preamble and FCS
end loop;

See further examples in the test bench nw_pcap_tb.vhd.