core: shorten names in header definitions
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 4 Feb 2015 21:51:11 +0000 (22:51 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 4 Feb 2015 21:51:11 +0000 (22:51 +0100)
liteeth/common.py
liteeth/core/arp.py
liteeth/core/ip.py
liteeth/core/udp.py
liteeth/test/mac_core_tb.py
liteeth/test/model/arp.py
liteeth/test/model/dumps.py
liteeth/test/model/ip.py
liteeth/test/model/udp.py
liteeth/test/udpip_tb.py

index 5c5b06ecc2bcad606f474a8b471e6a59a2b1a49c..3507764e9e93a0a0e23d7a7c756cae2bfe86fa44 100644 (file)
@@ -28,9 +28,9 @@ ethernet_type_arp = 0x806
 
 mac_header_len = 14
 mac_header = {
-       "destination_mac_address":      HField(0,  0, 48),
-       "source_mac_address":           HField(6,  0, 48),
-       "ethernet_type":                        HField(12, 0, 16)
+       "target_mac":           HField(0,  0, 48),
+       "sender_mac":           HField(6,  0, 48),
+       "ethernet_type":        HField(12, 0, 16)
 }
 
 arp_packet_length = 60
@@ -41,40 +41,40 @@ arp_opcode_reply = 0x0002
 
 arp_header_len = 28
 arp_header = {
-       "hardware_type":                        HField( 0,  0, 16),
-       "protocol_type":                        HField( 2,  0, 16),
-       "hardware_address_length":      HField( 4,  0, 8),
-       "protocol_address_length":      HField( 5,  0, 8),
-       "operation":                            HField( 6,  0, 16),
-       "source_mac_address":           HField( 8,  0, 48),
-       "source_ip_address":            HField(14,  0, 32),
-       "destination_mac_address":      HField(18,  0, 48),
-       "destination_ip_address":       HField(24,  0, 32)
+       "hwtype":                       HField( 0,  0, 16),
+       "proto":                        HField( 2,  0, 16),
+       "hwsize":                       HField( 4,  0, 8),
+       "protosize":            HField( 5,  0, 8),
+       "opcode":                       HField( 6,  0, 16),
+       "sender_mac":           HField( 8,  0, 48),
+       "sender_ip":            HField(14,  0, 32),
+       "target_mac":           HField(18,  0, 48),
+       "target_ip":            HField(24,  0, 32)
 }
 
 ipv4_header_len = 20
 ipv4_header = {
-       "version":                                      HField(0,  0, 4),
-       "ihl":                                          HField(0,  4, 4),
-       "dscp":                                         HField(1,  0, 6),
-       "ecn":                                          HField(1,  6, 2),
-       "total_length":                         HField(2,  0, 16),
-       "identification":                       HField(4,  0, 16),
-       "flags":                                        HField(6,  0, 3),
-       "fragment_offset":                      HField(6,  3, 13),
-       "time_to_live":                         HField(8,  0, 8),
-       "protocol":                                     HField(9,  0, 8),
-       "header_checksum":                      HField(10,  0, 16),
-       "source_ip_address":            HField(12,  0, 32),
-       "destination_ip_address":       HField(16,  0, 32)
+       "version":                      HField(0,  0, 4),
+       "ihl":                          HField(0,  4, 4),
+       "diff_services":        HField(1,  0, 6),
+       "ecn":                          HField(1,  6, 2),
+       "total_length":         HField(2,  0, 16),
+       "identification":       HField(4,  0, 16),
+       "flags":                        HField(6,  0, 3),
+       "fragment_offset":      HField(6,  3, 13),
+       "ttl":                          HField(8,  0, 8),
+       "protocol":                     HField(9,  0, 8),
+       "checksum":                     HField(10,  0, 16),
+       "sender_ip":            HField(12,  0, 32),
+       "target_ip":            HField(16,  0, 32)
 }
 
 udp_header_len = 8
 udp_header = {
-       "source_port":                          HField( 0,  0, 16),
-       "destination_port":                     HField( 2,  0, 16),
-       "length":                                       HField( 4,  0, 16),
-       "checksum":                                     HField( 6,  0, 16)
+       "src_port":             HField( 0,  0, 16),
+       "dst_port":             HField( 2,  0, 16),
+       "length":               HField( 4,  0, 16),
+       "checksum":             HField( 6,  0, 16)
 }
 
 udp_protocol = 0x11
@@ -151,8 +151,8 @@ def eth_udp_description(dw):
 
 def eth_udp_user_description(dw):
        layout = [
-               ("source_port", 16),
-               ("destination_port", 16),
+               ("src_port", 16),
+               ("dst_port", 16),
                ("ip_address", 32),
                ("length", 16),
                ("data", dw),
index 49d1af9991f25e611192c3f0459594609ba4909e..e5b67373b8af98d8f4aee30abe13cb7e9d27569c 100644 (file)
@@ -48,20 +48,20 @@ class LiteEthARPTX(Module):
                        )
                )
                self.comb += [
-                       source.hardware_type.eq(arp_hwtype_ethernet),
-                       source.protocol_type.eq(arp_proto_ip),
-                       source.hardware_address_length.eq(6),
-                       source.protocol_address_length.eq(4),
-                       source.source_mac_address.eq(mac_address),
-                       source.source_ip_address.eq(ip_address),
+                       source.hwtype.eq(arp_hwtype_ethernet),
+                       source.proto.eq(arp_proto_ip),
+                       source.hwsize.eq(6),
+                       source.protosize.eq(4),
+                       source.sender_mac.eq(mac_address),
+                       source.sender_ip.eq(ip_address),
                        If(sink.reply,
-                               source.operation.eq(arp_opcode_reply),
-                               source.destination_mac_address.eq(sink.mac_address),
-                               source.destination_ip_address.eq(sink.ip_address)
+                               source.opcode.eq(arp_opcode_reply),
+                               source.target_mac.eq(sink.mac_address),
+                               source.target_ip.eq(sink.ip_address)
                        ).Elif(sink.request,
-                               source.operation.eq(arp_opcode_request),
-                               source.destination_mac_address.eq(0xffffffffffff),
-                               source.destination_ip_address.eq(sink.ip_address)
+                               source.opcode.eq(arp_opcode_request),
+                               source.target_mac.eq(0xffffffffffff),
+                               source.target_ip.eq(sink.ip_address)
                        )
                ]
                fsm.act("SEND",
@@ -69,8 +69,8 @@ class LiteEthARPTX(Module):
                        source.sop.eq(counter.value == 0),
                        source.eop.eq(counter.value == arp_packet_length-1),
                        Record.connect(packetizer.source, self.source),
-                       self.source.destination_mac_address.eq(source.destination_mac_address),
-                       self.source.source_mac_address.eq(mac_address),
+                       self.source.target_mac.eq(source.target_mac),
+                       self.source.sender_mac.eq(mac_address),
                        self.source.ethernet_type.eq(ethernet_type_arp),
                        If(self.source.stb & self.source.ack,
                                sink.ack.eq(source.eop),
@@ -103,22 +103,22 @@ class LiteEthARPRX(Module):
                valid = Signal()
                self.comb += valid.eq(
                        sink.stb &
-                       (sink.hardware_type == arp_hwtype_ethernet) &
-                       (sink.protocol_type == arp_proto_ip) &
-                       (sink.hardware_address_length == 6) &
-                       (sink.protocol_address_length == 4) &
-                       (sink.destination_ip_address == ip_address)
+                       (sink.hwtype == arp_hwtype_ethernet) &
+                       (sink.proto == arp_proto_ip) &
+                       (sink.hwsize == 6) &
+                       (sink.protosize == 4) &
+                       (sink.target_ip == ip_address)
                )
                reply = Signal()
                request = Signal()
-               self.comb += Case(sink.operation, {
+               self.comb += Case(sink.opcode, {
                        arp_opcode_request      :       [request.eq(1)],
                        arp_opcode_reply        :       [reply.eq(1)],
                        "default"                       :       []
                        })
                self.comb += [
-                       source.ip_address.eq(sink.source_ip_address),
-                       source.mac_address.eq(sink.source_mac_address)
+                       source.ip_address.eq(sink.sender_ip),
+                       source.mac_address.eq(sink.sender_mac)
                ]
                fsm.act("CHECK",
                        If(valid,
index 812dc8a0819cf9a28f405761d211bd152d7a7ffd..24120ed14661bac92f415334da4468ad767c07b4 100644 (file)
@@ -50,18 +50,18 @@ class LiteEthIPTX(Module):
                        packetizer.sink.sop.eq(self.sink.sop),
                        packetizer.sink.eop.eq(self.sink.eop),
                        self.sink.ack.eq(packetizer.sink.ack),
-                       packetizer.sink.destination_ip_address.eq(ip_address),
+                       packetizer.sink.target_ip.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.diff_services.eq(0),
                        packetizer.sink.ecn.eq(0),
                        packetizer.sink.identification.eq(0),
                        packetizer.sink.flags.eq(0),
                        packetizer.sink.fragment_offset.eq(0),
-                       packetizer.sink.time_to_live.eq(0x80),
-                       packetizer.sink.source_ip_address.eq(ip_address),
+                       packetizer.sink.ttl.eq(0x80),
+                       packetizer.sink.sender_ip.eq(ip_address),
                        packetizer.sink.data.eq(self.sink.data)
                ]
                sink = packetizer.source
@@ -70,10 +70,10 @@ class LiteEthIPTX(Module):
                self.submodules += checksum
                self.comb += [
                        checksum.header.eq(packetizer.header),
-                       packetizer.sink.header_checksum.eq(checksum.value)
+                       packetizer.sink.checksum.eq(checksum.value)
                ]
 
-               destination_mac_address = Signal(48)
+               target_mac = Signal(48)
 
                fsm = FSM(reset_state="IDLE")
                self.submodules += fsm
@@ -99,12 +99,12 @@ class LiteEthIPTX(Module):
                                NextState("SEND")
                        )
                )
-               self.sync += If(arp_table.response.stb, destination_mac_address.eq(arp_table.response.mac_address))
+               self.sync += If(arp_table.response.stb, target_mac.eq(arp_table.response.mac_address))
                fsm.act("SEND",
                        Record.connect(packetizer.source, self.source),
                        self.source.ethernet_type.eq(ethernet_type_ip),
-                       self.source.destination_mac_address.eq(destination_mac_address),
-                       self.source.source_mac_address.eq(mac_address),
+                       self.source.target_mac.eq(target_mac),
+                       self.source.sender_mac.eq(mac_address),
                        If(self.source.stb & self.source.eop & self.source.ack,
                                # XXX manage failed
                                NextState("IDLE")
@@ -137,7 +137,7 @@ class LiteEthIPRX(Module):
                valid = Signal()
                self.comb += valid.eq(
                        sink.stb &
-                       (sink.destination_ip_address == ip_address) &
+                       (sink.target_ip == ip_address) &
                        (sink.version == 0x4) &
                        (sink.ihl == 0x5) &
                        (checksum.value == 0)
@@ -157,7 +157,7 @@ class LiteEthIPRX(Module):
                        sink.ack.eq(source.ack),
                        source.length.eq(sink.total_length - (sink.ihl*4)),
                        source.protocol.eq(sink.protocol),
-                       source.ip_address.eq(sink.destination_ip_address),
+                       source.ip_address.eq(sink.target_ip),
                        source.data.eq(sink.data),
                        source.error.eq(sink.error),
                        If(source.stb & source.eop & source.ack,
index 777d76d3f246601c2c575077c2f23205e09d72cc..f00429a670016b4c93dc278d0e4345eaf9125e34 100644 (file)
@@ -30,8 +30,8 @@ class LiteEthUDPTX(Module):
                        packetizer.sink.sop.eq(self.sink.sop),
                        packetizer.sink.eop.eq(self.sink.eop),
                        self.sink.ack.eq(packetizer.sink.ack),
-                       packetizer.sink.source_port.eq(self.sink.source_port),
-                       packetizer.sink.destination_port.eq(self.sink.destination_port),
+                       packetizer.sink.src_port.eq(self.sink.src_port),
+                       packetizer.sink.dst_port.eq(self.sink.dst_port),
                        packetizer.sink.length.eq(self.sink.length + udp_header_len),
                        packetizer.sink.checksum.eq(0),
                        packetizer.sink.data.eq(self.sink.data)
@@ -95,8 +95,8 @@ class LiteEthUDPRX(Module):
                        source.sop.eq(sink.sop),
                        source.eop.eq(sink.eop),
                        sink.ack.eq(source.ack),
-                       source.source_port.eq(sink.source_port),
-                       source.destination_port.eq(sink.destination_port),
+                       source.src_port.eq(sink.src_port),
+                       source.dst_port.eq(sink.dst_port),
                        source.ip_address.eq(0),
                        source.length.eq(sink.length - udp_header_len),
                        source.data.eq(sink.data),
index 6fbaa6f7e6bfcd6a7d9669c400741472e583b472..341028b7984b706df650c9c106ffe4a60f69c9d1 100644 (file)
@@ -47,8 +47,8 @@ class TB(Module):
 
                for i in range(8):
                        packet = mac.MACPacket([i for i in range(64)])
-                       packet.destination_mac_address = 0x010203040506
-                       packet.source_mac_address = 0x090A0B0C0C0D
+                       packet.target_mac = 0x010203040506
+                       packet.sender_mac = 0x090A0B0C0C0D
                        packet.ethernet_type = 0x0800
                        packet.encode_header()
                        yield from self.streamer.send(packet)
index 65f006f32387de00298797833857b9218a3c845f..8b27b4a605bb208cf0ad5aed35e0cae10089bd5d 100644 (file)
@@ -59,8 +59,8 @@ class ARP(Module):
                        print_arp(">>>>>>>>")
                        print_arp(packet)
                mac_packet = mac.MACPacket(packet)
-               mac_packet.destination_mac_address = packet.destination_mac_address
-               mac_packet.source_mac_address = packet.source_mac_address
+               mac_packet.target_mac = packet.target_mac
+               mac_packet.sender_mac = packet.sender_mac
                mac_packet.ethernet_type = ethernet_type_arp
                self.mac.send(mac_packet)
 
@@ -75,47 +75,47 @@ class ARP(Module):
        def process(self, packet):
                if len(packet) != arp_packet_length-arp_header_len:
                        raise ValueError
-               if packet.hardware_type != arp_hwtype_ethernet:
+               if packet.hwtype != arp_hwtype_ethernet:
                        raise ValueError
-               if packet.protocol_type != arp_proto_ip:
+               if packet.proto != arp_proto_ip:
                        raise ValueError
-               if packet.hardware_address_length != 6:
+               if packet.hwsize != 6:
                        raise ValueError
-               if packet.protocol_address_length != 4:
+               if packet.protosize != 4:
                        raise ValueError
-               if packet.operation == arp_opcode_request:
+               if packet.opcode == arp_opcode_request:
                        self.process_request(packet)
-               elif packet.operation == arp_opcode_reply:
+               elif packet.opcode == arp_opcode_reply:
                        self.process_reply(packet)
 
        def process_request(self, request):
-               if request.destination_ip_address == self.ip_address:
+               if request.target_ip == self.ip_address:
                        reply = ARPPacket([0]*(arp_packet_length-arp_header_len))
-                       reply.hardware_type = arp_hwtype_ethernet
-                       reply.protocol_type = arp_proto_ip
-                       reply.operation = arp_opcode_reply
-                       reply.hardware_address_length = 6
-                       reply.protocol_address_length = 4
-                       reply.source_mac_address = self.mac_address
-                       reply.source_ip_address = self.ip_address
-                       reply.destination_mac_address = request.source_mac_address
-                       reply.destination_ip_address = request.source_ip_address
+                       reply.hwtype = arp_hwtype_ethernet
+                       reply.proto = arp_proto_ip
+                       reply.opcode = arp_opcode_reply
+                       reply.hwsize = 6
+                       reply.protosize = 4
+                       reply.sender_mac = self.mac_address
+                       reply.sender_ip = self.ip_address
+                       reply.target_mac = request.sender_mac
+                       reply.target_ip = request.sender_ip
                        self.send(reply)
 
        def process_reply(self, reply):
-               self.table[reply.source_ip_address] = reply.source_mac_address
+               self.table[reply.sender_ip] = reply.sender_mac
 
        def request(self, ip_address):
                request = ARPPacket([0]*(arp_packet_length-arp_header_len))
-               request.hardware_type = arp_hwtype_ethernet
-               request.protocol_type = arp_proto_ip
-               request.operation = arp_opcode_request
-               request.hardware_address_length = 6
-               request.protocol_address_length = 4
-               request.source_mac_address = self.mac_address
-               request.source_ip_address = self.ip_address
-               request.destination_mac_address = 0xffffffffffff
-               request.destination_ip_address = ip_address
+               request.hwtype = arp_hwtype_ethernet
+               request.proto = arp_proto_ip
+               request.opcode = arp_opcode_request
+               request.hwsize = 6
+               request.protosize = 4
+               request.sender_mac = self.mac_address
+               request.sender_ip = self.ip_address
+               request.target_mac = 0xffffffffffff
+               request.target_ip = ip_address
 
 if __name__ == "__main__":
        from liteeth.test.model.dumps import *
index 8c6cee86831e0b8c8307ca0e85514fd71d48f5e1..8245ed5c50b42d6bd436f3748a3cbfe3d4143c0d 100644 (file)
@@ -18,15 +18,15 @@ arp_request = format_dump("""
 00 22 19 22 54 9e a9 fe 64 62""")
 
 arp_request_infos = {
-       "source_mac_address"            :       0x00123f979201,
-       "destination_mac_address"       :       0x00221922549e,
+       "sender_mac"            :       0x00123f979201,
+       "target_mac"    :       0x00221922549e,
        "ethernet_type"                         :       0x806,
-       "hardware_type"                         :       0x1,
-       "operation"                                     :       0x1,
-       "protocol_address_length"       :       0x4,
-       "protocol_type"                         :       0x800,
-       "source_ip_address"                     :       0xa9feff42,
-       "destination_ip_address"        :       0xa9fe6462
+       "hwtype"                                :       0x1,
+       "opcode"                                        :       0x1,
+       "protosize"     :       0x4,
+       "proto"                         :       0x800,
+       "sender_ip"                     :       0xa9feff42,
+       "target_ip"     :       0xa9fe6462
 
 }
 
@@ -37,15 +37,15 @@ arp_reply = format_dump("""
 00 00 00 00 00 00 00 00 00 00 00 00""")
 
 arp_reply_infos = {
-       "source_mac_address"            :       0x00221922549e,
-       "destination_mac_address"       :       0x00123f979201,
+       "sender_mac"            :       0x00221922549e,
+       "target_mac"    :       0x00123f979201,
        "ethernet_type"                         :       0x806,
-       "hardware_type"                         :       0x1,
-       "operation"                                     :       0x2,
-       "protocol_address_length"       :       0x4,
-       "protocol_type"                         :       0x800,
-       "source_ip_address"                     :       0xa9fe6462,
-       "destination_ip_address"        :       0xa9feff42
+       "hwtype"                                :       0x1,
+       "opcode"                                        :       0x2,
+       "protosize"     :       0x4,
+       "proto"                         :       0x800,
+       "sender_ip"                     :       0xa9fe6462,
+       "target_ip"     :       0xa9feff42
 }
 
 udp = format_dump("""
@@ -58,11 +58,11 @@ aa 9b 4e 4d f9 2e 51 52 fe ff 65 31 3a 71 34 3a
 34 3a 55 54 7e 62 31 3a 79 31 3a 71 65""")
 
 udp_infos = {
-       "source_mac_address"            :       0x00140b333327,
-       "destination_mac_address"       :       0xd07ab596cd0a,
+       "sender_mac"            :       0x00140b333327,
+       "target_mac"    :       0xd07ab596cd0a,
        "protocol"                                      :       0x11,
-       "source_ip_address"                     :       0xc0a80165,
-       "destination_ip_address"        :       0xb27b0d78,
-       "source_port"                           :       0xa63f,
-       "destination_port"                      :       0x690f
+       "sender_ip"                     :       0xc0a80165,
+       "target_ip"     :       0xb27b0d78,
+       "src_port"                              :       0xa63f,
+       "dst_port"                      :       0x690f
 }
index 9c5db8947d864e4a0db0c20cce728eed97879cb5..afac3298029ac56441f469ef7ce10ff26028cdf7 100644 (file)
@@ -87,8 +87,8 @@ class IP(Module):
                        print_ip(">>>>>>>>")
                        print_ip(packet)
                mac_packet = mac.MACPacket(packet)
-               mac_packet.destination_mac_address = 0x12345678abcd # XXX
-               mac_packet.source_mac_address = self.mac_address
+               mac_packet.target_mac = 0x12345678abcd # XXX
+               mac_packet.sender_mac = self.mac_address
                mac_packet.ethernet_type = ethernet_type_ip
                self.mac.send(mac_packet)
 
index c76853ee9d24ce3bf845b05afc4e92ed40f6b8b0..f43a32aa3f83e0bd815cdada6308907c3906e853 100644 (file)
@@ -57,16 +57,16 @@ class UDP(Module):
                ip_packet = ip.IPPacket(packet)
                ip_packet.version = 0x4
                ip_packet.ihl = 0x5
-               ip_packet.dscp = 0x0
+               ip_packet.diff_services = 0x0
                ip_packet.ecn = 0x0
                ip_packet.total_length = len(packet) + ip_packet.ihl
                ip_packet.identification = 0
                ip_packet.flags = 0
                ip_packet.fragment_offset = 0
-               ip_packet.time_to_live = 0x80
-               ip_packet.source_ip_address = self.ip_address
-               ip_packet.destination_ip_address = 0x12345678 # XXX
-               ip_packet.header_checksum = 0
+               ip_packet.ttl = 0x80
+               ip_packet.sender_ip = self.ip_address
+               ip_packet.target_ip = 0x12345678 # XXX
+               ip_packet.checksum = 0
                ip_packet.protocol = udp_protocol
                self.ip.send(ip_packet)
 
index e0a0549a5cb96d1e3013bc25581f629288b51091..4dc70a9846f84af7c1f6146e34f9dc67a67d2bf3 100644 (file)
@@ -26,8 +26,8 @@ class TB(Module):
                self.comb += [
                        Record.connect(self.streamer.source, self.udp_ip.sink),
                        self.udp_ip.sink.ip_address.eq(0x12345678),
-                       self.udp_ip.sink.source_port.eq(0x1234),
-                       self.udp_ip.sink.destination_port.eq(0x5678),
+                       self.udp_ip.sink.src_port.eq(0x1234),
+                       self.udp_ip.sink.dst_port.eq(0x5678),
                        self.udp_ip.sink.length.eq(64),
                        Record.connect(self.udp_ip.source, self.logger.sink)
                ]