mirror of
https://github.com/corundum/corundum.git
synced 2025-01-30 08:32:52 +08:00
Clean up endpoint modules
This commit is contained in:
parent
0b6614e8d4
commit
4e522e52af
74
tb/arp_ep.py
74
tb/arp_ep.py
@ -29,18 +29,19 @@ import struct
|
||||
|
||||
class ARPFrame(object):
|
||||
def __init__(self,
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
arp_htype=1,
|
||||
arp_ptype=0x0800,
|
||||
arp_hlen=6,
|
||||
arp_plen=4,
|
||||
arp_oper=2,
|
||||
arp_sha=0x5A5152535455,
|
||||
arp_spa=0xc0a80164,
|
||||
arp_tha=0xDAD1D2D3D4D5,
|
||||
arp_tpa=0xc0a80164):
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
arp_htype=1,
|
||||
arp_ptype=0x0800,
|
||||
arp_hlen=6,
|
||||
arp_plen=4,
|
||||
arp_oper=2,
|
||||
arp_sha=0x5A5152535455,
|
||||
arp_spa=0xc0a80164,
|
||||
arp_tha=0xDAD1D2D3D4D5,
|
||||
arp_tpa=0xc0a80164
|
||||
):
|
||||
|
||||
self.eth_dest_mac = eth_dest_mac
|
||||
self.eth_src_mac = eth_src_mac
|
||||
@ -122,32 +123,37 @@ class ARPFrame(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) is ARPFrame:
|
||||
return (self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.arp_htype == other.arp_htype and
|
||||
self.arp_ptype == other.arp_ptype and
|
||||
self.arp_hlen == other.arp_hlen and
|
||||
self.arp_plen == other.arp_plen and
|
||||
self.arp_oper == other.arp_oper and
|
||||
self.arp_sha == other.arp_sha and
|
||||
self.arp_spa == other.arp_spa and
|
||||
self.arp_tha == other.arp_tha and
|
||||
self.arp_tpa == other.arp_tpa)
|
||||
return (
|
||||
self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.arp_htype == other.arp_htype and
|
||||
self.arp_ptype == other.arp_ptype and
|
||||
self.arp_hlen == other.arp_hlen and
|
||||
self.arp_plen == other.arp_plen and
|
||||
self.arp_oper == other.arp_oper and
|
||||
self.arp_sha == other.arp_sha and
|
||||
self.arp_spa == other.arp_spa and
|
||||
self.arp_tha == other.arp_tha and
|
||||
self.arp_tpa == other.arp_tpa
|
||||
)
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
return (('ArpFrame(eth_dest_mac=0x%012x, ' % self.eth_dest_mac) +
|
||||
return (
|
||||
('ArpFrame(eth_dest_mac=0x%012x, ' % self.eth_dest_mac) +
|
||||
('eth_src_mac=0x%012x, ' % self.eth_src_mac) +
|
||||
('eth_type=0x%04x, ' % self.eth_type) +
|
||||
('arp_htype=0x%04x, ' % self.arp_htype) +
|
||||
('arp_ptype=0x%04x, ' % self.arp_ptype) +
|
||||
('arp_hlen=%d, ' % self.arp_hlen) +
|
||||
('arp_plen=%d, ' % self.arp_plen) +
|
||||
('arp_oper=0x%04x, ' % self.arp_oper) +
|
||||
('arp_sha=0x%012x, ' % self.arp_sha) +
|
||||
('arp_spa=0x%08x, ' % self.arp_spa) +
|
||||
('arp_tha=0x%012x, ' % self.arp_tha) +
|
||||
('arp_tpa=0x%08x)' % self.arp_tpa))
|
||||
('arp_htype=0x%04x, ' % self.arp_htype) +
|
||||
('arp_ptype=0x%04x, ' % self.arp_ptype) +
|
||||
('arp_hlen=%d, ' % self.arp_hlen) +
|
||||
('arp_plen=%d, ' % self.arp_plen) +
|
||||
('arp_oper=0x%04x, ' % self.arp_oper) +
|
||||
('arp_sha=0x%012x, ' % self.arp_sha) +
|
||||
('arp_spa=0x%08x, ' % self.arp_spa) +
|
||||
('arp_tha=0x%012x, ' % self.arp_tha) +
|
||||
('arp_tpa=0x%08x)' % self.arp_tpa)
|
||||
)
|
||||
|
||||
|
||||
class ARPFrameSource():
|
||||
|
11
tb/eth_ep.py
11
tb/eth_ep.py
@ -105,10 +105,13 @@ class EthFrame(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) is EthFrame:
|
||||
return (self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.payload == other.payload)
|
||||
return (
|
||||
self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.payload == other.payload
|
||||
)
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
fcs = 'None'
|
||||
|
81
tb/ip_ep.py
81
tb/ip_ep.py
@ -28,23 +28,25 @@ import eth_ep
|
||||
import struct
|
||||
|
||||
class IPFrame(object):
|
||||
def __init__(self, payload=b'',
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
ip_version=4,
|
||||
ip_ihl=5,
|
||||
ip_dscp=0,
|
||||
ip_ecn=0,
|
||||
ip_length=None,
|
||||
ip_identification=0,
|
||||
ip_flags=2,
|
||||
ip_fragment_offset=0,
|
||||
ip_ttl=64,
|
||||
ip_protocol=0x11,
|
||||
ip_header_checksum=None,
|
||||
ip_source_ip=0xc0a80164,
|
||||
ip_dest_ip=0xc0a80165):
|
||||
def __init__(self,
|
||||
payload=b'',
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
ip_version=4,
|
||||
ip_ihl=5,
|
||||
ip_dscp=0,
|
||||
ip_ecn=0,
|
||||
ip_length=None,
|
||||
ip_identification=0,
|
||||
ip_flags=2,
|
||||
ip_fragment_offset=0,
|
||||
ip_ttl=64,
|
||||
ip_protocol=0x11,
|
||||
ip_header_checksum=None,
|
||||
ip_source_ip=0xc0a80164,
|
||||
ip_dest_ip=0xc0a80165
|
||||
):
|
||||
|
||||
self._payload = axis_ep.AXIStreamFrame()
|
||||
self.eth_dest_mac = eth_dest_mac
|
||||
@ -192,26 +194,30 @@ class IPFrame(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) is IPFrame:
|
||||
return (self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.ip_version == other.ip_version and
|
||||
self.ip_ihl == other.ip_ihl and
|
||||
self.ip_dscp == other.ip_dscp and
|
||||
self.ip_ecn == other.ip_ecn and
|
||||
self.ip_length == other.ip_length and
|
||||
self.ip_identification == other.ip_identification and
|
||||
self.ip_flags == other.ip_flags and
|
||||
self.ip_fragment_offset == other.ip_fragment_offset and
|
||||
self.ip_ttl == other.ip_ttl and
|
||||
self.ip_protocol == other.ip_protocol and
|
||||
self.ip_header_checksum == other.ip_header_checksum and
|
||||
self.ip_source_ip == other.ip_source_ip and
|
||||
self.ip_dest_ip == other.ip_dest_ip and
|
||||
self.payload == other.payload)
|
||||
return (
|
||||
self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.ip_version == other.ip_version and
|
||||
self.ip_ihl == other.ip_ihl and
|
||||
self.ip_dscp == other.ip_dscp and
|
||||
self.ip_ecn == other.ip_ecn and
|
||||
self.ip_length == other.ip_length and
|
||||
self.ip_identification == other.ip_identification and
|
||||
self.ip_flags == other.ip_flags and
|
||||
self.ip_fragment_offset == other.ip_fragment_offset and
|
||||
self.ip_ttl == other.ip_ttl and
|
||||
self.ip_protocol == other.ip_protocol and
|
||||
self.ip_header_checksum == other.ip_header_checksum and
|
||||
self.ip_source_ip == other.ip_source_ip and
|
||||
self.ip_dest_ip == other.ip_dest_ip and
|
||||
self.payload == other.payload
|
||||
)
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
return (('IPFrame(payload=%s, ' % repr(self.payload)) +
|
||||
return (
|
||||
('IPFrame(payload=%s, ' % repr(self.payload)) +
|
||||
('eth_dest_mac=0x%012x, ' % self.eth_dest_mac) +
|
||||
('eth_src_mac=0x%012x, ' % self.eth_src_mac) +
|
||||
('eth_type=0x%04x, ' % self.eth_type) +
|
||||
@ -225,9 +231,10 @@ class IPFrame(object):
|
||||
('ip_fragment_offset=%d, ' % self.ip_fragment_offset) +
|
||||
('ip_ttl=%d, ' % self.ip_ttl) +
|
||||
('ip_protocol=0x%02x, ' % self.ip_protocol) +
|
||||
('ip_header_checksum=%x, ' % self.ip_header_checksum) +
|
||||
('ip_header_checksum=0x%x, ' % self.ip_header_checksum) +
|
||||
('ip_source_ip=0x%08x, ' % self.ip_source_ip) +
|
||||
('ip_dest_ip=0x%08x)' % self.ip_dest_ip))
|
||||
('ip_dest_ip=0x%08x)' % self.ip_dest_ip)
|
||||
)
|
||||
|
||||
|
||||
class IPFrameSource():
|
||||
|
133
tb/udp_ep.py
133
tb/udp_ep.py
@ -29,27 +29,29 @@ import ip_ep
|
||||
import struct
|
||||
|
||||
class UDPFrame(object):
|
||||
def __init__(self, payload=b'',
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
ip_version=4,
|
||||
ip_ihl=5,
|
||||
ip_dscp=0,
|
||||
ip_ecn=0,
|
||||
ip_length=None,
|
||||
ip_identification=0,
|
||||
ip_flags=2,
|
||||
ip_fragment_offset=0,
|
||||
ip_ttl=64,
|
||||
ip_protocol=0x11,
|
||||
ip_header_checksum=None,
|
||||
ip_source_ip=0xc0a80164,
|
||||
ip_dest_ip=0xc0a80165,
|
||||
udp_source_port=1,
|
||||
udp_dest_port=2,
|
||||
udp_length=None,
|
||||
udp_checksum=None):
|
||||
def __init__(self,
|
||||
payload=b'',
|
||||
eth_dest_mac=0,
|
||||
eth_src_mac=0,
|
||||
eth_type=0,
|
||||
ip_version=4,
|
||||
ip_ihl=5,
|
||||
ip_dscp=0,
|
||||
ip_ecn=0,
|
||||
ip_length=None,
|
||||
ip_identification=0,
|
||||
ip_flags=2,
|
||||
ip_fragment_offset=0,
|
||||
ip_ttl=64,
|
||||
ip_protocol=0x11,
|
||||
ip_header_checksum=None,
|
||||
ip_source_ip=0xc0a80164,
|
||||
ip_dest_ip=0xc0a80165,
|
||||
udp_source_port=1,
|
||||
udp_dest_port=2,
|
||||
udp_length=None,
|
||||
udp_checksum=None
|
||||
):
|
||||
|
||||
self._payload = axis_ep.AXIStreamFrame()
|
||||
self.eth_dest_mac = eth_dest_mac
|
||||
@ -212,23 +214,25 @@ class UDPFrame(object):
|
||||
|
||||
data += self.payload.data
|
||||
|
||||
return ip_ep.IPFrame(data,
|
||||
self.eth_dest_mac,
|
||||
self.eth_src_mac,
|
||||
self.eth_type,
|
||||
self.ip_version,
|
||||
self.ip_ihl,
|
||||
self.ip_dscp,
|
||||
self.ip_ecn,
|
||||
self.ip_length,
|
||||
self.ip_identification,
|
||||
self.ip_flags,
|
||||
self.ip_fragment_offset,
|
||||
self.ip_ttl,
|
||||
self.ip_protocol,
|
||||
self.ip_header_checksum,
|
||||
self.ip_source_ip,
|
||||
self.ip_dest_ip)
|
||||
return ip_ep.IPFrame(
|
||||
data,
|
||||
self.eth_dest_mac,
|
||||
self.eth_src_mac,
|
||||
self.eth_type,
|
||||
self.ip_version,
|
||||
self.ip_ihl,
|
||||
self.ip_dscp,
|
||||
self.ip_ecn,
|
||||
self.ip_length,
|
||||
self.ip_identification,
|
||||
self.ip_flags,
|
||||
self.ip_fragment_offset,
|
||||
self.ip_ttl,
|
||||
self.ip_protocol,
|
||||
self.ip_header_checksum,
|
||||
self.ip_source_ip,
|
||||
self.ip_dest_ip
|
||||
)
|
||||
|
||||
def parse_axis(self, data):
|
||||
frame = eth_ep.EthFrame()
|
||||
@ -267,30 +271,34 @@ class UDPFrame(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) is UDPFrame:
|
||||
return (self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.ip_version == other.ip_version and
|
||||
self.ip_ihl == other.ip_ihl and
|
||||
self.ip_dscp == other.ip_dscp and
|
||||
self.ip_ecn == other.ip_ecn and
|
||||
self.ip_length == other.ip_length and
|
||||
self.ip_identification == other.ip_identification and
|
||||
self.ip_flags == other.ip_flags and
|
||||
self.ip_fragment_offset == other.ip_fragment_offset and
|
||||
self.ip_ttl == other.ip_ttl and
|
||||
self.ip_protocol == other.ip_protocol and
|
||||
self.ip_header_checksum == other.ip_header_checksum and
|
||||
self.ip_source_ip == other.ip_source_ip and
|
||||
self.ip_dest_ip == other.ip_dest_ip and
|
||||
self.udp_source_port == other.udp_source_port and
|
||||
self.udp_dest_port == other.udp_dest_port and
|
||||
self.udp_length == other.udp_length and
|
||||
self.udp_checksum == other.udp_checksum and
|
||||
self.payload == other.payload)
|
||||
return (
|
||||
self.eth_src_mac == other.eth_src_mac and
|
||||
self.eth_dest_mac == other.eth_dest_mac and
|
||||
self.eth_type == other.eth_type and
|
||||
self.ip_version == other.ip_version and
|
||||
self.ip_ihl == other.ip_ihl and
|
||||
self.ip_dscp == other.ip_dscp and
|
||||
self.ip_ecn == other.ip_ecn and
|
||||
self.ip_length == other.ip_length and
|
||||
self.ip_identification == other.ip_identification and
|
||||
self.ip_flags == other.ip_flags and
|
||||
self.ip_fragment_offset == other.ip_fragment_offset and
|
||||
self.ip_ttl == other.ip_ttl and
|
||||
self.ip_protocol == other.ip_protocol and
|
||||
self.ip_header_checksum == other.ip_header_checksum and
|
||||
self.ip_source_ip == other.ip_source_ip and
|
||||
self.ip_dest_ip == other.ip_dest_ip and
|
||||
self.udp_source_port == other.udp_source_port and
|
||||
self.udp_dest_port == other.udp_dest_port and
|
||||
self.udp_length == other.udp_length and
|
||||
self.udp_checksum == other.udp_checksum and
|
||||
self.payload == other.payload
|
||||
)
|
||||
return False
|
||||
|
||||
def __repr__(self):
|
||||
return (('UDPFrame(payload=%s, ' % repr(self.payload)) +
|
||||
return (
|
||||
('UDPFrame(payload=%s, ' % repr(self.payload)) +
|
||||
('eth_dest_mac=0x%012x, ' % self.eth_dest_mac) +
|
||||
('eth_src_mac=0x%012x, ' % self.eth_src_mac) +
|
||||
('eth_type=0x%04x, ' % self.eth_type) +
|
||||
@ -304,13 +312,14 @@ class UDPFrame(object):
|
||||
('ip_fragment_offset=%d, ' % self.ip_fragment_offset) +
|
||||
('ip_ttl=%d, ' % self.ip_ttl) +
|
||||
('ip_protocol=0x%02x, ' % self.ip_protocol) +
|
||||
('ip_header_checksum=%x, ' % self.ip_header_checksum) +
|
||||
('ip_header_checksum=0x%x, ' % self.ip_header_checksum) +
|
||||
('ip_source_ip=0x%08x, ' % self.ip_source_ip) +
|
||||
('ip_dest_ip=0x%08x, ' % self.ip_dest_ip) +
|
||||
('udp_source_port=%d, ' % self.udp_source_port) +
|
||||
('udp_dest_port=%d, ' % self.udp_dest_port) +
|
||||
('udp_length=%d, ' % self.udp_length) +
|
||||
('udp_checksum=%04x)' % self.udp_checksum))
|
||||
('udp_checksum=0x%04x)' % self.udp_checksum)
|
||||
)
|
||||
|
||||
|
||||
class UDPFrameSource():
|
||||
|
Loading…
x
Reference in New Issue
Block a user