funcs.append(partial(annotate_if_route_objects, ro_rad_tree)) if args.rpki_roa_file is not None: roa_rad_tree = Radix() fill_roa_struct(args.rpki_roa_file, roa_rad_tree) funcs.append(partial(annotate_if_roa, ro_rad_tree)) if args.irr_org_file is not None and args.irr_mnt_file: relations_dict = dict() fill_relation_struct(args.irr_org_file, relations_dict, "organisations") fill_relation_struct(args.irr_mnt_file, relations_dict, "maintainers") funcs.append(partial(annotate_if_relation, relations_dict)) if args.as_rel_file is not None and args.ppdc_ases_file is not None and args.as2org_file is not None: a, b,c,d = caida_filter_annaunce(args.as_rel_file, args.ppdc_ases_file, args.as2org_file) funcs.append(partial(is_legittimate, a, b, c,d)) if args.from_timestamp is None: consumer = KafkaConsumer("conflicts", metadata_broker_list=args.our_servers.split(","), group_id="detector", auto_commit_enable=False) offset, = consumer.get_partition_offsets("conflicts", PARTITIONS[args.collector], -1, 1) consumer.set_topic_partitions({("conflicts", PARTITIONS[args.collector]): offset - 1}) last_message = next(iter(consumer)) last_data = json.loads(last_message.value) last_ts = last_data["timestamp"] logger.info("last detected event was at offset %s timestamp %s", offset, last_ts) else: last_ts = args.from_timestamp
if args.anycast_file is not None: anycast = Radix() count = 0 with open(args.anycast_file, "r") as f: for prefix in f: 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 args.anycast_file is not None: anycast = Radix() count = 0 with open(args.anycast_file, "r") as f: for prefix in f: 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