ICMP for IPv4
The ICMPv4 library provides functions for creating and manipulation ICMP packets.
Functionality
- Create ICMP packets of any length
- Create and extract ICMP headers
- Verify checksum of ICMP packets
More details in nw_icmpv4_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 ICMP payload. The variables are defined:
variable v_header : t_icmpv4_header; -- ICMP header record
variable v_payload : t_slv_arr(0 to 31)(7 downto 0);
variable v_icmp_pkt : t_slv_arr(0 to 39)(7 downto 0); -- byte array
variable v_len : natural;
First setup the header, then calculate the total ICMP packet length before creating the packet.
v_header := C_DEFAULT_ICMPV4_HEADER; -- copy default header (ping request)
v_payload := f_gen_nrs(x"80", 32); -- payload contents
v_len := f_icmpv4_create_pkt_len(v_header, v_payload); -- calculate total packet length
v_icmp_pkt(0 to v_len - 1) := f_icmpv4_create_pkt(v_header, v_payload); -- create the packet (no checksum)
The variable v_icmp_pkt
is an 8-bit array. This can of course be rearranged to any word width with f_repack()
.
v_icmpv4_pkt_32 := f_repack(v_icmp_pkt, 32, C_MSB_FIRST); -- repack to 32bit words (padded with zeros if required)
See further examples in the test bench nw_ipv4_tb.vhd.