Network Wizard for VHDL Test Benches
UDP

UDP for IPv6

The UDP library provides functions for creating and manipulation UDP(v6) packets.

Functionality

  • Create UDP packets of any length
  • Create and extract UDP headers
  • Verify checksum of UDP packets



More details in nw_udpv6_pkg

Example use

Include the libraries:

library nw_util;
context nw_util.nw_util_context;
library nw_ipv6;
context nw_ipv6.nw_ipv6_context;

Assume the variable v_payload contains the UDP payload. The variables are defined:

variable v_header : t_udp_header; -- UDP header record
variable v_udp_pkt : t_slv_arr(0 to 1500)(7 downto 0); -- byte array
variable v_len : natural;

First setup the header, then calculate the total UDP packet length before creating the packet. Checksum is not optional for UDP over IPv6.

v_header := C_DEFAULT_UDP_HEADER; -- copy default header
v_header.src_port := x"0101"; -- change source port
v_len := f_udpv6_create_pkt_len(v_header, v_payload); -- calculate total packet length
v_udp_pkt(0 to v_len - 1) := f_udpv6_create_pkt(v_header, v_payload); -- create the packet (no checksum)

The IPv6 header must be supplied for the pseudo header:

v_ipv6_header := C_DEFAULT_IPV6_HEADER; -- copy default header
v_ipv6_header.dest_addr := f_ipv6_addr_2_slv_arr("2102:ec7::2ce"); -- change destination address
v_udp_pkt(0 to v_len - 1) := f_udpv6_create_pkt(v_ipv6_header, v_header, v_payload); -- create the packet

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

v_upd_pkt_32 := f_repack(v_udp_pkt, 32, C_MSB_FIRST); -- repack to 32bit words (padded with zeros if required)

See further examples in the test bench nw_ipv6_tb.vhd.