Example #1
0
def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
    """
    Verify static route configure with interface name as gateway'
        'address'
    """
    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)

    dut = "r1"
    intf = topo["routers"]["r1"]["links"]["r2-link0"]["interface"]
    nh = topo["routers"]["r1"]["links"]["r2-link0"]
    ip_list = {
        "ipv4": [(dut, intf, ["1.1.1.1/32"], nh["ipv4"].split("/")[0])],
        "ipv6": [(dut, intf, ["4001::32/128"], nh["ipv6"].split("/")[0])],
    }

    step(
        "Configure IPv4 and IPv6 static route in FRR with different next"
        "hop (ens224 as nexthop))"
    )
    step("ip route 2.2.2.0/24 20.1.1.1 ens224 ----from FRR cli")
    step("ipv6 route 2000::1/120 5000::1 ens224 ----from FRR cli")

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

        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(
            "IPv4 and IPv6 Static route added in FRR verify using "
            "show ip route , nexthop is resolved using show nht"
        )
        protocol = "static"
        result = verify_rib(
            tgen, addr_type, dut, input_dict_4, protocol=protocol, next_hop=nh
        )
        assert result is True, "Testcase {} : Failed \nError: Routes is"
        " missing in RIB".format(tc_name)

        input_dict_nh = {
            "r1": {
                nh: {
                    "Address": nh,
                    "resolvedVia": "connected",
                    "nexthops": {"nexthop1": {"Interfcae": intf}},
                }
            }
        }
        result = verify_ip_nht(tgen, input_dict_nh)
        assert result is True, "Testcase {} : Failed \nError: Nexthop is"
        " missing in RIB".format(tc_name)

        step(
            "Shut / no shut IPv4 and IPv6 static next hop interface from"
            "kernel and FRR CLI"
        )

        shutdown_bringup_interface(tgen, dut, intf, False)

        step(
            "After shut of nexthop interface, IPv4 and IPv6 route got removed "
            "from RIB verify using show ip route show nht"
        )
        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: Routes is"
        " missing in RIB".format(tc_name)

        shutdown_bringup_interface(tgen, dut, intf, True)

        step(
            "After no shut route got added again in RIB /FIB using "
            "show ip route nexthop is resolved using show nht"
        )
        result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
        assert result is True, "Testcase {} : Failed".format(tc_name)

    for addr_type in ADDR_TYPES:
        nh = topo["routers"]["r2"]["links"]["r1-link0"][addr_type].split("/")[0]
        input_dict_4 = {
            "r1": {
                "static_routes": [
                    {
                        "network": ip_list[addr_type][0][2][0],
                        "next_hop": nh,
                        "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(
            "Removing FRR configured static route verify FRR route also "
            "removed from FRR"
        )
        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: Routes"
        " still present in RIB".format(tc_name)

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc21_p0(request):
    """
    OSPF route map support functionality.

    Verify OSPF route map support functionality with set/match clauses
    /call/continue/goto in a route-map to see if it takes immediate effect.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

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

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

    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")

    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "seq_id": 10
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that route is advertised to R2.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "delete": True,
                    "seq_id": 10
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step(" Configure route map with set clause (set metric)")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "set": {
                        "med": 123
                    },
                    "seq_id": 10
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that configured metric is applied to ospf routes.")
    dut = "r1"
    protocol = "ospf"

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

    step("Configure route map with match clause (match metric) with "
         "some actions(change metric).")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "med": 123
                    },
                    "set": {
                        "med": 150
                    },
                    "seq_id": 10,
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure route map with call clause")

    # Create ip prefix list
    input_dict_2 = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [{
                        "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 = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_1_ipv4"
                        }
                    },
                    "set": {
                        "med": 150
                    },
                    "call": "rmap_match_pf_2_ipv4",
                    "seq_id": 10,
                }],
                "rmap_match_pf_2_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_1_ipv4"
                        }
                    },
                    "set": {
                        "med": 200
                    },
                    "seq_id": 10,
                }],
            }
        }
    }
    result = create_route_maps(tgen, input_dict_3)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"delete": True}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure route map with continue clause")

    # Create route map
    input_dict_3 = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [
                    {
                        "action": "permit",
                        "seq_id": "10",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "set": {
                            "med": 150
                        },
                        "continue": "30",
                        "seq_id": 10,
                    },
                    {
                        "action": "permit",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "set": {
                            "med": 100
                        },
                        "seq_id": 20,
                    },
                    {
                        "action": "permit",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "set": {
                            "med": 50
                        },
                        "seq_id": 30,
                    },
                ]
            }
        }
    }
    result = create_route_maps(tgen, input_dict_3)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

    step("Configure route map with goto clause")
    # Create route map
    input_dict_3 = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [
                    {
                        "action": "permit",
                        "seq_id": "10",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "goto": "30",
                    },
                    {
                        "action": "permit",
                        "seq_id": "20",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "set": {
                            "med": 100
                        },
                    },
                    {
                        "action": "permit",
                        "seq_id": "30",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                        "set": {
                            "med": 200
                        },
                    },
                ]
            }
        }
    }
    result = create_route_maps(tgen, input_dict_3)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    write_test_footer(tc_name)
Example #3
0
def test_ospf_learning_tc15_p0(request):
    """Verify OSPF can learn different types of LSA and processes them.

    OSPF Learning : Edge learning different types of LSAs.
    """
    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
    step("Bring up the base config as per the topology")
    step("Configure area 1 as NSSA Area")

    reset_config_on_routers(tgen)

    step("Verify that Type 3 summary LSA is originated for the same Area 0")
    ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv4"]
    ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)

    dut = "r0"
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": ip_net,
                "no_of_ip": 1,
                "routeType": "N IA"
            }]
        }
    }

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

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

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

    step("Redistribute static route in R2 ospf.")
    dut = "r2"
    redistribute_ospf(tgen, topo, dut, "static")

    step("Verify that Type 5 LSA is originated by R2.")
    dut = "r0"
    protocol = "ospf"
    result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that R0 receives Type 4 summary LSA.")
    dut = "r0"
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "routeType": "N E2"
            }]
        }
    }

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

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

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

    step("Change area 1 as non nssa area (on the fly changing area"
         " type on DUT).")

    for rtr in ["r1", "r2", "r3"]:
        input_dict = {
            rtr: {
                "ospf": {
                    "area": [{
                        "id": "0.0.0.2",
                        "type": "nssa",
                        "delete": True
                    }]
                }
            }
        }
        result = create_router_ospf(tgen, topo, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Verify that OSPF neighbours are reset after changing area type.")
    step("Verify that ABR R2 originates type 5 LSA in area 1.")
    step("Verify that route is calculated and installed in R1.")

    input_dict = {
        "r1": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "routeType": "N E2"
            }]
        }
    }

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

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

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc25_p0(request):
    """
    OSPF route map support functionality.

    Verify OSPF route map support functionality
    when route map actions are toggled.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")

    reset_config_on_routers(tgen)

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

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

    ospf_red_r0 = {
        "r0": {
            "ospf": {
                "redistribute": [{
                    "redist_type": "static",
                    "route_map": "rmap_ipv4"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_red_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    step("Configure route map with permit rule")
    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "permit"}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that route is advertised to R1.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    step("Configure route map with deny rule")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "seq_id": 10,
                    "action": "deny"
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

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

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc19_p0(request):
    """
    OSPF Route map - Verify OSPF route map support functionality.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    redistribute_ospf(tgen, topo, "r0", "static")

    dut = "r1"
    lsid = NETWORK["ipv4"][0].split("/")[0]
    rid = routerids[0]
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    redistribute_ospf(tgen, topo, "r0", "static", delete=True)

    step("Create prefix-list in R0 to permit 10.0.20.1/32 prefix &"
         " deny 10.0.20.2/32")

    # Create ip prefix list
    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [
                        {
                            "seqid": 10,
                            "network": NETWORK["ipv4"][0],
                            "action": "permit",
                        },
                        {
                            "seqid": 11,
                            "network": "any",
                            "action": "deny"
                        },
                    ]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_1_ipv4"
                        }
                    },
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure route map rmap1 and redistribute static routes to"
         " ospf using route map rmap1")

    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")

    step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1")
    # Create ip prefix list
    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [
                        {
                            "seqid": 10,
                            "network": NETWORK["ipv4"][1],
                            "action": "permit",
                        },
                        {
                            "seqid": 11,
                            "network": "any",
                            "action": "deny"
                        },
                    ]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.")
    dut = "r1"
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][1],
                "no_of_ip": 1,
                "next_hop": "Null0"
            }]
        }
    }
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "next_hop": "Null0"
            }]
        }
    }
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    step("Delete and reconfigure prefix list.")
    # Create ip prefix list
    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [
                        {
                            "seqid": 10,
                            "network": NETWORK["ipv4"][1],
                            "action": "permit",
                            "delete": True,
                        },
                        {
                            "seqid": 11,
                            "network": "any",
                            "action": "deny",
                            "delete": True,
                        },
                    ]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0"
            }]
        }
    }
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [
                        {
                            "seqid": 10,
                            "network": NETWORK["ipv4"][1],
                            "action": "permit",
                        },
                        {
                            "seqid": 11,
                            "network": "any",
                            "action": "deny"
                        },
                    ]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.")
    dut = "r1"
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][1],
                "no_of_ip": 1,
                "next_hop": "Null0"
            }]
        }
    }
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "next_hop": "Null0"
            }]
        }
    }
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    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)
Example #7
0
def test_static_routes(request):
    """ Test to create and verify static routes. """

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

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

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    # Api call to create static routes
    input_dict = {
        "r1": {
            "static_routes": [
                {
                    "network": "10.0.20.1/32",
                    "no_of_ip": 9,
                    "admin_distance": 100,
                    "next_hop": "10.0.0.2",
                }
            ]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    # Api call to redistribute static routes
    input_dict_1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [
                                {"redist_type": "static"},
                                {"redist_type": "connected"},
                            ]
                        }
                    }
                }
            }
        }
    }

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

    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"
    next_hop = ["10.0.0.2", "10.0.0.5"]
    result = verify_rib(
        tgen, "ipv4", dut, input_dict, next_hop=next_hop, protocol=protocol
    )
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
def test_ospf_type5_summary_tc44_p0(request):
    """OSPF summarisation with type7 LSAs"""

    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("Bring up the base config as per the topology")
    step("Configure area 1 as NSSA Area")

    reset_config_on_routers(tgen)

    dut = "r0"
    protocol = "ospf"

    red_static(dut)
    input_dict_static_rtes = {
        "r0": {
            "static_routes": [
                {
                    "network": NETWORK["ipv4"],
                    "next_hop": "blackhole"
                },
                {
                    "network": NETWORK2["ipv4"],
                    "next_hop": "blackhole"
                },
            ]
        }
    }
    result = create_static_routes(tgen, input_dict_static_rtes)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that routes are learnt on R1.")
    dut = "r1"

    result = verify_ospf_rib(tgen, dut, input_dict_static_rtes)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict_static_rtes,
                        protocol=protocol)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)

    step("Configure External Route summary in R0 to summarise 5"
         " routes to one route.")

    ospf_summ_r0 = {
        "r0": {
            "ospf": {
                "summary-address": [{
                    "prefix": SUMMARY["ipv4"][0].split("/")[0],
                    "mask": "8"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_summ_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that external routes are summarised to configured summary "
         "address on R0 after 5 secs of delay timer expiry and only one "
         "route is sent to R1.")

    step("Configure summary & redistribute static/connected route with "
         "metric type 2")

    input_dict_summary = {
        "r0": {
            "static_routes": [{
                "network": SUMMARY["ipv4"][3]
            }]
        }
    }
    dut = "r1"

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

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict_summary,
                        protocol=protocol)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)

    step("Verify that show ip ospf summary should show the summaries.")
    input_dict = {
        SUMMARY["ipv4"][3]: {
            "Summary address": SUMMARY["ipv4"][3],
            "Metric-type": "E2",
            "Metric": 20,
            "Tag": 0,
            "External route count": 5,
        }
    }
    dut = "r0"
    result = verify_ospf_summary(tgen, topo, dut, input_dict)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(
        tc_name)

    step("Learn type 7 lsa from neighbours")

    dut = "r1"
    protocol = "ospf"

    red_static(dut)
    input_dict_static_rtes = {
        "r1": {
            "static_routes": [{
                "network": NETWORK3["ipv4"],
                "next_hop": "blackhole"
            }]
        }
    }
    result = create_static_routes(tgen, input_dict_static_rtes)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that routes are learnt on R0.")
    dut = "r0"

    result = verify_ospf_rib(tgen, dut, input_dict_static_rtes)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict_static_rtes,
                        protocol=protocol)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)

    ospf_summ_r0 = {
        "r0": {
            "ospf": {
                "summary-address": [{
                    "prefix": SUMMARY["ipv4"][2].split("/")[0],
                    "mask": "8"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_summ_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that type7 LSAs received from neighbor are not summarised.")
    input_dict = {
        "13.0.0.0/8": {
            "Summary address": "13.0.0.0/8",
            "Metric-type": "E2",
            "Metric": 20,
            "Tag": 0,
            "External route count": 0,
        }
    }
    dut = "r0"
    result = verify_ospf_summary(tgen, topo, dut, input_dict)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(
        tc_name)

    step("Verify that already originated summary is intact.")
    input_dict = {
        SUMMARY["ipv4"][3]: {
            "Summary address": SUMMARY["ipv4"][3],
            "Metric-type": "E2",
            "Metric": 20,
            "Tag": 0,
            "External route count": 5,
        }
    }
    dut = "r0"
    result = verify_ospf_summary(tgen, topo, dut, input_dict)
    assert (
        result is True
    ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(
        tc_name)

    dut = "r1"
    aggr_timer = {"r1": {"ospf": {"aggr_timer": 6}}}
    result = create_router_ospf(tgen, topo, aggr_timer)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    ospf_summ_r0 = {
        "r0": {
            "ospf": {
                "summary-address": [{
                    "prefix": SUMMARY["ipv4"][2].split("/")[0],
                    "mask": "8"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_summ_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("wait for 6+1 seconds as ospf aggregation start after 6 secs as "
         "per the above aggr_timer command")
    sleep(7)
    dut = "r1"
    aggr_timer = {"r1": {"ospf": {"del_aggr_timer": 6}}}
    result = create_router_ospf(tgen, topo, aggr_timer)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
Example #9
0
def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
    """
    Verify static route ECMP functionality with 8 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 8 interfaces / links between R1 and R2,")
    step("Configure IPv4 static route in R2 with 8 next hop"
         "N1(21.1.1.2), N2(22.1.1.2), N3(23.1.1.2), N4(24.1.1.2),"
         "N5(25.1.1.2), N6(26.1.1.2), N7(27.1.1.2),N8(28.1.1.2), Static"
         "route next-hop present on R1")

    step("Configure IBGP IPv4 peering between R2 and R3 router.")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][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)
        logger.info("Verifying %s routes on r2", addr_type)
        nh = [
            NEXT_HOP_IP["nh1"][addr_type],
            NEXT_HOP_IP["nh2"][addr_type],
            NEXT_HOP_IP["nh3"][addr_type],
            NEXT_HOP_IP["nh4"][addr_type],
            NEXT_HOP_IP["nh5"][addr_type],
            NEXT_HOP_IP["nh6"][addr_type],
            NEXT_HOP_IP["nh7"][addr_type],
            NEXT_HOP_IP["nh8"][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 are" " missing in RIB".format(
            tc_name)
    step("Configure redistribute static in BGP on R2 router")
    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("Remove the static route configured with nexthop N1 to N8, one"
         "by one from running config")
    for addr_type in ADDR_TYPES:
        # delete static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][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)

        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 are" " still present in RIB".format(
            tc_name)

    step("Configure the static route with nexthop N1 to N8, one by" "one")

    for addr_type in ADDR_TYPES:
        # add static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][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)

    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("Random shut of the nexthop interfaces")
    randnum = random.randint(0, 7)
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        input_dict_5 = {
            "r2": {
                "static_routes": [{
                    "network":
                    PREFIX1[addr_type],
                    "next_hop":
                    NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
                }]
            }
        }
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_5,
            next_hop=nhip,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
            tc_name)

    step("Random no shut of the nexthop interfaces")
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_5,
                            next_hop=nhip,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \n" "Error: Routes are missing 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")

    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)

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

    Test extended capability nexthop , restart frr.

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

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

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

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

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

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

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

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

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

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

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

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

    # verify the routes with nh as ext_nh
    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [{
                "network": NETWORK_CMD_IP,
                "no_of_ip": 1,
                "next_hop": llip
            }]
        }
    }
    bgp_rib = verify_rib(tgen,
                         "ipv4",
                         dut,
                         verify_nh_for_nw_rtes,
                         next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, bgp_rib)
    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        verify_nh_for_nw_rtes,
                        next_hop=llip,
                        protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    write_test_footer(tc_name)
Example #11
0
def test_ospf_lan_ecmp_tc18_p0(request):
    """
    OSPF ECMP.

    Verify OSPF ECMP with max path configured as 8
    (Edge having 1 uplink port as broadcast network,
    connect to 8 TORs - LAN case)

    """
    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
    step("Bring up the base config as per the topology")
    step(". Configure ospf in all the routers on LAN interface.")
    reset_config_on_routers(tgen)
    step("Verify that OSPF is up with 8 neighborship sessions.")

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

    step("Configure a static route in all the routes and "
         "redistribute static/connected in OSPF.")

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

        dut = rtr
        red_static(dut)

    step("Verify that route in R0 in stalled with 8 hops. "
         "Verify ospf route table and ip route table.")

    nh = []
    for rtr in topo["routers"]:
        nh.append(topo["routers"][rtr]["links"]["s1"]["ipv4"].split("/")[0])
    nh.remove(topo["routers"]["r1"]["links"]["s1"]["ipv4"].split("/")[0])
    dut = "r1"
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    step(" clear ip ospf interface on DUT(r0)")
    clear_ospf(tgen, "r0")

    step("Verify that after clearing the ospf interface all the "
         "neighbours are up and routes are installed with 8 next hop "
         "in ospf and ip route tables on R0")

    dut = "r0"
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step(" clear ip ospf interface on R2")
    clear_ospf(tgen, "r2")

    dut = "r2"
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Delete static/connected cmd in ospf in all the routes one by one.")
    for rtr in topo["routers"]:
        input_dict = {
            rtr: {
                "static_routes": [{
                    "network": NETWORK["ipv4"][0],
                    "no_of_ip": 5,
                    "next_hop": "Null0",
                    "delete": True,
                }]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Verify that all the routes are withdrawn from R0")
    dut = "r1"
    result = verify_ospf_rib(tgen,
                             dut,
                             input_dict,
                             next_hop=nh,
                             attempts=5,
                             expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    write_test_footer(tc_name)
Example #12
0
def test_ospf_ecmp_tc17_p0(request):
    """
    Verify OSPF ECMP.

    Verify OSPF ECMP with max path configured as 2 (Edge having 2 uplink ports)
    """
    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
    step("Bring up the base config as per the topology")
    step("Configure 2 interfaces between R1 and R2 & enable ospf in area 0.")
    reset_config_on_routers(tgen)
    step("Verify that OSPF is up with 2 neighborship sessions.")
    dut = "r1"
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Configure a static route in R0 and redistribute in OSPF.")

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

    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static")

    step("Verify that route in R2 in stalled with 2 next hops.")

    nh1 = topo["routers"]["r0"]["links"]["r1-link1"]["ipv4"].split("/")[0]
    nh2 = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
    nh = [nh1, nh2]

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

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

    step(" Un configure static route on R0")

    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static", delete=True)
    # sleep till the route gets withdrawn
    sleep(10)

    step("Verify that route is withdrawn from R2.")
    dut = "r1"
    result = verify_ospf_rib(tgen,
                             dut,
                             input_dict,
                             next_hop=nh,
                             attempts=5,
                             expected=False)
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present \n Error: {}".format(tc_name, result))

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

    step("Reconfigure the static route in R0.Change ECMP value to 2.")
    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static")

    step("Configure cost on R0 as 100")
    r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 100}}}}}
    result = config_ospf_interface(tgen, topo, r0_ospf_cost)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

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

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

    write_test_footer(tc_name)
Example #13
0
def test_ospf_ecmp_tc16_p0(request):
    """
    Verify OSPF ECMP.

    Verify OSPF ECMP with max path configured as 8 (ECMP
    configured at FRR level)
    """
    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
    step("Bring up the base config as per the topology")
    step("Configure 8 interfaces between R1 and R2 and enable ospf in area 0.")
    reset_config_on_routers(tgen)
    step("Verify that OSPF is up with 8 neighborship sessions.")
    dut = "r1"
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Configure a static route in R0 and redistribute in OSPF.")

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

    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static")

    step("Verify that route in R2 in stalled with 8 next hops.")
    nh = []
    for item in range(1, 7):
        nh.append(
            topo["routers"]["r0"]["links"]["r1-link1"]["ipv4"].split("/")[0])

    nh2 = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]

    nh.append(nh2)

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

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

    step("shut no shut all the interfaces on the remote router - R2")
    dut = "r1"
    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

    result = verify_ospf_rib(tgen,
                             dut,
                             input_dict,
                             next_hop=nh,
                             expected=False)
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present \n Error: {}".format(tc_name, result))

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

    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

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

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

    step("shut no shut on all the interfaces on DUT (r1)")
    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

    step("Verify that all the neighbours are up and routes are installed"
         " with 8 next hop in ospf and ip route tables on R1.")

    step("Verify that OSPF is up with 8 neighborship sessions.")
    dut = "r1"
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

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

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

    step(" Un configure static route on R0")

    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static", delete=True)

    # Wait for R0 to flush external LSAs.
    sleep(10)

    step("Verify that route is withdrawn from R2.")
    dut = "r1"
    result = verify_ospf_rib(tgen,
                             dut,
                             input_dict,
                             next_hop=nh,
                             attempts=5,
                             expected=False)
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present \n Error: {}".format(tc_name, result))

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

    step("Re configure the static route in R0.")
    dut = "r0"
    redistribute_ospf(tgen, topo, dut, "static")

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

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

    write_test_footer(tc_name)
Example #14
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, result)

    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_ecmp_remove_static_route(request):
    """
    Delete static routes and verify routers are cleared from BGP table,
    and RIB of DUT.
    """

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

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

    reset_config_on_routers(tgen)

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

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

    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP[addr_type],
                    "delete": True,
                }]
            }
        }

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

        logger.info("Verifying %s routes on r3 are removed", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_2,
            next_hop=[],
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n Routes still" " present in RIB".format(
            tc_name)

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

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

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=NEXT_HOPS[addr_type],
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
Example #16
0
def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ibgp(request):
    """
    Verify static route ECMP functionality with 8 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)

    step("Configure 8 interfaces / links between R1 and R2,")
    step("Configure IBGP IPv4 peering between R2 and R3 router.")
    NEXT_HOP_IP = populate_nh()
    nh_all = {}
    for addr_type in ADDR_TYPES:
        nh_all[addr_type] = []
        for nhp in range(1, 9):
            nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
    step("Configure IPv4 static route in R2 with 8 next hop"
         "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
         "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
         "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
         "present on R1")
    for addr_type in ADDR_TYPES:
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                    }]
                }
            }
            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)
        logger.info("Verifying %s routes on r2", addr_type)

        step("On R2, static route installed in RIB using "
             "show ip route with 8 next hop, lowest AD nexthop is active")
        step("On R2, static route with lowest AD nexthop installed in FIB")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        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,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    step("Configure redistribute static in BGP on R2 router")
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }

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

        step("After configuring them, route is always active with lowest AD"
             "value and all the nexthop populated in RIB and FIB again ")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        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,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

    step("Remove the static route configured with nexthop N1 to N8, one"
         "by one from running config")

    for addr_type in ADDR_TYPES:
        # delete static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                        "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 N1 to N8 one by one, "
         "route become active with next preferred nexthop and nexthop which "
         "got removed is not shown in RIB and FIB")
    result = verify_rib(
        tgen,
        addr_type,
        dut,
        input_dict_4,
        next_hop=nh_all[addr_type],
        protocol=protocol,
        expected=False,
    )
    assert (
        result is not True
    ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
        tc_name)

    step("Configure the static route with nexthop N1 to N8, one by" "one")
    for addr_type in ADDR_TYPES:
        # add static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                    }]
                }
            }
        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 with lowest AD nexthop installed in FIB")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        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,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    step("Random shut of the nexthop interfaces")
    randnum = random.randint(0, 7)
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        input_dict_5 = {
            "r2": {
                "static_routes": [{
                    "network":
                    PREFIX1[addr_type],
                    "next_hop":
                    NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
                }]
            }
        }
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_5,
            next_hop=nhip,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
            tc_name)

    step("Random no shut of the nexthop interfaces")
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_5,
                            next_hop=nhip,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \n" "Error: Routes are missing 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")

    step("After reload of FRR router, static route installed "
         "in RIB and FIB properly .")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        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,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    step("Remove the redistribute static knob")

    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static",
                                    "delete": True
                                }]
                            }
                        }
                    }
                }
            }
        }

        logger.info("Remove redistribute 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 routes are deleted from R3 routing table")
        dut = "r3"
        protocol = "bgp"
        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 are"
            " still present in RIB of R3".format(tc_name))

    write_test_footer(tc_name)
def test_ecmp_remove_nw_advertise(request):
    """
    Verify routes are cleared from BGP and RIB table of DUT,
    when advertise network configuration is removed
    """

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

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

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

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

    input_dict_3 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "advertise_networks": [{
                                "network": NETWORK["ipv4"],
                                "delete": True
                            }]
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "advertise_networks": [{
                                "network": NETWORK["ipv6"],
                                "delete": True
                            }]
                        }
                    },
                }
            }
        }
    }

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

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

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict,
            next_hop=[],
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n Routes still" " present in RIB".format(
            tc_name)

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

    write_test_footer(tc_name)
Example #18
0
def test_bgp_local_nexthop_p1_tc14_ibgp(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 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)
Example #20
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)
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)
Example #22
0
def test_route_summarisation_with_as_set_p1(request):
    """
    Verify route summarisation with as-set for redistributed 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],
                            NETWORK_1_4[addr_type],
                            NETWORK_1_5[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],
                            NETWORK_1_4[addr_type],
                            NETWORK_1_5[addr_type],
                        ]
                    }
                ]
            }
        }

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

    step(
        "Configure a route-map to attach a unique community attribute value "
        "to each of these prefixes, while re-distributing static."
    )

    for addr_type in ADDR_TYPES:
        for pfx, seq_id, network, in zip(
            [1, 2, 3, 4, 5],
            [10, 20, 30, 40, 50],
            [NETWORK_1_1, NETWORK_1_2, NETWORK_1_3, NETWORK_1_4, NETWORK_1_5],
        ):
            prefix_list = {
                "r1": {
                    "prefix_lists": {
                        addr_type: {
                            "pf_list_{}_{}".format(addr_type, pfx): [
                                {
                                    "seqid": seq_id,
                                    "network": network[addr_type],
                                    "action": "permit",
                                }
                            ]
                        }
                    }
                }
            }
            result = create_prefix_lists(tgen, prefix_list)
            assert result is True, "Test case {} : Failed \n Error: {}".format(
                tc_name, result
            )

    step("Create route-map for applying prefix-list on r1")

    for addr_type in ADDR_TYPES:
        for pfx, comm_id in zip([1, 2, 3, 4, 5], [0, 1, 2, 3, 4]):
            route_map = {
                "r1": {
                    "route_maps": {
                        "rmap_{}".format(addr_type): [
                            {
                                "action": "permit",
                                "match": {
                                    addr_type: {
                                        "prefix_lists": "pf_list_{}_{}".format(
                                            addr_type, pfx
                                        )
                                    }
                                },
                                "set": {"community": {"num": COMMUNITY[comm_id]}},
                            }
                        ]
                    }
                }
            }

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

    step("Re-configure redistribute static with route-map")

    for addr_type in ADDR_TYPES:
        input_redistribute = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [
                                    {
                                        "redist_type": "static",
                                        "attribute": {
                                            "route-map": "rmap_{}".format(addr_type)
                                        },
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }

        result = create_router_bgp(tgen, topo, input_redistribute)
        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], "as_set": 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 summarised route on router R3 with all the "
        "community attribute values combined with that aggregate route."
    )

    for addr_type in ADDR_TYPES:
        input_dict = {"community": COMMUNITY[5]}
        result = verify_bgp_community(
            tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict
        )
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Remove static routes as below: "
        "(no) ip route 10.1.1.0/24 blackhole "
        "(no) ip route 10.1.2.0/24 blackhole "
        "(no) ipv6 route 10:1::1:0/120 blackhole "
        "(no) ipv6 route 10:1::2:0/120 blackhole "
    )

    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": True,
                    }
                ]
            }
        }

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

    step(
        "Verify on R3 that whenever we remove the static routes, we still"
        " see aggregated route however the corresponding community attribute"
        "values are withdrawn."
    )

    for addr_type in ADDR_TYPES:
        input_dict = {"community": COMMUNITY[6]}
        result = verify_bgp_community(
            tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict
        )
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Add/remove a new network with community value, each one from out of "
        "aggregation range and other within aggregation range. "
    )

    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], NETWORK_4_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:
        for pfx, seq_id, network, in zip([6, 7], [60, 70], [NETWORK_3_1, NETWORK_4_1]):
            prefix_list = {
                "r1": {
                    "prefix_lists": {
                        addr_type: {
                            "pf_list_{}_{}".format(addr_type, pfx): [
                                {
                                    "seqid": seq_id,
                                    "network": network[addr_type],
                                    "action": "permit",
                                }
                            ]
                        }
                    }
                }
            }
            result = create_prefix_lists(tgen, prefix_list)
            assert result is True, "Test case {} : Failed \n Error: {}".format(
                tc_name, result
            )

    step("Create route-map for applying prefix-list on r1")

    for addr_type in ADDR_TYPES:
        for pfx, comm_id in zip([6, 7], [7, 8]):
            route_map = {
                "r1": {
                    "route_maps": {
                        "rmap_{}".format(addr_type): [
                            {
                                "action": "permit",
                                "match": {
                                    addr_type: {
                                        "prefix_lists": "pf_list_{}_{}".format(
                                            addr_type, pfx
                                        )
                                    }
                                },
                                "set": {"community": {"num": COMMUNITY[comm_id]}},
                            }
                        ]
                    }
                }
            }

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

    step(
        "Verify on R3 when route is added within the summary range, aggregated"
        " route also has associated community value added. However if the route"
        " is beyond the summary range the aggregated route would have no impact"
    )

    for addr_type in ADDR_TYPES:
        input_dict = {"community": COMMUNITY[9]}
        result = verify_bgp_community(
            tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict
        )
        assert result is True, "Test case {} : 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],
                                            "as_set": 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 that when as-set command is removed, we do not see community "
            "attribute added to summarised route on R3. However when as-set option "
            "is re-added, all the community attribute values must appear with "
            "summarised route."
        )

        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
                )

                input_dict = {"community": COMMUNITY[9]}
                result = verify_bgp_community(
                    tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict
                )
                assert result is True, "Test case {} : Failed \n Error: {}".format(
                    tc_name, result
                )

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc22_p0(request):
    """
    OSPF Route map - Multiple sequence numbers.

    Verify OSPF route map support  functionality with multiple sequence
    numbers in a single  route-map for different match/set clauses.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")

    reset_config_on_routers(tgen)

    step("Configure route map with seq number 10 to with ip prefix"
         " permitting route 10.0.20.1/32 in R1")
    step("Configure route map with seq number 20 to with  ip prefix"
         "  permitting route 10.0.20.2/32 in R1")

    # Create route map
    input_dict_3 = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [
                    {
                        "action": "permit",
                        "seq_id": "10",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_1_ipv4"
                            }
                        },
                    },
                    {
                        "action": "permit",
                        "seq_id": "20",
                        "match": {
                            "ipv4": {
                                "prefix_lists": "pf_list_2_ipv4"
                            }
                        },
                    },
                ]
            }
        }
    }
    result = create_route_maps(tgen, input_dict_3)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    # Create ip prefix list
    input_dict_2 = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [{
                        "seqid": 10,
                        "network": NETWORK["ipv4"][0],
                        "action": "permit"
                    }]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, input_dict_2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    # Create ip prefix list
    input_dict_2 = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_2_ipv4": [{
                        "seqid": 10,
                        "network": NETWORK["ipv4"][1],
                        "action": "permit"
                    }]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, input_dict_2)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

    step("Verify that both routes are learned in R1 and R2")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

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

    step("Change route map with seq number 20 to deny.")
    # Create route map
    input_dict_3 = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "deny",
                    "seq_id": "20",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_2_ipv4"
                        }
                    },
                }]
            }
        }
    }
    result = create_route_maps(tgen, input_dict_3)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify the route 10.0.20.2/32 is withdrawn and not present "
         "in the routing table of R0 and R1.")

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][1],
                "next_hop": "Null0"
            }]
        }
    }

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

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

    dut = "r2"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

    write_test_footer(tc_name)
def test_modify_ecmp_max_paths(request, ecmp_num, test_type):
    """
    Verify routes installed as per maximum-paths
    configuration (8/16/32).
    """

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

    reset_config_on_routers(tgen)

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

    input_dict = {
        "r3": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "maximum_paths": {
                                "ebgp": ecmp_num,
                            }
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "maximum_paths": {
                                "ebgp": ecmp_num,
                            }
                        }
                    },
                }
            }
        }
    }

    logger.info("Configuring bgp maximum-paths %s on router r3", ecmp_num)
    result = create_router_bgp(tgen, topo, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

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

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc20_p0(request):
    """
    OSPF route map support functionality.

    Verify OSPF route map support functionality when route map is not
    configured at system level but configured in OSPF

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Redistribute to ospf using route map ( non existent route map)")
    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")

    step("Verify that routes are not allowed in OSPF even tough no "
         "matching routing map is configured.")

    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen,
                             dut,
                             input_dict,
                             retry_timeout=4,
                             expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    step("configure the route map with the same name that is used "
         "in the ospf with deny rule.")

    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that now route map is activated & routes are denied in OSPF.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that now route map is activated & routes are denied in OSPF.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    step("Delete the route map.")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "deny",
                    "delete": True
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that routes are allowed in OSPF even tough "
         "no matching routing map is configured.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
        tc_name, result)

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

    write_test_footer(tc_name)
def test_ecmp_after_clear_bgp(request, test_type):
    """ Verify BGP table and RIB in DUT after clear BGP routes and neighbors"""

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

    reset_config_on_routers(tgen)

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

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

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

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

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

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

    write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc24_p0(request):
    """
    OSPF Route map - Multiple set clauses.

    Verify OSPF route map support functionality when we
    add/remove route-maps with multiple match clauses and without
    any set statement.(Match only)

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32) in R1 and redistribute to "
         "OSPF using route map.")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")

    # Create ip prefix list
    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [{
                        "seqid": 10,
                        "network": "any",
                        "action": "permit"
                    }]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that prefix-list is created in R0.")
    result = verify_prefix_lists(tgen, pfx_list)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
        tc_name, result)

    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_1_ipv4"
                        }
                    },
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that metric falls back to original metric for ospf routes.")
    dut = "r1"
    protocol = "ospf"

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

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

    step("Create static routes(10.0.20.1/32) in R1 and redistribute to "
         "OSPF using route map.")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][1],
                "no_of_ip": 1,
                "next_hop": "Null0",
                "tag": 1000,
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    # Create ip prefix list
    pfx_list = {
        "r0": {
            "prefix_lists": {
                "ipv4": {
                    "pf_list_1_ipv4": [{
                        "seqid": 10,
                        "network": "any",
                        "action": "permit"
                    }]
                }
            }
        }
    }
    result = create_prefix_lists(tgen, pfx_list)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that prefix-list is created in R0.")
    result = verify_prefix_lists(tgen, pfx_list)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
        tc_name, result)

    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "tag": "1000"
                        }
                    }
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that metric falls back to original metric for ospf routes.")
    dut = "r1"
    protocol = "ospf"

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

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

    step("Delete the match clause with tag in route map")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "tag": "1000",
                            "delete": True
                        }
                    },
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that metric falls back to original metric for ospf routes.")
    dut = "r1"
    protocol = "ospf"

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

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

    step("Delete the match clause with metric in route map.")

    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "permit",
                    "match": {
                        "ipv4": {
                            "prefix_lists": "pf_list_1_ipv4"
                        }
                    },
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

    write_test_footer(tc_name)
def test_ecmp_shut_bgp_neighbor(request, test_type):
    """ Shut BGP neigbors one by one and verify BGP and routing table updated
        accordingly in DUT """

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

    logger.info(INTF_LIST_R2)
    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"

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

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

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

    for intf_num in range(len(INTF_LIST_R2) + 1, 16):
        intf_val = INTF_LIST_R2[intf_num:intf_num + 16]

        input_dict_1 = {"r2": {"interface_list": [intf_val], "status": "down"}}
        logger.info(
            "Shutting down neighbor interface {} on r2".format(intf_val))
        result = interface_status(tgen, topo, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        for addr_type in ADDR_TYPES:
            if intf_num + 16 < 32:
                check_hops = NEXT_HOPS[addr_type]
            else:
                check_hops = []

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

    input_dict_1 = {"r2": {"interface_list": INTF_LIST_R2, "status": "up"}}

    logger.info("Enabling all neighbor interface {} on r2")
    result = interface_status(tgen, topo, input_dict_1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

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

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

    write_test_footer(tc_name)
Example #29
0
def test_ospf_redistribution_tc5_p0(request):
    """Test OSPF intra area route calculations."""
    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
    step("Bring up the base config.")
    reset_config_on_routers(tgen)

    step("Verify that OSPF neighbors are FULL.")
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence
    )

    step("verify intra area route is calculated for r0-r3 interface ip in R1")
    ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
    ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
    nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
    input_dict = {
        "r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1, "routeType": "N"}]}
    }

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

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

    step("Delete the ip address on newly configured interface of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
                    "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
                    "delete": True,
                }
            }
        }
    }

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

    dut = "r1"
    for num in range(0, nretry):
        result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False)
        if result is not True:
            break

    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present after deleting ip address of newly "
        "configured interface of R0 \n Error: {}".format(tc_name, result)
    )

    protocol = "ospf"
    result = verify_rib(
        tgen,
        "ipv4",
        dut,
        input_dict,
        protocol=protocol,
        next_hop=nh,
        retry_timeout=10,
        expected=False,
    )
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present in fib after deleting ip address of newly "
        "configured interface of R0 \n Error: {}".format(tc_name, result)
    )

    step("Add back the deleted ip address on newly configured interface of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
                    "interface": topo["routers"]["r0"]["links"]["r3"]["interface"],
                }
            }
        }
    }

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

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

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

    step("Shut no shut interface on R0")
    dut = "r0"
    intf = topo["routers"]["r0"]["links"]["r3"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    step("un shut the OSPF interface on R0")
    dut = "r0"
    shutdown_bringup_interface(tgen, dut, intf, True)

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

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

    write_test_footer(tc_name)
Example #30
0
def test_BGP_GR_15_p2(request):
    """
    Test Objective : Test GR scenarios by enabling Graceful Restart
    for multiple address families..
    """

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

    # Check router status
    check_router_status(tgen)

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

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    write_test_footer(tc_name)