X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=blobdiff_plain;f=base_gexf_generator.py;h=ad677eccdd2882fd3c9b1258674f02d16bf1b45c;hp=eed37c050b2fdf8319cd677feeeb2623f9d1daed;hb=18b3c06f38f8083d485f232c51e78e0fa5066d53;hpb=bd43c85fe624f8a086052de9d027c42bf9221061 diff --git a/base_gexf_generator.py b/base_gexf_generator.py index eed37c0..ad677ec 100644 --- a/base_gexf_generator.py +++ b/base_gexf_generator.py @@ -43,6 +43,7 @@ JSON_KEY_FRAME_LENGTH = "frame.len" JSON_KEY_ETH = "eth" JSON_KEY_ETH_SRC = "eth.src" JSON_KEY_ETH_DST = "eth.dst" +JSON_KEY_IPV6 = "ipv6" JSON_KEY_IP = "ip" JSON_KEY_IP_SRC = "ip.src" JSON_KEY_IP_DST = "ip.dst" @@ -105,7 +106,7 @@ def traverse_and_merge_nodes(G, dev_list_file): dev_list = create_device_list(DEVICE_MAC_LIST) # Traverse every node # Check that the node is not a smarthome device - for node in nodes: + for node in list(nodes): neighbors = G[node] #G.neighbors(node) #print "Neighbors: ", neighbors, "\n" # Skip if the node is a smarthome device @@ -169,10 +170,19 @@ def place_in_graph(G, eth_src, eth_dst, device_dns_mappings, dev_list, layers, else: protocol = split_protocol[3] + ":" + split_protocol[4] #print "timestamp: ", timestamp, " - new protocol added: ", protocol, "\n" + # And source and destination IPs + ip_src = layers[JSON_KEY_IP][JSON_KEY_IP_SRC] + ip_dst = layers[JSON_KEY_IP][JSON_KEY_IP_DST] + # Categorize source and destination IP addresses: local vs. non-local + #ip_re = re.compile(r'\b192.168.[0-9.]+') + ip_re = re.compile(r'\b192.168.1.[0-9.]+') + src_is_local = ip_re.search(ip_src) + dst_is_local = ip_re.search(ip_dst) # Store protocol into the set (source) protocols = None # Key to search in the dictionary is - - dict_key = eth_src + "-" + eth_dst + dict_key = ip_src + "-" + ip_dst + #print "Key: ", dict_key if dict_key not in edge_to_prot: edge_to_prot[dict_key] = set() protocols = edge_to_prot[dict_key] @@ -184,13 +194,6 @@ def place_in_graph(G, eth_src, eth_dst, device_dns_mappings, dev_list, layers, edge_to_vol[dict_key] = 0; edge_to_vol[dict_key] = edge_to_vol[dict_key] + packet_len volume = str(edge_to_vol[dict_key]) - # And source and destination IPs - ip_src = layers[JSON_KEY_IP][JSON_KEY_IP_SRC] - ip_dst = layers[JSON_KEY_IP][JSON_KEY_IP_DST] - # Categorize source and destination IP addresses: local vs. non-local - ip_re = re.compile(r'\b192.168.[0-9.]+') - src_is_local = ip_re.search(ip_src) - dst_is_local = ip_re.search(ip_dst) # Skip device to cloud communication if we are interested in the local graph. # TODO should this go before the protocol dict is changed? @@ -251,7 +254,7 @@ def parse_json(file_path): # Create an exclusion list exc_list = create_device_list(EXCLUSION_MAC_LIST) # First parse the file once, constructing a map that contains information about individual devices' DNS resolutions. - device_dns_mappings = parser.parse_dns.parse_json_dns(file_path) # "./json/eth1.dump.json" + device_dns_mappings = parser.parse_dns.parse_json_dns(file_path) # Init empty graph G = nx.DiGraph() # Mapping from edge to a set of protocols @@ -259,6 +262,7 @@ def parse_json(file_path): # Mapping from edge to traffic volume edge_to_vol = dict() # Parse file again, this time constructing a graph of device<->server and device<->device communication. + i = 0 with open(file_path) as jf: # Read JSON; data becomes reference to root JSON object (or in our case json array) data = json.load(jf) @@ -292,7 +296,10 @@ def parse_json(file_path): if eth_dst in exc_list: print "[ WARNING: Destination ", eth_dst, " is excluded from graph! ]" continue - + # Exclude if IP does not exist in layers - this means IPv6 + if JSON_KEY_IP not in layers and JSON_KEY_IPV6 in layers: + continue + # Place nodes and edges in graph place_in_graph(G, eth_src, eth_dst, device_dns_mappings, dev_list, layers, edge_to_prot, edge_to_vol)