From cb816db417dff4d0f985455c1d7cbd261fd40f9b Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sun, 10 Aug 2014 22:08:14 +0200 Subject: [PATCH] Adding data progressing functions for CCN --- examples/ccn_flooding/planetlab.py | 13 +- src/nepi/data/processing/ccn/parser.py | 37 ++--- src/nepi/data/processing/ping/parser.py | 10 +- src/nepi/execution/ec.py | 31 +++-- src/nepi/execution/resource.py | 2 +- src/nepi/execution/runner.py | 17 +-- src/nepi/resources/all/collector.py | 5 +- src/nepi/resources/linux/application.py | 2 +- src/nepi/resources/linux/ccn/fibentry.py | 5 +- src/nepi/util/netgraph.py | 148 +++++++++++--------- src/nepi/util/parsers/xml_parser.py | 167 +++++++++++++++++++++-- src/nepi/util/serializer.py | 6 +- 12 files changed, 311 insertions(+), 132 deletions(-) diff --git a/examples/ccn_flooding/planetlab.py b/examples/ccn_flooding/planetlab.py index 5834a85b..766e96b2 100644 --- a/examples/ccn_flooding/planetlab.py +++ b/examples/ccn_flooding/planetlab.py @@ -26,6 +26,7 @@ from nepi.execution.runner import ExperimentRunner from nepi.util.netgraph import NetGraph, TopologyType import nepi.data.processing.ccn.parser as ccn_parser +import networkx import socket import os @@ -152,8 +153,6 @@ def avg_interests(ec, run): ## Process logs logs_dir = ec.run_dir - print ec.netgraph - (graph, content_names, interest_expiry_count, @@ -161,7 +160,7 @@ def avg_interests(ec, run): interest_count, content_count) = ccn_parser.process_content_history_logs( logs_dir, - ec.netgraph) + ec.netgraph.topology) shortest_path = networkx.shortest_path(graph, source = ec.netgraph.sources()[0], @@ -170,11 +169,15 @@ def avg_interests(ec, run): ### Compute metric: Avg number of Interests seen per content name ### normalized by the number of nodes in the shortest path content_name_count = len(content_names.values()) - nodes_in_shortest_path = len(content_names.values()) - metric = interest_count / float(content_name_count) / float(nodes_in_shortest_path) + nodes_in_shortest_path = len(shortest_path) - 1 + metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path)) # TODO: DUMP RESULTS TO FILE # TODO: DUMP GRAPH DELAYS! + f = open("/tmp/metric", "w+") + f.write("%.2f\n" % metric) + f.close() + print " METRIC", metric return metric diff --git a/src/nepi/data/processing/ccn/parser.py b/src/nepi/data/processing/ccn/parser.py index 1a658307..e3c1007a 100644 --- a/src/nepi/data/processing/ccn/parser.py +++ b/src/nepi/data/processing/ccn/parser.py @@ -135,12 +135,12 @@ def parse_file(filename): # If no external IP address was identified for this face # asume it is a local face - hostip = "localhost" + peer = "localhost" if face_id in faces: - hostip, port = faces[face_id] + peer, port = faces[face_id] - data.append((content_name, timestamp, message_type, hostip, face_id, + data.append((content_name, timestamp, message_type, peer, face_id, size, nonce, line)) f.close() @@ -162,18 +162,12 @@ def load_content_history(fname): return content_history def annotate_cn_node(graph, nid, ips2nid, data, content_history): - for (content_name, timestamp, message_type, hostip, face_id, + for (content_name, timestamp, message_type, peer, face_id, size, nonce, line) in data: - # Ignore local messages for the time being. - # They could later be used to calculate the processing times - # of messages. - if peer == "localhost": - return - # Ignore control messages for the time being if is_control(content_name): - return + continue if message_type == "interest_from" and \ peer == "localhost": @@ -182,6 +176,12 @@ def annotate_cn_node(graph, nid, ips2nid, data, content_history): peer == "localhost": graph.node[nid]["ccn_producer"] = True + # Ignore local messages for the time being. + # They could later be used to calculate the processing times + # of messages. + if peer == "localhost": + continue + # remove digest if message_type in ["content_from", "content_to"]: content_name = "/".join(content_name.split("/")[:-1]) @@ -190,7 +190,7 @@ def annotate_cn_node(graph, nid, ips2nid, data, content_history): content_history[content_name] = list() peernid = ips2nid[peer] - add_edge(graph, nid, peernid) + graph.add_edge(nid, peernid) content_history[content_name].append((timestamp, message_type, nid, peernid, nonce, size, line)) @@ -202,12 +202,12 @@ def annotate_cn_graph(logs_dir, graph, parse_ping_logs = False): # Make a copy of the graph to ensure integrity graph = graph.copy() - ips2nids = dict() + ips2nid = dict() for nid in graph.nodes(): ips = graph.node[nid]["ips"] for ip in ips: - ips2nids[ip] = nid + ips2nid[ip] = nid # Now walk through the ccnd logs... for dirpath, dnames, fnames in os.walk(logs_dir): @@ -224,7 +224,7 @@ def annotate_cn_graph(logs_dir, graph, parse_ping_logs = False): if fname.endswith(".log"): filename = os.path.join(dirpath, fname) data = parse_file(filename) - annotate_cn_node(graph, nid, ips2nids, data, content_history) + annotate_cn_node(graph, nid, ips2nid, data, content_history) # Avoid storing everything in memory, instead dump to a file # and reference the file @@ -358,7 +358,8 @@ def process_content_history(graph): content_names[content_name]["rtt"] = rtt content_names[content_name]["lapse"] = (interest_timestamp, content_timestamp) - return (content_names, + return (graph, + content_names, interest_expiry_count, interest_dupnonce_count, interest_count, @@ -377,8 +378,8 @@ def process_content_history_logs(logs_dir, graph): print "Skipping: Error parsing ccnd logs", logs_dir raise - source = consumers(graph)[0] - target = producers(graph)[0] + source = ccn_consumers(graph)[0] + target = ccn_producers(graph)[0] # Process the data from the ccnd logs, but do not re compute # the link delay. diff --git a/src/nepi/data/processing/ping/parser.py b/src/nepi/data/processing/ping/parser.py index 33962075..0248c8cf 100644 --- a/src/nepi/data/processing/ping/parser.py +++ b/src/nepi/data/processing/ping/parser.py @@ -27,7 +27,9 @@ # This library contains functions to parse log files generated using ping. # +import collections import re +import os # RE to match line starting "traceroute to" _rre = re.compile("\d+ bytes from ((?P[^\s]+) )?\(?(?P[^\s]+)\)??: icmp_.eq=\d+ ttl=\d+ time=(?P