def connect_riots(): global potential_targnodes, riots, dont_send riots_complete.acquire() riots_ready.acquire() collect_potential_targnodes() for position, connection in riots.iteritems(): start_new_thread(test_sender_thread,(position,connection[0])) # make sure the main thread isn't killed before we initialize our sockets time.sleep(2) logging.debug("riots: %s\n", riots) print "graphviz:\n", tv.prep_graphviz(str(riots)) # write info about riots to file for easier gdb debuggingthings # I am going straight to hell for this. ip_info_file = open("./ip_port.info", "w") ip_info_file.write(json.dumps(dict({(v[0],v[1][0]) for k,v in riots.iteritems()}))) ip_info_file.close() if (shutdown_riots > 0): start_new_thread(test_shutdown_thread,()) if (plain_mode): while (not dont_send): orignode = random.choice(riots.keys()) if (len(potential_targnodes[orignode]) > 0): targnode = random.choice(potential_targnodes[orignode]) targnode_ip = riots[targnode][1][0] print "orignode:", orignode, "targnode:", targnode, "targnode_ip", targnode_ip msg_queues[orignode].put("send_data %s\n" % targnode_ip) dont_send = True # after experiment_duration, this function will exit and kill all the threads it generated. time.sleep(experiment_duration)
def count_successes(log_file_location): print "counting successful route discoveries and transmissions..." pp = pprint.PrettyPrinter(indent=2) logfile = open(log_file_location) route_discoveries = [] transmissions = [] curr_ip = "" curr_discovery = {} line_number = 0 for line in logfile: line_number += 1 # reached original topology info; convert it to graphviz-readable format and print if ("riots:" in line): print tv.prep_graphviz(line) node_log_start = re.search(".* {Dummy-.*: (.*), \(., .\)}", line) # TODO match more thoroughly if (node_log_start): curr_ip = node_log_start.groups()[0] #print line #print curr_ip elif ("[demo] sending packet" in line): # save old discovery (if not empty), record new one if (curr_discovery): route_discoveries.append(curr_discovery) curr_discovery = {} curr_discovery["orignode"] = curr_ip curr_discovery["targnode"] = re.search("{(.*)}\[demo\] sending packet of (.*) bytes towards (.*)...", line).groups()[2] curr_discovery["seqnums"] = [] curr_discovery["success"] = 0 curr_discovery["rreq_arrived"] = 0 #print curr_discovery ##this seems to be generally correct, but a bug in aodv/desvirt through which neighbors receive packets from their 2 hop neighbors confuses it (and aodv) # look for (successful) discoveries elif ("originating RREQ" in line): info = re.search("\[aodvv2\] originating RREQ with SeqNum (.*) towards (.*); updating RREQ table...", line).groups() seqnum = info[0] targnode = info[1] #print line_number, ":", line #print "1", curr_discovery if (curr_discovery and targnode != curr_discovery.get("targnode")): print "ERROR: IP conflict: ", targnode, ", ", curr_discovery.get("targnode"), "in line ", line_number sys.exit() return # double tap! curr_discovery["seqnums"].append(seqnum) # requested route is direct neighbor elif ("[ndp] found NC entry. Returning dest addr." in line): curr_discovery = {} #print line_number, ":", line #print "3", curr_discovery # delete logged attempt if no discovery has taken place because the route was already known elif ("found dest " in line): #print line_number, ":", line targnode = re.search(".*found dest (.*) in routing table", line).groups()[0] # a route towards dest already exists; the discovery has been successful before it even started. # thus, we can remove it from the discovery list, since there was nothing to discover. if (curr_discovery.get("targnode") == targnode and curr_discovery.get("seqnums") == []): #print "hbzd", curr_discovery curr_discovery = {} elif ("This is my RREP" in line): info = re.search(".* (.*): This is my RREP \(SeqNum: (.*)\). We are done here, thanks (.*)!", line).groups() #print line orignode = info[0] targnode = info[2] seqnum = info[1] discovery = [disc for disc in route_discoveries if disc["orignode"] == orignode and disc["targnode"] == targnode and seqnum in disc["seqnums"]] if (curr_discovery["orignode"] == orignode and curr_discovery["targnode"] == targnode and seqnum in curr_discovery["seqnums"]): # RREP in time! wohooo! (oder? TODO verify) discovery.append(curr_discovery) if (len(discovery) > 1): print "huch" else: print discovery discovery[0]["success"] = 1 # look for (successful) transmissions # found initiation of new transmission if ("[demo] sending packet" in line): [timestamp, targnode] = re.search("{(.*)}\[demo\] sending packet of 15 bytes towards (.*)...", line).groups() transmission = { "timestamp": timestamp, "orignode": curr_ip, "targnode": targnode, "success": 0} transmissions.append(transmission) # found packet that arrived (-> successful transmission) if ("[demo] UDP packet received" in line): orignode = re.search(".*\[demo\].*UDP packet received from (.*):.*", line).groups()[0] print line_number, ":", line #print transmissions print "orignode: ", orignode, "\ncurr_ip: ", curr_ip print [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip] suitable_transmissions = [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip and t["success"] == 0] #print suitable_transmissions # doesn't matter which one exactly we mark as successful, just pick one. suitable_transmissions[-1]["success"] = 1 print "route_discoveries \n", pp.pprint(route_discoveries) #print "transmissions\n", pp.pprint(transmissions) successful_discoveries = [d for d in route_discoveries if d["success"] == 1] in_timeout_discoveries = [d for d in route_discoveries if len(d["seqnums"]) <3 and d["success"] == 1] successful_transmissions = [t for t in transmissions if t["success"] == 1] discovery_summary = {} discovery_summary["success"] = len (successful_discoveries) discovery_summary["fail"] = len(route_discoveries) - discovery_summary["success"] transmission_summary = {} transmission_summary["success"] = len(successful_transmissions) transmission_summary["fail"] = len(transmissions) - transmission_summary["success"] return {"discoveries" : discovery_summary, "transmissions" : transmission_summary, "discoveries within timeout" : len(in_timeout_discoveries), "rrep_fail": 0} def main(): pcap_file_str = "" parser = argparse.ArgumentParser(description='evaluate traffic generated by auto_test') parser.add_argument('-p','--pcap', type=str, help='pcap file to evaluate') parser.add_argument('-l', '--log', type=str, help='aodv_test log file to evaluate') args = parser.parse_args() if (args.pcap): print "evaluating pcap..." pcap_file_str = args.pcap xml_file_location = pcap_to_xml(pcap_file_str) handle_capture(xml_file_location) if (args.log): print "evaluating log..." handle_logfile(args.log) #print pktbb_packets if __name__ == "__main__": main()
def count_successes(log_file_location): print "counting successful route discoveries and transmissions..." pp = pprint.PrettyPrinter(indent=2) logfile = open(log_file_location) route_discoveries = [] transmissions = [] curr_ip = "" curr_discovery = {"orignode": "", "targnode": ""} line_number = 0 num_success_transm = 0 for line in logfile: line_number += 1 # reached original topology info; convert it to graphviz-readable format and print if ("riots:" in line): print "xoxo" info = line.split("riots: ")[1] print info print "graphviz:\n", tv.prep_graphviz(info) node_log_start = re.search(".* {Dummy-.*: (.*), \(.*\)\}", line) # TODO match more thoroughly if (node_log_start): curr_ip = node_log_start.groups()[0] #print "setting current IP to:", curr_ip elif ("getting next hop for" in line): # TODO gegen getting next hop for # save old discovery (if not empty), record new one #if (curr_discovery): # route_discoveries.append(curr_discovery) info = re.search( "\[aodvv2\] aodv_get_next_hop\(\) (.*): getting next hop for (.*)", line).groups() orignode = info[0] targnode = info[1] if (orignode != curr_ip): print "ERROR: current IP ", curr_ip, "differs from orignode ", orignode #print curr_discovery # only add new discovery if it is not a Route Discovery Retry if (not (curr_discovery["orignode"] == orignode and curr_discovery["targnode"] == targnode)): curr_discovery = {} curr_discovery["orignode"] = orignode curr_discovery["targnode"] = targnode curr_discovery["seqnums"] = [] curr_discovery["success"] = 0 curr_discovery["rreq_arrived"] = 0 #print "new discovery: ", curr_discovery # look for (successful) discoveries elif ("originating RREQ" in line): info = re.search( "\[aodvv2\] originating RREQ with SeqNum (.*) towards (.*); updating RREQ table...", line).groups() seqnum = info[0] targnode = info[1] #print line_number, ":", line #print curr_discovery if (curr_discovery and targnode != curr_discovery.get("targnode")): print "ERROR: IP conflict between targnode of discovery: ", targnode, " and expected targnode: ", curr_discovery.get( "targnode"), "in line ", line_number sys.exit() return # double tap! curr_discovery["seqnums"].append(seqnum) # TODO do this more elegantly # this is the first time this discovery is started -> add it to list of started discoveries if (len(curr_discovery["seqnums"]) == 1): route_discoveries.append(curr_discovery) # requested route is direct neighbor elif ("[ndp] found NC entry. Returning dest addr." in line): curr_discovery["success"] = 1 #print line_number, ":", line #print "3", curr_discovery # delete logged attempt if no discovery has taken place because the route was already known elif ("found dest " in line): #print line_number, ":", line targnode = re.search(".*found dest (.*) in routing table", line).groups()[0] # a route towards dest already exists; the discovery has been successful before it even started. # thus, we can remove it from the discovery list, since there was nothing to discover. if (curr_discovery.get("targnode") == targnode and curr_discovery.get("seqnums") == []): #print "hbzd", curr_discovery curr_discovery["success"] = 1 elif ("This is my RREP" in line): info = re.search( ".* (.*): This is my RREP \(SeqNum: (.*)\). We are done here, thanks (.*)!", line).groups() orignode = info[0] targnode = info[2] seqnum = info[1] # mark success in route_discoveries discovery = [ disc for disc in route_discoveries if disc["orignode"] == orignode and disc["targnode"] == targnode ] # and seqnum in disc["seqnums"]] if (len(discovery) > 1): print "WARNING: More than 1 suitable discovery found for line: \n", line discovery[0]["success"] = 1 # look for (successful) transmissions # found initiation of new transmission if ("[demo] sending packet" in line): [timestamp, targnode] = re.search( "{(.*)}\[demo\] sending packet of 15 bytes towards (.*)...", line).groups() transmission = {} transmission = { "timestamp": timestamp, "orignode": curr_ip, "targnode": targnode, "success": 0 } transmissions.append(transmission) if ("[demo] UDP packet received" in line): orignode = re.search( ".*\[demo\].*UDP packet received from (.*):.*", line).groups()[0] print "orignode", orignode print "targnode", curr_ip print "matching transmissions", [ t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip ] #print transmissions print "\n" # found packet that arrived (-> successful transmission) if ("[demo] UDP packet received" in line): num_success_transm += 1 orignode = re.search( ".*\[demo\].*UDP packet received from (.*):.*", line).groups()[0] # problem: packet comes from next hop, not originating node! -> embed info in message? ''' print line_number, ":", line print re.search(".*\[demo\].*UDP packet received from (.*):.*", line).groups() #print transmissions print "orignode: ", orignode, "targnode: ", targnode ,"\ncurr_ip: ", curr_ip #print "transmissions:", transmissions print "matching transmissions", [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip] suitable_transmissions = [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip and t["success"] == 0] #print suitable_transmissions # doesn't matter which one exactly we mark as successful, just pick one. # TODO: herausfinden, warum es success: ... lines ohne suitable transmission gibt. doppelt gesendet? if (len(suitable_transmissions) > 1): suitable_transmissions[-1]["success"] = 1 ''' #print "route_discoveries \n", pp.pprint(route_discoveries) print "transmissions\n", pp.pprint(transmissions) print "successful transmissions: ", num_success_transm successful_discoveries = [ d for d in route_discoveries if d["success"] == 1 ] in_timeout_discoveries = [ d for d in route_discoveries if len(d["seqnums"]) < 3 and d["success"] == 1 ] successful_transmissions = [t for t in transmissions if t["success"] == 1] discovery_summary = {} discovery_summary["success"] = len(successful_discoveries) discovery_summary["fail"] = len( route_discoveries) - discovery_summary["success"] transmission_summary = {} transmission_summary[ "success"] = num_success_transm #len(successful_transmissions) transmission_summary["fail"] = len( transmissions) - transmission_summary["success"] return { "discoveries": discovery_summary, "transmissions": transmission_summary, "discoveries within timeout": len(in_timeout_discoveries), "rrep_fail": 0 }
def count_successes(log_file_location): print "counting successful route discoveries and transmissions..." pp = pprint.PrettyPrinter(indent=2) logfile = open(log_file_location) route_discoveries = [] transmissions = [] curr_ip = "" curr_discovery = {"orignode": "", "targnode": ""} line_number = 0 num_success_transm = 0 for line in logfile: line_number += 1 # reached original topology info; convert it to graphviz-readable format and print if ("riots:" in line): print "xoxo" info = line.split("riots: ")[1] print info print "graphviz:\n", tv.prep_graphviz(info) node_log_start = re.search(".* {Dummy-.*: (.*), \(.*\)\}", line) # TODO match more thoroughly if (node_log_start): curr_ip = node_log_start.groups()[0] #print "setting current IP to:", curr_ip elif ("getting next hop for" in line): # TODO gegen getting next hop for # save old discovery (if not empty), record new one #if (curr_discovery): # route_discoveries.append(curr_discovery) info = re.search("\[aodvv2\] aodv_get_next_hop\(\) (.*): getting next hop for (.*)", line).groups() orignode = info[0] targnode = info[1] if (orignode != curr_ip): print "ERROR: current IP ", curr_ip, "differs from orignode ", orignode #print curr_discovery # only add new discovery if it is not a Route Discovery Retry if (not (curr_discovery["orignode"] == orignode and curr_discovery["targnode"] == targnode)): curr_discovery = {} curr_discovery["orignode"] = orignode curr_discovery["targnode"] = targnode curr_discovery["seqnums"] = [] curr_discovery["success"] = 0 curr_discovery["rreq_arrived"] = 0 #print "new discovery: ", curr_discovery # look for (successful) discoveries elif ("originating RREQ" in line): info = re.search("\[aodvv2\] originating RREQ with SeqNum (.*) towards (.*); updating RREQ table...", line).groups() seqnum = info[0] targnode = info[1] #print line_number, ":", line #print curr_discovery if (curr_discovery and targnode != curr_discovery.get("targnode")): print "ERROR: IP conflict between targnode of discovery: ", targnode, " and expected targnode: ", curr_discovery.get("targnode"), "in line ", line_number sys.exit() return # double tap! curr_discovery["seqnums"].append(seqnum) # TODO do this more elegantly # this is the first time this discovery is started -> add it to list of started discoveries if (len(curr_discovery["seqnums"]) == 1): route_discoveries.append(curr_discovery) # requested route is direct neighbor elif ("[ndp] found NC entry. Returning dest addr." in line): curr_discovery["success"] = 1 #print line_number, ":", line #print "3", curr_discovery # delete logged attempt if no discovery has taken place because the route was already known elif ("found dest " in line): #print line_number, ":", line targnode = re.search(".*found dest (.*) in routing table", line).groups()[0] # a route towards dest already exists; the discovery has been successful before it even started. # thus, we can remove it from the discovery list, since there was nothing to discover. if (curr_discovery.get("targnode") == targnode and curr_discovery.get("seqnums") == []): #print "hbzd", curr_discovery curr_discovery["success"] = 1 elif ("This is my RREP" in line): info = re.search(".* (.*): This is my RREP \(SeqNum: (.*)\). We are done here, thanks (.*)!", line).groups() orignode = info[0] targnode = info[2] seqnum = info[1] # mark success in route_discoveries discovery = [disc for disc in route_discoveries if disc["orignode"] == orignode and disc["targnode"] == targnode] # and seqnum in disc["seqnums"]] if (len(discovery) > 1): print "WARNING: More than 1 suitable discovery found for line: \n", line discovery[0]["success"] = 1 # look for (successful) transmissions # found initiation of new transmission if ("[demo] sending packet" in line): [timestamp, targnode] = re.search("{(.*)}\[demo\] sending packet of 15 bytes towards (.*)...", line).groups() transmission = {} transmission = {"timestamp": timestamp, "orignode": curr_ip, "targnode": targnode, "success": 0} transmissions.append(transmission) if ("[demo] UDP packet received" in line): orignode = re.search(".*\[demo\].*UDP packet received from (.*):.*", line).groups()[0] print "orignode", orignode print "targnode", curr_ip print "matching transmissions", [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip] #print transmissions print "\n" # found packet that arrived (-> successful transmission) if ("[demo] UDP packet received" in line): num_success_transm += 1 orignode = re.search(".*\[demo\].*UDP packet received from (.*):.*", line).groups()[0] # problem: packet comes from next hop, not originating node! -> embed info in message? ''' print line_number, ":", line print re.search(".*\[demo\].*UDP packet received from (.*):.*", line).groups() #print transmissions print "orignode: ", orignode, "targnode: ", targnode ,"\ncurr_ip: ", curr_ip #print "transmissions:", transmissions print "matching transmissions", [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip] suitable_transmissions = [t for t in transmissions if t["orignode"] == orignode and t["targnode"] == curr_ip and t["success"] == 0] #print suitable_transmissions # doesn't matter which one exactly we mark as successful, just pick one. # TODO: herausfinden, warum es success: ... lines ohne suitable transmission gibt. doppelt gesendet? if (len(suitable_transmissions) > 1): suitable_transmissions[-1]["success"] = 1 ''' #print "route_discoveries \n", pp.pprint(route_discoveries) print "transmissions\n", pp.pprint(transmissions) print "successful transmissions: ", num_success_transm successful_discoveries = [d for d in route_discoveries if d["success"] == 1] in_timeout_discoveries = [d for d in route_discoveries if len(d["seqnums"]) <3 and d["success"] == 1] successful_transmissions = [t for t in transmissions if t["success"] == 1] discovery_summary = {} discovery_summary["success"] = len (successful_discoveries) discovery_summary["fail"] = len(route_discoveries) - discovery_summary["success"] transmission_summary = {} transmission_summary["success"] = num_success_transm #len(successful_transmissions) transmission_summary["fail"] = len(transmissions) - transmission_summary["success"] return {"discoveries" : discovery_summary, "transmissions" : transmission_summary, "discoveries within timeout" : len(in_timeout_discoveries), "rrep_fail": 0}