Exemplo n.º 1
0
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    global ADDR_TYPES

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: %s", testsuite_run_time)
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    tgen = Topogen(CreateTopo, mod.__name__)
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Checking BGP convergence
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "setup_module :Failed \n Error:" " {}".format(result)

    logger.info("Running setup_module() done")
Exemplo n.º 2
0
def setup_module(mod):
    """Set up the pytest environment."""
    global topo, ADDR_TYPES

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/rfc5549_ebgp_unnumbered_nbr.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo

    # Starting topology, create tmp files which are loaded to routers
    #  to start daemons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
        BGP_CONVERGENCE
    )
    logger.info("Running setup_module() done")
Exemplo n.º 3
0
def setup_module(mod):
    """
    Sets up the pytest environment.

    * `mod`: module name
    """
    global ADDR_TYPES

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    tgen = topojson.setup_module_from_json(mod.__file__)
    topo = tgen.json_topo

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Api call verify whether BGP is converged
    ADDR_TYPES = check_address_types()

    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
        BGP_CONVERGENCE)

    # STATIC_ROUTE = True
    logger.info("Running setup_module() done")
Exemplo n.º 4
0
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    tgen = Topogen(CreateTopo, mod.__name__)
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    global BGP_CONVERGENCE
    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}". \
        format(BGP_CONVERGENCE)

    logger.info("Running setup_module() done")
def test_bgp_convergence(tgen, topo):
    "Test for BGP convergence."

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    bgp_convergence = bgp.verify_bgp_convergence(tgen, topo)
    assert bgp_convergence
Exemplo n.º 6
0
def test_BGP_config_with_2byteAS_and_4byteAS_number_p1(request):
    """
    Configure BGP with 4 byte and 2 byte ASN and verify BGP is converged
    """

    tgen = get_topogen()
    global BGP_CONVERGENCE

    if BGP_CONVERGENCE != True:
        pytest.skip("skipped because of BGP Convergence failure")

    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    result = verify_bgp_convergence(tgen, topo)
    if result != True:
        assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)

    # Api call to modify AS number
    input_dict = {
        "r1": {"bgp": {"local_as": 131079}},
        "r2": {"bgp": {"local_as": 131079}},
        "r3": {"bgp": {"local_as": 131079}},
        "r4": {"bgp": {"local_as": 111}},
    }
    result = modify_as_number(tgen, topo, input_dict)
    if result != True:
        assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)

    result = verify_as_numbers(tgen, topo, input_dict)
    if result != True:
        assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)

    # Api call verify whether BGP is converged
    result = verify_bgp_convergence(tgen, topo)
    if result != True:
        assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)

    write_test_footer(tc_name)
Exemplo n.º 7
0
def test_BGP_config_with_invalid_ASN_p2(request):
    """
    Configure BGP with invalid ASN(ex - 0, reserved ASN) and verify test case
    ended up with error
    """

    tgen = get_topogen()
    global BGP_CONVERGENCE

    if BGP_CONVERGENCE != True:
        pytest.skip("skipped because of BGP Convergence failure")

    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    # Api call to modify AS number
    input_dict = {
        "r1": {
            "bgp": {
                "local_as": 0,
            }
        },
        "r2": {
            "bgp": {
                "local_as": 0,
            }
        },
        "r3": {
            "bgp": {
                "local_as": 0,
            }
        },
        "r4": {
            "bgp": {
                "local_as": 64000,
            }
        },
    }
    result = modify_as_number(tgen, topo, input_dict)
    assert (
        result is not True
    ), "Expected BGP config is not created because of invalid ASNs: {}".format(result)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    result = verify_bgp_convergence(tgen, topo)
    if result != True:
        assert False, "Testcase " + tc_name + " :Failed \n Error: {}".format(result)

    write_test_footer(tc_name)
Exemplo n.º 8
0
def test_ecmp_after_clear_bgp(request, ecmp_num, test_type):
    """ Verify BGP table and RIB in DUT after clear BGP routes and neighbors"""

    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()

    reset_config_on_routers(tgen)

    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"

    static_or_nw(tgen, topo, tc_name, test_type, "r2")
    for addr_type in ADDR_TYPES:
        input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_1,
            next_hop=NEXT_HOPS[addr_type][: int(ecmp_num)],
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    # Clear BGP
    for addr_type in ADDR_TYPES:
        clear_bgp(tgen, addr_type, dut)

    # Verify BGP convergence
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    for addr_type in ADDR_TYPES:
        input_dict_1 = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_1,
            next_hop=NEXT_HOPS[addr_type][: int(ecmp_num)],
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Exemplo n.º 9
0
def setup_module(mod):
    """

    Set up the pytest environment.

    * `mod`: module name
    """
    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/static_routes_topo3_ibgp.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    if version_cmp(platform.release(), "4.19") < 0:
        error_msg = (
            'These tests will not run. (have kernel "{}", '
            "requires kernel >= 4.19)".format(platform.release())
        )
        pytest.skip(error_msg)

    # Checking BGP convergence
    global BGP_CONVERGENCE
    global ADDR_TYPES

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    # Api call verify whether BGP is converged
    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
        BGP_CONVERGENCE
    )

    logger.info("Running setup_module() done")
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """
    # Required linux kernel version for this suite to run.
    result = required_linux_kernel_version("4.15")
    if result is not True:
        pytest.skip("Kernel requirements are not met")

    global ADDR_TYPES
    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/bgp_large_community_topo_1.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Checking BGP convergence
    global bgp_convergence

    # Don"t run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    ##tgen.mininet_cli()
    # Api call verify whether BGP is converged
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format(
        bgp_convergence
    )

    ADDR_TYPES = check_address_types()
    logger.info("Running setup_module() done")
Exemplo n.º 11
0
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/evpn_type5_chaos_topo1.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    if version_cmp(platform.release(), "4.19") < 0:
        error_msg = (
            'EVPN tests will not run (have kernel "{}", '
            "but it requires >= 4.19)".format(platform.release())
        )
        pytest.skip(error_msg)

    global BGP_CONVERGENCE
    global ADDR_TYPES
    ADDR_TYPES = check_address_types()

    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
        BGP_CONVERGENCE
    )

    logger.info("Pre-requisite config for testsuite")
    prerequisite_config_for_test_suite(tgen)

    logger.info("Running setup_module() done")
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    # Required linux kernel version for this suite to run.
    result = required_linux_kernel_version("4.16")
    if result is not True:
        pytest.skip("Kernel requirements are not met")

    global ADDR_TYPES

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/bgp_gr_topojson_topo2.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start daemons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Api call verify whether BGP is converged
    ADDR_TYPES = check_address_types()

    for addr_type in ADDR_TYPES:
        BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
        assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format(
            BGP_CONVERGENCE
        )

    logger.info("Running setup_module() done")
Exemplo n.º 13
0
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    # Required linux kernel version for this suite to run.
    result = required_linux_kernel_version("4.15")
    if result is not True:
        pytest.skip("Kernel requirements are not met")

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    tgen = Topogen(BGPCOMMUNITIES, mod.__name__)
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Checking BGP convergence
    global BGP_CONVERGENCE
    global ADDR_TYPES

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Api call verify whether BGP is converged
    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
        BGP_CONVERGENCE
    )

    logger.info("Running setup_module() done")
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    global topo
    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    tgen = Topogen(build_topo, mod.__name__)
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Run these tests for kernel version 4.19 or above
    if version_cmp(platform.release(), "4.19") < 0:
        error_msg = (
            "BGP vrf dynamic route leak tests will not run "
            '(have kernel "{}", but it requires >= 4.19)'.format(platform.release())
        )
        pytest.skip(error_msg)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    global BGP_CONVERGENCE
    global ADDR_TYPES
    ADDR_TYPES = check_address_types()

    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
        BGP_CONVERGENCE
    )

    logger.info("Running setup_module() done")
def test_bgp_convergence(request):
    " Test BGP daemon convergence "

    tgen = get_topogen()
    global bgp_convergence
    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Api call verify whether BGP is converged
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "test_bgp_convergence failed.. \n" \
                                    " Error: {}".format(bgp_convergence)

    logger.info("BGP is converged successfully \n")
    write_test_footer(tc_name)
Exemplo n.º 16
0
def setup_module(mod):
    """
    Sets up the pytest environment

    * `mod`: module name
    """

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    json_file = "{}/prefix_lists.json".format(CWD)
    tgen = Topogen(json_file, mod.__name__)
    global topo
    topo = tgen.json_topo
    # ... and here it calls Mininet initialization functions.

    # Starting topology, create tmp files which are loaded to routers
    #  to start daemons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Checking BGP convergence
    global BGP_CONVERGENCE

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Api call verify whether BGP is converged
    BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
    assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
        BGP_CONVERGENCE
    )

    logger.info("Running setup_module() done")
Exemplo n.º 17
0
def test_restart_frr_p2(request):
    """

    Test extended capability nexthop , restart frr.

    Verify IPv4 routes are intact after stop and start the FRR services
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)
    step("Configure IPv6 EBGP Unnumbered session between R1 and R2")
    step("Enable capability extended-nexthop on both the IPv6 BGP peers")
    step("Activate same IPv6 nbr from IPv4 unicast family")
    step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
    step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
    for rte in range(0, NO_OF_RTES):
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"][rte],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP["ipv4"][rte],
                    }
                ]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Advertise static routes from IPv4 unicast family and IPv6 "
        "unicast family respectively from R1 using red static cmd "
        "Advertise loopback from IPv4 unicast family using network command "
        "from R1"
    )

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {"network": NETWORK_CMD_IP, "no_of_network": 1}
                            ],
                        }
                    },
                    "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    step(
        "IPv4 routes advertised using static and network command are "
        " received on R2 BGP and routing table , "
        "verify using show ip bgp, show ip route for IPv4 routes ."
    )

    llip = get_llip("r1", "r2-link0")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    dut = "r2"
    protocol = "bgp"
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {
                    "network": NETWORK["ipv4"][0],
                    "no_of_ip": NO_OF_RTES,
                    "next_hop": llip,
                }
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }

    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r1")
    stop_router(tgen, "r2")
    start_router(tgen, "r1")
    start_router(tgen, "r2")

    step(
        "After stop/start of FRR services , verify session up and routes "
        "came up fine ,nh is proper using show bgp & show ipv6 route on R2 "
    )
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    llip = get_llip("r1", "r2-link0")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # verify the routes with nh as ext_nh
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # verify the routes with nh as ext_nh
    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    write_test_footer(tc_name)
Exemplo n.º 18
0
def test_ibgp_loopback_nbr_p1(request):
    """
    Verify Extended capability nexthop with loopback interface.

    Verify IPv4 routes are advertised and withdrawn when IPv6 IBGP
    session established using loopback interface
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    global topo
    topo1 = deepcopy(topo)
    reset_config_on_routers(tgen)
    step("Configure IPv6 global address between R1 and R2")
    step(
        "Configure loopback on R1 and R2 and establish EBGP session "
        "between R1 and R2 over loopback global ip"
    )
    step("Configure static route on R1 and R2 for loopback reachability")
    step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")

    for routerN in ["r1", "r2"]:
        for addr_type in ["ipv6"]:
            for bgp_neighbor in topo1["routers"][routerN]["bgp"]["address_family"][
                addr_type
            ]["unicast"]["neighbor"].keys():
                # Adding ['source_link'] = 'lo' key:value pair
                if bgp_neighbor == "r1" or bgp_neighbor == "r2":
                    topo1["routers"][routerN]["bgp"]["address_family"][addr_type][
                        "unicast"
                    ]["neighbor"][bgp_neighbor]["dest_link"] = {
                        "lo": {
                            "source_link": "lo",
                            "ebgp_multihop": 2,
                            "capability": "extended-nexthop",
                            "activate": "ipv4",
                        }
                    }
    # Creating configuration from JSON
    build_config_from_json(tgen, topo1, save_bkup=False)

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {"r1-link0": {"deactivate": "ipv6"}}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r2 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {"r2-link0": {"deactivate": "ipv6"}}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {"r1-link0": {"deactivate": "ipv4"}}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r2 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {"r2-link0": {"deactivate": "ipv4"}}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    r2_lo_v4 = topo["routers"]["r2"]["links"]["lo"]["ipv4"]
    r2_lo_v6 = topo["routers"]["r2"]["links"]["lo"]["ipv6"]
    r1_lo_v4 = topo["routers"]["r1"]["links"]["lo"]["ipv4"]
    r1_lo_v6 = topo["routers"]["r1"]["links"]["lo"]["ipv6"]
    r1_r2_intf = topo["routers"]["r1"]["links"]["r2-link0"]["interface"]
    r2_r1_intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]

    r1_r2_v6_nh = topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0]
    r2_r1_v6_nh = topo["routers"]["r2"]["links"]["r1-link0"]["ipv6"].split("/")[0]

    ipv4_list = [("r1", r1_r2_intf, [r2_lo_v4]), ("r2", r2_r1_intf, [r1_lo_v4])]

    ipv6_list = [
        ("r1", r1_r2_intf, [r2_lo_v6], r2_r1_v6_nh),
        ("r2", r2_r1_intf, [r1_lo_v6], r1_r2_v6_nh),
    ]

    for dut, intf, loop_addr in ipv4_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr)
        # assert result is True, "Testcase {}:Failed \n Error: {}". \
        #    format(tc_name, result)

    for dut, intf, loop_addr, next_hop in ipv6_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr, next_hop)
        # assert result is True, "Testcase {}:Failed \n Error: {}". \
        #    format(tc_name, result)

    r2_lo_v4 = topo["routers"]["r2"]["links"]["lo"]["ipv4"]
    r2_lo_v6 = topo["routers"]["r2"]["links"]["lo"]["ipv6"]
    r1_lo_v4 = topo["routers"]["r1"]["links"]["lo"]["ipv4"]
    r1_lo_v6 = topo["routers"]["r1"]["links"]["lo"]["ipv6"]
    r1_r2_intf = topo["routers"]["r1"]["links"]["r2-link0"]["interface"]
    r2_r1_intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]

    r1_r2_v6_nh = topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0]
    r2_r1_v6_nh = topo["routers"]["r2"]["links"]["r1-link0"]["ipv6"].split("/")[0]

    r1_r2_v4_nh = topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0]
    r2_r1_v4_nh = topo["routers"]["r2"]["links"]["r1-link0"]["ipv4"].split("/")[0]

    input_dict = {
        "r1": {
            "static_routes": [
                {"network": r2_lo_v4, "next_hop": r2_r1_v4_nh},
                {"network": r2_lo_v6, "next_hop": r2_r1_v6_nh},
            ]
        },
        "r2": {
            "static_routes": [
                {"network": r1_lo_v4, "next_hop": r1_r2_v4_nh},
                {"network": r1_lo_v6, "next_hop": r1_r2_v6_nh},
            ]
        },
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    # Api call verify whether BGP is converged
    result = verify_bgp_convergence(tgen, topo1)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
    configure_bgp_on_r1 = {
        "r1": {
            "default_ipv4_unicast": False,
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "lo": {
                                            "activate": "ipv4",
                                            "capability": "extended-nexthop",
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r2 = {
        "r2": {
            "default_ipv4_unicast": False,
            "bgp": {
                "address_family": {
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "lo": {
                                            "activate": "ipv4",
                                            "capability": "extended-nexthop",
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step("Verify bgp convergence.")
    bgp_convergence = verify_bgp_convergence(tgen, topo1)
    assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    step("Configure 2 IPv4 static" " routes on R1, Nexthop as different links of R0")

    for rte in range(0, NO_OF_RTES):
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"][rte],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP["ipv4"][rte],
                    }
                ]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Advertise static routes from IPv4 unicast family and IPv6 "
        "unicast family respectively from R1 using red static cmd "
        "Advertise loopback from IPv4 unicast family using network command "
        "from R1"
    )

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {"network": NETWORK_CMD_IP, "no_of_network": 1}
                            ],
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step(
        "IPv4 routes advertised using static and network command are "
        " received on R2 BGP and routing table , "
        "verify using show ip bgp, show ip route for IPv4 routes ."
    )

    gllip = (topo1["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]).lower()
    assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result
    )

    dut = "r2"
    protocol = "bgp"
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {
                    "network": NETWORK["ipv4"][0],
                    "no_of_ip": NO_OF_RTES,
                    "next_hop": gllip,
                }
            ]
        }
    }
    bgp_rib = verify_bgp_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip
    )
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": gllip}
            ]
        }
    }
    bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step(
        "Remove IPv4 routes advertised using network command"
        " from R1 and advertise again"
    )

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {
                                    "network": NETWORK_CMD_IP,
                                    "no_of_network": 1,
                                    "delete": True,
                                }
                            ],
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {
                                    "network": NETWORK_CMD_IP,
                                    "no_of_network": 1,
                                }
                            ],
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    step(
        "After removing IPv4 routes from network command , routes which are "
        "advertised using redistribute static are still present in the on "
        "R2 , verify using show ip bgp and show ip route"
    )

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": gllip}
            ]
        }
    }
    bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step(
        "Remove IPv4 routes advertised using redistribute static"
        " command from R1 and advertise again"
    )

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static", "delete": True}]
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo1, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    step(
        "After removing IPv4 routes from redistribute static , routes which"
        " are advertised using network are still present in the on R2 , "
        "verify using show ip bgp and show ip route"
    )

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": gllip}
            ]
        }
    }
    bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    write_test_footer(tc_name)
Exemplo n.º 19
0
def test_bgp_with_loopback_with_same_subnet_p1(request):
    """
    Verify routes not installed in zebra when /32 routes received
    with loopback BGP session subnet
    """

    tgen = get_topogen()
    if BGP_CONVERGENCE is not True:
        pytest.skip("skipped because of BGP Convergence failure")

    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)
    step("Delete BGP seesion created initially")
    input_dict_r1 = {
        "r1": {"bgp": {"delete": True}},
        "r2": {"bgp": {"delete": True}},
        "r3": {"bgp": {"delete": True}},
        "r4": {"bgp": {"delete": True}},
    }
    result = create_router_bgp(tgen, topo, input_dict_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step("Create BGP session over loop address")
    topo_modify = deepcopy(topo)

    for routerN in sorted(topo["routers"].keys()):
        for addr_type in ADDR_TYPES:
            for bgp_neighbor in topo_modify["routers"][routerN]["bgp"][
                "address_family"
            ][addr_type]["unicast"]["neighbor"].keys():

                # Adding ['source_link'] = 'lo' key:value pair
                topo_modify["routers"][routerN]["bgp"]["address_family"][addr_type][
                    "unicast"
                ]["neighbor"][bgp_neighbor]["dest_link"] = {
                    "lo": {"source_link": "lo", "ebgp_multihop": 2}
                }

    result = create_router_bgp(tgen, topo_modify["routers"])
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step("Disable IPv6 BGP nbr from ipv4 address family")
    raw_config = {
        "r1": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r1"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r2": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r2"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r3": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r3"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r4"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r4": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r4"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
    }

    step("Configure kernel routes")
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    r1_ipv4_lo = topo["routers"]["r1"]["links"]["lo"]["ipv4"]
    r1_ipv6_lo = topo["routers"]["r1"]["links"]["lo"]["ipv6"]
    r2_ipv4_lo = topo["routers"]["r2"]["links"]["lo"]["ipv4"]
    r2_ipv6_lo = topo["routers"]["r2"]["links"]["lo"]["ipv6"]
    r3_ipv4_lo = topo["routers"]["r3"]["links"]["lo"]["ipv4"]
    r3_ipv6_lo = topo["routers"]["r3"]["links"]["lo"]["ipv6"]
    r4_ipv4_lo = topo["routers"]["r4"]["links"]["lo"]["ipv4"]
    r4_ipv6_lo = topo["routers"]["r4"]["links"]["lo"]["ipv6"]

    r1_r2 = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
    r2_r1 = topo["routers"]["r2"]["links"]["r1"]["ipv6"].split("/")[0]
    r1_r3 = topo["routers"]["r1"]["links"]["r3"]["ipv6"].split("/")[0]
    r3_r1 = topo["routers"]["r3"]["links"]["r1"]["ipv6"].split("/")[0]
    r2_r3 = topo["routers"]["r2"]["links"]["r3"]["ipv6"].split("/")[0]
    r3_r2 = topo["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
    r3_r4 = topo["routers"]["r3"]["links"]["r4"]["ipv6"].split("/")[0]
    r4_r3 = topo["routers"]["r4"]["links"]["r3"]["ipv6"].split("/")[0]

    r1_r2_ipv4 = topo["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
    r2_r1_ipv4 = topo["routers"]["r2"]["links"]["r1"]["ipv4"].split("/")[0]
    r1_r3_ipv4 = topo["routers"]["r1"]["links"]["r3"]["ipv4"].split("/")[0]
    r3_r1_ipv4 = topo["routers"]["r3"]["links"]["r1"]["ipv4"].split("/")[0]
    r2_r3_ipv4 = topo["routers"]["r2"]["links"]["r3"]["ipv4"].split("/")[0]
    r3_r2_ipv4 = topo["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
    r3_r4_ipv4 = topo["routers"]["r3"]["links"]["r4"]["ipv4"].split("/")[0]
    r4_r3_ipv4 = topo["routers"]["r4"]["links"]["r3"]["ipv4"].split("/")[0]

    r1_r2_intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
    r2_r1_intf = topo["routers"]["r2"]["links"]["r1"]["interface"]
    r1_r3_intf = topo["routers"]["r1"]["links"]["r3"]["interface"]
    r3_r1_intf = topo["routers"]["r3"]["links"]["r1"]["interface"]
    r2_r3_intf = topo["routers"]["r2"]["links"]["r3"]["interface"]
    r3_r2_intf = topo["routers"]["r3"]["links"]["r2"]["interface"]
    r3_r4_intf = topo["routers"]["r3"]["links"]["r4"]["interface"]
    r4_r3_intf = topo["routers"]["r4"]["links"]["r3"]["interface"]

    ipv4_list = [
        ("r1", r1_r2_intf, r2_ipv4_loopback),
        ("r1", r1_r3_intf, r3_ipv4_loopback),
        ("r2", r2_r1_intf, r1_ipv4_loopback),
        ("r2", r2_r3_intf, r3_ipv4_loopback),
        ("r3", r3_r1_intf, r1_ipv4_loopback),
        ("r3", r3_r2_intf, r2_ipv4_loopback),
        ("r3", r3_r4_intf, r4_ipv4_loopback),
        ("r4", r4_r3_intf, r3_ipv4_loopback),
    ]

    ipv6_list = [
        ("r1", r1_r2_intf, r2_ipv6_loopback, r2_r1),
        ("r1", r1_r3_intf, r3_ipv6_loopback, r3_r1),
        ("r2", r2_r1_intf, r1_ipv6_loopback, r1_r2),
        ("r2", r2_r3_intf, r3_ipv6_loopback, r3_r2),
        ("r3", r3_r1_intf, r1_ipv6_loopback, r1_r3),
        ("r3", r3_r2_intf, r2_ipv6_loopback, r2_r3),
        ("r3", r3_r4_intf, r4_ipv6_loopback, r4_r3),
        ("r4", r4_r3_intf, r3_ipv6_loopback, r3_r4),
    ]

    for dut, intf, loop_addr in ipv4_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr)
        assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)

    for dut, intf, loop_addr, next_hop in ipv6_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr, next_hop)
        assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)

    step("Configure static routes")

    input_dict = {
        "r1": {
            "static_routes": [
                {"network": r2_ipv4_loopback, "next_hop": r2_r1_ipv4},
                {"network": r3_ipv4_loopback, "next_hop": r3_r1_ipv4},
                {"network": r2_ipv6_loopback, "next_hop": r2_r1},
                {"network": r3_ipv6_loopback, "next_hop": r3_r1},
            ]
        },
        "r2": {
            "static_routes": [
                {"network": r1_ipv4_loopback, "next_hop": r1_r2_ipv4},
                {"network": r3_ipv4_loopback, "next_hop": r3_r2_ipv4},
                {"network": r1_ipv6_loopback, "next_hop": r1_r2},
                {"network": r3_ipv6_loopback, "next_hop": r3_r2},
            ]
        },
        "r3": {
            "static_routes": [
                {"network": r1_ipv4_loopback, "next_hop": r1_r3_ipv4},
                {"network": r2_ipv4_loopback, "next_hop": r2_r3_ipv4},
                {"network": r4_ipv4_loopback, "next_hop": r4_r3_ipv4},
                {"network": r1_ipv6_loopback, "next_hop": r1_r3},
                {"network": r2_ipv6_loopback, "next_hop": r2_r3},
                {"network": r4_ipv6_loopback, "next_hop": r4_r3},
            ]
        },
        "r4": {
            "static_routes": [
                {"network": r3_ipv4_loopback, "next_hop": r3_r4_ipv4},
                {"network": r3_ipv6_loopback, "next_hop": r3_r4},
            ]
        },
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Verify BGP session convergence")

    result = verify_bgp_convergence(tgen, topo_modify)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configure redistribute connected on R2 and R4")
    input_dict_1 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                    "ipv6": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                }
            }
        },
        "r4": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                    "ipv6": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                }
            }
        },
    }

    result = create_router_bgp(tgen, topo, input_dict_1)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Verify Ipv4 and Ipv6 network installed in R1 RIB but not in FIB")
    input_dict_r1 = {
        "r1": {
            "static_routes": [
                {"network": "1.0.2.17/32"},
                {"network": "2001:db8:f::2:17/128"},
            ]
        }
    }

    dut = "r1"
    protocol = "bgp"
    for addr_type in ADDR_TYPES:
        result = verify_fib_routes(
            tgen, addr_type, dut, input_dict_r1, expected=False
        )  # pylint: disable=E1123
        assert result is not True, (
            "Testcase {} : Failed \n".format(tc_name)
            + "Expected behavior: routes should not present in fib \n"
            + "Error: {}".format(result)
        )

    step("Verify Ipv4 and Ipv6 network installed in r3 RIB but not in FIB")
    input_dict_r3 = {
        "r3": {
            "static_routes": [
                {"network": "1.0.4.17/32"},
                {"network": "2001:db8:f::4:17/128"},
            ]
        }
    }
    dut = "r3"
    protocol = "bgp"
    for addr_type in ADDR_TYPES:
        result = verify_fib_routes(
            tgen, addr_type, dut, input_dict_r1, expected=False
        )  # pylint: disable=E1123
        assert result is not True, (
            "Testcase {} : Failed \n".format(tc_name)
            + "Expected behavior: routes should not present in fib \n"
            + "Error: {}".format(result)
        )

    write_test_footer(tc_name)
Exemplo n.º 20
0
def test_bgp_with_loopback_interface(request):
    """
    Test BGP with loopback interface

    Adding keys:value pair  "dest_link": "lo" and "source_link": "lo"
    peer dict of input json file for all router's creating config using
    loopback interface. Once BGP neighboship is up then verifying BGP
    convergence
    """

    tgen = get_topogen()
    if BGP_CONVERGENCE is not True:
        pytest.skip("skipped because of BGP Convergence failure")

    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    for routerN in sorted(topo["routers"].keys()):
        for bgp_neighbor in topo["routers"][routerN]["bgp"]["address_family"]["ipv4"][
            "unicast"
        ]["neighbor"].keys():

            # Adding ['source_link'] = 'lo' key:value pair
            topo["routers"][routerN]["bgp"]["address_family"]["ipv4"]["unicast"][
                "neighbor"
            ][bgp_neighbor]["dest_link"] = {
                "lo": {
                    "source_link": "lo",
                }
            }

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    input_dict = {
        "r1": {
            "static_routes": [
                {"network": "1.0.2.17/32", "next_hop": "10.0.0.2"},
                {"network": "1.0.3.17/32", "next_hop": "10.0.0.6"},
            ]
        },
        "r2": {
            "static_routes": [
                {"network": "1.0.1.17/32", "next_hop": "10.0.0.1"},
                {"network": "1.0.3.17/32", "next_hop": "10.0.0.10"},
            ]
        },
        "r3": {
            "static_routes": [
                {"network": "1.0.1.17/32", "next_hop": "10.0.0.5"},
                {"network": "1.0.2.17/32", "next_hop": "10.0.0.9"},
                {"network": "1.0.4.17/32", "next_hop": "10.0.0.14"},
            ]
        },
        "r4": {"static_routes": [{"network": "1.0.3.17/32", "next_hop": "10.0.0.13"}]},
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    # Api call verify whether BGP is converged
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Exemplo n.º 21
0
def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
    """
    Verify static route are blocked from route-map & prefix-list applied in BGP
    nbrs

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)
    step("Configure holddown timer = 1 keep alive = 3 in all the neighbors")
    step("verify bgp convergence before starting test case")

    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    step(
        "Configure 4 IPv4 and 4 IPv6 nbrs with password with mismatch "
        " authentication between FRR routers "
    )

    for addr_type in ADDR_TYPES:
        # Api call to modfiy BGP timerse
        input_dict = {
            "r2": {
                "bgp": {
                    "local_as": "200",
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2-link0": {"password": "******"},
                                            "r2-link1": {"password": "******"},
                                            "r2-link2": {"password": "******"},
                                            "r2-link3": {"password": "******"},
                                        }
                                    },
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {"password": "******"},
                                            "r2-link1": {"password": "******"},
                                            "r2-link2": {"password": "******"},
                                            "r2-link3": {"password": "******"},
                                        }
                                    },
                                }
                            }
                        }
                    },
                }
            }
        }
        result = create_router_bgp(tgen, topo, deepcopy(input_dict))
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )
        clear_bgp(tgen, addr_type, "r2")

    step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")

    bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False)
    assert bgp_convergence is not True, "Testcase {} : "
    "Failed \n BGP nbrs must be down. Error: {}".format(tc_name, bgp_convergence)

    step(
        "Configure 4 IPv4 and 4 IPv6 nbrs with macthing password  "
        " authentication between FRR routers "
    )
    for addr_type in ADDR_TYPES:
        input_dict = {
            "r2": {
                "bgp": {
                    "local_as": "200",
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2-link0": {"password": "******"},
                                            "r2-link1": {"password": "******"},
                                            "r2-link2": {"password": "******"},
                                            "r2-link3": {"password": "******"},
                                        }
                                    },
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {"password": "******"},
                                            "r2-link1": {"password": "******"},
                                            "r2-link2": {"password": "******"},
                                            "r2-link3": {"password": "******"},
                                        }
                                    },
                                }
                            }
                        }
                    },
                }
            }
        }
        result = create_router_bgp(tgen, topo, deepcopy(input_dict))
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    step("All BGP nbrs are up as authentication is matched now")
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format(
        tc_name, bgp_convergence
    )

    step("Create prefix list P1 to permit VM3 & deny VM1 v4 & v6 routes")
    step("Create prefix list P2 to permit VM6 IPv4 and IPv6 routes")
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "prefix_lists": {
                    addr_type: {
                        "pf_list_1_{}".format(addr_type): [
                            {
                                "seqid": 10,
                                "network": topo["routers"]["r2"]["links"]["vm3"][
                                    addr_type
                                ],
                                "action": "permit",
                            },
                            {
                                "seqid": 20,
                                "network": topo["routers"]["r2"]["links"]["vm1"][
                                    addr_type
                                ],
                                "action": "deny",
                            },
                        ],
                        "pf_list_2_{}".format(addr_type): [
                            {
                                "seqid": 10,
                                "network": topo["routers"]["r2"]["links"]["vm6"][
                                    addr_type
                                ],
                                "action": "permit",
                            }
                        ],
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "Prefix list created with matching networks deny or permit "
            "show ip prefix list"
        )
        result = verify_prefix_lists(tgen, input_dict_2)
        assert result is not True, "Testcase {} : Failed \n"
        " Error: {}".format(tc_name, result)

        step("Redistribute all the routes (connected, static)")
        input_dict_2_r1 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "static"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2_r1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        input_dict_2_r2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "static"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2_r2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        input_dict_2_r3 = {
            "r3": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "static"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2_r3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("configure redistribute connected in Router BGP")

        input_dict_2_r1 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "connected"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2_r1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        input_dict_2_r3 = {
            "r3": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "connected"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2_r3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {"redistribute": [{"redist_type": "connected"}]}
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
        # Configure prefix list to bgp neighbor
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Apply prefix list P2 on BGP nbrs 5 & 6 connected from FRR-2")
        # Configure prefix list to bgp neighbor
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        clear_bgp_and_verify(tgen, topo, "r2")

        step(
            "VM1 IPv4 and IPv6 Route which is denied using prefix list is "
            "not present on FRR1 side routing table , also not able to "
            "ping the routes show ip route"
        )

        dut = "r1"
        protocol = "bgp"
        ntwk_r2_vm1 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
            ).network
        )
        input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
        result4 = verify_rib(
            tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
        )
        assert result4 is not True, "Testcase {} : Failed , VM1 route is "
        "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)

        step(
            "VM4 and VM6 IPV4 and IPv6 address are present in local and "
            "FRR2 routing table show ip bgp show ip route"
        )

        dut = "r2"
        ntwk_r2_vm6 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
            ).network
        )
        input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
        result4 = verify_rib(tgen, addr_type, dut, input_dict)
        assert result4 is True, "Testcase {} : Failed.\n Error: {}".format(
            tc_name, result4
        )

        step("Remove prefix list from all the neighbors")
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_1_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "prefix_lists": [
                                                    {
                                                        "name": "pf_list_2_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                        "delete": True,
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        clear_bgp_and_verify(tgen, topo, "r2")

        step("Create RouteMap_1 with prefix list P1 and weight 50")
        # Create route map
        rmap_dict = {
            "r2": {
                "route_maps": {
                    "rmap_pf_list_1_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "set": {"weight": 50},
                            "match": {
                                addr_type: {
                                    "prefix_lists": "pf_list_1_{}".format(addr_type)
                                }
                            },
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, rmap_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Create RouteMap_2 with prefix list P2 and weight 50")
        # Create route map
        rmap_dict = {
            "r2": {
                "route_maps": {
                    "rmap_pf_list_2_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "set": {"weight": 50},
                            "match": {
                                addr_type: {
                                    "prefix_lists": "pf_list_2_{}".format(addr_type)
                                }
                            },
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, rmap_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Verify Route-map created verify using show route-map")
        # verify rmap_pf_list_1 and rmap_pf_list_2 are present in router r2
        input_dict = {
            "r2": {
                "route_maps": [
                    "rmap_pf_list_1_{}".format(addr_type),
                    "rmap_pf_list_2_{}".format(addr_type),
                ]
            }
        }
        result = verify_route_maps(tgen, input_dict, expected=False)
        assert result is not True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Apply policy RouteMap_1 nbrs 1 2 3 4 to FRR 1")
        # Configure prefix list to bgp neighbor
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_1_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_1_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_1_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_1_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Apply policy RouteMap_2 nbrs 5 and 6 to FRR2")
        # Configure prefix list to bgp neighbor
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_2_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link1": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_2_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_2_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                            "r2-link3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_pf_list_2_"
                                                        "{}".format(addr_type),
                                                        "direction": "out",
                                                    }
                                                ]
                                            },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "After applying to BGP neighbors verify VM1 IPv4 and IPv6 Route"
            " which is denied using prefix list is not present on FRR side"
            " routing table , also not able to ping the routes show ip route"
            " and VM4 and VM6 IPV4 and IPv6 address are present in local and"
            " FRR routing table show ip bgp show ip route"
        )

        dut = "r1"
        protocol = "bgp"
        ntwk_r2_vm1 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
            ).network
        )
        input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
        result4 = verify_rib(
            tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
        )
        assert (
            result4 is not True
        ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
            tc_name, result4
        )

        step("vm4 should be present in FRR1")
        dut = "r1"
        ntwk_r2_vm1 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
            ).network
        )
        input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
        result4 = verify_rib(tgen, addr_type, dut, input_dict)
        assert result4 is True, "Testcase {} : Failed , VM1 route is "
        "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)

        step("vm4 should be present in FRR2")
        dut = "r2"
        ntwk_r2_vm1 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
            ).network
        )
        input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
        result4 = verify_rib(tgen, addr_type, dut, input_dict)
        assert result4 is True, "Testcase {} : Failed , VM1 route is "
        "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)

        dut = "r3"
        protocol = "bgp"
        ntwk_r2_vm6 = str(
            ipaddress.ip_interface(
                u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
            ).network
        )
        input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
        result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result4 is True, "Testcase {} : Failed.\n Error: {}".format(
            tc_name, result4
        )

    write_test_footer(tc_name)
Exemplo n.º 22
0
def setup_module(mod):
    """
    Sets up the pytest environment.

    * `mod`: module name
    """
    global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC
    global ADDR_TYPES

    # Required linux kernel version for this suite to run.
    result = required_linux_kernel_version("4.15")
    if result is not True:
        pytest.skip("Kernel requirements are not met")

    testsuite_run_time = time.asctime(time.localtime(time.time()))
    logger.info("Testsuite start time: {}".format(testsuite_run_time))
    logger.info("=" * 40)

    logger.info("Running setup_module to create topology")

    # This function initiates the topology build with Topogen...
    tgen = Topogen(CreateTopo, mod.__name__)

    # Starting topology, create tmp files which are loaded to routers
    #  to start deamons and then start routers
    start_topology(tgen)

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # tgen.mininet_cli()
    # Api call verify whether BGP is converged
    ADDR_TYPES = check_address_types()

    for addr_type in ADDR_TYPES:
        BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
        assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
            BGP_CONVERGENCE)

    link_data = [
        val for links, val in topo["routers"]["r2"]["links"].items()
        if "r3" in links
    ]
    for adt in ADDR_TYPES:
        NEXT_HOPS[adt] = [val[adt].split("/")[0] for val in link_data]
        if adt == "ipv4":
            NEXT_HOPS[adt] = sorted(NEXT_HOPS[adt],
                                    key=lambda x: int(x.split(".")[2]))
        elif adt == "ipv6":
            NEXT_HOPS[adt] = sorted(NEXT_HOPS[adt],
                                    key=lambda x: int(x.split(":")[-3], 16))

    INTF_LIST_R2 = [val["interface"].split("/")[0] for val in link_data]
    INTF_LIST_R2 = sorted(INTF_LIST_R2, key=lambda x: int(x.split("eth")[1]))

    link_data = [
        val for links, val in topo["routers"]["r3"]["links"].items()
        if "r2" in links
    ]
    INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data]
    INTF_LIST_R3 = sorted(INTF_LIST_R3, key=lambda x: int(x.split("eth")[1]))

    # STATIC_ROUTE = True
    logger.info("Running setup_module() done")
Exemplo n.º 23
0
def test_verify_deleting_re_adding_route_map_with_iBGP_peers_p0(request):
    """
    Verify graceful-shutdown functionality after deleting/re-adding route-map
    with iBGP peers
    """

    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    reset_config_on_routers(tgen)

    step("Done in base config: Configure base config as per the topology")
    step("Base config should be up, verify using BGP convergence")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Done in base config: Advertise prefixes from R1")
    step("Verify BGP routes are received at R4 with best path from R3 to R1")

    for addr_type in ADDR_TYPES:
        dut = "r4"
        next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type,
                                                NEXT_HOP_IP_2)

        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_topo,
                                next_hop=[next_hop1, next_hop2])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_topo,
                            next_hop=[next_hop1, next_hop2])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("On R1 configure:")
    step("Create standard bgp community-list to permit graceful-shutdown:")
    input_dict_1 = {
        "r1": {
            "bgp_community_lists": [{
                "community_type": "standard",
                "action": "permit",
                "name": "GSHUT",
                "value": "graceful-shutdown",
            }]
        }
    }

    result = create_bgp_community_lists(tgen, input_dict_1)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Create route-map to set community GSHUT in OUT direction")

    input_dict_2 = {
        "r1": {
            "route_maps": {
                "GSHUT-OUT": [{
                    "action": "permit",
                    "seq_id": "10",
                    "set": {
                        "community": {
                            "num": "graceful-shutdown"
                        }
                    },
                }]
            }
        }
    }

    result = create_route_maps(tgen, input_dict_2)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    input_dict_3 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r3": {
                                    "dest_link": {
                                        "r1": {
                                            "route_maps": [{
                                                "name": "GSHUT-OUT",
                                                "direction": "out",
                                            }]
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r3": {
                                    "dest_link": {
                                        "r1": {
                                            "route_maps": [{
                                                "name": "GSHUT-OUT",
                                                "direction": "out",
                                            }]
                                        }
                                    }
                                }
                            }
                        }
                    },
                }
            }
        }
    }

    result = create_router_bgp(tgen, topo, input_dict_3)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step(
        "FRR is setting local-pref to 0 by-default on receiver GSHUT community, "
        "below step is not needed, but keeping for reference")
    step("On R3, apply route-map IN direction to match GSHUT community "
         "and set local-preference to 0.")

    step("Verify BGP convergence on R4 and ensure all the neighbours state "
         "is established")

    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify BGP routes on R4:")
    step("local pref for routes coming from R1 is set to 0.")

    for addr_type in ADDR_TYPES:
        rmap_dict = {
            "r1": {
                "route_maps": {
                    "GSHUT-OUT": [{
                        "set": {
                            "locPrf": 0
                        }
                    }],
                }
            }
        }

        static_routes = [NETWORK[addr_type]]
        result = verify_bgp_attributes(tgen, addr_type, dut, static_routes,
                                       "GSHUT-OUT", rmap_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Ensure that best path is selected from R4 to R3.")

    for addr_type in ADDR_TYPES:
        dut = "r4"
        next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type,
                                                NEXT_HOP_IP_2)

        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_topo,
                                next_hop=[next_hop1, next_hop2])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_topo,
                            next_hop=next_hop1)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Delete route-map from R1")
    del_rmap_dict = {
        "r1": {
            "route_maps": {
                "GSHUT-OUT": [{
                    "action": "permit",
                    "seq_id": "10",
                    "set": {
                        "community": {
                            "num": "graceful-shutdown",
                            "delete": True
                        }
                    },
                }]
            }
        }
    }

    result = create_route_maps(tgen, del_rmap_dict)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify BGP convergence on R3 and ensure that all neighbor state "
         "is established")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify BGP routes on R4:")
    step("Ensure that best path is selected from R1->R3")

    for addr_type in ADDR_TYPES:
        dut = "r4"
        next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type,
                                                NEXT_HOP_IP_2)

        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_topo,
                                next_hop=[next_hop1])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_topo,
                            next_hop=[next_hop1])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Re-add route-map in R1")
    result = create_route_maps(tgen, input_dict_2)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify BGP convergence on R3 and ensure all the neighbours state "
         "is established")

    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Test case {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify BGP routes on R4:")
    step("local pref for routes coming from R1 is set to 0.")

    for addr_type in ADDR_TYPES:
        rmap_dict = {
            "r1": {
                "route_maps": {
                    "GSHUT-OUT": [{
                        "set": {
                            "locPrf": 0
                        }
                    }]
                }
            }
        }

        static_routes = [NETWORK[addr_type]]
        result = verify_bgp_attributes(tgen, addr_type, dut, static_routes,
                                       "GSHUT-OUT", rmap_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Ensure that best path is selected from R4 to R3.")

    for addr_type in ADDR_TYPES:
        dut = "r4"
        next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type,
                                                NEXT_HOP_IP_2)

        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_topo,
                                next_hop=[next_hop1, next_hop2])
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_topo,
                            next_hop=next_hop1)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
Exemplo n.º 24
0
def test_ecmp_fast_convergence(request, test_type, tgen, topo):
    """This test is to verify bgp fast-convergence cli functionality"""

    tc_name = request.node.name
    write_test_header(tc_name)

    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"

    reset_config_on_routers(tgen)
    static_or_nw(tgen, topo, tc_name, test_type, "r2")

    for addr_type in ADDR_TYPES:
        input_dict = {
            "r3": {
                "static_routes": [{
                    "network": NETWORK[addr_type]
                }]
            }
        }

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict,
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    intf1 = topo["routers"]["r2"]["links"]["r3-link1"]["interface"]
    intf2 = topo["routers"]["r2"]["links"]["r3-link2"]["interface"]

    logger.info("Shutdown one of the link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, False)

    logger.info("Verify bgp neighbors are still up")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("Shutdown another link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf2, False)

    logger.info("Wait for 10 sec and make sure bgp neighbors are still up")
    sleep(10)
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("No shut links b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, True)
    shutdown_bringup_interface(tgen, "r2", intf2, True)

    logger.info("Ensure that the links are still up")
    result = verify_bgp_convergence(tgen, topo)

    logger.info("Enable bgp fast-convergence cli")
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {}".format(
                    topo["routers"]["r2"]["bgp"]["local_as"]),
                "bgp fast-convergence",
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    logger.info("Ensure BGP has processed the cli")
    r2 = tgen.gears["r2"]
    output = r2.vtysh_cmd("show run")
    verify = re.search(r"fast-convergence", output)
    assert verify is not None, (
        "r2 does not have the fast convergence command yet")

    logger.info("Shutdown one link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, False)

    logger.info("Verify bgp neighbors goes down immediately")
    result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("Shutdown second link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf2, False)

    logger.info("Verify bgp neighbors goes down immediately")
    result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
Exemplo n.º 25
0
def test_BGP_GR_15_p2(request):
    """
    Test Objective : Test GR scenarios by enabling Graceful Restart
    for multiple address families..
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)

    # Check router status
    check_router_status(tgen)

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                }
            }
        },
        "r6": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r6": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r6": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

    configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r6")

    for addr_type in ADDR_TYPES:
        result = verify_graceful_restart(
            tgen, topo, addr_type, input_dict, dut="r1", peer="r6"
        )
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    logger.info(
        "[Step 2] : Test Setup "
        "[Helper Mode]R6-----R1[Restart Mode]"
        "--------R2[Helper Mode] Initilized"
    )

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                }
            }
        },
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r2": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r2": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

    configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")

    for addr_type in ADDR_TYPES:
        result = verify_graceful_restart(
            tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
        )
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    # Kill BGPd daemon on R1
    kill_router_daemons(tgen, "r1", ["bgpd"])

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    # Start BGPd daemon on R1
    start_router_daemons(tgen, "r1", ["bgpd"])

    for addr_type in ADDR_TYPES:
        result = verify_bgp_convergence(tgen, topo)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying BGP RIB routes
        dut = "r6"
        input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_2)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    write_test_footer(tc_name)
Exemplo n.º 26
0
def test_bgp_no_advertise_community_p0(request):
    """
    Verify routes are not advertised when NO-ADVERTISE Community is applied

    """

    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    reset_config_on_routers(tgen)

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    NEXT_HOP_IP = {
        "ipv4": topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0],
        "ipv6": topo["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0],
    }

    # configure static routes
    dut = "r3"
    protocol = "bgp"

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("configure redistribute static and connected in Router BGP " "in R1")

        input_dict_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [
                                    {"redist_type": "static"},
                                    {"redist_type": "connected"},
                                ]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "BGP neighbors are up, static and connected route advertised from"
            " R1 are present on R2 BGP table and RIB using show ip bgp and "
            " show ip route"
        )
        step(
            "Static and connected route advertised from R1 are present on R3"
            " BGP table and RIB using show ip bgp and show ip route"
        )

        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Configure prefix list P1 on R2 to permit route coming from R1")
        # Create ip prefix list
        input_dict_2 = {
            "r2": {
                "prefix_lists": {
                    addr_type: {
                        "pf_list_1_{}".format(addr_type): [
                            {"seqid": 10, "network": "any", "action": "permit"}
                        ]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_pf_1_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "seq_id": "5",
                            "match": {
                                addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
                            },
                            "set": {"community": {"num": "no-advertise"}},
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
        step(
            "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no"
            " advertise community"
        )
        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1_"
                                                        + addr_type,
                                                        "direction": "in",
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "After advertising no advertise community to BGP neighbor "
            "static and connected router got removed from R3 verify using "
            "show ip bgp & show ip route"
        )

        result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        result = verify_rib(
            tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
        )
        assert result is not True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        step("Remove and Add no advertise community")
        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1_"
                                                        + addr_type,
                                                        "direction": "in",
                                                        "delete": True,
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "After removing no advertise community from BGP neighbor "
            "static and connected router got advertised to R3 and "
            "removing route-map, verify route using show ip bgp"
            " and show ip route"
        )

        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

    step("Repeat above steps when IBGP nbr configured between R1, R2 & R2, R3")
    topo1 = deepcopy(topo)

    topo1["routers"]["r1"]["bgp"]["local_as"] = "100"
    topo1["routers"]["r2"]["bgp"]["local_as"] = "100"
    topo1["routers"]["r3"]["bgp"]["local_as"] = "100"

    for rtr in ["r1", "r2", "r3"]:
        if "bgp" in topo1["routers"][rtr].keys():
            delete_bgp = {rtr: {"bgp": {"delete": True}}}
            result = create_router_bgp(tgen, topo1, delete_bgp)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result
            )
            config_bgp = {
                rtr: {"bgp": {"local_as": topo1["routers"][rtr]["bgp"]["local_as"]}}
            }
            result = create_router_bgp(tgen, topo1, config_bgp)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result
            )

    build_config_from_json(tgen, topo1, save_bkup=False)

    step("verify bgp convergence before starting test case")

    bgp_convergence = verify_bgp_convergence(tgen, topo1)
    assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    # configure static routes
    dut = "r3"
    protocol = "bgp"

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("configure redistribute static and connected in Router " "BGP in R1")

        input_dict_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [
                                    {"redist_type": "static"},
                                    {"redist_type": "connected"},
                                ]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "BGP neighbors are up, static and connected route advertised from"
            " R1 are present on R2 BGP table and RIB using show ip bgp and "
            " show ip route"
        )
        step(
            "Static and connected route advertised from R1 are present on R3"
            " BGP table and RIB using show ip bgp and show ip route"
        )

        dut = "r2"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("Configure prefix list P1 on R2 to permit route coming from R1")
        # Create ip prefix list
        input_dict_2 = {
            "r2": {
                "prefix_lists": {
                    addr_type: {
                        "pf_list_1_{}".format(addr_type): [
                            {"seqid": 10, "network": "any", "action": "permit"}
                        ]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_pf_1_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "seq_id": "5",
                            "match": {
                                addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
                            },
                            "set": {"community": {"num": "no-advertise"}},
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
        step(
            "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no"
            " advertise community"
        )

        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1_"
                                                        + addr_type,
                                                        "direction": "in",
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "After advertising no advertise community to BGP neighbor "
            "static and connected router got removed from R3 verify using "
            "show ip bgp & show ip route"
        )

        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        step("Remove and Add no advertise community")
        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r2": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1_"
                                                        + addr_type,
                                                        "direction": "in",
                                                        "delete": True,
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step(
            "After removing no advertise community from BGP neighbor "
            "static and connected router got advertised to R3 and "
            "removing route verify using show ip bgp and "
            " show ip route"
        )

        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

        result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n "
        " Routes still present in R3 router. Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Exemplo n.º 27
0
def test_bgp_vrf_tcp_mss(request):
    tgen = get_topogen()
    tc_name = request.node.name
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    step("Verify the router failures")
    if tgen.routers_have_failure():
        check_router_status(tgen)

    step("Configuring 5 static Routes in Router R3 with NULL0 as Next hop")
    for addr_type in ADDR_TYPES:
        static_routes_input = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                ]
            }
        }
        result = create_static_routes(tgen, static_routes_input)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Verify the static Routes in R3 on default VRF")
    for addr_type in ADDR_TYPES:
        static_routes_input = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                ]
            }
        }
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

    step("Verify the static Routes in R2 on default VRF")
    for addr_type in ADDR_TYPES:
        static_routes_input = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                    {
                        "network":
                        [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                    },
                ]
            }
        }
        dut = "r2"
        result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

    step("importing  default vrf  on R2 under VRF RED Address Family")
    for addr_type in ADDR_TYPES:
        input_import_vrf = {
            "r2": {
                "bgp": [{
                    "local_as": 200,
                    "vrf": "RED",
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "import": {
                                    "vrf": "default"
                                }
                            }
                        }
                    },
                }]
            }
        }
        result = create_router_bgp(tgen, topo, input_import_vrf)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Verify the static Routes in R2 on RED VRF")
    for addr_type in ADDR_TYPES:
        static_routes_input = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                ]
            }
        }
        dut = "r2"
        result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

    step("Verify the static Routes in R1 on RED VRF")
    for addr_type in ADDR_TYPES:
        static_routes_input = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                    {
                        "network":
                        [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]],
                        "next_hop":
                        NEXT_HOP_IP[addr_type],
                        "vrf":
                        "RED",
                    },
                ]
            }
        }
        dut = "r1"
        result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

    step("Enabling tcp-mss 150 on Router R1 in VRF RED")
    TCP_MSS = 150
    raw_config = {
        "r1": {
            "raw_config": [
                "router bgp {} vrf {}".format(
                    topo["routers"]["r1"]["bgp"][0]["local_as"],
                    topo["routers"]["r1"]["bgp"][0]["vrf"],
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r1-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r1-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        },
    }

    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Clearing BGP on R1 and R2 ")
    for addr_type in ADDR_TYPES:
        clear_bgp(tgen,
                  addr_type,
                  "r1",
                  vrf=topo["routers"]["r1"]["bgp"][0]["vrf"])
        clear_bgp(tgen,
                  addr_type,
                  "r2",
                  vrf=topo["routers"]["r2"]["bgp"][1]["vrf"])

    step("Verify the BGP Convergence at R1 & R2 after Clear BGP")
    r1_convergence = verify_bgp_convergence(tgen, topo, dut="r1")
    assert (r1_convergence is True
            ), "BGP convergence after Clear BGP :Failed \n Error: {}".format(
                r1_convergence)
    r2_convergence = verify_bgp_convergence(tgen, topo, dut="r2")
    assert (r2_convergence is True
            ), "BGP convergence after Clear BGP :Failed \n Error: {}".format(
                r2_convergence)

    step("Verify the TCP-MSS  value on both Router R1 and R2")
    for addr_type in ADDR_TYPES:
        dut = "r1"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")
            [0],
            TCP_MSS,
            "RED",
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)

    step("Enabling tcp-mss 500 between R2 and R3 of VRF Default")
    TCP_MSS = 500
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r2"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        },
        "r3": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r3"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        },
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Clear BGP at router R2 and R3")
    for addr_type in ADDR_TYPES:
        clear_bgp(tgen, topo, "r2", addr_type)
        clear_bgp(tgen, topo, "r3", addr_type)

    step("Verify the BGP Convergence at R2 & R3 after Clear BGP")
    r1_convergence = verify_bgp_convergence(tgen, topo, dut="r2")
    assert (r1_convergence is True
            ), "BGP convergence after Clear BGP :Failed \n Error: {}".format(
                r2_convergence)
    r2_convergence = verify_bgp_convergence(tgen, topo, dut="r3")
    assert (r2_convergence is True
            ), "BGP convergence after Clear BGP :Failed \n Error: {}".format(
                r2_convergence)

    step("Verify the TCP-MSS value on both Router R2 and R3")
    for addr_type in ADDR_TYPES:
        dut = "r2"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)

        dut = "r3"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)

    step("Removing tcp-mss 150 between R1 and R2 of VRF RED ")
    TCP_MSS = 150
    raw_config = {
        "r1": {
            "raw_config": [
                "router bgp {} vrf {}".format(
                    topo["routers"]["r1"]["bgp"][0]["local_as"],
                    topo["routers"]["r1"]["bgp"][0]["vrf"],
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r1-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r1-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {} vrf {}".format(
                    topo["routers"]["r2"]["bgp"][0]["local_as"],
                    topo["routers"]["r2"]["bgp"][1]["vrf"],
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Verify the TCP-MSS  value cleared on both Router R1 and R2")
    for addr_type in ADDR_TYPES:
        dut = "r1"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")
            [0],
            TCP_MSS,
            "RED",
        )
        assert (tcp_mss_result
                is not True), " TCP-MSS mismatch :Failed \n Error: {}".format(
                    tcp_mss_result)

        dut = "r2"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
            "RED",
        )
        assert (tcp_mss_result
                is not True), " TCP-MSS mismatch :Failed \n Error: {}".format(
                    tcp_mss_result)

    step("Removing tcp-mss 500 between R2 and R3 of VRF Default ")
    TCP_MSS = 500
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r2"]["bgp"][0]["local_as"]),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    raw_config = {
        "r3": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r3"]["bgp"][0]["local_as"]),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "no neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Verify the TCP-MSS value got cleared on both Router R2 and R3")
    for addr_type in ADDR_TYPES:
        dut = "r2"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert (tcp_mss_result
                is not True), " TCP-MSS mismatch :Failed \n Error: {}".format(
                    tcp_mss_result)

        dut = "r3"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert (tcp_mss_result
                is not True), " TCP-MSS mismatch :Failed \n Error: {}".format(
                    tcp_mss_result)

    step("Configuring different TCP-MSS  R2 and R3 ")
    TCP_MSS = 500
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {}".format(
                    topo["routers"]["r2"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)
    TCP_MSS = 300
    raw_config = {
        "r3": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r3"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Verify the TCP-MSS value on both Router R2 and R3")
    for addr_type in ADDR_TYPES:
        TCP_MSS = 500
        dut = "r2"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)

        TCP_MSS = 300
        dut = "r3"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)

    step("Configure TCP_MSS > MTU on R2 and R3 and it should be 1460 ")
    TCP_MSS = 4096
    REF_TCP_MSS = 1460
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r2"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r3"]["links"]["r2-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)
    raw_config = {
        "r3": {
            "raw_config": [
                "router bgp {} ".format(
                    topo["routers"]["r3"]["bgp"][0]["local_as"]),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split(
                        "/")[0],
                    TCP_MSS,
                ),
                "neighbor {} tcp-mss {}".format(
                    topo["routers"]["r2"]["links"]["r3-link1"]["ipv6"].split(
                        "/")[0],
                    TCP_MSS,
                ),
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    step("Restarting  BGP Daemon on R3")

    kill_router_daemons(tgen, "r3", ["bgpd"])
    start_router_daemons(tgen, "r3", ["bgpd"])

    step(
        "Verify the configured  TCP-MSS 4096 value on restarting both Daemon both Router R2 and R3 "
    )
    for addr_type in ADDR_TYPES:
        TCP_MSS = 4096
        dut = "r2"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r3"]["links"]["r2-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)
        dut = "r3"
        tcp_mss_result = verify_tcp_mss(
            tgen,
            dut,
            topo["routers"]["r2"]["links"]["r3-link1"]["ipv4"].split("/")[0],
            TCP_MSS,
        )
        assert tcp_mss_result is True, " TCP-MSS mismatch :Failed \n Error: {}".format(
            tcp_mss_result)
    write_test_footer(tc_name)
Exemplo n.º 28
0
def test_ospf_redistribution_tc8_p1(request):
    """
    Test OSPF redistribution of connected routes.

    Verify OSPF redistribution of connected routes when bgp multi hop
    neighbor is configured using ospf routes

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config.")
    step("Configure loopback interface on all routers, and redistribut"
         "e connected routes into ospf")
    reset_config_on_routers(tgen)

    step("verify that connected routes -loopback is found in all routers"
         "advertised/exchaged via ospf")
    for rtr in topo["routers"]:
        redistribute_ospf(tgen, topo, rtr, "static")
        redistribute_ospf(tgen, topo, rtr, "connected")
    for node in topo["routers"]:
        input_dict = {
            "r0": {
                "static_routes": [{
                    "network":
                    topo["routers"][node]["links"]["lo"]["ipv4"],
                    "no_of_ip":
                    1,
                }]
            }
        }
        for rtr in topo["routers"]:
            result = verify_rib(tgen, "ipv4", rtr, input_dict)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)

    step("Configure E BGP multi hop using the loopback addresses.")
    as_num = 100
    for node in topo["routers"]:
        as_num += 1
        topo["routers"][node].update({
            "bgp": {
                "local_as": as_num,
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {}
                        }
                    }
                },
            }
        })
    for node in topo["routers"]:
        for rtr in topo["routers"]:
            if node is not rtr:
                topo["routers"][node]["bgp"]["address_family"]["ipv4"][
                    "unicast"]["neighbor"].update({
                        rtr: {
                            "dest_link": {
                                "lo": {
                                    "source_link": "lo",
                                    "ebgp_multihop": 2
                                }
                            }
                        }
                    })

    result = create_router_bgp(tgen, topo, topo["routers"])
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that BGP neighbor is ESTABLISHED")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)
    step("Configure couple of static routes in R0 and "
         "Redistribute static routes in R1 bgp.")

    for rtr in topo["routers"]:
        redistribute_ospf(tgen, topo, rtr, "static", delete=True)

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    configure_bgp_on_r0 = {
        "r0": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }]
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    protocol = "bgp"
    for rtr in ["r1", "r2", "r3"]:
        result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Clear ospf neighbours in R0")
    for rtr in topo["routers"]:
        clear_ospf(tgen, rtr)

    step("Verify that OSPF neighbours are reset and forms new adjacencies.")
    # Api call verify whether OSPF is converged
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Verify that BGP neighbours are reset and forms new adjacencies.")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    protocol = "bgp"
    for rtr in ["r1", "r2", "r3"]:
        result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
def test_ext_nh_cap_red_static_network_ebgp_peer_unnumbered_nbr_p1(request):
    """

    Test extended capability nexthop.

    Verify IPv4 routes advertise using "redistribute static" and
    "network command" are received on EBGP peer with IPv6 nexthop
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)
    step("Configure IPv6 IBGP Unnumbered session between R1 and R2 and enable "
         "ipv6 nd ra-interval 10 in the interface")

    step("Enable capability extended-nexthop"
         "on the neighbor from both the routers and "
         "ipv6 nd ra-interval 10 on link connected between R1 and R2")

    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase :Failed \n Error:" " {}".format(
        bgp_convergence)

    for rte in range(0, NO_OF_RTES):
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [{
                    "network": NETWORK["ipv4"][rte],
                    "no_of_ip": 1,
                    "next_hop": NEXT_HOP["ipv4"][rte],
                }]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
    step("Advertise static routes from IPv4 unicast family and IPv6 unicast "
         "family respectively from R1 "
         "Configure loopback on R1 with IPv4 address Advertise loopback "
         "from IPv4 unicast family using network cmd from R1 ")

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }],
                            "advertise_networks": [{
                                "network": NETWORK_CMD_IP,
                                "no_of_network": 1
                            }],
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    llip = get_llip("r1", "r2-link0")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    step(
        " IPv4 and IPv6 routes advertised using static and network command are"
        " received on R2 BGP and routing table , verify using show ip bgp"
        " show ip route for IPv4 routes and show bgp show ipv6 routes"
        " for IPv6 routes .")

    dut = "r2"
    protocol = "bgp"
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": NO_OF_RTES,
                "next_hop": llip,
            }]
        }
    }
    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        verify_nh_for_static_rtes,
                        next_hop=llip,
                        protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    verify_nh_for_nw_cmd_rtes = {
        "r1": {
            "static_routes": [{
                "network": NETWORK_CMD_IP,
                "no_of_ip": 1,
                "next_hop": llip,
            }]
        }
    }

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        verify_nh_for_nw_cmd_rtes,
                        next_hop=llip,
                        protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)