示例#1
0
def test_prefixlist_append():
    pfx0 = PrefixList(prefixes0)
    pfx1 = PrefixList()

    for each in prefixes0:
        pfx1.append(each)

    print pfx0
    print pfx1
    assert pfx0 == pfx1
示例#2
0
def test_aggregate_single():
    prefixlist = [
        '10.0.1.0/24',
    ]
    expected = [
        '10.0.1.0/24',
    ]
    pfx = PrefixList(prefixlist)

    assert expected == pfx.aggregate().str_list()
    assert PrefixList(prefixlist) == pfx
示例#3
0
def test_aggregate_combine_multi():
    prefixlist = [
        '10.0.0.0/24',
        '10.0.1.0/24',
        '10.0.2.0/23',
    ]
    expected = [
        '10.0.0.0/22',
    ]

    pfx = PrefixList(prefixlist)

    assert expected == pfx.aggregate().str_list()
    assert PrefixList(prefixlist) == pfx
示例#4
0
def test_prefixlist_eq():
    pfx0 = PrefixList(prefixes0)
    pfx1 = PrefixList(prefixes0)
    assert pfx0 == pfx1

    pfx1.pop()
    assert pfx0 != pfx1

    with pytest.raises(TypeError) as e:
        pfx0 != "string"
    assert "object not PrefixList type" == e.value.message

    with pytest.raises(TypeError) as e:
        pfx0 != "string"
    assert "object not PrefixList type" == e.value.message
示例#5
0
def test_aggregate_super():
    prefixlist = [
        '10.0.1.0/24',
        '10.0.0.0/20',
        '2001:db8::/32',
        '2001:db8:1::/64',
    ]
    expected = [
        '10.0.0.0/20',
        '2001:db8::/32',
    ]
    pfx = PrefixList(prefixlist)

    assert expected == pfx.aggregate().str_list()
    assert PrefixList(prefixlist) == pfx
示例#6
0
文件: cli.py 项目: benmaddison/bgpfu
def prefixlist(ctx, as_set, output, output_format, proto, **kwargs):
    """ get prefix list for specified as-sets """
    if kwargs.get('debug', False):
        logging.basicConfig(level=logging.DEBUG)

    prefixes = PrefixList()
    bgpfuc = bgpfu.client.IRRClient()
    with bgpfuc as c:
        if kwargs.get('sources', False):
            c.set_sources(kwargs['sources'])
#        prefixes = c.get_prefixes(as_set, proto)

        for chunk in c.iter_prefixes(as_set, proto):
            prefixes.add_iter(chunk)

        if kwargs.get('aggregate', True):
            prefixes = prefixes.aggregate()

        with click.open_file(output, 'w') as fobj:
            outfmt.write(output_format, fobj, prefixes.str_list())

        print("LEN {}".format(len(prefixes)))
示例#7
0
def test_prefixlist_str_list():
    pfx0 = PrefixList(prefixes0)
    assert prefixes0 == pfx0.str_list()