IPv4
The IPv4 library provides functions for creating and manipulation IPv4 packets.
Functionality
- Create IPv4 packets of any length
- Create and extract IPv4 headers
- Verify checksum of IPv4 packets
Other libraries in IPv4 are:
More details in nw_ipv4_pkg
Example use
Include the libraries:
library nw_util;
context nw_util.nw_util_context;
library nw_ipv4;
context nw_ipv4.nw_ipv4_context;
Assume the variable v_payload
contains the IPv4 payload, for example an UDP packet. The variables are defined:
variable v_header : t_ipv4_header; -- header record
variable v_ipv4_pkt : t_slv_arr(0 to 1500)(7 downto 0); -- byte array
variable v_len : natural;
First setup the header, then calculate the total IPv4 packet length before creating the packet.
v_header := C_DEFAULT_IPV4_HEADER; -- copy default header
v_header.src_ip := x"c0a820fe"; -- change source IP
v_len := f_ipv4_create_pkt_len(v_header, v_payload); -- calculate total packet length
v_ipv4_pkt(0 to v_len - 1) := f_ipv4_create_pkt(v_header, v_payload); -- create the packet
The variable v_ipv4_pkt
is an 8-bit array. This can of course be rearranged to any word width with f_repack
.
v_ipv4_pkt_64 := f_repack(v_ipv4_pkt, 64, C_MSB_FIRST); -- repack to 64bit words (padded with zeros if required)
See further examples in the test bench nw_ipv4_tb.vhd.