def find_more_specific(consumer): rib = Radix() for item in consumer: data = json.loads(item.value) if "as_path" not in data: continue for node in rib.search_covering(data["prefix"]): for peer, as_path in node.data.iteritems(): if peer != data["peer_as"]: yield (node.prefix, as_path, data["prefix"], data["as_path"]) node = rib.add(data["prefix"]) node.data[data["peer_as"]] = data["as_path"]
if not prefix.startswith("#"): anycast.add(prefix.strip()) count += 1 logger.info("loaded %s prefixes in the anycast list", count) logger.info("filtering on prefixes from the file %s", args.anycast_file) else: raise ValueError("please provide a anycast prefix list file") if args.as_rel_file is not None and args.ppdc_ases_file is not None: relations, childs, parents = caida_filter_annaunce(args.as_rel_file, args.ppdc_ases_file) else: raise ValueError("caida files required") for event in find_more_specific(consumer): try: as_path1 = event[1].split(" ") as_path2 = event[3].split(" ") except: logger.warning("oops %s", event) continue if len(as_path1) < 3 or len(as_path2) < 3: continue if same_path(as_path1, as_path2) or (verify_path(as_path1) and verify_path(as_path2)): continue nodes = list(anycast.search_covering(event[3])) print(event, "anycast" if len(nodes) > 0 else "unknown")
logger.info("loaded %s prefixes in the anycast list", count) logger.info("filtering on prefixes from the file %s", args.anycast_file) else: raise ValueError("please provide a anycast prefix list file") if args.as_rel_file is not None and args.ppdc_ases_file is not None: relations, childs, parents = caida_filter_annaunce( args.as_rel_file, args.ppdc_ases_file) else: raise ValueError("caida files required") for event in find_more_specific(consumer): try: as_path1 = event[1].split(" ") as_path2 = event[3].split(" ") except: logger.warning("oops %s", event) continue if len(as_path1) < 3 or len(as_path2) < 3: continue if same_path(as_path1, as_path2) or (verify_path(as_path1) and verify_path(as_path2)): continue nodes = list(anycast.search_covering(event[3])) print(event, "anycast" if len(nodes) > 0 else "unknown")