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
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
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),
)
)
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",
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),
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,
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
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
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")
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)
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,
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)
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),
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)
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)
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 *
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
}
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("""
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
}
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)
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)
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)
]