1
0
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:
Alex Forencich 2016-09-30 22:02:29 -07:00
parent 0b6614e8d4
commit 4e522e52af
4 changed files with 162 additions and 137 deletions

View File

@ -40,7 +40,8 @@ class ARPFrame(object):
arp_sha=0x5A5152535455, arp_sha=0x5A5152535455,
arp_spa=0xc0a80164, arp_spa=0xc0a80164,
arp_tha=0xDAD1D2D3D4D5, arp_tha=0xDAD1D2D3D4D5,
arp_tpa=0xc0a80164): arp_tpa=0xc0a80164
):
self.eth_dest_mac = eth_dest_mac self.eth_dest_mac = eth_dest_mac
self.eth_src_mac = eth_src_mac self.eth_src_mac = eth_src_mac
@ -122,7 +123,8 @@ class ARPFrame(object):
def __eq__(self, other): def __eq__(self, other):
if type(other) is ARPFrame: if type(other) is ARPFrame:
return (self.eth_src_mac == other.eth_src_mac and return (
self.eth_src_mac == other.eth_src_mac and
self.eth_dest_mac == other.eth_dest_mac and self.eth_dest_mac == other.eth_dest_mac and
self.eth_type == other.eth_type and self.eth_type == other.eth_type and
self.arp_htype == other.arp_htype and self.arp_htype == other.arp_htype and
@ -133,10 +135,13 @@ class ARPFrame(object):
self.arp_sha == other.arp_sha and self.arp_sha == other.arp_sha and
self.arp_spa == other.arp_spa and self.arp_spa == other.arp_spa and
self.arp_tha == other.arp_tha and self.arp_tha == other.arp_tha and
self.arp_tpa == other.arp_tpa) self.arp_tpa == other.arp_tpa
)
return False
def __repr__(self): 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_src_mac=0x%012x, ' % self.eth_src_mac) +
('eth_type=0x%04x, ' % self.eth_type) + ('eth_type=0x%04x, ' % self.eth_type) +
('arp_htype=0x%04x, ' % self.arp_htype) + ('arp_htype=0x%04x, ' % self.arp_htype) +
@ -147,7 +152,8 @@ class ARPFrame(object):
('arp_sha=0x%012x, ' % self.arp_sha) + ('arp_sha=0x%012x, ' % self.arp_sha) +
('arp_spa=0x%08x, ' % self.arp_spa) + ('arp_spa=0x%08x, ' % self.arp_spa) +
('arp_tha=0x%012x, ' % self.arp_tha) + ('arp_tha=0x%012x, ' % self.arp_tha) +
('arp_tpa=0x%08x)' % self.arp_tpa)) ('arp_tpa=0x%08x)' % self.arp_tpa)
)
class ARPFrameSource(): class ARPFrameSource():

View File

@ -105,10 +105,13 @@ class EthFrame(object):
def __eq__(self, other): def __eq__(self, other):
if type(other) is EthFrame: if type(other) is EthFrame:
return (self.eth_src_mac == other.eth_src_mac and return (
self.eth_src_mac == other.eth_src_mac and
self.eth_dest_mac == other.eth_dest_mac and self.eth_dest_mac == other.eth_dest_mac and
self.eth_type == other.eth_type and self.eth_type == other.eth_type and
self.payload == other.payload) self.payload == other.payload
)
return False
def __repr__(self): def __repr__(self):
fcs = 'None' fcs = 'None'

View File

@ -28,7 +28,8 @@ import eth_ep
import struct import struct
class IPFrame(object): class IPFrame(object):
def __init__(self, payload=b'', def __init__(self,
payload=b'',
eth_dest_mac=0, eth_dest_mac=0,
eth_src_mac=0, eth_src_mac=0,
eth_type=0, eth_type=0,
@ -44,7 +45,8 @@ class IPFrame(object):
ip_protocol=0x11, ip_protocol=0x11,
ip_header_checksum=None, ip_header_checksum=None,
ip_source_ip=0xc0a80164, ip_source_ip=0xc0a80164,
ip_dest_ip=0xc0a80165): ip_dest_ip=0xc0a80165
):
self._payload = axis_ep.AXIStreamFrame() self._payload = axis_ep.AXIStreamFrame()
self.eth_dest_mac = eth_dest_mac self.eth_dest_mac = eth_dest_mac
@ -192,7 +194,8 @@ class IPFrame(object):
def __eq__(self, other): def __eq__(self, other):
if type(other) is IPFrame: if type(other) is IPFrame:
return (self.eth_src_mac == other.eth_src_mac and return (
self.eth_src_mac == other.eth_src_mac and
self.eth_dest_mac == other.eth_dest_mac and self.eth_dest_mac == other.eth_dest_mac and
self.eth_type == other.eth_type and self.eth_type == other.eth_type and
self.ip_version == other.ip_version and self.ip_version == other.ip_version and
@ -208,10 +211,13 @@ class IPFrame(object):
self.ip_header_checksum == other.ip_header_checksum and self.ip_header_checksum == other.ip_header_checksum and
self.ip_source_ip == other.ip_source_ip and self.ip_source_ip == other.ip_source_ip and
self.ip_dest_ip == other.ip_dest_ip and self.ip_dest_ip == other.ip_dest_ip and
self.payload == other.payload) self.payload == other.payload
)
return False
def __repr__(self): 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_dest_mac=0x%012x, ' % self.eth_dest_mac) +
('eth_src_mac=0x%012x, ' % self.eth_src_mac) + ('eth_src_mac=0x%012x, ' % self.eth_src_mac) +
('eth_type=0x%04x, ' % self.eth_type) + ('eth_type=0x%04x, ' % self.eth_type) +
@ -225,9 +231,10 @@ class IPFrame(object):
('ip_fragment_offset=%d, ' % self.ip_fragment_offset) + ('ip_fragment_offset=%d, ' % self.ip_fragment_offset) +
('ip_ttl=%d, ' % self.ip_ttl) + ('ip_ttl=%d, ' % self.ip_ttl) +
('ip_protocol=0x%02x, ' % self.ip_protocol) + ('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_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(): class IPFrameSource():

View File

@ -29,7 +29,8 @@ import ip_ep
import struct import struct
class UDPFrame(object): class UDPFrame(object):
def __init__(self, payload=b'', def __init__(self,
payload=b'',
eth_dest_mac=0, eth_dest_mac=0,
eth_src_mac=0, eth_src_mac=0,
eth_type=0, eth_type=0,
@ -49,7 +50,8 @@ class UDPFrame(object):
udp_source_port=1, udp_source_port=1,
udp_dest_port=2, udp_dest_port=2,
udp_length=None, udp_length=None,
udp_checksum=None): udp_checksum=None
):
self._payload = axis_ep.AXIStreamFrame() self._payload = axis_ep.AXIStreamFrame()
self.eth_dest_mac = eth_dest_mac self.eth_dest_mac = eth_dest_mac
@ -212,7 +214,8 @@ class UDPFrame(object):
data += self.payload.data data += self.payload.data
return ip_ep.IPFrame(data, return ip_ep.IPFrame(
data,
self.eth_dest_mac, self.eth_dest_mac,
self.eth_src_mac, self.eth_src_mac,
self.eth_type, self.eth_type,
@ -228,7 +231,8 @@ class UDPFrame(object):
self.ip_protocol, self.ip_protocol,
self.ip_header_checksum, self.ip_header_checksum,
self.ip_source_ip, self.ip_source_ip,
self.ip_dest_ip) self.ip_dest_ip
)
def parse_axis(self, data): def parse_axis(self, data):
frame = eth_ep.EthFrame() frame = eth_ep.EthFrame()
@ -267,7 +271,8 @@ class UDPFrame(object):
def __eq__(self, other): def __eq__(self, other):
if type(other) is UDPFrame: if type(other) is UDPFrame:
return (self.eth_src_mac == other.eth_src_mac and return (
self.eth_src_mac == other.eth_src_mac and
self.eth_dest_mac == other.eth_dest_mac and self.eth_dest_mac == other.eth_dest_mac and
self.eth_type == other.eth_type and self.eth_type == other.eth_type and
self.ip_version == other.ip_version and self.ip_version == other.ip_version and
@ -287,10 +292,13 @@ class UDPFrame(object):
self.udp_dest_port == other.udp_dest_port and self.udp_dest_port == other.udp_dest_port and
self.udp_length == other.udp_length and self.udp_length == other.udp_length and
self.udp_checksum == other.udp_checksum and self.udp_checksum == other.udp_checksum and
self.payload == other.payload) self.payload == other.payload
)
return False
def __repr__(self): 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_dest_mac=0x%012x, ' % self.eth_dest_mac) +
('eth_src_mac=0x%012x, ' % self.eth_src_mac) + ('eth_src_mac=0x%012x, ' % self.eth_src_mac) +
('eth_type=0x%04x, ' % self.eth_type) + ('eth_type=0x%04x, ' % self.eth_type) +
@ -304,13 +312,14 @@ class UDPFrame(object):
('ip_fragment_offset=%d, ' % self.ip_fragment_offset) + ('ip_fragment_offset=%d, ' % self.ip_fragment_offset) +
('ip_ttl=%d, ' % self.ip_ttl) + ('ip_ttl=%d, ' % self.ip_ttl) +
('ip_protocol=0x%02x, ' % self.ip_protocol) + ('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_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) +
('udp_source_port=%d, ' % self.udp_source_port) + ('udp_source_port=%d, ' % self.udp_source_port) +
('udp_dest_port=%d, ' % self.udp_dest_port) + ('udp_dest_port=%d, ' % self.udp_dest_port) +
('udp_length=%d, ' % self.udp_length) + ('udp_length=%d, ' % self.udp_length) +
('udp_checksum=%04x)' % self.udp_checksum)) ('udp_checksum=0x%04x)' % self.udp_checksum)
)
class UDPFrameSource(): class UDPFrameSource():