⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_bgp_config.py

📁 xorp源码hg
💻 PY
📖 第 1 页 / 共 2 页
字号:
set local-ip 127.0.0.1set as 4commit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return True    def conf_redist_static(builddir, create_static = True):    """    Redistribute static into BGP    """    if create_static:        create_static_command = \"""create protocols staticedit protocols statictop"""    else:        create_static_command = ''    # Configure the xorpsh    xorpsh_commands = \"""configure%screate policyedit policycreate policy-statement staticedit policy-statement staticcreate term 1edit term 1create fromedit fromset protocol statictopedit protocols bgpset export staticcommit""" % (create_static_command)    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_redist_static_incomplete(builddir):    """    Redistribute static into BGP and set the origin to INCOMPLETE    """    conf_redist_static(builddir)    # Configure the xorpsh    xorpsh_commands = \"""configureedit policy policy-statement static term 1create thenedit thenset origin 2commit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_redist_static_no_export(builddir):    """    Redistribute static into BGP and set NO_EXPORT    """    conf_redist_static(builddir)    # Configure the xorpsh    xorpsh_commands = \"""configureedit policy policy-statement static term 1create thenedit thenset community NO_EXPORTcommit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_redist_static_med(builddir):    """    Redistribute static into BGP and set the MED to 42    """    conf_redist_static(builddir)    # Configure the xorpsh    xorpsh_commands = \"""configureedit policy policy-statement static term 1create thenedit thenset med 42upupcreate term 2edit term 2create toedit toset as-path ^$upcreate thenedit thenset med-remove truecommit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_preference_TR1(builddir):    """    Configure TR1 to have a higher preference than TR2    """    # Configure the xorpsh    xorpsh_commands = \    """configurecreate policy policy-statement preference term 1edit policy policy-statement preference term 1create fromedit fromset nexthop4 127.0.0.2..127.0.0.2upcreate thenedit thenset localpref 200topedit protocols bgpset import preferencecommit    """    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_import_med_change(builddir):    """    Set the med of all incoming packets to 42    """    # Configure the xorpsh    xorpsh_commands = \    """configurecreate policy policy-statement preference term 1edit policy policy-statement preference term 1create thenedit thenset med 42topedit protocols bgpset import preferencecommit    """    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_export_med_change(builddir):    """    Set the med of all outgoing packets to 42    """    # Configure the xorpsh    xorpsh_commands = \    """configurecreate policy policy-statement preference term 1edit policy policy-statement preference term 1create thenedit thenset med 42topedit protocols bgpset export preferencecommit    """    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_import_origin_change(builddir):    """    Set the origin of all incoming packets to incomplete    """    # Configure the xorpsh    xorpsh_commands = \    """configurecreate policy policy-statement preference term 1edit policy policy-statement preference term 1create thenedit thenset origin 2topedit protocols bgpset import preferencecommit    """    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_export_origin_change(builddir):    """    Set the origin of all outgoing packets to incomplete    """    # Configure the xorpsh    xorpsh_commands = \    """configurecreate policy policy-statement preference term 1edit policy policy-statement preference term 1create thenedit thenset origin 2topedit protocols bgpset export preferencecommit    """    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_damping(builddir):    """    Configure damping    """    # Configure the xorpsh    xorpsh_commands = \"""configureedit protocols bgpcreate dampingedit dampingset suppress 2000set reuse 800set half-life 3set max-suppress 5commit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_aggregate_brief(builddir):    if not conf_aggregate(builddir, "true"):        return False    return Truedef conf_aggregate_asset(builddir):    if not conf_aggregate(builddir, "false"):        return False    return Truedef conf_aggregate(builddir, brief_mode):    """    Configure aggregate     """    # Configure the xorpsh    xorpsh_commands = \"""configurecreate policyedit policycreate policy-statement aggregateedit policy-statement aggregatecreate term 1edit term 1create fromedit fromset network4 <= 192.0.0.0/8upcreate thenedit thenset aggregate-prefix-len 8set aggregate-brief-mode %stopedit policycreate policy-statement drop-componentedit policy-statement drop-componentcreate term 1edit term 1create toedit toset was-aggregated trueupcreate thenedit thenset rejecttopedit protocol bgpset import aggregateset export drop-componentcommit""" % (brief_mode)    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_create_protocol_static(builddir):    """    Create the static protocol    """    # Configure the xorpsh    xorpsh_commands = \"""configurecreate protocols staticcommit"""    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_add_static_route4(builddir, net, next_hop = "127.0.0.1"):    """    Add a static route    """    # Configure the xorpsh    xorpsh_commands = \"""configureedit protocols staticcreate route %sedit route %sset next-hop %scommit""" % (net, net, next_hop)    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_delete_static_route4(builddir, net, next_hop = "127.0.0.1"):    """    Delete a static route    """    # Configure the xorpsh    xorpsh_commands = \"""configuredelete protocols static route %scommit""" % (net)    if not xorpsh(builddir, xorpsh_commands):        return False    return Truedef conf_multiprotocol(builddir):    """    Configure multiprotocol    """    return Truedef show_bgp_routes(builddir):    """    Return the output of the show bgp routes command.    """    xorpsh_commands = \"""show bgp routes"""    result, output = xorpsh(builddir, xorpsh_commands)    if not result:        return False, output    return True, output        # Local Variables:# mode: python# py-indent-offset: 4# End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -