Network Wizard for VHDL Test Benches
Ethernet library

Ethernet

The ethernet library provides functions for creating and checking ethernet packets.

Functionality

  • Create ethernet packets of any length and type (small packets are padded to 64 byte).
  • Create and extract ethernet headers, including VLAN tags
  • Check CRC of ethernet packets

Other libraries in Ethernet are:


More details in nw_ethernet_pkg

Example use

Include the libraries:

library nw_util;
context nw_util.nw_util_context;
library nw_ethernet;
use nw_ethernet.nw_ethernet_pkg.all;

Assume the variable v_payload contains the ethernet payload, for example an IPv4 packet. The variables are defined:

variable v_header : t_ethernet_header; -- header record
variable v_eth_pkt : t_slv_arr(0 to 1500)(7 downto 0); -- byte array
variable v_len : natural;

First setup the header, then calculate the total ethernet packet length before creating the packet.

v_header := C_DEFAULT_ETH_HEADER; -- copy default header
v_header.mac_dest := f_eth_mac_2_slv_arr("08:00:27:27:1a:d5"); -- change destination MAC
v_len := f_eth_create_pkt_len(v_header, v_payload); -- calculate total packet length
v_eth_pkt(0 to v_len - 1) := f_eth_create_pkt(v_header, v_payload); -- create the packet
v_eth_pkt(0 to v_len + 7) := f_concat(C_ETH_PREAMBLE, v_eth_pkt(0 to v_len - 1)); -- add preamble

The variable v_eth_pkt is an 8-bit array. This can of course be rearranged to any word width with f_repack().

v_eth_pkt_256 := f_repack(v_eth_pkt, 256, C_MSB_FIRST); -- repack to 256bit words (padded with zeros if required)

See further examples in the test bench nw_ethernet_tb.vhd.