Changeset 1372


Ignore:
Timestamp:
02/20/07 11:59:05 (6 years ago)
Author:
mglb1
Message:

Fix the getAthStats function

  • Can't rely on the base interface being called 'wifiXXX'
  • Remove extraneous indentation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccsd/private/modules/ccs_monitor_status.py

    r1371 r1372  
    144144        return -1 
    145145 
     146def getMadwifiBase(mac, interfaces): 
     147    """Searches the provided list of interfaces for base madwifi interface  
     148       matching the supplied MAC address""" 
     149 
     150    for iface in interfaces: 
     151        # If the last 5 octets of the mac don't match, ignore 
     152        if mac[3:] != iface["mac"][3:]: 
     153            continue 
     154        # If the iface is of type link/ieee802.11 rathern than link/ether 
     155        # then it is the base interface 
     156        fd = os.popen("/sbin/ip link ls dev %s" % iface["name"]) 
     157        lines = fd.readlines() 
     158        fd.close() 
     159        if lines[-1].find("link/ieee802.11") != -1: 
     160            return  iface["name"] 
     161    return None 
     162 
    146163def getAthStats(oiface, interfaces): 
    147164    """Gets stats from Athstats""" 
    148     phy = 0 
    149     crc = 0 
     165    phy = -1 
     166    crc = -1 
    150167    base = None 
    151168    try: 
    152         mac = oiface["mac"][3:] 
    153         #Find the base wifi* interface 
    154         for iface in interfaces: 
    155             if iface == oiface: 
     169        mac = oiface["mac"] 
     170        # Find the base interface 
     171        base = getMadwifiBase(mac, interfaces) 
     172        if not base: return phy, crc 
     173        # Run athstats and retrieve output 
     174        lines = os.popen("athstats -i %s" % base).readlines() 
     175        if len(lines) == 0: return phy, crc 
     176        # Parse athstats output 
     177        for line in lines: 
     178            # Look for key text 
     179            if line.find("PHY errors") != -1: 
     180                # Store PHY errors 
     181                phy = int(line.strip().split()[0]) 
     182            elif line.find("rx failed due to bad CRC") != -1: 
     183                # Store CRC errors 
     184                crc = int(line.strip().split()[0]) 
     185            else: 
     186                # Ignored line 
    156187                continue 
    157             if mac == iface["mac"][3:] and iface["name"][:4] == "wifi": 
    158                 base = iface["name"] 
     188            # Ignore the rest if we've found both values 
     189            if phy != -1 and crc != -1: 
    159190                break 
    160  
    161         #Run athstats 
    162         if base: 
    163             lines = os.popen("athstats -i %s" % base).readlines() 
    164             if len(lines) == 0: 
    165                 phy = -1 
    166                 crc = -1 
    167             for line in lines: 
    168                 line = line.strip('\n') 
    169                 sline = line.split(' ') 
    170                 if len(sline) > 1: 
    171                     value = sline[0] 
    172                     line = line[len(value)+1:] 
    173                     if line == "PHY errors": 
    174                         phy = int(value) 
    175                     if line == "rx failed due to bad CRC": 
    176                         crc = int(value) 
    177         else: 
    178             phy = -1 
    179             crc = -1 
    180191    except: 
    181         phu = -1 
     192        log_error("Failed to fetch ath stats for %s" % oiface["name"],  
     193                sys.exc_info()) 
     194        phy = -1 
    182195        crc = -1 
    183196    return phy, crc 
    184  
    185197 
    186198Cache = None 
Note: See TracChangeset for help on using the changeset viewer.