Esempio n. 1
0
def main():
    import sys
    if len(sys.argv) < 3:
        print('Usage: %s <as-rel.txt> <as-types.txt>')
        sys.exit()
    dg = load_as_rel(sys.argv[1])
    load_as_type(sys.argv[2], dg)
    stubs = get_stub_networks(dg)

    split_stubs(stubs)
Esempio n. 2
0
def main1():
    import sys
    if len(sys.argv) < 4:
        print('Usage: %s <as-rel.txt> <as-types.txt> <as-country.txt>')
        sys.exit()
    dg = load_as_rel(sys.argv[1])
    load_as_type(sys.argv[2], dg)
    load_as_country(sys.argv[3], dg)
    sdg = get_subtopo(dg, 'US')
    stubs = get_stub_networks(sdg)

    split_stubs(stubs)
Esempio n. 3
0
def main():
    import sys
    if len(sys.argv) < 4:
        print(
            "Usage: %s <as-rel.txt> <stubs.txt> <line_num> [count] [src_as] [dst_as]"
            % sys.argv[0])
        sys.exit()
    dg = load_as_rel(sys.argv[1])
    # load_as_type(sys.argv[2], dg)
    count = 100
    if len(sys.argv) > 4:
        count = int(sys.argv[4])
    # if len(sys.argv) > 4:
    #     src = int(sys.argv[4])
    # else:
    #     src = random.choice(list(dg.nodes()))

    # if len(sys.argv) > 5:
    #     dst = int(sys.argv[5])
    # else:
    #     dst = random.choice([n for n in dg.nodes() if n != src])

    # print('qcast origin: %d' % src)
    # print('dcast origin: %d' % dst)

    stubs = read_stubs(sys.argv[2], int(sys.argv[3]))

    total = 0
    success = 0

    for src in stubs:
        for dst in stubs:
            if src == dst:
                continue

            init_hints(dg, hint_key='qhint')
            bfs_with_rel(dg, src, count=count, hint_key='qhint')

            init_hints(dg, hint_key='dhint')
            bfs_with_rel(dg, dst, count=count, hint_key='dhint')

            match_nodes = bubblecast_match(dg)
            # print('number of nodes matching qcast/dcast: %d' % len(match_nodes))
            total += 1
            if len(match_nodes) > 0:
                success += 1
            print(len(match_nodes))

    print('*** %d/%d  src-dst pairs had at least one match' % success, total)
Esempio n. 4
0
def main():
    import sys
    if len(sys.argv) < 5:
        print("Usage: %s <as-rel.txt> <as-country.txt> <stubs.txt> <line_num> [count]" % sys.argv[0])
        sys.exit()
    rdg = load_as_rel(sys.argv[1])
    load_as_country(sys.argv[2], rdg)
    dg = get_subtopo(rdg, 'US')
    count = 100
    if len(sys.argv) > 5:
        count = int(sys.argv[5])

    stubs = read_stubs(sys.argv[3], int(sys.argv[4]))

    total = 0
    success = 0

    for src in stubs:
        for dst in stubs:
            if src == dst:
                continue

            init_hints(dg, hint_key='qhint')
            bfs_with_rel(dg, src, count=count, hint_key='qhint')

            init_hints(dg, hint_key='dhint')
            bfs_with_rel(dg, dst, count=count, hint_key='dhint')

            match_nodes = bubblecast_match(dg)
            # print('number of nodes matching qcast/dcast: %d' % len(match_nodes))
            total += 1
            if len(match_nodes) > 0:
                success += 1
            print(len(match_nodes))


    print('*** %d/%d  src-dst pairs had at least one match' % success, total)
Esempio n. 5
0
def plot_degree_stats(dg, filepath=None, **kwargs):
    degrees = np.array([dg.out_degree(n) for n in dg.nodes()])
    ecdf = sm.distributions.ECDF(degrees)
    # e_smooth = np.linspace(0, max(degrees), 10000)
    e_smooth = np.arange(1, max(degrees) + 1)
    c_smooth = ecdf(e_smooth)
    fig = plt.figure(figsize=kwargs.get('figsize', None))
    # plt.plot(e_smooth, c_smooth)
    logfunc = np.vectorize(lambda x: np.log2(x) if x > 0 else 0)

    plt.plot(logfunc(e_smooth), c_smooth)
    plt.axis([0, np.log2(max(degrees)), 0, 1])
    plt.xlabel('Degree of AS')
    plt.ylabel('CDF')

    ax = plt.gca()
    x_format = lambda x, pos: r'$2^{%d}$' % x
    ax.xaxis.set_major_formatter(tkr.FuncFormatter(x_format))

    if filepath:
        fig.savefig(filepath, **kwargs)
        plt.close()


if __name__ == '__main__':
    import sys
    if len(sys.argv) < 3:
        print('Usage: %s <as-rel.txt> <fig.pdf>')
    dg = load_as_rel(sys.argv[1])
    plot_degree_stats(dg, filepath=sys.argv[2], dpi=600, figsize=(8, 4))
Esempio n. 6
0
def load_as_graph():
    from as_rel import load_as_rel
    return load_as_rel("data/20181201.as-rel.txt")