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;
Definition nw_ethernet_pkg.vhd:86
Assume the variable v_payload contains the ethernet payload, for example an IPv4 packet. The variables are defined:
variable v_header : t_ethernet_header;
variable v_eth_pkt : t_slv_arr(0 to 1500)(7 downto 0);
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;
v_header.mac_dest := f_eth_mac_2_slv_arr("08:00:27:27:1a:d5");
v_header.mac_src := f_randmac;
v_len := f_eth_create_pkt_len(v_header, v_payload);
v_eth_pkt(0 to v_len - 1) := f_eth_create_pkt(v_header, v_payload);
v_eth_pkt(0 to v_len + 7) := f_concat(C_ETH_PREAMBLE, v_eth_pkt(0 to v_len - 1));
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);
See further examples in the test bench nw_ethernet_tb.vhd.