Ejemplo n.º 1
0
def hornet_analyze_boundary_pfx(msm_id, probe_id, boundary, num_strides=4):
    t0, t1 = boundary
    p0 = probe_path_at_time(msm_id, probe_id, t0)
    p1 = probe_path_at_time(msm_id, probe_id, t1)

    t0_obs = hornet_adv_obs(p0)
    t1_obs = hornet_adv_obs(p1)

    interval = ripe_atlas.msm_interval(msm_id)

    t0_date_range = datetimes_from_stride(t1, interval, num_strides, -1)
    t1_date_range = datetimes_from_stride(t0, interval, num_strides, 1)

    t0_anon = anonymity_set_wide(msm_id, t0_obs, hornet_adv_obs,
                                 asns_are_indistinguishable, t0_date_range)

    t1_anon = anonymity_set_wide(msm_id, t1_obs, hornet_adv_obs,
                                 asns_are_indistinguishable, t1_date_range)

    t0_prefixes = probe_times_to_uniq_pfxs(msm_id, t0_anon)
    t1_prefixes = probe_times_to_uniq_pfxs(msm_id, t1_anon)

    itc_pfxs = t0_prefixes.intersection(t1_prefixes)

    t0_num_addrs = num_ipv4_addrs(t0_prefixes)
    itc_num_addrs = num_ipv4_addrs(itc_pfxs)

    return t0_num_addrs, itc_num_addrs
Ejemplo n.º 2
0
def search_for_boundaries(msm_id, probe_id, start_datetime, end_datetime):

    array_fn = lambda x: probe_path_at_time(msm_id, probe_id, x)

    key_fn = lambda x: None if x is None else hornet_adv_obs(x)

    idx_metric_fn = lambda x, y: abs(y.timestamp() - x.timestamp())

    def idx_mid_fn(x, y):
        ts = (x.timestamp() + y.timestamp()) / 2
        dt = datetime.datetime.utcfromtimestamp(ts)
        dt = dt.replace(tzinfo=datetime.timezone.utc)
        return round_datetime_to_interval(dt, msm_id)

    interval = ripe_atlas.msm_interval(msm_id)

    return boundary_search(array_fn, key_fn, idx_metric_fn, idx_mid_fn,
                           start_datetime, end_datetime, interval)
Ejemplo n.º 3
0
def main(args):
    std_format =\
        ("[%(asctime)s %(process)d %(filename)s %(funcName)s %(levelname)s" +
         "] -- %(message)s")

    logging.basicConfig(format=std_format,
                        stream=sys.stderr,
                        level=logging.INFO)

    cache = persistent_lru.PersistentLRU(args.cache_filename, 8096)
    cache.load()
    atexit.register(cache.close)

    hornet.define_common_probe_locations_cached(cache)
    hornet.define_hornet_obs_seqs_cached(cache)
    hornet.define_pfx2as_cached(cache)
    hornet.define_probe_paths_cached(cache)

    start_datetime = datetime.datetime.strptime(args.start_date, "%Y-%m-%d")
    start_datetime = start_datetime.replace(tzinfo=datetime.timezone.utc)

    end_datetime = datetime.datetime.strptime(args.end_date, "%Y-%m-%d")
    end_datetime = end_datetime.replace(tzinfo=datetime.timezone.utc)

    tick_width =\
        datetime.timedelta(seconds=ripe_atlas.msm_interval(args.msm_id))

    analysis_interval = hornet.analysis_interval_points(
        start_datetime, end_datetime, tick_width, args.msm_id)

    stable_probes = hornet.stable_loc_probes(args.msm_id, analysis_interval)

    single_origin_stable_probes = list(
        filter(
            lambda x: len(
                hornet.split_asn_set(
                    hornet.probe_time_to_as(args.msm_id, x, analysis_interval[
                        0]))) == 1, stable_probes))

    # print(len(stable_probes))

    probe_to_asn =\
        lambda x: hornet.split_asn_set(hornet.probe_time_to_as(args.msm_id, x,
                                                          analysis_interval[0])).pop()

    unique_stable_ases = set(map(probe_to_asn, stable_probes))
    # print(len(unique_stable_ases))

    # return

    single_origin_stable_probes = single_origin_stable_probes[:100]

    hornet_obs_seqs = hornet.hornet_obs_seqs_cached(stable_probes,
                                                    analysis_interval,
                                                    args.msm_id)

    asn_before_means = defaultdict(list)
    asn_after_means = defaultdict(list)
    changes_per_asn = defaultdict(list)

    for idx, probe in enumerate(single_origin_stable_probes):
        if idx % 10 == 0:
            logging.info("Analyzing probe {} of {}".format(
                idx, len(stable_probes)))
        try:
            boundaries = hornet.list_of_boundaries(hornet_obs_seqs[probe])

            probe_asn = hornet.probe_time_to_as(args.msm_id, probe,
                                                start_datetime)

            changes_per_asn[probe_asn].append(len(boundaries))

            if len(boundaries) == 0:
                continue

            before_sz = list()
            after_sz = list()

            for boundary in boundaries:
                before_size, after_size =\
                    hornet.hornet_analyze_boundary_asn(args.msm_id, probe,
                                                       boundary)

                before_sz.append(before_size)
                after_sz.append(after_size)

                # before_sz_rel.append(before_size / pfx_size)
                #after_sz_rel.append(after_size / pfx_size)

            asn_before_means[probe_asn].append(np.mean(before_sz))
            asn_after_means[probe_asn].append(np.mean(after_sz))
        except Exception as e:
            logging.warn("Encountered exception {} during probe {}".format(
                e, probe))
            continue

    # Changes per pfx contains all probe pfxs, whereas before and after means
    # only contain pfx's with at least one change
    for asn in changes_per_asn.keys():
        mean_changes = np.mean(changes_per_asn[asn])

        before_means = asn_before_means[asn]
        after_means = asn_after_means[asn]
        before_grand_mean = np.mean(before_means)
        after_grand_mean = np.mean(after_means)

        output = (asn, mean_changes, before_grand_mean, after_grand_mean)

        print(",".join(map(lambda x: str(x), output)))
Ejemplo n.º 4
0
def round_datetime_to_interval(dt, msm_id):
    ts = int(dt.timestamp())
    interval = ripe_atlas.msm_interval(msm_id)
    ts = ts - (ts % interval)
    dt = datetime.datetime.utcfromtimestamp(ts)
    return dt.replace(tzinfo=datetime.timezone.utc)
Ejemplo n.º 5
0
def hornet_analyze_boundaries(msm_id, probe_id, boundaries, num_strides=4):

    found_result = False

    for (t0, t1) in boundaries:
        if t0 == None or t1 == None:
            continue

        p0 = probe_path_at_time(msm_id, probe_id, t0)
        p1 = probe_path_at_time(msm_id, probe_id, t1)
        if p0 is None or p1 is None or (p0[0] != p1[0]):
            s = "Ignoring boundary {} - {} with location {} change to {}"
            logging.info(s.format(str(t0), str(t1), p0, p1))

        t0_obs = hornet_adv_obs(p0)
        t1_obs = hornet_adv_obs(p1)

        if not asn_is_unambig(t0_obs) or not asn_is_unambig(t1_obs):
            s = "Ignoring boundary {} - {} with hop {} change to {}"
            logging.info(s.format(str(t0), str(t1), t0_obs, t1_obs))
            continue

        interval = ripe_atlas.msm_interval(msm_id)

        # Overlapping intervals?
        t0_date_range = datetimes_from_stride(t1, interval, num_strides, -1)
        t1_date_range = datetimes_from_stride(t0, interval, num_strides, 1)

        all_probes = all_known_probes(msm_id, t0_date_range)
        all_valid = all_probes_with_valid_obs(msm_id, hornet_adv_obs,
                                              asn_is_unambig, t0_date_range)

        out_0 = probe_times_stats(msm_id, all_probes)
        out_1 = probe_times_stats(msm_id, all_valid)

        prv = anonymity_set_wide(msm_id, t0_obs, hornet_adv_obs,
                                 asns_are_indistinguishable, t0_date_range)

        out_2 = probe_times_stats(msm_id, prv)

        prv_ases = probe_times_to_uniq_ases(msm_id, prv)
        prv_pfxs = probe_times_to_uniq_pfxs(msm_id, prv)
        prv_probes = probe_times_to_uniq_probes(prv)

        nxt = anonymity_set_wide(msm_id, t1_obs, hornet_adv_obs,
                                 asns_are_indistinguishable, t1_date_range)

        nxt_ases = probe_times_to_uniq_ases(msm_id, nxt)
        nxt_pfxs = probe_times_to_uniq_pfxs(msm_id, nxt)
        nxt_probes = probe_times_to_uniq_probes(nxt)

        itc_ases = prv_ases.intersection(nxt_ases)
        itc_pfxs = prv_pfxs.intersection(nxt_pfxs)
        itc_probes = prv_probes.intersection(nxt_probes)

        itc_addrs = num_ipv4_addrs(itc_pfxs)
        itc_pct = pct_ipv4_addrs(itc_pfxs)

        out_3 = (len(itc_probes), len(itc_pfxs), itc_addrs, itc_pct,
                 len(itc_ases))

        out = (msm_id, probe_id, t0, t1, t0_obs, t1_obs) + out_0 + out_1 +\
                out_2 + out_3

        print(",".join(map(lambda x: str(x), out)))

        found_result = True

        break

    if not found_result:
        out = (msm_id, probe_id, "NIL")
        print(",".join(map(lambda x: str(x), out)))