import re from common import * firstre = re.compile("^([a-z]+[0-9]): .*") inetre = re.compile("^\tinet ([^ ]+) netmask ([^ ]+) .*") ssidre = re.compile("^\tssid ([^ ]+).*") channelre = re.compile("^\tchannel ([0-9]+).*") root = xml_to_obj_hierarchy("nodes.xml") ready_nodes_dtd_hierarchy(root) def parsemask(s): count = 0 i = int(s, 16) while i > 0: count = count + (i & 1) i = i >> 1 return count def parse_ifconfig(s): wis = {} wi = None addrs = [] ssid = None channel = None for l in s.split("\n"): match = firstre.match(l) if match != None: if wi != None: wis[wi] = ( addrs, ssid, channel ) wi = match.group(1) addrs = [] ssid = None channel = None match = inetre.match(l) if match != None: inet = parseaddr(match.group(1)) mask = parsemask(match.group(2)) addrs.append( (inet, mask) ) match = ssidre.match(l) if match != None: ssid = match.group(1) match = channelre.match(l) if match != None: channel = match.group(1) if wi != None: wis[wi] = ( addrs, ssid, channel ) return wis def validate(node, wis): foundlinks = {} for wi in wis.keys(): (addrs, ssid, channel) = wis[wi] for (addr, mask) in addrs: for l in node.links: if l.iface.iface == wi and l.ip == addr and int(l.mask) == mask: foundlinks[l] = 1 for l in node.links: if not foundlinks.has_key(l): print "Couldn't find link", l.iface.iface, showaddr(l.ip), l.mask def do_node(name): try: wis = parse_ifconfig(open("/home/lodewijk/nodes/CNode%s/ifconfig" % name).read()) node = findnode(root, name) print "%s:" % name validate(node, wis) except: pass for n in sys.argv[1:]: do_node(n)