Network Wizard for VHDL Test Benches
TCP

TCP for IPv6

The TCP for IPv6 library provides functions for creating and manipulation TCP packets.

Functionality

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



More details in nw_tcpv6_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 TCP payload. The variables are defined:

variable v_header : t_tcp_header; -- TCP header record
variable v_ipv6_header : t_ipv6_header; -- IPv6 header record
variable v_tcp_pkt : t_slv_arr(0 to 1500)(7 downto 0); -- byte array
variable v_len : natural;

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

v_header := C_DEFAULT_TCP_HEADER; -- copy default header
v_header.seq_no := x"1033010f"; -- change sequence number
v_ipv6_header := C_DEFAULT_IPV6_HEADER; -- IPv6 header needed for pseudo header
v_ipv6_header.protocol := C_TCP; -- set protocol
-- change other header fields as required...
v_len := f_tcpv6_create_pkt_len(v_ipv6_header, v_header, v_payload); -- calculate total packet length
v_tcp_pkt(0 to v_len - 1) := f_tcpv6_create_pkt(v_ipv6_header, v_header, v_payload); -- create the packet

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

v_tcp_pkt_32 := f_repack(v_tcp_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.