Changeset 1279


Ignore:
Timestamp:
01/11/07 17:46:11 (6 years ago)
Author:
mglb1
Message:

Implement a routine that regularly checks that iwspy has been given MAC addresses for all links that are using Orinoco cards.

If iwspy does not have a MAC address for the other end of a link which is using Orinoco cards then we cannot gather SNR statistics.

Fixes #18

Location:
ccsd
Files:
2 edited

Legend:

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

    r1262 r1279  
    2020from crcnetd._utils.ccsd_common import * 
    2121from crcnetd._utils.ccsd_log import * 
    22 from crcnetd._utils.ccsd_clientserver import registerPage, registerDir 
     22from crcnetd._utils.ccsd_clientserver import registerPage, registerDir, \ 
     23        registerRecurring 
    2324from crcnetd._utils.ccsd_config import config_get 
    2425from crcnetd._utils.ccsd_events import registerEvent, triggerEvent 
     
    3435DEFAULT_AVERAGE_SIGNAL = 14 
    3536DEFAULT_GOOD_SIGNAL = 20 
     37 
     38IWSPY_CHECK_INTERVAL = 300 
    3639 
    3740class ccs_status_error(ccsd_error): 
     
    170173     
    171174    return interfaces2 
    172          
     175     
     176@registerRecurring(IWSPY_CHECK_INTERVAL) 
     177def checkiwspy(): 
     178    """Called regularly to check that iwspy is correctly configured 
     179 
     180    If an Orinoco interface (heuristically determined as any wireless interface 
     181    that is not madwifi or hostap) does not have a MAC address added to iwspy, 
     182    the arp table is looked up and the MAC of the host at the opposite end of 
     183    the subnet is added.  
     184 
     185    If a MAC address is present it is checked against the ARP table and 
     186    corrected if it is out of date. 
     187 
     188    This procedure is required for SNR statistics to be collected for Orinoco 
     189    card links. 
     190    """ 
     191 
     192    for iface in iwtools.interfaces: 
     193        # Skip madwifi and hostap interfaces 
     194        if iwtools.is_madwifi(iface) or iwtools.is_hostap(iface): continue 
     195        # Skip interfaces that are down 
     196        state = getInterfaces(returnOne=iface) 
     197        if len(state) != 1 or not state[0]["up"]: continue 
     198        # Determine whether to start from the top of the bottom of the net 
     199        cidr = state[0]["address"] 
     200        ip = ipnum(cidrToIP(cidr)) 
     201        bcast = cidrToBroadcast(cidr) 
     202        network = cidrToNetwork(cidr) 
     203        ldiff = ip - network 
     204        udiff = bcast - ip 
     205        if ldiff > udiff: 
     206            # ip is closest to top, start at bottom 
     207            start = network+1 
     208            inc = 1 
     209            end = bcast 
     210        else: 
     211            # ip is closet to the bottom, start at the top 
     212            start = bcast-1 
     213            inc = -1 
     214            end = network 
     215        # Short broadcast ping to populate ARP table 
     216        log_command("/usr/sbin/fping -c2 -q %s &>/dev/null" % formatIP(bcast)) 
     217        # Get all MACs on the link 
     218        macs = getLinkMACs(iface) 
     219        if len(macs) == 0: continue 
     220        # Walk from the opposite end of the network and use the first entry 
     221        use = None 
     222        while start != end: 
     223            if start == ip:  
     224                start += inc 
     225                continue # skip self 
     226            if formatIP(start) in macs.keys(): 
     227                use = macs[formatIP(start)] 
     228                break 
     229            start += inc 
     230        # Next interface if no usable macs found 
     231        if use is None: continue 
     232        # Otherwise update iwspy 
     233        current = getiwspyMAC(iface) 
     234        if use == current: continue 
     235        log_command("/sbin/iwspy %s off 2>&1" % iface) 
     236        log_command("/sbin/iwspy %s + %s" % (iface, use)) 
     237        log_info("Updated iwspy for interface '%s' to '%s'" % (iface, use)) 
     238 
    173239############################################################################## 
    174240# Node Map 
     
    620686    localnode = socket.gethostname() 
    621687    nodemap =  config_get("status", "nodemap", DEFAULT_NODEMAP_FILE) 
     688 
     689    # Check that iwspy has MAC addresses 
     690    checkiwspy() 
    622691         
    623692    if (gateway == None or root == None or localnode == None): 
  • ccsd/trunk/crcnetd/_utils/ccsd_common.py

    r1270 r1279  
    10041004    return routes 
    10051005 
     1006def getLinkMACs(iface): 
     1007    """Returns a dictionary of ip:mac for all ARP entries on the link""" 
     1008 
     1009    macs = {} 
     1010 
     1011    fh = os.popen("/sbin/ip neigh show dev %s" % iface) 
     1012    output = fh.readlines() 
     1013    rv = fh.close() 
     1014    for line in output: 
     1015        parts = line.strip().split(" ") 
     1016        if parts[-1] != "reachable": 
     1017            continue 
     1018        macs[parts[0]] = parts[2].lower() 
     1019 
     1020    return macs 
     1021 
     1022def getiwspyMAC(iface): 
     1023     
     1024    fh = os.popen("/sbin/iwspy %s" % iface) 
     1025    output = fh.readlines() 
     1026    rv = fh.close() 
     1027    if len(output) < 2: return "" 
     1028    parts = output[1].strip().split(" : ") 
     1029    mac = parts[0] 
     1030    if isValidMAC(mac): 
     1031        return mac.lower() 
     1032    return "" 
     1033 
    10061034def route_cmp(a, b): 
    10071035    """Comparison function to sort the route table by netmask then prefix""" 
Note: See TracChangeset for help on using the changeset viewer.