ip: small clean up
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 4 Feb 2015 15:31:37 +0000 (16:31 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 4 Feb 2015 15:31:37 +0000 (16:31 +0100)
liteeth/common.py
liteeth/ip/__init__.py
liteeth/test/arp_tb.py
liteeth/test/ip_tb.py

index 682ab4fac07aa0ad621ac8e7596824eda9c2f413..09972a994d5ef60b001357f84ed23bed56edc245 100644 (file)
@@ -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)
        ]
index 7685f3cd3e3a5b731a2c3ec7e39b16c2380a2343..1ffb52938cf247aa5e824e87ab15a899c65a8beb 100644 (file)
@@ -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,
index 534cf0769cf168269c94bf37f4712784bbd81b86..484230ec70a4016c09c903ef9e253b5bf511a587 100644 (file)
@@ -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__":
index 8057371dfc4799acac55718fe8b65dffbc796307..66927654ba450ca77103800054d5a852aa48b0e0 100644 (file)
@@ -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