Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix udp checksum header overflow #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rtl/udp_checksum_gen.v
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ localparam [2:0]
STATE_SUM_HEADER_2 = 3'd2,
STATE_SUM_HEADER_3 = 3'd3,
STATE_SUM_PAYLOAD = 3'd4,
STATE_FINISH_SUM = 3'd5;
STATE_FINISH_SUM = 3'd5,
STATE_COMMIT_HDR = 3'd6;

reg [2:0] state_reg = STATE_IDLE, state_next;

Expand Down Expand Up @@ -507,6 +508,9 @@ always @* begin
checksum_part = checksum_reg[15:0] + checksum_reg[31:16];
checksum_next = ~(checksum_part[15:0] + checksum_part[16]);
hdr_valid_next = 1;
state_next = STATE_COMMIT_HDR;
end
STATE_COMMIT_HDR: begin
state_next = STATE_IDLE;
end
endcase
Expand Down
6 changes: 5 additions & 1 deletion rtl/udp_checksum_gen_64.v
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ localparam [2:0]
STATE_SUM_HEADER = 3'd1,
STATE_SUM_PAYLOAD = 3'd2,
STATE_FINISH_SUM_1 = 3'd3,
STATE_FINISH_SUM_2 = 3'd4;
STATE_FINISH_SUM_2 = 3'd4,
STATE_COMMIT_HDR = 3'd5;

reg [2:0] state_reg = STATE_IDLE, state_next;

Expand Down Expand Up @@ -541,6 +542,9 @@ always @* begin
checksum_part = checksum_reg[15:0] + checksum_reg[31:16];
checksum_next = ~(checksum_part[15:0] + checksum_part[16]);
hdr_valid_next = 1;
state_next = STATE_COMMIT_HDR;
end
STATE_COMMIT_HDR: begin
state_next = STATE_IDLE;
end
endcase
Expand Down
48 changes: 48 additions & 0 deletions tb/test_udp_checksum_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,54 @@ def check():

yield delay(100)

yield clk.posedge
payload_len = 8
print("test 4: header fifo overflow with back-to-back packets, length %d" % payload_len)
current_test.next = 4

test_frame1 = udp_ep.UDPFrame()
test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
test_frame1.eth_src_mac = 0x5A5152535455
test_frame1.eth_type = 0x0800
test_frame1.ip_version = 4
test_frame1.ip_ihl = 5
test_frame1.ip_length = None
test_frame1.ip_identification = 0
test_frame1.ip_flags = 2
test_frame1.ip_fragment_offset = 0
test_frame1.ip_ttl = 64
test_frame1.ip_protocol = 0x11
test_frame1.ip_header_checksum = None
test_frame1.ip_source_ip = 0xc0a80164
test_frame1.ip_dest_ip = 0xc0a80165
test_frame1.udp_source_port = 1
test_frame1.udp_dest_port = 2
test_frame1.udp_length = None
test_frame1.udp_checksum = None
test_frame1.payload = bytearray(range(payload_len))
test_frame1.build()

cnt = 32
sink_pause.next = True
yield clk.posedge

for i in range(cnt):
source.send(test_frame1)

i = 8*cnt
while i > 0:
i = max(0, i-1)
yield clk.posedge

sink_pause.next = False
yield clk.posedge

for i in range(cnt):
yield sink.wait()
rx_frame = sink.recv()

yield delay(100)

raise StopSimulation

return instances()
Expand Down
49 changes: 49 additions & 0 deletions tb/test_udp_checksum_gen_64.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,55 @@ def check():
assert sink.empty()

yield delay(100)

yield clk.posedge
payload_len = 8
print("test 4: header fifo overflow with back-to-back packets, length %d" % payload_len)
current_test.next = 4

test_frame1 = udp_ep.UDPFrame()
test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
test_frame1.eth_src_mac = 0x5A5152535455
test_frame1.eth_type = 0x0800
test_frame1.ip_version = 4
test_frame1.ip_ihl = 5
test_frame1.ip_length = None
test_frame1.ip_identification = 0
test_frame1.ip_flags = 2
test_frame1.ip_fragment_offset = 0
test_frame1.ip_ttl = 64
test_frame1.ip_protocol = 0x11
test_frame1.ip_header_checksum = None
test_frame1.ip_source_ip = 0xc0a80164
test_frame1.ip_dest_ip = 0xc0a80165
test_frame1.udp_source_port = 1
test_frame1.udp_dest_port = 2
test_frame1.udp_length = None
test_frame1.udp_checksum = None
test_frame1.payload = bytearray(range(payload_len))
test_frame1.build()

cnt = 16
sink_pause.next = True
yield clk.posedge

for i in range(cnt):
source.send(test_frame1)

i = 8*cnt
while i > 0:
i = max(0, i-1)
yield clk.posedge

sink_pause.next = False
yield clk.posedge

for i in range(cnt):
yield sink.wait()
rx_frame = sink.recv()

yield delay(100)


raise StopSimulation

Expand Down