Пример #1
0
def test_gr_rt1():
    logger.info("Test: verify rt1 performing a graceful restart")
    tgen = get_topogen()

    # Skip if previous fatal error condition is raised
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    tgen.net["rt1"].cmd('vtysh -c "graceful-restart prepare ipv6 ospf"')
    expect_grace_lsa(restarting="1.1.1.1", helper="rt2")
    ensure_gr_is_in_zebra("rt1")
    kill_router_daemons(tgen, "rt1", ["ospf6d"], save_config=False)
    check_routers(exiting="rt1")
    start_router_daemons(tgen, "rt1", ["ospf6d"])
    check_routers(restarting="rt1")
Пример #2
0
def test_gr_rt7():
    logger.info("Test: verify rt7 performing a graceful restart")
    tgen = get_topogen()

    # Skip if previous fatal error condition is raised
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    tgen.net["rt7"].cmd('vtysh -c "graceful-restart prepare ip ospf"')
    sleep(3)
    kill_router_daemons(tgen, "rt7", ["ospfd"], save_config=False)
    check_routers(exiting="rt7")

    start_router_daemons(tgen, "rt7", ["ospfd"])
    check_routers(restarting="rt7")
Пример #3
0
def test_verify_restarting_zebra_bgpd_staticd_frr_with_eBGP_peers_p0(request):
    """
    Verify graceful-shutdown functionality when daemons bgpd/zebra/staticd and
    frr services are restarted with eBGP 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 R3 with best path from R3 to R1")

    for addr_type in ADDR_TYPES:
        dut = "r3"
        next_hop1 = next_hop_per_address_family(tgen, "r3", "r1", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r3", "r4", 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("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 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 R3:")
    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 = "r3"
        next_hop1 = next_hop_per_address_family(tgen, "r3", "r1", addr_type,
                                                NEXT_HOP_IP_1)
        next_hop2 = next_hop_per_address_family(tgen, "r3", "r4", 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_hop2)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Restart daemons and frr services")

    for daemon in ["bgpd", "zebra", "staticd", "frr"]:
        if daemon != "frr":
            kill_router_daemons(tgen, "r3", ["staticd"])
            start_router_daemons(tgen, "r3", ["staticd"])
        else:
            stop_router(tgen, "r3")
            start_router(tgen, "r3")

        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 R3:")
        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 = "r3"
            next_hop1 = next_hop_per_address_family(tgen, "r3", "r1",
                                                    addr_type, NEXT_HOP_IP_1)
            next_hop2 = next_hop_per_address_family(tgen, "r3", "r4",
                                                    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_hop2)
            assert result is True, "Test case {} : Failed \n Error: {}".format(
                tc_name, result)

    write_test_footer(tc_name)
Пример #4
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)
def test_BGP_GR_chaos_33_p1(request):
    """
    Test Objective : Helper router receives same prefixes from two
    different routers (GR-restarting and GR-disabled). Keeps the
    stale entry only for GR-restarting node(next-hop is correct).
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_33 "
        "BGP GR "
        "[Restart Mode]R1--R3[Helper Mode]--R4[Disabled Mode]"
    )

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

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

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

    logger.info("[Step 2] : Advertise same networks from R1 and R4..")

    # Api call to delete advertised networks
    input_dict_2 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "advertise_networks": [
                                {
                                    "network": "200.0.20.1/32",
                                    "no_of_network": 2,
                                }
                            ]
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "advertise_networks": [
                                {"network": "2001::1/128", "no_of_network": 2}
                            ]
                        }
                    },
                }
            }
        },
        "r4": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "advertise_networks": [
                                {"network": "200.0.20.1/32", "no_of_network": 2}
                            ]
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "advertise_networks": [
                                {"network": "2001::1/128", "no_of_network": 2}
                            ]
                        }
                    },
                }
            }
        },
    }

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

    for addr_type in ADDR_TYPES:
        # Verifying RIB routes
        dut = "r3"
        peer1 = "r1"
        peer2 = "r4"
        intf1 = topo["routers"][peer1]["links"][dut]["interface"]
        intf2 = topo["routers"][peer2]["links"][dut]["interface"]

        if addr_type == "ipv4":
            next_hop_4 = NEXT_HOP_4
            result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_4)
            assert result is True, "Testcase {} : Failed \n Error {}".format(
                tc_name, result
            )

        if addr_type == "ipv6":
            if "link_local" in PREFERRED_NEXT_HOP:
                next_hop1 = get_frr_ipv6_linklocal(tgen, peer1, intf=intf1)
                next_hop2 = get_frr_ipv6_linklocal(tgen, peer2, intf=intf2)

                next_hop_6 = [next_hop1, next_hop2]
            else:
                next_hop_6 = NEXT_HOP_6

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

    logger.info("[Step 3] : Kill BGPd daemon on R1 and R4..")

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

    # Kill BGPd daemon on R4
    kill_router_daemons(tgen, "r4", ["bgpd"])

    for addr_type in ADDR_TYPES:
        # Verifying RIB routes
        next_hop_6 = ["fd00:0:0:1::1"]
        if addr_type == "ipv4":
            next_hop_4 = NEXT_HOP_4[0]

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

        if addr_type == "ipv6":
            if "link_local" in PREFERRED_NEXT_HOP:
                next_hop_6 = get_frr_ipv6_linklocal(tgen, peer1, intf=intf1)
            else:
                next_hop_6 = NEXT_HOP_6[0]

            result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_6)

        # Verifying RIB routes
        if addr_type == "ipv4":
            next_hop_4 = NEXT_HOP_4[1]
            result = verify_rib(
                tgen, addr_type, dut, input_dict_2, next_hop_4, expected=False
            )
            assert result is not True, (
                "Testcase {} : Failed \n "
                "r3: routes are still present in BGP RIB\n Error: {}".format(
                    tc_name, result
                )
            )
            logger.info(" Expected behavior: {}".format(result))

        if addr_type == "ipv6":
            if "link_local" in PREFERRED_NEXT_HOP:
                next_hop_6 = get_frr_ipv6_linklocal(tgen, peer2, intf=intf2)
            else:
                next_hop_6 = NEXT_HOP_6[1]

            result = verify_rib(
                tgen, addr_type, dut, input_dict_2, next_hop_6, expected=False
            )
            assert result is not True, (
                "Testcase {} : Failed \n "
                "r3: routes are still present in ZEBRA\n Error: {}".format(
                    tc_name, result
                )
            )
            logger.info(" Expected behavior: {}".format(result))

    logger.info("[Step 4] : Start BGPd daemon on R1 and R4..")

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

    # Start BGPd daemon on R4
    start_router_daemons(tgen, "r4", ["bgpd"])

    write_test_footer(tc_name)
def test_BGP_GR_TC_1_2_p0(request):
    """
    Verify that EOR message is sent out only after initial convergence
    Verify whether EOR message is received from all the peers after restart
    """

    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)

    logger.info(
        "Verify EOR Sent and Received : BGP_GR_TC_1_2 >> "
        "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
    )

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

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

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

        # Verifying BGP RIB routes received from router R3
        dut = "r1"
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("R1 goes for reload")
    kill_router_daemons(tgen, "r1", ["bgpd"])

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

    logger.info("Starting bgpd process")
    start_router_daemons(tgen, "r1", ["bgpd"])
    logger.info("R1 is UP Now")

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

        # Verifying BGP RIB routes received from router R3
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # Verifying EOR on restarting router
        result = verify_eor(tgen, topo, addr_type, input_dict, dut="r3", peer="r1")
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Пример #7
0
def test_BGP_GR_chaos_34_1_p1(request):
    """
    Test Objective : Restarting node doesn't preserve forwarding
    state, helper router should not keep the stale entries.
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_31 "
        "BGP GR "
        "[Restart Mode]R1---R3[Helper Mode]"
    )

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {
                    "preserve-fw-state": True,
                    "timer": {"restart-time": GR_RESTART_TIMER},
                },
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                },
            }
        },
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

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

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

        # Verifying BGP RIB routes after starting BGPd daemon
        dut = "r3"
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info(
        "[Step 1] : Remove the preserve-fw-state command"
        " from restarting node R1's config"
    )

    # Configure graceful-restart to set f-bit as False
    input_dict_2 = {"r1": {"bgp": {"graceful-restart": {"preserve-fw-state": False}}}}

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

    logger.info("[Step 2] : Reset the session between R1 and R3..")

    # Reset sessions
    for addr_type in ADDR_TYPES:
        clear_bgp(tgen, addr_type, "r1")

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

    for addr_type in ADDR_TYPES:
        # Verify f-bit after starting BGPd daemon
        result = verify_f_bit(
            tgen, topo, addr_type, input_dict_2, "r3", "r1", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r3: F-bit is set to True\n Error: {}".format(
            tc_name, result
        )
        logger.info(" Expected behavior: {}".format(result))

    logger.info("[Step 3] : Kill BGPd daemon on R1..")

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

    # Waiting for GR_RESTART_TIMER
    logger.info("Waiting for {} sec..".format(GR_RESTART_TIMER))
    sleep(GR_RESTART_TIMER)

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes
        input_dict = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes
        result = verify_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

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

    write_test_footer(tc_name)
def test_BGP_GR_chaos_28_p1(request):
    """
    Test Objective : Verify if helper node goes down before restarting
    node comes up online, helper node sets the R-bit to avoid dead-lock
    till SDT expiry.
    """

    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)

    logger.info(
        "Test Case: test_BGP_GR_chaos_28 :"
        "[Helper Mode]R3-----R1[Restart Mode] initialized"
    )

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

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

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

    logger.info("[Step 1] : Kill BGPd daemon on R1..")

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

    logger.info("[Step 2] : Kill BGPd daemon on R3..")

    # Kill BGPd daemon on R3
    kill_router_daemons(tgen, "r3", ["bgpd"])

    logger.info("[Step 3] : Start BGPd daemon on R1..")

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

    logger.info("[Step 4] : Start BGPd daemon on R3..")

    # Start BGPd daemon on R3
    start_router_daemons(tgen, "r3", ["bgpd"])

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

    write_test_footer(tc_name)
def test_BGP_GR_TC_8_p1(request):
    """
    Test Objective : Verify that restarting nodes set "F" bit while sending
     the BGP open messages after it restarts, only when BGP GR is enabled.
    """

    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)

    logger.info("[Phase 1] : Test Setup"
                " [Restart Mode]R1-----R2[Restart Mode] initialized  ")

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {
                    "preserve-fw-state": True
                },
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1-link1": {
                                            "graceful-restart": True
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1-link1": {
                                            "graceful-restart": True
                                        }
                                    }
                                }
                            }
                        }
                    },
                },
            }
        },
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r2-link1": {
                                            "graceful-restart": True
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r2-link1": {
                                            "graceful-restart": 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 = "r1"
        peer = "r2"
        next_hop = next_hop_per_address_family(tgen, dut, peer, addr_type,
                                               NEXT_HOP_IP_2)
        input_topo = {key: topo["routers"][key] for key in ["r2"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

        # Verifying RIB routes
        protocol = "bgp"
        result = verify_rib(tgen, addr_type, dut, input_topo, next_hop,
                            protocol)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    logger.info("[Phase 2] : R1 goes for reload  ")

    kill_router_daemons(tgen, "r1", ["bgpd"])

    logger.info("[Phase 3] : R1 is about to come up now  ")
    start_router_daemons(tgen, "r1", ["bgpd"])

    logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats  ")

    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)

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

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

    write_test_footer(tc_name)
Пример #10
0
def BGP_GR_TC_7_p1(request):
    """
    Verify that BGP restarting node deletes all the routes received from peer
    if BGP Graceful capability is not present in BGP Open message from the
    peer
    """

    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)

    logger.info(
        " Verify route download to RIB: BGP_GR_TC_7 >> "
        "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
    )

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

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

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

        # Verifying BGP RIB routes received from router R1
        dut = "r1"
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    logger.info("R1 goes for reload")
    kill_router_daemons(tgen, "r1", ["bgpd"])

    # Change the configuration on router R1
    input_dict_2 = {
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-disable": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-disable": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        }
    }

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

    # Change the configuration on R1
    network = {"ipv4": "103.0.20.1/32", "ipv6": "3::1/128"}
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r3": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [
                                    {
                                        "network": network[addr_type],
                                        "no_of_network": 5,
                                        "delete": True,
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

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

    logger.info("R1 is about to come up now")
    start_router_daemons(tgen, "r1", ["bgpd"])
    logger.info("R1 is UP Now")

    # Wait for RIB stale timeout
    logger.info("Verify routes are not present" "in restart router")

    for addr_type in ADDR_TYPES:
        # Verifying RIB routes
        dut = "r1"
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r1: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )

    write_test_footer(tc_name)
def BGP_GR_16_p2(request):
    """
    Test Objective : Verify BGP-GR feature when restarting node
    is a transit router for it's iBGP peers.
    """

    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)

    logger.info(
        "[Step 1] : Test Setup " "[Helper Mode]R3-----R1[Restart Mode] initialized"
    )

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

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

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

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

    # Configure graceful-restart and timers
    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 = "r3"
        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
        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
        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
        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:
        # Verifying BGP RIB routes
        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
        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
        )

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

    write_test_footer(tc_name)
def test_BGP_GR_TC_11_p0(request):
    """
    Verify that selection-deferral timer sets the maximum time to
    avoid deadlock during which the best-path
    selection process is deferred, after a peer session was restarted
    """

    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)

    logger.info("Verify EOR Sent after deferral timeout : BGP_GR_TC_11")

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {
                    "graceful-restart": True,
                    "select-defer-time": GR_SELECT_DEFER_TIMER,
                },
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r2": {"dest_link": {"r1": {"graceful-restart": True}}},
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}},
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {"dest_link": {"r1": {"graceful-restart": True}}},
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}},
                            }
                        }
                    },
                },
            }
        },
        "r3": {
            "bgp": {
                "graceful-restart": {"disable-eor": True},
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                },
            }
        },
    }

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

    for addr_type in ADDR_TYPES:
        clear_bgp(tgen, addr_type, "r1")
        clear_bgp(tgen, addr_type, "r3")

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

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

        # Verifying BGP RIB routes received from router R1
        dut = "r1"
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("R1 goes for reload")
    kill_router_daemons(tgen, "r1", ["bgpd"])

    logger.info("Starting bgpd process")
    start_router_daemons(tgen, "r1", ["bgpd"])
    logger.info("R1 is UP Now")

    for addr_type in ADDR_TYPES:
        # Verify EOR on restarting router
        result = verify_eor(
            tgen, topo, addr_type, input_dict, dut="r1", peer="r3", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r1: EOR is set to True\n Error: {}".format(
            tc_name, result
        )

    logger.info(
        "Waiting for selection deferral timer({} sec).. ".format(
            GR_SELECT_DEFER_TIMER + 2
        )
    )
    sleep(GR_SELECT_DEFER_TIMER + 2)

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes received from router R1
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # Verifying EOR on restarting router
        result = verify_eor(
            tgen, topo, addr_type, input_dict, dut="r3", peer="r1", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r3: EOR is set to True\n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_BGP_GR_TC_3_p0(request):
    """
    Verify the selection deferral timer functionality when EOR is not sent
    by the helper router
    """

    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)

    logger.info(
        " Verify route download to RIB: BGP_GR_TC_3 >> "
        "BGP GR [Helper Mode]R1-----R2[Restart Mode] "
    )

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {
                    "disable-eor": True,
                },
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                },
            }
        },
        "r2": {
            "bgp": {
                "graceful-restart": {
                    "graceful-restart": True,
                    "preserve-fw-state": True,
                    "timer": {"select-defer-time": GR_SELECT_DEFER_TIMER},
                },
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {"dest_link": {"r2": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {"dest_link": {"r2": {"graceful-restart": 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 received from router R1
        dut = "r2"
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("R2 goes for reload ")
    kill_router_daemons(tgen, "r2", ["bgpd"])

    logger.info("R2 is about to come up now")
    start_router_daemons(tgen, "r2", ["bgpd"])
    logger.info("R2 is UP Now")

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes received from router R1
        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
        )

    # Verify EOR on restarting router
    result = verify_eor(
        tgen, topo, addr_type, input_dict, dut="r2", peer="r1", expected=False
    )
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r2: EOR is set to True\n Error: {}".format(
        tc_name, result
    )

    logger.info(
        "Waiting for selection deferral timer({} sec)..".format(GR_SELECT_DEFER_TIMER)
    )
    sleep(GR_SELECT_DEFER_TIMER)

    for addr_type in ADDR_TYPES:
        # Verifying RIB routes
        result = verify_rib(tgen, addr_type, "r2", input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_BGP_GR_chaos_34_2_p1(request):
    """
    Test Objective : Restarting node doesn't preserve the forwarding
    state verify the behaviour on helper node, if it still keeps the
    stale routes.
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_34 "
        "BGP GR "
        "[Restart Mode]R1---R3[Helper Mode]"
    )

    logger.info("[Step 1] : Configure restarting" "  router R1 to prevent ")
    logger.info("[Step 2] : Reset the session" " between R1 and R3..")

    # Configure graceful-restart
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {"preserve-fw-state": True, "disable-eor": True},
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                },
            }
        },
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

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

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

        # Verify f-bit before killing BGPd daemon
        result = verify_f_bit(tgen, topo, addr_type, input_dict, "r3", "r1")
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # Verifying BGP RIB routes after starting BGPd daemon
        dut = "r3"
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("[Step 3] : Kill BGPd daemon on R1..")

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

    logger.info("[Step 4] : Withdraw/delete the prefixes " "originated from R1..")

    # Api call to delete advertised networks
    network = {"ipv4": "101.0.20.1/32", "ipv6": "1::1/128"}
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [
                                    {
                                        "network": network[addr_type],
                                        "no_of_network": 5,
                                        "delete": True,
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

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

    logger.info("[Step 5] : Remove the CLI from R1's config to " "set the F-bit..")

    # Modify graceful-restart config not to set f-bit
    # and write to /etc/frr
    input_dict_2 = {"r1": {"bgp": {"graceful-restart": {"preserve-fw-state": False}}}}

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

    logger.info("[Step 6] : Bring up the BGPd daemon on R1 again..")

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

    for addr_type in ADDR_TYPES:
        # Verify f-bit after starting BGPd daemon
        result = verify_f_bit(
            tgen, topo, addr_type, input_dict, "r3", "r1", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r3: F-bit is set to True\n Error: {}".format(
            tc_name, result
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying BGP RIB routes after starting BGPd daemon
        input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes
        result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

    write_test_footer(tc_name)
Пример #15
0
def test_BGP_GR_chaos_32_p1(request):
    """
    Test Objective : Restarting node is connected to multiple helper
    nodes, one of them doesn't send EOR to restarting router. Verify
    that only after SDT restarting node send EOR to all helper peers
    excluding the prefixes originated by faulty router.
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_32 "
        "BGP GR "
        "[Restart Mode]R1---R3&R5[Helper Mode]"
    )

    logger.info(
        "[Step 1] : Change the mode on R1 be a restarting" " node on global level"
    )

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

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

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

        # Verifying BGP RIB routes after starting BGPd daemon
        dut = "r3"
        input_dict_1 = {key: topo["routers"][key] for key in ["r5"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("[Step 2] : Kill BGPd daemon on R1..")
    # Kill BGPd daemon on R1
    kill_router_daemons(tgen, "r1", ["bgpd"])

    logger.info("[Step 3] : Withdraw all the advertised prefixes from R5")

    # Api call to delete advertised networks
    network = {"ipv4": "105.0.20.1/32", "ipv6": "5::1/128"}
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r5": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [
                                    {
                                        "network": network[addr_type],
                                        "no_of_network": 5,
                                        "delete": True,
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

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

    logger.info(
        "[Step 4] : Stop the helper router R5 from sending EOR" " message using CLI"
    )

    # Modify graceful-restart config to prevent sending EOR
    input_dict_3 = {"r5": {"bgp": {"graceful-restart": {"disable-eor": True}}}}

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

    logger.info("[Step 5] : Bring up the BGPd daemon on R1..")

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

    for addr_type in ADDR_TYPES:
        # Verify EOR is disabled
        result = verify_eor(
            tgen, topo, addr_type, input_dict_3, dut="r5", peer="r1", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r5: EOR is set to TRUE\n Error: {}".format(
            tc_name, result
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying BGP RIB routes after starting BGPd daemon
        input_dict_1 = {key: topo["routers"][key] for key in ["r5"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes
        result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

    write_test_footer(tc_name)
def test_BGP_GR_26_p2(request):
    """
    Test Objective : Test GR scenarios on helper router 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)

    logger.info(
        "[Step 1] : Test Setup " "[Helper Mode]R3-----R1[Restart Mode] initialized"
    )

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

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

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

        # Verifying BGP RIB routes
        dut = "r3"
        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
        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_topo)
        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
        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
        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_topo)
        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:
        # Verifying BGP RIB routes
        input_topo = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
        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_topo)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # verify multi address family
        result = verify_gr_address_family(
            tgen,
            topo,
            addr_type,
            "ipv4Unicast",
            dut="r1",
            peer="r3",
        )
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # verify multi address family
        result = verify_gr_address_family(
            tgen,
            topo,
            addr_type,
            "ipv6Unicast",
            dut="r1",
            peer="r3",
        )
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # verify multi address family
        result = verify_gr_address_family(
            tgen,
            topo,
            addr_type,
            "ipv4Unicast",
            dut="r3",
            peer="r1",
        )
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

        # verify multi address family
        result = verify_gr_address_family(
            tgen,
            topo,
            addr_type,
            "ipv6Unicast",
            dut="r3",
            peer="r1",
        )
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Пример #17
0
def test_BGP_GR_chaos_37_p1(request):
    """
    Test Objective : Verify if helper node restarts before sending the
    EOR message, restarting node doesn't wait until stale path timer
    expiry to do the best path selection and sends an EOR
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_37 "
        "BGP GR "
        "[Restart Mode]R1---R3[Helper Mode]"
    )

    logger.info(
        "[Step 1] : Configure restarting router R3 to prevent " "sending an EOR.."
    )

    logger.info("[Step 2] : Reset the session between R3 and R1..")

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

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

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

        # Verify EOR is disabled
        result = verify_eor(
            tgen, topo, addr_type, input_dict, dut="r3", peer="r1", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r3: EOR is set to True\n Error: {}".format(
            tc_name, result
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying BGP RIB routes after starting BGPd daemon
        dut = "r1"
        input_dict_1 = {key: topo["routers"][key] for key in ["r3"]}
        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
        result = verify_rib(tgen, addr_type, dut, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("[Step 3] : Kill BGPd daemon on R1..")

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

    logger.info("[Step 4] : Start BGPd daemon on R1..")

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

    logger.info("[Step 5] : Kill BGPd daemon on R3..")

    # Kill BGPd daemon on R3
    kill_router_daemons(tgen, "r3", ["bgpd"])

    # Modify graceful-restart config to prevent sending EOR
    input_dict_2 = {"r3": {"bgp": {"graceful-restart": {"disable-eor": True}}}}

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

    logger.info("[Step 6] : Start BGPd daemon on R3..")

    # Start BGPd daemon on R3
    start_router_daemons(tgen, "r3", ["bgpd"])

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

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

        # Verify EOR is send from R1 to R3
        input_dict_3 = {"r1": {"bgp": {"graceful-restart": {"disable-eor": True}}}}

        result = verify_eor(
            tgen, topo, addr_type, input_dict_3, dut="r1", peer="r3", expected=False
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "r1: EOR is set to True\n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_BGP_GR_chaos_29_p1(request):
    """
    Test Objective : Change timers on the fly, and
    verify if it takes immediate effect.
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_29"
        " BGP GR [Helper Mode]R3-----R1[Restart Mode]"
        " and [restart-time 150]R1 initialized"
    )

    # Configure graceful-restart and timers
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER}},
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                },
            }
        },
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

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

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

    # Verify graceful-restart timers
    input_dict_2 = {
        "r1": {
            "bgp": {
                "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER + 5}}
            }
        }
    }

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

    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r1": {
                "bgp": {
                    "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER}}
                }
            }
        }

        result = verify_graceful_restart_timers(
            tgen, topo, addr_type, input_dict_2, dut="r3", peer="r1"
        )
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes before shutting down BGPd daemon
        dut = "r3"
        input_dict = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        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)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("[Step 2] : Kill BGPd daemon on R1..")

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

    logger.info("[Step 3] : Wait for {} seconds..".format(GR_RESTART_TIMER))

    # Waiting for GR_RESTART_TIMER
    sleep(GR_RESTART_TIMER)

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes before shutting down BGPd daemon
        input_dict = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r3: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

    logger.info("[Step 4] : Start BGPd daemon on R1..")

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

    write_test_footer(tc_name)
Пример #19
0
def test_BGP_GR_chaos_30_p1(request):
    """
    Test Objective : Restarting node removes stale routes from Zebra
    after receiving an EOR from helper router.
    """

    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)

    logger.info(
        " Test Case : test_BGP_GR_chaos_30  "
        "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
    )

    # Configure graceful-restart and timers
    input_dict = {
        "r1": {
            "bgp": {
                "graceful-restart": {"preserve-fw-state": True},
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
                            }
                        }
                    },
                },
            }
        },
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r1": {
                                    "dest_link": {
                                        "r3": {"graceful-restart-helper": True}
                                    }
                                }
                            }
                        }
                    },
                }
            }
        },
    }

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

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

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes before shutting down BGPd daemon
        dut = "r1"
        input_dict = {key: topo["routers"][key] for key in ["r3"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
        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)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result
        )

    logger.info("[Step 2] : Kill BGPd daemon on R1..")

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

    logger.info("[Step 3] : Withdraw advertised prefixes from R3...")

    # Api call to delete advertised networks
    network = {"ipv4": "103.0.20.1/32", "ipv6": "3::1/128"}
    for addr_type in ADDR_TYPES:
        input_dict = {
            "r3": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [
                                    {
                                        "network": network[addr_type],
                                        "no_of_network": 5,
                                        "delete": True,
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

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

    logger.info("[Step 4] : Start BGPd daemon on R1..")

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

    for addr_type in ADDR_TYPES:
        # Verifying BGP RIB routes before shutting down BGPd daemon
        input_dict = {key: topo["routers"][key] for key in ["r3"]}
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r1: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r1: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

    write_test_footer(tc_name)
Пример #20
0
def test_ospf_chaos_tc34_p1(request):
    """
    verify ospf functionality when staticd is restarted.

    Verify ospf functionalitywhen staticroutes are
    redistributed & Staticd is restarted.
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32) in R1 and redistribute "
         "to OSPF using route map.")

    # Create Static routes
    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)

    ospf_red_r0 = {
        "r0": {
            "ospf": {
                "redistribute": [{
                    "redist_type": "static"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_red_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify OSPF neighbors after base config is done.")
    # 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 route is advertised to R1.")
    dut = "r1"
    protocol = "ospf"
    nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    step("Kill staticd daemon on R0.")
    kill_router_daemons(tgen, "r0", ["staticd"])

    step("Verify that route advertised to R1 are deleted from RIB and FIB.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
        tc_name, result)

    step("Bring up staticd daemon on R0.")
    start_router_daemons(tgen, "r0", ["staticd"])

    step("Verify OSPF neighbors are up after bringing back ospfd in R0")
    # 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("All the neighbours are up and routes are installed before the"
         " restart. Verify OSPF route table and ip route table.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    step("Kill staticd daemon on R1.")
    kill_router_daemons(tgen, "r1", ["staticd"])

    step("Bring up staticd daemon on R1.")
    start_router_daemons(tgen, "r1", ["staticd"])

    step("Verify OSPF neighbors are up after bringing back ospfd in R1")
    # 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("All the neighbours are up and routes are installed before the"
         " restart. Verify OSPF route table and ip route table.")

    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    write_test_footer(tc_name)
def test_BGP_GR_18_p1(request):
    """
    Test Objective : Verify that GR helper router deletes stale routes
    received from restarting node, if GR capability is not present in
    restarting node's OPEN message.
    """

    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)

    logger.info(
        "[Step 1] : Test Setup " "[Helper Mode]R6-----R1[Restart Mode] initialized"
    )

    # Configure graceful-restart and timers
    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] initialized"
    )

    # Configure graceful-restart and timers
    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 = "r2"
        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
        )

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

    logger.info("[Step 3] : Configure R1 to prevent sending EOR")

    # Modify graceful-restart config to prevent sending EOR
    input_dict_3 = {"r1": {"bgp": {"graceful-restart": {"disable-eor": True}}}}

    result = modify_bgp_config_when_bgpd_down(tgen, topo, input_dict_3)

    # Modify configuration to delete routes
    network = {"ipv4": "101.0.20.1/32", "ipv6": "1::1/128"}
    for addr_type in ADDR_TYPES:
        input_dict_3 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [
                                    {
                                        "network": network[addr_type],
                                        "no_of_network": 5,
                                        "delete": True,
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

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

    # Modify graceful-restart config
    input_dict_3 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-disable": True}
                                    }
                                },
                                "r6": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-disable": True}
                                    }
                                },
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r2": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-disable": True}
                                    }
                                },
                                "r6": {
                                    "dest_link": {
                                        "r1": {"graceful-restart-disable": True}
                                    }
                                },
                            }
                        }
                    },
                }
            }
        }
    }

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

    logger.info("[Step 4] : Bring up the BGPd daemon on R1 for 30" " seconds..")

    # Start BGPd daemon on R1
    start_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, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r6: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r6: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying BGP RIB routes
        dut = "r2"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r2: routes are still present in BGP RIB\n Error: {}".format(
                tc_name, result
            )
        )
        logger.info(" Expected behavior: {}".format(result))

        # Verifying RIB routes before shutting down BGPd daemon
        result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \n "
            "r6: routes are still present in ZEBRA\n Error: {}".format(tc_name, result)
        )
        logger.info(" Expected behavior: {}".format(result))

    write_test_footer(tc_name)