diff --git a/trashernet/trashernet_ipv4.vhd b/trashernet/trashernet_ipv4.vhd index cd92f85..7dc6c1e 100644 --- a/trashernet/trashernet_ipv4.vhd +++ b/trashernet/trashernet_ipv4.vhd @@ -143,27 +143,28 @@ begin signal full_length : ipv4_length; + signal sr : byte_vector(0 to 19); + signal byte_cnt : integer range 0 to sr'length - 1; + signal alt_byte : std_logic; + signal checksum : unsigned(20 downto 0); -- 20 Header fields -> 19 chances for carry -> 5 additional bits + signal checksum_ones : unsigned(15 downto 0); + constant TTL : byte := x"40"; impure function get_header(checksum : std_logic_vector(15 downto 0)) return byte_vector is + variable ret : byte_vector(sr'range); begin - return -- - byte_vector'( - x"45", x"00", byte(full_length(15 downto 8)), byte(full_length(7 downto 0)), -- Ver/IHL, DSCP/ECN, Len - x"00", x"00", x"00", x"00" -- Identification, Flags/FragOffset - ) & TTL & ipv4_in.tx_protocol & checksum(15 downto 8) & checksum(7 downto 0) & -- TTL, Protocol, Header Checksum - ipv4_config.ip_address & -- Source IP - ipv4_in.tx_ip_address -- Destination IP - ; + ret := -- + byte_vector'( + x"45", x"00", byte(full_length(15 downto 8)), byte(full_length(7 downto 0)), -- Ver/IHL, DSCP/ECN, Len + x"00", x"00", x"00", x"00" -- Identification, Flags/FragOffset + ) & TTL & ipv4_in.tx_protocol & checksum(15 downto 8) & checksum(7 downto 0) & -- TTL, Protocol, Header Checksum + ipv4_config.ip_address & -- Source IP + ipv4_in.tx_ip_address -- Destination IP + ; + return ret; end function get_header; - - constant PSEUDO_HEADER : byte_vector := get_header(x"0000"); - signal sr : byte_vector(PSEUDO_HEADER'range); - signal byte_cnt : integer range 0 to sr'length - 1; - signal alt_byte : std_logic; - signal checksum : unsigned(20 downto 0); -- 20 Header fields -> 19 chances for carry -> 5 additional bits - signal checksum_ones : unsigned(15 downto 0); begin - full_length <= PSEUDO_HEADER'length + ipv4_in.tx_length; + full_length <= sr'length + ipv4_in.tx_length; checksum_ones <= checksum(15 downto 0) + checksum(checksum'high downto 16); tx_fsm : process(clk, rst) is