def test_ospf_gr_helper_tc2_p0(request): """ OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor sends grace lsa, helps RR to restart gracefully (RR = DR) """ 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) 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 setup_module(mod): return pytest.skip("OSPF GR helper mode is currently broken") """ Sets up the pytest environment * `mod`: module name """ global topo, intf, intf1, sw_name, pkt testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... json_file = "{}/ospf_gr_helper.json".format(CWD) tgen = Topogen(json_file, mod.__name__) global topo topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. daemons = topo_daemons(tgen, topo) # Starting topology, create tmp files which are loaded to routers # to start deamons and then start routers start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) sw_name = "s1" intf = topo["routers"]["r0"]["links"][sw_name]["interface"] intf1 = topo["routers"]["r1"]["links"][sw_name]["interface"] pkt = topo["routers"]["r1"]["opq_lsa_hex"] logger.info("Running setup_module() done")
def setup_module(mod): """ Sets up the pytest environment * `mod`: module name """ testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... json_file = "{}/ospf_asbr_summary_type7_lsa.json".format(CWD) tgen = Topogen(json_file, mod.__name__) global topo topo = tgen.json_topo # ... and here it calls Mininet initialization functions. # get list of daemons needs to be started for this suite. daemons = topo_daemons(tgen, topo) # Starting topology, create tmp files which are loaded to routers # to start daemons and then start routers start_topology(tgen, daemons) # Creating configuration from JSON build_config_from_json(tgen, topo) # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # 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 ) logger.info("Running setup_module() done")
def test_ospf_learning_tc15_p0(request): """Verify OSPF can learn different types of LSA and processes them. OSPF Learning : Edge learning different types of LSAs. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step("Bring up the base config as per the topology") step("Configure area 1 as NSSA Area") reset_config_on_routers(tgen) step("Verify that Type 3 summary LSA is originated for the same Area 0") ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv4"] ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) dut = "r0" input_dict = { "r1": { "static_routes": [{ "network": ip_net, "no_of_ip": 1, "routeType": "N IA" }] } } dut = "r0" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = { "r2": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0" }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Redistribute static route in R2 ospf.") dut = "r2" redistribute_ospf(tgen, topo, dut, "static") step("Verify that Type 5 LSA is originated by R2.") dut = "r0" protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that R0 receives Type 4 summary LSA.") dut = "r0" input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2" }] } } dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).") for rtr in ["r1", "r2", "r3"]: input_dict = { rtr: { "ospf": { "area": [{ "id": "0.0.0.2", "type": "nssa", "delete": True }] } } } result = create_router_ospf(tgen, topo, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that OSPF neighbours are reset after changing area type.") step("Verify that ABR R2 originates type 5 LSA in area 1.") step("Verify that route is calculated and installed in R1.") input_dict = { "r1": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 1, "routeType": "N E2" }] } } dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_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])) + 3) + "/{}".format( intf_ip.split("/")[1]) build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) 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_ospf_chaos_tc34_p1(request): """ verify ospf functionality when staticd is restarted. Verify ospf functionalitywhen staticroutes are redistributed & Staticd is restarted. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute " "to OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify OSPF neighbors after base config is done.") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Verify that route is advertised to R1.") dut = "r1" protocol = "ospf" nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0] result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Kill staticd daemon on R0.") kill_router_daemons(tgen, "r0", ["staticd"]) step("Verify that route advertised to R1 are deleted from RIB and FIB.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert ( result is not True ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert ( result is not True ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format( tc_name, result) step("Bring up staticd daemon on R0.") start_router_daemons(tgen, "r0", ["staticd"]) step("Verify OSPF neighbors are up after bringing back ospfd in R0") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("All the neighbours are up and routes are installed before the" " restart. Verify OSPF route table and ip route table.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Kill staticd daemon on R1.") kill_router_daemons(tgen, "r1", ["staticd"]) step("Bring up staticd daemon on R1.") start_router_daemons(tgen, "r1", ["staticd"]) step("Verify OSPF neighbors are up after bringing back ospfd in R1") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("All the neighbours are up and routes are installed before the" " restart. Verify OSPF route table and ip route table.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_ecmp_tc16_p0(request): """ Verify OSPF ECMP. Verify OSPF ECMP with max path configured as 8 (ECMP configured at FRR level) """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step("Bring up the base config as per the topology") step("Configure 8 interfaces between R1 and R2 and enable ospf in area 0.") reset_config_on_routers(tgen) step("Verify that OSPF is up with 8 neighborship sessions.") dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Configure a static route in R0 and redistribute in OSPF.") input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r0" red_static(dut) step("Verify that route in R2 in stalled with 8 next hops.") nh = [] for item in range(1, 7): nh.append( topo["routers"]["r0"]["links"]["r1-link1"]["ipv4"].split("/")[0]) nh2 = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0] nh.append(nh2) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("shut no shut all the interfaces on the remote router - R2") dut = "r1" for intfr in range(1, 7): intf = topo["routers"]["r1"]["links"]["r0-link{}".format( intfr)]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for intfr in range(1, 7): intf = topo["routers"]["r1"]["links"]["r0-link{}".format( intfr)]["interface"] shutdown_bringup_interface(tgen, dut, intf, True) result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("shut no shut on all the interfaces on DUT (r1)") for intfr in range(1, 7): intf = topo["routers"]["r1"]["links"]["r0-link{}".format( intfr)]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) for intfr in range(1, 7): intf = topo["routers"]["r1"]["links"]["r0-link{}".format( intfr)]["interface"] shutdown_bringup_interface(tgen, dut, intf, True) step("Verify that all the neighbours are up and routes are installed" " with 8 next hop in ospf and ip route tables on R1.") step("Verify that OSPF is up with 8 neighborship sessions.") dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step(" Un configure static route on R0") dut = "r0" red_static(dut, config=False) # Wait for R0 to flush external LSAs. sleep(10) step("Verify that route is withdrawn from R2.") dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, attempts=5, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib( tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh, attempts=5, expected=False, ) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Re configure the static route in R0.") dut = "r0" red_static(dut) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_ecmp_tc17_p0(request): """ Verify OSPF ECMP. Verify OSPF ECMP with max path configured as 2 (Edge having 2 uplink ports) """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step("Bring up the base config as per the topology") step("Configure 2 interfaces between R1 and R2 & enable ospf in area 0.") reset_config_on_routers(tgen) step("Verify that OSPF is up with 2 neighborship sessions.") dut = "r1" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Configure a static route in R0 and redistribute in OSPF.") input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r0" red_static(dut) step("Verify that route in R2 in stalled with 2 next hops.") nh1 = topo["routers"]["r0"]["links"]["r1-link1"]["ipv4"].split("/")[0] nh2 = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0] nh = [nh1, nh2] dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step(" Un configure static route on R0") dut = "r0" red_static(dut, config=False) # sleep till the route gets withdrawn sleep(10) step("Verify that route is withdrawn from R2.") dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, attempts=5, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib( tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh, attempts=5, expected=False, ) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Reconfigure the static route in R0.Change ECMP value to 2.") dut = "r0" red_static(dut) step("Configure cost on R0 as 100") r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 100}}}}} result = config_ospf_interface(tgen, topo, r0_ospf_cost) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_show_p1(request): """Verify ospf show commands with json output.""" 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) ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) dut = "r1" input_dict = { "r1": { "links": { "r0": { "ospf": { "ifUp": True, "ifFlags": "<UP,BROADCAST,RUNNING,MULTICAST>", "ospfEnabled": True, "ipAddressPrefixlen": 24, "ospfIfType": "Broadcast", "area": "0.0.0.0", "networkType": "BROADCAST", "cost": 10, "transmitDelaySecs": 1, "state": "DR", "priority": 1, "mcastMemberOspfAllRouters": True, "timerMsecs": 1000, "timerDeadSecs": 4, "timerWaitSecs": 4, "timerRetransmitSecs": 5, "nbrCount": 1, "nbrAdjacentCount": 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) # show ip ospf route ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"] ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0] input_dict = { "r1": { "static_routes": [{ "network": ip_net, "no_of_ip": 1, "routeType": "N" }] } } dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_rfc2328_appendinxE_p0(request): """ Test OSPF appendinx E RFC2328. """ 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("Verify that OSPF neighbours are Full.") # 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 ) redistribute_ospf(tgen, topo, "r0", "static") step("Configure static route with prefix 24, 16, 8 to check ") input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["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) input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["ipv4"][1], "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) input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["ipv4"][2], "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) step("Verify that ospf originates routes with mask 24, 16, 8") ip_net = NETWORK_APP_E["ipv4"][0] input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}} dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ip_net = NETWORK_APP_E["ipv4"][1] input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}} dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) ip_net = NETWORK_APP_E["ipv4"][2] input_dict = {"r1": {"static_routes": [{"network": ip_net, "no_of_ip": 1}]}} dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Delete static route with prefix 24, 16, 8 to check ") input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["ipv4"][0], "no_of_ip": 1, "next_hop": "Null0", "delete": True, } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["ipv4"][1], "no_of_ip": 1, "next_hop": "Null0", "delete": True, } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) input_dict = { "r0": { "static_routes": [ { "network": NETWORK_APP_E["ipv4"][2], "no_of_ip": 1, "next_hop": "Null0", "delete": True, } ] } } result = create_static_routes(tgen, input_dict) 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_ospf_redistribution_tc6_p0(request): """Test OSPF inter area route calculations.""" tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step("Bring up the base config.") reset_config_on_routers(tgen) step("Verify that OSPF neighbors are FULL.") ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("verify intra area route is calculated for r0-r3 interface ip in R1") ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"] ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0] input_dict = { "r1": { "static_routes": [{ "network": ip_net, "no_of_ip": 1, "routeType": "N" }] } } dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Delete the ip address on newly configured loopback of R0") topo1 = { "r0": { "links": { "r3": { "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"], "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r1" for num in range(0, nretry): result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False) if result is not True: break assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present after deleting ip address of newly " "configured loopback of R0 \n Error: {}".format(tc_name, result)) protocol = "ospf" result = verify_rib( tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh, expected=False, ) assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present in fib after deleting ip address of newly " "configured loopback of R0 \n Error: {}".format(tc_name, result)) step("Add back the deleted ip address on newly configured interface of R0") topo1 = { "r0": { "links": { "r3": { "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"], "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Shut no shut interface on R0") dut = "r0" intf = topo["routers"]["r0"]["links"]["r3"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) step("un shut the OSPF interface on R0") dut = "r0" shutdown_bringup_interface(tgen, dut, intf, True) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_chaos_tc32_p1(request): """Verify ospf functionality after restart FRR service. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute " "to OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK['ipv4'][0], "no_of_ip": 5, "next_hop": 'Null0', }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify OSPF neighbors after base config is done.") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step("Verify that route is advertised to R1.") dut = 'r1' protocol = 'ospf' nh = topo['routers']['r0']['links']['r1']['ipv4'].split('/')[0] result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Restart frr on R0") stop_router(tgen, 'r0') start_router(tgen, 'r0') step("Verify OSPF neighbors are up after restarting R0") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step("All the neighbours are up and routes are installed before the" " restart. Verify OSPF route table and ip route table.") dut = 'r1' protocol = 'ospf' result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Restart frr on R1") stop_router(tgen, 'r1') start_router(tgen, 'r1') step("Verify OSPF neighbors are up after restarting R1") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step("All the neighbours are up and routes are installed before the" " restart. Verify OSPF route table and ip route table.") dut = 'r1' protocol = 'ospf' result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_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_ospf_tc4_mtu_ignore_p0(request): """ OSPF NFSM - MTU change Verify NFSM events when ospf nbr changes with different MTU values """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step(" Bring up the base config as per the topology") step("Configure OSPF on all the routers of the topology.") step("Verify that OSPF neighbors are FULL.") reset_config_on_routers(tgen) result = verify_ospf_neighbor(tgen, topo) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Modify the MTU to non default Value on R0 to R1 interface. " "Reset ospf neighbors on R0.") rtr0 = tgen.routers()["r0"] rtr1 = tgen.routers()["r1"] r0_r1_intf = topo["routers"]["r0"]["links"]["r1"]["interface"] r1_r0_intf = topo["routers"]["r1"]["links"]["r0"]["interface"] rtr0.run("ip link set {} mtu 1200".format(r0_r1_intf)) clear_ospf(tgen, "r0") step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State.") result = verify_ospf_neighbor(tgen, topo, expected=False) assert result is not True, ("Testcase {} : Failed \n OSPF nbrs are Full " "instead of Exstart. Error: {}".format( tc_name, result)) step("Verify that configured MTU value is updated in the show ip " "ospf interface.") dut = "r0" input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuBytes": 1200}}}}} 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 MTU to non default Value on R0 to R1 interface. " "Reset ospf neighbors on R0.") rtr0.run("ip link set {} mtu 1500".format(r0_r1_intf)) clear_ospf(tgen, "r0") step("Verify that OSPF neighborship between R0 and R1 becomes full.") result = verify_ospf_neighbor(tgen, topo) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure mtu ignore and change the value of the mtu to non default" " on R0 to R1 interface. Reset ospf neighbors on R0.") r0_ospf_mtu = {"r0": {"links": {"r1": {"ospf": {"mtu_ignore": True}}}}} result = config_ospf_interface(tgen, topo, r0_ospf_mtu) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) dut = "r0" input_dict = { "r0": { "links": { "r1": { "ospf": { "mtuMismatchDetect": 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) r1_ospf_mtu = {"r1": {"links": {"r0": {"ospf": {"mtu_ignore": True}}}}} result = config_ospf_interface(tgen, topo, r1_ospf_mtu) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) rtr0.run("ip link set {} mtu 1200".format(r0_r1_intf)) clear_ospf(tgen, "r0") step("Verify that OSPF neighborship between R0 and R1 becomes full.") result = verify_ospf_neighbor(tgen, topo) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Unconfigure mtu-ignore command from the interface. " "Reset ospf neighbors on R0.") r1_ospf_mtu = { "r1": { "links": { "r0": { "ospf": { "mtu_ignore": True, "del_action": True } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_mtu) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) clear_ospf(tgen, "r0") step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State.") result = verify_ospf_neighbor(tgen, topo, expected=False) assert result is not True, ("Testcase {} : Failed \n OSPF nbrs are Full " "instead of Exstart. Error: {}".format( tc_name, result)) step("Modify the MTU to again default valaue on R0 to R1 interface.") rtr0.run("ip link set {} mtu 1500".format(r0_r1_intf)) clear_ospf(tgen, "r0") step("Verify that OSPF neighborship between R0 and R1 becomes full.") result = verify_ospf_neighbor(tgen, topo) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure ospf interface with jumbo MTU (9216)." "Reset ospf neighbors on R0.") rtr0.run("ip link set {} mtu 9216".format(r0_r1_intf)) rtr1.run("ip link set {} mtu 9216".format(r1_r0_intf)) clear_ospf(tgen, "r0") clear_ospf(tgen, "r1") step("Verify that OSPF neighborship between R0 and R1 becomes full.") result = verify_ospf_neighbor(tgen, topo) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that jumbo MTU is updated in the show ip ospf interface.") dut = "r0" input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuBytes": 9216}}}}} 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 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, attempts=5) 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_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, attempts=3) 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, attempts=5) 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(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_ospf_p2p_tc3_p0(request): """OSPF IFSM -Verify state change events on p2p network.""" 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.") step("Verify that config is successful.") dut = "r0" input_dict = { "r0": { "links": { "r3": { "ospf": { "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"]["r3"]["ipv4"], "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ip on the R0 interface") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["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": { "r3": { "ospf": { "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"]["r3"] ["ipv4"].split("/")[0], "ipAddressPrefixlen": int(topo_modify_change_ip["routers"]["r0"]["links"] ["r3"]["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"]["r3"]["ipv4"] mask = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] step("Delete the ip address") topo1 = { "r0": { "links": { "r3": { "ipv4": ip_addr, "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change the ip on the R0 interface") topo_modify_change_ip = deepcopy(topo) intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["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": { "r3": { "ospf": { "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"]["r3"] ["ipv4"].split("/")[0], "ipAddressPrefixlen": int(topo_modify_change_ip["routers"]["r0"]["links"] ["r3"]["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) topo1 = { "r0": { "links": { "r3": { "ipv4": topo_modify_change_ip["routers"]["r0"]["links"]["r3"] ["ipv4"], "interface": topo_modify_change_ip["routers"]["r0"]["links"]["r3"] ["interface"], "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) build_config_from_json(tgen, topo, save_bkup=False) step("Change the area id on the interface") input_dict = { "r0": { "links": { "r3": { "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "ospf": { "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 = { "r0": { "links": { "r3": { "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "ospf": { "area": "0.0.0.1" }, } } } } 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": { "r3": { "ospf": { "area": "0.0.0.1", "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) input_dict = { "r0": { "links": { "r3": { "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "ospf": { "area": "0.0.0.1" }, "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": { "r3": { "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], "ospf": { "area": "0.0.0.0" }, } } } } result = create_interfaces_cfg(tgen, input_dict) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) # Api call verify whether BGP is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) 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_ospf_hello_tc10_p0(request): """ OSPF timers. Verify OSPF interface timer hello interval functionality """ 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("modify hello timer from default value to some other value on r1") topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 11, "dead_interval": 12 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured and applied using " "the show ip ospf interface command.") dut = "r1" input_dict = { "r1": { "links": { "r0": { "ospf": { "timerMsecs": 11 * 1000, "timerDeadSecs": 12 } } } } } 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 hello timer from default value to r1 hello timer on r2") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 11, "dead_interval": 12 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = { "r0": { "links": { "r1": { "ospf": { "timerMsecs": 11 * 1000, "timerDeadSecs": 12 } } } } } dut = "r0" 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("reconfigure the default hello timer value to default on r1 and r2") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 10, "dead_interval": 40 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 10, "dead_interval": 40 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = { "r0": { "links": { "r1": { "ospf": { "timerMsecs": 10 * 1000, "timerDeadSecs": 40 } } } } } dut = "r0" 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("reconfigure the default hello timer value to default on r1 and r2") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 10, "dead_interval": 40 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 10, "dead_interval": 40 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = { "r0": { "links": { "r1": { "ospf": { "timerMsecs": 10 * 1000, "timerDeadSecs": 40 } } } } } dut = "r0" 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("configure hello timer = 1 on r1 and r2") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 1, "dead_interval": 4 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 1, "dead_interval": 4 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = { "r0": { "links": { "r1": { "ospf": { "timerMsecs": 1 * 1000, "timerDeadSecs": 4 } } } } } dut = "r0" 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step(" Configure hello timer = 65535") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 65535, "dead_interval": 4 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 65535, "dead_interval": 4 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = { "r0": { "links": { "r1": { "ospf": { "timerMsecs": 65535 * 1000, "timerDeadSecs": 4 } } } } } dut = "r0" 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step(" Try configuring timer values outside range for example 65536") topo1 = { "r0": { "links": { "r1": { "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], "ospf": { "hello_interval": 65536, "dead_interval": 4 }, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Unconfigure the hello timer from the interface from r1 and r2.") topo1 = { "r1": { "links": { "r0": { "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], "ospf": { "hello_interval": 65535 }, "delete": True, } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that timer value is deleted from intf & " "set to default value 40 sec.") input_dict = {"r1": {"links": {"r0": {"ospf": {"timerMsecs": 10 * 1000}}}}} dut = "r1" 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 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_dead_tc11_p0(request): """ OSPF timers. Verify OSPF interface timer dead interval functionality """ 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("modify dead interval from default value to some other value on r1") topo1 = { 'r1': { 'links': { 'r0': { 'interface': topo['routers']['r1']['links']['r0']['interface'], 'ospf': { 'hello_interval': 12, 'dead_interval': 48 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured and applied using " "the show ip ospf interface command.") dut = 'r1' input_dict = {'r1': {'links': {'r0': {'ospf': {'timerDeadSecs': 48}}}}} 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 dead interval from default value to r1" "dead interval timer on r2") topo1 = { 'r0': { 'links': { 'r1': { 'interface': topo['routers']['r0']['links']['r1']['interface'], 'ospf': { 'dead_interval': 48, 'hello_interval': 12 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = {'r0': {'links': {'r1': {'ospf': {'timerDeadSecs': 48}}}}} dut = 'r0' 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step("reconfigure the default dead interval timer value to " "default on r1 and r2") topo1 = { 'r0': { 'links': { 'r1': { 'interface': topo['routers']['r0']['links']['r1']['interface'], 'ospf': { 'dead_interval': 40 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { 'r1': { 'links': { 'r0': { 'interface': topo['routers']['r1']['links']['r0']['interface'], 'ospf': { 'dead_interval': 40 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = {'r0': {'links': {'r1': {'ospf': {'timerDeadSecs': 40}}}}} dut = 'r0' 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step(" Configure dead timer = 65535 on r1 and r2") topo1 = { 'r0': { 'links': { 'r1': { 'interface': topo['routers']['r0']['links']['r1']['interface'], 'ospf': { 'dead_interval': 65535 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) topo1 = { 'r1': { 'links': { 'r0': { 'interface': topo['routers']['r1']['links']['r0']['interface'], 'ospf': { 'dead_interval': 65535 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that new timer value is configured.") input_dict = {'r0': {'links': {'r1': {'ospf': {'timerDeadSecs': 65535}}}}} dut = 'r0' 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("verify that ospf neighbours are full") ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) assert ospf_covergence is True, ("setup_module :Failed \n Error:" " {}".format(ospf_covergence)) step(" Try configuring timer values outside range for example 65536") topo1 = { 'r0': { 'links': { 'r1': { 'interface': topo['routers']['r0']['links']['r1']['interface'], 'ospf': { 'dead_interval': 65536 } } } } } result = create_interfaces_cfg(tgen, topo1) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Unconfigure the dead timer from the interface from r1 and r2.") topo1 = { 'r1': { 'links': { 'r0': { 'interface': topo['routers']['r1']['links']['r0']['interface'], 'ospf': { 'dead_interval': 65535 }, 'delete': True } } } } result = create_interfaces_cfg(tgen, topo1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that timer value is deleted from intf & " "set to default value 40 sec.") input_dict = {'r1': {'links': {'r0': {'ospf': {'timerDeadSecs': 40}}}}} dut = 'r1' 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 test_ospf_routemaps_functionality_tc25_p0(request): """ OSPF route map support functionality. Verify OSPF route map support functionality when route map actions are toggled. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute " "to OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static", "route_map": "rmap_ipv4" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with permit rule") # Create route map routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "permit"}]}}} result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route is advertised to R1.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with deny rule") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "seq_id": 10, "action": "deny" }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Verify that route is not advertised to R1.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_redistribution_tc8_p1(request): """ Test OSPF redistribution of connected routes. Verify OSPF redistribution of connected routes when bgp multi hop neighbor is configured using ospf routes """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config.") step("Configure loopback interface on all routers, and redistribut" "e connected routes into ospf") reset_config_on_routers(tgen) step("verify that connected routes -loopback is found in all routers" "advertised/exchaged via ospf") for rtr in topo["routers"]: redistribute_ospf(tgen, topo, rtr, "static") redistribute_ospf(tgen, topo, rtr, "connected") for node in topo["routers"]: input_dict = { "r0": { "static_routes": [{ "network": topo["routers"][node]["links"]["lo"]["ipv4"], "no_of_ip": 1, }] } } for rtr in topo["routers"]: result = verify_rib(tgen, "ipv4", rtr, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure E BGP multi hop using the loopback addresses.") as_num = 100 for node in topo["routers"]: as_num += 1 topo["routers"][node].update({ "bgp": { "local_as": as_num, "address_family": { "ipv4": { "unicast": { "neighbor": {} } } }, } }) for node in topo["routers"]: for rtr in topo["routers"]: if node is not rtr: topo["routers"][node]["bgp"]["address_family"]["ipv4"][ "unicast"]["neighbor"].update({ rtr: { "dest_link": { "lo": { "source_link": "lo", "ebgp_multihop": 2 } } } }) result = create_router_bgp(tgen, topo, topo["routers"]) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that BGP neighbor is ESTABLISHED") result = verify_bgp_convergence(tgen, topo) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Configure couple of static routes in R0 and " "Redistribute static routes in R1 bgp.") for rtr in topo["routers"]: redistribute_ospf(tgen, topo, rtr, "static", delete=True) input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) configure_bgp_on_r0 = { "r0": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static" }] } } } } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "bgp" for rtr in ["r1", "r2", "r3"]: result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Clear ospf neighbours in R0") for rtr in topo["routers"]: clear_ospf(tgen, rtr) step("Verify that OSPF neighbours are reset and forms new adjacencies.") # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Verify that BGP neighbours are reset and forms new adjacencies.") result = verify_bgp_convergence(tgen, topo) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) protocol = "bgp" for rtr in ["r1", "r2", "r3"]: result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_lan_ecmp_tc18_p0(request): """ OSPF ECMP. Verify OSPF ECMP with max path configured as 8 (Edge having 1 uplink port as broadcast network, connect to 8 TORs - LAN case) """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) global topo step("Bring up the base config as per the topology") step(". Configure ospf in all the routers on LAN interface.") reset_config_on_routers(tgen) step("Verify that OSPF is up with 8 neighborship sessions.") ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Configure a static route in all the routes and " "redistribute static/connected in OSPF.") for rtr in topo["routers"]: input_dict = { rtr: { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0" }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = rtr redistribute_ospf(tgen, topo, dut, "static") step("Verify that route in R0 in stalled with 8 hops. " "Verify ospf route table and ip route table.") nh = [] for rtr in topo["routers"]: nh.append(topo["routers"][rtr]["links"]["s1"]["ipv4"].split("/")[0]) nh.remove(topo["routers"]["r1"]["links"]["s1"]["ipv4"].split("/")[0]) dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step(" clear ip ospf interface on DUT(r0)") clear_ospf(tgen, "r0") step("Verify that after clearing the ospf interface all the " "neighbours are up and routes are installed with 8 next hop " "in ospf and ip route tables on R0") dut = "r0" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step(" clear ip ospf interface on R2") clear_ospf(tgen, "r2") dut = "r2" ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Delete static/connected cmd in ospf in all the routes one by one.") for rtr in topo["routers"]: input_dict = { rtr: { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", "delete": True, }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that all the routes are withdrawn from R0") dut = "r1" result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, retry_timeout=10, expected=False) assert ( result is not True ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format( tc_name, result) protocol = "ospf" result = verify_rib( tgen, "ipv4", dut, input_dict, protocol=protocol, next_hop=nh, retry_timeout=10, expected=False, ) assert ( result is not True ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format( tc_name, result) write_test_footer(tc_name)