diff --git a/src/fortygbe.py b/src/fortygbe.py index adfa6b27..0cd5d37e 100644 --- a/src/fortygbe.py +++ b/src/fortygbe.py @@ -36,6 +36,33 @@ def __init__(self, parent, name, address, length_bytes, 'multicast_ip' : 0x20, 'multicast_mask' : 0x24} + @property + def ip_address(self): + ip = self._wbone_rd(self.address + self.reg_map['ip']) + ip_address = IpAddress(ip) + return ip_address + + @property + def mac(self): + gbedata = [] + for ctr in range(0xC, 0x14, 4): + gbedata.append(self._wbone_rd(self.address + ctr)) + gbebytes = [] + for d in gbedata: + gbebytes.append((d >> 24) & 0xff) + gbebytes.append((d >> 16) & 0xff) + gbebytes.append((d >> 8) & 0xff) + gbebytes.append((d >> 0) & 0xff) + pd = gbebytes + return Mac('{}:{}:{}:{}:{}:{}'.format( + *pd[2:])) + + @property + def port(self): + en_port = self._wbone_rd(self.address + self.reg_map['fabric_port']) + port = en_port & (2 ** 16 - 1) + return port + def post_create_update(self, raw_device_info): """ Update the device with information not available at creation. @@ -99,7 +126,7 @@ def _wbone_wr(self, addr, val): def fabric_enable(self): """ - Enables 40G corei fabric interface. + Enables 40G core fabric interface. :return: """ en_port = self._wbone_rd(self.address + self.reg_map['fabric_en']) @@ -133,8 +160,7 @@ def get_mac(self): :return: Mac object """ - details = self.get_gbe_core_details() - return details['mac'] + return self.mac def get_ip(self): """ @@ -142,8 +168,6 @@ def get_ip(self): :return: IpAddress object """ - ip = self._wbone_rd(self.address + self.reg_map['ip']) - self.ip_address = IpAddress(ip) return self.ip_address def get_port(self): @@ -152,8 +176,6 @@ def get_port(self): :return: int """ - en_port = self._wbone_rd(self.address + self.reg_map['fabric_port']) - self.port = en_port & (2 ** 16 - 1) return self.port def set_port(self, port): @@ -170,7 +192,6 @@ def set_port(self, port): errmsg = 'Error setting 40gbe port to 0x%04x' % port self.logger.error(errmsg) raise ValueError(errmsg) - self.port = port def get_gbe_core_details(self, read_arp=False, read_cpu=False): """ @@ -230,9 +251,6 @@ def get_gbe_core_details(self, read_arp=False, read_cpu=False): if read_cpu: # returnval.update(self.get_cpu_details(gbedata)) self.logger.warn('Retrieving CPU packet buffers not yet implemented.') - self.mac = returnval['mac'] - self.ip_address = returnval['ip'] - self.port = returnval['fabric_port'] return returnval def get_arp_details(self, port_dump=None): diff --git a/src/gbe.py b/src/gbe.py index d956c7e4..283b1820 100644 --- a/src/gbe.py +++ b/src/gbe.py @@ -20,9 +20,6 @@ def __init__(self, parent, name, address, length_bytes, device_info=None): self.name = name self.address = address self.length_bytes = length_bytes - self.mac = None - self.ip_address = None - self.port = None self.fullname = self.parent.host + ':' + self.name self.block_info = device_info self.process_device_info(device_info) @@ -34,6 +31,18 @@ def __init__(self, parent, name, address, length_bytes, device_info=None): # if self.parent.is_connected(): # self._check() + @property + def mac(self): + return None + + @property + def ip_address(self): + return None + + @property + def port(self): + return None + @classmethod def from_device_info(cls, parent, device_name, device_info, memorymap_dict, **kwargs): """ @@ -99,7 +108,6 @@ def process_device_info(self, device_info): if mac is None or ip_address is None or port is None: raise ValueError('%s: 10Gbe interface must ' 'have mac, ip and port.' % self.fullname) - self.setup(mac, ip_address, port) def setup(self, mac, ipaddress, port): """ @@ -109,9 +117,10 @@ def setup(self, mac, ipaddress, port): :param ipaddress: String or Integer input :param port: String or Integer input """ - self.mac = Mac(mac) - self.ip_address = IpAddress(ipaddress) - self.port = port if isinstance(port, int) else int(port) + raise NotImplementedError('This is no longer required as the mac, ' + 'ip_address and port are no longer stored ' + 'as attributes. These values are retrieved ' + 'from the processing node when required.') def post_create_update(self, raw_device_info): """ diff --git a/src/onegbe.py b/src/onegbe.py index 09d75abe..c6b4f9e8 100644 --- a/src/onegbe.py +++ b/src/onegbe.py @@ -93,6 +93,18 @@ def __init__(self, parent, name, address, length_bytes, device_info=None): Gbe.__init__(self, parent, name, address, length_bytes, device_info) self.memmap_compliant = self._check_memmap_compliance() + @property + def mac(self): + return self.get_gbe_core_details()['mac'] + + @property + def ip_address(self): + return self.get_gbe_core_details()['ip'] + + @property + def port(self): + return self.get_gbe_core_details()['fabric_port'] + def _check_memmap_compliance(self): """ Look at the first word of the core's memory map and try to @@ -162,9 +174,9 @@ def dhcp_start(self): """ Configure this interface, then start a DHCP client on ALL interfaces. """ - if self.mac is None: + #if self.mac is None: # TODO get MAC from EEPROM serial number and assign here - self.mac = '0' + # self.mac = '0' reply, _ = self.parent.transport.katcprequest( name='tap-start', request_timeout=5, require_ok=True, diff --git a/src/tengbe.py b/src/tengbe.py index d79f5c0c..fff4f629 100644 --- a/src/tengbe.py +++ b/src/tengbe.py @@ -93,6 +93,18 @@ def __init__(self, parent, name, address, length_bytes, device_info=None): Gbe.__init__(self, parent, name, address, length_bytes, device_info) self.memmap_compliant = self._check_memmap_compliance() + @property + def mac(self): + return self.get_gbe_core_details()['mac'] + + @property + def ip_address(self): + return self.get_gbe_core_details()['ip'] + + @property + def port(self): + return self.get_gbe_core_details()['fabric_port'] + def _check_memmap_compliance(self): """ Look at the first word of the core's memory map and try to @@ -162,9 +174,9 @@ def dhcp_start(self): """ Configure this interface, then start a DHCP client on ALL interfaces. """ - if self.mac is None: + #if self.mac is None: # TODO get MAC from EEPROM serial number and assign here - self.mac = '0' + #self.mac = '0' reply, _ = self.parent.transport.katcprequest( name='tap-start', request_timeout=5, require_ok=True,