From df2f283495a37a36a028ddbff277648e3a3d71cf Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 4 Feb 2015 16:31:37 +0100 Subject: [PATCH] ip: small clean up --- liteeth/common.py | 5 +++-- liteeth/ip/__init__.py | 18 ++++++++++++------ liteeth/test/arp_tb.py | 4 ++-- liteeth/test/ip_tb.py | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/liteeth/common.py b/liteeth/common.py index 682ab4fa..09972a99 100644 --- a/liteeth/common.py +++ b/liteeth/common.py @@ -69,6 +69,7 @@ ipv4_header = { "destination_ip_address": HField(16, 0, 32), "options": HField(20, 0, 32) } + udp_header_len = 8 udp_header = { "source_port": HField( 0, 0, 16), @@ -132,9 +133,9 @@ def eth_ipv4_description(dw): def eth_ipv4_user_description(dw): layout = [ - ("total_length", 16), + ("length", 16), ("protocol", 8), - ("destination_ip_address", 32), + ("ip_address", 32), ("data", dw), ("error", dw//8) ] diff --git a/liteeth/ip/__init__.py b/liteeth/ip/__init__.py index 7685f3cd..1ffb5293 100644 --- a/liteeth/ip/__init__.py +++ b/liteeth/ip/__init__.py @@ -26,9 +26,15 @@ class LiteEthIPTX(Module): packetizer = LiteEthIPV4Packetizer() self.submodules += packetizer self.comb += [ - Record.connect(self.sink, packetizer.sink), - packetizer.sink.version.eq(0x5), - packetizer.sink.ihl.eq(0x4), + packetizer.sink.stb.eq(self.sink.stb), + packetizer.sink.sop.eq(self.sink.sop), + packetizer.sink.eop.eq(self.sink.eop), + self.sink.eq(packetizer.sink.ack), + packetizer.sink.destination_ip_address.eq(ip_address), + packetizer.sink.protocol.eq(self.sink.protocol), + packetizer.sink.total_length.eq(self.sink.length + (0x5*4)), + packetizer.sink.version.eq(0x4), # ipv4 + packetizer.sink.ihl.eq(0x5), # 20 bytes packetizer.sink.dscp.eq(0), packetizer.sink.ecn.eq(0), packetizer.sink.identification.eq(0), @@ -53,7 +59,7 @@ class LiteEthIPTX(Module): ) fsm.act("SEND_MAC_ADDRESS_REQUEST", arp_table.request.stb.eq(1), - arp_table.request.ip_address.eq(self.sink.destination_ip_address), + arp_table.request.ip_address.eq(self.sink.ip_address), If(arp_table.request.stb & arp_table.request.ack, NextState("WAIT_MAC_ADDRESS_RESPONSE") ) @@ -112,9 +118,9 @@ class LiteEthIPRX(Module): source.sop.eq(sink.sop), source.eop.eq(sink.eop), sink.ack.eq(source.ack), - source.total_length.eq(sink.total_length), + source.length.eq(sink.total_length - (sink.ihl*4)), source.protocol.eq(sink.protocol), - source.destination_ip_address.eq(sink.destination_ip_address), + source.ip_address.eq(sink.destination_ip_address), source.data.eq(sink.data), source.error.eq(sink.error), If(source.stb & source.eop & source.ack, diff --git a/liteeth/test/arp_tb.py b/liteeth/test/arp_tb.py index 534cf076..484230ec 100644 --- a/liteeth/test/arp_tb.py +++ b/liteeth/test/arp_tb.py @@ -15,7 +15,7 @@ mac_address = 0x12345678abcd class TB(Module): def __init__(self): - self.submodules.phy_model = phy.PHY(8, debug=False) + self.submodules.phy_model = phy.PHY(8, debug=True) self.submodules.mac_model = mac.MAC(self.phy_model, debug=False, loopback=False) self.submodules.arp_model = arp.ARP(self.mac_model, mac_address, ip_address, debug=False) @@ -50,7 +50,7 @@ class TB(Module): while selfp.arp.table.response.stb != 1: selfp.arp.table.response.ack = 1 yield - print("Model MAC : 0x%12x" %selfp.arp.table.response.mac_address) + print("Model's MAC : 0x%12x" %selfp.arp.table.response.mac_address) if __name__ == "__main__": diff --git a/liteeth/test/ip_tb.py b/liteeth/test/ip_tb.py index 8057371d..66927654 100644 --- a/liteeth/test/ip_tb.py +++ b/liteeth/test/ip_tb.py @@ -45,12 +45,12 @@ class TB(Module): selfp.ip.sink.stb = 1 selfp.ip.sink.sop = 1 selfp.ip.sink.eop = 1 - selfp.ip.sink.destination_ip_address = 0x12345678 + selfp.ip.sink.ip_address = 0x12345678 selfp.ip.sink.protocol = 0x11 selfp.ip.source.ack = 1 if selfp.ip.source.stb == 1 and selfp.ip.source.sop == 1: - print("IP Packet / destination_ip_address %08x" %selfp.ip.sink.destination_ip_address) + print("IP Packet / from ip_address %08x" %selfp.ip.sink.ip_address) yield -- 2.30.2