Changeset 1279
- Timestamp:
- 01/11/07 17:46:11 (6 years ago)
- Location:
- ccsd
- Files:
-
- 2 edited
-
private/modules/ccs_monitor_status.py (modified) (4 diffs)
-
trunk/crcnetd/_utils/ccsd_common.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/private/modules/ccs_monitor_status.py
r1262 r1279 20 20 from crcnetd._utils.ccsd_common import * 21 21 from crcnetd._utils.ccsd_log import * 22 from crcnetd._utils.ccsd_clientserver import registerPage, registerDir 22 from crcnetd._utils.ccsd_clientserver import registerPage, registerDir, \ 23 registerRecurring 23 24 from crcnetd._utils.ccsd_config import config_get 24 25 from crcnetd._utils.ccsd_events import registerEvent, triggerEvent … … 34 35 DEFAULT_AVERAGE_SIGNAL = 14 35 36 DEFAULT_GOOD_SIGNAL = 20 37 38 IWSPY_CHECK_INTERVAL = 300 36 39 37 40 class ccs_status_error(ccsd_error): … … 170 173 171 174 return interfaces2 172 175 176 @registerRecurring(IWSPY_CHECK_INTERVAL) 177 def 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 173 239 ############################################################################## 174 240 # Node Map … … 620 686 localnode = socket.gethostname() 621 687 nodemap = config_get("status", "nodemap", DEFAULT_NODEMAP_FILE) 688 689 # Check that iwspy has MAC addresses 690 checkiwspy() 622 691 623 692 if (gateway == None or root == None or localnode == None): -
ccsd/trunk/crcnetd/_utils/ccsd_common.py
r1270 r1279 1004 1004 return routes 1005 1005 1006 def 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 1022 def 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 1006 1034 def route_cmp(a, b): 1007 1035 """Comparison function to sort the route table by netmask then prefix"""
Note: See TracChangeset
for help on using the changeset viewer.
