示例#1
0
文件: gbe.py 项目: ska-sa/casperfpga
 def print_gbe_core_details(self, arp=False, cpu=False, refresh=True):
     """
     Prints 10GbE core details.
     :param arp: boolean, include the ARP table
     :param cpu: boolean, include the CPU packet buffers
     :param refresh: read the 10gbe details first
     """
     if refresh or (self.core_details is None):
         self.get_gbe_core_details(arp, cpu)
     details = self.core_details
     print('------------------------')
     print('%s configuration:' % self.fullname)
     print('MAC: ', Mac.mac2str(int(details['mac'])))
     print('Gateway: ', details['gateway_ip'])
     print('IP: ', details['ip'])
     print('Fabric port: ',)
     print('%5d' % details['fabric_port'])
     print('Fabric interface is currently: %s' %
           'Enabled' if details['fabric_en'] else 'Disabled')
     print('XAUI Status: ', details['xaui_status'])
     for ctr in range(0, 4):
         print('\tlane sync %i:  %i' % (ctr, details['xaui_lane_sync'][ctr]))
     print('\tChannel bond: %i' % details['xaui_chan_bond'])
     print('XAUI PHY config: ')
     print('\tRX_eq_mix: %2X' % details['xaui_phy']['rx_eq_mix'])
     print('\tRX_eq_pol: %2X' % details['xaui_phy']['rx_eq_pol'])
     print('\tTX_pre-emph: %2X' % details['xaui_phy']['tx_preemph'])
     print('\tTX_diff_ctrl: %2X' % details['xaui_phy']['tx_swing'])
     print('Multicast:')
     for k in details['multicast']:
         print('\t%s: %s' % (k, details['multicast'][k]))
     if arp:
         self.print_arp_details(refresh=refresh, only_hits=True)
     if cpu:
         self.print_cpu_details(refresh=refresh)
示例#2
0
 def print_gbe_core_details(self, arp=False, cpu=False, refresh=True):
     """
     Prints 40GbE core details.
     """
     details = self.get_gbe_core_details()
     print('------------------------')
     print('%s configuration:' % self.name)
     print('MAC: ', Mac.mac2str(int(details['mac'])))
     print('Gateway: ', details['gateway_ip'].__str__())
     print('IP: ', details['ip'].__str__())
     print('Fabric port: %5d' % details['fabric_port'])
     print('Fabric interface is currently: %s' %
           'Enabled' if details['fabric_en'] else 'Disabled')
     # print('XAUI Status: ', details['xaui_status'])
     # for ctr in range(0, 4):
     #     print('\tlane sync %i:  %i' % (ctr, details['xaui_lane_sync'][ctr]))
     # print('\tChannel bond: %i' % details['xaui_chan_bond'])
     # print('XAUI PHY config: ')
     # print('\tRX_eq_mix: %2X' % details['xaui_phy']['rx_eq_mix'])
     # print('\tRX_eq_pol: %2X' % details['xaui_phy']['rx_eq_pol'])
     # print('\tTX_pre-emph: %2X' % details['xaui_phy']['tx_preemph'])
     # print('\tTX_diff_ctrl: %2X' % details['xaui_phy']['tx_swing'])
     print('Multicast:')
     for k in details['multicast']:
         print('\t%s: %s' % (k, details['multicast'][k].__str__()))
示例#3
0
 def print_gbe_core_details(self, arp=False, cpu=False, refresh=True):
     """
     Prints 40GbE core details.
     """
     details = self.get_gbe_core_details()
     print('------------------------')
     print('%s configuration:' % self.name)
     print('MAC: ', Mac.mac2str(int(details['mac'])))
     print('Gateway: ', details['gateway_ip'].__str__())
     print('IP: ', details['ip'].__str__())
     print('Fabric port: %5d' % details['fabric_port'])
     print('Fabric interface is currently: %s' %
           'Enabled' if details['fabric_en'] else 'Disabled')
     # print('XAUI Status: ', details['xaui_status'])
     # for ctr in range(0, 4):
     #     print('\tlane sync %i:  %i' % (ctr, details['xaui_lane_sync'][ctr]))
     # print('\tChannel bond: %i' % details['xaui_chan_bond'])
     # print('XAUI PHY config: ')
     # print('\tRX_eq_mix: %2X' % details['xaui_phy']['rx_eq_mix'])
     # print('\tRX_eq_pol: %2X' % details['xaui_phy']['rx_eq_pol'])
     # print('\tTX_pre-emph: %2X' % details['xaui_phy']['tx_preemph'])
     # print('\tTX_diff_ctrl: %2X' % details['xaui_phy']['tx_swing'])
     print('Multicast:')
     for k in details['multicast']:
         print('\t%s: %s' % (k, details['multicast'][k].__str__()))
示例#4
0
 def print_gbe_core_details(self, arp=False, cpu=False, refresh=True):
     """
     Prints 10GbE core details.
     :param arp: boolean, include the ARP table
     :param cpu: boolean, include the CPU packet buffers
     :param refresh: read the 10gbe details first
     """
     if refresh or (self.core_details is None):
         self.get_gbe_core_details(arp, cpu)
     details = self.core_details
     print('------------------------')
     print('%s configuration:' % self.fullname)
     print('MAC: ', Mac.mac2str(int(details['mac'])))
     print('Gateway: ', details['gateway_ip'])
     print('IP: ', details['ip'])
     print('Fabric port: ',)
     print('%5d' % details['fabric_port'])
     print('Fabric interface is currently: %s' %
           'Enabled' if details['fabric_en'] else 'Disabled')
     print('XAUI Status: ', details['xaui_status'])
     for ctr in range(0, 4):
         print('\tlane sync %i:  %i' % (ctr, details['xaui_lane_sync'][ctr]))
     print('\tChannel bond: %i' % details['xaui_chan_bond'])
     print('XAUI PHY config: ')
     print('\tRX_eq_mix: %2X' % details['xaui_phy']['rx_eq_mix'])
     print('\tRX_eq_pol: %2X' % details['xaui_phy']['rx_eq_pol'])
     print('\tTX_pre-emph: %2X' % details['xaui_phy']['tx_preemph'])
     print('\tTX_diff_ctrl: %2X' % details['xaui_phy']['tx_swing'])
     print('Multicast:')
     for k in details['multicast']:
         print('\t%s: %s' % (k, details['multicast'][k]))
     if arp:
         self.print_arp_details(refresh=refresh, only_hits=True)
     if cpu:
         self.print_cpu_details(refresh=refresh)
示例#5
0
    def get_gbe_core_details(self, read_arp=False, read_cpu=False):
        """
        Get the details of the ethernet core from the device memory map. 
        Updates local variables as well.
        """
        gbebase = self.address
        gbedata = []
        for ctr in range(0, 0x40, 4):
            gbedata.append(self._wbone_rd(gbebase + 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


        returnval = {
            'ip': IpAddress('{}.{}.{}.{}'.format(
                *pd[self.reg_map['ip']:])),
            'subnet_mask': IpAddress('{}.{}.{}.{}'.format(
                *pd[self.reg_map['subnet_mask']:])),
            'mac': Mac('{}:{}:{}:{}:{}:{}'.format(
                *pd[self.reg_map['mac']:])),
            'gateway_ip': IpAddress('{}.{}.{}.{}'.format(
                *pd[self.reg_map['gateway_ip']:])),
            # idx 0 and 1 are the mask so access idx 2 and 3
            'fabric_port': ((pd[self.reg_map['fabric_port']+2] << 8)
                            + pd[self.reg_map['fabric_port']+3]),
            # idx 3 is the enable bit
            'fabric_en': bool(pd[self.reg_map['fabric_en']+3] & 1),
            'multicast': {
                'base_ip': IpAddress('{}.{}.{}.{}'.format(
                    *pd[self.reg_map['multicast_ip']:])),
                'ip_mask': IpAddress('{}.{}.{}.{}'.format(
                    *pd[self.reg_map['multicast_mask']:]))}
        }

        possible_addresses = [int(returnval['multicast']['base_ip'])]
        mask_int = int(returnval['multicast']['ip_mask'])
        for ctr in range(32):
            mask_bit = (mask_int >> ctr) & 1
            if not mask_bit:
                new_ips = []
                for ip in possible_addresses:
                    new_ips.append(ip & (~(1 << ctr)))
                    new_ips.append(new_ips[-1] | (1 << ctr))
                possible_addresses.extend(new_ips)
        returnval['multicast']['rx_ips'] = []
        tmp = list(set(possible_addresses))
        for ip in tmp:
            returnval['multicast']['rx_ips'].append(IpAddress(ip))
        if read_arp:
            returnval['arp'] = self.get_arp_details()
        if read_cpu:
            # returnval.update(self.get_cpu_details(gbedata))
            self.logger.warn('Retrieving CPU packet buffers not yet implemented.')
        return returnval
示例#6
0
    def setup(self, mac, ipaddress, port):
        """
        Set up the MAC, IP and port for this interface

        :param mac: String or Integer input
        :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)
示例#7
0
 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:]))
示例#8
0
    def setup(self, mac, ipaddress, port, gateway=None, subnet_mask=None):
        """
        Set up the MAC, IP and port for this interface

        :param mac: String or Integer input, MAC address (e.g. '02:00:00:00:00:01')
        :param ipaddress: String or Integer input, IP address (eg '10.0.0.1')
        :param port: String or Integer input
        :param gateway: String or Integer input, an IP address
        :param subnet_mask: string or integer, subnet mask (e.g. '255.255.255.0')
        """
        self.mac = Mac(mac)
        self.ip_address = IpAddress(ipaddress)
        self.port = port if isinstance(port, int) else int(port)
        self.gateway = None if gateway is None else IpAddress(gateway)
        self.subnet_mask = None if subnet_mask is None else IpAddress(
            subnet_mask)
示例#9
0
    def get_gbe_core_details(self, read_arp=False, read_cpu=False):
        """
        Get 10GbE core details.
        assemble struct for header stuff...

        .. code-block:: python

            \"\"\"
            0x00 - 0x07: MAC address
            0x08 - 0x0b: Not used
            0x0c - 0x0f: Gateway addr
            0x10 - 0x13: IP addr
            0x14 - 0x17: Not assigned
            0x18 - 0x1b: Buffer sizes
            0x1c - 0x1f: Not assigned
            0x20    :    Soft reset (bit 0)
            0x21    :    Fabric enable (bit 0)
            0x22 - 0x23: Fabric port
            0x24 - 0x27: XAUI status (bit 2,3,4,5 = lane sync, bit6 = chan_bond)
            0x28 - 0x2b: PHY config
            0x28    :    RX_eq_mix
            0x29    :    RX_eq_pol
            0x2a    :    TX_preemph
            0x2b    :    TX_diff_ctrl
            0x30 - 0x33: Multicast IP RX base address
            0x34 - 0x37: Multicast IP mask
            0x38 - 0x3b: Subnet mask
            0x1000  :    CPU TX buffer
            0x2000  :    CPU RX buffer
            0x3000  :    ARP tables start
            word_width = 8
            \"\"\"
            self.add_field(Bitfield.Field('mac0', 0,            word_width,                 0, 0 * word_width))
            self.add_field(Bitfield.Field('mac1', 0,            word_width,                 0, 1 * word_width))
            self.add_field(Bitfield.Field('mac2', 0,            word_width,                 0, 2 * word_width))
            self.add_field(Bitfield.Field('mac3', 0,            word_width,                 0, 3 * word_width))
            self.add_field(Bitfield.Field('mac4', 0,            word_width,                 0, 4 * word_width))
            self.add_field(Bitfield.Field('mac5', 0,            word_width,                 0, 5 * word_width))
            self.add_field(Bitfield.Field('mac6', 0,            word_width,                 0, 6 * word_width))
            self.add_field(Bitfield.Field('mac7', 0,            word_width,                 0, 7 * word_width))
            self.add_field(Bitfield.Field('unused_1', 0,        (0x0c - 0x08) * word_width, 0, 8 * word_width))
            self.add_field(Bitfield.Field('gateway_ip0', 0,     word_width,                 0, 0x0c * word_width))
            self.add_field(Bitfield.Field('gateway_ip1', 0,     word_width,                 0, 0x0d * word_width))
            self.add_field(Bitfield.Field('gateway_ip2', 0,     word_width,                 0, 0x0e * word_width))
            self.add_field(Bitfield.Field('gateway_ip3', 0,     word_width,                 0, 0x0f * word_width))
            self.add_field(Bitfield.Field('ip0', 0,             word_width,                 0, 0x10 * word_width))
            self.add_field(Bitfield.Field('ip1', 0,             word_width,                 0, 0x11 * word_width))
            self.add_field(Bitfield.Field('ip2', 0,             word_width,                 0, 0x12 * word_width))
            self.add_field(Bitfield.Field('ip3', 0,             word_width,                 0, 0x13 * word_width))
            self.add_field(Bitfield.Field('unused_2', 0,        (0x18 - 0x14) * word_width, 0, 0x14 * word_width))
            self.add_field(Bitfield.Field('buf_sizes', 0,       (0x1c - 0x18) * word_width, 0, 0x18 * word_width))
            self.add_field(Bitfield.Field('unused_3', 0,        (0x20 - 0x1c) * word_width, 0, 0x1c * word_width))
            self.add_field(Bitfield.Field('soft_reset', 2,      1,                          0, 0x20 * word_width))
            self.add_field(Bitfield.Field('fabric_enable', 2,   1,                          0, 0x21 * word_width))
            self.add_field(Bitfield.Field('port', 0,            (0x24 - 0x22) * word_width, 0, 0x22 * word_width))
            self.add_field(Bitfield.Field('xaui_status', 0,     (0x28 - 0x24) * word_width, 0, 0x24 * word_width))
            self.add_field(Bitfield.Field('rx_eq_mix', 0,       word_width,                 0, 0x28 * word_width))
            self.add_field(Bitfield.Field('rq_eq_pol', 0,       word_width,                 0, 0x29 * word_width))
            self.add_field(Bitfield.Field('tx_preempth', 0,     word_width,                 0, 0x2a * word_width))
            self.add_field(Bitfield.Field('tx_diff_ctrl', 0,    word_width,                 0, 0x2b * word_width))
            #self.add_field(Bitfield.Field('buffer_tx', 0,       0x1000 * word_width,        0, 0x1000 * word_width))
            #self.add_field(Bitfield.Field('buffer_rx', 0,       0x1000 * word_width,        0, 0x2000 * word_width))
            #self.add_field(Bitfield.Field('arp_table', 0,       0x1000 * word_width,        0, 0x3000 * word_width))
        """
        if self.memmap_compliant:
            data = self.parent.read(self.name, 16384)
            data = list(struct.unpack('>16384B', data))
            returnval = {
                'ip_prefix':
                '%i.%i.%i.' % (data[0x14], data[0x15], data[0x16]),
                'ip':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x14], data[0x15], data[0x16], data[0x17])),
                'subnet_mask':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x1c], data[0x1d], data[0x1e], data[0x1f])),
                'mac':
                Mac('%i:%i:%i:%i:%i:%i' %
                    (data[0x0e], data[0x0f], data[0x10], data[0x11],
                     data[0x12], data[0x13])),
                'gateway_ip':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x18], data[0x19], data[0x1a], data[0x1b])),
                'fabric_port': ((data[0x32] << 8) + (data[0x33])),
                'fabric_en':
                bool(data[0x2f] & 1),
                'multicast': {
                    'base_ip':
                    IpAddress(
                        '%i.%i.%i.%i' %
                        (data[0x20], data[0x21], data[0x22], data[0x23])),
                    'ip_mask':
                    IpAddress(
                        '%i.%i.%i.%i' %
                        (data[0x24], data[0x25], data[0x26], data[0x27])),
                    'rx_ips': []
                }
            }
        else:
            data = self.parent.read(self.name, 16384)
            data = list(struct.unpack('>16384B', data))
            returnval = {
                'ip_prefix':
                '%i.%i.%i.' % (data[0x10], data[0x11], data[0x12]),
                'ip':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x10], data[0x11], data[0x12], data[0x13])),
                'subnet_mask':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x38], data[0x39], data[0x3a], data[0x3b])),
                'mac':
                Mac('%i:%i:%i:%i:%i:%i' %
                    (data[0x02], data[0x03], data[0x04], data[0x05],
                     data[0x06], data[0x07])),
                'gateway_ip':
                IpAddress('%i.%i.%i.%i' %
                          (data[0x0c], data[0x0d], data[0x0e], data[0x0f])),
                'fabric_port': ((data[0x22] << 8) + (data[0x23])),
                'fabric_en':
                bool(data[0x21] & 1),
                'xaui_lane_sync': [
                    bool(data[0x27] & 4),
                    bool(data[0x27] & 8),
                    bool(data[0x27] & 16),
                    bool(data[0x27] & 32)
                ],
                'xaui_status':
                [data[0x24], data[0x25], data[0x26], data[0x27]],
                'xaui_chan_bond':
                bool(data[0x27] & 64),
                'xaui_phy': {
                    'rx_eq_mix': data[0x28],
                    'rx_eq_pol': data[0x29],
                    'tx_preemph': data[0x2a],
                    'tx_swing': data[0x2b]
                },
                'multicast': {
                    'base_ip':
                    IpAddress(
                        '%i.%i.%i.%i' %
                        (data[0x30], data[0x31], data[0x32], data[0x33])),
                    'ip_mask':
                    IpAddress(
                        '%i.%i.%i.%i' %
                        (data[0x34], data[0x35], data[0x36], data[0x37])),
                    'rx_ips': []
                }
            }
        possible_addresses = [int(returnval['multicast']['base_ip'])]
        mask_int = int(returnval['multicast']['ip_mask'])
        for ctr in range(32):
            mask_bit = (mask_int >> ctr) & 1
            if not mask_bit:
                new_ips = []
                for ip in possible_addresses:
                    new_ips.append(ip & (~(1 << ctr)))
                    new_ips.append(new_ips[-1] | (1 << ctr))
                possible_addresses.extend(new_ips)
        tmp = list(set(possible_addresses))
        for ip in tmp:
            returnval['multicast']['rx_ips'].append(IpAddress(ip))
        if read_arp:
            returnval['arp'] = self.get_arp_details(data)
        if read_cpu:
            returnval.update(self.get_cpu_details(data))
        self.core_details = returnval
        return returnval
示例#10
0
 def get_core_details(self,read_arp=False, read_cpu=False):
     """
     Get the details of the ethernet core from the device memory map. 
     Updates local variables as well.
     :return: 
     """
     from tengbe import IpAddress, Mac
     gbebase = self.address
     gbedata = []
     for ctr in range(0, 0x40, 4):
         gbedata.append(self._wbone_rd(gbebase + 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
     returnval = {
         'ip_prefix': '%i.%i.%i.' % (pd[0x10], pd[0x11], pd[0x12]),
         'ip': IpAddress('%i.%i.%i.%i' % (pd[0x10], pd[0x11],
                                          pd[0x12], pd[0x13])),
         'mac': Mac('%i:%i:%i:%i:%i:%i' % (pd[0x02], pd[0x03], pd[0x04],
                                           pd[0x05], pd[0x06], pd[0x07])),
         'gateway_ip': IpAddress('%i.%i.%i.%i' % (pd[0x0c], pd[0x0d],
                                                  pd[0x0e], pd[0x0f])),
         'fabric_port': ((pd[0x22] << 8) + (pd[0x23])),
         'fabric_en': bool(pd[0x21] & 1),
         'xaui_lane_sync': [
             bool(pd[0x27] & 4), bool(pd[0x27] & 8),
             bool(pd[0x27] & 16), bool(pd[0x27] & 32)],
         'xaui_status': [
             pd[0x24], pd[0x25], pd[0x26], pd[0x27]],
         'xaui_chan_bond': bool(pd[0x27] & 64),
         'xaui_phy': {
             'rx_eq_mix': pd[0x28],
             'rx_eq_pol': pd[0x29],
             'tx_preemph': pd[0x2a],
             'tx_swing': pd[0x2b]},
         'multicast': {
             'base_ip': IpAddress('%i.%i.%i.%i' % (pd[0x30], pd[0x31],
                                                   pd[0x32], pd[0x33])),
             'ip_mask': IpAddress('%i.%i.%i.%i' % (pd[0x34], pd[0x35],
                                                   pd[0x36], pd[0x37])),
             'subnet_mask': IpAddress('%i.%i.%i.%i' % (pd[0x38], pd[0x39],
                                                       pd[0x3a], pd[0x3b]))}
     }
     possible_addresses = [int(returnval['multicast']['base_ip'])]
     mask_int = int(returnval['multicast']['ip_mask'])
     for ctr in range(32):
         mask_bit = (mask_int >> ctr) & 1
         if not mask_bit:
             new_ips = []
             for ip in possible_addresses:
                 new_ips.append(ip & (~(1 << ctr)))
                 new_ips.append(new_ips[-1] | (1 << ctr))
             possible_addresses.extend(new_ips)
     returnval['multicast']['rx_ips'] = []
     tmp = list(set(possible_addresses))
     for ip in tmp:
         returnval['multicast']['rx_ips'].append(IpAddress(ip))
     if read_arp:
         returnval['arp'] = self.get_arp_details(data)
         #LOGGER.warn("Retrieving ARP details not yet implemented.") 
     if read_cpu:
         returnval.update(self.get_cpu_details(data))
         LOGGER.warn("Retrieving CPU packet buffers not yet implemented.") 
     return returnval
示例#11
0
    def get_gbe_core_details(self, read_arp=False, read_cpu=False):
        """
        Get the details of the ethernet core from the device memory map. 
        Updates local variables as well.
        """
        gbebase = self.address
        gbedata = []
        for ctr in range(0, 0x40, 4):
            gbedata.append(self._wbone_rd(gbebase + 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
        
        if self.legacy_reg_map:
            returnval = {
                # no longer meaningful, since subnet can be less than 256?
                # 'ip_prefix': '%i.%i.%i.' % (pd[0x10], pd[0x11], pd[0x12]),
                'ip': IpAddress('%i.%i.%i.%i' % (
                    pd[0x10], pd[0x11], pd[0x12], pd[0x13])),
                'subnet_mask': IpAddress('%i.%i.%i.%i' % (
                        pd[0x38], pd[0x39], pd[0x3a], pd[0x3b])),
                'mac': Mac('%i:%i:%i:%i:%i:%i' % (
                    pd[0x02], pd[0x03], pd[0x04], pd[0x05], pd[0x06], pd[0x07])),
                'gateway_ip': IpAddress('%i.%i.%i.%i' % (
                    pd[0x0c], pd[0x0d], pd[0x0e], pd[0x0f])),
                'fabric_port': ((pd[0x22] << 8) + (pd[0x23])),
                'fabric_en': bool(pd[0x21] & 1),
                'xaui_lane_sync': [
                    bool(pd[0x27] & 4), bool(pd[0x27] & 8),
                    bool(pd[0x27] & 16), bool(pd[0x27] & 32)],
                'xaui_status': [
                    pd[0x24], pd[0x25], pd[0x26], pd[0x27]],
                'xaui_chan_bond': bool(pd[0x27] & 64),
                'xaui_phy': {
                    'rx_eq_mix': pd[0x28],
                    'rx_eq_pol': pd[0x29],
                    'tx_preemph': pd[0x2a],
                    'tx_swing': pd[0x2b]},
                'multicast': {
                    'base_ip': IpAddress('%i.%i.%i.%i' % (
                        pd[0x30], pd[0x31], pd[0x32], pd[0x33])),
                    'ip_mask': IpAddress('%i.%i.%i.%i' % (
                        pd[0x34], pd[0x35], pd[0x36], pd[0x37]))}
            }

        else:
            returnval = {
                # no longer meaningful, since subnet can be less than 256?
                # 'ip_prefix': '%i.%i.%i.' % (pd[0x10], pd[0x11], pd[0x12]),
                'ip': IpAddress('%i.%i.%i.%i' % (
                    pd[0x14], pd[0x15], pd[0x16], pd[0x17])),
                'subnet_mask': IpAddress('%i.%i.%i.%i' % (
                        pd[0x24], pd[0x25], pd[0x26], pd[0x27])),
                'mac': Mac('%i:%i:%i:%i:%i:%i' % (
                    pd[0x0E], pd[0x0F], pd[0x10], pd[0x11], pd[0x12], pd[0x13])),
                'gateway_ip': IpAddress('%i.%i.%i.%i' % (
                    pd[0x18], pd[0x19], pd[0x20], pd[0x21])),
                'fabric_port': ((pd[0x2E] << 8) + (pd[0x2F])),
                'fabric_en': bool(pd[0x29] & 1),
                # 'xaui_lane_sync': [
                #     bool(pd[0x27] & 4), bool(pd[0x27] & 8),
                #     bool(pd[0x27] & 16), bool(pd[0x27] & 32)],
                # 'xaui_status': [
                #     pd[0x24], pd[0x25], pd[0x26], pd[0x27]],
                # 'xaui_chan_bond': bool(pd[0x27] & 64),
                # 'xaui_phy': {
                #     'rx_eq_mix': pd[0x28],
                #     'rx_eq_pol': pd[0x29],
                #     'tx_preemph': pd[0x2a],
                #     'tx_swing': pd[0x2b]},
                'multicast': {
                    'base_ip': IpAddress('%i.%i.%i.%i' % (
                        pd[0x20], pd[0x21], pd[0x22], pd[0x23])),
                    'ip_mask': IpAddress('%i.%i.%i.%i' % (
                        pd[0x24], pd[0x25], pd[0x26], pd[0x27]))}
            }
        possible_addresses = [int(returnval['multicast']['base_ip'])]
        mask_int = int(returnval['multicast']['ip_mask'])
        for ctr in range(32):
            mask_bit = (mask_int >> ctr) & 1
            if not mask_bit:
                new_ips = []
                for ip in possible_addresses:
                    new_ips.append(ip & (~(1 << ctr)))
                    new_ips.append(new_ips[-1] | (1 << ctr))
                possible_addresses.extend(new_ips)
        returnval['multicast']['rx_ips'] = []
        tmp = list(set(possible_addresses))
        for ip in tmp:
            returnval['multicast']['rx_ips'].append(IpAddress(ip))
        if read_arp:
            returnval['arp'] = self.get_arp_details()
        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
示例#12
0
    def get_gbe_core_details(self,
                             read_arp=False,
                             read_cpu=False,
                             read_multicast=False):
        """
        Get 10GbE core details.

        :param read_arp (bool): Get ARP table details (default False)
        :param read_cpu (bool): Get CPU details (default False)
        :param read_multicast (bool): Get multicast address table (default False)

        :returns: dictionary of core details (IP address, subnet mask, MAC address, port, etc).
        """
        IP_ADDR = self._memmap_read('IP_ADDR')
        IP_PREFIX = '.'.join(IpAddress(IP_ADDR).ip_str.split('.')[:3])

        returnval = {
            'ip_prefix': IP_PREFIX,
            'ip': IpAddress(IP_ADDR),
            'subnet_mask': IpAddress(self._memmap_read('NETMASK')),
            'mac': Mac(self._memmap_read('MAC_ADDR')),
            'gateway_ip': IpAddress(self._memmap_read('GW_ADDR')),
            'fabric_port': self._memmap_read('PORT'),
            'fabric_en': self._memmap_read('ENABLE'),
            'multicast': {
                'base_ip': IpAddress(self._memmap_read('MC_IP')),
                'ip_mask': IpAddress(self._memmap_read('MC_MASK')),
                'rx_ips': []
            }
        }

        if not self.memmap_compliant:
            data = self.parent.read(self.name, 16384)
            data = list(struct.unpack('>16384B', data))

            returnval_legacy_dict = {
                'xaui_lane_sync': [
                    bool(data[0x27] & 4),
                    bool(data[0x27] & 8),
                    bool(data[0x27] & 16),
                    bool(data[0x27] & 32)
                ],
                'xaui_status':
                [data[0x24], data[0x25], data[0x26], data[0x27]],
                'xaui_chan_bond':
                bool(data[0x27] & 64),
                'xaui_phy': {
                    'rx_eq_mix': data[0x28],
                    'rx_eq_pol': data[0x29],
                    'tx_preemph': data[0x2a],
                    'tx_swing': data[0x2b]
                },
            }
            returnval.update(returnval_legacy_dict)

        if read_multicast:
            possible_addresses = [int(returnval['multicast']['base_ip'])]
            mask_int = int(returnval['multicast']['ip_mask'])
            for ctr in range(32):
                mask_bit = (mask_int >> ctr) & 1
                if not mask_bit:
                    new_ips = []
                    for ip in possible_addresses:
                        new_ips.append(ip & (~(1 << ctr)))
                        new_ips.append(new_ips[-1] | (1 << ctr))
                    possible_addresses.extend(new_ips)
            tmp = list(set(possible_addresses))
            for ip in tmp:
                returnval['multicast']['rx_ips'].append(IpAddress(ip))

        if read_arp:
            returnval['arp'] = self.get_arp_details()
        if read_cpu:
            returnval.update(self.get_cpu_details())

        self.core_details = returnval
        return returnval