Пример #1
0
def test_ext_nh_cap_red_static_network_ibgp_peer_p1(request):
    """

    Test extended capability nexthop with ibgp peer.

    Verify IPv4 and IPv6 routes advertise using "redistribute static"
    and "network command" are received on IBGP peer with IPv6 nexthop
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)
    step(
        "Configure IPv6 EBGP session between R1 and R2 with global IPv6"
        " address Enable capability extended-nexthop on the nbr from both"
        " the routers"
    )
    step(
        "Change ebgp to ibgp nbrs between r1 and r2 , Activate same IPv6"
        " nbr from IPv4 unicast family "
    )

    step(
        " Configure 5 IPv4 static routes"
        " on R1 nexthop for static route exists on different link of R0"
    )

    for rte in range(0, NO_OF_RTES):
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"][rte],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP["ipv4"][rte],
                    }
                ]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
    step(
        "Advertise static routes from IPv4 unicast family and IPv6 unicast"
        " family respectively from R1.Configure loopback on R1 with IPv4 addr"
        " & Advertise loopback from IPv4 unicast family using network cmd "
        " from R1"
    )
    # this test case needs ipv6 routes to be configured
    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {"network": NETWORK_CMD_IP, "no_of_network": 1}
                            ],
                        }
                    },
                    "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

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

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

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

    step(
        "Verify IPv4 routes are installed with IPv6 global nexthop of R1"
        "R1 to R2 connected link"
    )
    verify_nh_for_nw_cmd_rtes = {
        "r1": {
            "static_routes": [
                {
                    "network": NETWORK_CMD_IP,
                    "no_of_ip": 1,
                    "next_hop": glip,
                }
            ]
        }
    }
    bgp_rib = verify_bgp_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glip
    )
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, 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)
Пример #3
0
def test_static_route_with_tag_p0_tc_13_ebgp(request):
    """
    Verify static route with tag option

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

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

    step("Configure 8 links between R1 and R2")
    step("Configure 1 links between R2 and R3")
    NEXT_HOP_IP = populate_nh()

    step("Configure 2 IPv4 static route (S1 and S2) in R2 with same"
         "next hop N1 28.1.1.2")
    step("Configure static route S1 with tag 1 and static route S2 with"
         "tag2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2")
    step("Enable redistribute static in BGP with route-map")
    reset_config_on_routers(tgen)

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4002,
                    },
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("verify routes are present in RIB")
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
            tc_name)

        step("Configure route-map on R2 with allow tag1 and deny tag2")

        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "deny",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_match_tag_1_ipv4",
                                                    "direction":
                                                    "out",
                                                }]
                                            }
                                        }
                                    }
                                },
                                "redistribute": [{
                                    "redist_type": "static"
                                }],
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify static route S1 advetised in BGP table when tag1 permit"
             "in route-map else it is denied")
        dut = "r3"
        input_dict_0 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "tag": 4002,
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol,
                            expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Route with "
            "tag 4002 is still present in RIB".format(tc_name))

        dut = "r2"
        input_dict_1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "tag": 4001
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                "tag 4001 is missing in RIB".format(tc_name))

        step("Modify the route-map to allow tag2 and deny tag1")
        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "deny",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        dut = "r3"
        step("Verify static route S2 advertised in BGP table when tag2"
             "permit in route-map else it is denied")
        protocol = "bgp"
        input_dict_0 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "tag": 4002
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                "tag 4002 is missing in RIB".format(tc_name))

        input_dict_1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "tag": 4001
                }]
            }
        }
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_1,
                            protocol=protocol,
                            expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Route with "
            "tag 4001 is still present in RIB".format(tc_name))

    step("Configure one static route with 2 ECMP nexthop N1 and N2")
    step("For N1 configure tag 1 and for N2 configure tag 2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
    step("configure the route-map to allow tag1 and deny tag 2")
    step("Modify the route-map to allow tag2 and deny tag1")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                        "tag": 4002,
                    },
                ]
            }
        }

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

        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
            tc_name)

    step("shut/no shut of tag1 and tag2 nexthop")

    intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    shutdown_bringup_interface(tgen, dut, intf, True)

    step("configure one static route with 3 next-hop")
    step("N1-tag1, N2-tag2, N3-tag3")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 3")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                        "tag": 4002,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh3"][addr_type],
                        "tag": 4003,
                    },
                ]
            }
        }

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

        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol)

        step("configure the route-map to allow tag2 & tag3 and deny tag1")
        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "deny",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 30,
                            "match": {
                                addr_type: {
                                    "tag": "4003"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify static route advertised in BGP table with tag3"
             " nexthop if tag2 is down")
        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("shut / no shut of tag2 and tag3 next-hop")

        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

        intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

        step("shut/no shut of tag2 and tag3 nexthop")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

        intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("Verify after shut/noshut of nexthop BGP table updated correctly")
        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
def test_modify_route_map_match_set_clauses_p1(request):
    """
    TC13_CHAOS_4:
    1.5.13. Verify that Changing route-map configurations(match/set clauses) on
    the fly it takes immediate effect.
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    build_config_from_json(tgen, topo)

    if tgen.routers_have_failure():
        check_router_status(tgen)

    for addr_type in ADDR_TYPES:

        step("Configure route-map to set community attribute for a specific"
             "prefix on R1 in vrf ISR")

        input_dict_pf = {
            "r1": {
                "prefix_lists": {
                    addr_type: {
                        "pflist_ABC_{}".format(addr_type): [{
                            "seqid":
                            10,
                            "network":
                            NETWORK1_1[addr_type],
                            "action":
                            "permit",
                        }]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_pf)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    input_dict_cl = {
        "r1": {
            "bgp_community_lists": [{
                "community_type": "expanded",
                "action": "permit",
                "name": "COMM",
                "value": "100:100",
            }]
        }
    }
    result = create_bgp_community_lists(tgen, input_dict_cl)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    for addr_type in ADDR_TYPES:
        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_XYZ_{}".format(addr_type): [{
                        "action": "permit",
                        "match": {
                            addr_type: {
                                "prefix_lists":
                                "pflist_ABC_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "community": {
                                "num": "100:100"
                            }
                        },
                    }]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_rm)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Apply this route-map on R1 to vrf ISR while redistributing the"
             " prefixes into BGP")

        input_dict_1 = {}
        DUT = ["r1"]
        VRFS = ["ISR"]
        AS_NUM = [100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_1.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static",
                                "attribute": {
                                    "route-map":
                                    "rmap_XYZ_{}".format(addr_type)
                                },
                            }]
                        }
                    }
                },
            })

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

    for addr_type in ADDR_TYPES:

        step("Configure another route-map for filtering the prefixes based on"
             " community attribute while importing into default vrf")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_IMP_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            "community_list": {
                                "id": "COMM"
                            }
                        },
                        "set": {
                            "community": {
                                "num": "none"
                            }
                        },
                    }]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_rm)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Apply the route-map while Importing vrf ISR's prefixes into "
             "default vrf on router R1:")

        input_dict_isr = {}
        DUT = ["r1"]
        VRFS = ["default"]
        AS_NUM = [100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_isr.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf": "ISR"
                            }
                        }
                    }
                },
            })

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf":
                                "route-map rmap_IMP_{}".format(addr_type)
                            }
                        }
                    }
                },
            })

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

    for addr_type in ADDR_TYPES:

        step("Verify on R1 that only prefixes with community value 100:100"
             "in vrf ISR are imported to vrf default. While importing, the"
             " community value has been stripped off:")

        input_routes_r1 = {
            "r1": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                    "vrf": "default"
                }]
            }
        }

        result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Add set clause in route-map IMP:")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_IMP_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            "community_list": {
                                "id": "COMM"
                            }
                        },
                        "set": {
                            "large_community": {
                                "num": "100:100:100"
                            },
                            "locPrf": 500,
                            "path": {
                                "as_num": "100 100",
                                "as_action": "prepend"
                            },
                        },
                    }]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_rm)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Verify that as we continue adding different attributes "
             "step-by-step in route-map IMP those attributes gets "
             "attached to prefixes:")

        input_routes_r1 = {
            "r1": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                    "vrf": "default"
                }]
            }
        }

        input_dict_comm = {"largeCommunity": "100:100:100"}

        result = verify_bgp_community(tgen, addr_type, dut,
                                      [NETWORK1_1[addr_type]], input_dict_comm)
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

        input_rmap = {
            "r1": {
                "route_maps": {
                    "rmap_IMP_{}".format(addr_type): [{
                        "set": {
                            "locPrf": 500
                        }
                    }]
                }
            }
        }

        result = verify_bgp_attributes(
            tgen,
            addr_type,
            "r1",
            [NETWORK1_1[addr_type]],
            rmap_name="rmap_IMP_{}".format(addr_type),
            input_dict=input_rmap,
        )
        assert result is True, "Testcase  : Failed \n Error: {}".format(
            tc_name, result)

    step("Change community-list to match a different value then " "100:100.")

    input_dict_cl = {
        "r1": {
            "bgp_community_lists": [{
                "community_type": "expanded",
                "action": "permit",
                "name": "COMM",
                "value": "100:100",
                "delete": True,
            }]
        }
    }
    result = create_bgp_community_lists(tgen, input_dict_cl)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    for addr_type in ADDR_TYPES:

        input_routes_r1 = {
            "r1": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                    "vrf": "default"
                }]
            }
        }

        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r1,
                                expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \n Error : Routes are still " "present {}".format(
            tc_name, result)

    write_test_footer(tc_name)
Пример #5
0
def test_unnumbered_loopback_ebgp_nbr_p0(request):
    """

    Test extended capability nexthop with un numbered ebgp.

    Verify IPv4 routes are advertised when IPv6 EBGP loopback
    session established using Unnumbered interface
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)

    step("Configure IPv6 EBGP Unnumbered session between R1 and R2")
    step("Enable capability extended-nexthop on both the IPv6 BGP peers")
    step("Activate same IPv6 nbr from IPv4 unicast family")
    step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
    step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")

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

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

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

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

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

    dut = "r2"
    protocol = "bgp"
    for rte in range(0, NO_OF_RTES):
        # verify the routes with nh as ext_nh
        verify_nh_for_static_rtes = {
            "r1": {
                "static_routes": [
                    {"network": NETWORK["ipv4"][rte], "no_of_ip": 1, "next_hop": llip}
                ]
            }
        }
        """         interface_list = ['r1-link0','r1-link1']
        nh_list =[]
        for i in range(NO_OF_RTES):
            nh_list.append(topo['routers']['r2']['links'][i][
                'interface']) """
        bgp_rib = verify_rib(
            tgen,
            "ipv4",
            dut,
            # verify_nh_for_static_rtes, next_hop='r2-r1-eth0')
            verify_nh_for_static_rtes,
            next_hop=llip,
        )
        assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, bgp_rib
        )
        result = verify_rib(
            tgen,
            "ipv4",
            dut,
            verify_nh_for_static_rtes,
            next_hop=llip,
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    # verify the routes with nh as ext_nh
    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }

    bgp_rib = verify_rib(
        tgen,
        "ipv4",
        dut,
        # verify_nh_for_nw_rtes, next_hop='r2-r1-eth0')
        verify_nh_for_nw_rtes,
        next_hop=llip,
    )
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r1")
    stop_router(tgen, "r2")
    start_router(tgen, "r1")
    start_router(tgen, "r2")
    step(
        "After stop/start of FRR services , verify session up and routes "
        "came up fine ,nh is proper using show bgp & show ipv6 route on R2 "
    )
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

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

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

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }
    bgp_rib = verify_rib(
        tgen,
        "ipv4",
        dut,
        # verify_nh_for_nw_rtes, next_hop='r2-r1-eth0')
        verify_nh_for_nw_rtes,
        next_hop=llip,
    )
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    write_test_footer(tc_name)
def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
    """
    Verify RIB status when same route advertise via BGP and static
    route

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    reset_config_on_routers(tgen)

    NEXT_HOP_IP = populate_nh()
    step("Configure EBGP IPv4 peering between R2 and R3 router.")

    step("Configure IPv4 static route (10.1.1.1/24) in R2 with next hop"
         "N1 (28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present"
         "on R1")

    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    },
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Configure redistribute static in BGP.")
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("Verify on R3 , route receive on R3 BGP table ")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        step("Verify route installed in the RIB and FIB of R3")
        protocol = "bgp"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

    step("Configure 2 links/interfaces between R1 and R3 , keep one"
         "interface in shut (active) state and other interface in no shut"
         "(inactive) state")
    dut = "r3"
    intf = topo["routers"]["r3"]["links"]["r1-link0"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    step("Configure same static route (10.1.1.1/24) in R3 with inactive"
         "nexthop interface")

    step("Configure same static route 10.1.1.1/24) again in R3 with"
         "active nexthop interface")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link0"][addr_type],
                    },
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link1"][addr_type],
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify when static route configure with inactive nexthop , "
             "verify BGP received route is active in the RIB and FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
            tc_name)

        protocol = "bgp"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

    step("Remove the static route on R3 configured with active" "interface")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link0"][addr_type],
                        "delete":
                        True,
                    },
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link1"][addr_type],
                        "delete":
                        True,
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("After removing the static route with active nexthop verify "
             "BGP received route is became active in RIB and FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
            tc_name)

        protocol = "bgp"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

    write_test_footer(tc_name)
Пример #7
0
def test_route_summarisation_with_summary_only_p1(request):
    """
    Verify route summarisation with summary-only for redistributed as well as
    locally generated routes.
    """

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

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

    step("Configure static routes on router R1 and redistribute in "
         "BGP process.")

    for addr_type in ADDR_TYPES:
        input_static = {
            "r1": {
                "static_routes": [{
                    "network": [
                        NETWORK_1_1[addr_type],
                        NETWORK_1_2[addr_type],
                        NETWORK_1_3[addr_type],
                    ],
                    "next_hop":
                    NEXT_HOP[addr_type],
                }]
            }
        }
        input_redistribute = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }

        step("Configuring {} static routes on router R1 ".format(addr_type))

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

        step(
            "Configuring redistribute static for {} address-family on router R1 "
            .format(addr_type))

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

    step("Verify that Static routes are redistributed in BGP process")

    for addr_type in ADDR_TYPES:
        input_static = {
            "r1": {
                "static_routes": [{
                    "network": [
                        NETWORK_1_1[addr_type],
                        NETWORK_1_2[addr_type],
                        NETWORK_1_3[addr_type],
                    ]
                }]
            }
        }

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

    step("Advertise some prefixes using network command")
    step("Additionally advertise 10.1.4.0/24 & 10.1.5.0/24 and "
         "10:1::4:0/120 & 10:1::5:0/120 from R4 to R1.")

    for addr_type in ADDR_TYPES:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_2_1[addr_type],
                                        NETWORK_2_2[addr_type],
                                        NETWORK_2_3[addr_type],
                                        NETWORK_2_4[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            },
            "r4": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_1_4[addr_type],
                                        NETWORK_1_5[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            },
        }

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

    step("Verify that advertised prefixes using network command are being "
         "advertised in BGP process")

    for addr_type in ADDR_TYPES:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_2_1[addr_type],
                                        NETWORK_2_2[addr_type],
                                        NETWORK_2_3[addr_type],
                                        NETWORK_2_4[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            }
        }

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

    step("Configure aggregate-address to summarise all the advertised routes.")

    for addr_type in ADDR_TYPES:
        route_aggregate = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "aggregate_address": [{
                                    "network":
                                    AGGREGATE_NW[addr_type],
                                    "summary":
                                    True,
                                }]
                            }
                        }
                    }
                }
            }
        }

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

    step("Verify that we see 1 summarised route and remaining suppressed "
         "routes on advertising router R1 and only 1 summarised route on "
         "receiving router R3 for both AFIs.")

    for addr_type in ADDR_TYPES:
        input_static_agg = {
            "r1": {
                "static_routes": [{
                    "network": AGGREGATE_NW[addr_type]
                }]
            }
        }

        input_static = {
            "r1": {
                "static_routes": [{
                    "network": [
                        NETWORK_1_1[addr_type],
                        NETWORK_1_2[addr_type],
                        NETWORK_1_3[addr_type],
                    ]
                }]
            }
        }

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

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            input_static,
                            protocol="bgp",
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
            tc_name, result)

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

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

    for action, value in zip(["removed", "add"], [True, False]):

        step("{} static routes as below: "
             "(no) ip route 10.1.1.0/24 and (no) ip route 10.1.2.0/24"
             "(no) ipv6 route 10:1::1:0/120 and (no) ip route 10:1::2:0/120".
             format(action))

        for addr_type in ADDR_TYPES:
            input_static = {
                "r1": {
                    "static_routes": [{
                        "network":
                        [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]],
                        "next_hop":
                        NEXT_HOP[addr_type],
                        "delete":
                        value,
                    }]
                }
            }

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

        step(
            "Verify that there is no impact on R3, as summarised route remains "
            "intact. However suppressed routes on R1 disappear and re-appear "
            "based on {} static routes.".format(action))

        for addr_type in ADDR_TYPES:
            input_static_1 = {
                "r1": {
                    "static_routes": [{
                        "network":
                        [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]]
                    }]
                }
            }

            input_static_2 = {
                "r1": {
                    "static_routes": [{
                        "network": AGGREGATE_NW[addr_type]
                    }]
                }
            }

            if value:
                result = verify_rib(tgen,
                                    addr_type,
                                    "r1",
                                    input_static_1,
                                    expected=False)
                assert (
                    result is not True
                ), "Testcase {} : Failed \n Routes are still present \n Error: {}".format(
                    tc_name, result)
            else:
                result = verify_rib(tgen, addr_type, "r1", input_static_1)
                assert result is True, "Testcase {} : Failed \n Error: {}".format(
                    tc_name, result)

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

        step(
            "{} prefixes using network command as below:"
            "(no) network 10.1.6.1/24 and (no) network 10.1.7.1/24"
            "(no) network 10:1::6:0/120 and (no) network 10:1::7:0/120".format(
                action))

        for addr_type in ADDR_TYPES:
            input_advertise = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network": [
                                            NETWORK_2_3[addr_type],
                                            NETWORK_2_4[addr_type],
                                        ],
                                        "delete":
                                        value,
                                    }]
                                }
                            }
                        }
                    }
                }
            }

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

        step(
            "Verify that there is no impact on R3, as summarised route remains "
            "intact. However suppressed routes on R1 disappear and re-appear "
            "based on {} of network command.".format(action))

        for addr_type in ADDR_TYPES:
            input_advertise_1 = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network": [
                                            NETWORK_2_3[addr_type],
                                            NETWORK_2_4[addr_type],
                                        ]
                                    }]
                                }
                            }
                        }
                    }
                }
            }

            input_advertise_2 = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network":
                                        AGGREGATE_NW[addr_type]
                                    }]
                                }
                            }
                        }
                    }
                }
            }

            if value:
                result = verify_bgp_rib(tgen,
                                        addr_type,
                                        "r1",
                                        input_advertise_1,
                                        expected=False)
                assert result is not True, (
                    "Testcase {} : Failed \n "
                    "Routes are still present \n Error: {}".format(
                        tc_name, result))
            else:
                result = verify_bgp_rib(tgen, addr_type, "r1",
                                        input_advertise_1)
                assert result is True, "Testcase {} : Failed \n Error: {}".format(
                    tc_name, result)

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

    step("Add a new network each one from out of aggregation range and "
         "other within aggregation range. ")

    for addr_type in ADDR_TYPES:
        input_static = {
            "r1": {
                "static_routes": [{
                    "network": NETWORK_3_1[addr_type],
                    "next_hop": NEXT_HOP[addr_type]
                }]
            }
        }

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

    for addr_type in ADDR_TYPES:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network":
                                    NETWORK_4_1[addr_type],
                                }]
                            }
                        }
                    }
                }
            }
        }

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

    step("Verify that when a network within aggregation range is added, "
         "there is no impact on receiving router. However if a network "
         "outside aggregation range is added/removed, R3 receives and "
         "withdraws it accordingly.")

    for addr_type in ADDR_TYPES:
        input_static = {
            "r1": {
                "static_routes": [{
                    "network": AGGREGATE_NW[addr_type]
                }]
            }
        }

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

        input_advertise_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_4_1[addr_type],
                                        AGGREGATE_NW[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            }
        }

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

    for action, value in zip(["Delete", "Re-add"], [True, False]):
        step("{} aggregation command from R1.".format(action))

        for addr_type in ADDR_TYPES:
            route_aggregate = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "aggregate_address": [{
                                        "network":
                                        AGGREGATE_NW[addr_type],
                                        "summary":
                                        True,
                                        "delete":
                                        value,
                                    }]
                                }
                            }
                        }
                    }
                }
            }

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

        step(
            "Verify on both routers that summarised route is withdrawn from R1 "
            "and R3 when aggregate-address command is removed and appears again "
            "when aggregate-address command is re-added. Check for both AFIs.")

        for addr_type in ADDR_TYPES:
            input_static_agg = {
                "r1": {
                    "static_routes": [{
                        "network": AGGREGATE_NW[addr_type]
                    }]
                }
            }

            if value:
                result = verify_rib(tgen,
                                    addr_type,
                                    "r1",
                                    input_static_agg,
                                    expected=False)
                assert (
                    result is not True
                ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format(
                    tc_name, result)

                result = verify_rib(tgen,
                                    addr_type,
                                    "r3",
                                    input_static_agg,
                                    expected=False)
                assert (
                    result is not True
                ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format(
                    tc_name, result)
            else:
                result = verify_rib(tgen, addr_type, "r1", input_static_agg)
                assert result is True, "Testcase {} : Failed \n Error: {}".format(
                    tc_name, result)

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

    write_test_footer(tc_name)
Пример #8
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)
Пример #9
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)
Пример #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)
Пример #11
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_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)
Пример #13
0
def test_ibgp_loopback_nbr_p1(request):
    """
    Verify Extended capability nexthop with loopback interface.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": gllip}
            ]
        }
    }
    bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=gllip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    write_test_footer(tc_name)
Пример #14
0
def test_ext_nh_cap_admin_dist_tag_ibgp_peer_p1(request):
    """

    Test extended capability nexthop with admin distance and route tag.

    Verify IPv4 routes are advertised to peer when static routes
    are configured with ADMIN distance and tag option
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    reset_config_on_routers(tgen)
    step(
        "Configure IPv6 EBGP session between R1 and R2 with global IPv6"
        " address Enable capability extended-nexthop on the nbr from both"
        " the routers"
    )
    step(
        "Change ebgp to ibgp nbrs between r1 and r2 , Activate same IPv6"
        " nbr from IPv4 unicast family "
    )
    step(
        " Configure 5 IPv4 static routes"
        " on R1 nexthop for static route exists on different link of R0"
    )
    count = 0
    for rte in range(0, NO_OF_RTES):
        count += 1
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"][rte],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP["ipv4"][rte],
                        "admin_distance": 100 + count,
                        "tag": 4001 + count,
                    }
                ]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
    step(
        "Advertise static routes from IPv4 unicast family & IPv6 unicast"
        " family respectively from R1.Configure loopback on R1 with IPv4 "
        "address & Advertise loopback from IPv4 unicast family "
        "using network cmd from R1"
    )
    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

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

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

    dut = "r2"
    protocol = "bgp"
    count = 0
    # verify the routes with nh as ext_nh
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {
                    "network": NETWORK["ipv4"][0],
                    "no_of_ip": NO_OF_RTES,
                    "next_hop": glip,
                    "admin_distance": 100 + count,
                    "tag": 4001 + count,
                }
            ]
        }
    }
    bgp_rib = verify_bgp_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glip
    )
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    count = 0
    for rte in range(0, NO_OF_RTES):
        count += 10
        input_dict_2 = {
            "r3": {
                "prefix_lists": {
                    "ipv4": {
                        "pf_list_1_ipv4": [
                            {
                                "seqid": 0 + count,
                                "action": "permit",
                                "network": NETWORK["ipv4"][rte],
                            }
                        ]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_2)
        assert result is True, "Testcase {} : Failed \n " "Error: {}".format(
            tc_name, result
        )

        # Create route map
        input_dict_6 = {
            "r3": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format("ipv4"): [
                        {
                            "action": "deny",
                            "match": {
                                "ipv4": {"prefix_lists": "pf_list_1_{}".format("ipv4")}
                            },
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_6)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Configure neighbor for route map
        input_dict_7 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        "ipv6": {
                            "unicast": {
                                "neighbor": {
                                    "r2": {
                                        "dest_link": {
                                            "r1-link0": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_tag_1_ipv4",
                                                        "direction": "out",
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

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

    write_test_footer(tc_name)
Пример #15
0
def test_verify_deleting_re_adding_route_map_with_iBGP_peers_p0(request):
    """
    Verify graceful-shutdown functionality after deleting/re-adding route-map
    with iBGP peers
    """

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    write_test_footer(tc_name)
Пример #16
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)
Пример #17
0
def test_static_route_2nh_p0_tc_1_ibgp(request):
    """
    Verify static route ECMP functionality with 2 next hop

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    reset_config_on_routers(tgen)
    NEXT_HOP_IP = populate_nh()

    step("Configure IPv4 static route (10.1.1.1) in R2 with next hop N1"
         "(28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present on"
         "R1")
    step("ex :- ip route 10.1.1.1/24 28.1.1.2 & ip route 10.1.1.1/24 29.1.1.1")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    },
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                    },
                ]
            }
        }

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

        step("On R2, static route installed in RIB using show ip route"
             " with 2 ECMP next hop ")
        nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Configure IBGP IPv4 peering between R2 and R3 router.")
        step("Configure redistribute static in BGP on R2 router")

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

        step(
            "Remove the static route configured with nexthop N1 from running config"
        )
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "delete": True,
                }]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, after removing the static route with N1 , "
             "route become active with nexthop N2 and vice versa.")
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [NEXT_HOP_IP["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N1")

        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                }]
            }
        }

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

        step(
            "Remove the static route configured with nexthop N2 from running config"
        )

        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                    "delete": True,
                }]
            }
        }

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

        step("On R2, after removing the static route with N2 , "
             "route become active with nexthop N1 and vice versa.")
        nh = NEXT_HOP_IP["nh2"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [NEXT_HOP_IP["nh1"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N2")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                }]
            }
        }

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

        step("Shut nexthop interface N1")
        intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]

        shutdown_bringup_interface(tgen, dut, intf, False)

        step("Only one the nexthops should be active in RIB.")

        nh = NEXT_HOP_IP["nh2"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_dict_4,
                                next_hop=nh,
                                expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            protocol=protocol,
            next_hop=nh,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        dut = "r2"
        nh = [NEXT_HOP_IP["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        dut = "r2"
        step("No shut the nexthop interface N1")
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Shut nexthop interface N2")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        dut = "r2"
        shutdown_bringup_interface(tgen, dut, intf, False)

        step(" after shut of nexthop N1 , route become active with "
             "nexthop N2 and vice versa.")
        nh = NEXT_HOP_IP["nh2"][addr_type]

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [NEXT_HOP_IP["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        step("No shut nexthop interface N2")
        dut = "r2"
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        step("Reload the FRR router")
        # stop/start -> restart FRR router and verify
        stop_router(tgen, "r2")

        start_router(tgen, "r2")

        dut = "r2"
        step("After reload of FRR router , static route installed"
             " in RIB and FIB properly .")
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

    write_test_footer(tc_name)
def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request):
    """
    Verify ECMP for imported routes from different VRFs.
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    if tgen.routers_have_failure():
        check_router_status(tgen)
    reset_config_on_routers(tgen)

    step("Configure same static routes in tenant vrfs RED and GREEN on router "
         "R3 and redistribute in respective BGP process")

    for vrf_name in ["RED", "GREEN"]:
        for addr_type in ADDR_TYPES:
            if vrf_name == "GREEN":
                next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][
                    addr_type].split("/")[0]
            else:
                next_hop_vrf = topo["routers"]["r2"]["links"]["r3-link1"][
                    addr_type].split("/")[0]
            static_routes = {
                "r3": {
                    "static_routes": [{
                        "network": [NETWORK1_1[addr_type]],
                        "next_hop": next_hop_vrf,
                        "vrf": vrf_name
                    }]
                }
            }

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

        step("Redistribute static route on BGP VRF : {}".format(vrf_name))
        temp = {}
        for addr_type in ADDR_TYPES:
            temp.update({
                addr_type: {
                    "unicast": {
                        "redistribute": [{
                            "redist_type": "static"
                        }]
                    }
                }
            })

        redist_dict = {
            "r3": {
                "bgp": [{
                    "vrf": vrf_name,
                    "local_as": 3,
                    "address_family": temp
                }]
            }
        }

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

    step("Verify that configured static routes are installed in respective "
         "BGP table for vrf RED & GREEN")
    for vrf_name in ["RED", "GREEN"]:
        for addr_type in ADDR_TYPES:
            if vrf_name == "GREEN":
                next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][
                    addr_type].split("/")[0]
            else:
                next_hop_vrf = topo["routers"]["r2"]["links"]["r3-link1"][
                    addr_type].split("/")[0]
            static_routes = {
                "r3": {
                    "static_routes": [{
                        "network": [NETWORK1_1[addr_type]],
                        "vrf": vrf_name
                    }]
                }
            }

            result = verify_bgp_rib(tgen,
                                    addr_type,
                                    "r3",
                                    static_routes,
                                    next_hop=next_hop_vrf)
            assert result is True, "Testcase {} : Failed \n Error {}". \
                format(tc_name, result)

            result = verify_rib(tgen,
                                addr_type,
                                "r3",
                                static_routes,
                                next_hop=next_hop_vrf)
            assert result is True, "Testcase {} : Failed \n Error {}". \
                format(tc_name, result)

    step("Import vrf RED and GREEN into default vrf and Configure ECMP")
    bgp_val = []
    for vrf_name in ["RED", "GREEN"]:
        temp = {}
        for addr_type in ADDR_TYPES:
            temp.update({
                addr_type: {
                    "unicast": {
                        "import": {
                            "vrf": vrf_name
                        },
                        "maximum_paths": {
                            "ebgp": 2
                        }
                    }
                }
            })

        bgp_val.append({"local_as": 3, "address_family": temp})

    import_dict = {"r3": {"bgp": bgp_val}}

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

    step("Configure bgp bestpath on router r3")
    r3_raw_config = {
        "r3": {
            "raw_config":
            ["router bgp 3", "bgp bestpath as-path multipath-relax"]
        }
    }
    result = apply_raw_config(tgen, r3_raw_config)
    assert result is True, "Testcase {} :Failed \n Error: {}". \
        format(tc_name, result)

    step("Verify that routes are imported with two different next-hop vrfs "
         "and IPs. Additionally R3 must do ECMP for both the routes.")

    for addr_type in ADDR_TYPES:
        next_hop_vrf = [
            topo["routers"]["r2"]["links"]["r3-link1"][addr_type]. \
                split("/")[0],
            topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \
                split("/")[0]
            ]
        static_routes = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                }]
            }
        }

        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r3",
                                static_routes,
                                next_hop=next_hop_vrf)
        assert result is True, "Testcase {} : Failed \n Error {}". \
            format(tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            static_routes,
                            next_hop=next_hop_vrf)
        assert result is True, "Testcase {} : Failed \n Error {}". \
            format(tc_name, result)

    step("Now change the next-hop of static routes in vrf RED and GREEN to "
         "same IP address")
    for addr_type in ADDR_TYPES:
        next_hop_vrf = topo["routers"]["r1"]["links"]["r3-link3"][
            addr_type].split("/")[0]
        static_routes = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                    "next_hop": next_hop_vrf,
                    "vrf": "RED"
                }, {
                    "network": [NETWORK1_1[addr_type]],
                    "next_hop":
                    topo["routers"]["r2"]["links"]["r3-link1"]
                    [addr_type].split("/")[0],
                    "vrf":
                    "RED",
                    "delete":
                    True
                }]
            }
        }

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

    step("Verify that now routes are imported with two different next-hop "
         "vrfs but same IPs. Additionally R3 must do ECMP for both the routes")

    for addr_type in ADDR_TYPES:
        next_hop_vrf = [
            topo["routers"]["r1"]["links"]["r3-link3"][addr_type].\
                split("/")[0],
            topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \
                split("/")[0]
            ]
        static_routes = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK1_1[addr_type]],
                }]
            }
        }

        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r3",
                                static_routes,
                                next_hop=next_hop_vrf)
        assert result is True, "Testcase {} : Failed \n Error {}". \
            format(tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            static_routes,
                            next_hop=next_hop_vrf)
        assert result is True, "Testcase {} : Failed \n Error {}". \
            format(tc_name, result)

    write_test_footer(tc_name)
def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
    """
    Verify static route functionality with 2 next hop & different AD value.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    reset_config_on_routers(tgen)

    step("Configure IPv4 static route (10.1.1.1) in R2 with next hop N1"
         "(28.1.1.2 ) AD 10 and N2 (29.1.1.2) AD 20 , Static route next-hop"
         "present on R1 \n ex :- ip route 10.1.1.1/24 28.1.1.2 10 & "
         "ip route 10.1.1.1/24 29.1.1.2 20")

    reset_config_on_routers(tgen)
    next_hop_ip = populate_nh()
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": next_hop_ip["nh1"][addr_type],
                        "admin_distance": 10,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": next_hop_ip["nh2"][addr_type],
                        "admin_distance": 20,
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, static route installed in RIB using "
             "show ip route with 2 next hop , lowest AD nexthop is active ")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        step("Configure IBGP IPv4 peering between R2 and R3 router.")
        step("Explicit route is added in R3 for R2 nexthop rechability")
        rt3_rtes = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        next_hop_ip["nh1"][addr_type] + "/32",
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r3"][addr_type],
                    },
                    {
                        "network":
                        next_hop_ip["nh2"][addr_type] + "/32",
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r3"][addr_type],
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rt3_rtes)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("Configure redistribute static in BGP on R2 router")

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

        step("Remove the static route configured with nexthop N1 from"
             "running config")
        rt1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                    "delete": True,
                }]
            }
        }

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

        step("On R2, after removing the static route with N1 , "
             "route become active with nexthop N2 and vice versa.")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte1_nh1,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte2_nh2,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N1")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rte1_nh1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Remove the static route configured with nexthop N2 from"
             "running config")
        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                    "delete": True,
                }]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rte2_nh2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, after removing the static route with N2 , "
             "route become active with nexthop N1 and vice versa.")
        nh = next_hop_ip["nh2"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh1"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N2")
        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }

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

        step("Shut nexthop interface N1")
        intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]

        shutdown_bringup_interface(tgen, dut, intf, False)

        step("after shut of nexthop N1 , route become active with nexthop N2")

        nh = next_hop_ip["nh1"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte1_nh1,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte2_nh2,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("No shut the nexthop interface N1")
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        nh = [next_hop_ip["nh1"][addr_type]]

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Shut nexthop interface N2")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]

        shutdown_bringup_interface(tgen, dut, intf, False)

        step(" after shut of nexthop N1 , route become active with "
             "nexthop N2 and vice versa.")
        nh = next_hop_ip["nh2"][addr_type]

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh1"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("No shut nexthop interface N2")
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r2"
        step("Reload the FRR router")
        # stop/start -> restart FRR router and verify
        stop_router(tgen, "r2")

        start_router(tgen, "r2")

        step("After reload of FRR router , static route installed"
             " in RIB and FIB properly .")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

    write_test_footer(tc_name)
def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(
        request):
    """
    Verify ECMP for imported routes from different VRFs.
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    if tgen.routers_have_failure():
        check_router_status(tgen)
    reset_config_on_routers(tgen)

    step(
        "Configure same static routes on R2 and R3 vrfs and redistribute in BGP "
        "for GREEN and RED vrf instances")
    for dut, network in zip(
        ["r2", "r3"], [[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]):
        for vrf_name, network_vrf in zip(["RED", "GREEN"], network):
            step("Configure static route for VRF : {} on {}".format(
                vrf_name, dut))
            for addr_type in ADDR_TYPES:
                static_routes = {
                    dut: {
                        "static_routes": [{
                            "network": [network_vrf[addr_type]],
                            "next_hop": "blackhole",
                            "vrf": vrf_name
                        }]
                    }
                }

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

    for dut, as_num in zip(["r2", "r3"], ["2", "3"]):
        for vrf_name in ["RED", "GREEN"]:
            step("Redistribute static route on BGP VRF : {}".format(vrf_name))
            temp = {}
            for addr_type in ADDR_TYPES:
                temp.update({
                    addr_type: {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }]
                        }
                    }
                })

            redist_dict = {
                dut: {
                    "bgp": [{
                        "vrf": vrf_name,
                        "local_as": as_num,
                        "address_family": temp
                    }]
                }
            }

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

    step("Verify that R2 and R3 has installed redistributed routes in default "
         "and RED vrfs and GREEN respectively:")
    for dut, network in zip(
        ["r2", "r3"], [[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]):
        for vrf_name, network_vrf in zip(["RED", "GREEN"], network):
            for addr_type in ADDR_TYPES:
                static_routes = {
                    dut: {
                        "static_routes": [{
                            "network": [network_vrf[addr_type]],
                            "next_hop": "blackhole",
                            "vrf": vrf_name
                        }]
                    }
                }
                result = verify_bgp_rib(tgen, addr_type, dut, static_routes)
                assert result is True, "Testcase {} : Failed \n Error {}". \
                    format(tc_name, result)

    step("Import vrf RED's route in vrf GREEN on R3")
    temp = {}
    for addr_type in ADDR_TYPES:
        temp.update({addr_type: {"unicast": {"import": {"vrf": "RED"}}}})

    import_dict = {
        "r3": {
            "bgp": [{
                "vrf": "GREEN",
                "local_as": 3,
                "address_family": temp
            }]
        }
    }

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

    step("Verify that locally imported routes are installed over eBGP imported"
         " routes from VRF RED into VRF GREEN")
    for addr_type in ADDR_TYPES:
        static_routes = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK1_2[addr_type]],
                    "next_hop": "blackhole",
                    "vrf": "GREEN"
                }]
            }
        }

        input_routes = {
            "r3": {
                addr_type: [{
                    "network": NETWORK1_2[addr_type],
                    "bestpath": BESTPATH[addr_type],
                    "vrf": "GREEN"
                }]
            }
        }

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

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

    write_test_footer(tc_name)
def test_bgp_best_path_with_dynamic_import_p0(request):
    """
    TC6_FUNC_6:
    1.5.6. Verify BGP best path selection algorithm works fine when
    routes are imported from ISR to default vrf and vice versa.
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    build_config_from_json(tgen, topo)

    if tgen.routers_have_failure():
        check_router_status(tgen)

    for addr_type in ADDR_TYPES:

        step("Redistribute configured static routes into BGP process"
             " on R1/R2 and R3")

        input_dict_1 = {}
        DUT = ["r1", "r2", "r3", "r4"]
        VRFS = ["ISR", "ISR", "default", "default"]
        AS_NUM = [100, 100, 300, 400]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_1.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }]
                        }
                    }
                },
            })

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

    for addr_type in ADDR_TYPES:

        step("Import from default vrf into vrf ISR on R1 and R2 as below")

        input_dict_vrf = {}
        DUT = ["r1", "r2"]
        VRFS = ["ISR", "ISR"]
        AS_NUM = [100, 100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_vrf.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf": "default"
                            }
                        }
                    }
                },
            })

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

        input_dict_default = {}
        DUT = ["r1", "r2"]
        VRFS = ["default", "default"]
        AS_NUM = [100, 100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_default.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf": "ISR"
                            }
                        }
                    }
                },
            })

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

    step("Verify ECMP/Next-hop/Imported routes Vs Locally originated "
         "routes/eBGP routes vs iBGP routes --already covered in almost"
         " all tests")

    for addr_type in ADDR_TYPES:

        step("Verify Pre-emption")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r4_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Shutdown interface connected to r1 from r4:")
    shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False)

    for addr_type in ADDR_TYPES:

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        step("Verify next-hop is changed")
        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r3_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Bringup interface connected to r1 from r4:")
    shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True)

    for addr_type in ADDR_TYPES:

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        step("Verify next-hop is not chnaged aftr shutdown:")
        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r3_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Active-Standby scenario(as-path prepend and Local pref)")

    for addr_type in ADDR_TYPES:

        step("Create prefix-list")

        input_dict_pf = {
            "r1": {
                "prefix_lists": {
                    addr_type: {
                        "pf_ls_{}".format(addr_type): [{
                            "seqid":
                            10,
                            "network":
                            NETWORK3_4[addr_type],
                            "action":
                            "permit",
                        }]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_pf)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set localpref 500")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH1_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 500
                        },
                    }]
                }
            }
        }

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

        step("Create route-map to match prefix-list and set localpref 600")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH2_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 20,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 600
                        },
                    }]
                }
            }
        }

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

        input_dict_rma = {
            "r1": {
                "bgp": [{
                    "local_as": "100",
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r1-link1": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_PATH1_{}".format(
                                                        addr_type),
                                                    "direction":
                                                    "in",
                                                }]
                                            }
                                        }
                                    },
                                    "r4": {
                                        "dest_link": {
                                            "r1-link1": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_PATH2_{}".format(
                                                        addr_type),
                                                    "direction":
                                                    "in",
                                                }]
                                            }
                                        }
                                    },
                                }
                            }
                        }
                    },
                }]
            }
        }

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

    dut = "r1"
    attribute = "locPrf"

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is installed as per highest localpref")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set localpref 700")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH1_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 700
                        },
                    }]
                }
            }
        }

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

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is changed as per highest localpref")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set as-path prepend")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH2_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 20,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "localpref": 700,
                            "path": {
                                "as_num": "111",
                                "as_action": "prepend"
                            },
                        },
                    }]
                }
            }
        }

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

    attribute = "path"

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is changed as per shortest as-path")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
def test_bgp_no_export_local_as_and_internet_communities_p0(request):
    """
    Verify that BGP well known communities work fine for
    eBGP and iBGP peers.
    Well known communities tested: no-export, local-AS, internet
    """

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

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

    step("Initial config: Configure BGP neighborship between R1 and R3.")
    reset_config_on_routers(tgen)

    step("Configure static routes on R1 with next-hop as null0")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r1": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": "null0"
                }]
            }
        }
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for comm_type in ["no-export", "local-AS", "internet"]:

        step("Create a route-map on R1 to set community as {}".format(
            comm_type))

        seq_id = 10
        input_rmap = {
            "r1": {
                "route_maps": {
                    "rmap_wkc": [{
                        "action": "permit",
                        "seq_id": seq_id,
                        "set": {
                            "community": {
                                "num": "{}".format(comm_type)
                            }
                        },
                    }]
                }
            }
        }
        result = create_route_maps(tgen, input_rmap)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Apply route-map while redistributing static routes into BGP")
        input_dict_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static",
                                    "attribute": {
                                        "route-map": "rmap_wkc"
                                    },
                                }]
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static",
                                    "attribute": {
                                        "route-map": "rmap_wkc"
                                    },
                                }]
                            }
                        },
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)

        step("Verify that BGP prefixes on R1 have community: {}".format(
            comm_type))
        input_dict_4 = {"community": "{}".format(comm_type)}
        for addr_type in ADDR_TYPES:
            result = verify_bgp_community(tgen, addr_type, "r1",
                                          NETWORK[addr_type], input_dict_4)
            assert result is True, "Test case {} : Should fail \n Error: {}".format(
                tc_name, result)

        for addr_type in ADDR_TYPES:
            input_dict_4 = {
                "r1": {
                    "static_routes": [{
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r1"][addr_type].split(
                            "/")[0],
                    }]
                }
            }
            result = verify_bgp_rib(
                tgen,
                addr_type,
                "r2",
                input_dict_4,
                next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split(
                    "/")[0],
            )
            assert result is True, "Testcase  : Failed \n Error: {}".format(
                tc_name, result)

            if comm_type == "internet":
                step("Verify that these prefixes, originated on R1, are"
                     "received on both R2 and R3")

                result = verify_rib(
                    tgen,
                    addr_type,
                    "r3",
                    input_dict_4,
                    next_hop=topo["routers"]["r1"]["links"]["r3"]
                    [addr_type].split("/")[0],
                )
                assert result is True, "Testcase  : Failed \n Error: {}".format(
                    tc_name, result)
            else:
                step("Verify that these prefixes, originated on R1, are not"
                     "received on R3 but received on R2")

                result = verify_rib(
                    tgen,
                    addr_type,
                    "r3",
                    input_dict_4,
                    next_hop=topo["routers"]["r1"]["links"]["r3"]
                    [addr_type].split("/")[0],
                    expected=False,
                )
                assert result is not True, "Testcase  : Failed \n Error: {}".format(
                    tc_name, result)

        step("Remove route-map from redistribute static on R1")
        input_dict_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static",
                                    "delete": True
                                }]
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static",
                                    "delete": True
                                }]
                            }
                        },
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase  : Failed \n Error: {}".format(
            tc_name, result)

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

        step("Verify that these prefixes, originated on R1, are now"
             "received on both routers R2 and R3")
        for addr_type in ADDR_TYPES:
            input_dict_4 = {
                "r1": {
                    "static_routes": [{
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r1"][addr_type].split(
                            "/")[0],
                    }]
                }
            }
            result = verify_bgp_rib(
                tgen,
                addr_type,
                "r2",
                input_dict_4,
                next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split(
                    "/")[0],
            )
            assert result is True, "Testcase  : Failed \n Error: {}".format(
                tc_name, result)

            result = verify_bgp_rib(
                tgen,
                addr_type,
                "r3",
                input_dict_4,
                next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split(
                    "/")[0],
            )
            assert result is True, "Testcase  : Failed \n Error: {}".format(
                tc_name, result)

    write_test_footer(tc_name)
Пример #23
0
def test_BGP_attributes_with_vrf_default_keyword_p0(request):
    """
    TC_9:
    Verify BGP functionality for default vrf with
    "vrf default" keyword.
    """

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

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    step("Configure static routes and redistribute in BGP on R3")
    for addr_type in ADDR_TYPES:
        input_dict = {
            "r3": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type][0],
                        "no_of_ip": 4,
                        "next_hop": "Null0",
                    }
                ]
            }
        }

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

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

    step(
        "Create a route-map to match a specific prefix and modify"
        "BGP attributes for matched prefix"
    )
    input_dict_2 = {
        "r3": {
            "prefix_lists": {
                "ipv4": {
                    "ABC": [
                        {
                            "seqid": 10,
                            "action": "permit",
                            "network": NETWORK["ipv4"][0],
                        }
                    ]
                },
                "ipv6": {
                    "XYZ": [
                        {
                            "seqid": 100,
                            "action": "permit",
                            "network": NETWORK["ipv6"][0],
                        }
                    ]
                },
            }
        }
    }
    result = create_prefix_lists(tgen, input_dict_2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    for addr_type in ADDR_TYPES:
        if addr_type == "ipv4":
            pf_list = "ABC"
        else:
            pf_list = "XYZ"

        input_dict_6 = {
            "r3": {
                "route_maps": {
                    "BGP_ATTR_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "seq_id": 10,
                            "match": {addr_type: {"prefix_lists": pf_list}},
                            "set": {
                                "aspath": {"as_num": 500, "as_action": "prepend"},
                                "localpref": 500,
                                "origin": "egp",
                                "community": {"num": "500:500", "action": "additive"},
                                "large_community": {
                                    "num": "500:500:500",
                                    "action": "additive",
                                },
                            },
                        },
                        {"action": "permit", "seq_id": 20},
                    ]
                },
                "BGP_ATTR_{}".format(addr_type): [
                    {
                        "action": "permit",
                        "seq_id": 100,
                        "match": {addr_type: {"prefix_lists": pf_list}},
                        "set": {
                            "aspath": {"as_num": 500, "as_action": "prepend"},
                            "localpref": 500,
                            "origin": "egp",
                            "community": {"num": "500:500", "action": "additive"},
                            "large_community": {
                                "num": "500:500:500",
                                "action": "additive",
                            },
                        },
                    },
                    {"action": "permit", "seq_id": 200},
                ],
            }
        }

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

    step("Apply the route-map on R3 in outbound direction for peer R4")

    input_dict_7 = {
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {
                                "r4": {
                                    "dest_link": {
                                        "r3": {
                                            "route_maps": [
                                                {
                                                    "name": "BGP_ATTR_ipv4",
                                                    "direction": "out",
                                                }
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "neighbor": {
                                "r4": {
                                    "dest_link": {
                                        "r3": {
                                            "route_maps": [
                                                {
                                                    "name": "BGP_ATTR_ipv6",
                                                    "direction": "out",
                                                }
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    },
                }
            }
        }
    }

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

    step(
        "verify modified attributes for specific prefix with 'vrf default'"
        "keyword on R4"
    )
    for addr_type in ADDR_TYPES:
        dut = "r4"
        input_dict = {
            "r3": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type][0],
                        "vrf": "default",
                        "largeCommunity": "500:500:500",
                    }
                ]
            }
        }

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

    for addr_type in ADDR_TYPES:
        dut = "r4"
        input_dict = {
            "r3": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type][0],
                        "vrf": "default",
                        "community": "500:500",
                    }
                ]
            }
        }

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

        input_dict_4 = {"largeCommunity": "500:500:500", "community": "500:500"}

        result = verify_bgp_community(
            tgen, addr_type, dut, [NETWORK[addr_type][0]], input_dict_4
        )
        assert result is True, "Test case {} : Should fail \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Пример #24
0
def test_bgp_no_advertise_community_p0(request):
    """
    Verify routes are not advertised when NO-ADVERTISE Community is applied

    """

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    build_config_from_json(tgen, topo1, save_bkup=False)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    write_test_footer(tc_name)
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)
Пример #26
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_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)
Пример #28
0
def test_bgp_allowas_in_sameastoebgp_p1(request):
    """
    Verify that when we advertise a network, learned from the same AS
    via allowas-in command, to an eBGP neighbor we see multiple
    occurrences of our own AS based on configured value+1.

    """

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

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

    dut = "r3"
    protocol = "bgp"

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

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

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

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

    step("Configure a route-map on R2 to prepend AS 2 times.")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "route_maps": {
                    "ASP_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "set": {
                                "path": {"as_num": "200 200", "as_action": "prepend"}
                            },
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        step("configure route map in out direction on R2")
        # Configure neighbor for route map
        input_dict_7 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2": {
                                                "route_maps": [
                                                    {
                                                        "name": "ASP_{}".format(
                                                            addr_type
                                                        ),
                                                        "direction": "out",
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

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

    for addr_type in ADDR_TYPES:
        step('Configure "allowas-in 3" on R3 for R1.')
        input_dict_1 = {
            "r3": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r2": {
                                        "dest_link": {
                                            "r3": {
                                                "allowas-in": {"number_occurences": 3}
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
        static_routes = {
            "r1": {
                "static_routes": [
                    {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
                ]
            }
        }
        dut = "r5"
        path = "200 100 200 200 200"
        result = verify_bgp_rib(tgen, addr_type, dut, static_routes, aspath=path)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )
    write_test_footer(tc_name)
Пример #29
0
def test_bgp_local_nexthop_p1_tc14_ebgp(request):
    """
    Verify BGP did not install the static route when it receive route
    with local next hop

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

    step("Configure BGP IPv4 session between R2 and R3")
    step("Configure IPv4 static route on R2")
    reset_config_on_routers(tgen)

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network":
                    NETWORK[addr_type],
                    "next_hop":
                    topo["routers"]["r3"]["links"]["r2-link0"]
                    [addr_type].split("/")[0],
                }]
            }
        }

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

        step("Configure redistribute static in the BGP")

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

        step("Verify R2 BGP table has IPv4 route")
        dut = "r2"
        result = verify_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
            tc_name)

        step(" Verify route did not install in the R3 BGP table, RIB/FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_dict_4,
                                expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes is"
            " still present in BGP RIB of R2".format(tc_name))

        result = verify_rib(tgen, addr_type, dut, input_dict_4, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes is"
            " still present in RIB of R2".format(tc_name))

    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)