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_ext_nh_cap_red_static_network_ebgp_peer_tc8_p0(request): """ Test exted capability nexthop with route map in. Verify IPv4 routes advertise using "redistribute static" and "network command" are received on EBGP peer with IPv6 nexthop """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("Configure IPv6 EBGP session between R1 and R2 with global" " IPv6 address") reset_config_on_routers(tgen) step("Enable capability extended-nexthop on the nbr from both the " " routers Activate same IPv6 nbr from IPv4 unicast family") step(" Configure 2 IPv4 static " "routes on R1 (nexthop for static route exists on different " "link of R0") for rte in range(0, NO_OF_RTES): # Create Static routes input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv4"][rte], "no_of_ip": 1, "next_hop": NEXT_HOP["ipv4"][rte], }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for rte in range(0, NO_OF_RTES): # Create Static routes input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv6"][rte], "no_of_ip": 1, "next_hop": NEXT_HOP["ipv6"][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": { "local_as": "100", "default_ipv4_unicast": "True", "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static" }], "advertise_networks": [{ "network": NETWORK_CMD_IP, "no_of_network": 1 }], } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static" }] } }, }, } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) glip = get_llip("r1", "r2-link0") assert glip is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("IPv4 and IPv6 routes advertised using static and network command " "are received on R2 BGP & routing table , verify using show ip bgp " "show ip route for IPv4 routes and show bgp ipv6,show ipv6 routes " "for IPv6 routes .") dut = "r2" protocol = "bgp" for addr_type in ADDR_TYPES: # verify the routes with nh as ext_nh verify_nh_for_static_rtes = { "r1": { "static_routes": [{ "network": NETWORK[addr_type][0], "no_of_ip": 2, "next_hop": glip, }] } } bgp_rib = verify_bgp_rib(tgen, addr_type, dut, verify_nh_for_static_rtes, next_hop=glip) assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format( tc_name, bgp_rib) result = verify_rib( tgen, addr_type, dut, verify_nh_for_static_rtes, next_hop=glip, protocol=protocol, ) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify IPv4 routes are installed with IPv6 global nexthop of R1" " R1 to R2 connected link") verify_nh_for_nw_cmd_rtes = { "r1": { "static_routes": [{ "network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": glip, }] } } bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glip) assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format( tc_name, bgp_rib) result = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glip, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result)
def test_ospfv3_nssa_tc26_p0(request): """Verify that ospf non back bone area can be configured as NSSA area""" 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(): check_router_status(tgen) global topo step("Bring up the base config as per the topology") step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area") reset_config_on_routers(tgen) input_dict = { "r2": { "static_routes": [{ "network": NETWORK["ipv6"][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" red_static(dut) step("Verify that Type 5 LSA is originated by R2.") dut = "r0" protocol = "ospf6" result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Un configure redistribute command in R4") dut = "r2" red_static(dut, config=False) input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network" }] } } step("Configure area 0 on interface of r2 connecting to r1") input_dict = { "r2": { "links": { "r1": { "interface": topo["routers"]["r2"]["links"]["r1"]["interface"], "ospf6": { "area": "0.0.0.2" }, "delete": True, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) input_dict = { "r2": { "links": { "r1": { "interface": topo["routers"]["r2"]["links"]["r1"]["interface"], "ospf6": { "area": "0.0.0.0" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("verify that ospf neighbor goes down between r2 and r1.") result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False) assert (result is not True ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format( tc_name, result) step("Now configure area 0 on interface of r1 connecting to r2.") input_dict = { "r1": { "links": { "r2": { "interface": topo["routers"]["r1"]["links"]["r2"]["interface"], "ospf6": { "area": "0.0.0.2" }, "delete": True, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) input_dict = { "r1": { "links": { "r2": { "interface": topo["routers"]["r1"]["links"]["r2"]["interface"], "ospf6": { "area": "0.0.0.0" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that ospf neighbour comes up between r2 and r1.") result = verify_ospf6_neighbor(tgen, topo, dut="r2") assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure area 2 on interface of r2 connecting to r1.") input_dict = { "r2": { "links": { "r1": { "interface": topo["routers"]["r2"]["links"]["r1"]["interface"], "ospf6": { "area": "0.0.0.0" }, "delete": True, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) input_dict = { "r2": { "links": { "r1": { "interface": topo["routers"]["r2"]["links"]["r1"]["interface"], "ospf6": { "area": "0.0.0.2" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("verify that ospf neighbor goes down between r2 and r1.") result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False) assert (result is not True ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format( tc_name, result) step("Now configure area 2 on interface of r1 connecting to r2.") input_dict = { "r1": { "links": { "r2": { "interface": topo["routers"]["r1"]["links"]["r2"]["interface"], "ospf6": { "area": "0.0.0.0" }, "delete": True, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) input_dict = { "r1": { "links": { "r2": { "interface": topo["routers"]["r1"]["links"]["r2"]["interface"], "ospf6": { "area": "0.0.0.2" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that ospf neighbour comes up between r2 and r1.") result = verify_ospf6_neighbor(tgen, topo, dut="r2") assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospfv3_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_ospf6_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["ipv6"][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" red_static(dut) llip = get_llip("r0", "r1-link1") assert llip is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route in R2 in stalled with 8 next hops.") nh = [] for item in range(1, 7): nh.append(llip) llip = get_llip("r0", "r1") assert llip is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) nh2 = llip nh.append(nh2) dut = "r1" result = verify_ospf6_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, "ipv6", 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_ospf6_rib(tgen, dut, input_dict, next_hop=nh, expected=False) assert ( result is not True ), "Testcase {} : Failed \n Route present in OSPF RIB. Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh, expected=False) assert ( result is not True ), "Testcase {} : Failed \n Route present in RIB. 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_ospf6_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, "ipv6", 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_ospf6_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) dut = "r1" result = verify_ospf6_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, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_dynamic_import_ecmp_imported_routed_diffrent_vrfs_p0(request): """ Verify ECMP for imported routes from different VRFs. """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) if tgen.routers_have_failure(): check_router_status(tgen) reset_config_on_routers(tgen) step("Configure same static routes in tenant vrfs RED and GREEN on router " "R3 and redistribute in respective BGP process") for vrf_name in ["RED", "GREEN"]: for addr_type in ADDR_TYPES: if vrf_name == "GREEN": next_hop_vrf = topo["routers"]["r1"]["links"][ "r3-link3"][addr_type].split("/")[0] else: next_hop_vrf = topo["routers"]["r2"]["links"][ "r3-link1"][addr_type].split("/")[0] static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], "next_hop": next_hop_vrf, "vrf": vrf_name } ] } } result = create_static_routes(tgen, static_routes) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Redistribute static route on BGP VRF : {}".format(vrf_name)) temp = {} for addr_type in ADDR_TYPES: temp.update({ addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } }) redist_dict = {"r3": {"bgp": [{ "vrf": vrf_name, "local_as": 3, "address_family": temp }]}} result = create_router_bgp(tgen, topo, redist_dict) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Verify that configured static routes are installed in respective " "BGP table for vrf RED & GREEN") for vrf_name in ["RED", "GREEN"]: for addr_type in ADDR_TYPES: if vrf_name == "GREEN": next_hop_vrf = topo["routers"]["r1"]["links"][ "r3-link3"][addr_type].split("/")[0] else: next_hop_vrf = topo["routers"]["r2"]["links"][ "r3-link1"][addr_type].split("/")[0] static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], "vrf": vrf_name } ] } } result = verify_bgp_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) result = verify_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) step("Import vrf RED and GREEN into default vrf and Configure ECMP") bgp_val = [] for vrf_name in ["RED", "GREEN"]: temp = {} for addr_type in ADDR_TYPES: temp.update({ addr_type: { "unicast": { "import": { "vrf": vrf_name }, "maximum_paths": { "ebgp": 2 } } } }) bgp_val.append({ "local_as": 3, "address_family": temp }) import_dict = {"r3": {"bgp": bgp_val}} result = create_router_bgp(tgen, topo, import_dict) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Configure bgp bestpath on router r3") r3_raw_config = { "r3": { "raw_config": [ "router bgp 3", "bgp bestpath as-path multipath-relax" ] } } result = apply_raw_config(tgen, r3_raw_config) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Verify that routes are imported with two different next-hop vrfs " "and IPs. Additionally R3 must do ECMP for both the routes.") for addr_type in ADDR_TYPES: next_hop_vrf = [ topo["routers"]["r2"]["links"]["r3-link1"][addr_type]. \ split("/")[0], topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \ split("/")[0] ] static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], } ] } } result = verify_bgp_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) result = verify_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) step("Now change the next-hop of static routes in vrf RED and GREEN to " "same IP address") for addr_type in ADDR_TYPES: next_hop_vrf = topo["routers"]["r1"]["links"][ "r3-link3"][addr_type].split("/")[0] static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], "next_hop": next_hop_vrf, "vrf": "RED" }, { "network": [NETWORK1_1[addr_type]], "next_hop": topo["routers"]["r2"]["links"][ "r3-link1"][addr_type].split("/")[0], "vrf": "RED", "delete": True } ] } } result = create_static_routes(tgen, static_routes) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Verify that now routes are imported with two different next-hop " "vrfs but same IPs. Additionally R3 must do ECMP for both the routes") for addr_type in ADDR_TYPES: next_hop_vrf = [ topo["routers"]["r1"]["links"]["r3-link3"][addr_type].\ split("/")[0], topo["routers"]["r1"]["links"]["r3-link3"][addr_type]. \ split("/")[0] ] static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], } ] } } result = verify_bgp_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) result = verify_rib(tgen, addr_type, "r3", static_routes, next_hop=next_hop_vrf) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) write_test_footer(tc_name)
def test_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)
def test_bgp_with_loopback_with_same_subnet_p1(request): """ Verify routes not installed in zebra when /32 routes received with loopback BGP session subnet """ tgen = get_topogen() if BGP_CONVERGENCE is not True: pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) step("Delete BGP seesion created initially") input_dict_r1 = { "r1": { "bgp": { "delete": True } }, "r2": { "bgp": { "delete": True } }, "r3": { "bgp": { "delete": True } }, "r4": { "bgp": { "delete": True } }, } result = create_router_bgp(tgen, topo, input_dict_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Create BGP session over loop address") topo_modify = deepcopy(topo) for routerN in sorted(topo["routers"].keys()): for addr_type in ADDR_TYPES: for bgp_neighbor in topo_modify["routers"][routerN]["bgp"][ "address_family"][addr_type]["unicast"]["neighbor"].keys(): # Adding ['source_link'] = 'lo' key:value pair topo_modify["routers"][routerN]["bgp"]["address_family"][ addr_type]["unicast"]["neighbor"][bgp_neighbor][ "dest_link"] = { "lo": { "source_link": "lo", "ebgp_multihop": 2 } } result = create_router_bgp(tgen, topo_modify["routers"]) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Disable IPv6 BGP nbr from ipv4 address family") raw_config = { "r1": { "raw_config": [ "router bgp {}".format( topo["routers"]["r1"]["bgp"]["local_as"]), "address-family ipv4 unicast", "no neighbor {} activate".format(topo["routers"]["r2"]["links"] ["lo"]["ipv6"].split("/")[0]), "no neighbor {} activate".format(topo["routers"]["r3"]["links"] ["lo"]["ipv6"].split("/")[0]), ] }, "r2": { "raw_config": [ "router bgp {}".format( topo["routers"]["r2"]["bgp"]["local_as"]), "address-family ipv4 unicast", "no neighbor {} activate".format(topo["routers"]["r1"]["links"] ["lo"]["ipv6"].split("/")[0]), "no neighbor {} activate".format(topo["routers"]["r3"]["links"] ["lo"]["ipv6"].split("/")[0]), ] }, "r3": { "raw_config": [ "router bgp {}".format( topo["routers"]["r3"]["bgp"]["local_as"]), "address-family ipv4 unicast", "no neighbor {} activate".format(topo["routers"]["r1"]["links"] ["lo"]["ipv6"].split("/")[0]), "no neighbor {} activate".format(topo["routers"]["r2"]["links"] ["lo"]["ipv6"].split("/")[0]), "no neighbor {} activate".format(topo["routers"]["r4"]["links"] ["lo"]["ipv6"].split("/")[0]), ] }, "r4": { "raw_config": [ "router bgp {}".format( topo["routers"]["r4"]["bgp"]["local_as"]), "address-family ipv4 unicast", "no neighbor {} activate".format(topo["routers"]["r3"]["links"] ["lo"]["ipv6"].split("/")[0]), ] }, } step("Configure kernel routes") result = apply_raw_config(tgen, raw_config) assert result is True, "Testcase {} : Failed Error: {}".format( tc_name, result) r1_ipv4_lo = topo["routers"]["r1"]["links"]["lo"]["ipv4"] r1_ipv6_lo = topo["routers"]["r1"]["links"]["lo"]["ipv6"] r2_ipv4_lo = topo["routers"]["r2"]["links"]["lo"]["ipv4"] r2_ipv6_lo = topo["routers"]["r2"]["links"]["lo"]["ipv6"] r3_ipv4_lo = topo["routers"]["r3"]["links"]["lo"]["ipv4"] r3_ipv6_lo = topo["routers"]["r3"]["links"]["lo"]["ipv6"] r4_ipv4_lo = topo["routers"]["r4"]["links"]["lo"]["ipv4"] r4_ipv6_lo = topo["routers"]["r4"]["links"]["lo"]["ipv6"] r1_r2 = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0] r2_r1 = topo["routers"]["r2"]["links"]["r1"]["ipv6"].split("/")[0] r1_r3 = topo["routers"]["r1"]["links"]["r3"]["ipv6"].split("/")[0] r3_r1 = topo["routers"]["r3"]["links"]["r1"]["ipv6"].split("/")[0] r2_r3 = topo["routers"]["r2"]["links"]["r3"]["ipv6"].split("/")[0] r3_r2 = topo["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0] r3_r4 = topo["routers"]["r3"]["links"]["r4"]["ipv6"].split("/")[0] r4_r3 = topo["routers"]["r4"]["links"]["r3"]["ipv6"].split("/")[0] r1_r2_ipv4 = topo["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0] r2_r1_ipv4 = topo["routers"]["r2"]["links"]["r1"]["ipv4"].split("/")[0] r1_r3_ipv4 = topo["routers"]["r1"]["links"]["r3"]["ipv4"].split("/")[0] r3_r1_ipv4 = topo["routers"]["r3"]["links"]["r1"]["ipv4"].split("/")[0] r2_r3_ipv4 = topo["routers"]["r2"]["links"]["r3"]["ipv4"].split("/")[0] r3_r2_ipv4 = topo["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0] r3_r4_ipv4 = topo["routers"]["r3"]["links"]["r4"]["ipv4"].split("/")[0] r4_r3_ipv4 = topo["routers"]["r4"]["links"]["r3"]["ipv4"].split("/")[0] r1_r2_intf = topo["routers"]["r1"]["links"]["r2"]["interface"] r2_r1_intf = topo["routers"]["r2"]["links"]["r1"]["interface"] r1_r3_intf = topo["routers"]["r1"]["links"]["r3"]["interface"] r3_r1_intf = topo["routers"]["r3"]["links"]["r1"]["interface"] r2_r3_intf = topo["routers"]["r2"]["links"]["r3"]["interface"] r3_r2_intf = topo["routers"]["r3"]["links"]["r2"]["interface"] r3_r4_intf = topo["routers"]["r3"]["links"]["r4"]["interface"] r4_r3_intf = topo["routers"]["r4"]["links"]["r3"]["interface"] ipv4_list = [ ("r1", r1_r2_intf, r2_ipv4_loopback), ("r1", r1_r3_intf, r3_ipv4_loopback), ("r2", r2_r1_intf, r1_ipv4_loopback), ("r2", r2_r3_intf, r3_ipv4_loopback), ("r3", r3_r1_intf, r1_ipv4_loopback), ("r3", r3_r2_intf, r2_ipv4_loopback), ("r3", r3_r4_intf, r4_ipv4_loopback), ("r4", r4_r3_intf, r3_ipv4_loopback), ] ipv6_list = [ ("r1", r1_r2_intf, r2_ipv6_loopback, r2_r1), ("r1", r1_r3_intf, r3_ipv6_loopback, r3_r1), ("r2", r2_r1_intf, r1_ipv6_loopback, r1_r2), ("r2", r2_r3_intf, r3_ipv6_loopback, r3_r2), ("r3", r3_r1_intf, r1_ipv6_loopback, r1_r3), ("r3", r3_r2_intf, r2_ipv6_loopback, r2_r3), ("r3", r3_r4_intf, r4_ipv6_loopback, r4_r3), ("r4", r4_r3_intf, r3_ipv6_loopback, r3_r4), ] for dut, intf, loop_addr in ipv4_list: result = addKernelRoute(tgen, dut, intf, loop_addr) assert result is True, "Testcase {}:Failed \n Error: {}".format( tc_name, result) for dut, intf, loop_addr, next_hop in ipv6_list: result = addKernelRoute(tgen, dut, intf, loop_addr, next_hop) assert result is True, "Testcase {}:Failed \n Error: {}".format( tc_name, result) step("Configure static routes") input_dict = { "r1": { "static_routes": [ { "network": r2_ipv4_loopback, "next_hop": r2_r1_ipv4 }, { "network": r3_ipv4_loopback, "next_hop": r3_r1_ipv4 }, { "network": r2_ipv6_loopback, "next_hop": r2_r1 }, { "network": r3_ipv6_loopback, "next_hop": r3_r1 }, ] }, "r2": { "static_routes": [ { "network": r1_ipv4_loopback, "next_hop": r1_r2_ipv4 }, { "network": r3_ipv4_loopback, "next_hop": r3_r2_ipv4 }, { "network": r1_ipv6_loopback, "next_hop": r1_r2 }, { "network": r3_ipv6_loopback, "next_hop": r3_r2 }, ] }, "r3": { "static_routes": [ { "network": r1_ipv4_loopback, "next_hop": r1_r3_ipv4 }, { "network": r2_ipv4_loopback, "next_hop": r2_r3_ipv4 }, { "network": r4_ipv4_loopback, "next_hop": r4_r3_ipv4 }, { "network": r1_ipv6_loopback, "next_hop": r1_r3 }, { "network": r2_ipv6_loopback, "next_hop": r2_r3 }, { "network": r4_ipv6_loopback, "next_hop": r4_r3 }, ] }, "r4": { "static_routes": [ { "network": r3_ipv4_loopback, "next_hop": r3_r4_ipv4 }, { "network": r3_ipv6_loopback, "next_hop": r3_r4 }, ] }, } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify BGP session convergence") result = verify_bgp_convergence(tgen, topo_modify) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Configure redistribute connected on R2 and R4") input_dict_1 = { "r2": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "connected" }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "connected" }] } }, } } }, "r4": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "connected" }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "connected" }] } }, } } }, } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify Ipv4 and Ipv6 network installed in R1 RIB but not in FIB") input_dict_r1 = { "r1": { "static_routes": [ { "network": "1.0.2.17/32" }, { "network": "2001:db8:f::2:17/128" }, ] } } dut = "r1" protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict_r1, protocol=protocol) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1, expected=False) assert result is not True, "Testcase {} : Failed \n" "Expected behavior: routes should not present in fib \n" "Error: {}".format(tc_name, result) step("Verify Ipv4 and Ipv6 network installed in r3 RIB but not in FIB") input_dict_r3 = { "r3": { "static_routes": [ { "network": "1.0.4.17/32" }, { "network": "2001:db8:f::4:17/128" }, ] } } dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict_r3, protocol=protocol, fib=None) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) result = verify_fib_routes(tgen, addr_type, dut, input_dict_r1, expected=False) assert result is not True, "Testcase {} : Failed \n" "Expected behavior: routes should not present in fib \n" "Error: {}".format(tc_name, result) write_test_footer(tc_name)
def test_ospf_authentication_different_auths_tc30_p1(request): """ OSPF Authentication - Verify ospf authentication with different authentication methods. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config.") reset_config_on_routers(tgen) step("Configure ospf with on R1 and R2, enable ospf on R1 interface " "connected to R2 with message-digest authentication using ip " "ospf authentication message-digest cmd.") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) # wait for dead timer expiry sleep(6) step("Verify that the neighbour is not FULL between R1 and R2.") dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False, retry_timeout=10) assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("On R2 enable ospf on interface with message-digest authentication" " using ip ospf authentication message-digest password cmd.") r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is FULL between R1 and R2 " "using show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step(" Delete the configured password on both the routers.") r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", "del_action": True, } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", "del_action": True, } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the deletion is successful and neighbour is FULL" " between R1 and R2 using show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Change the authentication type to simple password.") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": True, "authentication-key": "ospf" } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": True, "authentication-key": "ospf" } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the deletion is successful and neighbour is" " FULL between R1 and R2 using show ip ") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Change the password in simple password.") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": True, "authentication-key": "OSPFv4" } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": True, "authentication-key": "OSPFv4" } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the deletion is successful and neighbour is" " FULL between R1 and R2 using show ip ") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Delete the password authentication on the interface ") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": True, "authentication-key": "OSPFv4", "del_action": True, } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": True, "authentication-key": "OSPFv4", "del_action": True, } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the deletion is successful and neighbour is" " FULL between R1 and R2 using show ip ") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Enable Md5 authentication on the interface") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is FULL between R1 and R2 using" " show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Change the MD5 authentication password") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "OSPFv4", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "OSPFv4", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_same_rte_from_bgp_static_p0_tc5_ebgp(request): """ Verify RIB status when same route advertise via BGP and static route """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) reset_config_on_routers(tgen) NEXT_HOP_IP = populate_nh() step("Configure EBGP IPv4 peering between R2 and R3 router.") step("Configure IPv4 static route (10.1.1.1/24) in R2 with next hop" "N1 (28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present" "on R1") for addr_type in ADDR_TYPES: input_dict_4 = { "r2": { "static_routes": [ { "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], }, { "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure redistribute static in BGP.") for addr_type in ADDR_TYPES: input_dict_2 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify on R3 , route receive on R3 BGP table ") dut = "r3" result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4) assert result is True, "Testcase {} : Failed \nError: Route is" " still present in RIB".format(tc_name) step("Verify route installed in the RIB and FIB of R3") protocol = "bgp" result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol) assert result is True, "Testcase {} : Failed \nError: Route is" " still present in RIB".format(tc_name) step("Configure 2 links/interfaces between R1 and R3 , keep one" "interface in shut (active) state and other interface in no shut" "(inactive) state") dut = "r3" intf = topo["routers"]["r3"]["links"]["r1-link0"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) step("Configure same static route (10.1.1.1/24) in R3 with inactive" "nexthop interface") step("Configure same static route 10.1.1.1/24) again in R3 with" "active nexthop interface") for addr_type in ADDR_TYPES: input_dict_4 = { "r3": { "static_routes": [ { "network": NETWORK[addr_type], "next_hop": topo["routers"]["r1"]["links"]["r3-link0"][addr_type], }, { "network": NETWORK[addr_type], "next_hop": topo["routers"]["r1"]["links"]["r3-link1"][addr_type], }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify when static route configure with inactive nexthop , " "verify BGP received route is active in the RIB and FIB") dut = "r3" result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4) assert result is True, "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(tc_name) protocol = "bgp" result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name) step("Remove the static route on R3 configured with active" "interface") for addr_type in ADDR_TYPES: input_dict_4 = { "r3": { "static_routes": [ { "network": NETWORK[addr_type], "next_hop": topo["routers"]["r1"]["links"]["r3-link0"][addr_type], "delete": True, }, { "network": NETWORK[addr_type], "next_hop": topo["routers"]["r1"]["links"]["r3-link1"][addr_type], "delete": True, }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("After removing the static route with active nexthop verify " "BGP received route is became active in RIB and FIB") dut = "r3" result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4) assert result is True, "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(tc_name) protocol = "bgp" result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name) write_test_footer(tc_name)
def test_PIM_hello_tx_rx_p1(request): """ TC_54 Verify received and transmit hello stats are getting cleared after PIM nbr reset """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step( "Remove c1-c2 connected link to simulate topo " "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)" ) intf_c1_c2 = topo["routers"]["c1"]["links"]["c2"]["interface"] intf_c2_c1 = topo["routers"]["c2"]["links"]["c1"]["interface"] shutdown_bringup_interface(tgen, "c1", intf_c1_c2, False) shutdown_bringup_interface(tgen, "c2", intf_c2_c1, False) step("Enable the PIM on all the interfaces of FRR1, FRR2, FRR3") step( "Enable IGMP of FRR1 interface and send IGMP joins " " from FRR1 node for group range (225.1.1.1-5)" ) intf_c1_i4 = topo["routers"]["c1"]["links"]["i4"]["interface"] input_dict = { "c1": {"igmp": {"interfaces": {intf_c1_i4: {"igmp": {"version": "2"}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]} for recvr, recvr_intf in input_join.items(): result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") input_dict = { "l1": { "pim": { "rp": [ { "rp_addr": topo["routers"]["l1"]["links"]["lo"]["ipv4"].split( "/" )[0], "group_addr_range": GROUP_RANGE, } ] } } } result = create_pim_config(tgen, topo, input_dict) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send Mcast traffic from C2 to all the groups ( 225.1.1.1 to 225.1.1.5)") input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]} for src, src_intf in input_src.items(): result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0] input_dict_starg = [ { "dut": "c1", "src_address": "*", "iif": topo["routers"]["c1"]["links"]["l1"]["interface"], "oil": topo["routers"]["c1"]["links"]["i4"]["interface"], } ] input_dict_sg = [ { "dut": "c1", "src_address": source_i5, "iif": topo["routers"]["c1"]["links"]["l1"]["interface"], "oil": topo["routers"]["c1"]["links"]["i4"]["interface"], } ] step("(*,G) and (S,G) created on f1 and node verify using 'show ip mroute'") for data in input_dict_sg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) for data in input_dict_starg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) intf_l1_c1 = topo["routers"]["l1"]["links"]["c1"]["interface"] intf_c1_l1 = topo["routers"]["c1"]["links"]["l1"]["interface"] step("verify before stats on C1") state_dict = { "c1": { intf_c1_l1: ["helloTx", "helloRx"], } } c1_state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("Flap PIM nbr while doing interface c1-l1 interface shut from f1 side") shutdown_bringup_interface(tgen, "c1", intf_c1_l1, False) step( "After shut of local interface from c1 , verify rx/tx hello counters are cleared on c1 side" "verify using 'show ip pim interface traffic'" ) shutdown_bringup_interface(tgen, "c1", intf_c1_l1, True) step("verify stats after on c1") c1_state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_after, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("verify stats not increamented on c1") result = verify_state_incremented(c1_state_before, c1_state_after) assert ( result is not True ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result) step("verify before stats on l1") l1_state_dict = { "l1": { intf_l1_c1: ["helloTx", "helloRx"], } } l1_state_before = verify_pim_interface_traffic(tgen, l1_state_dict) assert isinstance( l1_state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("Flap PIM nbr while doing interface r2-c1 shut from r2 side") shutdown_bringup_interface(tgen, "l1", intf_l1_c1, False) step( "After shut the interface from r2 side , verify r2 side rx and tx of hello" "counters are resetted show ip pim interface traffic" ) shutdown_bringup_interface(tgen, "l1", intf_l1_c1, True) step("verify stats after on l1") l1_state_after = verify_pim_interface_traffic(tgen, l1_state_dict) assert isinstance( l1_state_after, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("verify stats not increamented on l1") result = verify_state_incremented(l1_state_before, l1_state_after) assert ( result is not True ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result) step("Reinit the dict") c1_state_before = {} l1_state_before = {} c1_state_after = {} l1_state_after = {} step("verify before stats on C1") state_dict = { "c1": { intf_c1_l1: ["helloTx", "helloRx"], } } c1_state_before = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_before, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("Flap c1-r2 pim nbr while changing ip address from c1 side") c1_l1_ip_subnet = topo["routers"]["c1"]["links"]["l1"]["ipv4"] raw_config = { "c1": { "raw_config": [ "interface {}".format(intf_c1_l1), "no ip address {}".format(c1_l1_ip_subnet), "ip address {}".format(NEW_ADDRESS_2_SUBNET), ] } } result = apply_raw_config(tgen, raw_config) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("verify stats after on c1") c1_state_after = verify_pim_interface_traffic(tgen, state_dict) assert isinstance( c1_state_after, dict ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(tc_name, result) step("verify stats not increamented on c1") result = verify_state_incremented(c1_state_before, c1_state_after) assert ( result is not True ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result) write_test_footer(tc_name)
def test_ospf_authentication_md5_tc29_p1(request): """ OSPF Authentication - Verify ospf authentication with MD5 authentication. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config.") reset_config_on_routers(tgen) step("Configure ospf with on R1 and R2, enable ospf on R1 interface " "connected to R2 with message-digest authentication using ip " "ospf authentication message-digest cmd.") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is not FULL between R1 and R2.") # wait for dead time expiry. sleep(6) dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False, retry_timeout=6) assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("On R2 enable ospf on interface with message-digest authentication" " using ip ospf authentication message-digest password cmd.") r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is FULL between R1 and R2 " "using show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Disable message-digest authentication on R2 using no ip ospf " "authentication message-digest password cmd.") r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", "del_action": True, } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry") # wait till the dead timer expiry sleep(6) dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False, retry_timeout=10) assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Again On R2 enable ospf on interface with message-digest auth") r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r2_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is FULL between R1 and R2 using" " show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Shut no shut interface on R1") dut = "r1" intf = topo["routers"]["r1"]["links"]["r2"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) dut = "r2" step("Verify that the neighbour is not FULL between R1 and R2 using " "show ip ospf neighbor cmd.") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False) assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) dut = "r1" shutdown_bringup_interface(tgen, dut, intf, True) step("Verify that the neighbour is FULL between R1 and R2 using " "show ip ospf neighbor cmd.") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Change Ip address on R1 and R2") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] = str( IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3) + "/{}".format( intf_ip.split("/")[1]) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) reset_config_on_routers(tgen, routerName="r1") dut = "r1" intf = topo["routers"]["r1"]["links"]["r2"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) shutdown_bringup_interface(tgen, dut, intf, True) clear_ospf(tgen, "r1") r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10", } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that the neighbour is FULL between R1 and R2 with new " "ip address using show ip ospf ") dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) write_test_footer(tc_name)
def test_mroute_with_RP_default_route_all_nodes_p2(request): """ TC_50 Verify mroute when LHR,FHR,RP and transit routers reachable using default routes """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON kill_iperf(tgen) clear_ip_mroute(tgen) reset_config_on_routers(tgen) clear_ip_pim_interface_traffic(tgen, topo) # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step( "Remove c1-c2 connected link to simulate topo " "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)" ) intf_c1_c2 = topo["routers"]["c1"]["links"]["c2"]["interface"] intf_c2_c1 = topo["routers"]["c2"]["links"]["c1"]["interface"] shutdown_bringup_interface(tgen, "c1", intf_c1_c2, False) shutdown_bringup_interface(tgen, "c2", intf_c2_c1, False) step("Enable the PIM on all the interfaces of FRR1, FRR2, FRR3") step( "Enable IGMP of FRR1 interface and send IGMP joins " " from FRR1 node for group range (225.1.1.1-5)" ) intf_c1_i4 = topo["routers"]["c1"]["links"]["i4"]["interface"] input_dict = { "c1": {"igmp": {"interfaces": {intf_c1_i4: {"igmp": {"version": "2"}}}}} } result = create_igmp_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]} for recvr, recvr_intf in input_join.items(): result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for (225.1.1.1-5) as R2") input_dict = { "l1": { "pim": { "rp": [ { "rp_addr": topo["routers"]["l1"]["links"]["lo"]["ipv4"].split( "/" )[0], "group_addr_range": GROUP_RANGE, } ] } } } result = create_pim_config(tgen, topo, input_dict) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send traffic from C2 to all the groups ( 225.1.1.1 to 225.1.1.5)") input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]} for src, src_intf in input_src.items(): result = config_to_send_igmp_join_and_traffic( tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True ) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0] input_dict_starg = [ { "dut": "c1", "src_address": "*", "iif": topo["routers"]["c1"]["links"]["l1"]["interface"], "oil": topo["routers"]["c1"]["links"]["i4"]["interface"], } ] input_dict_sg = [ { "dut": "c1", "src_address": source_i5, "iif": topo["routers"]["c1"]["links"]["l1"]["interface"], "oil": topo["routers"]["c1"]["links"]["i4"]["interface"], } ] step("Verify mroutes and iff upstream") for data in input_dict_sg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) result = verify_upstream_iif( tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) for data in input_dict_starg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) result = verify_upstream_iif( tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Delete static routes RP on all the nodes") input_dict = { "c2": { "static_routes": [ {"network": ["1.0.4.11/32"], "next_hop": "10.0.3.2", "delete": True} ] }, "c1": { "static_routes": [ {"network": ["1.0.4.11/32"], "next_hop": "10.0.2.2", "delete": True} ] }, "r2": { "static_routes": [ {"network": ["1.0.4.11/32"], "next_hop": "10.0.12.1", "delete": True} ] }, "f1": { "static_routes": [ {"network": ["1.0.4.11/32"], "next_hop": "10.0.7.2", "delete": True} ] }, } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) step("Verify RP info unknown after removing static route from c2 ") dut = "c2" rp_address = topo["routers"]["l1"]["links"]["lo"]["ipv4"].split("/")[0] SOURCE = "Static" result = verify_pim_rp_info( tgen, topo, dut, GROUP_RANGE_1, "Unknown", rp_address, SOURCE ) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) for data in input_dict_starg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], expected=False, ) assert result is not True, ("Testcase {} : Failed \n " "mroutes are still present \n Error: {}".format( tc_name, result )) result = verify_upstream_iif( tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1, expected=False, ) assert result is not True, ("Testcase {} : Failed \n " "upstream is still present \n Error: {}".format( tc_name, result )) step("Configure default routes on all the nodes") intf_f1_c2 = topo["routers"]["f1"]["links"]["c2"]["ipv4"].split("/")[0] intf_l1_c1 = topo["routers"]["l1"]["links"]["c1"]["ipv4"].split("/")[0] intf_l1_r2 = topo["routers"]["l1"]["links"]["r2"]["ipv4"].split("/")[0] intf_r2_f1 = topo["routers"]["r2"]["links"]["f1"]["ipv4"].split("/")[0] input_dict = { "c1": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_l1_c1}]}, "c2": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_f1_c2}]}, "r2": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_l1_r2}]}, "f1": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_r2_f1}]}, } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) step("applying ip nht config on c2") raw_config = { "c1": {"raw_config": ["ip nht resolve-via-default"]}, "c2": {"raw_config": ["ip nht resolve-via-default"]}, "r2": {"raw_config": ["ip nht resolve-via-default"]}, "f1": {"raw_config": ["ip nht resolve-via-default"]}, "l1": {"raw_config": ["ip nht resolve-via-default"]}, } result = apply_raw_config(tgen, raw_config) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Verify RP info Not unknown after removing static route from c2 ") dut = "c2" step("Verify RP info is NOT unknown after removing static route from c2 ") result = verify_pim_rp_info( tgen, topo, dut, GROUP_RANGE_1, "Unknown", rp_address, SOURCE, expected=False ) assert result is not True, ("Testcase {} : Failed \n " "RP info is unknown after removing static route from c2 \n Error: {}".format( tc_name, result )) step("Verify (s,g) populated after adding default route ") for data in input_dict_sg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) result = verify_upstream_iif( tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Verify (*,g) populated after adding default route ") for data in input_dict_starg: result = verify_ip_mroutes( tgen, data["dut"], data["src_address"], IGMP_JOIN_RANGE_1, data["iif"], data["oil"], ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) result = verify_upstream_iif( tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 ) assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) write_test_footer(tc_name)
def test_bgp_gr_stale_routes(request): tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) step("Verify the router failures") if tgen.routers_have_failure(): check_router_status(tgen) step("Creating 5 static Routes in Router R3 with NULL0 as Next hop") for addr_type in ADDR_TYPES: input_dict_1 = { "r3": { "static_routes": [{ "network": [NETWORK1_1[addr_type]] + [NETWORK1_2[addr_type]], "next_hop": NEXT_HOP_IP[addr_type] }, { "network": [NETWORK2_1[addr_type]] + [NETWORK2_2[addr_type]], "next_hop": NEXT_HOP_IP[addr_type] }, { "network": [NETWORK3_1[addr_type]] + [NETWORK3_2[addr_type]], "next_hop": NEXT_HOP_IP[addr_type] }, { "network": [NETWORK4_1[addr_type]] + [NETWORK4_2[addr_type]], "next_hop": NEXT_HOP_IP[addr_type] }, { "network": [NETWORK5_1[addr_type]] + [NETWORK5_2[addr_type]], "next_hop": NEXT_HOP_IP[addr_type] }] } } result = create_static_routes(tgen, input_dict_1) assert result is True, 'Testcase {} : Failed \n Error: {}'.format( tc_name, result) step("verifying Created Route at R3 in VRF default") for addr_type in ADDR_TYPES: dut = 'r3' input_dict_1= {'r3': topo['routers']['r3']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) #done step("verifying Created Route at R2 in VRF default") for addr_type in ADDR_TYPES: dut = 'r2' input_dict_1= {'r2': topo['routers']['r2']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) step("importing vrf RED on R2 under Address Family") for addr_type in ADDR_TYPES: input_import_vrf={ "r2": { "bgp": [ { "local_as": 200, "vrf": "RED", "address_family": {addr_type: {"unicast": {"import": {"vrf": "default"}}}}, } ] } } result = create_router_bgp(tgen, topo,input_import_vrf) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) #done step("verifying static Routes at R2 in VRF RED") for addr_type in ADDR_TYPES: dut = 'r2' input_dict_1= {'r2': topo['routers']['r2']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) step("verifying static Routes at R1 in VRF RED") for addr_type in ADDR_TYPES: dut = 'r1' input_dict_1= {'r1': topo['routers']['r1']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) step("Configuring Graceful restart at R2 and R3 ") input_dict = { "r2": { "bgp": { "local_as": "200", "graceful-restart": { "graceful-restart": True, } } }, "r3": { "bgp": { "local_as": "300", "graceful-restart": { "graceful-restart": True } } } } configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name,dut='r2', peer='r3') step("verify Graceful restart at R2") for addr_type in ADDR_TYPES: result = verify_graceful_restart(tgen, topo, addr_type, input_dict, dut='r2', peer='r3') assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) step("verify Graceful restart at R3") for addr_type in ADDR_TYPES: result = verify_graceful_restart(tgen, topo, addr_type, input_dict, dut='r3', peer='r2') assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) step("Configuring Graceful-restart-disable at R3") input_dict = { "r2": { "bgp": { "local_as": "200", "graceful-restart": { "graceful-restart": False, } } }, "r3": { "bgp": { "local_as": "300", "graceful-restart": { "graceful-restart": False } } } } configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name,dut='r3', peer='r2') step("Verify Graceful-restart-disable at R3") for addr_type in ADDR_TYPES: result = verify_graceful_restart(tgen, topo, addr_type, input_dict, dut='r3', peer='r2') assert result is True, \ "Testcase {} :Failed \n Error {}". \ format(tc_name, result) for iteration in range(5): step("graceful-restart-disable:True at R3") input_dict = { "r3": { "bgp": { "graceful-restart": { "graceful-restart-disable": True, } } } } configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut='r3', peer='r2') step("Verifying Routes at R2 on enabling GRD") dut = 'r2' for addr_type in ADDR_TYPES: input_dict_1= {'r2': topo['routers']['r2']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) step("Verify stale Routes in Router R2 enabling GRD") for addr_type in ADDR_TYPES: dut = "r2" protocol = "bgp" verify_nh_for_static_rtes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], "no_of_ip": 2, "vrf": "RED" } ] } } bgp_rib_next_hops = verify_stale_routes_list( tgen, addr_type, dut, verify_nh_for_static_rtes) assert (len(bgp_rib_next_hops)== 1) is True, "Testcase {} : Failed \n Error: {}".format( tc_name, bgp_rib_next_hops,expected=True) step("graceful-restart-disable:False at R3") input_dict = { "r3": { "bgp": { "graceful-restart": { "graceful-restart-disable": False, } } } } configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut='r3', peer='r2') step("Verifying Routes at R2 on disabling GRD") dut = 'r2' for addr_type in ADDR_TYPES: input_dict_1= {'r2': topo['routers']['r2']} result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1) assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) step("Verify stale Routes in Router R2 on disabling GRD") for addr_type in ADDR_TYPES: dut = "r2" protocol = "bgp" verify_nh_for_static_rtes = { "r3": { "static_routes": [ { "network": [NETWORK1_1[addr_type]], "no_of_ip": 2, "vrf": "RED" } ] } } bgp_rib_next_hops = verify_stale_routes_list(tgen, addr_type, dut, verify_nh_for_static_rtes) stale_route_status=len(bgp_rib_next_hops)== 1 assert stale_route_status is True, "Testcase {} : Failed \n Error: {}".format( tc_name, stale_route_status,expected=True) write_test_footer(tc_name)
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" red_static(dut) 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_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 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 ) 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 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 ) 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 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_static_route_2nh_admin_dist_p0_tc_2_ebgp(request): """ Verify static route functionality with 2 next hop & different AD value. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) reset_config_on_routers(tgen) NEXT_HOP_IP = populate_nh() step("Configure IPv4 static route (10.1.1.1) in R2 with next hop N1" "(28.1.1.2 ) AD 10 and N2 (29.1.1.2) AD 20 , Static route next-hop" "present on R1 \n ex :- ip route 10.1.1.1/24 28.1.1.2 10 & " "ip route 10.1.1.1/24 29.1.1.2 20") reset_config_on_routers(tgen) NEXT_HOP_IP = populate_nh() for addr_type in ADDR_TYPES: input_dict_4 = { "r2": { "static_routes": [ { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }, { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("On R2, static route installed in RIB using " "show ip route with 2 next hop , lowest AD nexthop is active ") rte1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }] } } nh = [NEXT_HOP_IP["nh1"][addr_type]] dut = "r2" protocol = "static" result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name) rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }] } } nh = [NEXT_HOP_IP["nh2"][addr_type]] dut = "r2" protocol = "static" result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) step("Configure IBGP IPv4 peering between R2 and R3 router.") step("Explicit route is added in R3 for R2 nexthop rechability") rt3_rtes = { "r3": { "static_routes": [ { "network": NEXT_HOP_IP["nh1"][addr_type] + "/32", "next_hop": topo["routers"]["r2"]["links"]["r3"][addr_type], }, { "network": NEXT_HOP_IP["nh2"][addr_type] + "/32", "next_hop": topo["routers"]["r2"]["links"]["r3"][addr_type], }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, rt3_rtes) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure redistribute static in BGP on R2 router") input_dict_2 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Remove the static route configured with nexthop N1 from" "running config") rt1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, "delete": True, }] } } logger.info("Configure static routes") result = create_static_routes(tgen, rt1_nh1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("On R2, after removing the static route with N1 , " "route become active with nexthop N2 and vice versa.") rte1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }] } } nh = [NEXT_HOP_IP["nh1"][addr_type]] dut = "r2" protocol = "static" result = verify_rib( tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name) rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }] } } nh = [NEXT_HOP_IP["nh2"][addr_type]] result = verify_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) step("Configure the static route with nexthop N1") rte1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }] } } logger.info("Configure static routes") result = create_static_routes(tgen, rte1_nh1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Remove the static route configured with nexthop N2 from" "running config") rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, "delete": True, }] } } logger.info("Configure static routes") result = create_static_routes(tgen, rte2_nh2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("On R2, after removing the static route with N2 , " "route become active with nexthop N1 and vice versa.") nh = NEXT_HOP_IP["nh2"][addr_type] result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(tc_name) nh = [NEXT_HOP_IP["nh1"][addr_type]] result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol) assert result is True, "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name) step("Configure the static route with nexthop N2") rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }] } } logger.info("Configure static routes") result = create_static_routes(tgen, rte2_nh2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Shut nexthop interface N1") intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) step("after shut of nexthop N1 , route become active with nexthop N2") nh = NEXT_HOP_IP["nh1"][addr_type] result = verify_rib( tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(tc_name) nh = [NEXT_HOP_IP["nh2"][addr_type]] result = verify_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name) step("No shut the nexthop interface N1") shutdown_bringup_interface(tgen, dut, intf, True) step("after shut of nexthop N1 , route become active " "with nexthop N2 and vice versa.") nh = [NEXT_HOP_IP["nh1"][addr_type]] result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name) step("Shut nexthop interface N2") intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) step(" after shut of nexthop N1 , route become active with " "nexthop N2 and vice versa.") nh = NEXT_HOP_IP["nh2"][addr_type] result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(tc_name) nh = [NEXT_HOP_IP["nh1"][addr_type]] result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol) assert result is True, "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name) step("No shut nexthop interface N2") shutdown_bringup_interface(tgen, dut, intf, True) step("after shut of nexthop N1 , route become active " "with nexthop N2 and vice versa.") rte1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }] } } nh = [NEXT_HOP_IP["nh1"][addr_type]] dut = "r2" protocol = "static" result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name) rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }] } } nh = [NEXT_HOP_IP["nh2"][addr_type]] dut = "r2" protocol = "static" result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) dut = "r3" protocol = "bgp" result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) dut = "r2" step("Reload the FRR router") # stop/start -> restart FRR router and verify stop_router(tgen, "r2") start_router(tgen, "r2") step("After reload of FRR router , static route installed" " in RIB and FIB properly .") rte1_nh1 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "admin_distance": 10, }] } } nh = [NEXT_HOP_IP["nh1"][addr_type]] dut = "r2" protocol = "static" result = verify_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True) assert result is True, "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name) dut = "r3" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh) assert result is True, "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name) rte2_nh2 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "admin_distance": 20, }] } } nh = [NEXT_HOP_IP["nh2"][addr_type]] dut = "r2" protocol = "static" result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) dut = "r3" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh) assert result is True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) result = verify_rib( tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True, expected=False, ) assert result is not True, "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name) write_test_footer(tc_name)
def test_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, attempts=2, 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, attempts=2, expected=False ) assert result is not True, "Testcase {} : Failed \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 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 ) # 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 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 ) 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 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_gr_helper_tc1_p0(request): """Verify by default helper support is disabled for FRR ospf""" 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, intf, intf1, pkt step("Bring up the base config as per the topology") reset_config_on_routers(tgen) ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ( ospf_covergence is True ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence) step("Verify that GR helper route is disabled by default to the in" "the DUT.") input_dict = { "helperSupport": "Disabled", "strictLsaCheck": "Enabled", "restartSupoort": "Planned and Unplanned Restarts", "supportedGracePeriod": 1800, } dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that DUT does not enter helper mode upon receiving the " "grace lsa.") # send grace lsa scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) input_dict = {"activeRestarterCnt": 1} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False) assert ( result is not True ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format( tc_name, result ) step("Configure graceful restart in the DUT") ospf_gr_r0 = { "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that GR helper route is enabled in the DUT.") input_dict = { "helperSupport": "Enabled", "strictLsaCheck": "Enabled", "restartSupoort": "Planned and Unplanned Restarts", "supportedGracePeriod": 1800, } dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ospf_gr_r1 = { "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Perform GR in RR.") step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.") input_dict = {"activeRestarterCnt": 1} gracelsa_sent = False repeat = 0 dut = "r0" while not gracelsa_sent and repeat < Iters: gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) if isinstance(result, str): repeat += 1 gracelsa_sent = False assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Unconfigure the GR helper command.") ospf_gr_r0 = { "r0": { "ospf": { "graceful-restart": {"helper enable": [], "opaque": True, "delete": True} } } } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict = {"helperSupport": "Disabled"} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure gr helper using the router id") ospf_gr_r0 = { "r0": { "ospf": {"graceful-restart": {"helper enable": ["1.1.1.1"], "opaque": True}} } } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.") input_dict = {"activeRestarterCnt": 1} gracelsa_sent = False repeat = 0 dut = "r0" while not gracelsa_sent and repeat < Iters: gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) if isinstance(result, str): repeat += 1 gracelsa_sent = False assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Un Configure gr helper using the router id") ospf_gr_r0 = { "r0": { "ospf": { "graceful-restart": { "helper enable": ["1.1.1.1"], "opaque": True, "delete": True, } } } } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that GR helper router is disabled in the DUT for" " router id x.x.x.x") input_dict = {"enabledRouterIds": [{"routerId": "1.1.1.1"}]} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False) assert ( result is not True ), "Testcase {} : Failed, Helper role enabled for RR\n Error: {}".format( tc_name, result ) delete_ospf() 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_ospf_gr_helper_tc4_p1(request): """ OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor sends grace lsa, helps RR to restart gracefully (RR = DRother) """ 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, intf, intf1, pkt step("Bring up the base config as per the topology") step( "Configure DR priority as 99 in RR , DUT dr priority = 98 " "& reset ospf process in all the routers" ) reset_config_on_routers(tgen) ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ( ospf_covergence is True ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence) step( "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers." ) input_dict = { "r0": { "links": { sw_name: { "interface": topo["routers"]["r0"]["links"][sw_name]["interface"], "ospf": {"priority": 0}, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("Clear ospf neighbours in all routers") for rtr in topo["routers"]: clear_ospf(tgen, rtr) step("Verify that DR election is triggered and R0 is elected as 2-Way") input_dict = { "r0": { "ospf": { "neighbors": { "r1": {"state": "Full", "role": "DR"}, "r2": {"state": "2-Way", "role": "DROther"}, "r3": {"state": "2-Way", "role": "DROther"}, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ospf_gr_r0 = { "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ospf_gr_r1 = { "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that DUT enters into helper mode.") input_dict = {"activeRestarterCnt": 1} gracelsa_sent = False repeat = 0 dut = "r0" while not gracelsa_sent and repeat < Iters: gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) if isinstance(result, str): repeat += 1 gracelsa_sent = False assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) delete_ospf() write_test_footer(tc_name)
def test_BGP_attributes_with_vrf_default_keyword_p0(request): """ TC_9: Verify BGP functionality for default vrf with "vrf default" keyword. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) # reset_config_on_routers(tgen) step("Configure static routes and redistribute in BGP on R3") for addr_type in ADDR_TYPES: input_dict = { "r3": { "static_routes": [{ "network": NETWORK[addr_type][0], "no_of_ip": 4, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_2 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static" }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static" }] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Create a route-map to match a specific prefix and modify" "BGP attributes for matched prefix") input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "ABC": [{ "seqid": 10, "action": "permit", "network": NETWORK["ipv4"][0], }] }, "ipv6": { "XYZ": [{ "seqid": 100, "action": "permit", "network": NETWORK["ipv6"][0], }] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: if addr_type == "ipv4": pf_list = "ABC" else: pf_list = "XYZ" input_dict_6 = { "r3": { "route_maps": { "BGP_ATTR_{}".format(addr_type): [ { "action": "permit", "seq_id": 10, "match": { addr_type: { "prefix_lists": pf_list } }, "set": { "aspath": { "as_num": 500, "as_action": "prepend" }, "localpref": 500, "origin": "egp", "community": { "num": "500:500", "action": "additive" }, "large_community": { "num": "500:500:500", "action": "additive", }, }, }, { "action": "permit", "seq_id": 20 }, ] }, "BGP_ATTR_{}".format(addr_type): [ { "action": "permit", "seq_id": 100, "match": { addr_type: { "prefix_lists": pf_list } }, "set": { "aspath": { "as_num": 500, "as_action": "prepend" }, "localpref": 500, "origin": "egp", "community": { "num": "500:500", "action": "additive" }, "large_community": { "num": "500:500:500", "action": "additive", }, }, }, { "action": "permit", "seq_id": 200 }, ], } } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Apply the route-map on R3 in outbound direction for peer R4") input_dict_7 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [{ "name": "BGP_ATTR_ipv4", "direction": "out", }] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [{ "name": "BGP_ATTR_ipv6", "direction": "out", }] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify modified attributes for specific prefix with 'vrf default'" "keyword on R4") for addr_type in ADDR_TYPES: dut = "r4" input_dict = { "r3": { "static_routes": [{ "network": NETWORK[addr_type][0], "vrf": "default", "largeCommunity": "500:500:500", }] } } result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: dut = "r4" input_dict = { "r3": { "static_routes": [{ "network": NETWORK[addr_type][0], "vrf": "default", "community": "500:500", }] } } result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) input_dict_4 = { "largeCommunity": "500:500:500", "community": "500:500" } result = verify_bgp_community(tgen, addr_type, dut, [NETWORK[addr_type][0]], input_dict_4) assert result is True, "Test case {} : Should fail \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_gr_helper_tc7_p1(request): """ Test ospf gr helper Verify helper when grace lsa is received with different configured value in process level (higher, lower, grace lsa timer above 1800) """ 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, intf, intf1, pkt step("Bring up the base config as per the topology") step( "Configure DR priority as 99 in RR , DUT dr priority = 98 " "& reset ospf process in all the routers" ) step( "Enable GR on RR and DUT with grace period on RR = 333" "and grace period on DUT = 300" ) reset_config_on_routers(tgen) ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ( ospf_covergence is True ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence) ospf_gr_r0 = { "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ospf_gr_r1 = { "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict = {"supportedGracePeriod": 1800} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Configure grace period = 1801 on RR and restart ospf .") grace_period_1801 = "01005e00000570708bd051ef080045c0005cbeb10000015907d111010101e00000050204004801010101000000009714000000000000000000000000000100010209030000000101010180000001c8e9002c000100040000016800020001010000000003000411010101" gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, grace_period_1801) step("Verify R0 does not enter helper mode.") input_dict = {"activeRestarterCnt": 1} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False) assert ( result is not True ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format( tc_name, result ) delete_ospf() write_test_footer(tc_name)
def test_ospfv3_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_ospf6_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["ipv6"][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" red_static(dut) step("Verify that route in R2 in stalled with 2 next hops.") llip = get_llip("r0", "r1-link1") assert llip is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) nh1 = llip llip = get_llip("r0", "r1") assert llip is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) nh2 = llip nh = [nh1, nh2] dut = "r1" result = verify_ospf6_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, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure ECMP value as 1.") max_path = {"r1": {"ospf6": {"maximum-paths": 1}}} result = create_router_ospf(tgen, topo, max_path) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r1" max_path = {"r1": {"ospf6": {"maximum-paths": 2}}} result = create_router_ospf(tgen, topo, max_path) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure cost on R0 as 100") r0_ospf_cost = {"r0": {"links": {"r1": {"ospf6": {"cost": 100}}}}} result = config_ospf6_interface(tgen, topo, r0_ospf_cost) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) dut = "r1" result = verify_ospf6_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, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_gr_helper_tc8_p1(request): """ Test ospf gr helper Verify helper functionality when dut is helping RR and new grace lsa is received from RR. """ 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, intf, intf1, pkt step("Bring up the base config as per the topology") step("Enable GR") reset_config_on_routers(tgen) ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ( ospf_covergence is True ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence) ospf_gr_r0 = { "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ospf_gr_r1 = { "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}} } result = create_router_ospf(tgen, topo, ospf_gr_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict = {"supportedGracePeriod": 1800} dut = "r0" result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that DUT enters into helper mode.") input_dict = {"activeRestarterCnt": 1} gracelsa_sent = False repeat = 0 dut = "r0" while not gracelsa_sent and repeat < Iters: gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) if isinstance(result, str): repeat += 1 gracelsa_sent = False assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Send the Grace LSA again to DUT when RR is in GR.") input_dict = {"activeRestarterCnt": 1} gracelsa_sent = False repeat = 0 dut = "r0" while not gracelsa_sent and repeat < Iters: gracelsa_sent = scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt) result = verify_ospf_gr_helper(tgen, topo, dut, input_dict) if isinstance(result, str): repeat += 1 gracelsa_sent = False assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) delete_ospf() write_test_footer(tc_name)
def test_locally_imported_routes_selected_as_bestpath_over_ebgp_imported_routes_p0(request): """ Verify ECMP for imported routes from different VRFs. """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) if tgen.routers_have_failure(): check_router_status(tgen) reset_config_on_routers(tgen) step("Configure same static routes on R2 and R3 vrfs and redistribute in BGP " "for GREEN and RED vrf instances") for dut, network in zip(["r2", "r3"], [ [NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]): for vrf_name, network_vrf in zip(["RED", "GREEN"], network): step("Configure static route for VRF : {} on {}".format(vrf_name, dut)) for addr_type in ADDR_TYPES: static_routes = { dut: { "static_routes": [ { "network": [network_vrf[addr_type]], "next_hop": "blackhole", "vrf": vrf_name } ] } } result = create_static_routes(tgen, static_routes) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) for dut, as_num in zip(["r2", "r3"], ["2", "3"]): for vrf_name in ["RED", "GREEN"]: step("Redistribute static route on BGP VRF : {}".format(vrf_name)) temp = {} for addr_type in ADDR_TYPES: temp.update({ addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } }) redist_dict = {dut: {"bgp": [{ "vrf": vrf_name, "local_as": as_num, "address_family": temp }]}} result = create_router_bgp(tgen, topo, redist_dict) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Verify that R2 and R3 has installed redistributed routes in default " "and RED vrfs and GREEN respectively:") for dut, network in zip(["r2", "r3"], [[NETWORK1_1, NETWORK1_2], [NETWORK1_1, NETWORK1_2]]): for vrf_name, network_vrf in zip(["RED", "GREEN"], network): for addr_type in ADDR_TYPES: static_routes = { dut: { "static_routes": [ { "network": [network_vrf[addr_type]], "next_hop": "blackhole", "vrf": vrf_name } ] } } result = verify_bgp_rib(tgen, addr_type, dut, static_routes) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) step("Import vrf RED's route in vrf GREEN on R3") temp = {} for addr_type in ADDR_TYPES: temp.update({ addr_type: { "unicast": { "import": { "vrf": "RED" } } } }) import_dict = {"r3": {"bgp": [{ "vrf": "GREEN", "local_as": 3, "address_family": temp }]}} result = create_router_bgp(tgen, topo, import_dict) assert result is True, "Testcase {} :Failed \n Error: {}". \ format(tc_name, result) step("Verify that locally imported routes are installed over eBGP imported" " routes from VRF RED into VRF GREEN") for addr_type in ADDR_TYPES: static_routes = { "r3": { "static_routes": [ { "network": [NETWORK1_2[addr_type]], "next_hop": "blackhole", "vrf": "GREEN" } ] } } input_routes = { "r3": { addr_type: [ { "network": NETWORK1_2[addr_type], "bestpath": BESTPATH[addr_type], "vrf": "GREEN" } ] } } result = verify_bgp_bestpath(tgen, addr_type, input_routes) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) result = verify_rib(tgen, addr_type, "r3", static_routes) assert result is True, "Testcase {} : Failed \n Error {}". \ format(tc_name, result) write_test_footer(tc_name)
def test_ospf_lan_tc1_p0(request): """ OSPF Hello protocol - Verify DR BDR Elections """ 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") reset_config_on_routers(tgen) step("Verify that DR BDR DRother are elected in the LAN.") input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "DR" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that all the routers are in FULL state with DR and BDR " "in the topology") input_dict = { "r1": { "ospf": { "neighbors": { "r0": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r1" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers.") input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "priority": 100 }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Clear ospf neighbours in all routers") for rtr in ["r0", "r1", "r2", "r3"]: clear_ospf(tgen, rtr) step("Verify that DR election is triggered and R0 is elected as DR") input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure DR pririty 150 on R0 and clear ospf neighbors " "on all the routers.") input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "priority": 150 }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Clear ospf neighbours in all routers") for rtr in ["r0", "r1"]: clear_ospf(tgen, rtr) step("Verify that DR election is triggered and R0 is elected as DR") input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure DR priority 0 on R0 & Clear ospf nbrs on all the routers") input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "priority": 0 }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Clear ospf neighbours in all routers") for rtr in ["r1"]: clear_ospf(tgen, rtr) step("Verify that DR election is triggered and R0 is elected as DRother") input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "DR" }, "r2": { "state": "2-Way", "role": "DROther" }, "r3": { "state": "2-Way", "role": "DROther" }, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure DR priority to default on R0 and Clear ospf neighbors" " on all the routers") input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "priority": 100 }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Clear ospf neighbours in all routers") for rtr in ["r0", "r1"]: clear_ospf(tgen, rtr) step("Verify that DR election is triggered and R0 is elected as DR") input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r0" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Shut interface on R0") dut = "r0" intf = topo["routers"]["r0"]["links"]["s1"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) result = verify_ospf_neighbor(tgen, topo, dut, lan=True, expected=False) assert ( result is not True ), "Testcase {} : Failed \n " "r0: OSPF neighbors-hip is up \n Error: {}".format( tc_name, result) step("No Shut interface on R0") dut = "r0" intf = topo["routers"]["r0"]["links"]["s1"]["interface"] shutdown_bringup_interface(tgen, dut, intf, True) input_dict = { "r0": { "ospf": { "neighbors": { "r1": { "state": "Full", "role": "DR" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } step("Verify that after no shut ospf neighbours are full on R0.") result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Clear ospf on DR router in the topology.") clear_ospf(tgen, "r0") step("Verify that BDR is getting promoted to DR after clear.") step("Verify that all the nbrs are in FULL state with the elected DR.") result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ip on LAN intf on R0 to other ip from the same subnet.") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] = str( IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 4) + "/{}".format( intf_ip.split("/")[1]) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) clear_ospf(tgen, "r0") step("Verify that OSPF is in FULL state with other routers with " "newly configured IP.") result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ospf router id on the R0 and clear ip ospf interface.") change_rid = {"r0": {"ospf": {"router_id": "100.1.1.100"}}} result = create_router_ospf(tgen, topo, change_rid) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo["routers"]["r0"]["ospf"]["router_id"] = "100.1.1.100" step("Reload the FRR router") stop_router(tgen, "r0") start_router(tgen, "r0") step("Verify that OSPF is in FULL state with other routers with" " newly configured router id.") input_dict = { "r1": { "ospf": { "neighbors": { "r0": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r1" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Reconfigure the original router id and clear ip ospf interface.") change_rid = {"r0": {"ospf": {"router_id": "100.1.1.0"}}} result = create_router_ospf(tgen, topo, change_rid) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo["routers"]["r0"]["ospf"]["router_id"] = "100.1.1.0" step("Reload the FRR router") # stop/start -> restart FRR router and verify stop_router(tgen, "r0") start_router(tgen, "r0") step("Verify that OSPF is enabled with router id previously configured.") input_dict = { "r1": { "ospf": { "neighbors": { "r0": { "state": "Full", "role": "Backup" }, "r2": { "state": "Full", "role": "DROther" }, "r3": { "state": "Full", "role": "DROther" }, } } } } dut = "r1" result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ext_nh_cap_remove_red_static_network_ebgp_peer_tc10_p1(request): """ Test exted capability nexthop with route map in. Verify IPv4 routes are deleted after un-configuring of network command and redistribute static knob """ 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 IPv6 EBGP session between R1 and R2 with global IPv6" " address Enable capability extended-nexthop on the nbr from both" " the routers , Activate same IPv6 nbr from IPv4 unicast family") step(" Configure 2 IPv4 static routes " " on R1 nexthop for static route exists on different link of R0") reset_config_on_routers(tgen) for rte in range(0, NO_OF_RTES): # Create Static routes input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv4"][rte], "no_of_ip": 1, "next_hop": NEXT_HOP["ipv4"][rte], }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Advertise static routes from IPv4 unicast family and IPv6 unicast" " family respectively from R1. Configure loopback on R1 with IPv4 " "address Advertise loobak from IPv4 unicast family using network " "command from R1") configure_bgp_on_r1 = { "r1": { "bgp": { "local_as": "100", "default_ipv4_unicast": "True", "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static" }], "advertise_networks": [{ "network": NETWORK_CMD_IP, "no_of_network": 1 }], } } }, } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("IPv4 and IPv6 routes advertised using static and network command are" " received on R2 BGP and routing table , verify using show ip bgp" " show ip route for IPv4 routes and show bgp, show ipv6 routes" " for IPv6 routes .") glipv6 = get_llip("r1", "r2-link0") assert glipv6 is not None, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r2" protocol = "bgp" verify_nh_for_static_rtes = { "r1": { "advertise_networks": [{ "network": NETWORK["ipv4"][0], "no_of_ip": NO_OF_RTES, "next_hop": get_glipv6, }] } } bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=get_glipv6) 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=get_glipv6, protocol=protocol, ) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify IPv4 routes are installed with IPv6 global nexthop of R1 " " R1 to R2 connected link") verify_nh_for_nw_cmd_rtes = { "r1": { "advertise_networks": [{ "network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": glipv6, }] } } result = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glipv6, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) configure_bgp_on_r1 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static", "delete": True }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static", "delete": True }] } }, } } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # verify the routes with nh as ext_nh verify_nh_for_static_rtes = { "r1": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": NO_OF_RTES, "next_hop": glipv6, }] } } bgp_rib = verify_bgp_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glipv6, expected=False) assert ( bgp_rib is not True ), "Testcase {} : Failed \n Error: Routes still" " present in BGP rib".format( tc_name) result = verify_rib( tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glipv6, protocol=protocol, expected=False, ) assert ( result is not True ), "Testcase {} : Failed \n Error: Routes " "still present in RIB".format( tc_name) step("After removing IPv4 routes from redistribute static those routes" " are removed from R2, after re-advertising routes which are " " advertised using network are still present in the on R2 with " " IPv6 global nexthop, verify using show ip bgp and show ip routes") verify_nh_for_nw_cmd_rtes = { "r1": { "static_routes": [{ "network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": glipv6, }] } } result = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glipv6, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) configure_bgp_on_r1 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [{ "network": NETWORK_CMD_IP, "no_of_network": 1, "delete": True, }] } } } } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib( tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=glipv6, protocol=protocol, expected=False, ) assert ( result is not True ), "Testcase {} : Failed \n " "Error: Routes still present in BGP rib".format( tc_name) write_test_footer(tc_name)
def test_ospf_lan_tc2_p0(request): """ OSPF IFSM -Verify state change events on DR / BDR / DR Other """ 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") reset_config_on_routers(tgen) step("Verify that OSPF is subscribed to multi cast services " "(All SPF, all DR Routers).") step("Verify that interface is enabled in ospf.") dut = "r0" input_dict = { "r0": { "links": { "s1": { "ospf": { "priority": 98, "timerDeadSecs": 4, "area": "0.0.0.3", "mcastMemberOspfDesignatedRouters": True, "mcastMemberOspfAllRouters": True, "ospfEnabled": True, } } } } } result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Delete the ip address") topo1 = { "r0": { "links": { "r3": { "ipv4": topo["routers"]["r0"]["links"]["s1"]["ipv4"], "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ip on the R0 interface") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] = str( IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3) + "/{}".format( intf_ip.split("/")[1]) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) step("Verify that interface is enabled in ospf.") dut = "r0" input_dict = { "r0": { "links": { "s1": { "ospf": { "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"]["s1"] ["ipv4"].split("/")[0], "ipAddressPrefixlen": int(topo_modify_change_ip["routers"]["r0"]["links"] ["s1"]["ipv4"].split("/")[1]), } } } } } result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Modify the mask on the R0 interface") ip_addr = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] mask = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] step("Delete the ip address") topo1 = { "r0": { "links": { "r3": { "ipv4": ip_addr, "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ip on the R0 interface") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] = str( IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3) + "/{}".format(int(intf_ip.split("/")[1]) + 1) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) step("Verify that interface is enabled in ospf.") dut = "r0" input_dict = { "r0": { "links": { "s1": { "ospf": { "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"]["s1"] ["ipv4"].split("/")[0], "ipAddressPrefixlen": int(topo_modify_change_ip["routers"]["r0"]["links"] ["s1"]["ipv4"].split("/")[1]), } } } } } result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the area id on the interface") input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "area": "0.0.0.3" }, "delete": True, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) input_dict = { "r0": { "links": { "s1": { "interface": topo["routers"]["r0"]["links"]["s1"]["interface"], "ospf": { "area": "0.0.0.2" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that interface is enabled in ospf.") dut = "r0" input_dict = { "r0": { "links": { "s1": { "ospf": { "area": "0.0.0.2", "ospfEnabled": True } } } } } result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def ospfv3_nssa_tc27_p0(request): """ OSPF NSSA. Verify that ospf NSSA area DUT is capable receiving & processing Type7 N2 route. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): check_router_status(tgen) global topo step("Bring up the base config as per the topology") step("Configure ospf area 2 on r0 , r1 & r4, make the area 2 as NSSA area") reset_config_on_routers(tgen) input_dict = { "r2": { "static_routes": [{ "network": NETWORK["ipv6"][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" red_static(dut) step("Verify that Type 5 LSA is originated by R2.") dut = "r0" protocol = "ospf6" result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Un configure redistribute command in R4") dut = "r2" red_static(dut, config=False) input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv6"][0], "no_of_ip": 1, "routeType": "Network" }] } } dut = "r0" result = verify_ospf6_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv6", 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_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)